@silurus/ooxml 0.50.1 → 0.52.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.
@@ -476,6 +476,139 @@ declare interface ManualLayout {
476
476
  h?: number;
477
477
  }
478
478
 
479
+ /** Accent (`m:acc`), e.g. hat, bar, vector arrow over the base. */
480
+ declare interface MathAccent {
481
+ kind: 'accent';
482
+ char: string;
483
+ base: MathNode[];
484
+ }
485
+
486
+ /** Matrix (`m:m`) or aligned equation array (`m:eqArr`). rows → cells → nodes. */
487
+ declare interface MathArray {
488
+ kind: 'array';
489
+ rows: MathNode[][][];
490
+ /** 'eq' = alternating right/left (eqArr); 'center' = matrix; 'left'. */
491
+ align: 'eq' | 'center' | 'left';
492
+ }
493
+
494
+ /** Over/under bar (`m:bar`). */
495
+ declare interface MathBar {
496
+ kind: 'bar';
497
+ pos: 'top' | 'bot';
498
+ base: MathNode[];
499
+ }
500
+
501
+ declare interface MathDelimiter {
502
+ kind: 'delimiter';
503
+ /** opening char (default '('). */
504
+ begChar: string;
505
+ /** closing char (default ')'). */
506
+ endChar: string;
507
+ /** separated groups (e.g. for cases / multiple args). */
508
+ items: MathNode[][];
509
+ }
510
+
511
+ declare interface MathFraction {
512
+ kind: 'fraction';
513
+ num: MathNode[];
514
+ den: MathNode[];
515
+ /** false = no rule (e.g. binomial); defaults to true. */
516
+ bar?: boolean;
517
+ }
518
+
519
+ declare interface MathFunc {
520
+ kind: 'func';
521
+ name: MathNode[];
522
+ arg: MathNode[];
523
+ }
524
+
525
+ declare interface MathGroup {
526
+ kind: 'group';
527
+ items: MathNode[];
528
+ }
529
+
530
+ /** Group character (`m:groupChr`), e.g. under/over brace. */
531
+ declare interface MathGroupChr {
532
+ kind: 'groupChr';
533
+ char: string;
534
+ pos: 'top' | 'bot';
535
+ base: MathNode[];
536
+ }
537
+
538
+ /** Lower/upper limit (`m:limLow` / `m:limUpp`), e.g. lim under n→∞. */
539
+ declare interface MathLimit {
540
+ kind: 'limit';
541
+ base: MathNode[];
542
+ lower?: MathNode[];
543
+ upper?: MathNode[];
544
+ }
545
+
546
+ declare interface MathNary {
547
+ kind: 'nary';
548
+ /** operator char, e.g. '∑', '∫', '∏'. */
549
+ op: string;
550
+ /** limit location (`m:limLoc`): 'subSup' = beside the op, 'undOvr' = above/below.
551
+ * Empty/omitted = default by operator class (integrals → subSup, others → undOvr). */
552
+ limLoc?: string;
553
+ sub?: MathNode[];
554
+ sup?: MathNode[];
555
+ body: MathNode[];
556
+ }
557
+
558
+ declare type MathNode = MathRun | MathFraction | MathScript | MathNary | MathDelimiter | MathRadical | MathLimit | MathArray | MathGroupChr | MathBar | MathAccent | MathFunc | MathGroup;
559
+
560
+ declare interface MathRadical {
561
+ kind: 'radical';
562
+ /** optional index (e.g. cube root); empty/omitted = square root. */
563
+ index?: MathNode[];
564
+ radicand: MathNode[];
565
+ }
566
+
567
+ /**
568
+ * The math engine contract a viewer needs to render equations. Satisfied by the
569
+ * `math` named export of the separate `@silurus/ooxml/math` entry point, which
570
+ * the consumer opts into:
571
+ *
572
+ * ```ts
573
+ * import { DocxViewer } from '@silurus/ooxml/docx';
574
+ * import { math } from '@silurus/ooxml/math';
575
+ * new DocxViewer(canvas, { math });
576
+ * ```
577
+ *
578
+ * Omit it and the equation engine (MathJax + STIX Two Math, ~3 MB) is never
579
+ * imported, so a bundler drops it entirely.
580
+ */
581
+ declare interface MathRenderer {
582
+ /** Preload the engine. Called once before converting equations. */
583
+ loadMathJax(): Promise<void>;
584
+ /** MathML string → standalone SVG + baseline-relative em extents. */
585
+ mathMLToSvg(mathml: string): Promise<MathSvg>;
586
+ }
587
+
588
+ declare interface MathRun {
589
+ kind: 'run';
590
+ text: string;
591
+ style: MathStyle;
592
+ }
593
+
594
+ declare interface MathScript {
595
+ kind: 'sup' | 'sub' | 'subSup';
596
+ base: MathNode[];
597
+ sup?: MathNode[];
598
+ sub?: MathNode[];
599
+ }
600
+
601
+ declare type MathStyle = 'roman' | 'italic' | 'bold' | 'boldItalic';
602
+
603
+ declare interface MathSvg {
604
+ /** standalone `<svg>…</svg>` markup. */
605
+ svg: string;
606
+ /** extents in em (the SVG viewBox uses 1em = 1000 units). */
607
+ widthEm: number;
608
+ ascentEm: number;
609
+ descentEm: number;
610
+ }
611
+
479
612
  export declare interface MergeCell {
480
613
  top: number;
481
614
  left: number;
@@ -549,6 +682,11 @@ export declare interface RenderViewportOptions {
549
682
  cellScale?: number;
550
683
  /** Pre-loaded Image elements keyed by their dataUrl (for ImageAnchor rendering). */
551
684
  loadedImages?: Map<string, HTMLImageElement>;
685
+ /** Opt-in OMML equation engine. Import it from the separate `@silurus/ooxml/math`
686
+ * entry and pass it in (`import { math } from '@silurus/ooxml/math'`). When
687
+ * omitted, equations in shapes are skipped and the ~3 MB engine never enters
688
+ * the bundle. Same DI contract as docx/pptx. */
689
+ math?: MathRenderer;
552
690
  /** Called once per cell that contains text, with canvas-pixel position and cell address. */
553
691
  onTextRun?: (info: XlsxTextRunInfo) => void;
554
692
  /** Highlighted row range for selected row headers (1-indexed inclusive).
@@ -683,7 +821,12 @@ declare interface ShapeText {
683
821
  paragraphs: ShapeParagraph[];
684
822
  }
685
823
 
686
- declare interface ShapeTextRun {
824
+ /** A run within a shape paragraph — tagged union mirroring the Rust enum
825
+ * (matches the pptx `TextRun` shape): styled text, a soft line break, or an
826
+ * OMML equation. Excel stores "Insert > Equation" as OMML inside the shared
827
+ * DrawingML `<xdr:txBody>` grammar (ECMA-376 §22.1), like PowerPoint. */
828
+ declare type ShapeTextRun = {
829
+ type: 'text';
687
830
  text: string;
688
831
  bold: boolean;
689
832
  italic: boolean;
@@ -692,7 +835,18 @@ declare interface ShapeTextRun {
692
835
  size: number;
693
836
  color?: string;
694
837
  fontFace?: string;
695
- }
838
+ } | {
839
+ type: 'break';
840
+ } | {
841
+ type: 'math';
842
+ /** OMML AST (shared `MathNode` model) for the equation. */
843
+ nodes: MathNode[];
844
+ /** true = block (`m:oMathPara`), false = inline (`m:oMath`). */
845
+ display: boolean;
846
+ /** Point size when the run carries an explicit `rPr@sz`; else inherit. */
847
+ fontSize?: number;
848
+ color?: string;
849
+ };
696
850
 
697
851
  declare interface SharedString {
698
852
  text: string;
@@ -1076,6 +1230,14 @@ export declare interface XlsxViewerOptions {
1076
1230
  * values fall back to the default.
1077
1231
  */
1078
1232
  maxZipEntryBytes?: number;
1233
+ /**
1234
+ * Opt-in OMML equation engine for rendering math in shapes/text boxes.
1235
+ * Import it from the separate `@silurus/ooxml/math` entry and pass it in
1236
+ * (`import { math } from '@silurus/ooxml/math'`). When omitted, equations are
1237
+ * skipped and the ~3 MB engine never enters the bundle (tree-shaken). Same
1238
+ * dependency-injection contract as the docx/pptx viewers.
1239
+ */
1240
+ math?: MathRenderer;
1079
1241
  }
1080
1242
 
1081
1243
  export declare class XlsxWorkbook {