MathDocument.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { OptionList } from '../util/Options.js';
  2. import { InputJax } from './InputJax.js';
  3. import { OutputJax } from './OutputJax.js';
  4. import { MathList } from './MathList.js';
  5. import { MathItem } from './MathItem.js';
  6. import { MmlNode } from './MmlTree/MmlNode.js';
  7. import { MmlFactory } from '../core/MmlTree/MmlFactory.js';
  8. import { DOMAdaptor } from '../core/DOMAdaptor.js';
  9. import { BitField } from '../util/BitField.js';
  10. import { PrioritizedList } from '../util/PrioritizedList.js';
  11. export declare type RenderDoc<N, T, D> = (document: MathDocument<N, T, D>) => boolean;
  12. export declare type RenderMath<N, T, D> = (math: MathItem<N, T, D>, document: MathDocument<N, T, D>) => boolean;
  13. export declare type RenderData<N, T, D> = {
  14. id: string;
  15. renderDoc: RenderDoc<N, T, D>;
  16. renderMath: RenderMath<N, T, D>;
  17. convert: boolean;
  18. };
  19. export declare type RenderAction<N, T, D> = [
  20. number
  21. ] | [
  22. number,
  23. string
  24. ] | [
  25. number,
  26. string,
  27. string
  28. ] | [
  29. number,
  30. RenderDoc<N, T, D>,
  31. RenderMath<N, T, D>
  32. ] | [
  33. number,
  34. boolean
  35. ] | [
  36. number,
  37. string,
  38. boolean
  39. ] | [
  40. number,
  41. string,
  42. string,
  43. boolean
  44. ] | [
  45. number,
  46. RenderDoc<N, T, D>,
  47. RenderMath<N, T, D>,
  48. boolean
  49. ];
  50. export declare type RenderActions<N, T, D> = {
  51. [id: string]: RenderAction<N, T, D>;
  52. };
  53. export declare class RenderList<N, T, D> extends PrioritizedList<RenderData<N, T, D>> {
  54. static create<N, T, D>(actions: RenderActions<N, T, D>): RenderList<N, T, D>;
  55. static action<N, T, D>(id: string, action: RenderAction<N, T, D>): [RenderData<N, T, D>, number];
  56. protected static methodActions(method1: string, method2?: string): ((math: any, document: any) => boolean)[];
  57. renderDoc(document: MathDocument<N, T, D>, start?: number): void;
  58. renderMath(math: MathItem<N, T, D>, document: MathDocument<N, T, D>, start?: number): void;
  59. renderConvert(math: MathItem<N, T, D>, document: MathDocument<N, T, D>, end?: number): void;
  60. findID(id: string): RenderData<N, T, D> | null;
  61. }
  62. export declare type ContainerList<N> = string | N | (string | N | N[])[];
  63. export declare type ResetList = {
  64. all?: boolean;
  65. processed?: boolean;
  66. inputJax?: any[];
  67. outputJax?: any[];
  68. };
  69. export declare const resetOptions: ResetList;
  70. export declare const resetAllOptions: ResetList;
  71. export interface MathDocument<N, T, D> {
  72. document: D;
  73. kind: string;
  74. options: OptionList;
  75. math: MathList<N, T, D>;
  76. renderActions: RenderList<N, T, D>;
  77. processed: BitField;
  78. inputJax: InputJax<N, T, D>[];
  79. outputJax: OutputJax<N, T, D>;
  80. adaptor: DOMAdaptor<N, T, D>;
  81. mmlFactory: MmlFactory;
  82. addRenderAction(id: string, ...action: any[]): void;
  83. removeRenderAction(id: string): void;
  84. render(): MathDocument<N, T, D>;
  85. rerender(start?: number): MathDocument<N, T, D>;
  86. convert(math: string, options?: OptionList): MmlNode | N;
  87. findMath(options?: OptionList): MathDocument<N, T, D>;
  88. compile(): MathDocument<N, T, D>;
  89. getMetrics(): MathDocument<N, T, D>;
  90. typeset(): MathDocument<N, T, D>;
  91. updateDocument(): MathDocument<N, T, D>;
  92. removeFromDocument(restore?: boolean): MathDocument<N, T, D>;
  93. state(state: number, restore?: boolean): MathDocument<N, T, D>;
  94. reset(options?: ResetList): MathDocument<N, T, D>;
  95. clear(): MathDocument<N, T, D>;
  96. concat(list: MathList<N, T, D>): MathDocument<N, T, D>;
  97. clearMathItemsWithin(containers: ContainerList<N>): MathItem<N, T, D>[];
  98. getMathItemsWithin(elements: ContainerList<N>): MathItem<N, T, D>[];
  99. }
  100. export declare abstract class AbstractMathDocument<N, T, D> implements MathDocument<N, T, D> {
  101. static KIND: string;
  102. static OPTIONS: OptionList;
  103. static ProcessBits: typeof BitField;
  104. document: D;
  105. options: OptionList;
  106. math: MathList<N, T, D>;
  107. renderActions: RenderList<N, T, D>;
  108. processed: BitField;
  109. inputJax: InputJax<N, T, D>[];
  110. outputJax: OutputJax<N, T, D>;
  111. adaptor: DOMAdaptor<N, T, D>;
  112. mmlFactory: MmlFactory;
  113. constructor(document: D, adaptor: DOMAdaptor<N, T, D>, options: OptionList);
  114. get kind(): string;
  115. addRenderAction(id: string, ...action: any[]): void;
  116. removeRenderAction(id: string): void;
  117. render(): this;
  118. rerender(start?: number): this;
  119. convert(math: string, options?: OptionList): any;
  120. findMath(_options?: OptionList): this;
  121. compile(): this;
  122. protected compileMath(math: MathItem<N, T, D>): void;
  123. compileError(math: MathItem<N, T, D>, err: Error): void;
  124. typeset(): this;
  125. typesetError(math: MathItem<N, T, D>, err: Error): void;
  126. getMetrics(): this;
  127. updateDocument(): this;
  128. removeFromDocument(_restore?: boolean): this;
  129. state(state: number, restore?: boolean): this;
  130. reset(options?: ResetList): this;
  131. clear(): this;
  132. concat(list: MathList<N, T, D>): this;
  133. clearMathItemsWithin(containers: ContainerList<N>): MathItem<N, T, D>[];
  134. getMathItemsWithin(elements: ContainerList<N>): MathItem<N, T, D>[];
  135. }
  136. export interface MathDocumentConstructor<D extends MathDocument<any, any, any>> {
  137. KIND: string;
  138. OPTIONS: OptionList;
  139. ProcessBits: typeof BitField;
  140. new (...args: any[]): D;
  141. }