@cj-tech-master/excelts 9.2.1 → 9.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 +25 -2
- package/README_zh.md +29 -6
- package/dist/browser/index.browser.d.ts +1 -1
- package/dist/browser/index.browser.js +4 -0
- package/dist/browser/index.d.ts +1 -1
- package/dist/browser/index.js +4 -0
- package/dist/browser/modules/excel/cell.d.ts +17 -3
- package/dist/browser/modules/excel/cell.js +170 -22
- package/dist/browser/modules/excel/defined-names.d.ts +96 -1
- package/dist/browser/modules/excel/defined-names.js +411 -21
- package/dist/browser/modules/excel/image.d.ts +11 -0
- package/dist/browser/modules/excel/image.js +24 -1
- package/dist/browser/modules/excel/stream/workbook-reader.browser.d.ts +9 -3
- package/dist/browser/modules/excel/stream/workbook-reader.browser.js +14 -0
- package/dist/browser/modules/excel/stream/workbook-reader.d.ts +2 -1
- package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +39 -5
- package/dist/browser/modules/excel/stream/workbook-writer.browser.js +48 -1
- package/dist/browser/modules/excel/stream/workbook-writer.d.ts +3 -2
- package/dist/browser/modules/excel/stream/worksheet-reader.js +17 -1
- package/dist/browser/modules/excel/stream/worksheet-writer.d.ts +39 -6
- package/dist/browser/modules/excel/stream/worksheet-writer.js +45 -5
- package/dist/browser/modules/excel/table.js +15 -2
- package/dist/browser/modules/excel/types.d.ts +133 -2
- package/dist/browser/modules/excel/utils/col-cache.d.ts +1 -0
- package/dist/browser/modules/excel/utils/col-cache.js +15 -0
- package/dist/browser/modules/excel/utils/drawing-utils.d.ts +3 -3
- package/dist/browser/modules/excel/utils/drawing-utils.js +4 -0
- package/dist/browser/modules/excel/utils/external-link-formula.d.ts +76 -0
- package/dist/browser/modules/excel/utils/external-link-formula.js +208 -0
- package/dist/browser/modules/excel/utils/iterate-stream.d.ts +9 -3
- package/dist/browser/modules/excel/utils/iterate-stream.js +3 -1
- package/dist/browser/modules/excel/utils/ooxml-paths.d.ts +19 -0
- package/dist/browser/modules/excel/utils/ooxml-paths.js +37 -2
- package/dist/browser/modules/excel/utils/shared-strings.d.ts +8 -3
- package/dist/browser/modules/excel/utils/shared-strings.js +21 -2
- package/dist/browser/modules/excel/utils/workbook-protection.d.ts +30 -0
- package/dist/browser/modules/excel/utils/workbook-protection.js +30 -0
- package/dist/browser/modules/excel/workbook.browser.d.ts +257 -6
- package/dist/browser/modules/excel/workbook.browser.js +318 -34
- package/dist/browser/modules/excel/workbook.d.ts +1 -1
- package/dist/browser/modules/excel/worksheet.d.ts +3 -1
- package/dist/browser/modules/excel/worksheet.js +21 -2
- package/dist/browser/modules/excel/xlsx/rel-type.d.ts +15 -0
- package/dist/browser/modules/excel/xlsx/rel-type.js +16 -1
- package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +6 -5
- package/dist/browser/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
- package/dist/browser/modules/excel/xlsx/xform/book/external-link-xform.d.ts +84 -0
- package/dist/browser/modules/excel/xlsx/xform/book/external-link-xform.js +330 -0
- package/dist/browser/modules/excel/xlsx/xform/book/external-reference-xform.d.ts +17 -0
- package/dist/browser/modules/excel/xlsx/xform/book/external-reference-xform.js +24 -0
- package/dist/browser/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.d.ts +3 -0
- package/dist/browser/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
- package/dist/browser/modules/excel/xlsx/xform/book/workbook-protection-xform.d.ts +20 -0
- package/dist/browser/modules/excel/xlsx/xform/book/workbook-protection-xform.js +66 -0
- package/dist/browser/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
- package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +19 -1
- package/dist/browser/modules/excel/xlsx/xform/core/metadata-xform.d.ts +56 -0
- package/dist/browser/modules/excel/xlsx/xform/core/metadata-xform.js +158 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.d.ts +26 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +105 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
- package/dist/browser/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
- package/dist/browser/modules/excel/xlsx/xform/sheet/cell-xform.d.ts +1 -1
- package/dist/browser/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
- package/dist/browser/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
- package/dist/browser/modules/excel/xlsx/xform/sheet/ignored-errors-xform.d.ts +21 -0
- package/dist/browser/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +80 -0
- package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
- package/dist/browser/modules/excel/xlsx/xform/style/border-xform.js +4 -1
- package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +172 -13
- package/dist/browser/modules/excel/xlsx/xlsx.browser.js +410 -20
- package/dist/browser/modules/excel/xlsx/xlsx.d.ts +7 -4
- package/dist/browser/modules/excel/xlsx/xlsx.js +4 -5
- package/dist/browser/modules/formula/compile/address-utils.d.ts +62 -0
- package/dist/browser/modules/formula/compile/address-utils.js +83 -0
- package/dist/browser/modules/formula/compile/binder.d.ts +42 -0
- package/dist/browser/modules/formula/compile/binder.js +487 -0
- package/dist/browser/modules/formula/compile/bound-ast.d.ts +230 -0
- package/dist/browser/modules/formula/compile/bound-ast.js +80 -0
- package/dist/browser/modules/formula/compile/compiled-formula.d.ts +137 -0
- package/dist/browser/modules/formula/compile/compiled-formula.js +383 -0
- package/dist/browser/modules/formula/compile/dependency-analysis.d.ts +93 -0
- package/dist/browser/modules/formula/compile/dependency-analysis.js +432 -0
- package/dist/browser/modules/formula/compile/structured-ref-utils.d.ts +93 -0
- package/dist/browser/modules/formula/compile/structured-ref-utils.js +136 -0
- package/dist/browser/modules/formula/default-syntax-probe.d.ts +79 -0
- package/dist/browser/modules/formula/default-syntax-probe.js +83 -0
- package/dist/browser/modules/formula/functions/_date-context.d.ts +4 -0
- package/dist/browser/modules/formula/functions/_date-context.js +29 -0
- package/dist/browser/modules/formula/functions/_shared.d.ts +121 -0
- package/dist/browser/modules/formula/functions/_shared.js +381 -0
- package/dist/browser/modules/formula/functions/conditional.d.ts +27 -0
- package/dist/browser/modules/formula/functions/conditional.js +343 -0
- package/dist/browser/modules/formula/functions/database.d.ts +37 -0
- package/dist/browser/modules/formula/functions/database.js +274 -0
- package/dist/browser/modules/formula/functions/date.d.ts +61 -0
- package/dist/browser/modules/formula/functions/date.js +855 -0
- package/dist/browser/modules/formula/functions/dynamic-array.d.ts +23 -0
- package/dist/browser/modules/formula/functions/dynamic-array.js +860 -0
- package/dist/browser/modules/formula/functions/engineering.d.ts +57 -0
- package/dist/browser/modules/formula/functions/engineering.js +1128 -0
- package/dist/browser/modules/formula/functions/financial.d.ts +202 -0
- package/dist/browser/modules/formula/functions/financial.js +2296 -0
- package/dist/browser/modules/formula/functions/lookup.d.ts +18 -0
- package/dist/browser/modules/formula/functions/lookup.js +886 -0
- package/dist/browser/modules/formula/functions/math.d.ts +114 -0
- package/dist/browser/modules/formula/functions/math.js +1406 -0
- package/dist/browser/modules/formula/functions/statistical.d.ts +193 -0
- package/dist/browser/modules/formula/functions/statistical.js +3390 -0
- package/dist/browser/modules/formula/functions/text.d.ts +86 -0
- package/dist/browser/modules/formula/functions/text.js +1845 -0
- package/dist/browser/modules/formula/host-registry.d.ts +53 -0
- package/dist/browser/modules/formula/host-registry.js +69 -0
- package/dist/browser/modules/formula/index.d.ts +39 -0
- package/dist/browser/modules/formula/index.js +49 -0
- package/dist/browser/modules/formula/install.d.ts +62 -0
- package/dist/browser/modules/formula/install.js +88 -0
- package/dist/browser/modules/formula/integration/apply-writeback-plan.d.ts +26 -0
- package/dist/browser/modules/formula/integration/apply-writeback-plan.js +210 -0
- package/dist/browser/modules/formula/integration/calculate-formulas-impl.d.ts +30 -0
- package/dist/browser/modules/formula/integration/calculate-formulas-impl.js +616 -0
- package/dist/browser/modules/formula/integration/calculate-formulas.d.ts +67 -0
- package/dist/browser/modules/formula/integration/calculate-formulas.js +68 -0
- package/dist/browser/modules/formula/integration/formula-instance.d.ts +64 -0
- package/dist/browser/modules/formula/integration/formula-instance.js +79 -0
- package/dist/browser/modules/formula/integration/workbook-adapter.d.ts +26 -0
- package/dist/browser/modules/formula/integration/workbook-adapter.js +324 -0
- package/dist/browser/modules/formula/integration/workbook-snapshot.d.ts +267 -0
- package/dist/browser/modules/formula/integration/workbook-snapshot.js +77 -0
- package/dist/browser/modules/formula/materialize/build-writeback-plan.d.ts +34 -0
- package/dist/browser/modules/formula/materialize/build-writeback-plan.js +473 -0
- package/dist/browser/modules/formula/materialize/spill-engine.d.ts +9 -0
- package/dist/browser/modules/formula/materialize/spill-engine.js +38 -0
- package/dist/browser/modules/formula/materialize/types.d.ts +179 -0
- package/dist/browser/modules/formula/materialize/types.js +29 -0
- package/dist/browser/modules/formula/materialize/writeback-plan.d.ts +167 -0
- package/dist/browser/modules/formula/materialize/writeback-plan.js +27 -0
- package/dist/browser/modules/formula/runtime/evaluator.d.ts +151 -0
- package/dist/browser/modules/formula/runtime/evaluator.js +2291 -0
- package/dist/browser/modules/formula/runtime/function-registry.d.ts +47 -0
- package/dist/browser/modules/formula/runtime/function-registry.js +840 -0
- package/dist/browser/modules/formula/runtime/values.d.ts +211 -0
- package/dist/browser/modules/formula/runtime/values.js +385 -0
- package/dist/browser/modules/formula/syntax/ast.d.ts +129 -0
- package/dist/browser/modules/formula/syntax/ast.js +28 -0
- package/dist/browser/modules/formula/syntax/parser.d.ts +18 -0
- package/dist/browser/modules/formula/syntax/parser.js +439 -0
- package/dist/browser/modules/formula/syntax/token-types.d.ts +153 -0
- package/dist/browser/modules/formula/syntax/token-types.js +59 -0
- package/dist/browser/modules/formula/syntax/tokenizer.d.ts +10 -0
- package/dist/browser/modules/formula/syntax/tokenizer.js +1074 -0
- package/dist/browser/modules/pdf/excel-bridge.js +9 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/modules/excel/cell.js +170 -22
- package/dist/cjs/modules/excel/defined-names.js +411 -21
- package/dist/cjs/modules/excel/image.js +24 -1
- package/dist/cjs/modules/excel/stream/workbook-reader.browser.js +14 -0
- package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +48 -1
- package/dist/cjs/modules/excel/stream/worksheet-reader.js +17 -1
- package/dist/cjs/modules/excel/stream/worksheet-writer.js +45 -5
- package/dist/cjs/modules/excel/table.js +15 -2
- package/dist/cjs/modules/excel/utils/col-cache.js +15 -0
- package/dist/cjs/modules/excel/utils/drawing-utils.js +4 -0
- package/dist/cjs/modules/excel/utils/external-link-formula.js +212 -0
- package/dist/cjs/modules/excel/utils/iterate-stream.js +3 -1
- package/dist/cjs/modules/excel/utils/ooxml-paths.js +42 -2
- package/dist/cjs/modules/excel/utils/shared-strings.js +21 -2
- package/dist/cjs/modules/excel/utils/workbook-protection.js +33 -0
- package/dist/cjs/modules/excel/workbook.browser.js +318 -34
- package/dist/cjs/modules/excel/worksheet.js +20 -1
- package/dist/cjs/modules/excel/xlsx/rel-type.js +16 -1
- package/dist/cjs/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
- package/dist/cjs/modules/excel/xlsx/xform/book/external-link-xform.js +333 -0
- package/dist/cjs/modules/excel/xlsx/xform/book/external-reference-xform.js +27 -0
- package/dist/cjs/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
- package/dist/cjs/modules/excel/xlsx/xform/book/workbook-protection-xform.js +69 -0
- package/dist/cjs/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
- package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +18 -0
- package/dist/cjs/modules/excel/xlsx/xform/core/metadata-xform.js +161 -0
- package/dist/cjs/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +108 -0
- package/dist/cjs/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
- package/dist/cjs/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
- package/dist/cjs/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
- package/dist/cjs/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
- package/dist/cjs/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +83 -0
- package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
- package/dist/cjs/modules/excel/xlsx/xform/style/border-xform.js +4 -1
- package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +408 -18
- package/dist/cjs/modules/excel/xlsx/xlsx.js +4 -5
- package/dist/cjs/modules/formula/compile/address-utils.js +89 -0
- package/dist/cjs/modules/formula/compile/binder.js +489 -0
- package/dist/cjs/modules/formula/compile/bound-ast.js +68 -0
- package/dist/cjs/modules/formula/compile/compiled-formula.js +387 -0
- package/dist/cjs/modules/formula/compile/dependency-analysis.js +437 -0
- package/dist/cjs/modules/formula/compile/structured-ref-utils.js +141 -0
- package/dist/cjs/modules/formula/default-syntax-probe.js +87 -0
- package/dist/cjs/modules/formula/functions/_date-context.js +33 -0
- package/dist/cjs/modules/formula/functions/_shared.js +396 -0
- package/dist/cjs/modules/formula/functions/conditional.js +354 -0
- package/dist/cjs/modules/formula/functions/database.js +288 -0
- package/dist/cjs/modules/formula/functions/date.js +883 -0
- package/dist/cjs/modules/formula/functions/dynamic-array.js +881 -0
- package/dist/cjs/modules/formula/functions/engineering.js +1183 -0
- package/dist/cjs/modules/formula/functions/financial.js +2348 -0
- package/dist/cjs/modules/formula/functions/lookup.js +902 -0
- package/dist/cjs/modules/formula/functions/math.js +1487 -0
- package/dist/cjs/modules/formula/functions/statistical.js +3488 -0
- package/dist/cjs/modules/formula/functions/text.js +1889 -0
- package/dist/cjs/modules/formula/host-registry.js +75 -0
- package/dist/cjs/modules/formula/index.js +58 -0
- package/dist/cjs/modules/formula/install.js +93 -0
- package/dist/cjs/modules/formula/integration/apply-writeback-plan.js +213 -0
- package/dist/cjs/modules/formula/integration/calculate-formulas-impl.js +619 -0
- package/dist/cjs/modules/formula/integration/calculate-formulas.js +71 -0
- package/dist/cjs/modules/formula/integration/formula-instance.js +82 -0
- package/dist/cjs/modules/formula/integration/workbook-adapter.js +327 -0
- package/dist/cjs/modules/formula/integration/workbook-snapshot.js +84 -0
- package/dist/cjs/modules/formula/materialize/build-writeback-plan.js +475 -0
- package/dist/cjs/modules/formula/materialize/spill-engine.js +42 -0
- package/dist/cjs/modules/formula/materialize/types.js +32 -0
- package/dist/cjs/modules/formula/materialize/writeback-plan.js +28 -0
- package/dist/cjs/modules/formula/runtime/evaluator.js +2298 -0
- package/dist/cjs/modules/formula/runtime/function-registry.js +846 -0
- package/dist/cjs/modules/formula/runtime/values.js +385 -0
- package/dist/cjs/modules/formula/syntax/ast.js +8 -0
- package/dist/cjs/modules/formula/syntax/parser.js +440 -0
- package/dist/cjs/modules/formula/syntax/token-types.js +32 -0
- package/dist/cjs/modules/formula/syntax/tokenizer.js +1076 -0
- package/dist/cjs/modules/pdf/excel-bridge.js +9 -0
- package/dist/esm/index.browser.js +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/modules/excel/cell.js +170 -22
- package/dist/esm/modules/excel/defined-names.js +411 -21
- package/dist/esm/modules/excel/image.js +24 -1
- package/dist/esm/modules/excel/stream/workbook-reader.browser.js +14 -0
- package/dist/esm/modules/excel/stream/workbook-writer.browser.js +48 -1
- package/dist/esm/modules/excel/stream/worksheet-reader.js +17 -1
- package/dist/esm/modules/excel/stream/worksheet-writer.js +45 -5
- package/dist/esm/modules/excel/table.js +15 -2
- package/dist/esm/modules/excel/utils/col-cache.js +15 -0
- package/dist/esm/modules/excel/utils/drawing-utils.js +4 -0
- package/dist/esm/modules/excel/utils/external-link-formula.js +208 -0
- package/dist/esm/modules/excel/utils/iterate-stream.js +3 -1
- package/dist/esm/modules/excel/utils/ooxml-paths.js +37 -2
- package/dist/esm/modules/excel/utils/shared-strings.js +21 -2
- package/dist/esm/modules/excel/utils/workbook-protection.js +30 -0
- package/dist/esm/modules/excel/workbook.browser.js +318 -34
- package/dist/esm/modules/excel/worksheet.js +21 -2
- package/dist/esm/modules/excel/xlsx/rel-type.js +16 -1
- package/dist/esm/modules/excel/xlsx/xform/book/defined-name-xform.js +21 -86
- package/dist/esm/modules/excel/xlsx/xform/book/external-link-xform.js +330 -0
- package/dist/esm/modules/excel/xlsx/xform/book/external-reference-xform.js +24 -0
- package/dist/esm/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.js +11 -2
- package/dist/esm/modules/excel/xlsx/xform/book/workbook-protection-xform.js +66 -0
- package/dist/esm/modules/excel/xlsx/xform/book/workbook-xform.js +38 -5
- package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +19 -1
- package/dist/esm/modules/excel/xlsx/xform/core/metadata-xform.js +158 -0
- package/dist/esm/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +105 -0
- package/dist/esm/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +3 -0
- package/dist/esm/modules/excel/xlsx/xform/drawing/drawing-xform.js +10 -2
- package/dist/esm/modules/excel/xlsx/xform/sheet/cell-xform.js +166 -8
- package/dist/esm/modules/excel/xlsx/xform/sheet/data-validations-xform.js +1 -1
- package/dist/esm/modules/excel/xlsx/xform/sheet/ignored-errors-xform.js +80 -0
- package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +9 -4
- package/dist/esm/modules/excel/xlsx/xform/style/border-xform.js +4 -1
- package/dist/esm/modules/excel/xlsx/xlsx.browser.js +410 -20
- package/dist/esm/modules/excel/xlsx/xlsx.js +4 -5
- package/dist/esm/modules/formula/compile/address-utils.js +83 -0
- package/dist/esm/modules/formula/compile/binder.js +487 -0
- package/dist/esm/modules/formula/compile/bound-ast.js +80 -0
- package/dist/esm/modules/formula/compile/compiled-formula.js +383 -0
- package/dist/esm/modules/formula/compile/dependency-analysis.js +432 -0
- package/dist/esm/modules/formula/compile/structured-ref-utils.js +136 -0
- package/dist/esm/modules/formula/default-syntax-probe.js +83 -0
- package/dist/esm/modules/formula/functions/_date-context.js +29 -0
- package/dist/esm/modules/formula/functions/_shared.js +381 -0
- package/dist/esm/modules/formula/functions/conditional.js +343 -0
- package/dist/esm/modules/formula/functions/database.js +274 -0
- package/dist/esm/modules/formula/functions/date.js +855 -0
- package/dist/esm/modules/formula/functions/dynamic-array.js +860 -0
- package/dist/esm/modules/formula/functions/engineering.js +1128 -0
- package/dist/esm/modules/formula/functions/financial.js +2296 -0
- package/dist/esm/modules/formula/functions/lookup.js +886 -0
- package/dist/esm/modules/formula/functions/math.js +1406 -0
- package/dist/esm/modules/formula/functions/statistical.js +3390 -0
- package/dist/esm/modules/formula/functions/text.js +1845 -0
- package/dist/esm/modules/formula/host-registry.js +69 -0
- package/dist/esm/modules/formula/index.js +49 -0
- package/dist/esm/modules/formula/install.js +88 -0
- package/dist/esm/modules/formula/integration/apply-writeback-plan.js +210 -0
- package/dist/esm/modules/formula/integration/calculate-formulas-impl.js +616 -0
- package/dist/esm/modules/formula/integration/calculate-formulas.js +68 -0
- package/dist/esm/modules/formula/integration/formula-instance.js +79 -0
- package/dist/esm/modules/formula/integration/workbook-adapter.js +324 -0
- package/dist/esm/modules/formula/integration/workbook-snapshot.js +77 -0
- package/dist/esm/modules/formula/materialize/build-writeback-plan.js +473 -0
- package/dist/esm/modules/formula/materialize/spill-engine.js +38 -0
- package/dist/esm/modules/formula/materialize/types.js +29 -0
- package/dist/esm/modules/formula/materialize/writeback-plan.js +27 -0
- package/dist/esm/modules/formula/runtime/evaluator.js +2291 -0
- package/dist/esm/modules/formula/runtime/function-registry.js +840 -0
- package/dist/esm/modules/formula/runtime/values.js +385 -0
- package/dist/esm/modules/formula/syntax/ast.js +28 -0
- package/dist/esm/modules/formula/syntax/parser.js +439 -0
- package/dist/esm/modules/formula/syntax/token-types.js +59 -0
- package/dist/esm/modules/formula/syntax/tokenizer.js +1074 -0
- package/dist/esm/modules/pdf/excel-bridge.js +9 -0
- package/dist/iife/excelts.iife.js +2302 -373
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +34 -34
- package/dist/types/index.browser.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/modules/excel/cell.d.ts +17 -3
- package/dist/types/modules/excel/defined-names.d.ts +96 -1
- package/dist/types/modules/excel/image.d.ts +11 -0
- package/dist/types/modules/excel/stream/workbook-reader.browser.d.ts +9 -3
- package/dist/types/modules/excel/stream/workbook-reader.d.ts +2 -1
- package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +39 -5
- package/dist/types/modules/excel/stream/workbook-writer.d.ts +3 -2
- package/dist/types/modules/excel/stream/worksheet-writer.d.ts +39 -6
- package/dist/types/modules/excel/types.d.ts +133 -2
- package/dist/types/modules/excel/utils/col-cache.d.ts +1 -0
- package/dist/types/modules/excel/utils/drawing-utils.d.ts +3 -3
- package/dist/types/modules/excel/utils/external-link-formula.d.ts +76 -0
- package/dist/types/modules/excel/utils/iterate-stream.d.ts +9 -3
- package/dist/types/modules/excel/utils/ooxml-paths.d.ts +19 -0
- package/dist/types/modules/excel/utils/shared-strings.d.ts +8 -3
- package/dist/types/modules/excel/utils/workbook-protection.d.ts +30 -0
- package/dist/types/modules/excel/workbook.browser.d.ts +257 -6
- package/dist/types/modules/excel/workbook.d.ts +1 -1
- package/dist/types/modules/excel/worksheet.d.ts +3 -1
- package/dist/types/modules/excel/xlsx/rel-type.d.ts +15 -0
- package/dist/types/modules/excel/xlsx/xform/book/defined-name-xform.d.ts +6 -5
- package/dist/types/modules/excel/xlsx/xform/book/external-link-xform.d.ts +84 -0
- package/dist/types/modules/excel/xlsx/xform/book/external-reference-xform.d.ts +17 -0
- package/dist/types/modules/excel/xlsx/xform/book/workbook-calc-properties-xform.d.ts +3 -0
- package/dist/types/modules/excel/xlsx/xform/book/workbook-protection-xform.d.ts +20 -0
- package/dist/types/modules/excel/xlsx/xform/core/metadata-xform.d.ts +56 -0
- package/dist/types/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.d.ts +26 -0
- package/dist/types/modules/excel/xlsx/xform/sheet/cell-xform.d.ts +1 -1
- package/dist/types/modules/excel/xlsx/xform/sheet/ignored-errors-xform.d.ts +21 -0
- package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +172 -13
- package/dist/types/modules/excel/xlsx/xlsx.d.ts +7 -4
- package/dist/types/modules/formula/compile/address-utils.d.ts +62 -0
- package/dist/types/modules/formula/compile/binder.d.ts +42 -0
- package/dist/types/modules/formula/compile/bound-ast.d.ts +230 -0
- package/dist/types/modules/formula/compile/compiled-formula.d.ts +137 -0
- package/dist/types/modules/formula/compile/dependency-analysis.d.ts +93 -0
- package/dist/types/modules/formula/compile/structured-ref-utils.d.ts +93 -0
- package/dist/types/modules/formula/default-syntax-probe.d.ts +79 -0
- package/dist/types/modules/formula/functions/_date-context.d.ts +4 -0
- package/dist/types/modules/formula/functions/_shared.d.ts +121 -0
- package/dist/types/modules/formula/functions/conditional.d.ts +27 -0
- package/dist/types/modules/formula/functions/database.d.ts +37 -0
- package/dist/types/modules/formula/functions/date.d.ts +61 -0
- package/dist/types/modules/formula/functions/dynamic-array.d.ts +23 -0
- package/dist/types/modules/formula/functions/engineering.d.ts +57 -0
- package/dist/types/modules/formula/functions/financial.d.ts +202 -0
- package/dist/types/modules/formula/functions/lookup.d.ts +18 -0
- package/dist/types/modules/formula/functions/math.d.ts +114 -0
- package/dist/types/modules/formula/functions/statistical.d.ts +193 -0
- package/dist/types/modules/formula/functions/text.d.ts +86 -0
- package/dist/types/modules/formula/host-registry.d.ts +53 -0
- package/dist/types/modules/formula/index.d.ts +39 -0
- package/dist/types/modules/formula/install.d.ts +62 -0
- package/dist/types/modules/formula/integration/apply-writeback-plan.d.ts +26 -0
- package/dist/types/modules/formula/integration/calculate-formulas-impl.d.ts +30 -0
- package/dist/types/modules/formula/integration/calculate-formulas.d.ts +67 -0
- package/dist/types/modules/formula/integration/formula-instance.d.ts +64 -0
- package/dist/types/modules/formula/integration/workbook-adapter.d.ts +26 -0
- package/dist/types/modules/formula/integration/workbook-snapshot.d.ts +267 -0
- package/dist/types/modules/formula/materialize/build-writeback-plan.d.ts +34 -0
- package/dist/types/modules/formula/materialize/spill-engine.d.ts +9 -0
- package/dist/types/modules/formula/materialize/types.d.ts +179 -0
- package/dist/types/modules/formula/materialize/writeback-plan.d.ts +167 -0
- package/dist/types/modules/formula/runtime/evaluator.d.ts +151 -0
- package/dist/types/modules/formula/runtime/function-registry.d.ts +47 -0
- package/dist/types/modules/formula/runtime/values.d.ts +211 -0
- package/dist/types/modules/formula/syntax/ast.d.ts +129 -0
- package/dist/types/modules/formula/syntax/parser.d.ts +18 -0
- package/dist/types/modules/formula/syntax/token-types.d.ts +153 -0
- package/dist/types/modules/formula/syntax/tokenizer.d.ts +10 -0
- package/package.json +28 -28
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Value System — The engine's canonical value representation.
|
|
3
|
+
*
|
|
4
|
+
* Every value that flows through the formula evaluator is a `RuntimeValue`.
|
|
5
|
+
* This is a properly tagged discriminated union that all function
|
|
6
|
+
* implementations operate on directly — no adapter layer.
|
|
7
|
+
*
|
|
8
|
+
* ## Design Principles
|
|
9
|
+
*
|
|
10
|
+
* 1. **No Date objects** — dates are represented as their Excel serial
|
|
11
|
+
* number (a plain `number`). Date formatting is an output concern.
|
|
12
|
+
* 2. **No monkey-patched arrays** — `ArrayValue` is a proper type with
|
|
13
|
+
* explicit `height`, `width`, and optional origin metadata.
|
|
14
|
+
* 3. **Reference is a first-class value** — `ReferenceValue` can flow
|
|
15
|
+
* through the evaluator and be passed to functions.
|
|
16
|
+
* 4. **Error codes are strict** — `ErrorValue` uses a typed code enum.
|
|
17
|
+
* 5. **Lambda is a value** — `LambdaValue` is part of the value union.
|
|
18
|
+
*/
|
|
19
|
+
import type { BoundExpr } from "../compile/bound-ast.js";
|
|
20
|
+
import type { ErrorCode } from "../integration/workbook-snapshot.js";
|
|
21
|
+
export declare const enum RVKind {
|
|
22
|
+
/** Empty cell / blank. Numeric value 0, string value "". */
|
|
23
|
+
Blank = 0,
|
|
24
|
+
/** A number (includes dates as serial numbers). */
|
|
25
|
+
Number = 1,
|
|
26
|
+
/** A string. */
|
|
27
|
+
String = 2,
|
|
28
|
+
/** A boolean (TRUE / FALSE). */
|
|
29
|
+
Boolean = 3,
|
|
30
|
+
/** An error value (#N/A, #VALUE!, etc.). */
|
|
31
|
+
Error = 4,
|
|
32
|
+
/** A 2D array of scalar values. */
|
|
33
|
+
Array = 5,
|
|
34
|
+
/** A cell or area reference (lazy — not yet resolved to values). */
|
|
35
|
+
Reference = 6,
|
|
36
|
+
/** A lambda (closure). */
|
|
37
|
+
Lambda = 7
|
|
38
|
+
}
|
|
39
|
+
export interface BlankValue {
|
|
40
|
+
readonly kind: RVKind.Blank;
|
|
41
|
+
}
|
|
42
|
+
export interface NumberValue {
|
|
43
|
+
readonly kind: RVKind.Number;
|
|
44
|
+
readonly value: number;
|
|
45
|
+
}
|
|
46
|
+
export interface StringValue {
|
|
47
|
+
readonly kind: RVKind.String;
|
|
48
|
+
readonly value: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BooleanValue {
|
|
51
|
+
readonly kind: RVKind.Boolean;
|
|
52
|
+
readonly value: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface ErrorValue {
|
|
55
|
+
readonly kind: RVKind.Error;
|
|
56
|
+
readonly code: ErrorCode;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A 2D array of scalar values.
|
|
60
|
+
*
|
|
61
|
+
* `rows[r][c]` is a `ScalarValue`. Arrays are always rectangular.
|
|
62
|
+
* Origin metadata (for implicit intersection) is carried inline.
|
|
63
|
+
*/
|
|
64
|
+
export interface ArrayValue {
|
|
65
|
+
readonly kind: RVKind.Array;
|
|
66
|
+
/** Rows of scalar values. rows[0] is the first row. */
|
|
67
|
+
readonly rows: readonly (readonly ScalarValue[])[];
|
|
68
|
+
/** Number of rows. */
|
|
69
|
+
readonly height: number;
|
|
70
|
+
/** Number of columns. */
|
|
71
|
+
readonly width: number;
|
|
72
|
+
/** Origin row in the worksheet (1-based). Used for implicit intersection. */
|
|
73
|
+
readonly originRow?: number;
|
|
74
|
+
/** Origin column in the worksheet (1-based). Used for implicit intersection. */
|
|
75
|
+
readonly originCol?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Per-cell mask marking cells whose source formula is SUBTOTAL or
|
|
78
|
+
* AGGREGATE. When a range is passed to an outer SUBTOTAL/AGGREGATE
|
|
79
|
+
* call, those cells must be skipped so their results are not
|
|
80
|
+
* double-counted (Excel semantics — standard totals-row behavior).
|
|
81
|
+
*
|
|
82
|
+
* Same shape as `rows`: `subtotalMask[r][c]` is true when the cell
|
|
83
|
+
* should be excluded from outer SUBTOTAL/AGGREGATE aggregation.
|
|
84
|
+
* Omitted when no cell in the array is a SUBTOTAL/AGGREGATE output.
|
|
85
|
+
*/
|
|
86
|
+
readonly subtotalMask?: readonly (readonly boolean[])[];
|
|
87
|
+
/**
|
|
88
|
+
* Per-row mask marking rows whose source worksheet row is hidden.
|
|
89
|
+
* Used by SUBTOTAL's 1xx-variant codes (101-111) and by AGGREGATE
|
|
90
|
+
* options 5/7 to skip hidden rows. `hiddenRowMask[r]` is true when
|
|
91
|
+
* row `r` of the array should be excluded under those semantics.
|
|
92
|
+
* Omitted when no row in the array is hidden.
|
|
93
|
+
*/
|
|
94
|
+
readonly hiddenRowMask?: readonly boolean[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The shape of a reference.
|
|
98
|
+
*/
|
|
99
|
+
export type RefArea = {
|
|
100
|
+
readonly sheet: string;
|
|
101
|
+
readonly top: number;
|
|
102
|
+
readonly left: number;
|
|
103
|
+
readonly bottom: number;
|
|
104
|
+
readonly right: number;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* A reference value that represents one or more areas in the workbook.
|
|
108
|
+
*
|
|
109
|
+
* References are first-class values in the new engine — they can be
|
|
110
|
+
* passed to functions, returned from functions, and stored in variables.
|
|
111
|
+
* They are resolved to actual values lazily when needed.
|
|
112
|
+
*/
|
|
113
|
+
export interface ReferenceValue {
|
|
114
|
+
readonly kind: RVKind.Reference;
|
|
115
|
+
/** The areas this reference covers. Usually one, but UNION produces multiple. */
|
|
116
|
+
readonly areas: readonly RefArea[];
|
|
117
|
+
/** Whether this reference originated from a single-cell ref (A1) vs an area ref (A1:A1). */
|
|
118
|
+
readonly singleCell?: boolean;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* A lambda closure value.
|
|
122
|
+
*/
|
|
123
|
+
export interface LambdaValue {
|
|
124
|
+
readonly kind: RVKind.Lambda;
|
|
125
|
+
/** Parameter names (uppercase). */
|
|
126
|
+
readonly params: readonly string[];
|
|
127
|
+
/** The body expression to evaluate when called. */
|
|
128
|
+
readonly body: BoundExpr;
|
|
129
|
+
/** Captured variable bindings from the enclosing scope. */
|
|
130
|
+
readonly closureBindings?: ReadonlyMap<string, RuntimeValue>;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A scalar value (non-array, non-reference, non-lambda).
|
|
134
|
+
*/
|
|
135
|
+
export type ScalarValue = BlankValue | NumberValue | StringValue | BooleanValue | ErrorValue;
|
|
136
|
+
/**
|
|
137
|
+
* Any value that can flow through the evaluator.
|
|
138
|
+
*/
|
|
139
|
+
export type RuntimeValue = BlankValue | NumberValue | StringValue | BooleanValue | ErrorValue | ArrayValue | ReferenceValue | LambdaValue;
|
|
140
|
+
/** The singleton blank value. */
|
|
141
|
+
export declare const BLANK: BlankValue;
|
|
142
|
+
/** Common error values. */
|
|
143
|
+
export declare const ERRORS: {
|
|
144
|
+
readonly VALUE: ErrorValue;
|
|
145
|
+
readonly REF: ErrorValue;
|
|
146
|
+
readonly NAME: ErrorValue;
|
|
147
|
+
readonly DIV0: ErrorValue;
|
|
148
|
+
readonly NA: ErrorValue;
|
|
149
|
+
readonly NUM: ErrorValue;
|
|
150
|
+
readonly NULL: ErrorValue;
|
|
151
|
+
readonly SPILL: ErrorValue;
|
|
152
|
+
readonly CALC: ErrorValue;
|
|
153
|
+
};
|
|
154
|
+
export declare function rvNumber(value: number): NumberValue;
|
|
155
|
+
export declare function rvString(value: string): StringValue;
|
|
156
|
+
export declare function rvBoolean(value: boolean): BooleanValue;
|
|
157
|
+
export declare function rvError(code: ErrorCode): ErrorValue;
|
|
158
|
+
export declare function rvArray(rows: ScalarValue[][], originRow?: number, originCol?: number, subtotalMask?: readonly (readonly boolean[])[], hiddenRowMask?: readonly boolean[]): ArrayValue;
|
|
159
|
+
export declare function rvRef(sheet: string, top: number, left: number, bottom: number, right: number): ReferenceValue;
|
|
160
|
+
export declare function rvCellRef(sheet: string, row: number, col: number): ReferenceValue;
|
|
161
|
+
export declare function rvLambda(params: string[], body: BoundExpr, closureBindings?: ReadonlyMap<string, RuntimeValue>): LambdaValue;
|
|
162
|
+
export declare function isError(v: RuntimeValue): v is ErrorValue;
|
|
163
|
+
export declare function isArray(v: RuntimeValue): v is ArrayValue;
|
|
164
|
+
export declare function isLambda(v: RuntimeValue): v is LambdaValue;
|
|
165
|
+
export declare function isScalar(v: RuntimeValue): v is ScalarValue;
|
|
166
|
+
/**
|
|
167
|
+
* Coerce a runtime value to a number.
|
|
168
|
+
* - Blank → 0
|
|
169
|
+
* - Number → itself
|
|
170
|
+
* - Boolean → 1 / 0
|
|
171
|
+
* - String → parse or #VALUE!
|
|
172
|
+
* - Error → propagate
|
|
173
|
+
*/
|
|
174
|
+
export declare function toNumberRV(v: RuntimeValue): NumberValue | ErrorValue;
|
|
175
|
+
/**
|
|
176
|
+
* Coerce a runtime value to a string.
|
|
177
|
+
*/
|
|
178
|
+
export declare function toStringRV(v: RuntimeValue): string;
|
|
179
|
+
/**
|
|
180
|
+
* Coerce a runtime value to a boolean.
|
|
181
|
+
*/
|
|
182
|
+
export declare function toBooleanRV(v: RuntimeValue): BooleanValue | ErrorValue;
|
|
183
|
+
/**
|
|
184
|
+
* Structural equality of scalar values.
|
|
185
|
+
*
|
|
186
|
+
* - Different kinds → false
|
|
187
|
+
* - Number / Boolean / Blank → strict value equality (Blank always equal)
|
|
188
|
+
* - String → case-insensitive comparison (Excel semantics)
|
|
189
|
+
* - Error → not equal (errors do not compare equal to each other)
|
|
190
|
+
*/
|
|
191
|
+
/**
|
|
192
|
+
* Three-way compare two scalars that share a kind.
|
|
193
|
+
*
|
|
194
|
+
* Returns a negative number if `a < b`, zero if equal, positive if `a > b`.
|
|
195
|
+
* Returns `NaN` when the kinds differ or cannot be ordered (e.g. errors);
|
|
196
|
+
* callers decide how to surface the incomparability — sort helpers usually
|
|
197
|
+
* skip NaN pairs, while comparison operators route to a kind-priority
|
|
198
|
+
* tiebreak. Strings are compared case-insensitively to match Excel.
|
|
199
|
+
*/
|
|
200
|
+
export declare function compareScalarsSameKind(a: ScalarValue, b: ScalarValue): number;
|
|
201
|
+
export declare function scalarEquals(a: ScalarValue, b: ScalarValue): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Get the top-left scalar from any value (for implicit intersection fallback).
|
|
204
|
+
*/
|
|
205
|
+
export declare function topLeft(v: RuntimeValue): ScalarValue;
|
|
206
|
+
/**
|
|
207
|
+
* Convert a SnapshotCellValue to a RuntimeValue.
|
|
208
|
+
*/
|
|
209
|
+
export declare function fromSnapshotValue(v: number | string | boolean | {
|
|
210
|
+
error: string;
|
|
211
|
+
} | null): ScalarValue;
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Value System — The engine's canonical value representation.
|
|
3
|
+
*
|
|
4
|
+
* Every value that flows through the formula evaluator is a `RuntimeValue`.
|
|
5
|
+
* This is a properly tagged discriminated union that all function
|
|
6
|
+
* implementations operate on directly — no adapter layer.
|
|
7
|
+
*
|
|
8
|
+
* ## Design Principles
|
|
9
|
+
*
|
|
10
|
+
* 1. **No Date objects** — dates are represented as their Excel serial
|
|
11
|
+
* number (a plain `number`). Date formatting is an output concern.
|
|
12
|
+
* 2. **No monkey-patched arrays** — `ArrayValue` is a proper type with
|
|
13
|
+
* explicit `height`, `width`, and optional origin metadata.
|
|
14
|
+
* 3. **Reference is a first-class value** — `ReferenceValue` can flow
|
|
15
|
+
* through the evaluator and be passed to functions.
|
|
16
|
+
* 4. **Error codes are strict** — `ErrorValue` uses a typed code enum.
|
|
17
|
+
* 5. **Lambda is a value** — `LambdaValue` is part of the value union.
|
|
18
|
+
*/
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Value Tag Enum
|
|
21
|
+
// ============================================================================
|
|
22
|
+
export var RVKind;
|
|
23
|
+
(function (RVKind) {
|
|
24
|
+
/** Empty cell / blank. Numeric value 0, string value "". */
|
|
25
|
+
RVKind[RVKind["Blank"] = 0] = "Blank";
|
|
26
|
+
/** A number (includes dates as serial numbers). */
|
|
27
|
+
RVKind[RVKind["Number"] = 1] = "Number";
|
|
28
|
+
/** A string. */
|
|
29
|
+
RVKind[RVKind["String"] = 2] = "String";
|
|
30
|
+
/** A boolean (TRUE / FALSE). */
|
|
31
|
+
RVKind[RVKind["Boolean"] = 3] = "Boolean";
|
|
32
|
+
/** An error value (#N/A, #VALUE!, etc.). */
|
|
33
|
+
RVKind[RVKind["Error"] = 4] = "Error";
|
|
34
|
+
/** A 2D array of scalar values. */
|
|
35
|
+
RVKind[RVKind["Array"] = 5] = "Array";
|
|
36
|
+
/** A cell or area reference (lazy — not yet resolved to values). */
|
|
37
|
+
RVKind[RVKind["Reference"] = 6] = "Reference";
|
|
38
|
+
/** A lambda (closure). */
|
|
39
|
+
RVKind[RVKind["Lambda"] = 7] = "Lambda";
|
|
40
|
+
})(RVKind || (RVKind = {}));
|
|
41
|
+
// ============================================================================
|
|
42
|
+
// Singleton Constants
|
|
43
|
+
// ============================================================================
|
|
44
|
+
/** The singleton blank value. */
|
|
45
|
+
export const BLANK = { kind: RVKind.Blank };
|
|
46
|
+
/** Common error values. */
|
|
47
|
+
export const ERRORS = {
|
|
48
|
+
VALUE: { kind: RVKind.Error, code: "#VALUE!" },
|
|
49
|
+
REF: { kind: RVKind.Error, code: "#REF!" },
|
|
50
|
+
NAME: { kind: RVKind.Error, code: "#NAME?" },
|
|
51
|
+
DIV0: { kind: RVKind.Error, code: "#DIV/0!" },
|
|
52
|
+
NA: { kind: RVKind.Error, code: "#N/A" },
|
|
53
|
+
NUM: { kind: RVKind.Error, code: "#NUM!" },
|
|
54
|
+
NULL: { kind: RVKind.Error, code: "#NULL!" },
|
|
55
|
+
SPILL: { kind: RVKind.Error, code: "#SPILL!" },
|
|
56
|
+
CALC: { kind: RVKind.Error, code: "#CALC!" }
|
|
57
|
+
};
|
|
58
|
+
// ============================================================================
|
|
59
|
+
// Constructor Helpers
|
|
60
|
+
// ============================================================================
|
|
61
|
+
export function rvNumber(value) {
|
|
62
|
+
return { kind: RVKind.Number, value };
|
|
63
|
+
}
|
|
64
|
+
export function rvString(value) {
|
|
65
|
+
return { kind: RVKind.String, value };
|
|
66
|
+
}
|
|
67
|
+
export function rvBoolean(value) {
|
|
68
|
+
return { kind: RVKind.Boolean, value };
|
|
69
|
+
}
|
|
70
|
+
export function rvError(code) {
|
|
71
|
+
return { kind: RVKind.Error, code };
|
|
72
|
+
}
|
|
73
|
+
export function rvArray(rows, originRow, originCol, subtotalMask, hiddenRowMask) {
|
|
74
|
+
const height = rows.length;
|
|
75
|
+
// Determine max width across all rows for rectangular normalisation.
|
|
76
|
+
let width = 0;
|
|
77
|
+
for (const row of rows) {
|
|
78
|
+
if (row.length > width) {
|
|
79
|
+
width = row.length;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Pad short rows with BLANK so the resulting ArrayValue is rectangular.
|
|
83
|
+
// The old implementation did `row.push(BLANK)` directly — mutating the
|
|
84
|
+
// caller's arrays. Callers that shared row references across multiple
|
|
85
|
+
// `rvArray` calls could observe surprise modifications; we now copy any
|
|
86
|
+
// row that needs padding and leave the caller's arrays untouched.
|
|
87
|
+
let normalisedRows = rows;
|
|
88
|
+
if (height > 0 && width > 0) {
|
|
89
|
+
let anyNeedPadding = false;
|
|
90
|
+
for (const row of rows) {
|
|
91
|
+
if (row.length < width) {
|
|
92
|
+
anyNeedPadding = true;
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (anyNeedPadding) {
|
|
97
|
+
normalisedRows = new Array(height);
|
|
98
|
+
for (let r = 0; r < height; r++) {
|
|
99
|
+
const row = rows[r];
|
|
100
|
+
if (row.length === width) {
|
|
101
|
+
normalisedRows[r] = row;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const padded = new Array(width);
|
|
105
|
+
for (let c = 0; c < row.length; c++) {
|
|
106
|
+
padded[c] = row[c];
|
|
107
|
+
}
|
|
108
|
+
for (let c = row.length; c < width; c++) {
|
|
109
|
+
padded[c] = BLANK;
|
|
110
|
+
}
|
|
111
|
+
normalisedRows[r] = padded;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return originRow !== undefined
|
|
116
|
+
? {
|
|
117
|
+
kind: RVKind.Array,
|
|
118
|
+
rows: normalisedRows,
|
|
119
|
+
height,
|
|
120
|
+
width,
|
|
121
|
+
originRow,
|
|
122
|
+
originCol,
|
|
123
|
+
...(subtotalMask ? { subtotalMask } : {}),
|
|
124
|
+
...(hiddenRowMask ? { hiddenRowMask } : {})
|
|
125
|
+
}
|
|
126
|
+
: {
|
|
127
|
+
kind: RVKind.Array,
|
|
128
|
+
rows: normalisedRows,
|
|
129
|
+
height,
|
|
130
|
+
width,
|
|
131
|
+
...(subtotalMask ? { subtotalMask } : {}),
|
|
132
|
+
...(hiddenRowMask ? { hiddenRowMask } : {})
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function rvRef(sheet, top, left, bottom, right) {
|
|
136
|
+
return {
|
|
137
|
+
kind: RVKind.Reference,
|
|
138
|
+
areas: [{ sheet, top, left, bottom, right }]
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
export function rvCellRef(sheet, row, col) {
|
|
142
|
+
return {
|
|
143
|
+
kind: RVKind.Reference,
|
|
144
|
+
areas: [{ sheet, top: row, left: col, bottom: row, right: col }],
|
|
145
|
+
singleCell: true
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
export function rvLambda(params, body, closureBindings) {
|
|
149
|
+
return { kind: RVKind.Lambda, params, body, closureBindings };
|
|
150
|
+
}
|
|
151
|
+
// ============================================================================
|
|
152
|
+
// Type Guards
|
|
153
|
+
// ============================================================================
|
|
154
|
+
export function isError(v) {
|
|
155
|
+
return v.kind === RVKind.Error;
|
|
156
|
+
}
|
|
157
|
+
export function isArray(v) {
|
|
158
|
+
return v.kind === RVKind.Array;
|
|
159
|
+
}
|
|
160
|
+
export function isLambda(v) {
|
|
161
|
+
return v.kind === RVKind.Lambda;
|
|
162
|
+
}
|
|
163
|
+
export function isScalar(v) {
|
|
164
|
+
return (v.kind === RVKind.Blank ||
|
|
165
|
+
v.kind === RVKind.Number ||
|
|
166
|
+
v.kind === RVKind.String ||
|
|
167
|
+
v.kind === RVKind.Boolean ||
|
|
168
|
+
v.kind === RVKind.Error);
|
|
169
|
+
}
|
|
170
|
+
// ============================================================================
|
|
171
|
+
// Coercion Helpers
|
|
172
|
+
// ============================================================================
|
|
173
|
+
/**
|
|
174
|
+
* Parse a user-facing numeric string the way Excel does.
|
|
175
|
+
*
|
|
176
|
+
* Accepts:
|
|
177
|
+
* - plain decimals: `"1"`, `"-1.5"`, `"+.25"`
|
|
178
|
+
* - scientific notation: `"1.2e3"`, `"2E-4"`
|
|
179
|
+
* - percentage suffix: `"50%"` → 0.5
|
|
180
|
+
* - leading/trailing whitespace around the above
|
|
181
|
+
*
|
|
182
|
+
* Rejects (unlike JavaScript's `Number()`):
|
|
183
|
+
* - empty strings and whitespace-only (`" "` would become 0)
|
|
184
|
+
* - `"Infinity"`, `"-Infinity"`, `"NaN"` (Excel treats as text)
|
|
185
|
+
* - hexadecimal (`"0x10"`), octal, binary literals
|
|
186
|
+
* - currency symbols, thousands separators, locale-specific formats
|
|
187
|
+
* (these are out of scope for the engine; callers should strip before
|
|
188
|
+
* calling)
|
|
189
|
+
*
|
|
190
|
+
* Returns `#VALUE!` on any rejection so the error bubbles naturally
|
|
191
|
+
* through formula evaluation.
|
|
192
|
+
*/
|
|
193
|
+
function parseNumericString(raw) {
|
|
194
|
+
const s = raw.trim();
|
|
195
|
+
if (s === "") {
|
|
196
|
+
return ERRORS.VALUE;
|
|
197
|
+
}
|
|
198
|
+
let body = s;
|
|
199
|
+
let percentFactor = 1;
|
|
200
|
+
if (body.endsWith("%")) {
|
|
201
|
+
percentFactor = 0.01;
|
|
202
|
+
body = body.slice(0, -1).trim();
|
|
203
|
+
if (body === "") {
|
|
204
|
+
return ERRORS.VALUE;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Require at least one digit somewhere; this shuts the door on
|
|
208
|
+
// "Infinity", "NaN", "0x10", "1e" (Excel's own lexer refuses these).
|
|
209
|
+
// The strict decimal grammar below also rejects "1_000" etc.
|
|
210
|
+
if (!/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(body)) {
|
|
211
|
+
return ERRORS.VALUE;
|
|
212
|
+
}
|
|
213
|
+
const n = Number(body);
|
|
214
|
+
if (!Number.isFinite(n)) {
|
|
215
|
+
return ERRORS.VALUE;
|
|
216
|
+
}
|
|
217
|
+
return rvNumber(n * percentFactor);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Coerce a runtime value to a number.
|
|
221
|
+
* - Blank → 0
|
|
222
|
+
* - Number → itself
|
|
223
|
+
* - Boolean → 1 / 0
|
|
224
|
+
* - String → parse or #VALUE!
|
|
225
|
+
* - Error → propagate
|
|
226
|
+
*/
|
|
227
|
+
export function toNumberRV(v) {
|
|
228
|
+
switch (v.kind) {
|
|
229
|
+
case RVKind.Number:
|
|
230
|
+
return v;
|
|
231
|
+
case RVKind.Blank:
|
|
232
|
+
return rvNumber(0);
|
|
233
|
+
case RVKind.Boolean:
|
|
234
|
+
return rvNumber(v.value ? 1 : 0);
|
|
235
|
+
case RVKind.String: {
|
|
236
|
+
return parseNumericString(v.value);
|
|
237
|
+
}
|
|
238
|
+
case RVKind.Error:
|
|
239
|
+
return v;
|
|
240
|
+
default:
|
|
241
|
+
return ERRORS.VALUE;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Coerce a runtime value to a string.
|
|
246
|
+
*/
|
|
247
|
+
export function toStringRV(v) {
|
|
248
|
+
switch (v.kind) {
|
|
249
|
+
case RVKind.String:
|
|
250
|
+
return v.value;
|
|
251
|
+
case RVKind.Number:
|
|
252
|
+
return String(v.value);
|
|
253
|
+
case RVKind.Boolean:
|
|
254
|
+
return v.value ? "TRUE" : "FALSE";
|
|
255
|
+
case RVKind.Blank:
|
|
256
|
+
return "";
|
|
257
|
+
case RVKind.Error:
|
|
258
|
+
return v.code;
|
|
259
|
+
default:
|
|
260
|
+
return "";
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Coerce a runtime value to a boolean.
|
|
265
|
+
*/
|
|
266
|
+
export function toBooleanRV(v) {
|
|
267
|
+
switch (v.kind) {
|
|
268
|
+
case RVKind.Boolean:
|
|
269
|
+
return v;
|
|
270
|
+
case RVKind.Number:
|
|
271
|
+
return rvBoolean(v.value !== 0);
|
|
272
|
+
case RVKind.Blank:
|
|
273
|
+
return rvBoolean(false);
|
|
274
|
+
case RVKind.String: {
|
|
275
|
+
const u = v.value.toUpperCase();
|
|
276
|
+
if (u === "TRUE") {
|
|
277
|
+
return rvBoolean(true);
|
|
278
|
+
}
|
|
279
|
+
if (u === "FALSE") {
|
|
280
|
+
return rvBoolean(false);
|
|
281
|
+
}
|
|
282
|
+
return ERRORS.VALUE;
|
|
283
|
+
}
|
|
284
|
+
case RVKind.Error:
|
|
285
|
+
return v;
|
|
286
|
+
default:
|
|
287
|
+
return ERRORS.VALUE;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Structural equality of scalar values.
|
|
292
|
+
*
|
|
293
|
+
* - Different kinds → false
|
|
294
|
+
* - Number / Boolean / Blank → strict value equality (Blank always equal)
|
|
295
|
+
* - String → case-insensitive comparison (Excel semantics)
|
|
296
|
+
* - Error → not equal (errors do not compare equal to each other)
|
|
297
|
+
*/
|
|
298
|
+
/**
|
|
299
|
+
* Three-way compare two scalars that share a kind.
|
|
300
|
+
*
|
|
301
|
+
* Returns a negative number if `a < b`, zero if equal, positive if `a > b`.
|
|
302
|
+
* Returns `NaN` when the kinds differ or cannot be ordered (e.g. errors);
|
|
303
|
+
* callers decide how to surface the incomparability — sort helpers usually
|
|
304
|
+
* skip NaN pairs, while comparison operators route to a kind-priority
|
|
305
|
+
* tiebreak. Strings are compared case-insensitively to match Excel.
|
|
306
|
+
*/
|
|
307
|
+
export function compareScalarsSameKind(a, b) {
|
|
308
|
+
if (a.kind !== b.kind) {
|
|
309
|
+
return Number.NaN;
|
|
310
|
+
}
|
|
311
|
+
switch (a.kind) {
|
|
312
|
+
case RVKind.Number:
|
|
313
|
+
return a.value - b.value;
|
|
314
|
+
case RVKind.String: {
|
|
315
|
+
const al = a.value.toLowerCase();
|
|
316
|
+
const bl = b.value.toLowerCase();
|
|
317
|
+
return al < bl ? -1 : al > bl ? 1 : 0;
|
|
318
|
+
}
|
|
319
|
+
case RVKind.Boolean: {
|
|
320
|
+
const bv = b.value;
|
|
321
|
+
return a.value === bv ? 0 : a.value ? 1 : -1;
|
|
322
|
+
}
|
|
323
|
+
case RVKind.Blank:
|
|
324
|
+
return 0;
|
|
325
|
+
default:
|
|
326
|
+
return Number.NaN;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
export function scalarEquals(a, b) {
|
|
330
|
+
if (a.kind !== b.kind) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
switch (a.kind) {
|
|
334
|
+
case RVKind.Number:
|
|
335
|
+
return a.value === b.value;
|
|
336
|
+
case RVKind.String:
|
|
337
|
+
return a.value.toLowerCase() === b.value.toLowerCase();
|
|
338
|
+
case RVKind.Boolean:
|
|
339
|
+
return a.value === b.value;
|
|
340
|
+
case RVKind.Blank:
|
|
341
|
+
return true;
|
|
342
|
+
default:
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Get the top-left scalar from any value (for implicit intersection fallback).
|
|
348
|
+
*/
|
|
349
|
+
export function topLeft(v) {
|
|
350
|
+
if (isScalar(v)) {
|
|
351
|
+
return v;
|
|
352
|
+
}
|
|
353
|
+
if (v.kind === RVKind.Array) {
|
|
354
|
+
if (v.height === 0 || v.width === 0) {
|
|
355
|
+
return BLANK;
|
|
356
|
+
}
|
|
357
|
+
return v.rows[0][0];
|
|
358
|
+
}
|
|
359
|
+
// Reference, Lambda → need context to resolve
|
|
360
|
+
return ERRORS.VALUE;
|
|
361
|
+
}
|
|
362
|
+
// ============================================================================
|
|
363
|
+
// Snapshot Value Conversion
|
|
364
|
+
// ============================================================================
|
|
365
|
+
/**
|
|
366
|
+
* Convert a SnapshotCellValue to a RuntimeValue.
|
|
367
|
+
*/
|
|
368
|
+
export function fromSnapshotValue(v) {
|
|
369
|
+
if (v === null) {
|
|
370
|
+
return BLANK;
|
|
371
|
+
}
|
|
372
|
+
if (typeof v === "number") {
|
|
373
|
+
return rvNumber(v);
|
|
374
|
+
}
|
|
375
|
+
if (typeof v === "string") {
|
|
376
|
+
return rvString(v);
|
|
377
|
+
}
|
|
378
|
+
if (typeof v === "boolean") {
|
|
379
|
+
return rvBoolean(v);
|
|
380
|
+
}
|
|
381
|
+
if (typeof v === "object" && "error" in v) {
|
|
382
|
+
return rvError(v.error);
|
|
383
|
+
}
|
|
384
|
+
return BLANK;
|
|
385
|
+
}
|