@office-kit/xlsx 0.8.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/LICENSE +21 -0
- package/README.md +319 -0
- package/THIRD_PARTY_NOTICES.md +56 -0
- package/dist/cell/cell.d.ts +234 -0
- package/dist/cell/index.d.ts +4 -0
- package/dist/cell/rich-text.d.ts +37 -0
- package/dist/cell-D9CaNKnU.mjs +320 -0
- package/dist/cell-D9CaNKnU.mjs.map +1 -0
- package/dist/cell-style-BEDjMX1y.mjs +1579 -0
- package/dist/cell-style-BEDjMX1y.mjs.map +1 -0
- package/dist/cell.mjs +2 -0
- package/dist/chart/chart-xml.d.ts +16 -0
- package/dist/chart/chart.d.ts +735 -0
- package/dist/chart/cx/chartex-xml.d.ts +6 -0
- package/dist/chart/cx/chartex.d.ts +279 -0
- package/dist/chart/index.d.ts +6 -0
- package/dist/chart/user-shapes-xml.d.ts +4 -0
- package/dist/chart/user-shapes.d.ts +61 -0
- package/dist/chart.mjs +232 -0
- package/dist/chart.mjs.map +1 -0
- package/dist/chartsheet/chartsheet-xml.d.ts +17 -0
- package/dist/chartsheet/chartsheet.d.ts +121 -0
- package/dist/chartsheet/index.d.ts +2 -0
- package/dist/chartsheet-C3-tqkPy.mjs +23 -0
- package/dist/chartsheet-C3-tqkPy.mjs.map +1 -0
- package/dist/chartsheet.mjs +2 -0
- package/dist/colors-ovWAwnZI.mjs +67 -0
- package/dist/colors-ovWAwnZI.mjs.map +1 -0
- package/dist/compat/numbers.d.ts +14 -0
- package/dist/coordinate-96Ecci4d.mjs +276 -0
- package/dist/coordinate-96Ecci4d.mjs.map +1 -0
- package/dist/datetime-B2ySVlXt.mjs +71 -0
- package/dist/datetime-B2ySVlXt.mjs.map +1 -0
- package/dist/defined-names-CviWmtQg.mjs +89 -0
- package/dist/defined-names-CviWmtQg.mjs.map +1 -0
- package/dist/differential-D4dg-qtZ.mjs +37 -0
- package/dist/differential-D4dg-qtZ.mjs.map +1 -0
- package/dist/drawing/anchor.d.ts +63 -0
- package/dist/drawing/dml/colors.d.ts +109 -0
- package/dist/drawing/dml/dml-xml.d.ts +35 -0
- package/dist/drawing/dml/effect.d.ts +92 -0
- package/dist/drawing/dml/fill.d.ts +115 -0
- package/dist/drawing/dml/geometry.d.ts +113 -0
- package/dist/drawing/dml/line.d.ts +41 -0
- package/dist/drawing/dml/shape-properties.d.ts +33 -0
- package/dist/drawing/dml/text.d.ts +218 -0
- package/dist/drawing/drawing-xml.d.ts +5 -0
- package/dist/drawing/drawing.d.ts +117 -0
- package/dist/drawing/image.d.ts +40 -0
- package/dist/drawing/index.d.ts +14 -0
- package/dist/drawing-BxzLuryn.mjs +415 -0
- package/dist/drawing-BxzLuryn.mjs.map +1 -0
- package/dist/drawing.mjs +119 -0
- package/dist/drawing.mjs.map +1 -0
- package/dist/escape-DFTE7ZJc.mjs +51 -0
- package/dist/escape-DFTE7ZJc.mjs.map +1 -0
- package/dist/exceptions-D-CFwxgm.mjs +37 -0
- package/dist/exceptions-D-CFwxgm.mjs.map +1 -0
- package/dist/formula/tokenizer.d.ts +61 -0
- package/dist/formula/translate.d.ts +67 -0
- package/dist/inference-B3ES3KEJ.mjs +42 -0
- package/dist/inference-B3ES3KEJ.mjs.map +1 -0
- package/dist/io/browser.d.ts +41 -0
- package/dist/io/index.d.ts +7 -0
- package/dist/io/load.d.ts +46 -0
- package/dist/io/node-fs.d.ts +62 -0
- package/dist/io/node-save.d.ts +3 -0
- package/dist/io/node.d.ts +17 -0
- package/dist/io/save.d.ts +14 -0
- package/dist/io/sink.d.ts +54 -0
- package/dist/io/source.d.ts +14 -0
- package/dist/io.mjs +212 -0
- package/dist/io.mjs.map +1 -0
- package/dist/load-D5cbhoGx.mjs +1069 -0
- package/dist/load-D5cbhoGx.mjs.map +1 -0
- package/dist/manifest-Dps1-OpP.mjs +801 -0
- package/dist/manifest-Dps1-OpP.mjs.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.mjs +308 -0
- package/dist/node.mjs.map +1 -0
- package/dist/packaging/core.d.ts +45 -0
- package/dist/packaging/custom.d.ts +62 -0
- package/dist/packaging/extended.d.ts +45 -0
- package/dist/packaging/index.d.ts +10 -0
- package/dist/packaging/manifest.d.ts +24 -0
- package/dist/packaging/relationships.d.ts +30 -0
- package/dist/packaging.mjs +2 -0
- package/dist/parser-DuLejQy1.mjs +156 -0
- package/dist/parser-DuLejQy1.mjs.map +1 -0
- package/dist/reader-D1fNW9k1.mjs +534 -0
- package/dist/reader-D1fNW9k1.mjs.map +1 -0
- package/dist/save-RohQtgEZ.mjs +745 -0
- package/dist/save-RohQtgEZ.mjs.map +1 -0
- package/dist/schema/core.d.ts +133 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/serialize.d.ts +6 -0
- package/dist/schema.mjs +2 -0
- package/dist/serialize-55EnT30e.mjs +254 -0
- package/dist/serialize-55EnT30e.mjs.map +1 -0
- package/dist/serializer-BwbgHYJV.mjs +116 -0
- package/dist/serializer-BwbgHYJV.mjs.map +1 -0
- package/dist/streaming/index.d.ts +2 -0
- package/dist/streaming/read-only.d.ts +38 -0
- package/dist/streaming/write-only.d.ts +47 -0
- package/dist/streaming.mjs +612 -0
- package/dist/streaming.mjs.map +1 -0
- package/dist/styles/alignment.d.ts +33 -0
- package/dist/styles/alignment.schema.d.ts +3 -0
- package/dist/styles/borders.d.ts +40 -0
- package/dist/styles/borders.schema.d.ts +4 -0
- package/dist/styles/cell-style.d.ts +270 -0
- package/dist/styles/colors.d.ts +128 -0
- package/dist/styles/colors.schema.d.ts +3 -0
- package/dist/styles/differential.d.ts +41 -0
- package/dist/styles/fills.d.ts +54 -0
- package/dist/styles/fills.schema.d.ts +6 -0
- package/dist/styles/fonts.d.ts +44 -0
- package/dist/styles/fonts.schema.d.ts +3 -0
- package/dist/styles/index.d.ts +21 -0
- package/dist/styles/named-styles.d.ts +52 -0
- package/dist/styles/numbers.d.ts +39 -0
- package/dist/styles/numbers.schema.d.ts +3 -0
- package/dist/styles/protection.d.ts +9 -0
- package/dist/styles/protection.schema.d.ts +3 -0
- package/dist/styles/stylesheet-reader.d.ts +7 -0
- package/dist/styles/stylesheet-writer.d.ts +3 -0
- package/dist/styles/stylesheet.d.ts +95 -0
- package/dist/styles.mjs +4 -0
- package/dist/stylesheet-writer-C2eRmn22.mjs +8624 -0
- package/dist/stylesheet-writer-C2eRmn22.mjs.map +1 -0
- package/dist/table-DkX6UniA.mjs +113 -0
- package/dist/table-DkX6UniA.mjs.map +1 -0
- package/dist/tree-Bbs1C8Rc.mjs +192 -0
- package/dist/tree-Bbs1C8Rc.mjs.map +1 -0
- package/dist/units-rOMQqXh2.mjs +41 -0
- package/dist/units-rOMQqXh2.mjs.map +1 -0
- package/dist/user-shapes-DfmCGKB0.mjs +252 -0
- package/dist/user-shapes-DfmCGKB0.mjs.map +1 -0
- package/dist/utf8-D91g1XTG.mjs +143 -0
- package/dist/utf8-D91g1XTG.mjs.map +1 -0
- package/dist/utils/coordinate.d.ts +103 -0
- package/dist/utils/css.d.ts +18 -0
- package/dist/utils/datetime.d.ts +38 -0
- package/dist/utils/escape.d.ts +34 -0
- package/dist/utils/exceptions.d.ts +34 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/inference.d.ts +24 -0
- package/dist/utils/stable-stringify.d.ts +7 -0
- package/dist/utils/units.d.ts +14 -0
- package/dist/utils/utf8.d.ts +1 -0
- package/dist/utils.mjs +39 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/workbook/calc-properties.d.ts +47 -0
- package/dist/workbook/defined-names.d.ts +121 -0
- package/dist/workbook/file-recovery.d.ts +11 -0
- package/dist/workbook/file-sharing.d.ts +14 -0
- package/dist/workbook/file-version.d.ts +13 -0
- package/dist/workbook/function-groups.d.ts +10 -0
- package/dist/workbook/index.d.ts +24 -0
- package/dist/workbook/protection.d.ts +35 -0
- package/dist/workbook/shared-strings.d.ts +57 -0
- package/dist/workbook/smart-tags.d.ts +13 -0
- package/dist/workbook/views.d.ts +89 -0
- package/dist/workbook/workbook-properties.d.ts +57 -0
- package/dist/workbook/workbook.d.ts +643 -0
- package/dist/workbook-HGYNRBlV.mjs +636 -0
- package/dist/workbook-HGYNRBlV.mjs.map +1 -0
- package/dist/workbook.mjs +58 -0
- package/dist/workbook.mjs.map +1 -0
- package/dist/worksheet/auto-filter.d.ts +34 -0
- package/dist/worksheet/cell-range.d.ts +121 -0
- package/dist/worksheet/comments-xml.d.ts +24 -0
- package/dist/worksheet/comments.d.ts +13 -0
- package/dist/worksheet/conditional-formatting.d.ts +150 -0
- package/dist/worksheet/custom-sheet-views.d.ts +43 -0
- package/dist/worksheet/data-consolidate.d.ts +29 -0
- package/dist/worksheet/data-validations.d.ts +72 -0
- package/dist/worksheet/dimensions.d.ts +40 -0
- package/dist/worksheet/errors.d.ts +40 -0
- package/dist/worksheet/hyperlinks.d.ts +42 -0
- package/dist/worksheet/index.d.ts +46 -0
- package/dist/worksheet/ole-objects.d.ts +37 -0
- package/dist/worksheet/page-setup.d.ts +173 -0
- package/dist/worksheet/phonetic.d.ts +11 -0
- package/dist/worksheet/properties.d.ts +34 -0
- package/dist/worksheet/protected-ranges.d.ts +19 -0
- package/dist/worksheet/protection.d.ts +44 -0
- package/dist/worksheet/reader.d.ts +38 -0
- package/dist/worksheet/scenarios.d.ts +36 -0
- package/dist/worksheet/smart-tags.d.ts +23 -0
- package/dist/worksheet/sort-state.d.ts +28 -0
- package/dist/worksheet/table-xml.d.ts +5 -0
- package/dist/worksheet/table.d.ts +80 -0
- package/dist/worksheet/views.d.ts +47 -0
- package/dist/worksheet/web-publish.d.ts +21 -0
- package/dist/worksheet/worksheet.d.ts +935 -0
- package/dist/worksheet/writer.d.ts +72 -0
- package/dist/worksheet-CmCNoIgD.mjs +1726 -0
- package/dist/worksheet-CmCNoIgD.mjs.map +1 -0
- package/dist/worksheet.mjs +247 -0
- package/dist/worksheet.mjs.map +1 -0
- package/dist/writer-DspzfkNA.mjs +221 -0
- package/dist/writer-DspzfkNA.mjs.map +1 -0
- package/dist/xml/index.d.ts +10 -0
- package/dist/xml/iterparse.d.ts +22 -0
- package/dist/xml/namespaces.d.ts +91 -0
- package/dist/xml/parser.d.ts +7 -0
- package/dist/xml/serializer.d.ts +14 -0
- package/dist/xml/stream-writer.d.ts +39 -0
- package/dist/xml/tree.d.ts +37 -0
- package/dist/xml.mjs +140 -0
- package/dist/xml.mjs.map +1 -0
- package/dist/zip/decompression-guard.d.ts +70 -0
- package/dist/zip/index.d.ts +6 -0
- package/dist/zip/random-access-reader.d.ts +16 -0
- package/dist/zip/reader.d.ts +45 -0
- package/dist/zip/writer.d.ts +65 -0
- package/dist/zip/zip64-patch.d.ts +12 -0
- package/dist/zip.mjs +3 -0
- package/package.json +147 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { o as OpenXmlSchemaError } from "./exceptions-D-CFwxgm.mjs";
|
|
2
|
+
import { a as columnLetterFromIndex, n as MAX_ROW, t as MAX_COL } from "./coordinate-96Ecci4d.mjs";
|
|
3
|
+
import { t as ERROR_CODES } from "./inference-B3ES3KEJ.mjs";
|
|
4
|
+
//#region src/cell/rich-text.ts
|
|
5
|
+
function makeTextRun(text, font) {
|
|
6
|
+
if (typeof text !== "string") throw new OpenXmlSchemaError("makeTextRun: text must be a string");
|
|
7
|
+
return Object.freeze(font !== void 0 ? {
|
|
8
|
+
text,
|
|
9
|
+
font
|
|
10
|
+
} : { text });
|
|
11
|
+
}
|
|
12
|
+
function makeRichText(runs) {
|
|
13
|
+
const out = runs.map((r) => Object.isFrozen(r) ? r : makeTextRun(r.text, r.font));
|
|
14
|
+
return Object.freeze(out);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Concatenate the plain-text content of a rich-text value (rich-text
|
|
18
|
+
* read paths often want the raw text without formatting).
|
|
19
|
+
*/
|
|
20
|
+
function richTextToString(rt) {
|
|
21
|
+
let out = "";
|
|
22
|
+
for (const r of rt) out += r.text;
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/cell/cell.ts
|
|
27
|
+
const validateCoord = (row, col) => {
|
|
28
|
+
if (!Number.isInteger(row) || row < 1 || row > 1048576) throw new OpenXmlSchemaError(`Cell row ${row} out of range [1, ${MAX_ROW}]`);
|
|
29
|
+
if (!Number.isInteger(col) || col < 1 || col > 16384) throw new OpenXmlSchemaError(`Cell col ${col} out of range [1, ${MAX_COL}]`);
|
|
30
|
+
};
|
|
31
|
+
/** Build a fresh Cell. Validates coordinates against the OOXML grid bounds. */
|
|
32
|
+
function makeCell(row, col, value = null, styleId = 0) {
|
|
33
|
+
validateCoord(row, col);
|
|
34
|
+
return {
|
|
35
|
+
row,
|
|
36
|
+
col,
|
|
37
|
+
value,
|
|
38
|
+
styleId
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Format a Cell's coordinate as the canonical "A1" string. */
|
|
42
|
+
function getCoordinate(c) {
|
|
43
|
+
return `${columnLetterFromIndex(c.col)}${c.row}`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Direct value setter. No type inference, no validation beyond the union — the
|
|
47
|
+
* caller is in charge. Use {@link bindValue} for the "do what I mean" path.
|
|
48
|
+
*/
|
|
49
|
+
function setCellValue(c, value) {
|
|
50
|
+
c.value = value;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* "Smart" setter: infers the cell value from a JS runtime value.
|
|
54
|
+
* - `string` starting with `=` → formula
|
|
55
|
+
* - `string` matching an Excel error token → error variant
|
|
56
|
+
* - other primitives / Date / null pass through verbatim
|
|
57
|
+
*
|
|
58
|
+
* Intentionally not the default — explicit is clearer for typed code, and
|
|
59
|
+
* inferring on every write costs measurable time on the worksheet write hot
|
|
60
|
+
* path.
|
|
61
|
+
*/
|
|
62
|
+
function bindValue(c, value) {
|
|
63
|
+
if (typeof value === "string") {
|
|
64
|
+
if (value.length > 0 && value.charCodeAt(0) === 61) {
|
|
65
|
+
setFormula(c, value.slice(1));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (ERROR_CODES.has(value)) {
|
|
69
|
+
c.value = {
|
|
70
|
+
kind: "error",
|
|
71
|
+
code: value
|
|
72
|
+
};
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
c.value = value;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
c.value = value;
|
|
79
|
+
}
|
|
80
|
+
/** Plain `=A1+B1` style formula. Cached value is optional but recommended for round-trip. */
|
|
81
|
+
function setFormula(c, formula, opts) {
|
|
82
|
+
c.value = {
|
|
83
|
+
kind: "formula",
|
|
84
|
+
t: "normal",
|
|
85
|
+
formula,
|
|
86
|
+
...opts?.cachedValue !== void 0 ? { cachedValue: opts.cachedValue } : {}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Array (CSE) formula spanning a `ref` range. */
|
|
90
|
+
function setArrayFormula(c, ref, formula, opts) {
|
|
91
|
+
c.value = {
|
|
92
|
+
kind: "formula",
|
|
93
|
+
t: "array",
|
|
94
|
+
formula,
|
|
95
|
+
ref,
|
|
96
|
+
...opts?.cachedValue !== void 0 ? { cachedValue: opts.cachedValue } : {}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Shared formula. The first cell in the group carries the formula text + ref;
|
|
101
|
+
* subsequent cells with the same `si` carry only the index and Excel
|
|
102
|
+
* reconstructs the formula via reference shifting.
|
|
103
|
+
*/
|
|
104
|
+
function setSharedFormula(c, si, formula, ref, opts) {
|
|
105
|
+
if (!Number.isInteger(si) || si < 0) throw new OpenXmlSchemaError(`setSharedFormula: si must be a non-negative integer; got ${si}`);
|
|
106
|
+
c.value = {
|
|
107
|
+
kind: "formula",
|
|
108
|
+
t: "shared",
|
|
109
|
+
formula: formula ?? "",
|
|
110
|
+
si,
|
|
111
|
+
...ref !== void 0 ? { ref } : {},
|
|
112
|
+
...opts?.cachedValue !== void 0 ? { cachedValue: opts.cachedValue } : {}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Set a data-table formula on a cell. Preserves all the dt-specific attributes
|
|
117
|
+
* so the writer can re-emit `<f t="dataTable" r1="..." />` verbatim and Excel
|
|
118
|
+
* keeps treating the cell as a Data Table cell.
|
|
119
|
+
*/
|
|
120
|
+
function setDataTableFormula(c, formula, opts) {
|
|
121
|
+
c.value = {
|
|
122
|
+
kind: "formula",
|
|
123
|
+
t: "dataTable",
|
|
124
|
+
formula,
|
|
125
|
+
ref: opts.ref,
|
|
126
|
+
...opts.r1 !== void 0 ? { r1: opts.r1 } : {},
|
|
127
|
+
...opts.r2 !== void 0 ? { r2: opts.r2 } : {},
|
|
128
|
+
...opts.dt2D !== void 0 ? { dt2D: opts.dt2D } : {},
|
|
129
|
+
...opts.dtr !== void 0 ? { dtr: opts.dtr } : {},
|
|
130
|
+
...opts.del1 !== void 0 ? { del1: opts.del1 } : {},
|
|
131
|
+
...opts.del2 !== void 0 ? { del2: opts.del2 } : {},
|
|
132
|
+
...opts.aca !== void 0 ? { aca: opts.aca } : {},
|
|
133
|
+
...opts.ca !== void 0 ? { ca: opts.ca } : {},
|
|
134
|
+
...opts.cachedValue !== void 0 ? { cachedValue: opts.cachedValue } : {}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** Build a `{ kind: 'error', code }` cell value. */
|
|
138
|
+
function makeErrorValue(code) {
|
|
139
|
+
if (!ERROR_CODES.has(code)) throw new OpenXmlSchemaError(`makeErrorValue: unknown error code "${code}"`);
|
|
140
|
+
return Object.freeze({
|
|
141
|
+
kind: "error",
|
|
142
|
+
code
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** Build a `{ kind: 'duration', ms }` cell value. */
|
|
146
|
+
function makeDurationValue(ms) {
|
|
147
|
+
if (!Number.isFinite(ms)) throw new OpenXmlSchemaError(`makeDurationValue: ms "${ms}" is not finite`);
|
|
148
|
+
return Object.freeze({
|
|
149
|
+
kind: "duration",
|
|
150
|
+
ms
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/** True iff `c.value` is the formula variant. */
|
|
154
|
+
function isFormulaCell(c) {
|
|
155
|
+
return isFormulaValue(c.value);
|
|
156
|
+
}
|
|
157
|
+
/** True iff `c.value` is the rich-text variant. */
|
|
158
|
+
function isRichTextCell(c) {
|
|
159
|
+
return isRichTextValue(c.value);
|
|
160
|
+
}
|
|
161
|
+
/** Returns true iff the cell has no content. */
|
|
162
|
+
function isEmptyCell(c) {
|
|
163
|
+
return c.value === null;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Type guard for `MergedCell` — true iff the cell is a placeholder for a
|
|
167
|
+
* merged-range covered cell (the top-left of a merged range holds the value;
|
|
168
|
+
* the rest are `MergedCell`). Use this to filter merge-placeholders out of
|
|
169
|
+
* value-walking loops.
|
|
170
|
+
*/
|
|
171
|
+
function isMergedCell(c) {
|
|
172
|
+
return c.merged === true;
|
|
173
|
+
}
|
|
174
|
+
/** Returns true iff the cell holds an Excel error value (`#REF!`, `#NAME?`, …). */
|
|
175
|
+
function isErrorCell(c) {
|
|
176
|
+
return isErrorValue(c.value);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get the formula text from a formula-bearing cell, or `undefined` for
|
|
180
|
+
* non-formula cells. Equivalent to: isFormulaValue(c.value) ? c.value.formula :
|
|
181
|
+
* undefined but spares callers the type-narrow + member access.
|
|
182
|
+
*/
|
|
183
|
+
function getFormulaText(c) {
|
|
184
|
+
return isFormulaValue(c.value) ? c.value.formula : void 0;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Get the cached value Excel last computed for a formula cell, or `undefined`
|
|
188
|
+
* for non-formula / uncached cells. Useful for `data_only` read paths that want
|
|
189
|
+
* the displayed result without re-evaluating.
|
|
190
|
+
*/
|
|
191
|
+
function getCachedFormulaValue(c) {
|
|
192
|
+
return isFormulaValue(c.value) ? c.value.cachedValue : void 0;
|
|
193
|
+
}
|
|
194
|
+
/** True iff `v` is the formula variant. */
|
|
195
|
+
function isFormulaValue(v) {
|
|
196
|
+
return typeof v === "object" && v !== null && v.kind === "formula";
|
|
197
|
+
}
|
|
198
|
+
/** True iff `v` is the rich-text variant. */
|
|
199
|
+
function isRichTextValue(v) {
|
|
200
|
+
return typeof v === "object" && v !== null && v.kind === "rich-text";
|
|
201
|
+
}
|
|
202
|
+
/** True iff `v` is the error variant. */
|
|
203
|
+
function isErrorValue(v) {
|
|
204
|
+
return typeof v === "object" && v !== null && v.kind === "error";
|
|
205
|
+
}
|
|
206
|
+
/** True iff `v` is the duration variant. */
|
|
207
|
+
function isDurationValue(v) {
|
|
208
|
+
return typeof v === "object" && v !== null && v.kind === "duration";
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Coerce a CellValue to its plain-string display form. Numbers / booleans
|
|
212
|
+
* convert via `String`; rich text concatenates run text; formulas yield the
|
|
213
|
+
* cached value (or empty string when uncached); errors yield their Excel token;
|
|
214
|
+
* durations yield `"<ms> ms"` with no formatting; Dates yield
|
|
215
|
+
* `Date.toISOString()`; `null` yields `""`.
|
|
216
|
+
*
|
|
217
|
+
* Pass `opts.dateFormat` to override the Date renderer (e.g. a locale-specific
|
|
218
|
+
* format) and `opts.emptyText` to substitute a different placeholder for
|
|
219
|
+
* `null` cells.
|
|
220
|
+
*/
|
|
221
|
+
function cellValueAsString(v, opts) {
|
|
222
|
+
const emptyText = opts?.emptyText ?? "";
|
|
223
|
+
if (v === null) return emptyText;
|
|
224
|
+
if (typeof v === "string") return v;
|
|
225
|
+
if (typeof v === "number" || typeof v === "boolean") return String(v);
|
|
226
|
+
if (v instanceof Date) return opts?.dateFormat ? opts.dateFormat(v) : v.toISOString();
|
|
227
|
+
if (isRichTextValue(v)) return richTextToString(v.runs);
|
|
228
|
+
if (isFormulaValue(v)) {
|
|
229
|
+
if (v.cachedValue === void 0) return "";
|
|
230
|
+
return typeof v.cachedValue === "string" ? v.cachedValue : String(v.cachedValue);
|
|
231
|
+
}
|
|
232
|
+
if (isErrorValue(v)) return v.code;
|
|
233
|
+
if (isDurationValue(v)) return `${v.ms} ms`;
|
|
234
|
+
return "";
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Coerce a CellValue to `boolean | undefined`. Booleans pass through; `'TRUE'`
|
|
238
|
+
* / `'true'` and `'FALSE'` / `'false'` (case-insensitive) parse to true /
|
|
239
|
+
* false; numbers yield `false` for 0 and `true` for any other finite value
|
|
240
|
+
* (matching Excel's truthy-number coercion); formula cells return their cached
|
|
241
|
+
* boolean if any. Everything else (null, Date, error, duration, rich-text,
|
|
242
|
+
* non-bool strings) yields `undefined`.
|
|
243
|
+
*/
|
|
244
|
+
function cellValueAsBoolean(v) {
|
|
245
|
+
if (typeof v === "boolean") return v;
|
|
246
|
+
if (typeof v === "number") {
|
|
247
|
+
if (!Number.isFinite(v)) return void 0;
|
|
248
|
+
return v !== 0;
|
|
249
|
+
}
|
|
250
|
+
if (typeof v === "string") {
|
|
251
|
+
const lc = v.toLowerCase();
|
|
252
|
+
if (lc === "true") return true;
|
|
253
|
+
if (lc === "false") return false;
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (isFormulaValue(v) && typeof v.cachedValue === "boolean") return v.cachedValue;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Coerce a CellValue to a `Date` when one is meaningful. Pass-through for
|
|
260
|
+
* `Date`-typed values; ISO-8601 strings (anything `new Date(s)` parses to a
|
|
261
|
+
* finite time) round-trip; durations are interpreted as `new Date(ms)`.
|
|
262
|
+
* Numbers, booleans, formulas, errors, rich text, and null all return
|
|
263
|
+
* `undefined` — this helper does **not** apply the Excel-serial-to-Date
|
|
264
|
+
* conversion (use `excelToDate` for that).
|
|
265
|
+
*/
|
|
266
|
+
function cellValueAsDate(v) {
|
|
267
|
+
if (v instanceof Date) return v;
|
|
268
|
+
if (typeof v === "string") {
|
|
269
|
+
if (v === "") return void 0;
|
|
270
|
+
const t = Date.parse(v);
|
|
271
|
+
if (!Number.isFinite(t)) return void 0;
|
|
272
|
+
return new Date(t);
|
|
273
|
+
}
|
|
274
|
+
if (isDurationValue(v)) return new Date(v.ms);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Coerce a CellValue to a number when one is meaningful. Booleans yield 0/1;
|
|
278
|
+
* numeric strings parse via `Number(s)`; rich-text concats then parses;
|
|
279
|
+
* formulas with a numeric cached value pass through. Returns `undefined` when
|
|
280
|
+
* there's no sensible numeric reading (text strings, errors, dates, durations,
|
|
281
|
+
* null, empty).
|
|
282
|
+
*/
|
|
283
|
+
function cellValueAsNumber(v) {
|
|
284
|
+
if (v === null) return void 0;
|
|
285
|
+
if (typeof v === "number") return Number.isFinite(v) ? v : void 0;
|
|
286
|
+
if (typeof v === "boolean") return v ? 1 : 0;
|
|
287
|
+
if (typeof v === "string") {
|
|
288
|
+
if (v === "") return void 0;
|
|
289
|
+
const n = Number(v);
|
|
290
|
+
return Number.isFinite(n) ? n : void 0;
|
|
291
|
+
}
|
|
292
|
+
if (isFormulaValue(v) && typeof v.cachedValue === "number") return v.cachedValue;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Map a CellValue to the most natural JS primitive for display / export.
|
|
296
|
+
* Unlike `cellValueAsString`/`cellValueAsNumber`/etc., which each force a
|
|
297
|
+
* single target type and return `undefined` when the value can't be coerced,
|
|
298
|
+
* this returns whatever primitive best represents the union variant:
|
|
299
|
+
*
|
|
300
|
+
* - `null` → `null`
|
|
301
|
+
* - `string` / `number` / `boolean` / `Date` → passthrough
|
|
302
|
+
* - rich text → joined run text (`string`)
|
|
303
|
+
* - formula → recursive on `cachedValue` (`null` when uncached)
|
|
304
|
+
* - error → error code (`string`)
|
|
305
|
+
* - duration → `ms` (`number`)
|
|
306
|
+
*/
|
|
307
|
+
function cellValueAsPrimitive(v) {
|
|
308
|
+
if (v === null) return null;
|
|
309
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean") return v;
|
|
310
|
+
if (v instanceof Date) return v;
|
|
311
|
+
if (isRichTextValue(v)) return richTextToString(v.runs);
|
|
312
|
+
if (isFormulaValue(v)) return v.cachedValue === void 0 ? null : v.cachedValue;
|
|
313
|
+
if (isErrorValue(v)) return v.code;
|
|
314
|
+
if (isDurationValue(v)) return v.ms;
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
export { setCellValue as C, makeRichText as D, setSharedFormula as E, makeTextRun as O, setArrayFormula as S, setFormula as T, isRichTextCell as _, cellValueAsPrimitive as a, makeDurationValue as b, getCoordinate as c, isEmptyCell as d, isErrorCell as f, isMergedCell as g, isFormulaValue as h, cellValueAsNumber as i, richTextToString as k, getFormulaText as l, isFormulaCell as m, cellValueAsBoolean as n, cellValueAsString as o, isErrorValue as p, cellValueAsDate as r, getCachedFormulaValue as s, bindValue as t, isDurationValue as u, isRichTextValue as v, setDataTableFormula as w, makeErrorValue as x, makeCell as y };
|
|
319
|
+
|
|
320
|
+
//# sourceMappingURL=cell-D9CaNKnU.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-D9CaNKnU.mjs","names":[],"sources":["../src/cell/rich-text.ts","../src/cell/cell.ts"],"sourcesContent":["// Inline rich-text runs.\n//\n// A rich-text cell value is `{ kind: 'rich-text', runs }`. Each run is\n// a string segment with an optional InlineFont describing the in-line\n// formatting (font name, size, bold / italic / underline, colour, …).\n// Run-level fields use OOXML's short attribute names (`sz`, `b`, `i`,\n// `u`) so the writer can splice them into `<rPr>` directly without\n// renaming.\n\nimport type { Color } from '../styles/colors';\nimport { OpenXmlSchemaError } from '../utils/exceptions';\n\n/** Underline styles per openpyxl's cell-level NestedNoneSet. */\nexport type InlineUnderline = 'single' | 'double' | 'singleAccounting' | 'doubleAccounting';\n\nexport type InlineVertAlign = 'baseline' | 'superscript' | 'subscript';\n\nexport interface InlineFont {\n readonly name?: string;\n readonly sz?: number;\n readonly b?: boolean;\n readonly i?: boolean;\n readonly u?: InlineUnderline;\n readonly strike?: boolean;\n readonly outline?: boolean;\n readonly shadow?: boolean;\n readonly condense?: boolean;\n readonly extend?: boolean;\n readonly vertAlign?: InlineVertAlign;\n readonly color?: Color;\n readonly family?: number;\n readonly charset?: number;\n readonly scheme?: 'major' | 'minor';\n}\n\nexport interface TextRun {\n readonly text: string;\n readonly font?: InlineFont;\n}\n\n/** A frozen array of TextRuns. The shared cell value shape under `kind: 'rich-text'`. */\nexport type RichText = ReadonlyArray<TextRun>;\n\nexport function makeTextRun(text: string, font?: InlineFont): TextRun {\n if (typeof text !== 'string') {\n throw new OpenXmlSchemaError('makeTextRun: text must be a string');\n }\n return Object.freeze(font !== undefined ? { text, font } : { text });\n}\n\nexport function makeRichText(runs: ReadonlyArray<TextRun | { text: string; font?: InlineFont }>): RichText {\n const out = runs.map((r) => (Object.isFrozen(r) ? (r as TextRun) : makeTextRun(r.text, r.font)));\n return Object.freeze(out);\n}\n\n/**\n * Concatenate the plain-text content of a rich-text value (rich-text\n * read paths often want the raw text without formatting).\n */\nexport function richTextToString(rt: RichText): string {\n let out = '';\n for (const r of rt) out += r.text;\n return out;\n}\n","// Cell value model. Mirrors openpyxl/openpyxl/cell/cell.py.\n//\n// A Cell is a plain mutable object: the worksheet stores millions of these, so\n// per-cell freezes / spreads aren't viable on the hot path. The public surface\n// stays small — makeCell + getCoordinate + targeted setters — and uses\n// discriminated unions for the special CellValue shapes (formula, rich text,\n// duration, error).\n\nimport { columnLetterFromIndex, MAX_COL, MAX_ROW } from '../utils/coordinate';\nimport { OpenXmlSchemaError } from '../utils/exceptions';\nimport { ERROR_CODES } from '../utils/inference';\nimport { type RichText, richTextToString } from './rich-text';\n\n/** Excel error tokens. */\nexport type ExcelErrorCode = '#NULL!' | '#DIV/0!' | '#VALUE!' | '#REF!' | '#NAME?' | '#NUM!' | '#N/A' | '#GETTING_DATA';\n\n/** Formula sub-kind — drives the OOXML `<f t=\"…\">` attribute. */\nexport type FormulaKind = 'normal' | 'array' | 'shared' | 'dataTable';\n\nexport interface FormulaValue {\n readonly kind: 'formula';\n readonly formula: string;\n readonly t: FormulaKind;\n /** Cached value Excel last computed for the cell, used when `data_only` reads it back. */\n readonly cachedValue?: number | string | boolean;\n /** Range string (`\"A1:A10\"`) for array / shared / dataTable formulas. */\n readonly ref?: string;\n /** Shared-formula index. */\n readonly si?: number;\n /** Data-table specific fields (mirrors openpyxl DataTableFormula). */\n readonly r1?: string;\n readonly r2?: string;\n readonly dt2D?: boolean;\n readonly dtr?: boolean;\n readonly del1?: boolean;\n readonly del2?: boolean;\n readonly aca?: boolean;\n readonly ca?: boolean;\n}\n\nexport type CellValue =\n | number\n | string\n | boolean\n | Date\n | { kind: 'duration'; ms: number }\n | { kind: 'error'; code: ExcelErrorCode }\n | { kind: 'rich-text'; runs: RichText }\n | FormulaValue\n | null;\n\nexport interface Cell {\n /** 1-based row index. */\n row: number;\n /** 1-based column index. */\n col: number;\n /** Effective cell value. `null` represents an empty cell. */\n value: CellValue;\n /** Index into Workbook.styles.cellXfs. 0 = default. */\n styleId: number;\n /** Optional reference to a Hyperlink registered on the worksheet. */\n hyperlinkId?: number;\n /** Optional reference to a Comment registered on the worksheet. */\n commentId?: number;\n}\n\n/** Marker subtype for the placeholder cells inside a merged range (top-left holds the value). */\nexport interface MergedCell extends Cell {\n merged: true;\n}\n\nconst validateCoord = (row: number, col: number): void => {\n if (!Number.isInteger(row) || row < 1 || row > MAX_ROW) {\n throw new OpenXmlSchemaError(`Cell row ${row} out of range [1, ${MAX_ROW}]`);\n }\n if (!Number.isInteger(col) || col < 1 || col > MAX_COL) {\n throw new OpenXmlSchemaError(`Cell col ${col} out of range [1, ${MAX_COL}]`);\n }\n};\n\n/** Build a fresh Cell. Validates coordinates against the OOXML grid bounds. */\nexport function makeCell(row: number, col: number, value: CellValue = null, styleId = 0): Cell {\n validateCoord(row, col);\n return { row, col, value, styleId };\n}\n\n/** Format a Cell's coordinate as the canonical \"A1\" string. */\nexport function getCoordinate(c: Cell): string {\n return `${columnLetterFromIndex(c.col)}${c.row}`;\n}\n\n/**\n * Direct value setter. No type inference, no validation beyond the union — the\n * caller is in charge. Use {@link bindValue} for the \"do what I mean\" path.\n */\nexport function setCellValue(c: Cell, value: CellValue): void {\n c.value = value;\n}\n\n/**\n * \"Smart\" setter: infers the cell value from a JS runtime value.\n * - `string` starting with `=` → formula\n * - `string` matching an Excel error token → error variant\n * - other primitives / Date / null pass through verbatim\n *\n * Intentionally not the default — explicit is clearer for typed code, and\n * inferring on every write costs measurable time on the worksheet write hot\n * path.\n */\nexport function bindValue(c: Cell, value: number | string | boolean | Date | null): void {\n if (typeof value === 'string') {\n if (value.length > 0 && value.charCodeAt(0) === 61 /* '=' */) {\n setFormula(c, value.slice(1));\n return;\n }\n if (ERROR_CODES.has(value)) {\n c.value = { kind: 'error', code: value as ExcelErrorCode };\n return;\n }\n c.value = value;\n return;\n }\n c.value = value;\n}\n\n// ---- formula setters -------------------------------------------------------\n\n/** Plain `=A1+B1` style formula. Cached value is optional but recommended for round-trip. */\nexport function setFormula(c: Cell, formula: string, opts?: { cachedValue?: FormulaValue['cachedValue'] }): void {\n const v: FormulaValue = {\n kind: 'formula',\n t: 'normal',\n formula,\n ...(opts?.cachedValue !== undefined ? { cachedValue: opts.cachedValue } : {}),\n };\n c.value = v;\n}\n\n/** Array (CSE) formula spanning a `ref` range. */\nexport function setArrayFormula(\n c: Cell,\n ref: string,\n formula: string,\n opts?: { cachedValue?: FormulaValue['cachedValue'] },\n): void {\n const v: FormulaValue = {\n kind: 'formula',\n t: 'array',\n formula,\n ref,\n ...(opts?.cachedValue !== undefined ? { cachedValue: opts.cachedValue } : {}),\n };\n c.value = v;\n}\n\n/**\n * Shared formula. The first cell in the group carries the formula text + ref;\n * subsequent cells with the same `si` carry only the index and Excel\n * reconstructs the formula via reference shifting.\n */\nexport function setSharedFormula(\n c: Cell,\n si: number,\n formula?: string,\n ref?: string,\n opts?: { cachedValue?: FormulaValue['cachedValue'] },\n): void {\n if (!Number.isInteger(si) || si < 0) {\n throw new OpenXmlSchemaError(`setSharedFormula: si must be a non-negative integer; got ${si}`);\n }\n const v: FormulaValue = {\n kind: 'formula',\n t: 'shared',\n formula: formula ?? '',\n si,\n ...(ref !== undefined ? { ref } : {}),\n ...(opts?.cachedValue !== undefined ? { cachedValue: opts.cachedValue } : {}),\n };\n c.value = v;\n}\n\n/**\n * Excel data-table formula (`<f t=\"dataTable\">`). These appear as the \"What-if\n * Analysis → Data Table\" feature output: a 1- or 2-variable sensitivity grid\n * where the formula references one or two input cells. The wire format mirrors\n * openpyxl's `DataTableFormula`:\n *\n * - `ref` — inclusive cell range the formula spans.\n * - `r1`, `r2`— input cell coordinates (\"$A$1\" etc.).\n * - `dt2D` — true for two-variable tables (uses both r1 and r2).\n * - `dtr` — row-direction flag (true) vs column-direction (false).\n * - `del1`/`del2` — Excel marks one of these true when the\n * corresponding input cell has been deleted; the formula keeps round-tripping\n * so Excel can show the warning state.\n * - `aca`/`ca` — alwaysCalculate / calculate flags.\n */\nexport interface DataTableFormulaOpts {\n ref: string;\n r1?: string;\n r2?: string;\n dt2D?: boolean;\n dtr?: boolean;\n del1?: boolean;\n del2?: boolean;\n aca?: boolean;\n ca?: boolean;\n cachedValue?: FormulaValue['cachedValue'];\n}\n\n/**\n * Set a data-table formula on a cell. Preserves all the dt-specific attributes\n * so the writer can re-emit `<f t=\"dataTable\" r1=\"...\" />` verbatim and Excel\n * keeps treating the cell as a Data Table cell.\n */\nexport function setDataTableFormula(c: Cell, formula: string, opts: DataTableFormulaOpts): void {\n const v: FormulaValue = {\n kind: 'formula',\n t: 'dataTable',\n formula,\n ref: opts.ref,\n ...(opts.r1 !== undefined ? { r1: opts.r1 } : {}),\n ...(opts.r2 !== undefined ? { r2: opts.r2 } : {}),\n ...(opts.dt2D !== undefined ? { dt2D: opts.dt2D } : {}),\n ...(opts.dtr !== undefined ? { dtr: opts.dtr } : {}),\n ...(opts.del1 !== undefined ? { del1: opts.del1 } : {}),\n ...(opts.del2 !== undefined ? { del2: opts.del2 } : {}),\n ...(opts.aca !== undefined ? { aca: opts.aca } : {}),\n ...(opts.ca !== undefined ? { ca: opts.ca } : {}),\n ...(opts.cachedValue !== undefined ? { cachedValue: opts.cachedValue } : {}),\n };\n c.value = v;\n}\n\n// ---- value-shape helpers ---------------------------------------------------\n\n/** Build a `{ kind: 'error', code }` cell value. */\nexport function makeErrorValue(code: ExcelErrorCode): { kind: 'error'; code: ExcelErrorCode } {\n if (!ERROR_CODES.has(code)) {\n throw new OpenXmlSchemaError(`makeErrorValue: unknown error code \"${code}\"`);\n }\n return Object.freeze({ kind: 'error', code });\n}\n\n/** Build a `{ kind: 'duration', ms }` cell value. */\nexport function makeDurationValue(ms: number): { kind: 'duration'; ms: number } {\n if (!Number.isFinite(ms)) {\n throw new OpenXmlSchemaError(`makeDurationValue: ms \"${ms}\" is not finite`);\n }\n return Object.freeze({ kind: 'duration', ms });\n}\n\n/** True iff `c.value` is the formula variant. */\nexport function isFormulaCell(c: Cell): boolean {\n return isFormulaValue(c.value);\n}\n\n/** True iff `c.value` is the rich-text variant. */\nexport function isRichTextCell(c: Cell): boolean {\n return isRichTextValue(c.value);\n}\n\n/** Returns true iff the cell has no content. */\nexport function isEmptyCell(c: Cell): boolean {\n return c.value === null;\n}\n\n/**\n * Type guard for `MergedCell` — true iff the cell is a placeholder for a\n * merged-range covered cell (the top-left of a merged range holds the value;\n * the rest are `MergedCell`). Use this to filter merge-placeholders out of\n * value-walking loops.\n */\nexport function isMergedCell(c: Cell): c is MergedCell {\n return (c as MergedCell).merged === true;\n}\n\n/** Returns true iff the cell holds an Excel error value (`#REF!`, `#NAME?`, …). */\nexport function isErrorCell(c: Cell): boolean {\n return isErrorValue(c.value);\n}\n\n/**\n * Get the formula text from a formula-bearing cell, or `undefined` for\n * non-formula cells. Equivalent to: isFormulaValue(c.value) ? c.value.formula :\n * undefined but spares callers the type-narrow + member access.\n */\nexport function getFormulaText(c: Cell): string | undefined {\n return isFormulaValue(c.value) ? c.value.formula : undefined;\n}\n\n/**\n * Get the cached value Excel last computed for a formula cell, or `undefined`\n * for non-formula / uncached cells. Useful for `data_only` read paths that want\n * the displayed result without re-evaluating.\n */\nexport function getCachedFormulaValue(c: Cell): number | string | boolean | undefined {\n return isFormulaValue(c.value) ? c.value.cachedValue : undefined;\n}\n\n// ---- value-level type guards + coercion ----------------------------------\n\n/** True iff `v` is the formula variant. */\nexport function isFormulaValue(v: CellValue): v is FormulaValue {\n return typeof v === 'object' && v !== null && (v as { kind?: string }).kind === 'formula';\n}\n\n/** True iff `v` is the rich-text variant. */\nexport function isRichTextValue(v: CellValue): v is { kind: 'rich-text'; runs: RichText } {\n return typeof v === 'object' && v !== null && (v as { kind?: string }).kind === 'rich-text';\n}\n\n/** True iff `v` is the error variant. */\nexport function isErrorValue(v: CellValue): v is { kind: 'error'; code: ExcelErrorCode } {\n return typeof v === 'object' && v !== null && (v as { kind?: string }).kind === 'error';\n}\n\n/** True iff `v` is the duration variant. */\nexport function isDurationValue(v: CellValue): v is { kind: 'duration'; ms: number } {\n return typeof v === 'object' && v !== null && (v as { kind?: string }).kind === 'duration';\n}\n\nexport interface CellValueAsStringOptions {\n /** Renderer for `Date` cells. Defaults to `d => d.toISOString()`. */\n dateFormat?: (value: Date) => string;\n /** Replacement for the `null` cell value. Defaults to `''`. */\n emptyText?: string;\n}\n\n/**\n * Coerce a CellValue to its plain-string display form. Numbers / booleans\n * convert via `String`; rich text concatenates run text; formulas yield the\n * cached value (or empty string when uncached); errors yield their Excel token;\n * durations yield `\"<ms> ms\"` with no formatting; Dates yield\n * `Date.toISOString()`; `null` yields `\"\"`.\n *\n * Pass `opts.dateFormat` to override the Date renderer (e.g. a locale-specific\n * format) and `opts.emptyText` to substitute a different placeholder for\n * `null` cells.\n */\nexport function cellValueAsString(v: CellValue, opts?: CellValueAsStringOptions): string {\n const emptyText = opts?.emptyText ?? '';\n if (v === null) return emptyText;\n if (typeof v === 'string') return v;\n if (typeof v === 'number' || typeof v === 'boolean') return String(v);\n if (v instanceof Date) return opts?.dateFormat ? opts.dateFormat(v) : v.toISOString();\n if (isRichTextValue(v)) return richTextToString(v.runs);\n if (isFormulaValue(v)) {\n if (v.cachedValue === undefined) return '';\n return typeof v.cachedValue === 'string' ? v.cachedValue : String(v.cachedValue);\n }\n if (isErrorValue(v)) return v.code;\n if (isDurationValue(v)) return `${v.ms} ms`;\n return '';\n}\n\n/**\n * Coerce a CellValue to `boolean | undefined`. Booleans pass through; `'TRUE'`\n * / `'true'` and `'FALSE'` / `'false'` (case-insensitive) parse to true /\n * false; numbers yield `false` for 0 and `true` for any other finite value\n * (matching Excel's truthy-number coercion); formula cells return their cached\n * boolean if any. Everything else (null, Date, error, duration, rich-text,\n * non-bool strings) yields `undefined`.\n */\nexport function cellValueAsBoolean(v: CellValue): boolean | undefined {\n if (typeof v === 'boolean') return v;\n if (typeof v === 'number') {\n if (!Number.isFinite(v)) return undefined;\n return v !== 0;\n }\n if (typeof v === 'string') {\n const lc = v.toLowerCase();\n if (lc === 'true') return true;\n if (lc === 'false') return false;\n return undefined;\n }\n if (isFormulaValue(v) && typeof v.cachedValue === 'boolean') return v.cachedValue;\n return undefined;\n}\n\n/**\n * Coerce a CellValue to a `Date` when one is meaningful. Pass-through for\n * `Date`-typed values; ISO-8601 strings (anything `new Date(s)` parses to a\n * finite time) round-trip; durations are interpreted as `new Date(ms)`.\n * Numbers, booleans, formulas, errors, rich text, and null all return\n * `undefined` — this helper does **not** apply the Excel-serial-to-Date\n * conversion (use `excelToDate` for that).\n */\nexport function cellValueAsDate(v: CellValue): Date | undefined {\n if (v instanceof Date) return v;\n if (typeof v === 'string') {\n if (v === '') return undefined;\n const t = Date.parse(v);\n if (!Number.isFinite(t)) return undefined;\n return new Date(t);\n }\n if (isDurationValue(v)) return new Date(v.ms);\n return undefined;\n}\n\n/**\n * Coerce a CellValue to a number when one is meaningful. Booleans yield 0/1;\n * numeric strings parse via `Number(s)`; rich-text concats then parses;\n * formulas with a numeric cached value pass through. Returns `undefined` when\n * there's no sensible numeric reading (text strings, errors, dates, durations,\n * null, empty).\n */\nexport function cellValueAsNumber(v: CellValue): number | undefined {\n if (v === null) return undefined;\n if (typeof v === 'number') return Number.isFinite(v) ? v : undefined;\n if (typeof v === 'boolean') return v ? 1 : 0;\n if (typeof v === 'string') {\n if (v === '') return undefined;\n const n = Number(v);\n return Number.isFinite(n) ? n : undefined;\n }\n if (isFormulaValue(v) && typeof v.cachedValue === 'number') return v.cachedValue;\n return undefined;\n}\n\n/**\n * Map a CellValue to the most natural JS primitive for display / export.\n * Unlike `cellValueAsString`/`cellValueAsNumber`/etc., which each force a\n * single target type and return `undefined` when the value can't be coerced,\n * this returns whatever primitive best represents the union variant:\n *\n * - `null` → `null`\n * - `string` / `number` / `boolean` / `Date` → passthrough\n * - rich text → joined run text (`string`)\n * - formula → recursive on `cachedValue` (`null` when uncached)\n * - error → error code (`string`)\n * - duration → `ms` (`number`)\n */\nexport function cellValueAsPrimitive(v: CellValue): string | number | boolean | Date | null {\n if (v === null) return null;\n if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean') return v;\n if (v instanceof Date) return v;\n if (isRichTextValue(v)) return richTextToString(v.runs);\n if (isFormulaValue(v)) {\n return v.cachedValue === undefined ? null : v.cachedValue;\n }\n if (isErrorValue(v)) return v.code;\n if (isDurationValue(v)) return v.ms;\n return null;\n}\n"],"mappings":";;;;AA2CA,SAAgB,YAAY,MAAc,MAA4B;CACpE,IAAI,OAAO,SAAS,UAClB,MAAM,IAAI,mBAAmB,oCAAoC;CAEnE,OAAO,OAAO,OAAO,SAAS,KAAA,IAAY;EAAE;EAAM;CAAK,IAAI,EAAE,KAAK,CAAC;AACrE;AAEA,SAAgB,aAAa,MAA8E;CACzG,MAAM,MAAM,KAAK,KAAK,MAAO,OAAO,SAAS,CAAC,IAAK,IAAgB,YAAY,EAAE,MAAM,EAAE,IAAI,CA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