import React from 'react'; import PropTypes from 'prop-types'; interface MathJaxConfig$1 { [name: string]: any; } interface MathJaxLibrary { [name: string]: any; } interface MathJaxObject$1 { version: string; _: MathJaxLibrary; config: MathJaxConfig$1; } declare type OptionList = { [name: string]: any; }; interface FactoryNode { readonly kind: string; } interface FactoryNodeClass { new (factory: Factory>, ...args: any[]): N; } interface Factory> { create(kind: string): N; setNodeClass(kind: string, nodeClass: C): void; getNodeClass(kind: string): C; deleteNodeClass(kind: string): void; nodeIsKind(node: N, kind: string): boolean; getKinds(): string[]; } declare abstract class AbstractFactory> implements Factory { static defaultNodes: {}; defaultKind: string; protected nodeMap: Map; protected node: { [kind: string]: (...args: any[]) => N; }; constructor(nodes?: { [kind: string]: C; }); create(kind: string, ...args: any[]): N; setNodeClass(kind: string, nodeClass: C): void; getNodeClass(kind: string): C; deleteNodeClass(kind: string): void; nodeIsKind(node: N, kind: string): boolean; getKinds(): string[]; } interface NodeFactory> extends Factory { create(kind: string, properties?: PropertyList, children?: N[]): N; } declare abstract class AbstractNodeFactory> extends AbstractFactory { create(kind: string, properties?: PropertyList, children?: N[]): N; } declare type Property = string | number | boolean; declare type PropertyList = { [key: string]: Property; }; interface Node { readonly kind: string; readonly factory: NodeFactory; parent: Node; childNodes: Node[]; setProperty(name: string, value: Property): void; getProperty(name: string): Property; getPropertyNames(): string[]; getAllProperties(): PropertyList; removeProperty(...names: string[]): void; isKind(kind: string): boolean; setChildren(children: Node[]): void; appendChild(child: Node): Node; replaceChild(newChild: Node, oldChild: Node): Node; removeChild(child: Node): Node; childIndex(child: Node): number; copy(): Node; findNodes(kind: string): Node[]; walkTree(func: (node: Node, data?: any) => void, data?: any): void; } interface NodeClass { new (factory: NodeFactory, properties?: PropertyList, children?: Node[]): Node; } declare class Attributes { protected attributes: PropertyList; protected inherited: PropertyList; protected defaults: PropertyList; protected global: PropertyList; constructor(defaults: PropertyList, global: PropertyList); set(name: string, value: Property): void; setList(list: PropertyList): void; get(name: string): Property; getExplicit(name: string): Property; getList(...names: string[]): PropertyList; setInherited(name: string, value: Property): void; getInherited(name: string): Property; getDefault(name: string): Property; isSet(name: string): boolean; hasDefault(name: string): boolean; getExplicitNames(): string[]; getInheritedNames(): string[]; getDefaultNames(): string[]; getGlobalNames(): string[]; getAllAttributes(): PropertyList; getAllInherited(): PropertyList; getAllDefaults(): PropertyList; getAllGlobals(): PropertyList; } declare class MmlFactory extends AbstractNodeFactory { static defaultNodes: { [kind: string]: MmlNodeClass; }; get MML(): Object; } declare type AttributeData = { name: string; value: string; }; declare type PageBBox = { left: number; right: number; top: number; bottom: number; }; interface DOMAdaptor { document: D; parse(text: string, format?: string): D; node(kind: string, def?: OptionList, children?: (N | T)[], ns?: string): N; text(text: string): T; head(doc: D): N; body(doc: D): N; root(doc: D): N; doctype(doc: D): string; tags(node: N, name: string, ns?: string): N[]; getElements(nodes: (string | N | N[])[], document: D): N[]; contains(container: N, node: N | T): boolean; parent(node: N | T): N; append(node: N, child: N | T): N | T; insert(nchild: N | T, ochild: N | T): void; remove(child: N | T): N | T; replace(nnode: N | T, onode: N | T): N | T; clone(node: N): N; split(node: T, n: number): T; next(node: N | T): N | T; previous(node: N | T): N | T; firstChild(node: N): N | T; lastChild(node: N): N | T; childNodes(node: N): (N | T)[]; childNode(node: N, i: number): N | T; kind(node: N | T): string; value(node: N | T): string; textContent(node: N): string; innerHTML(node: N): string; outerHTML(node: N): string; serializeXML(node: N): string; setAttribute(node: N, name: string, value: string | number, ns?: string): void; setAttributes(node: N, def: OptionList): void; getAttribute(node: N, name: string): string; removeAttribute(node: N, name: string): void; hasAttribute(node: N, name: string): boolean; allAttributes(node: N): AttributeData[]; addClass(node: N, name: string): void; removeClass(node: N, name: string): void; hasClass(node: N, name: string): boolean; allClasses(node: N): string[]; setStyle(node: N, name: string, value: string): void; getStyle(node: N, name: string): string; allStyles(node: N): string; insertRules(node: N, rules: string[]): void; fontSize(node: N): number; fontFamily(node: N): string; nodeSize(node: N, em?: number, local?: boolean): [number, number]; nodeBBox(node: N): PageBBox; } declare type AttributeList = { [attribute: string]: [string, Property]; }; interface MmlNode extends Node { readonly isToken: boolean; readonly isEmbellished: boolean; readonly isSpacelike: boolean; readonly linebreakContainer: boolean; readonly hasNewLine: boolean; readonly arity: number; readonly isInferred: boolean; readonly Parent: MmlNode; readonly notParent: boolean; parent: MmlNode; texClass: number; prevClass: number; prevLevel: number; attributes: Attributes; core(): MmlNode; coreMO(): MmlNode; coreIndex(): number; childPosition(): number; setTeXclass(prev: MmlNode): MmlNode; texSpacing(): string; hasSpacingAttributes(): boolean; setInheritedAttributes(attributes: AttributeList, display: boolean, level: number, prime: boolean): void; inheritAttributesFrom(node: MmlNode): void; mError(message: string, options: PropertyList, short?: boolean): MmlNode; verifyTree(options?: PropertyList): void; } interface MmlNodeClass extends NodeClass { defaults?: PropertyList; new (factory: MmlFactory, attributes?: PropertyList, children?: MmlNode[]): MmlNode; } declare type Location = { i?: number; n?: number; delim?: string; node?: N | T; }; declare type Metrics = { em: number; ex: number; containerWidth: number; lineWidth: number; scale: number; }; interface MathItem { math: string; inputJax: InputJax; display: boolean; isEscaped: boolean; start: Location; end: Location; root: MmlNode; typesetRoot: N; metrics: Metrics; inputData: OptionList; outputData: OptionList; render(document: MathDocument): void; rerender(document: MathDocument, start?: number): void; convert(document: MathDocument, end?: number): void; compile(document: MathDocument): void; typeset(document: MathDocument): void; updateDocument(document: MathDocument): void; removeFromDocument(restore: boolean): void; setMetrics(em: number, ex: number, cwidth: number, lwidth: number, scale: number): void; state(state?: number, restore?: boolean): number; reset(restore?: boolean): void; } declare type ProtoItem = { math: string; start: Location; end: Location; open?: string; close?: string; n?: number; display: boolean; }; interface PrioritizedListItem { priority: number; item: DataClass; } declare class PrioritizedList { static DEFAULTPRIORITY: number; protected items: PrioritizedListItem[]; constructor(); [Symbol.iterator](): Iterator>; add(item: DataClass, priority?: number): DataClass; remove(item: DataClass): void; } declare class FunctionList extends PrioritizedList { execute(...data: any[]): boolean; asyncExecute(...data: any[]): Promise; } interface InputJax { name: string; processStrings: boolean; options: OptionList; preFilters: FunctionList; postFilters: FunctionList; adaptor: DOMAdaptor; mmlFactory: MmlFactory; setAdaptor(adaptor: DOMAdaptor): void; setMmlFactory(mmlFactory: MmlFactory): void; initialize(): void; reset(...args: any[]): void; findMath(which: N | string[], options?: OptionList): ProtoItem[]; compile(math: MathItem, document: MathDocument): MmlNode; } interface OutputJax { name: string; options: OptionList; postFilters: FunctionList; adaptor: DOMAdaptor; setAdaptor(adaptor: DOMAdaptor): void; initialize(): void; reset(...args: any[]): void; typeset(math: MathItem, document?: MathDocument): N; escaped(math: MathItem, document?: MathDocument): N; getMetrics(document: MathDocument): void; styleSheet(document: MathDocument): N; pageElements(document: MathDocument): N; } declare type SortFn = (a: DataClass, b: DataClass) => boolean; declare class ListItem { data: DataClass | symbol; next: ListItem; prev: ListItem; constructor(data?: any); } declare class LinkedList { protected list: ListItem; constructor(...args: DataClass[]); isBefore(a: DataClass, b: DataClass): boolean; push(...args: DataClass[]): LinkedList; pop(): DataClass; unshift(...args: DataClass[]): LinkedList; shift(): DataClass; remove(...items: DataClass[]): void; clear(): LinkedList; [Symbol.iterator](): IterableIterator; reversed(): IterableIterator; insert(data: DataClass, isBefore?: SortFn): this; sort(isBefore?: SortFn): LinkedList; merge(list: LinkedList, isBefore?: SortFn): LinkedList; } interface MathList extends LinkedList> { isBefore(a: MathItem, b: MathItem): boolean; } declare class BitField { protected static MAXBIT: number; protected static next: number; protected static names: Map; protected bits: number; static allocate(...names: string[]): void; static has(name: string): boolean; set(name: string): void; clear(name: string): void; isSet(name: string): boolean; reset(): void; protected getBit(name: string): number; } declare type RenderDoc = (document: MathDocument) => boolean; declare type RenderMath = (math: MathItem, document: MathDocument) => boolean; declare type RenderData = { id: string; renderDoc: RenderDoc; renderMath: RenderMath; convert: boolean; }; declare type RenderAction = [ number ] | [ number, string ] | [ number, string, string ] | [ number, RenderDoc, RenderMath ] | [ number, boolean ] | [ number, string, boolean ] | [ number, string, string, boolean ] | [ number, RenderDoc, RenderMath, boolean ]; declare type RenderActions = { [id: string]: RenderAction; }; declare class RenderList extends PrioritizedList> { static create(actions: RenderActions): RenderList; static action(id: string, action: RenderAction): [RenderData, number]; protected static methodActions(method1: string, method2?: string): ((math: any, document: any) => boolean)[]; renderDoc(document: MathDocument, start?: number): void; renderMath(math: MathItem, document: MathDocument, start?: number): void; renderConvert(math: MathItem, document: MathDocument, end?: number): void; findID(id: string): RenderData | null; } declare type ContainerList = string | N | (string | N | N[])[]; declare type ResetList = { all?: boolean; processed?: boolean; inputJax?: any[]; outputJax?: any[]; }; interface MathDocument { document: D; kind: string; options: OptionList; math: MathList; renderActions: RenderList; processed: BitField; inputJax: InputJax[]; outputJax: OutputJax; adaptor: DOMAdaptor; mmlFactory: MmlFactory; addRenderAction(id: string, ...action: any[]): void; removeRenderAction(id: string): void; render(): MathDocument; rerender(start?: number): MathDocument; convert(math: string, options?: OptionList): MmlNode | N; findMath(options?: OptionList): MathDocument; compile(): MathDocument; getMetrics(): MathDocument; typeset(): MathDocument; updateDocument(): MathDocument; removeFromDocument(restore?: boolean): MathDocument; state(state: number, restore?: boolean): MathDocument; reset(options?: ResetList): MathDocument; clear(): MathDocument; concat(list: MathList): MathDocument; clearMathItemsWithin(containers: ContainerList): MathItem[]; getMathItemsWithin(elements: ContainerList): MathItem[]; } declare abstract class AbstractMathDocument implements MathDocument { static KIND: string; static OPTIONS: OptionList; static ProcessBits: typeof BitField; document: D; options: OptionList; math: MathList; renderActions: RenderList; processed: BitField; inputJax: InputJax[]; outputJax: OutputJax; adaptor: DOMAdaptor; mmlFactory: MmlFactory; constructor(document: D, adaptor: DOMAdaptor, options: OptionList); get kind(): string; addRenderAction(id: string, ...action: any[]): void; removeRenderAction(id: string): void; render(): this; rerender(start?: number): this; convert(math: string, options?: OptionList): any; findMath(_options?: OptionList): this; compile(): this; protected compileMath(math: MathItem): void; compileError(math: MathItem, err: Error): void; typeset(): this; typesetError(math: MathItem, err: Error): void; getMetrics(): this; updateDocument(): this; removeFromDocument(_restore?: boolean): this; state(state: number, restore?: boolean): this; reset(options?: ResetList): this; clear(): this; concat(list: MathList): this; clearMathItemsWithin(containers: ContainerList): MathItem[]; getMathItemsWithin(elements: ContainerList): MathItem[]; } interface MathDocumentConstructor> { KIND: string; OPTIONS: OptionList; ProcessBits: typeof BitField; new (...args: any[]): D; } interface Handler { name: string; adaptor: DOMAdaptor; priority: number; documentClass: MathDocumentConstructor>; handlesDocument(document: any): boolean; create(document: any, options: OptionList): MathDocument; } interface MathJaxConfig extends MathJaxConfig$1 { startup?: { input?: string[]; output?: string; handler?: string; adaptor?: string; document?: any; elements?: any[]; typeset?: boolean; ready?: () => void; pageReady?: () => void; invalidOption?: 'fatal' | 'warn'; optionError?: (message: string, key: string) => void; [name: string]: any; }; } declare type MATHDOCUMENT = MathDocument; declare type HANDLER = Handler; declare type DOMADAPTOR = DOMAdaptor; declare type INPUTJAX = InputJax; declare type OUTPUTJAX = OutputJax; declare type HandlerExtension = (handler: HANDLER) => HANDLER; interface MathJaxObject extends MathJaxObject$1 { config: MathJaxConfig; startup: { constructors: { [name: string]: any; }; input: INPUTJAX[]; output: OUTPUTJAX; handler: HANDLER; adaptor: DOMADAPTOR; elements: any[]; document: MATHDOCUMENT; promise: Promise; registerConstructor(name: string, constructor: any): void; useHandler(name: string, force?: boolean): void; useAdaptor(name: string, force?: boolean): void; useOutput(name: string, force?: boolean): void; useInput(name: string, force?: boolean): void; extendHandler(extend: HandlerExtension): void; toMML(node: MmlNode): string; defaultReady(): void; defaultPageReady(): Promise; getComponents(): void; makeMethods(): void; makeTypesetMethods(): void; makeOutputMethods(iname: string, oname: string, input: INPUTJAX): void; makeMmlMethods(name: string, input: INPUTJAX): void; makeResetMethod(name: string, input: INPUTJAX): void; getInputJax(): INPUTJAX[]; getOutputJax(): OUTPUTJAX; getAdaptor(): DOMADAPTOR; getHandler(): HANDLER; }; [name: string]: any; } declare enum TexLang { MML = "MathML", TEX = "TeX" } interface IMathJaxContext { MathJax3: MathJaxObject | null; language: TexLang; } declare const initialMathJaxContext: IMathJaxContext; declare const MathJaxContextType: React.Context; interface IProps$2 { /** * Formula language. */ readonly lang: TexLang; /** * The literal formula string. */ readonly formula: string; /** * Whether to render the formulas in inline mode. */ readonly inline: boolean; /** * Mathjax render settings. */ readonly error: string; } declare class MathError extends React.PureComponent { static readonly displayName = "MathError"; static readonly propTypes: { lang: PropTypes.Validator; formula: PropTypes.Validator; inline: PropTypes.Validator; error: PropTypes.Validator; }; render(): React.ReactElement; } interface IMathJaxNodeProps { /** * The literal formula string. */ formula: string; /** * Whether to render the formulas in inline mode. * @default false */ inline?: boolean; /** * CSS class name. */ className?: string; /** * CSS style properties */ style?: React.CSSProperties; } declare const MathJaxNode: React.FC; interface IMathErrorProps { lang: TexLang; formula: string; inline: boolean; error: string; } interface IProps$1 { MathJax3: MathJaxObject; language: TexLang; formula: string; inline: boolean; className?: string; style?: React.CSSProperties; MathErrorRenderer?: React.ComponentType; } interface IState$1 { error: string | undefined; } declare class MathJaxNodeWithoutContext extends React.Component { static readonly displayName = "MathJaxNodeWithoutContext"; static readonly propTypes: { MathJax3: PropTypes.Validator; language: PropTypes.Validator; formula: PropTypes.Validator>; inline: PropTypes.Validator; className: PropTypes.Requireable; style: PropTypes.Requireable; MathErrorRenderer: PropTypes.Requireable; }; protected readonly _nodeRef: React.RefObject; protected readonly _typesettingRef: React.MutableRefObject; constructor(props: IProps$1); shouldComponentUpdate(nextProps: Readonly, nextState: Readonly): boolean; render(): React.ReactElement; componentDidMount(): void; componentDidUpdate(prevProps: Readonly): void; componentWillUnmount(): void; /** * Update math in the node * @param isForceUpdate */ protected _typeset(): void | never; protected _onTypesetDone(): void; } interface IProps { /** * http / https url for loading mathjax. * @default 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax3.js?config=TeX-MML-AM_CHTML' */ mathjaxSrc?: string; /** * MathJax3 config */ mathjaxConfig?: MathJaxConfig; /** * Contents / Animation displayed at waiting MathJax3 loading. * @default null */ loading?: React.ReactNode; /** * Sub components. */ children?: React.ReactNode; /** * Triggered on mathjax loaded. * @param MathJax3 */ onLoad?(MathJax3: MathJaxObject): void; /** * Triggered on mathjax thrown an error. * * @param MathJax3 * @param error */ onError?(MathJax3: MathJaxObject, error: any): void; } interface IState { loaded: boolean; context: IMathJaxContext; } declare class MathJaxProvider extends React.Component { static readonly displayName = "MathJaxProvider"; static readonly propTypes: { mathjaxSrc: PropTypes.Requireable; mathjaxConfig: PropTypes.Requireable; loading: PropTypes.Requireable; children: PropTypes.Requireable; onLoad: PropTypes.Requireable<(...args: any[]) => any>; onError: PropTypes.Requireable<(...args: any[]) => any>; }; protected _cancelLoad: (() => Promise) | undefined; constructor(props: IProps); shouldComponentUpdate(nextProps: Readonly, nextState: Readonly): boolean; render(): React.ReactElement; componentDidMount(): void; componentDidUpdate(prevProps: Readonly): void; componentWillUnmount(): void; protected load(): Promise; protected clear(): Promise; protected readonly onLoad: (MathJax3: MathJaxObject) => void; protected readonly onError: (MathJax3: MathJaxObject, error: unknown) => void; } declare function loadMathJax3(mathjax3Src: string, mathjax3Config: MathJaxConfig | undefined): Promise; export { MathError, MathJaxContextType, MathJaxNode, MathJaxNodeWithoutContext, MathJaxProvider, TexLang, initialMathJaxContext, loadMathJax3 }; export type { MathJaxObject as IMathJax3, MathJaxConfig as IMathJaxConfig3, IMathJaxContext };