@silurus/ooxml 0.11.0 → 0.13.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.
@@ -56,7 +56,18 @@ export declare interface Cell {
56
56
  formula?: string;
57
57
  }
58
58
 
59
- declare interface CellRange {
59
+ export declare interface CellAddress {
60
+ row: number;
61
+ col: number;
62
+ }
63
+
64
+ export declare interface CellRange {
65
+ anchor: CellAddress;
66
+ active: CellAddress;
67
+ mode: SelectionMode_2;
68
+ }
69
+
70
+ declare interface CellRange_2 {
60
71
  top: number;
61
72
  left: number;
62
73
  bottom: number;
@@ -206,10 +217,40 @@ declare interface ChartData {
206
217
  catAxisFontSizeHpt?: number | null;
207
218
  /** Value axis tick-label font size in hpt. */
208
219
  valAxisFontSizeHpt?: number | null;
220
+ /** Outer chartSpace background (ECMA-376 §21.2.2.5 `<c:spPr>`). Hex without
221
+ * '#' for a solid fill, undefined for `<a:noFill/>` or an absent spPr.
222
+ * Combine with `hasChartSpPr` to distinguish explicit-transparent from
223
+ * default-opaque-white. */
224
+ chartBg?: string | null;
225
+ /** True when the parser saw a `<c:chartSpace><c:spPr>` element. Lets the
226
+ * adapter tell "spec said noFill → transparent" from "no spPr → default". */
227
+ hasChartSpPr?: boolean;
228
+ /** `<c:legend><c:manualLayout>` fractions of chart space (§21.2.2.31). */
229
+ legendManualLayout?: LegendManualLayout | null;
230
+ /** `<c:catAx><c:delete val="1"/>` — hide the category axis (§21.2.2.40). */
231
+ catAxisHidden?: boolean;
232
+ /** `<c:valAx><c:delete val="1"/>` — hide the value axis (§21.2.2.40). */
233
+ valAxisHidden?: boolean;
234
+ /** `<c:valAx><c:numFmt@formatCode>` — number format for value-axis tick
235
+ * labels (ECMA-376 §21.2.2.21). */
236
+ valAxisFormatCode?: string | null;
237
+ /** `<c:barChart><c:gapWidth>` — space between category groups as a percent
238
+ * of bar width (§21.2.2.13). */
239
+ barGapWidth?: number | null;
240
+ /** `<c:barChart><c:overlap>` — signed percent overlap between bars in a
241
+ * cluster (§21.2.2.25). Negative = gap. */
242
+ barOverlap?: number | null;
243
+ /** `<c:dLbls><c:dLblPos>` — data label position (§21.2.2.16). */
244
+ dataLabelPosition?: string | null;
245
+ /** Hex (no `#`) for data label text color, resolved from `<c:dLbls><c:txPr>`. */
246
+ dataLabelFontColor?: string | null;
247
+ /** `<c:dLbls><c:numFmt@formatCode>` — chart-level override for data label
248
+ * number format (§21.2.2.35). */
249
+ dataLabelFormatCode?: string | null;
209
250
  }
210
251
 
211
252
  declare interface ConditionalFormat {
212
- sqref: CellRange[];
253
+ sqref: CellRange_2[];
213
254
  rules: CfRule[];
214
255
  }
215
256
 
@@ -222,6 +263,11 @@ declare interface Dxf {
222
263
  font: Font | null;
223
264
  fill: Fill | null;
224
265
  border: Border | null;
266
+ /** Number format override from the dxf (ECMA-376 §18.8.17). When a
267
+ * conditional-formatting rule matches, this numFmt replaces the cell's own
268
+ * style numFmt for rendering — e.g. switching a calendar cell from `d` to
269
+ * `m"月"d"日"` on the first day of each month. */
270
+ numFmt?: NumFmt | null;
225
271
  }
226
272
 
227
273
  export declare interface Fill {
@@ -281,6 +327,15 @@ declare interface ImageAnchor {
281
327
  dataUrl: string;
282
328
  }
283
329
 
330
+ declare interface LegendManualLayout {
331
+ xMode: string;
332
+ yMode: string;
333
+ x: number;
334
+ y: number;
335
+ w: number;
336
+ h: number;
337
+ }
338
+
284
339
  export declare interface MergeCell {
285
340
  top: number;
286
341
  left: number;
@@ -299,6 +354,47 @@ export declare interface ParsedWorkbook {
299
354
  sharedStrings: SharedString[];
300
355
  }
301
356
 
357
+ declare type PathCmd = {
358
+ op: 'moveTo';
359
+ x: number;
360
+ y: number;
361
+ } | {
362
+ op: 'lineTo';
363
+ x: number;
364
+ y: number;
365
+ } | {
366
+ op: 'cubicBezTo';
367
+ x1: number;
368
+ y1: number;
369
+ x2: number;
370
+ y2: number;
371
+ x3: number;
372
+ y3: number;
373
+ } | {
374
+ op: 'quadBezTo';
375
+ x1: number;
376
+ y1: number;
377
+ x2: number;
378
+ y2: number;
379
+ }
380
+ /** ECMA-376 §20.1.9.3. stAng/swAng in 60000ths of a degree. wr/hr in
381
+ * the path's own coordinate units. Pen position is the arc start. */
382
+ | {
383
+ op: 'arcTo';
384
+ wr: number;
385
+ hr: number;
386
+ stAng: number;
387
+ swAng: number;
388
+ } | {
389
+ op: 'close';
390
+ };
391
+
392
+ declare interface PathInfo {
393
+ w: number;
394
+ h: number;
395
+ commands: PathCmd[];
396
+ }
397
+
302
398
  export declare interface RenderViewportOptions {
303
399
  width?: number;
304
400
  height?: number;
@@ -313,6 +409,8 @@ export declare interface RenderViewportOptions {
313
409
  cellScale?: number;
314
410
  /** Pre-loaded Image elements keyed by their dataUrl (for ImageAnchor rendering). */
315
411
  loadedImages?: Map<string, HTMLImageElement>;
412
+ /** Called once per cell that contains text, with canvas-pixel position and cell address. */
413
+ onTextRun?: (info: TextRunInfo) => void;
316
414
  }
317
415
 
318
416
  export declare interface Row {
@@ -336,6 +434,51 @@ declare interface RunFont {
336
434
  name?: string | null;
337
435
  }
338
436
 
437
+ declare type SelectionMode_2 = 'cells' | 'rows' | 'cols' | 'all';
438
+ export { SelectionMode_2 as SelectionMode }
439
+
440
+ declare interface ShapeAnchor {
441
+ fromCol: number;
442
+ fromColOff: number;
443
+ fromRow: number;
444
+ fromRowOff: number;
445
+ toCol: number;
446
+ toColOff: number;
447
+ toRow: number;
448
+ toRowOff: number;
449
+ shapes: ShapeInfo[];
450
+ }
451
+
452
+ declare type ShapeGeom = {
453
+ type: 'preset';
454
+ name: string;
455
+ } | {
456
+ type: 'custom';
457
+ paths: PathInfo[];
458
+ }
459
+ /** Bitmap picture leaf inside a `<xdr:grpSp>`. `dataUrl` is a pre-encoded
460
+ * `data:<mime>;base64,…` produced by the Rust parser from the drawing's
461
+ * relationship target. */
462
+ | {
463
+ type: 'image';
464
+ dataUrl: string;
465
+ };
466
+
467
+ declare interface ShapeInfo {
468
+ /** Normalized [0,1] position/size relative to the anchor rect. */
469
+ x: number;
470
+ y: number;
471
+ w: number;
472
+ h: number;
473
+ /** Rotation in degrees, clockwise. */
474
+ rot: number;
475
+ fillColor?: string;
476
+ strokeColor?: string;
477
+ /** Stroke width in EMU. 0 = no stroke. */
478
+ strokeWidth: number;
479
+ geom: ShapeGeom;
480
+ }
481
+
339
482
  declare interface SharedString {
340
483
  text: string;
341
484
  runs?: Run[];
@@ -347,6 +490,24 @@ export declare interface SheetMeta {
347
490
  rId: string;
348
491
  }
349
492
 
493
+ declare interface SlicerAnchor {
494
+ fromCol: number;
495
+ fromColOff: number;
496
+ fromRow: number;
497
+ fromRowOff: number;
498
+ toCol: number;
499
+ toColOff: number;
500
+ toRow: number;
501
+ toRowOff: number;
502
+ caption: string;
503
+ items: SlicerItem[];
504
+ }
505
+
506
+ declare interface SlicerItem {
507
+ name: string;
508
+ selected: boolean;
509
+ }
510
+
350
511
  export declare interface Styles {
351
512
  fonts: Font[];
352
513
  fills: Fill[];
@@ -357,7 +518,7 @@ export declare interface Styles {
357
518
  }
358
519
 
359
520
  declare interface TableInfo {
360
- range: CellRange;
521
+ range: CellRange_2;
361
522
  styleName: string;
362
523
  headerRowCount: number;
363
524
  totalsRowCount: number;
@@ -377,6 +538,21 @@ declare interface TableInfo {
377
538
  headerRowDxf?: number;
378
539
  }
379
540
 
541
+ /** Emitted once per cell that has text, with the cell's canvas-pixel bounds. */
542
+ export declare interface TextRunInfo {
543
+ text: string;
544
+ /** Canvas CSS-pixel x of the cell's top-left corner. */
545
+ x: number;
546
+ /** Canvas CSS-pixel y of the cell's top-left corner. */
547
+ y: number;
548
+ /** Cell width in canvas CSS pixels. */
549
+ width: number;
550
+ /** Cell height in canvas CSS pixels. */
551
+ height: number;
552
+ row: number;
553
+ col: number;
554
+ }
555
+
380
556
  export declare interface ViewportRange {
381
557
  row: number;
382
558
  col: number;
@@ -401,6 +577,10 @@ export declare interface Worksheet {
401
577
  conditionalFormats: ConditionalFormat[];
402
578
  images: ImageAnchor[];
403
579
  charts: ChartAnchor[];
580
+ /** Grouped shapes from `<xdr:grpSp>` inside twoCellAnchors
581
+ * (ECMA-376 §20.5.2.17). Each anchor holds leaf shapes pre-flattened
582
+ * with normalized [0,1] geometry relative to the anchor rect. */
583
+ shapeGroups?: ShapeAnchor[];
404
584
  /** Whether to display zero values (ECMA-376 §18.3.1.94). Defaults to true. */
405
585
  showZeros?: boolean;
406
586
  /** Whether to draw default grid lines (ECMA-376 §18.3.1.83
@@ -410,7 +590,7 @@ export declare interface Worksheet {
410
590
  /** Sheet tab color (ECMA-376 §18.3.1.79). */
411
591
  tabColor?: string | null;
412
592
  /** AutoFilter header range (ECMA-376 §18.3.1.2). */
413
- autoFilter?: CellRange | null;
593
+ autoFilter?: CellRange_2 | null;
414
594
  /** Hyperlinks in this worksheet (ECMA-376 §18.3.1.47). */
415
595
  hyperlinks?: Hyperlink[];
416
596
  /** A1-style cell refs of commented cells (ECMA-376 §18.7.3). Rendered as a
@@ -423,6 +603,10 @@ export declare interface Worksheet {
423
603
  /** Excel Tables on this sheet (ECMA-376 §18.5). The renderer overlays a
424
604
  * built-in style (bold header, banded rows) on the given ranges. */
425
605
  tables?: TableInfo[];
606
+ /** Pivot / table slicers (Office 2010+ extension). Each anchor carries a
607
+ * caption and the saved item list (with selection flags) so the renderer
608
+ * can draw a static button bank without the live pivot engine. */
609
+ slicers?: SlicerAnchor[];
426
610
  }
427
611
 
428
612
  /**
@@ -440,6 +624,11 @@ declare interface XlsxChartSeries {
440
624
  /** Marker visibility resolved from `<c:marker>`/chart-level default
441
625
  * (ECMA-376 §21.2.2.32). */
442
626
  showMarker?: boolean;
627
+ /** `<c:val>/<c:numRef>/<c:formatCode>` — Excel number format for series
628
+ * values (ECMA-376 §21.2.2.37). */
629
+ valFormatCode?: string | null;
630
+ /** `<c:ser><c:order>` — stacking/legend display order (§21.2.2.28). */
631
+ order?: number;
443
632
  }
444
633
 
445
634
  export declare class XlsxViewer {
@@ -454,9 +643,30 @@ export declare class XlsxViewer {
454
643
  private currentWorksheet;
455
644
  private opts;
456
645
  private resizeObserver;
646
+ private anchorCell;
647
+ private activeCell;
648
+ private selectionMode;
649
+ private isSelecting;
650
+ private selectionOverlay;
651
+ private keydownHandler;
457
652
  constructor(container: HTMLElement, opts?: XlsxViewerOptions);
458
653
  load(source: string | ArrayBuffer): Promise<void>;
459
654
  showSheet(index: number): Promise<void>;
655
+ /** Returns the cell at canvas-client coordinates, or null if outside the cell grid. */
656
+ getCellAt(clientX: number, clientY: number): CellAddress | null;
657
+ /** Returns the CSS-pixel rect of a cell within canvasArea, or null if not computable. */
658
+ private getCellRect;
659
+ /** Returns the current selection, including mode. */
660
+ get selection(): CellRange | null;
661
+ /**
662
+ * Returns what the header area contains at the given client coordinates.
663
+ * Returns null when the point is in the cell grid (not a header).
664
+ */
665
+ private getHeaderHit;
666
+ /** Copy the selected cell range as tab-separated text to the clipboard. */
667
+ private copySelection;
668
+ private updateSelectionOverlay;
669
+ private setupSelectionEvents;
460
670
  private buildTabs;
461
671
  private updateTabActive;
462
672
  private tabStyle;
@@ -472,6 +682,8 @@ export declare interface XlsxViewerOptions {
472
682
  onReady?: (sheetNames: string[]) => void;
473
683
  onSheetChange?: (index: number, name: string) => void;
474
684
  onError?: (err: Error) => void;
685
+ /** Called when the selected cell range changes. null means no selection. */
686
+ onSelectionChange?: (selection: CellRange | null) => void;
475
687
  }
476
688
 
477
689
  export declare class XlsxWorkbook {