import { Chart, DocumentInfo, ShapeBlock } from '../document-model/index.js'; import { DefinedName, MergedRange, ParsedWorksheet, SheetRichRun, XlsxStyles } from '../spreadsheet-model/index.js'; import { ResourceId, ResourceStore } from './resources.js'; /** * §20.5 SpreadsheetDrawingML — a chart frame anchored over a sheet's grid, * already sized from its two-cell anchor. `chartPartPath` keys into * {@link SheetDoc.chartData} for the resolved chart. */ export interface SheetChartRef { readonly chartPartPath: string; readonly widthPt: number; readonly heightPt: number; /** Where the anchor puts it, in points from the grid's top-left. */ readonly xPt?: number; readonly yPt?: number; } /** * §20.5.2.1 xdr:pic — a picture anchored over a sheet's grid, sized from its * anchor. The bytes live in {@link SheetDoc.resources}; `resourceId` keys into * it. The projection emits an ImageBlock per picture after the grid. */ export interface SheetImageRef { readonly resourceId: ResourceId; readonly widthPt: number; readonly heightPt: number; /** Where the anchor puts it, in points from the grid's top-left. */ readonly xPt?: number; readonly yPt?: number; } /** One item (label + selection state) in a {@link SheetSlicer}. */ export interface SheetSlicerItem { /** The item's display label. */ readonly label: string; /** Whether the item is currently selected (filtered in). */ readonly selected: boolean; } /** * A slicer panel (xl/slicers + xl/slicerCaches, E-SHEET SV2) resolved against * its source so the projection can render it as a captioned button box after the * grid. Items + selection resolve for native-table slicers; an OLAP/pivot slicer * the cache cannot resolve inline degrades to a caption-only box. */ export interface SheetSlicer { readonly caption: string; readonly columnCount: number; readonly items: ReadonlyArray; /** * Resolved fills + header text colour from the slicer style name + workbook * theme (the same accent heuristic as tables/pivots). Absent ⇒ a plain box. */ readonly headerHex?: string; readonly selectedHex?: string; readonly headerTextHex?: string; readonly selectedTextHex?: string; } /** * §18.3.1.47 — a cell (or range) hyperlink resolved to an external URL (E-SHEET * W3). The projection stamps `run.href` on every cell the range covers. */ export interface SheetHyperlink { readonly ref: MergedRange; readonly url: string; } /** * A cell comment / note (E-SHEET W7): an A1 anchor, the resolved author display * name, the text body, and whether it came from the modern threaded comments * part (a conversation) or the legacy note part. */ export interface SheetComment { readonly ref: string; readonly author?: string; readonly text: string; readonly threaded: boolean; } /** * A form control resolved against its ctrlProp part (E-SHEET W8): the display * name, the `objectType` (CheckBox / Radio / Spin / …) and the bit of state the * listing shows — `checked` for check/option buttons, `value` for * spin/scroll/list controls. Render-only. */ export interface SheetFormControl { /** * §18.3.1.19 `` — the shape's NAME, an identifier like * "CheckBox28". Excel shows it in the name box, never on the page; it is what * the after-the-grid listing calls a control that has no geometry. */ readonly name?: string; /** * The visible label, from the control's legacy VML ``. A control * drawn in place draws THIS beside its widget — never {@link name}, which is * an internal id: 45540_form_Header.xlsx has forty captionless check boxes * and printing their names put "CheckBox28" across the form's own text. */ readonly caption?: string; readonly objectType?: string; readonly checked?: boolean; readonly value?: number; /** Where the control sits on the sheet, in points from the grid's origin. */ readonly box?: SheetControlBox; /** The caption's declared size, when the shape names one. */ readonly fontSizePt?: number; } /** * A control's rectangle on the sheet, in points from the grid's top-left — read * from its legacy VML shape, the only part that says where a control goes. * Absent when the drawing carries no geometry, in which case the control is * listed after the grid rather than drawn in place. */ export interface SheetControlBox { readonly xPt: number; readonly yPt: number; readonly widthPt: number; readonly heightPt: number; } /** * An ActiveX control resolved against its activeX part (E-SHEET W10): the control * class (`type`, from the `` or, for a §18.3.1.19 ``, * its class id) plus the visible state persisted in the property bag — * `caption`, `value` (checked/text/number, as a string) and OptionButton * `groupName`. Render-only. */ export interface SheetActiveXControl { readonly type: string; /** Where the control sits on the sheet — from the VML shape sharing its `shapeId`. */ readonly box?: SheetControlBox; /** §18.3.1.19 `` — the control's identifier, when it came that way. */ readonly name?: string; readonly caption?: string; readonly value?: string; readonly groupName?: string; } /** One worksheet: the parsed grid plus its resolved, anchor-ordered overlays. */ export interface Sheet { /** The sheet (tab) name. */ readonly name: string; /** * §18.2.19 `` — the tab is `hidden` or `veryHidden`. Carried * because a consumer that shows the workbook (the HTML writer) may still want * it; the paginated projection skips it, as Excel and LibreOffice do. */ readonly hidden?: boolean; /** * The grid + per-sheet geometry exactly as parsed: cells, columns, rows, * merges, dimensions, pageSetup/printOptions, manual breaks, drawingRelId. */ readonly grid: ParsedWorksheet; /** Chart frames on this sheet, anchor-ordered (resolved data in {@link SheetDoc.chartData}). */ readonly charts?: ReadonlyArray; /** Picture frames on this sheet, anchor-ordered (bytes in {@link SheetDoc.resources}). */ readonly images?: ReadonlyArray; /** Drawing shapes on this sheet (E-SHEET W2), fully resolved + anchor-ordered. */ readonly shapes?: ReadonlyArray; /** * Cell hyperlinks resolved to external URLs (E-SHEET W3); the projection sets * `run.href` on covered cells. In-workbook (location-only) links are not carried. */ readonly hyperlinks?: ReadonlyArray; /** Slicer panels on this sheet (E-SHEET SV2), rendered after the grid + charts. */ readonly slicers?: ReadonlyArray; /** * Cell comments / notes (E-SHEET W7), legacy and threaded. The projection * lists them in a "Comments" section after the grid (mirroring Excel's "print * comments at end of sheet"); render-only. */ readonly comments?: ReadonlyArray; /** * Form controls on this sheet (E-SHEET W8), resolved to type + state. Listed * in a "Form controls" section after the grid; render-only. */ readonly formControls?: ReadonlyArray; /** * ActiveX controls on this sheet (E-SHEET W10), resolved to type + visible * state. Listed in an "ActiveX controls" section after the grid; render-only. */ readonly activeXControls?: ReadonlyArray; } /** * The SpreadsheetML IR tree (E-SHEET): a workbook of grid {@link Sheet}s plus * its workbook-scoped companions — the style table, shared-string table, defined * names, date system, parsed charts, binary resources and metadata. Cells keep * their RAW stored value + a style index; resolution (shared strings, number * formats, the style cascade, the print model) happens at the projection * boundary, never in the tree. */ export interface SheetDoc { /** Discriminant for {@link SourceDoc} (projected to a FlowDoc for rendering). */ readonly kind: 'sheet'; /** The workbook's worksheets, in tab order. */ readonly sheets: ReadonlyArray; /** §18.8 workbook style table (cellXfs + fonts/fills/borders/numFmts). */ readonly styles: XlsxStyles; /** §18.4 shared string table; a cell with type 's' indexes into it. */ readonly sharedStrings: ReadonlyArray; /** * §18.4.4 per-index rich-text runs (E-SHEET W6), parallel to sharedStrings — * `[i]` is defined only when shared string i carries per-run formatting. * Render-only: the writer flattens to plain text, so it is absent on round-trip. */ readonly sharedStringRuns?: ReadonlyArray | undefined>; /** §18.2.5 workbook defined names (print areas/titles, named ranges). */ readonly definedNames: ReadonlyArray; /** §18.2.28 1904 date system (serial-to-date epoch). */ readonly date1904: boolean; /** Parsed charts keyed by part path (SheetChartRef.chartPartPath). */ readonly chartData?: ReadonlyMap; /** Content-addressed binary resources (sheet images). */ readonly resources: ResourceStore; /** Document metadata from docProps/core.xml. */ readonly info?: DocumentInfo; /** * §20.1.6.2 the workbook theme's colour scheme, slot name → 6-hex. Cell * colours are resolved against it at parse time; a header/footer's `&K` theme * reference is resolved at projection time, which is why the palette travels. */ readonly themePalette?: ReadonlyMap; /** * §18.3.* — how many embedded objects (`` and the * like) the workbook carries. They print as an icon and a caption in Excel * and Calc, both of which live in a metafile; the projection reports them. */ readonly embeddedObjects?: number; /** * §20.5.2.x — how many anchored pictures are a metafile (WMF / EMF / PICT) * rather than a raster. They keep their anchor and their box, and draw * nothing: replaying a metafile is a different feature from embedding an * image. The projection reports them. */ readonly metafilePictures?: number; }