# XWUIFormulaEngine

A headless, Excel / Google-Sheets-compatible formula engine - the calculation core behind XWUISheet and XWUISpreadsheet - wrapped as an XWUIComponent facade with no DOM of its own. It tokenizes, parses, and evaluates formulas with 200+ built-in functions (math, stats, logic, text, lookup, date/time, financial, regex, dynamic arrays), A1 / absolute (`$A$1`) / range references, structured table refs, Excel-style errors, custom LAMBDA-style functions, and optional async providers plus Web Worker offload. Wire a cell-value getter, then call `evaluate()`, `parse()`, `getDependencies()`, and `registerFunction()`.

## Usage

```ts
import { XWUIFormulaEngine } from './XWUIFormulaEngine';

const grid = [[1, 2, 3], [4, 5, 6]];
const engine = new XWUIFormulaEngine(document.createElement('div'), {
  getCellValue: (col, row) => grid[row]?.[col],
});

engine.evaluate('=SUM(A1:C1)');      // 6
engine.getDependencies('=A1+B$2');    // Set of cell keys
engine.registerFunction('DOUBLE', (args) => Number(args[0]) * 2);
```

## Invoice Totals

Backs an invoice table with the headless engine - a 2-D grid behind `getCellValue`, totaled with `=SUM`, `=ROUND`, and `=MAX`.

```example
file: examples/InvoiceTotals.ts
html: examples/InvoiceTotals.html
title: Invoice Totals
description: Evaluate SUM / ROUND / MAX formulas over a wired cell grid.
```

## Custom MARGIN() Function

Registers a domain `MARGIN(cost, price)` function and inspects a formula's cell dependencies.

```example
file: examples/CustomMarginFunction.ts
html: examples/CustomMarginFunction.html
title: Custom MARGIN() Function
description: registerFunction plus getDependencies on a custom formula.
```

```api
```
