reamkit 1.15.0 → 1.15.2
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/dist/esm/core/arc-to-bezier.d.ts +23 -0
- package/dist/esm/core/arc-to-bezier.js +23 -0
- package/dist/esm/core/bidi/algorithm.d.ts +26 -0
- package/dist/esm/core/bidi/algorithm.js +21 -0
- package/dist/esm/core/bidi/char-types.d.ts +17 -0
- package/dist/esm/core/bidi/char-types.js +10 -0
- package/dist/esm/core/bidi/index.d.ts +42 -0
- package/dist/esm/core/bidi/index.js +27 -0
- package/dist/esm/core/bidi/segments.d.ts +22 -0
- package/dist/esm/core/bidi/segments.js +14 -0
- package/dist/esm/core/bytes.d.ts +9 -0
- package/dist/esm/core/bytes.js +9 -0
- package/dist/esm/core/converter/facade.d.ts +38 -1
- package/dist/esm/core/converter/facade.js +25 -0
- package/dist/esm/core/converter/project.d.ts +12 -0
- package/dist/esm/core/converter/project.js +11 -0
- package/dist/esm/core/converter/ream.d.ts +107 -0
- package/dist/esm/core/converter/ream.js +76 -0
- package/dist/esm/core/crypto/asn1.d.ts +77 -0
- package/dist/esm/core/crypto/asn1.js +65 -0
- package/dist/esm/core/crypto/cms.d.ts +25 -0
- package/dist/esm/core/crypto/cms.js +8 -0
- package/dist/esm/core/document-model/index.d.ts +7 -0
- package/dist/esm/core/document-model/types.d.ts +328 -0
- package/dist/esm/core/drawingml/chart-geometry.d.ts +125 -0
- package/dist/esm/core/drawingml/chart-geometry.js +96 -0
- package/dist/esm/core/drawingml/chart-parser.d.ts +34 -0
- package/dist/esm/core/drawingml/chart-parser.js +34 -0
- package/dist/esm/core/drawingml/chart-serializer.d.ts +12 -0
- package/dist/esm/core/drawingml/chart-serializer.js +12 -0
- package/dist/esm/core/drawingml/colors.d.ts +53 -0
- package/dist/esm/core/drawingml/colors.js +41 -0
- package/dist/esm/core/drawingml/preset-geometry.d.ts +30 -0
- package/dist/esm/core/drawingml/preset-geometry.js +30 -0
- package/dist/esm/core/drawingml/shape-render.d.ts +54 -0
- package/dist/esm/core/drawingml/shape-render.js +54 -0
- package/dist/esm/core/drawingml/sparkline-geometry.d.ts +15 -0
- package/dist/esm/core/drawingml/sparkline-geometry.js +13 -0
- package/dist/esm/core/drawingml/theme-parser.d.ts +11 -0
- package/dist/esm/core/drawingml/theme-parser.js +11 -0
- package/dist/esm/core/font/arabic-joining.d.ts +21 -0
- package/dist/esm/core/font/arabic-joining.js +16 -0
- package/dist/esm/core/font/binary-reader.d.ts +17 -0
- package/dist/esm/core/font/binary-reader.js +17 -0
- package/dist/esm/core/font/font-registry.d.ts +37 -0
- package/dist/esm/core/font/font-registry.js +31 -0
- package/dist/esm/core/font/measure.d.ts +20 -0
- package/dist/esm/core/font/measure.js +11 -0
- package/dist/esm/core/font/opentype-layout.d.ts +49 -0
- package/dist/esm/core/font/opentype-layout.js +37 -0
- package/dist/esm/core/font/ttf-parser.d.ts +32 -0
- package/dist/esm/core/font/ttf-parser.js +7 -0
- package/dist/esm/core/font/ttf-subset.d.ts +21 -0
- package/dist/esm/core/font/ttf-subset.js +21 -0
- package/dist/esm/core/fonts/provider.d.ts +8 -1
- package/dist/esm/core/fonts/provider.js +1 -0
- package/dist/esm/core/fonts/remote-fonts.d.ts +22 -0
- package/dist/esm/core/fonts/remote-fonts.js +16 -0
- package/dist/esm/core/hyphenation/index.d.ts +25 -0
- package/dist/esm/core/hyphenation/index.js +17 -0
- package/dist/esm/core/hyphenation/liang.d.ts +27 -0
- package/dist/esm/core/hyphenation/liang.js +14 -0
- package/dist/esm/core/images.d.ts +32 -0
- package/dist/esm/core/images.js +12 -0
- package/dist/esm/core/ir/adapters.d.ts +23 -0
- package/dist/esm/core/ir/features.d.ts +8 -0
- package/dist/esm/core/ir/features.js +1 -0
- package/dist/esm/core/ir/flow.d.ts +20 -0
- package/dist/esm/core/ir/index.d.ts +7 -0
- package/dist/esm/core/ir/loss.d.ts +12 -0
- package/dist/esm/core/ir/loss.js +8 -0
- package/dist/esm/core/ir/resources.d.ts +12 -0
- package/dist/esm/core/ir/resources.js +11 -0
- package/dist/esm/core/ir/sheet.d.ts +81 -0
- package/dist/esm/core/ir/units.d.ts +9 -0
- package/dist/esm/core/ir/units.js +2 -0
- package/dist/esm/core/line-breaker/cjk.d.ts +26 -0
- package/dist/esm/core/line-breaker/cjk.js +60 -0
- package/dist/esm/core/line-breaker/greedy.d.ts +14 -0
- package/dist/esm/core/line-breaker/greedy.js +14 -0
- package/dist/esm/core/line-breaker/index.d.ts +1 -0
- package/dist/esm/core/line-breaker/index.js +3 -0
- package/dist/esm/core/line-breaker/knuth-plass.d.ts +29 -5
- package/dist/esm/core/line-breaker/knuth-plass.js +10 -5
- package/dist/esm/core/numbering/apply.d.ts +19 -0
- package/dist/esm/core/numbering/apply.js +19 -0
- package/dist/esm/core/numbering/state.d.ts +15 -0
- package/dist/esm/core/numbering/state.js +15 -0
- package/dist/esm/core/ole/cfb.d.ts +19 -0
- package/dist/esm/core/ole/cfb.js +50 -4
- package/dist/esm/core/opc/core-properties.d.ts +12 -0
- package/dist/esm/core/opc/core-properties.js +5 -0
- package/dist/esm/core/opc/opc-writer.d.ts +24 -4
- package/dist/esm/core/opc/opc-writer.js +12 -0
- package/dist/esm/core/opc/package.d.ts +55 -0
- package/dist/esm/core/opc/package.js +46 -0
- package/dist/esm/core/opc/relationship-types.d.ts +8 -0
- package/dist/esm/core/opc/relationship-types.js +5 -0
- package/dist/esm/core/opc/relationships.d.ts +12 -0
- package/dist/esm/core/opc/relationships.js +7 -0
- package/dist/esm/core/po-helpers.d.ts +38 -0
- package/dist/esm/core/po-helpers.js +33 -0
- package/dist/esm/core/spreadsheet-model/types.d.ts +281 -0
- package/dist/esm/core/style-cascade/resolver.d.ts +31 -0
- package/dist/esm/core/style-cascade/resolver.js +31 -0
- package/dist/esm/core/style-cascade/table.d.ts +7 -0
- package/dist/esm/core/style-cascade/table.js +7 -0
- package/dist/esm/core/style-cascade/types.d.ts +27 -0
- package/dist/esm/core/style-cascade/types.js +2 -0
- package/dist/esm/core/vector.d.ts +67 -0
- package/dist/esm/core/vector.js +23 -0
- package/dist/esm/excel/activex-parser.d.ts +31 -0
- package/dist/esm/excel/activex-parser.js +24 -0
- package/dist/esm/excel/cell-reference.d.ts +14 -0
- package/dist/esm/excel/cell-reference.js +9 -0
- package/dist/esm/excel/column-bands.d.ts +29 -0
- package/dist/esm/excel/column-bands.js +26 -0
- package/dist/esm/excel/comments-parser.d.ts +19 -0
- package/dist/esm/excel/comments-parser.js +19 -0
- package/dist/esm/excel/conditional-format.d.ts +38 -0
- package/dist/esm/excel/conditional-format.js +25 -0
- package/dist/esm/excel/defined-name-ref.d.ts +21 -0
- package/dist/esm/excel/defined-name-ref.js +20 -0
- package/dist/esm/excel/form-control-parser.d.ts +13 -0
- package/dist/esm/excel/form-control-parser.js +5 -0
- package/dist/esm/excel/formula/context.d.ts +37 -0
- package/dist/esm/excel/formula/dates.d.ts +23 -0
- package/dist/esm/excel/formula/dates.js +20 -0
- package/dist/esm/excel/formula/eval.d.ts +21 -0
- package/dist/esm/excel/formula/eval.js +11 -0
- package/dist/esm/excel/formula/functions.d.ts +12 -0
- package/dist/esm/excel/formula/functions.js +12 -0
- package/dist/esm/excel/formula/index.d.ts +21 -0
- package/dist/esm/excel/formula/index.js +16 -0
- package/dist/esm/excel/formula/lexer.d.ts +12 -0
- package/dist/esm/excel/formula/lexer.js +10 -0
- package/dist/esm/excel/formula/parser.d.ts +20 -0
- package/dist/esm/excel/formula/parser.js +53 -0
- package/dist/esm/excel/formula/value.d.ts +53 -0
- package/dist/esm/excel/formula/value.js +30 -0
- package/dist/esm/excel/header-footer.d.ts +9 -0
- package/dist/esm/excel/header-footer.js +9 -0
- package/dist/esm/excel/number-format.d.ts +34 -0
- package/dist/esm/excel/number-format.js +34 -0
- package/dist/esm/excel/pivot-table-parser.d.ts +8 -0
- package/dist/esm/excel/pivot-table-parser.js +8 -0
- package/dist/esm/excel/print-model.d.ts +56 -0
- package/dist/esm/excel/print-model.js +43 -0
- package/dist/esm/excel/shared-strings-parser.d.ts +13 -0
- package/dist/esm/excel/shared-strings-parser.js +5 -0
- package/dist/esm/excel/sheet-drawing.d.ts +34 -0
- package/dist/esm/excel/sheet-drawing.js +21 -0
- package/dist/esm/excel/sheet-shape-parser.d.ts +12 -0
- package/dist/esm/excel/sheet-shape-parser.js +12 -0
- package/dist/esm/excel/sheet-to-flow.d.ts +19 -0
- package/dist/esm/excel/sheet-to-flow.js +10 -0
- package/dist/esm/excel/slicer-parser.d.ts +23 -0
- package/dist/esm/excel/slicer-parser.js +10 -0
- package/dist/esm/excel/styles-parser.d.ts +8 -0
- package/dist/esm/excel/styles-parser.js +8 -0
- package/dist/esm/excel/table-parser.d.ts +24 -0
- package/dist/esm/excel/table-parser.js +5 -0
- package/dist/esm/excel/workbook-parser.d.ts +17 -0
- package/dist/esm/excel/workbook-parser.js +5 -0
- package/dist/esm/excel/worksheet-parser.d.ts +9 -0
- package/dist/esm/excel/worksheet-parser.js +9 -0
- package/dist/esm/excel/xls/biff-chart.d.ts +10 -0
- package/dist/esm/excel/xls/biff-chart.js +10 -0
- package/dist/esm/excel/xls/biff-reader.d.ts +27 -0
- package/dist/esm/excel/xls/biff-reader.js +44 -0
- package/dist/esm/excel/xls/biff-styles.d.ts +20 -0
- package/dist/esm/excel/xls/biff-styles.js +20 -0
- package/dist/esm/excel/xls/escher.d.ts +27 -0
- package/dist/esm/excel/xls/escher.js +18 -0
- package/dist/esm/excel/xls/xls-reader.d.ts +6 -0
- package/dist/esm/excel/xls/xls-reader.js +6 -0
- package/dist/esm/excel/xlsx-reader.d.ts +26 -0
- package/dist/esm/excel/xlsx-reader.js +26 -0
- package/dist/esm/excel/xlsx-to-pdf.d.ts +27 -0
- package/dist/esm/excel/xlsx-writer.d.ts +14 -0
- package/dist/esm/excel/xlsx-writer.js +13 -0
- package/dist/esm/html/html-writer.d.ts +18 -0
- package/dist/esm/html/html-writer.js +18 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/layout/math-layout.d.ts +39 -0
- package/dist/esm/layout/math-layout.js +18 -0
- package/dist/esm/layout/page-doc.d.ts +91 -0
- package/dist/esm/layout/styled-layout.d.ts +175 -0
- package/dist/esm/layout/styled-layout.js +117 -2
- package/dist/esm/pdf/builtin-fonts.d.ts +5 -0
- package/dist/esm/pdf/cid-font.d.ts +22 -0
- package/dist/esm/pdf/cid-font.js +10 -0
- package/dist/esm/pdf/embedded-file.d.ts +16 -0
- package/dist/esm/pdf/embedded-file.js +9 -0
- package/dist/esm/pdf/encryption.d.ts +59 -0
- package/dist/esm/pdf/encryption.js +37 -0
- package/dist/esm/pdf/icc-profile.d.ts +8 -0
- package/dist/esm/pdf/icc-profile.js +8 -0
- package/dist/esm/pdf/image-xobject.d.ts +19 -0
- package/dist/esm/pdf/image-xobject.js +9 -0
- package/dist/esm/pdf/objects.d.ts +40 -0
- package/dist/esm/pdf/objects.js +36 -0
- package/dist/esm/pdf/serialize.d.ts +18 -0
- package/dist/esm/pdf/serialize.js +18 -0
- package/dist/esm/pdf/shading.d.ts +16 -0
- package/dist/esm/pdf/shading.js +16 -0
- package/dist/esm/pdf/signature.d.ts +36 -0
- package/dist/esm/pdf/signature.js +22 -0
- package/dist/esm/pdf/struct-tree.d.ts +64 -0
- package/dist/esm/pdf/struct-tree.js +60 -0
- package/dist/esm/pdf/styled-page-emitter.d.ts +33 -0
- package/dist/esm/pdf/styled-page-emitter.js +21 -0
- package/dist/esm/pdf/styled-page-renderer.d.ts +18 -0
- package/dist/esm/pdf/styled-page-renderer.js +18 -0
- package/dist/esm/pdf/text-encoding.d.ts +16 -0
- package/dist/esm/pdf/text-page-renderer.d.ts +11 -0
- package/dist/esm/pdf/vector-graphics.d.ts +12 -0
- package/dist/esm/pdf/vector-graphics.js +12 -0
- package/dist/esm/pdf/writer.d.ts +39 -0
- package/dist/esm/pdf/writer.js +27 -0
- package/dist/esm/pdf/xmp.d.ts +16 -0
- package/dist/esm/pdf/xmp.js +9 -0
- package/dist/esm/pdf-reader/ccitt.d.ts +25 -0
- package/dist/esm/pdf-reader/ccitt.js +15 -0
- package/dist/esm/pdf-reader/cmap.d.ts +12 -0
- package/dist/esm/pdf-reader/cmap.js +9 -0
- package/dist/esm/pdf-reader/content.d.ts +69 -0
- package/dist/esm/pdf-reader/content.js +16 -0
- package/dist/esm/pdf-reader/crypto.d.ts +5 -0
- package/dist/esm/pdf-reader/crypto.js +5 -0
- package/dist/esm/pdf-reader/decrypt.d.ts +17 -0
- package/dist/esm/pdf-reader/decrypt.js +12 -0
- package/dist/esm/pdf-reader/document.d.ts +53 -0
- package/dist/esm/pdf-reader/document.js +50 -0
- package/dist/esm/pdf-reader/flow-build.d.ts +51 -2
- package/dist/esm/pdf-reader/flow-build.js +67 -2
- package/dist/esm/pdf-reader/font.d.ts +12 -0
- package/dist/esm/pdf-reader/font.js +12 -0
- package/dist/esm/pdf-reader/image-decode.d.ts +21 -0
- package/dist/esm/pdf-reader/image-decode.js +14 -0
- package/dist/esm/pdf-reader/images.d.ts +19 -0
- package/dist/esm/pdf-reader/images.js +9 -0
- package/dist/esm/pdf-reader/layout.d.ts +15 -0
- package/dist/esm/pdf-reader/layout.js +17 -2
- package/dist/esm/pdf-reader/lexer.d.ts +43 -0
- package/dist/esm/pdf-reader/lexer.js +38 -0
- package/dist/esm/pdf-reader/parser.d.ts +15 -0
- package/dist/esm/pdf-reader/parser.js +8 -0
- package/dist/esm/pdf-reader/png-encode.d.ts +9 -0
- package/dist/esm/pdf-reader/png-encode.js +8 -0
- package/dist/esm/pdf-reader/predictor.d.ts +9 -0
- package/dist/esm/pdf-reader/predictor.js +8 -0
- package/dist/esm/pdf-reader/reader.d.ts +16 -0
- package/dist/esm/pdf-reader/reader.js +16 -0
- package/dist/esm/pdf-reader/shading.d.ts +10 -0
- package/dist/esm/pdf-reader/shading.js +10 -0
- package/dist/esm/pdf-reader/struct-tree.d.ts +24 -0
- package/dist/esm/pdf-reader/struct-tree.js +12 -0
- package/dist/esm/pdf-reader/tagged.d.ts +13 -0
- package/dist/esm/pdf-reader/tagged.js +15 -2
- package/dist/esm/pdf-reader/text.d.ts +11 -0
- package/dist/esm/pdf-reader/text.js +11 -0
- package/dist/esm/pdf-reader/vector.d.ts +19 -0
- package/dist/esm/pdf-reader/vector.js +9 -0
- package/dist/esm/pptx/placeholder-cascade.d.ts +21 -0
- package/dist/esm/pptx/placeholder-cascade.js +10 -0
- package/dist/esm/pptx/ppt/ppt-reader.d.ts +16 -0
- package/dist/esm/pptx/ppt/ppt-reader.js +16 -0
- package/dist/esm/pptx/ppt/ppt-text.d.ts +55 -0
- package/dist/esm/pptx/ppt/ppt-text.js +14 -0
- package/dist/esm/pptx/pptx-reader.d.ts +21 -0
- package/dist/esm/pptx/pptx-reader.js +37 -1
- package/dist/esm/pptx/slide-parser.d.ts +102 -0
- package/dist/esm/pptx/slide-parser.js +78 -0
- package/dist/esm/pptx/sp-helpers.d.ts +28 -0
- package/dist/esm/pptx/sp-helpers.js +22 -0
- package/dist/esm/svg/svg-writer.d.ts +17 -0
- package/dist/esm/svg/svg-writer.js +16 -0
- package/dist/esm/word/doc/doc-reader.d.ts +16 -0
- package/dist/esm/word/doc/doc-reader.js +26 -4
- package/dist/esm/word/doc/doc-text.d.ts +81 -0
- package/dist/esm/word/doc/doc-text.js +38 -0
- package/dist/esm/word/document-parser.d.ts +134 -0
- package/dist/esm/word/document-parser.js +86 -0
- package/dist/esm/word/docx-reader.d.ts +16 -0
- package/dist/esm/word/docx-reader.js +16 -0
- package/dist/esm/word/docx-to-pdf.d.ts +52 -0
- package/dist/esm/word/docx-to-pdf.js +21 -0
- package/dist/esm/word/docx-writer.d.ts +17 -0
- package/dist/esm/word/docx-writer.js +17 -0
- package/dist/esm/word/drawing-parser.d.ts +88 -0
- package/dist/esm/word/drawing-parser.js +68 -0
- package/dist/esm/word/font-table.d.ts +24 -0
- package/dist/esm/word/font-table.js +24 -0
- package/dist/esm/word/numbering-parser.d.ts +11 -0
- package/dist/esm/word/numbering-parser.js +11 -0
- package/dist/esm/word/omml-parser.d.ts +15 -0
- package/dist/esm/word/omml-parser.js +15 -0
- package/dist/esm/word/omml-serializer.d.ts +9 -0
- package/dist/esm/word/omml-serializer.js +9 -0
- package/dist/esm/word/paragraph-properties.d.ts +10 -0
- package/dist/esm/word/paragraph-properties.js +10 -0
- package/dist/esm/word/po-to-flat.d.ts +11 -0
- package/dist/esm/word/po-to-flat.js +11 -0
- package/dist/esm/word/run-properties.d.ts +10 -0
- package/dist/esm/word/run-properties.js +10 -0
- package/dist/esm/word/settings-parser.d.ts +13 -0
- package/dist/esm/word/settings-parser.js +8 -0
- package/dist/esm/word/styles-parser.d.ts +10 -0
- package/dist/esm/word/styles-parser.js +10 -0
- package/dist/esm/word/table-parser.d.ts +11 -0
- package/dist/esm/word/table-parser.js +11 -0
- package/dist/esm/word/text-extractor.d.ts +9 -0
- package/dist/esm/word/xml-helpers.d.ts +44 -0
- package/dist/esm/word/xml-helpers.js +38 -0
- package/package.json +1 -1
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { CellIcon } from '../core/document-model/index.js';
|
|
2
2
|
import { ConditionalFormat, DefinedName, WorksheetCell, XlsxStyles } from '../core/spreadsheet-model/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* A resolved per-cell override the print model layers over a cell's base format: a
|
|
5
|
+
* solid highlight fill, font tweaks, an in-cell data bar (fraction of the cell
|
|
6
|
+
* width 0..1 + colour), and/or a leading icon.
|
|
7
|
+
*/
|
|
3
8
|
export interface CfOverride {
|
|
4
9
|
readonly fillHex?: string;
|
|
5
10
|
readonly fontColorHex?: string;
|
|
6
11
|
readonly bold?: boolean;
|
|
7
12
|
readonly italic?: boolean;
|
|
13
|
+
/** An in-cell data bar: its fraction of the cell width, colour, and optional left offset. */
|
|
8
14
|
readonly dataBar?: {
|
|
9
15
|
readonly fraction: number;
|
|
10
16
|
readonly colorHex: string;
|
|
@@ -12,7 +18,39 @@ export interface CfOverride {
|
|
|
12
18
|
};
|
|
13
19
|
readonly icon?: CellIcon;
|
|
14
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* A per-cell lookup returning the {@link CfOverride} for the cell at `(row, col)`,
|
|
23
|
+
* or undefined when no rule applies. `numericValue` is the cell's comparable number
|
|
24
|
+
* (undefined for non-numeric cells); `text` is its resolved string — needed by the
|
|
25
|
+
* text tests and to key duplicate / unique comparisons for non-numeric cells
|
|
26
|
+
* (empty/undefined for a blank cell).
|
|
27
|
+
*/
|
|
15
28
|
export type CellConditionalFormatter = (row: number, col: number, numericValue: number | undefined, text: string | undefined) => CfOverride | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Compile a sheet's `<conditionalFormatting>` rules + the workbook's `<dxfs>` into
|
|
31
|
+
* a per-cell {@link CellConditionalFormatter}. Returns undefined when the sheet has
|
|
32
|
+
* no conditional formats (the common case) so callers skip the work entirely and
|
|
33
|
+
* stay byte-identical.
|
|
34
|
+
*
|
|
35
|
+
* @param conditionalFormats The sheet's rules; undefined/empty ⇒ no formatter.
|
|
36
|
+
* @param styles The workbook style table (its `dxfs` supply the highlights).
|
|
37
|
+
* @param cells The range values the extent rules need
|
|
38
|
+
* (min/max/percentile/mean/frequency); `cellIs` and the
|
|
39
|
+
* text tests ignore it.
|
|
40
|
+
* @param resolveText Resolves a cell's string value (shared strings / number
|
|
41
|
+
* format) for the duplicate/unique frequency map — numeric
|
|
42
|
+
* cells key by value without it, so it is only needed for
|
|
43
|
+
* text cells.
|
|
44
|
+
* @param date1904 The workbook date epoch (feeds the W9 formula engine).
|
|
45
|
+
* @param now An injected reference date — never the wall clock —
|
|
46
|
+
* driving `TODAY()`/`NOW()` and the `timePeriod` windows;
|
|
47
|
+
* absent ⇒ those constructs no-op (deterministic output).
|
|
48
|
+
* @param sheetGrids The whole workbook, for an `expression` rule that reaches
|
|
49
|
+
* another sheet (`Sheet2!A1`) or a defined name; absent ⇒
|
|
50
|
+
* same-sheet references only.
|
|
51
|
+
* @param currentSheet The rule sheet's name, for resolving sheet-local names.
|
|
52
|
+
* @param definedNames The workbook defined names visible to `expression` rules.
|
|
53
|
+
*/
|
|
16
54
|
export declare function buildConditionalFormatter(conditionalFormats: ReadonlyArray<ConditionalFormat> | undefined, styles: XlsxStyles, cells: ReadonlyArray<WorksheetCell>, resolveText?: (cell: WorksheetCell) => string, date1904?: boolean, now?: Date, sheetGrids?: ReadonlyMap<string, {
|
|
17
55
|
readonly cells: ReadonlyArray<WorksheetCell>;
|
|
18
56
|
}>, currentSheet?: string, definedNames?: ReadonlyArray<DefinedName>): CellConditionalFormatter | undefined;
|
|
@@ -3,6 +3,31 @@ import { BLANK, bool, err, num, str } from "./formula/value.js";
|
|
|
3
3
|
import { NO_SHIFT, evaluate } from "./formula/eval.js";
|
|
4
4
|
import { compileFormula, evaluateToBool } from "./formula/index.js";
|
|
5
5
|
//#region src/excel/conditional-format.ts
|
|
6
|
+
/**
|
|
7
|
+
* Compile a sheet's `<conditionalFormatting>` rules + the workbook's `<dxfs>` into
|
|
8
|
+
* a per-cell {@link CellConditionalFormatter}. Returns undefined when the sheet has
|
|
9
|
+
* no conditional formats (the common case) so callers skip the work entirely and
|
|
10
|
+
* stay byte-identical.
|
|
11
|
+
*
|
|
12
|
+
* @param conditionalFormats The sheet's rules; undefined/empty ⇒ no formatter.
|
|
13
|
+
* @param styles The workbook style table (its `dxfs` supply the highlights).
|
|
14
|
+
* @param cells The range values the extent rules need
|
|
15
|
+
* (min/max/percentile/mean/frequency); `cellIs` and the
|
|
16
|
+
* text tests ignore it.
|
|
17
|
+
* @param resolveText Resolves a cell's string value (shared strings / number
|
|
18
|
+
* format) for the duplicate/unique frequency map — numeric
|
|
19
|
+
* cells key by value without it, so it is only needed for
|
|
20
|
+
* text cells.
|
|
21
|
+
* @param date1904 The workbook date epoch (feeds the W9 formula engine).
|
|
22
|
+
* @param now An injected reference date — never the wall clock —
|
|
23
|
+
* driving `TODAY()`/`NOW()` and the `timePeriod` windows;
|
|
24
|
+
* absent ⇒ those constructs no-op (deterministic output).
|
|
25
|
+
* @param sheetGrids The whole workbook, for an `expression` rule that reaches
|
|
26
|
+
* another sheet (`Sheet2!A1`) or a defined name; absent ⇒
|
|
27
|
+
* same-sheet references only.
|
|
28
|
+
* @param currentSheet The rule sheet's name, for resolving sheet-local names.
|
|
29
|
+
* @param definedNames The workbook defined names visible to `expression` rules.
|
|
30
|
+
*/
|
|
6
31
|
function buildConditionalFormatter(conditionalFormats, styles, cells, resolveText, date1904 = false, now, sheetGrids, currentSheet, definedNames) {
|
|
7
32
|
if (!conditionalFormats || conditionalFormats.length === 0) return void 0;
|
|
8
33
|
const dxfs = styles.dxfs ?? [];
|
|
@@ -1,11 +1,32 @@
|
|
|
1
|
+
/** A 0-indexed inclusive cell range (the bounding box of a parsed area). */
|
|
1
2
|
export interface CellRange {
|
|
2
3
|
readonly startColumn: number;
|
|
3
4
|
readonly startRow: number;
|
|
4
5
|
readonly endColumn: number;
|
|
5
6
|
readonly endRow: number;
|
|
6
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Extract the repeated-row range from an `_xlnm.Print_Titles` value, e.g.
|
|
10
|
+
* `"Sheet1!$1:$2"` (rows 1-2) or `"Sheet1!$A:$B,Sheet1!$1:$1"` (cols A-B + row 1).
|
|
11
|
+
* Only the ROW range is recovered — column titles repeat across horizontal page
|
|
12
|
+
* breaks, which the layout does not paginate.
|
|
13
|
+
*
|
|
14
|
+
* @param value The defined-name value.
|
|
15
|
+
* @returns The 0-indexed inclusive row range, or `undefined` when no pure row
|
|
16
|
+
* range is present.
|
|
17
|
+
*/
|
|
7
18
|
export declare function parseTitleRowRange(value: string): {
|
|
8
19
|
readonly startRow: number;
|
|
9
20
|
readonly endRow: number;
|
|
10
21
|
} | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Resolve a `<definedName>` area value (§18.2.5 / §18.17) to the bounding box of
|
|
24
|
+
* every parseable area. A value may be a single cell (`"Sheet1!$A$1"`), a range
|
|
25
|
+
* (`"Sheet1!$A$1:$D$20"`), or several comma-separated areas; the sheet qualifier
|
|
26
|
+
* and `$` absolute markers are stripped. Multiple disjoint areas collapse to one
|
|
27
|
+
* enclosing box (a faithful approximation — Excel prints them in sequence).
|
|
28
|
+
*
|
|
29
|
+
* @param value The defined-name value (e.g. a `_xlnm.Print_Area`).
|
|
30
|
+
* @returns The 0-indexed inclusive bounding box, or `undefined` when no area parses.
|
|
31
|
+
*/
|
|
11
32
|
export declare function parseAreaRef(value: string): CellRange | undefined;
|
|
@@ -30,6 +30,16 @@ function parseSingleArea(token) {
|
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract the repeated-row range from an `_xlnm.Print_Titles` value, e.g.
|
|
35
|
+
* `"Sheet1!$1:$2"` (rows 1-2) or `"Sheet1!$A:$B,Sheet1!$1:$1"` (cols A-B + row 1).
|
|
36
|
+
* Only the ROW range is recovered — column titles repeat across horizontal page
|
|
37
|
+
* breaks, which the layout does not paginate.
|
|
38
|
+
*
|
|
39
|
+
* @param value The defined-name value.
|
|
40
|
+
* @returns The 0-indexed inclusive row range, or `undefined` when no pure row
|
|
41
|
+
* range is present.
|
|
42
|
+
*/
|
|
33
43
|
function parseTitleRowRange(value) {
|
|
34
44
|
if (!value) return void 0;
|
|
35
45
|
for (const token of value.split(",")) {
|
|
@@ -45,6 +55,16 @@ function parseTitleRowRange(value) {
|
|
|
45
55
|
};
|
|
46
56
|
}
|
|
47
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Resolve a `<definedName>` area value (§18.2.5 / §18.17) to the bounding box of
|
|
60
|
+
* every parseable area. A value may be a single cell (`"Sheet1!$A$1"`), a range
|
|
61
|
+
* (`"Sheet1!$A$1:$D$20"`), or several comma-separated areas; the sheet qualifier
|
|
62
|
+
* and `$` absolute markers are stripped. Multiple disjoint areas collapse to one
|
|
63
|
+
* enclosing box (a faithful approximation — Excel prints them in sequence).
|
|
64
|
+
*
|
|
65
|
+
* @param value The defined-name value (e.g. a `_xlnm.Print_Area`).
|
|
66
|
+
* @returns The 0-indexed inclusive bounding box, or `undefined` when no area parses.
|
|
67
|
+
*/
|
|
48
68
|
function parseAreaRef(value) {
|
|
49
69
|
if (!value) return void 0;
|
|
50
70
|
let box;
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
+
/** A form control's resolved state from its `ctrlProp` part (E-SHEET W8). */
|
|
1
2
|
export interface FormControlProps {
|
|
3
|
+
/**
|
|
4
|
+
* §18.18.18-ish `ST_ObjectType` — `CheckBox`, `Radio`, `Spin`, `Scroll`, `Drop`,
|
|
5
|
+
* `List`, `Buttons`, `Label`, `GBox`, `Dialog`, `EditBox`, `Note` … (the
|
|
6
|
+
* producer's spelling kept).
|
|
7
|
+
*/
|
|
2
8
|
readonly objectType?: string;
|
|
9
|
+
/** Checked state for a check/option button. */
|
|
3
10
|
readonly checked?: boolean;
|
|
11
|
+
/** Current value for a spin / scroll / list control. */
|
|
4
12
|
readonly value?: number;
|
|
5
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Parse a `xl/ctrlProps/ctrlProp#.xml` part (a single `<formControlPr>`) into the
|
|
16
|
+
* control's {@link FormControlProps} — its `objectType` plus the bit of state the
|
|
17
|
+
* listing shows (`checked` for check/option buttons, `val` for spin/scroll/list).
|
|
18
|
+
*/
|
|
6
19
|
export declare function parseFormControlProps(data: Uint8Array): FormControlProps;
|
|
@@ -7,6 +7,11 @@ var parser = new XMLParser({
|
|
|
7
7
|
parseAttributeValue: false,
|
|
8
8
|
removeNSPrefix: true
|
|
9
9
|
});
|
|
10
|
+
/**
|
|
11
|
+
* Parse a `xl/ctrlProps/ctrlProp#.xml` part (a single `<formControlPr>`) into the
|
|
12
|
+
* control's {@link FormControlProps} — its `objectType` plus the bit of state the
|
|
13
|
+
* listing shows (`checked` for check/option buttons, `val` for spin/scroll/list).
|
|
14
|
+
*/
|
|
10
15
|
function parseFormControlProps(data) {
|
|
11
16
|
const pr = parser.parse(decoder.decode(data))["formControlPr"];
|
|
12
17
|
const obj = pr && typeof pr === "object" ? pr : void 0;
|
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
import { FValue, Rect, Scalar } from './value.js';
|
|
2
|
+
/**
|
|
3
|
+
* Everything a formula needs from the world outside its own syntax tree (E-SHEET
|
|
4
|
+
* W9): the grid's cached cell values, the injected reference date, and the workbook
|
|
5
|
+
* date epoch — optionally extended with cross-sheet / defined-name resolution. The
|
|
6
|
+
* context is the seam that keeps the evaluator pure and deterministic: it never
|
|
7
|
+
* reads the wall clock or recomputes a cell, only looking up values Excel already
|
|
8
|
+
* cached.
|
|
9
|
+
*/
|
|
2
10
|
export interface EvalContext {
|
|
11
|
+
/**
|
|
12
|
+
* The cached value of the cell at `(row, col)` — both absolute, 0-indexed. An
|
|
13
|
+
* absent or empty cell yields a blank scalar; the evaluator never recurses into a
|
|
14
|
+
* referenced cell's own formula (there is none stored — we have only the cached
|
|
15
|
+
* value), which is exactly why no recalculation engine is needed.
|
|
16
|
+
*/
|
|
3
17
|
readonly getCell: (row: number, col: number) => Scalar;
|
|
18
|
+
/**
|
|
19
|
+
* Visit every POPULATED cell within a rectangle (blanks are skipped — they
|
|
20
|
+
* contribute nothing to SUM/COUNT/COUNTIF). Iterating the sparse cell set keeps an
|
|
21
|
+
* aggregate over a whole-column range O(populated), not O(rows), mirroring the
|
|
22
|
+
* colorScale extent scan. The order is unspecified.
|
|
23
|
+
*/
|
|
4
24
|
readonly eachCell: (rect: Rect, visit: (row: number, col: number, value: Scalar) => void) => void;
|
|
25
|
+
/**
|
|
26
|
+
* The reference "today" as an Excel serial day (`options.now`, converted with the
|
|
27
|
+
* workbook epoch). `TODAY()`/`NOW()` and the `timePeriod` windows read it.
|
|
28
|
+
* undefined ⇒ those clock-relative constructs yield `#VALUE!` / no-op, preserving
|
|
29
|
+
* determinism when the caller supplies no date.
|
|
30
|
+
*/
|
|
5
31
|
readonly nowSerial: number | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* false = 1900 epoch (the default), true = 1904 epoch. Date functions
|
|
34
|
+
* (YEAR/MONTH/DAY/DATE/WEEKDAY/…) convert serials ↔ calendar with it.
|
|
35
|
+
*/
|
|
6
36
|
readonly date1904: boolean;
|
|
37
|
+
/** A sheet name (case-insensitive) → its 0-based workbook index, or undefined. */
|
|
7
38
|
readonly sheetIndex?: (name: string) => number | undefined;
|
|
39
|
+
/** {@link EvalContext.getCell}, but on a specific sheet by index (cross-sheet references). */
|
|
8
40
|
readonly getCellOn?: (sheet: number, row: number, col: number) => Scalar;
|
|
41
|
+
/** {@link EvalContext.eachCell}, but on a specific sheet by index (cross-sheet references). */
|
|
9
42
|
readonly eachCellOn?: (sheet: number, rect: Rect, visit: (row: number, col: number, value: Scalar) => void) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a defined name (case-insensitive) to its target — a reference value (a
|
|
45
|
+
* Rect, optionally on another sheet) or a literal scalar; undefined ⇒ `#NAME?`.
|
|
46
|
+
*/
|
|
10
47
|
readonly resolveName?: (name: string) => FValue | undefined;
|
|
11
48
|
}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { TimePeriodKind } from '../../core/spreadsheet-model/index.js';
|
|
2
|
+
/** The UTC calendar fields an Excel serial decomposes into. */
|
|
2
3
|
export interface DateParts {
|
|
3
4
|
readonly year: number;
|
|
5
|
+
/** 1-indexed month (January = 1). */
|
|
4
6
|
readonly month: number;
|
|
5
7
|
readonly day: number;
|
|
8
|
+
/** Day of week, 0 = Sunday … 6 = Saturday (Excel WEEKDAY type 1 minus 1). */
|
|
6
9
|
readonly dow: number;
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Decompose an Excel serial into UTC calendar parts. A fractional serial is
|
|
13
|
+
* floored to its day first (the calendar date is time-of-day independent).
|
|
14
|
+
*/
|
|
8
15
|
export declare function serialToParts(serial: number, date1904: boolean): DateParts;
|
|
16
|
+
/**
|
|
17
|
+
* A UTC Date's calendar day → integer Excel serial. Reads the Date's UTC date
|
|
18
|
+
* parts (not its instant), so a caller passing `new Date('2026-06-17')`
|
|
19
|
+
* (UTC midnight) maps to that day regardless of the host time zone.
|
|
20
|
+
*/
|
|
9
21
|
export declare function serialFromDate(d: Date, date1904: boolean): number;
|
|
22
|
+
/**
|
|
23
|
+
* `(year, month1, day)` → integer serial. Excel's `DATE` rolls out-of-range
|
|
24
|
+
* months and days (`DATE(2024,13,1)` = 2025-01-01); `Date.UTC` already
|
|
25
|
+
* normalises, so this inherits the same behaviour.
|
|
26
|
+
*/
|
|
10
27
|
export declare function serialFromYmd(year: number, month1: number, day: number, date1904: boolean): number;
|
|
28
|
+
/**
|
|
29
|
+
* §18.3.1.10 `timePeriod` — does a cell's date fall in the window relative to
|
|
30
|
+
* `nowSerial` (the injected reference day)? Windows match Excel's built-in
|
|
31
|
+
* rules: the week runs Sunday..Saturday; "last 7 days" is today and the previous
|
|
32
|
+
* six. Both serials are floored to whole days before comparison.
|
|
33
|
+
*/
|
|
11
34
|
export declare function timePeriodMatches(period: TimePeriodKind, cellSerial: number, nowSerial: number, date1904: boolean): boolean;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { excelSerialFromUtcParts, excelSerialToDate } from "../number-format.js";
|
|
2
2
|
//#region src/excel/formula/dates.ts
|
|
3
|
+
/**
|
|
4
|
+
* Decompose an Excel serial into UTC calendar parts. A fractional serial is
|
|
5
|
+
* floored to its day first (the calendar date is time-of-day independent).
|
|
6
|
+
*/
|
|
3
7
|
function serialToParts(serial, date1904) {
|
|
4
8
|
const d = excelSerialToDate(Math.floor(serial), date1904);
|
|
5
9
|
return {
|
|
@@ -9,12 +13,28 @@ function serialToParts(serial, date1904) {
|
|
|
9
13
|
dow: d.getUTCDay()
|
|
10
14
|
};
|
|
11
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* A UTC Date's calendar day → integer Excel serial. Reads the Date's UTC date
|
|
18
|
+
* parts (not its instant), so a caller passing `new Date('2026-06-17')`
|
|
19
|
+
* (UTC midnight) maps to that day regardless of the host time zone.
|
|
20
|
+
*/
|
|
12
21
|
function serialFromDate(d, date1904) {
|
|
13
22
|
return excelSerialFromUtcParts(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(), date1904);
|
|
14
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* `(year, month1, day)` → integer serial. Excel's `DATE` rolls out-of-range
|
|
26
|
+
* months and days (`DATE(2024,13,1)` = 2025-01-01); `Date.UTC` already
|
|
27
|
+
* normalises, so this inherits the same behaviour.
|
|
28
|
+
*/
|
|
15
29
|
function serialFromYmd(year, month1, day, date1904) {
|
|
16
30
|
return excelSerialFromUtcParts(year, month1 - 1, day, date1904);
|
|
17
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* §18.3.1.10 `timePeriod` — does a cell's date fall in the window relative to
|
|
34
|
+
* `nowSerial` (the injected reference day)? Windows match Excel's built-in
|
|
35
|
+
* rules: the week runs Sunday..Saturday; "last 7 days" is today and the previous
|
|
36
|
+
* six. Both serials are floored to whole days before comparison.
|
|
37
|
+
*/
|
|
18
38
|
function timePeriodMatches(period, cellSerial, nowSerial, date1904) {
|
|
19
39
|
const cell = Math.floor(cellSerial);
|
|
20
40
|
const today = Math.floor(nowSerial);
|
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import { Ast } from './parser.js';
|
|
2
2
|
import { EvalContext } from './context.js';
|
|
3
3
|
import { FValue } from './value.js';
|
|
4
|
+
/**
|
|
5
|
+
* The cell's offset from the rule origin, added to UNANCHORED reference axes.
|
|
6
|
+
* `curRow`/`curCol` carry the ABSOLUTE current cell (origin + delta) so `ROW()`/
|
|
7
|
+
* `COLUMN()` with no argument can report it; absent ({@link NO_SHIFT}) ⇒ those
|
|
8
|
+
* no-arg forms have no cell to name and yield `#VALUE!`.
|
|
9
|
+
*/
|
|
4
10
|
export interface Shift {
|
|
11
|
+
/** Row delta from the rule origin, added to an unanchored row axis. */
|
|
5
12
|
readonly dRow: number;
|
|
13
|
+
/** Column delta from the rule origin, added to an unanchored column axis. */
|
|
6
14
|
readonly dCol: number;
|
|
15
|
+
/** The absolute current row, for no-arg `ROW()`; absent ⇒ `#VALUE!`. */
|
|
7
16
|
readonly curRow?: number;
|
|
17
|
+
/** The absolute current column, for no-arg `COLUMN()`; absent ⇒ `#VALUE!`. */
|
|
8
18
|
readonly curCol?: number;
|
|
9
19
|
}
|
|
20
|
+
/** The zero shift — no offset and no current cell (no-arg `ROW`/`COLUMN` → `#VALUE!`). */
|
|
10
21
|
export declare const NO_SHIFT: Shift;
|
|
22
|
+
/**
|
|
23
|
+
* Evaluate an {@link Ast} against an `EvalContext` and a per-cell {@link Shift},
|
|
24
|
+
* yielding an `FValue` (a scalar, a reference, or an array). Cells/ranges
|
|
25
|
+
* evaluate to reference values; scalar operators dereference them.
|
|
26
|
+
*
|
|
27
|
+
* @param ast The syntax tree to evaluate.
|
|
28
|
+
* @param ctx The evaluation context (grid access, defined names, date system).
|
|
29
|
+
* @param shift The current cell's offset from the rule origin.
|
|
30
|
+
* @returns The computed value.
|
|
31
|
+
*/
|
|
11
32
|
export declare function evaluate(ast: Ast, ctx: EvalContext, shift: Shift): FValue;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { bool, deref, err, num, str, toNumber, toText } from "./value.js";
|
|
2
2
|
import { callFn } from "./functions.js";
|
|
3
3
|
//#region src/excel/formula/eval.ts
|
|
4
|
+
/** The zero shift — no offset and no current cell (no-arg `ROW`/`COLUMN` → `#VALUE!`). */
|
|
4
5
|
var NO_SHIFT = {
|
|
5
6
|
dRow: 0,
|
|
6
7
|
dCol: 0
|
|
7
8
|
};
|
|
9
|
+
/**
|
|
10
|
+
* Evaluate an {@link Ast} against an `EvalContext` and a per-cell {@link Shift},
|
|
11
|
+
* yielding an `FValue` (a scalar, a reference, or an array). Cells/ranges
|
|
12
|
+
* evaluate to reference values; scalar operators dereference them.
|
|
13
|
+
*
|
|
14
|
+
* @param ast The syntax tree to evaluate.
|
|
15
|
+
* @param ctx The evaluation context (grid access, defined names, date system).
|
|
16
|
+
* @param shift The current cell's offset from the rule origin.
|
|
17
|
+
* @returns The computed value.
|
|
18
|
+
*/
|
|
8
19
|
function evaluate(ast, ctx, shift) {
|
|
9
20
|
switch (ast.k) {
|
|
10
21
|
case "num": return num(ast.v);
|
|
@@ -3,5 +3,17 @@ import { EvalContext } from './context.js';
|
|
|
3
3
|
import { Shift } from './eval.js';
|
|
4
4
|
import { FValue } from './value.js';
|
|
5
5
|
type Ev = (a: Ast) => FValue;
|
|
6
|
+
/**
|
|
7
|
+
* Dispatch a built-in formula function by name, evaluating its arguments through
|
|
8
|
+
* `ev`. An unknown or misused function returns `#NAME?`/`#VALUE!` so the calling
|
|
9
|
+
* conditional-format rule simply does not apply — Ream never guesses.
|
|
10
|
+
*
|
|
11
|
+
* @param name The upper-cased function name (e.g. `SUM`, `VLOOKUP`).
|
|
12
|
+
* @param args The unevaluated argument expressions.
|
|
13
|
+
* @param ev Evaluator for one argument (closes over the context + shift).
|
|
14
|
+
* @param ctx The evaluation context (grid access, defined names, date system).
|
|
15
|
+
* @param shift The per-cell shift (used by no-arg `ROW`/`COLUMN`).
|
|
16
|
+
* @returns The function's result value.
|
|
17
|
+
*/
|
|
6
18
|
export declare function callFn(name: string, args: ReadonlyArray<Ast>, ev: Ev, ctx: EvalContext, shift: Shift): FValue;
|
|
7
19
|
export {};
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { serialFromYmd, serialToParts } from "./dates.js";
|
|
2
2
|
import { arrEach, bool, deref, err, isErr, num, refEach, refGet, str, toBool, toNumber, toText } from "./value.js";
|
|
3
3
|
//#region src/excel/formula/functions.ts
|
|
4
|
+
/**
|
|
5
|
+
* Dispatch a built-in formula function by name, evaluating its arguments through
|
|
6
|
+
* `ev`. An unknown or misused function returns `#NAME?`/`#VALUE!` so the calling
|
|
7
|
+
* conditional-format rule simply does not apply — Ream never guesses.
|
|
8
|
+
*
|
|
9
|
+
* @param name The upper-cased function name (e.g. `SUM`, `VLOOKUP`).
|
|
10
|
+
* @param args The unevaluated argument expressions.
|
|
11
|
+
* @param ev Evaluator for one argument (closes over the context + shift).
|
|
12
|
+
* @param ctx The evaluation context (grid access, defined names, date system).
|
|
13
|
+
* @param shift The per-cell shift (used by no-arg `ROW`/`COLUMN`).
|
|
14
|
+
* @returns The function's result value.
|
|
15
|
+
*/
|
|
4
16
|
function callFn(name, args, ev, ctx, shift) {
|
|
5
17
|
switch (name) {
|
|
6
18
|
case "TRUE": return bool(true);
|
|
@@ -7,8 +7,29 @@ export type { Scalar, FValue, Rect, FErr } from './value.js';
|
|
|
7
7
|
export { num, str, bool, err, BLANK } from './value.js';
|
|
8
8
|
export { serialFromDate, serialToParts, timePeriodMatches } from './dates.js';
|
|
9
9
|
export { NO_SHIFT, evaluate } from './eval.js';
|
|
10
|
+
/**
|
|
11
|
+
* A parsed formula, ready to evaluate against many cells (the AST is compiled once
|
|
12
|
+
* per conditional-format rule, then evaluated per covered cell with a per-cell
|
|
13
|
+
* shift).
|
|
14
|
+
*/
|
|
10
15
|
export interface CompiledFormula {
|
|
11
16
|
readonly ast: Ast;
|
|
12
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse a formula string into a {@link CompiledFormula}. Returns undefined (rather
|
|
20
|
+
* than throwing) when the formula cannot be parsed — the caller treats that as a
|
|
21
|
+
* rule that never applies, which is the correct graceful-loss behaviour for an
|
|
22
|
+
* unsupported construct.
|
|
23
|
+
*/
|
|
13
24
|
export declare function compileFormula(src: string): CompiledFormula | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Evaluate a compiled formula in a cell context and reduce it to the rule's truth
|
|
27
|
+
* test: the conditional format applies iff the result is the logical TRUE or a
|
|
28
|
+
* non-zero number (Excel §18.3.1.10). Any error / blank / text / zero — and a
|
|
29
|
+
* multi-cell result — yields false, so the rule simply does not paint.
|
|
30
|
+
*
|
|
31
|
+
* @param compiled The compiled formula from {@link compileFormula}.
|
|
32
|
+
* @param ctx The evaluation context (cached grid values + reference date).
|
|
33
|
+
* @param shift The per-cell relative-reference shift; defaults to {@link NO_SHIFT}.
|
|
34
|
+
*/
|
|
14
35
|
export declare function evaluateToBool(compiled: CompiledFormula, ctx: EvalContext, shift?: Shift): boolean;
|
|
@@ -3,6 +3,12 @@ import "./dates.js";
|
|
|
3
3
|
import { toBool } from "./value.js";
|
|
4
4
|
import { NO_SHIFT, evaluate } from "./eval.js";
|
|
5
5
|
//#region src/excel/formula/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* Parse a formula string into a {@link CompiledFormula}. Returns undefined (rather
|
|
8
|
+
* than throwing) when the formula cannot be parsed — the caller treats that as a
|
|
9
|
+
* rule that never applies, which is the correct graceful-loss behaviour for an
|
|
10
|
+
* unsupported construct.
|
|
11
|
+
*/
|
|
6
12
|
function compileFormula(src) {
|
|
7
13
|
try {
|
|
8
14
|
return { ast: parse(src) };
|
|
@@ -10,6 +16,16 @@ function compileFormula(src) {
|
|
|
10
16
|
return;
|
|
11
17
|
}
|
|
12
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Evaluate a compiled formula in a cell context and reduce it to the rule's truth
|
|
21
|
+
* test: the conditional format applies iff the result is the logical TRUE or a
|
|
22
|
+
* non-zero number (Excel §18.3.1.10). Any error / blank / text / zero — and a
|
|
23
|
+
* multi-cell result — yields false, so the rule simply does not paint.
|
|
24
|
+
*
|
|
25
|
+
* @param compiled The compiled formula from {@link compileFormula}.
|
|
26
|
+
* @param ctx The evaluation context (cached grid values + reference date).
|
|
27
|
+
* @param shift The per-cell relative-reference shift; defaults to {@link NO_SHIFT}.
|
|
28
|
+
*/
|
|
13
29
|
function evaluateToBool(compiled, ctx, shift = NO_SHIFT) {
|
|
14
30
|
return toBool(evaluate(compiled.ast, ctx, shift), ctx) === true;
|
|
15
31
|
}
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
+
/** The lexical categories the {@link tokenize} pass emits. */
|
|
1
2
|
export type TokenKind = 'num' | 'str' | 'err' | 'word' | 'sheetq' | 'op' | 'eof';
|
|
3
|
+
/** One token: its {@link TokenKind} and the matched source text. */
|
|
2
4
|
export interface Token {
|
|
3
5
|
readonly kind: TokenKind;
|
|
4
6
|
readonly text: string;
|
|
5
7
|
}
|
|
8
|
+
/** Thrown when the source cannot be tokenized (bad character, over-long input). */
|
|
6
9
|
export declare class LexError extends Error {
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Tokenize a formula string into a flat token stream terminated by an `eof`
|
|
13
|
+
* token. Whitespace separates tokens but is otherwise dropped.
|
|
14
|
+
*
|
|
15
|
+
* @param src The formula source.
|
|
16
|
+
* @returns The token list, ending with an `eof` token.
|
|
17
|
+
* @throws LexError when `src` exceeds the source cap or holds an unexpected
|
|
18
|
+
* character / bad error literal.
|
|
19
|
+
*/
|
|
8
20
|
export declare function tokenize(src: string): Array<Token>;
|
|
@@ -9,6 +9,7 @@ var KNOWN_ERRORS = new Set([
|
|
|
9
9
|
"#NUM!",
|
|
10
10
|
"#N/A"
|
|
11
11
|
]);
|
|
12
|
+
/** Thrown when the source cannot be tokenized (bad character, over-long input). */
|
|
12
13
|
var LexError = class extends Error {};
|
|
13
14
|
function isDigit(ch) {
|
|
14
15
|
return ch >= "0" && ch <= "9";
|
|
@@ -19,6 +20,15 @@ function isWordStart(ch) {
|
|
|
19
20
|
function isWordPart(ch) {
|
|
20
21
|
return isWordStart(ch) || isDigit(ch) || ch === ".";
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Tokenize a formula string into a flat token stream terminated by an `eof`
|
|
25
|
+
* token. Whitespace separates tokens but is otherwise dropped.
|
|
26
|
+
*
|
|
27
|
+
* @param src The formula source.
|
|
28
|
+
* @returns The token list, ending with an `eof` token.
|
|
29
|
+
* @throws LexError when `src` exceeds the source cap or holds an unexpected
|
|
30
|
+
* character / bad error literal.
|
|
31
|
+
*/
|
|
22
32
|
function tokenize(src) {
|
|
23
33
|
if (src.length > MAX_SOURCE) throw new LexError("formula too long");
|
|
24
34
|
const out = [];
|
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import { FErr } from './value.js';
|
|
2
|
+
/**
|
|
3
|
+
* One coordinate of a cell reference. `abs` records whether the axis was `$`
|
|
4
|
+
* anchored — an unanchored axis shifts by the cell's offset from the rule's
|
|
5
|
+
* origin when a conditional-format expression is evaluated per cell.
|
|
6
|
+
*/
|
|
2
7
|
export interface Axis {
|
|
8
|
+
/** 0-indexed row or column. */
|
|
3
9
|
readonly index: number;
|
|
10
|
+
/** Whether the axis carried a `$` anchor (stays put under the per-cell shift). */
|
|
4
11
|
readonly abs: boolean;
|
|
5
12
|
}
|
|
13
|
+
/** A single-cell reference: its column and row {@link Axis}es. */
|
|
6
14
|
export interface CellRef {
|
|
7
15
|
readonly col: Axis;
|
|
8
16
|
readonly row: Axis;
|
|
9
17
|
}
|
|
18
|
+
/** The formula syntax tree — a discriminated union over the node kind `k`. */
|
|
10
19
|
export type Ast = {
|
|
11
20
|
readonly k: 'num';
|
|
12
21
|
readonly v: number;
|
|
@@ -51,7 +60,18 @@ export type Ast = {
|
|
|
51
60
|
readonly name: string;
|
|
52
61
|
readonly args: ReadonlyArray<Ast>;
|
|
53
62
|
};
|
|
63
|
+
/** The binary operators the parser recognises (see {@link Ast} `bin` nodes). */
|
|
54
64
|
export type BinOp = '+' | '-' | '*' | '/' | '^' | '&' | '=' | '<>' | '<' | '>' | '<=' | '>=';
|
|
65
|
+
/** Thrown when the token stream is not a well-formed formula. */
|
|
55
66
|
export declare class ParseError extends Error {
|
|
56
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Parse a formula string into an {@link Ast}. Callers (the CF compiler) catch
|
|
70
|
+
* the throw and treat a parse failure as "rule does not apply" — a formula using
|
|
71
|
+
* a construct we do not model never misrenders, it just no-ops.
|
|
72
|
+
*
|
|
73
|
+
* @param src The formula source.
|
|
74
|
+
* @returns The parsed syntax tree.
|
|
75
|
+
* @throws ParseError on a malformed formula (or {@link LexError} from tokenizing).
|
|
76
|
+
*/
|
|
57
77
|
export declare function parse(src: string): Ast;
|