From f52b2e3470e493d17ba591f63be7ad120509164f Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Tue, 1 Sep 2026 13:25:55 -0400 Subject: [PATCH 1/3] Refactor templates to convert to to reduce number of templates. --- ts/a11y/assistive-mml.ts | 108 ++--- ts/a11y/complexity.ts | 118 +++--- ts/a11y/complexity/visitor.ts | 29 +- ts/a11y/explorer.ts | 19 +- ts/a11y/explorer/KeyExplorer.ts | 5 +- ts/a11y/explorer/MouseExplorer.ts | 7 +- ts/a11y/semantic-enrich.ts | 128 +++--- ts/a11y/speech.ts | 116 +++--- ts/a11y/speech/GeneratorPool.ts | 39 +- ts/a11y/speech/WebWorker.ts | 66 ++- ts/adaptors/HTMLAdaptor.ts | 261 ++++++------ ts/adaptors/NodeMixin.ts | 30 +- ts/adaptors/browserAdaptor.ts | 5 +- ts/adaptors/jsdomAdaptor.ts | 14 +- ts/adaptors/linkedomAdaptor.ts | 9 +- ts/adaptors/lite/Parser.ts | 3 +- ts/adaptors/liteAdaptor.ts | 16 +- ts/components/package.ts | 13 +- ts/components/startup.ts | 55 +-- ts/core/DOMAdaptor.ts | 367 ++++++++-------- ts/core/FilterFunctions.ts | 24 +- ts/core/FindMath.ts | 25 +- ts/core/Handler.ts | 47 ++- ts/core/HandlerList.ts | 23 +- ts/core/InputJax.ts | 64 ++- ts/core/MathDocument.ts | 331 +++++++-------- ts/core/MathItem.ts | 103 +++-- ts/core/MathList.ts | 29 +- ts/core/MmlTree/MathMLVisitor.ts | 16 +- ts/core/MmlTree/MmlNode.ts | 5 +- ts/core/MmlTree/MmlNodes/HtmlNode.ts | 8 +- ts/core/MmlTree/TestMmlVisitor.ts | 2 +- ts/core/OutputJax.ts | 70 ++-- ts/core/Tree/Factory.ts | 16 +- ts/core/Tree/Node.ts | 26 +- ts/core/Tree/NodeFactory.ts | 8 +- ts/core/Tree/Visitor.ts | 16 +- ts/core/Tree/Wrapper.ts | 8 +- ts/core/Tree/WrapperFactory.ts | 2 +- ts/handlers/html.ts | 17 +- ts/handlers/html/HTMLDocument.ts | 92 ++-- ts/handlers/html/HTMLDomStrings.ts | 96 ++--- ts/handlers/html/HTMLHandler.ts | 19 +- ts/handlers/html/HTMLMathItem.ts | 29 +- ts/handlers/html/HTMLMathList.ts | 9 +- ts/input/asciimath.ts | 14 +- ts/input/asciimath/FindAsciiMath.ts | 17 +- ts/input/mathml.ts | 45 +- ts/input/mathml/FindMathML.ts | 35 +- ts/input/mathml/MathMLCompile.ts | 65 ++- ts/input/mathml/mml3/mml3-node.ts | 19 +- ts/input/mathml/mml3/mml3.ts | 33 +- ts/input/tex.ts | 38 +- ts/input/tex/ColumnParser.ts | 29 +- ts/input/tex/Configuration.ts | 19 +- ts/input/tex/FindTeX.ts | 21 +- ts/input/tex/ParseOptions.ts | 3 +- ts/input/tex/Tags.ts | 9 +- .../tex/autoload/AutoloadConfiguration.ts | 6 +- ts/input/tex/bussproofs/BussproofsUtil.ts | 6 +- ts/input/tex/color/ColorConfiguration.ts | 9 +- .../tex/colortbl/ColortblConfiguration.ts | 6 +- .../configmacros/ConfigMacrosConfiguration.ts | 12 +- .../tex/mathtools/MathtoolsConfiguration.ts | 6 +- ts/input/tex/mathtools/MathtoolsTags.ts | 14 +- .../tex/newcommand/NewcommandConfiguration.ts | 9 +- ts/input/tex/require/RequireConfiguration.ts | 22 +- .../tex/setoptions/SetOptionsConfiguration.ts | 9 +- .../tex/tagformat/TagFormatConfiguration.ts | 9 +- ts/input/tex/texhtml/TexHtmlConfiguration.ts | 8 +- .../tex/textmacros/TextMacrosConfiguration.ts | 9 +- ts/mathjax.ts | 8 +- ts/output/chtml.ts | 95 ++--- ts/output/chtml/FontData.ts | 9 +- ts/output/chtml/Notation.ts | 57 ++- ts/output/chtml/Wrapper.ts | 99 ++--- ts/output/chtml/WrapperFactory.ts | 46 +- ts/output/chtml/Wrappers.ts | 3 +- ts/output/chtml/Wrappers/HtmlNode.ts | 55 +-- ts/output/chtml/Wrappers/TeXAtom.ts | 98 ++--- ts/output/chtml/Wrappers/TextNode.ts | 116 ++---- ts/output/chtml/Wrappers/maction.ts | 124 ++---- ts/output/chtml/Wrappers/math.ts | 106 ++--- ts/output/chtml/Wrappers/menclose.ts | 142 +++---- ts/output/chtml/Wrappers/mfenced.ts | 102 ++--- ts/output/chtml/Wrappers/mfrac.ts | 164 +++----- ts/output/chtml/Wrappers/mglyph.ts | 102 ++--- ts/output/chtml/Wrappers/mi.ts | 96 ++--- ts/output/chtml/Wrappers/mmultiscripts.ts | 118 ++---- ts/output/chtml/Wrappers/mn.ts | 96 ++--- ts/output/chtml/Wrappers/mo.ts | 117 ++---- ts/output/chtml/Wrappers/mpadded.ts | 104 ++--- ts/output/chtml/Wrappers/mroot.ts | 104 ++--- ts/output/chtml/Wrappers/mrow.ts | 214 ++++------ ts/output/chtml/Wrappers/ms.ts | 98 ++--- ts/output/chtml/Wrappers/mspace.ts | 100 ++--- ts/output/chtml/Wrappers/msqrt.ts | 114 ++--- ts/output/chtml/Wrappers/msubsup.ts | 278 +++++-------- ts/output/chtml/Wrappers/mtable.ts | 146 +++---- ts/output/chtml/Wrappers/mtd.ts | 98 ++--- ts/output/chtml/Wrappers/mtext.ts | 100 ++--- ts/output/chtml/Wrappers/mtr.ts | 206 ++++----- ts/output/chtml/Wrappers/munderover.ts | 322 ++++++-------- ts/output/chtml/Wrappers/scriptbase.ts | 135 +++--- ts/output/chtml/Wrappers/semantics.ts | 279 +++++-------- ts/output/common.ts | 328 ++++++--------- ts/output/common/FontData.ts | 237 +++++------ ts/output/common/LinebreakVisitor.ts | 170 +++----- ts/output/common/Notation.ts | 29 +- ts/output/common/Wrapper.ts | 180 +++----- ts/output/common/WrapperFactory.ts | 50 +-- ts/output/common/Wrappers/TeXAtom.ts | 133 ++---- ts/output/common/Wrappers/TextNode.ts | 133 ++---- ts/output/common/Wrappers/XmlNode.ts | 154 +++---- ts/output/common/Wrappers/maction.ts | 304 +++++--------- ts/output/common/Wrappers/math.ts | 134 ++---- ts/output/common/Wrappers/menclose.ts | 160 +++---- ts/output/common/Wrappers/mfenced.ts | 139 +++---- ts/output/common/Wrappers/mfrac.ts | 137 +++--- ts/output/common/Wrappers/mglyph.ts | 139 +++---- ts/output/common/Wrappers/mi.ts | 133 ++---- ts/output/common/Wrappers/mmultiscripts.ts | 142 +++---- ts/output/common/Wrappers/mn.ts | 133 ++---- ts/output/common/Wrappers/mo.ts | 142 +++---- ts/output/common/Wrappers/mpadded.ts | 133 ++---- ts/output/common/Wrappers/mroot.ts | 133 ++---- ts/output/common/Wrappers/mrow.ts | 256 ++++-------- ts/output/common/Wrappers/ms.ts | 133 ++---- ts/output/common/Wrappers/mspace.ts | 133 ++---- ts/output/common/Wrappers/msqrt.ts | 137 +++--- ts/output/common/Wrappers/msubsup.ts | 393 ++++++------------ ts/output/common/Wrappers/mtable.ts | 141 +++---- ts/output/common/Wrappers/mtd.ts | 151 +++---- ts/output/common/Wrappers/mtext.ts | 135 ++---- ts/output/common/Wrappers/mtr.ts | 256 ++++-------- ts/output/common/Wrappers/munderover.ts | 380 ++++++----------- ts/output/common/Wrappers/scriptbase.ts | 213 ++++------ ts/output/common/Wrappers/semantics.ts | 133 ++---- ts/output/svg.ts | 165 ++++---- ts/output/svg/FontCache.ts | 15 +- ts/output/svg/Notation.ts | 53 ++- ts/output/svg/Wrapper.ts | 213 +++++----- ts/output/svg/WrapperFactory.ts | 46 +- ts/output/svg/Wrappers.ts | 3 +- ts/output/svg/Wrappers/HtmlNode.ts | 44 +- ts/output/svg/Wrappers/TeXAtom.ts | 100 ++--- ts/output/svg/Wrappers/TextNode.ts | 109 ++--- ts/output/svg/Wrappers/maction.ts | 128 ++---- ts/output/svg/Wrappers/math.ts | 98 ++--- ts/output/svg/Wrappers/menclose.ts | 233 ++++++----- ts/output/svg/Wrappers/merror.ts | 104 +++-- ts/output/svg/Wrappers/mfenced.ts | 104 ++--- ts/output/svg/Wrappers/mfrac.ts | 102 ++--- ts/output/svg/Wrappers/mglyph.ts | 102 ++--- ts/output/svg/Wrappers/mi.ts | 96 ++--- ts/output/svg/Wrappers/mmultiscripts.ts | 114 ++--- ts/output/svg/Wrappers/mn.ts | 96 ++--- ts/output/svg/Wrappers/mo.ts | 115 ++--- ts/output/svg/Wrappers/mpadded.ts | 102 ++--- ts/output/svg/Wrappers/mphantom.ts | 55 ++- ts/output/svg/Wrappers/mroot.ts | 102 ++--- ts/output/svg/Wrappers/mrow.ts | 218 ++++------ ts/output/svg/Wrappers/ms.ts | 98 ++--- ts/output/svg/Wrappers/mspace.ts | 98 ++--- ts/output/svg/Wrappers/msqrt.ts | 112 ++--- ts/output/svg/Wrappers/msubsup.ts | 276 +++++------- ts/output/svg/Wrappers/mtable.ts | 153 +++---- ts/output/svg/Wrappers/mtd.ts | 98 ++--- ts/output/svg/Wrappers/mtext.ts | 100 ++--- ts/output/svg/Wrappers/mtr.ts | 212 ++++------ ts/output/svg/Wrappers/munderover.ts | 284 +++++-------- ts/output/svg/Wrappers/scriptbase.ts | 104 ++--- ts/output/svg/Wrappers/semantics.ts | 271 +++++------- ts/types/Components.ts | 23 +- ts/types/Types.ts | 8 +- ts/ui/dialog/DraggableDialog.ts | 3 +- ts/ui/lazy/LazyHandler.ts | 166 ++++---- ts/ui/menu/MJContextMenu.ts | 3 +- ts/ui/menu/Menu.ts | 13 +- ts/ui/menu/MenuHandler.ts | 30 +- ts/ui/menu/MmlVisitor.ts | 11 +- ts/ui/no-dark-mode/no-dark-mode.ts | 3 +- ts/ui/safe/SafeHandler.ts | 58 ++- ts/ui/safe/SafeMethods.ts | 144 +++---- ts/ui/safe/safe.ts | 42 +- 185 files changed, 6824 insertions(+), 10723 deletions(-) diff --git a/ts/a11y/assistive-mml.ts b/ts/a11y/assistive-mml.ts index a361da18bd..1bb4f13122 100644 --- a/ts/a11y/assistive-mml.ts +++ b/ts/a11y/assistive-mml.ts @@ -34,7 +34,7 @@ import { MmlNode } from '../core/MmlTree/MmlNode.js'; import { SerializedMmlVisitor } from '../core/MmlTree/SerializedMmlVisitor.js'; import { expandable } from '../util/Options.js'; import { StyleJson } from '../util/StyleJson.js'; -import { DOM, DOM_TYPES, N, T, D, Constructor } from '../types/Types.js'; +import { DOM_TYPES, N, Constructor } from '../types/Types.js'; /*==========================================================================*/ @@ -60,46 +60,38 @@ newState('ASSISTIVEMML', 153); /** * The functions added to MathItem for assistive MathML * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface AssistiveMmlMathItem extends AbstractMathItem< - N, - T, - D -> { +export interface AssistiveMmlMathItem< + DOM extends DOM_TYPES, +> extends AbstractMathItem { /** * @param {MathDocument} document The document where assistive MathML is being added * @param {boolean} force True to force assistive MathML even if enableAssistiveMml is false */ - assistiveMml(document: MathDocument, force?: boolean): void; + assistiveMml(document: MathDocument, force?: boolean): void; } /** * The mixin for adding assistive MathML to MathItems * - * @param {B} BaseMathItem The MathItem class to be extended + * @param {B} BaseMathItem The MathItem class to be extended * @returns {AssistiveMmlMathItem} The augmented MathItem class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathItem class to extend + * @template DOM The DOM node types + * @template B The MathItem class to extend */ export function AssistiveMmlMathItemMixin< - N, - T, - D, - B extends Constructor>, ->(BaseMathItem: B): Constructor> & B { + DOM extends DOM_TYPES, + B extends Constructor>, +>(BaseMathItem: B): Constructor> & B { return class extends BaseMathItem { /** * @param {MathDocument} document The MathDocument for the MathItem * @param {boolean} force True to force assistive MathML evenif enableAssistiveMml is false */ public assistiveMml( - document: AssistiveMmlMathDocument, + document: AssistiveMmlMathDocument, force: boolean = false ) { if (this.state() >= STATE.ASSISTIVEMML) return; @@ -133,7 +125,7 @@ export function AssistiveMmlMathItemMixin< // Hide the typeset math from assistive technology and append the MathML that is visually // hidden from other users // - for (const child of adaptor.childNodes(this.typesetRoot) as N[]) { + for (const child of adaptor.childNodes(this.typesetRoot) as N[]) { adaptor.setAttribute(child, 'aria-hidden', 'true'); } adaptor.setStyle(this.typesetRoot, 'position', 'relative'); @@ -158,7 +150,7 @@ export type OPTIONS = { */ export interface ASSISTIVEMML_OPTIONS extends OPTIONS, DOCUMENT_OPTIONS { - MathItem: Constructor, T, D>>; + MathItem: Constructor>; } /** @@ -173,23 +165,19 @@ const options: OPTIONS = { /** * The functions added to MathDocument for assistive MathML * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface AssistiveMmlMathDocument extends AbstractMathDocument< - N, - T, - D -> { +export interface AssistiveMmlMathDocument< + DOM extends DOM_TYPES, +> extends AbstractMathDocument { /** * @override */ - options: ASSISTIVEMML_OPTIONS>; + options: ASSISTIVEMML_OPTIONS; /** * @param {MmlNode} node The node to be serializes - * @returns {string} The serialization of the node + * @returns {string} The serialization of the node */ toMML: (node: MmlNode) => string; @@ -204,26 +192,18 @@ export interface AssistiveMmlMathDocument extends AbstractMathDocument< /** * The mixin for adding assistive MathML to MathDocuments * - * @param {B} BaseDocument The MathDocument class to be extended + * @param {B} BaseDocument The MathDocument class to be extended * @returns {AssistiveMmlMathDocument} The Assistive MathML MathDocument class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathDocument class to extend + * @template DOM The DOM node types + * @template B The MathDocument class to extend */ export function AssistiveMmlMathDocumentMixin< - N, - T, - D, - B extends MathDocumentConstructor< - AbstractMathDocument, - DOM - >, + DOM extends DOM_TYPES, + B extends MathDocumentConstructor, DOM>, >( BaseDocument: B -): MathDocumentConstructor, DOM> & - B { +): MathDocumentConstructor, DOM> { return class BaseClass extends BaseDocument { /** * @override @@ -234,13 +214,13 @@ export function AssistiveMmlMathDocumentMixin< renderActions: expandable({ ...BaseDocument.OPTIONS.renderActions, assistiveMml: [STATE.ASSISTIVEMML], - }) as RenderActions, + }) as RenderActions, }; /** * @override */ - options: ASSISTIVEMML_OPTIONS>; + options: ASSISTIVEMML_OPTIONS; /** * styles needed for the hidden MathML @@ -295,10 +275,8 @@ export function AssistiveMmlMathDocumentMixin< } this.visitor = new LimitedMmlVisitor(this.mmlFactory); this.options.MathItem = AssistiveMmlMathItemMixin< - N, - T, - D, - Constructor> + DOM, + Constructor> >(this.options.MathItem); if ('addStyles' in this) { (this as any).addStyles(CLASS.assistiveStyles); @@ -307,7 +285,7 @@ export function AssistiveMmlMathDocumentMixin< /** * @param {MmlNode} node The node to be serializes - * @returns {string} The serialization of the node + * @returns {string} The serialization of the node */ public toMML(node: MmlNode): string { return this.visitor.visitTree(node); @@ -316,12 +294,12 @@ export function AssistiveMmlMathDocumentMixin< /** * Add assistive MathML to the MathItems in this MathDocument * - * @returns {AssistiveMmlMathDocument} The assistive mml document. + * @returns {AssistiveMmlMathDocument} The assistive mml document. */ public assistiveMml(): this { if (!this.processed.isSet('assistive-mml')) { for (const math of this.math) { - (math as AssistiveMmlMathItem).assistiveMml(this); + (math as AssistiveMmlMathItem).assistiveMml(this); } this.processed.set('assistive-mml'); } @@ -347,20 +325,16 @@ export function AssistiveMmlMathDocumentMixin< * Add assitive MathML support a Handler instance * * @param {Handler} handler The Handler instance to enhance - * @returns {Handler} The handler that was modified (for purposes of chainging extensions) + * @returns {Handler} The handler that was modified (for purposes of chainging extensions) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export function AssistiveMmlHandler( - handler: Handler -): Handler { +export function AssistiveMmlHandler( + handler: Handler +): Handler { handler.documentClass = AssistiveMmlMathDocumentMixin< - N, - T, - D, - MathDocumentConstructor, DOM> + DOM, + MathDocumentConstructor, DOM> >(handler.documentClass); return handler; } diff --git a/ts/a11y/complexity.ts b/ts/a11y/complexity.ts index 0e2ebeafa9..7cbc470d0d 100644 --- a/ts/a11y/complexity.ts +++ b/ts/a11y/complexity.ts @@ -37,18 +37,22 @@ import { } from './semantic-enrich.js'; import { ComplexityVisitor } from './complexity/visitor.js'; import { selectOptionsFromKeys, expandable } from '../util/Options.js'; -import { DOM, DOM_TYPES, N, T, D, Constructor } from '../types/Types.js'; +import { DOM_TYPES, Constructor } from '../types/Types.js'; /** * Shorthands for constructors */ -export type EMItemC = Constructor>; -export type CMItemC = Constructor>; -export type EMDocC = MathDocumentConstructor< - EnrichedMathDocument, - DOM +export type EMItemC = Constructor>; +export type CMItemC = Constructor< + ComplexityMathItem +>; +export type EMDocC = MathDocumentConstructor< + EnrichedMathDocument, + DOM +>; +export type CMDocC = Constructor< + ComplexityMathDocument >; -export type CMDocC = Constructor>; /*==========================================================================*/ @@ -60,11 +64,11 @@ newState('COMPLEXITY', 40); /** * The functions added to MathItem for complexity * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ComplexityMathItem extends EnrichedMathItem { +export interface ComplexityMathItem< + DOM extends DOM_TYPES, +> extends EnrichedMathItem { /** * The starting collapse ID for this expression */ @@ -74,25 +78,26 @@ export interface ComplexityMathItem extends EnrichedMathItem { * @param {ComplexityMathDocument} document The MathDocument for the MathItem * @param {boolean} force True to force the computation even if enableComplexity is false */ - complexity(document: ComplexityMathDocument, force?: boolean): void; + complexity(document: ComplexityMathDocument, force?: boolean): void; } /** * The mixin for adding complexity to MathItems * - * @param {B} BaseMathItem The MathItem class to be extended - * @param {(math: ComplexityMathItem) => void} computeComplexity Method of complexity computation. - * @returns {ComplexityMathItem} The complexity MathItem class + * @param {B} BaseMathItem The MathItem class to be extended + * @param {(math: ComplexityMathItem) => void} computeComplexity Method of complexity computation. + * @returns {ComplexityMathItem} The complexity MathItem class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathItem class to extend + * @template DOM The DOM node types + * @template B The MathItem class to extend */ -export function ComplexityMathItemMixin>( +export function ComplexityMathItemMixin< + DOM extends DOM_TYPES, + B extends EMItemC, +>( BaseMathItem: B, - computeComplexity: (math: ComplexityMathItem) => void -): CMItemC & B { + computeComplexity: (math: ComplexityMathItem) => void +): CMItemC & B { return class extends BaseMathItem { /** * The starting collapse ID for this expression @@ -104,7 +109,7 @@ export function ComplexityMathItemMixin>( * @param {boolean} force True to force the computation even if enableComplexity is false */ public complexity( - document: ComplexityMathDocument, + document: ComplexityMathDocument, force: boolean = false ) { if (this.state() >= STATE.COMPLEXITY) return; @@ -132,7 +137,7 @@ export type OPTIONS = { */ export interface COMPLEXITY_OPTIONS extends OPTIONS, ENRICH_OPTIONS { - MathItem: Constructor, T, D>>; + MathItem: Constructor>; } /** @@ -148,19 +153,15 @@ const options: OPTIONS = { /** * The functions added to MathDocument for complexity * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ComplexityMathDocument extends EnrichedMathDocument< - N, - T, - D -> { +export interface ComplexityMathDocument< + DOM extends DOM_TYPES, +> extends EnrichedMathDocument { /** * @override */ - options: COMPLEXITY_OPTIONS>; + options: COMPLEXITY_OPTIONS; /** * Perform complexity computations on the MathItems in the MathDocument @@ -173,17 +174,16 @@ export interface ComplexityMathDocument extends EnrichedMathDocument< /** * The mixin for adding complexity to MathDocuments * - * @param {B} BaseDocument The MathDocument class to be extended - * @returns {EnrichedMathDocument} The enriched MathDocument class + * @param {B} BaseDocument The MathDocument class to be extended + * @returns {EnrichedMathDocument} The enriched MathDocument class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathDocument class to extend + * @template DOM The DOM node types + * @template B The MathDocument class to extend */ -export function ComplexityMathDocumentMixin>( - BaseDocument: B -): CMDocC & B { +export function ComplexityMathDocumentMixin< + DOM extends DOM_TYPES, + B extends EMDocC, +>(BaseDocument: B): CMDocC & B { return class extends BaseDocument { /** * The options for this type of document @@ -192,7 +192,7 @@ export function ComplexityMathDocumentMixin>( ...BaseDocument.OPTIONS, ...ComplexityVisitor.OPTIONS, ...options, - renderActions: expandable>({ + renderActions: expandable>({ ...BaseDocument.OPTIONS.renderActions, complexity: [STATE.COMPLEXITY], }), @@ -201,7 +201,7 @@ export function ComplexityMathDocumentMixin>( /** * @override */ - public options: COMPLEXITY_OPTIONS>; + public options: COMPLEXITY_OPTIONS; /** * The visitor that computes complexities @@ -228,7 +228,7 @@ export function ComplexityMathDocumentMixin>( this.mmlFactory, visitorOptions ); - const computeComplexity = (math: ComplexityMathItem) => { + const computeComplexity = (math: ComplexityMathItem) => { math.parseSemanticNodes(); math.initialID = this.complexityVisitor.visitTree( math.root, @@ -236,12 +236,10 @@ export function ComplexityMathDocumentMixin>( math.semanticNodes ); }; - this.options.MathItem = ComplexityMathItemMixin< - N, - T, - D, - EMItemC - >(this.options.MathItem, computeComplexity); + this.options.MathItem = ComplexityMathItemMixin>( + this.options.MathItem, + computeComplexity + ); } /** @@ -253,7 +251,7 @@ export function ComplexityMathDocumentMixin>( if (!this.processed.isSet('complexity')) { if (this.options.enableComplexity) { for (const math of this.math) { - (math as ComplexityMathItem).complexity(this); + (math as ComplexityMathItem).complexity(this); } } this.processed.set('complexity'); @@ -283,19 +281,17 @@ export function ComplexityMathDocumentMixin>( * @param {MathML} MmlJax The MathML input jax to use for reading the enriched MathML * @returns {Handler} The handler that was modified (for purposes of chainging extensions) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export function ComplexityHandler( - handler: Handler, - MmlJax: MathML = null -): Handler { +export function ComplexityHandler( + handler: Handler, + MmlJax: MathML = null +): Handler { if (!handler.documentClass.prototype.enrich && MmlJax) { handler = EnrichHandler(handler, MmlJax); } - handler.documentClass = ComplexityMathDocumentMixin>( - handler.documentClass as any + handler.documentClass = ComplexityMathDocumentMixin>( + handler.documentClass as EMDocC ); return handler; } diff --git a/ts/a11y/complexity/visitor.ts b/ts/a11y/complexity/visitor.ts index fbcb3a3507..b66c97fb7c 100644 --- a/ts/a11y/complexity/visitor.ts +++ b/ts/a11y/complexity/visitor.ts @@ -75,22 +75,21 @@ export class ComplexityVisitor extends MmlVisitor { /** * Values used to compute complexities */ - /* prettier-ignore */ public complexity = { - text: .5, // each character of a token element adds this to complexity - token: .5, // each token element gets this additional complexity - child: 1, // child nodes add this to their parent node's complexity - - script: .8, // script elements reduce their complexity by this factor - sqrt: 2, // sqrt adds this extra complexity - subsup: 2, // sub-sup adds this extra complexity - underover: 2, // under-over adds this extra complexity - fraction: 2, // fractions add this extra complexity - enclose: 2, // menclose adds this extra complexity - action: 2, // maction adds this extra complexity - phantom: 0, // mphantom makes complexity 0? - xml: 2, // Can't really measure complexity of annotation-xml, so punt - glyph: 2 // Can't really measure complexity of mglyph, to punt + text: 0.5, // Each character of a token element adds this to complexity + token: 0.5, // Each token element gets this additional complexity + child: 1, // Child nodes add this to their parent node's complexity + + script: 0.8, // Script elements reduce their complexity by this factor + sqrt: 2, // Sqrt adds this extra complexity + subsup: 2, // Sub-sup adds this extra complexity + underover: 2, // Under-over adds this extra complexity + fraction: 2, // Fractions add this extra complexity + enclose: 2, // Menclose adds this extra complexity + action: 2, // Maction adds this extra complexity + phantom: 0, // Mphantom makes complexity 0? + xml: 2, // Can't really measure complexity of annotation-xml, so punt + glyph: 2, // Can't really measure complexity of mglyph, to punt }; /** diff --git a/ts/a11y/explorer.ts b/ts/a11y/explorer.ts index 668e1cf89c..786e744d85 100644 --- a/ts/a11y/explorer.ts +++ b/ts/a11y/explorer.ts @@ -55,12 +55,12 @@ const isUnix = context.os === 'Unix'; /** * Shorthands for types with HTMLElement, Text, and Document instead of generics */ -export type HANDLER = Handler; -export type HTMLDOCUMENT = SpeechMathDocument & { +export type HANDLER = Handler; +export type HTMLDOCUMENT = SpeechMathDocument & { menu?: any; }; -export type HTMLMATHITEM = SpeechMathItem; -export type MATHML = MathML; +export type HTMLMATHITEM = SpeechMathItem; +export type MATHML = MathML; /*==========================================================================*/ @@ -468,7 +468,7 @@ export interface ExplorerMathDocument extends HTMLDOCUMENT { /** * The mixin for adding the Explorer to MathDocuments * - * @param {B} BaseDocument The MathDocument class to be extended + * @param {B} BaseDocument The MathDocument class to be extended * @returns {ExplorerMathDocument} The extended MathDocument class * * @template B The MathItem class to extend @@ -482,17 +482,16 @@ export function ExplorerMathDocumentMixin< /** * @override */ - /* prettier-ignore */ public static OPTIONS = { ...BaseDocument.OPTIONS, ...options, - renderActions: expandable>({ + renderActions: expandable>({ ...BaseDocument.OPTIONS.renderActions, - explorable: [STATE.EXPLORER] + explorable: [STATE.EXPLORER], }), sre: expandable({ - ...(BaseDocument.OPTIONS as SPEECH_OPTIONS).sre, - speech: 'none', // None as speech is explicitly computed + ...(BaseDocument.OPTIONS as SPEECH_OPTIONS).sre, + speech: 'none', // None as speech is explicitly computed }), a11y: expandable({ ...(BaseDocument.OPTIONS as SPEECH_OPTIONS).a11y, diff --git a/ts/a11y/explorer/KeyExplorer.ts b/ts/a11y/explorer/KeyExplorer.ts index 4e4d2e6408..b6ce821c8b 100644 --- a/ts/a11y/explorer/KeyExplorer.ts +++ b/ts/a11y/explorer/KeyExplorer.ts @@ -36,6 +36,7 @@ import { GeneratorPool } from '../speech/GeneratorPool.js'; import { context } from '../../util/context.js'; import { InfoDialog } from '../../ui/dialog/InfoDialog.js'; import { localize } from './__locales__/Component.js'; +import { HTML_DOM } from '../../types/dom/html.js'; /**********************************************************************/ @@ -217,7 +218,7 @@ export class SpeechExplorer * * @returns {GeneratorPool} The item's generator pool. */ - private get generators(): GeneratorPool { + private get generators(): GeneratorPool { return this.item?.generatorPool; } @@ -383,7 +384,7 @@ export class SpeechExplorer this.Start(); this.backTab = event.target === this.img; } else if (!this.focusSpeech) { - this.speak(''); // don't speak initial equation until click event + this.speak(''); // don't speak initial equation until click event } this.clicked = null; } diff --git a/ts/a11y/explorer/MouseExplorer.ts b/ts/a11y/explorer/MouseExplorer.ts index 9642eb055f..7a4a63781c 100644 --- a/ts/a11y/explorer/MouseExplorer.ts +++ b/ts/a11y/explorer/MouseExplorer.ts @@ -22,12 +22,7 @@ */ import type { ExplorerMathDocument } from '../explorer.js'; -import { - DummyRegion, - Region, - HoverRegion, - ToolTip, -} from './Region.js'; +import { DummyRegion, Region, HoverRegion, ToolTip } from './Region.js'; import { Explorer, AbstractExplorer } from './Explorer.js'; import { ExplorerPool } from './ExplorerPool.js'; import type { ExplorerMathItem } from '../explorer.js'; diff --git a/ts/a11y/semantic-enrich.ts b/ts/a11y/semantic-enrich.ts index 82a9d93f45..ed791fa09e 100644 --- a/ts/a11y/semantic-enrich.ts +++ b/ts/a11y/semantic-enrich.ts @@ -47,7 +47,7 @@ import { MACTION } from './semantic-enrich/maction.js'; import { StructureUtil, SemanticMap } from './speech/StructureUtil.js'; import { Locale } from '../util/Locale.js'; import { COMPONENT } from './semantic-enrich/__locales__/Component.js'; -import { DOM, DOM_TYPES, N, T, D, Constructor } from '../types/Types.js'; +import { DOM, DOM_TYPES, Constructor } from '../types/Types.js'; /*==========================================================================*/ @@ -58,10 +58,10 @@ newState('ENRICHED', STATE.COMPILED + 10); /*==========================================================================*/ -export class enrichVisitor extends SerializedMmlVisitor { +export class enrichVisitor extends SerializedMmlVisitor { protected mactionId: number; - public visitTree(node: MmlNode, math?: MathItem) { + public visitTree(node: MmlNode, math?: MathItem) { this.mactionId = 0; const mml = super.visitTree(node); if (this.mactionId) { @@ -104,11 +104,11 @@ export class enrichVisitor extends SerializedMmlVisitor { /** * The functions added to MathItem for enrichment * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface EnrichedMathItem extends AbstractMathItem { +export interface EnrichedMathItem< + DOM extends DOM_TYPES, +> extends AbstractMathItem { /** * Maps semantic ids to extra nodes outside the DOM subtree. */ @@ -122,18 +122,18 @@ export interface EnrichedMathItem extends AbstractMathItem { /** * The serialization visitor */ - toMathML: (node: MmlNode, math: MathItem) => string; + toMathML: (node: MmlNode, math: MathItem) => string; /** * @param {MathDocument} document The document where enrichment is occurring * @param {boolean} force True to force the enrichment even if not enabled */ - enrich(document: MathDocument, force?: boolean): void; + enrich(document: MathDocument, force?: boolean): void; /** * @param {MathDocument} document The MathDocument for the MathItem */ - unEnrich(document: MathDocument): void; + unEnrich(document: MathDocument): void; /** * @param {string} mml The MathML string to enrich @@ -150,21 +150,17 @@ export interface EnrichedMathItem extends AbstractMathItem { * @param {Function} toMathML The function to serialize the internal MathML * @returns {EnrichedMathItem} The enriched MathItem class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathItem class to extend + * @template DOM The DOM Node types + * @template B The MathItem class to extend */ export function EnrichedMathItemMixin< - N, - T, - D, - B extends Constructor>, + DOM extends DOM_TYPES, + B extends Constructor>, >( BaseMathItem: B, - MmlJax: MathML, - toMathML: (node: MmlNode, math: MathItem) => string -): Constructor> & B { + MmlJax: MathML, + toMathML: (node: MmlNode, math: MathItem) => string +): Constructor> & B { return class extends BaseMathItem { /** * The MathML serializer @@ -215,10 +211,7 @@ export function EnrichedMathItemMixin< * @param {EnrichedMathDocument} document The MathDocument for the MathItem * @param {boolean} force True to force the enrichment even if not enabled */ - public enrich( - document: EnrichedMathDocument, - force: boolean = false - ) { + public enrich(document: EnrichedMathDocument, force: boolean = false) { if (this.state() >= STATE.ENRICHED) return; if (!this.isEscaped && (document.options.enableEnrichment || force)) { this.semanticNodes = null; @@ -265,7 +258,7 @@ export function EnrichedMathItemMixin< /** * @param {MathDocument} document The MathDocument for the MathItem */ - public unEnrich(document: MathDocument) { + public unEnrich(document: MathDocument) { const mml = this.inputData.originalMml; if (!mml) return; const math = new document.options.MathItem('', MmlJax); @@ -334,8 +327,8 @@ const SRE_options: SRE_OPTIONS = { export interface OPTIONS { enableEnrichment: boolean; enrichError: ( - doc: EnrichedMathDocument, T, D>, - math: EnrichedMathItem, T, D>, + doc: EnrichedMathDocument, + math: EnrichedMathItem, err: Error ) => void; sre: SRE_OPTIONS; @@ -346,7 +339,7 @@ export interface OPTIONS { */ export interface ENRICH_OPTIONS extends OPTIONS, DOCUMENT_OPTIONS { - MathItem: Constructor, T, D>>; + MathItem: Constructor>; } /** @@ -363,19 +356,15 @@ const options: OPTIONS = { /** * The functions added to MathDocument for enrichment * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface EnrichedMathDocument extends AbstractMathDocument< - N, - T, - D -> { +export interface EnrichedMathDocument< + DOM extends DOM_TYPES, +> extends AbstractMathDocument { /** * @override */ - options: ENRICH_OPTIONS>; + options: ENRICH_OPTIONS; /** * Perform enrichment on the MathItems in the MathDocument @@ -390,8 +379,8 @@ export interface EnrichedMathDocument extends AbstractMathDocument< * @param {Error} err The error being processed */ enrichError( - doc: EnrichedMathDocument, - math: EnrichedMathItem, + doc: EnrichedMathDocument, + math: EnrichedMathItem, err: Error ): void; } @@ -403,23 +392,16 @@ export interface EnrichedMathDocument extends AbstractMathDocument< * @param {MathML} MmlJax The MathML input jax used to convert the enriched MathML * @returns {EnrichedMathDocument} The enriched MathDocument class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathDocument class to extend + * @template DOM The DOM Node types + * @template B The MathDocument class to extend */ export function EnrichedMathDocumentMixin< - N, - T, - D, - B extends MathDocumentConstructor< - AbstractMathDocument, - DOM - >, + DOM extends DOM_TYPES, + B extends MathDocumentConstructor, DOM>, >( BaseDocument: B, - MmlJax: MathML -): MathDocumentConstructor, DOM> & B { + MmlJax: MathML +): MathDocumentConstructor, DOM> { return class extends BaseDocument { /** * @override @@ -427,7 +409,7 @@ export function EnrichedMathDocumentMixin< public static OPTIONS = { ...BaseDocument.OPTIONS, ...options, - renderActions: expandable>({ + renderActions: expandable>({ ...BaseDocument.OPTIONS.renderActions, enrich: [STATE.ENRICHED], }), @@ -436,7 +418,7 @@ export function EnrichedMathDocumentMixin< /** * @override */ - public options: ENRICH_OPTIONS>; + public options: ENRICH_OPTIONS; /** * Enrich the MathItem class used for this MathDocument, and create the @@ -453,14 +435,12 @@ export function EnrichedMathDocumentMixin< if (!ProcessBits.has('enriched')) { ProcessBits.allocate('enriched'); } - const visitor = new enrichVisitor(this.mmlFactory); - const toMathML = (node: MmlNode, math: MathItem) => + const visitor = new enrichVisitor(this.mmlFactory); + const toMathML = (node: MmlNode, math: MathItem) => visitor.visitTree(node, math); this.options.MathItem = EnrichedMathItemMixin< - N, - T, - D, - Constructor> + DOM, + Constructor> >(this.options.MathItem, MmlJax, toMathML); } @@ -474,7 +454,7 @@ export function EnrichedMathDocumentMixin< if (this.options.enableEnrichment) { Sre.setupEngine(this.options.sre as any); for (const math of this.math) { - (math as EnrichedMathItem).enrich(this); + (math as EnrichedMathItem).enrich(this); } } this.processed.set('enriched'); @@ -486,8 +466,8 @@ export function EnrichedMathDocumentMixin< * @override */ public enrichError( - _doc: EnrichedMathDocument, - _math: EnrichedMathItem, + _doc: EnrichedMathDocument, + _math: EnrichedMathItem, err: Error ) { console.warn(Locale.message(COMPONENT, 'EnrichError'), err); @@ -502,7 +482,7 @@ export function EnrichedMathDocumentMixin< this.processed.clear('enriched'); if (state >= STATE.COMPILED) { for (const item of this.math) { - (item as EnrichedMathItem).unEnrich(this); + (item as EnrichedMathItem).unEnrich(this); } } } @@ -520,20 +500,16 @@ export function EnrichedMathDocumentMixin< * @param {MathML} MmlJax The MathML input jax to use for reading the enriched MathML * @returns {Handler} The handler that was modified (for purposes of chainging extensions) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export function EnrichHandler( - handler: Handler, - MmlJax: MathML -): Handler { +export function EnrichHandler( + handler: Handler, + MmlJax: MathML +): Handler { MmlJax.setAdaptor(handler.adaptor); handler.documentClass = EnrichedMathDocumentMixin< - N, - T, - D, - MathDocumentConstructor, DOM> + DOM, + MathDocumentConstructor, DOM> >(handler.documentClass, MmlJax); return handler; } diff --git a/ts/a11y/speech.ts b/ts/a11y/speech.ts index 2103ee9a04..af5e579e02 100644 --- a/ts/a11y/speech.ts +++ b/ts/a11y/speech.ts @@ -40,7 +40,7 @@ import { GeneratorPool } from './speech/GeneratorPool.js'; import { WorkerHandler } from './speech/WebWorker.js'; import { sreRoot } from '#root/sre-root.js'; import { localize } from './speech/__locales__/Component.js'; -import { DOM, DOM_TYPES, N, T, D, Constructor } from '../types/Types.js'; +import { DOM, DOM_TYPES, Constructor } from '../types/Types.js'; /*==========================================================================*/ @@ -54,25 +54,25 @@ newState('ATTACHSPEECH', STATE.INSERTED + 10); /** * The functions added to MathItem for enrichment * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SpeechMathItem extends EnrichedMathItem { +export interface SpeechMathItem< + DOM extends DOM_TYPES, +> extends EnrichedMathItem { /** * The speech generators for this math item. */ - generatorPool: GeneratorPool; + generatorPool: GeneratorPool; /** * @param {MathDocument} document The document where speech is added */ - attachSpeech(document: MathDocument): void; + attachSpeech(document: MathDocument): void; /** * @param {MathDocument} document The MathDocument for the MathItem */ - detachSpeech(document: MathDocument): void; + detachSpeech(document: MathDocument): void; /** * @param {string} mml The MathML whose speech is needed. @@ -87,29 +87,25 @@ export interface SpeechMathItem extends EnrichedMathItem { * @param {B} EnrichedMathItem The MathItem class to be extended * @returns {SpeechMathItem} The enriched MathItem class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathItem class to extend + * @template DOM The DOM node types + * @template B The MathItem class to extend */ export function SpeechMathItemMixin< - N, - T, - D, - B extends Constructor>, ->(EnrichedMathItem: B): Constructor> & B { + DOM extends DOM_TYPES, + B extends Constructor>, +>(EnrichedMathItem: B): Constructor> & B { return class extends EnrichedMathItem { /** * @override */ - public generatorPool = new GeneratorPool(); + public generatorPool = new GeneratorPool(); /** * Attaches the aria labels for speech and braille. * * @param {MathDocument} document The MathDocument for the MathItem */ - public attachSpeech(document: SpeechMathDocument) { + public attachSpeech(document: SpeechMathDocument) { this.outputData.speechPromise = null; if (this.state() >= STATE.ATTACHSPEECH) return; this.state(STATE.ATTACHSPEECH); @@ -137,7 +133,7 @@ export function SpeechMathItemMixin< /** * @param {SpeechMathDocument} document The MathDocument for the MathItem */ - public detachSpeech(document: SpeechMathDocument) { + public detachSpeech(document: SpeechMathDocument) { document.webworker.Detach(this); } @@ -177,8 +173,8 @@ export type OPTIONS = { enableSpeech: boolean; enableBraille: boolean; speechError: ( - doc: SpeechMathDocument, T, D>, - math: SpeechMathItem, T, D>, + doc: SpeechMathDocument, + math: SpeechMathItem, err: string ) => void; worker: { @@ -201,7 +197,7 @@ export type A11Y_OPTIONS = { */ export interface SPEECH_OPTIONS extends OPTIONS, A11Y_OPTIONS, ENRICH_OPTIONS { - MathItem: Constructor, T, D>>; + MathItem: Constructor>; } /** @@ -224,24 +220,20 @@ const options: OPTIONS = { /** * The functions added to MathDocument for enrichment * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SpeechMathDocument extends EnrichedMathDocument< - N, - T, - D -> { +export interface SpeechMathDocument< + DOM extends DOM_TYPES, +> extends EnrichedMathDocument { /** * @override */ - options: SPEECH_OPTIONS>; + options: SPEECH_OPTIONS; /** * The webworker handler for the document */ - webworker: WorkerHandler; + webworker: WorkerHandler; /** * Attach speech to the MathItems in the MathDocument @@ -256,8 +248,8 @@ export interface SpeechMathDocument extends EnrichedMathDocument< * @param {string} err The error message being processed */ speechError( - doc: SpeechMathDocument, - math: SpeechMathItem, + doc: SpeechMathDocument, + math: SpeechMathItem, err: string ): void; @@ -273,22 +265,15 @@ export interface SpeechMathDocument extends EnrichedMathDocument< * @param {B} EnrichedMathDocument The MathDocument class to be extended * @returns {SpeechMathDocument} The enriched MathDocument class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathDocument class to extend + * @template DOM The DOM node types + * @template B The MathDocument class to extend */ export function SpeechMathDocumentMixin< - N, - T, - D, - B extends MathDocumentConstructor< - EnrichedMathDocument, - DOM - >, + DOM extends DOM_TYPES, + B extends MathDocumentConstructor, DOM>, >( EnrichedMathDocument: B -): MathDocumentConstructor, DOM> & B { +): MathDocumentConstructor, DOM> & B { return class extends EnrichedMathDocument { /** * @override @@ -296,7 +281,7 @@ export function SpeechMathDocumentMixin< public static OPTIONS = { ...EnrichedMathDocument.OPTIONS, ...options, - renderActions: expandable>({ + renderActions: expandable>({ ...EnrichedMathDocument.OPTIONS.renderActions, attachSpeech: [STATE.ATTACHSPEECH], }), @@ -309,12 +294,12 @@ export function SpeechMathDocumentMixin< /** * @override */ - public options: SPEECH_OPTIONS>; + public options: SPEECH_OPTIONS; /** * The webworker handler for the document */ - public webworker: WorkerHandler = null; + public webworker: WorkerHandler = null; /** * Enrich the MathItem class used for this MathDocument, and create the @@ -331,10 +316,8 @@ export function SpeechMathDocumentMixin< ProcessBits.allocate('attach-speech'); } this.options.MathItem = SpeechMathItemMixin< - N, - T, - D, - Constructor> + DOM, + Constructor> >(this.options.MathItem); } @@ -361,7 +344,7 @@ export function SpeechMathDocumentMixin< ) { this.getWebworker(); for (const math of this.math) { - (math as SpeechMathItem).attachSpeech(this); + (math as SpeechMathItem).attachSpeech(this); } } this.processed.set('attach-speech'); @@ -373,8 +356,8 @@ export function SpeechMathDocumentMixin< * @override */ public speechError( - _doc: SpeechMathDocument, - _math: SpeechMathItem, + _doc: SpeechMathDocument, + _math: SpeechMathItem, err: string ) { if (err) { @@ -391,7 +374,7 @@ export function SpeechMathDocumentMixin< this.processed.clear('attach-speech'); if (state >= STATE.TYPESET) { for (const math of this.math) { - (math as SpeechMathItem).detachSpeech(this); + (math as SpeechMathItem).detachSpeech(this); } } } @@ -417,17 +400,18 @@ export function SpeechMathDocumentMixin< * @param {MathML} MmlJax The MathML input jax to use for reading the enriched MathML * @returns {Handler} The handler that was modified (for purposes of chainging extensions) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export function SpeechHandler( - handler: Handler, - MmlJax: MathML -): Handler { +export function SpeechHandler( + handler: Handler, + MmlJax: MathML +): Handler { if (!handler.documentClass.prototype.enrich && MmlJax) { handler = EnrichHandler(handler, MmlJax); } - handler.documentClass = SpeechMathDocumentMixin(handler.documentClass as any); + handler.documentClass = SpeechMathDocumentMixin< + DOM, + MathDocumentConstructor, DOM> + >(handler.documentClass as any); return handler; } diff --git a/ts/a11y/speech/GeneratorPool.ts b/ts/a11y/speech/GeneratorPool.ts index 229d6039dd..78d12ca566 100644 --- a/ts/a11y/speech/GeneratorPool.ts +++ b/ts/a11y/speech/GeneratorPool.ts @@ -28,15 +28,14 @@ import { DOMAdaptor } from '../../core/DOMAdaptor.js'; import { SpeechMathItem } from '../speech.js'; import { WorkerHandler } from './WebWorker.js'; import { SEM } from '../semantic-enrich/strings.js'; +import { DOM_TYPES, N } from '../../types/Types.js'; import { localize } from '../speech/__locales__/Component.js'; /** - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class GeneratorPool { - private webworker: WorkerHandler; +export class GeneratorPool { + private webworker: WorkerHandler; private _element: Element; set element(element: Element) { @@ -55,7 +54,7 @@ export class GeneratorPool { /** * The adaptor to work with typeset nodes. */ - public adaptor: DOMAdaptor = null; + public adaptor: DOMAdaptor = null; /** * The current speech setting for Sre @@ -91,8 +90,8 @@ export class GeneratorPool { */ public init( options: OptionList, - adaptor: DOMAdaptor, - webworker: WorkerHandler + adaptor: DOMAdaptor, + webworker: WorkerHandler ) { this.options = options; if (this._init) return; @@ -117,13 +116,13 @@ export class GeneratorPool { * @param {SpeechMathItem} item The SpeechMathItem to add speech to * @returns {Promise} The promise that resolves when the command is complete */ - public Speech(item: SpeechMathItem): Promise { + public Speech(item: SpeechMathItem): Promise { const mml = item.outputData.mml; const options = Object.assign({}, this.options, { modality: 'speech' }); return (this.promise = this.webworker.Speech(mml, options, item)); } - public SpeechFor(item: SpeechMathItem, mml: string): Promise { + public SpeechFor(item: SpeechMathItem, mml: string): Promise { const options = Object.assign({}, this.options, { modality: 'speech' }); return this.webworker.speechFor(mml, options, item); } @@ -133,7 +132,7 @@ export class GeneratorPool { * * @param {SpeechMathItem} item The SpeechMathItem whose task is to be cancelled */ - public cancel(item: SpeechMathItem) { + public cancel(item: SpeechMathItem) { this.webworker?.Cancel(item); } @@ -146,7 +145,7 @@ export class GeneratorPool { * @param {LiveRegion} brailleRegion The braille region. */ public updateRegions( - node: N, + node: N, speechRegion: LiveRegion, brailleRegion: LiveRegion ) { @@ -160,7 +159,7 @@ export class GeneratorPool { * @param {N} node The root node of the expression. * @returns {OptionList} The relevant SRE options. */ - private getOptions(node: N): OptionList { + private getOptions(node: N): OptionList { return { locale: this.adaptor.getAttribute(node, SEM.LOCALE) ?? '', domain: this.adaptor.getAttribute(node, SEM.DOMAIN) ?? '', @@ -175,7 +174,7 @@ export class GeneratorPool { * @param {SpeechMathItem} item The SpeechMathItem whose rule set is changing * @returns {Promise} A promise that resolves when the command completes */ - public nextRules(item: SpeechMathItem): Promise { + public nextRules(item: SpeechMathItem): Promise { const options = this.getOptions(item.typesetRoot); this.update(options); return (this.promise = this.webworker.nextRules( @@ -192,7 +191,7 @@ export class GeneratorPool { * @param {SpeechMathItem} item The SpeechMathItem whose preferences are changing * @returns {Promise} A promise that resolves when the command completes */ - public nextStyle(node: N, item: SpeechMathItem): Promise { + public nextStyle(node: N, item: SpeechMathItem): Promise { const options = this.getOptions(item.typesetRoot); this.update(options); return (this.promise = this.webworker.nextStyle( @@ -211,7 +210,11 @@ export class GeneratorPool { * @param {string=} sep The speech separator. Defaults to space. * @returns {string} The assembled label. */ - public getLabel(node: N, _center: string = '', sep: string = ' '): string { + public getLabel( + node: N, + _center: string = '', + sep: string = ' ' + ): string { const adaptor = this.adaptor; if (!this.webworker.ready) { // return document.querySelector('.mjx-selected').textContent; @@ -234,7 +237,7 @@ export class GeneratorPool { * @param {N} node The typeset node. * @returns {string} The assembled label. */ - public getBraille(node: N): string { + public getBraille(node: N): string { const adaptor = this.adaptor; if (!this.webworker.ready) { // return document.querySelector('.mjx-selected').textContent; @@ -276,7 +279,7 @@ export class GeneratorPool { * @returns {Promise} The promise that resolves when the command is complete */ public getRelevantPreferences( - item: SpeechMathItem, + item: SpeechMathItem, semantic: string, prefs: Map, counter: number diff --git a/ts/a11y/speech/WebWorker.ts b/ts/a11y/speech/WebWorker.ts index 7381a89505..9b8920ecce 100644 --- a/ts/a11y/speech/WebWorker.ts +++ b/ts/a11y/speech/WebWorker.ts @@ -31,14 +31,17 @@ import { SPEECH, BRAILLE } from './strings.js'; import { StyleJsonData } from '../../util/StyleJson.js'; import { Locale } from '../../util/Locale.js'; import { localize, COMPONENT } from './__locales__/Component.js'; +import { DOM_TYPES, N, NT } from '../../types/Types.js'; /** * Class for relevant task information. + * + * @template DOM The DOM node types */ -class Task { +class Task { constructor( public cmd: ClientCommand, - public item: SpeechMathItem, + public item: SpeechMathItem, public resolve: (value: any) => void, public reject: (cmd: string) => void ) {} @@ -47,11 +50,9 @@ class Task { /** * The main WorkerHandler class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class WorkerHandler { +export class WorkerHandler { /** * Callback for ready signal */ @@ -60,7 +61,7 @@ export class WorkerHandler { /** * The task queue */ - private tasks: Task[] = []; + private tasks: Task[] = []; /** * The webworker @@ -87,7 +88,7 @@ export class WorkerHandler { * @param {OptionList} options The worker options. */ constructor( - public adaptor: DOMAdaptor, + public adaptor: DOMAdaptor, private options: OptionList ) {} @@ -142,10 +143,7 @@ export class WorkerHandler { * command name as input. * @returns {Promise} A promise that resolves when the command completes */ - public Post( - msg: ClientCommand, - item?: SpeechMathItem - ): Promise { + public Post(msg: ClientCommand, item?: SpeechMathItem): Promise { const promise = new Promise((resolve, reject) => { this.tasks.push(new Task(msg, item, resolve, reject)); }); @@ -172,7 +170,7 @@ export class WorkerHandler { * * @param {SpeechMathItem} item The item whose task is to be canceled. */ - public Cancel(item: SpeechMathItem) { + public Cancel(item: SpeechMathItem) { const i = this.tasks.findIndex((task) => task.item === item); if (i > 0) { this.tasks[i].reject(localize('Worker/Cancelled', this.tasks[i].cmd.cmd)); @@ -209,7 +207,7 @@ export class WorkerHandler { public async Speech( math: string, options: OptionList, - item: SpeechMathItem + item: SpeechMathItem ): Promise { this.Attach( item, @@ -237,7 +235,7 @@ export class WorkerHandler { public async nextRules( math: string, options: OptionList, - item: SpeechMathItem + item: SpeechMathItem ): Promise { this.Attach( item, @@ -273,7 +271,7 @@ export class WorkerHandler { math: string, options: OptionList, nodeId: string, - item: SpeechMathItem + item: SpeechMathItem ): Promise { this.Attach( item, @@ -304,7 +302,7 @@ export class WorkerHandler { public async speechFor( math: string, options: OptionList, - item: SpeechMathItem + item: SpeechMathItem ): Promise { const data = await this.Post( { @@ -325,7 +323,7 @@ export class WorkerHandler { * @param {string} structure The speech JSON structure to attach */ public Attach( - item: SpeechMathItem, + item: SpeechMathItem, speech: boolean, braille: boolean, structure: string @@ -347,9 +345,9 @@ export class WorkerHandler { if (!node || !adaptor.childNodes(node)[0]) { continue; } - node = adaptor.childNodes(node)[0] as N; + node = adaptor.childNodes(node)[0] as N; if (adaptor.kind(node) === 'rect') { - node = adaptor.next(node) as N; + node = adaptor.next(node) as N; } adaptor.setAttribute(node, SEM.TYPE, 'dummy'); this.setSpecialAttributes(node, sid, ''); @@ -387,7 +385,7 @@ export class WorkerHandler { * @param {boolean} braille True when Braille should be added */ protected setSpeechAttribute( - node: N, + node: N, data: Structure, speech: boolean, braille: boolean @@ -414,7 +412,7 @@ export class WorkerHandler { /** * Add the speech attributes to a node's DOM tree * - * @param {N|T} root The node to add speech to + * @param {NT} root The node to add speech to * @param {string} rootId The root nodes's ID * @param {Structure} data The speech data to use * @param {boolean} speech True when speech should be added @@ -422,7 +420,7 @@ export class WorkerHandler { * @returns {string} The updated root ID */ protected setSpeechAttributes( - root: N | T, + root: NT, rootId: string, data: Structure, speech: boolean, @@ -436,7 +434,7 @@ export class WorkerHandler { ) { return rootId; } - root = root as N; + root = root as N; if (adaptor.hasAttribute(root, SEM.ID)) { this.setSpeechAttribute(root, data, speech, braille); if (!rootId && !adaptor.hasAttribute(root, SEM.PARENT)) { @@ -458,7 +456,7 @@ export class WorkerHandler { * @param {string[]} keys An optional list to select only those attributes. */ protected setSpecialAttributes( - node: N, + node: N, map: OptionList, prefix: string, keys?: string[] @@ -478,7 +476,7 @@ export class WorkerHandler { * * @param {SpeechMathItem} item The MathItem whose speech attributes should be removed. */ - public Detach(item: SpeechMathItem) { + public Detach(item: SpeechMathItem) { const container = item.typesetRoot; this.adaptor.removeAttribute(container, SPEECH.ATTACHED); this.adaptor.removeAttribute(container, BRAILLE.ATTACHED); @@ -490,7 +488,7 @@ export class WorkerHandler { * * @param {N} node The root node of the tree to modify */ - public detachSpeech(node: N) { + public detachSpeech(node: N) { const adaptor = this.adaptor; const children = adaptor.childNodes(node); if (!children) return; @@ -507,7 +505,7 @@ export class WorkerHandler { } } for (const child of children) { - this.detachSpeech(child as N); + this.detachSpeech(child as N); } } @@ -604,7 +602,7 @@ export class WorkerHandler { * The list of valid commands from the Worker. */ public Commands: { - [id: string]: (handler: WorkerHandler, data: Message) => void; + [id: string]: (handler: WorkerHandler, data: Message) => void; } = { /** * This signals that the worker in the iframe is loaded and ready @@ -612,7 +610,7 @@ export class WorkerHandler { * @param {WorkerHandler} handler The active handler for the worker. * @param {Message} _data The data received from the worker. Ignored. */ - Ready(handler: WorkerHandler, _data: Message) { + Ready(handler: WorkerHandler, _data: Message) { handler.ready = true; handler.postNext(); }, @@ -623,7 +621,7 @@ export class WorkerHandler { * @param {WorkerHandler} handler The active handler for the worker. * @param {Message} data The data received from the worker. */ - Finished(handler: WorkerHandler, data: Message) { + Finished(handler: WorkerHandler, data: Message) { const task = handler.tasks.shift(); if (data.success) { task.resolve(data.result); @@ -639,7 +637,7 @@ export class WorkerHandler { * @param {WorkerHandler} handler The active handler for the worker. * @param {Message} data The data received from the worker. */ - Log(handler: WorkerHandler, data: Message) { + Log(handler: WorkerHandler, data: Message) { if (handler.options.debug) { console.log('Log:', data); } @@ -651,7 +649,7 @@ export class WorkerHandler { * @param {WorkerHandler} handler The active handler for the worker. * @param {Message} data The data received from the worker. */ - Failed(handler: WorkerHandler, data: Message) { + Failed(handler: WorkerHandler, data: Message) { const { path, worker } = handler.options; Locale.warn( COMPONENT, @@ -669,7 +667,7 @@ export class WorkerHandler { * @param {WorkerHandler} handler The active handler for the worker. * @param {Message} data The data received from the worker. */ - Maps(handler: WorkerHandler, data: Message) { + Maps(handler: WorkerHandler, data: Message) { const { maps } = handler.options; Locale.warn( COMPONENT, diff --git a/ts/adaptors/HTMLAdaptor.ts b/ts/adaptors/HTMLAdaptor.ts index b637216db8..ca2f992749 100644 --- a/ts/adaptors/HTMLAdaptor.ts +++ b/ts/adaptors/HTMLAdaptor.ts @@ -30,46 +30,47 @@ import { } from '../core/DOMAdaptor.js'; import { Locale } from '../util/Locale.js'; import { COMPONENT } from '../core/__locales__/Component.js'; +import { DOM as DOM_OF, DOM_TYPES, N, T, D } from '../types/Types.js'; + +type NT = N | T; /*****************************************************************/ /** * The minimum fields needed for a Document * - * @template N The HTMLElement node class - * @template T The Text node class + * @template DOM The DOM node types */ -export interface MinDocument { - documentElement: N; - head: N; - body: N; +export interface MinDocument { + documentElement: N; + head: N; + body: N; title: string; doctype: { name: string }; - defaultView: MinWindow>; + defaultView: MinWindow; location: { protocol: string; host: string }; - createElement(kind: string): N; - createElementNS(ns: string, kind: string): N; - createTextNode(text: string): T; - querySelectorAll(selector: string): ArrayLike; - querySelector(selector: string): N | null; + createElement(kind: string): N; + createElementNS(ns: string, kind: string): N; + createTextNode(text: string): T; + querySelectorAll(selector: string): ArrayLike>; + querySelector(selector: string): N | null; } /*****************************************************************/ /** * The minimum fields needed for an HTML Element * - * @template N The HTMLElement node class - * @template T The Text node class + * @template DOM The DOM node types */ -export interface MinHTMLElement { +export interface MinHTMLElement { nodeType: number; nodeName: string; nodeValue: string; textContent: string; innerHTML: string; outerHTML: string; - parentNode: N | Node; - nextSibling: N | T | Node; - previousSibling: N | T | Node; + parentNode: N | Node; + nextSibling: NT | Node; + previousSibling: NT | Node; offsetWidth: number; offsetHeight: number; @@ -81,20 +82,20 @@ export interface MinHTMLElement { insertRule: (rule: string, index?: number) => void; cssRules: Array<{ cssText: string }>; }; - childNodes: (N | T)[] | NodeList; - firstChild: N | T | Node; - lastChild: N | T | Node; - getElementsByTagName(name: string): N[] | HTMLCollectionOf; + childNodes: NT[] | NodeList; + firstChild: NT | Node; + lastChild: NT | Node; + getElementsByTagName(name: string): N[] | HTMLCollectionOf; getElementsByTagNameNS( ns: string, name: string - ): N[] | HTMLCollectionOf; - contains(child: N | T): boolean; - appendChild(child: N | T): N | T | Node; - removeChild(child: N | T): N | T | Node; - replaceChild(nnode: N | T, onode: N | T): N | T | Node; - insertBefore(nchild: N | T, ochild: N | T): void; - cloneNode(deep: boolean): N | Node; + ): N[] | HTMLCollectionOf; + contains(child: NT): boolean; + appendChild(child: NT): NT | Node; + removeChild(child: NT): NT | Node; + replaceChild(nnode: NT, onode: NT): NT | Node; + insertBefore(nchild: NT, ochild: NT): void; + cloneNode(deep: boolean): N | Node; setAttribute(name: string, value: string): void; setAttributeNS(ns: string, name: string, value: string): void; getAttribute(name: string): string; @@ -102,7 +103,7 @@ export interface MinHTMLElement { hasAttribute(name: string): boolean; getBoundingClientRect(): object; getBBox?(): { x: number; y: number; width: number; height: number }; - querySelector(selector: string): N | null; + querySelector(selector: string): N | null; src?: string; } @@ -110,60 +111,58 @@ export interface MinHTMLElement { /** * The minimum fields needed for a Text element * - * @template N The HTMLElement node class - * @template T The Text node class + * @template DOM The DOM node types */ -export interface MinText { +export interface MinText { nodeType: number; nodeName: string; nodeValue: string; - parentNode: N | Node; - nextSibling: N | T | Node; - previousSibling: N | T | Node; - splitText(n: number): T; + parentNode: N | Node; + nextSibling: NT | Node; + previousSibling: NT | Node; + splitText(n: number): T; } /*****************************************************************/ /** * The minimum fields needed for a DOMParser * - * @template D The Document class + * @template DOM The DOM node types */ -export interface MinDOMParser { - parseFromString(text: string, format?: string): D; +export interface MinDOMParser { + parseFromString(text: string, format?: string): D; } /*****************************************************************/ /** * The minimum fields needed for a DOMParser * - * @template N The HTMLElement node class + * @template DOM The DOM node types */ -export interface MinXMLSerializer { - serializeToString(node: N): string; +export interface MinXMLSerializer { + serializeToString(node: N): string; } /*****************************************************************/ /** * The minimum fields needed for a Window * - * @template N The HTMLElement node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface MinWindow { - document: D; +export interface MinWindow { + document: D; DOMParser: { - new (): MinDOMParser; + new (): MinDOMParser; }; XMLSerializer: { - new (): MinXMLSerializer; + new (): MinXMLSerializer; }; NodeList: any; HTMLCollection: any; HTMLElement: any; DocumentFragment: any; Document: any; - getComputedStyle(node: N): any; + getComputedStyle(node: N): any; addEventListener(kind: string, listener: (event: any) => void): void; postMessage(msg: any, domain: string): void; } @@ -172,12 +171,10 @@ export interface MinWindow { /** * The minimum needed for an HTML Adaptor * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface MinHTMLAdaptor extends DOMAdaptor { - window: MinWindow; +export interface MinHTMLAdaptor extends DOMAdaptor { + window: MinWindow; } /*****************************************************************/ @@ -185,21 +182,13 @@ export interface MinHTMLAdaptor extends DOMAdaptor { * Abstract HTMLAdaptor class for manipulating HTML elements * (subclass of AbstractDOMAdaptor) * - * N = HTMLElement node class - * T = Text node class - * D = Document class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM types */ export class HTMLAdaptor< - N extends MinHTMLElement, - T extends MinText, - D extends MinDocument, + DOM extends DOM_OF, MinText, MinDocument>, > - extends AbstractDOMAdaptor - implements MinHTMLAdaptor + extends AbstractDOMAdaptor + implements MinHTMLAdaptor { /** * The font size to use when it can't be measured (e.g., the element @@ -215,18 +204,18 @@ export class HTMLAdaptor< /** * The window object for this adaptor */ - public window: MinWindow; + public window: MinWindow; /** * The DOMParser used to parse a string into a DOM tree */ - public parser: MinDOMParser; + public parser: MinDOMParser; /** * @override * @class */ - constructor(window: MinWindow) { + constructor(window: MinWindow) { super(window.document); this.window = window; this.parser = new (window.DOMParser as any)(); @@ -258,58 +247,58 @@ export class HTMLAdaptor< /** * @override */ - public head(doc: D = this.document) { - return doc.head || (doc as any as N); + public head(doc: D = this.document) { + return doc.head || (doc as any as N); } /** * @override */ - public body(doc: D = this.document) { - return doc.body || (doc as any as N); + public body(doc: D = this.document) { + return doc.body || (doc as any as N); } /** * @override */ - public root(doc: D = this.document) { - return doc.documentElement || (doc as any as N); + public root(doc: D = this.document) { + return doc.documentElement || (doc as any as N); } /** * @override */ - public doctype(doc: D = this.document) { + public doctype(doc: D = this.document) { return doc.doctype ? `` : ''; } /** * @override */ - public tags(node: N, name: string, ns: string = null) { + public tags(node: N, name: string, ns: string = null) { const nodes = ns ? node.getElementsByTagNameNS(ns, name) : node.getElementsByTagName(name); - return Array.from(nodes as N[]) as N[]; + return Array.from(nodes as N[]) as N[]; } /** * @override */ - public getElements(nodes: (string | N | N[])[], _document: D) { - let containers: N[] = []; + public getElements(nodes: (string | N | N[])[], _document: D) { + let containers: N[] = []; for (const node of nodes) { if (typeof node === 'string') { containers = containers.concat( Array.from(this.document.querySelectorAll(node)) ); } else if (Array.isArray(node)) { - containers = containers.concat(Array.from(node) as N[]); + containers = containers.concat(Array.from(node) as N[]); } else if ( node instanceof this.window.NodeList || node instanceof this.window.HTMLCollection ) { - containers = containers.concat(Array.from(node as any as N[])); + containers = containers.concat(Array.from(node as any as N[])); } else { containers.push(node); } @@ -320,112 +309,115 @@ export class HTMLAdaptor< /** * @override */ - public getElement(selector: string, node: D | N = this.document): N { + public getElement( + selector: string, + node: D | N = this.document + ): N { return node.querySelector(selector); } /** * @override */ - public contains(container: N, node: N | T) { + public contains(container: N, node: NT) { return container.contains(node); } /** * @override */ - public parent(node: N | T) { - return node.parentNode as N; + public parent(node: NT) { + return node.parentNode as N; } /** * @override */ - public append(node: N, child: N | T) { - return node.appendChild(child) as N | T; + public append(node: N, child: NT) { + return node.appendChild(child) as NT; } /** * @override */ - public insert(nchild: N | T, ochild: N | T) { + public insert(nchild: NT, ochild: NT) { return this.parent(ochild).insertBefore(nchild, ochild); } /** * @override */ - public remove(child: N | T) { - return this.parent(child).removeChild(child) as N | T; + public remove(child: NT) { + return this.parent(child).removeChild(child) as NT; } /** * @override */ - public replace(nnode: N | T, onode: N | T) { - return this.parent(onode).replaceChild(nnode, onode) as N | T; + public replace(nnode: NT, onode: NT) { + return this.parent(onode).replaceChild(nnode, onode) as NT; } /** * @override */ - public clone(node: N, deep: boolean = true) { - return node.cloneNode(deep) as N; + public clone(node: N, deep: boolean = true) { + return node.cloneNode(deep) as N; } /** * @override */ - public split(node: T, n: number) { + public split(node: T, n: number) { return node.splitText(n); } /** * @override */ - public next(node: N | T) { - return node.nextSibling as N | T; + public next(node: NT) { + return node.nextSibling as NT; } /** * @override */ - public previous(node: N | T) { - return node.previousSibling as N | T; + public previous(node: NT) { + return node.previousSibling as NT; } /** * @override */ - public firstChild(node: N) { - return node.firstChild as N | T; + public firstChild(node: N) { + return node.firstChild as NT; } /** * @override */ - public lastChild(node: N) { - return node.lastChild as N | T; + public lastChild(node: N) { + return node.lastChild as NT; } /** * @override */ - public childNodes(node: N) { - return Array.from(node.childNodes as (N | T)[]); + public childNodes(node: N) { + return Array.from(node.childNodes as NT[]); } /** * @override */ - public childNode(node: N, i: number) { - return node.childNodes[i] as N | T; + public childNode(node: N, i: number) { + return node.childNodes[i] as NT; } /** * @override */ - public kind(node: N | T) { + public kind(node: NT) { const n = node.nodeType; return n === 1 || n === 3 || n === 8 ? node.nodeName.toLowerCase() : ''; } @@ -433,35 +425,35 @@ export class HTMLAdaptor< /** * @override */ - public value(node: N | T) { + public value(node: NT) { return node.nodeValue || ''; } /** * @override */ - public textContent(node: N) { + public textContent(node: N) { return node.textContent; } /** * @override */ - public innerHTML(node: N) { + public innerHTML(node: N) { return node.innerHTML; } /** * @override */ - public outerHTML(node: N) { + public outerHTML(node: N) { return node.outerHTML; } /** * @override */ - public serializeXML(node: N) { + public serializeXML(node: N) { const serializer = new this.window.XMLSerializer(); return serializer.serializeToString(node) as string; } @@ -469,7 +461,12 @@ export class HTMLAdaptor< /** * @override */ - public setAttribute(node: N, name: string, value: string, ns: string = null) { + public setAttribute( + node: N, + name: string, + value: string, + ns: string = null + ) { if (!ns) { if (name === 'style') { value = value.replace(/\n/g, ' '); @@ -483,28 +480,28 @@ export class HTMLAdaptor< /** * @override */ - public getAttribute(node: N, name: string) { + public getAttribute(node: N, name: string) { return node.getAttribute(name); } /** * @override */ - public removeAttribute(node: N, name: string) { + public removeAttribute(node: N, name: string) { return node.removeAttribute(name); } /** * @override */ - public hasAttribute(node: N, name: string) { + public hasAttribute(node: N, name: string) { return node.hasAttribute(name); } /** * @override */ - public allAttributes(node: N) { + public allAttributes(node: N) { return Array.from(node.attributes).map((x: AttributeData) => { return { name: x.name, value: x.value } as AttributeData; }); @@ -513,7 +510,7 @@ export class HTMLAdaptor< /** * @override */ - public addClass(node: N, name: string) { + public addClass(node: N, name: string) { if (node.classList) { node.classList.add(name); } else { @@ -524,7 +521,7 @@ export class HTMLAdaptor< /** * @override */ - public removeClass(node: N, name: string) { + public removeClass(node: N, name: string) { if (node.classList) { node.classList.remove(name); } else { @@ -538,7 +535,7 @@ export class HTMLAdaptor< /** * @override */ - public hasClass(node: N, name: string) { + public hasClass(node: N, name: string) { if (node.classList) { return node.classList.contains(name); } @@ -548,28 +545,28 @@ export class HTMLAdaptor< /** * @override */ - public setStyle(node: N, name: string, value: string) { + public setStyle(node: N, name: string, value: string) { node.style[name] = String(value).replace(/\n/g, ' '); } /** * @override */ - public getStyle(node: N, name: string) { + public getStyle(node: N, name: string) { return node.style[name]; } /** * @override */ - public allStyles(node: N) { + public allStyles(node: N) { return node.style.cssText; } /** * @override */ - public insertRules(node: N, rules: string[]) { + public insertRules(node: N, rules: string[]) { for (const rule of rules) { try { node.sheet.insertRule(rule, node.sheet.cssRules.length); @@ -582,7 +579,7 @@ export class HTMLAdaptor< /** * @override */ - public cssText(node: N) { + public cssText(node: N) { if (this.kind(node) !== 'style') { return ''; } @@ -594,7 +591,7 @@ export class HTMLAdaptor< /** * @override */ - public fontSize(node: N) { + public fontSize(node: N) { const style = this.window.getComputedStyle(node); return parseFloat( style.fontSize || @@ -605,7 +602,7 @@ export class HTMLAdaptor< /** * @override */ - public fontFamily(node: N) { + public fontFamily(node: N) { const style = this.window.getComputedStyle(node); return style.fontFamily || ''; } @@ -613,7 +610,7 @@ export class HTMLAdaptor< /** * @override */ - public nodeSize(node: N, em: number = 1, local: boolean = false) { + public nodeSize(node: N, em: number = 1, local: boolean = false) { if (local && node.getBBox) { const { width, height } = node.getBBox(); return [width / em, height / em] as [number, number]; @@ -624,7 +621,7 @@ export class HTMLAdaptor< /** * @override */ - public nodeBBox(node: N) { + public nodeBBox(node: N) { const { left, right, top, bottom } = node.getBoundingClientRect() as PageBBox; return { left, right, top, bottom }; diff --git a/ts/adaptors/NodeMixin.ts b/ts/adaptors/NodeMixin.ts index dae300bda9..05e8c0f78c 100644 --- a/ts/adaptors/NodeMixin.ts +++ b/ts/adaptors/NodeMixin.ts @@ -26,7 +26,7 @@ import { DOMAdaptor, minWorker } from '../core/DOMAdaptor.js'; import { userOptions, defaultOptions, OptionList } from '../util/Options.js'; import { asyncLoad } from '../util/AsyncLoad.js'; -import { Constructor } from '../types/Types.js'; +import { Constructor, DOM_TYPES, N } from '../types/Types.js'; export { Constructor }; /** @@ -40,8 +40,12 @@ export interface WebWorker { /** * The type of an Adaptor class + * + * @template DOM The DOM node types */ -export type AdaptorConstructor = Constructor>; +export type AdaptorConstructor = Constructor< + DOMAdaptor +>; export type MIXIN_OPTIONS = { badCSS?: boolean; // getComputedStyles() is not implemented in the DOM @@ -72,15 +76,13 @@ export type OPTIONS = { * @param {NodeMixinOptions} options The options * @returns {A} The NodeAdaptor mixin class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template A Extension of AdaptorConstructor + * @template DOM The DOM node types + * @template A Extension of AdaptorConstructor */ -export function NodeMixin>( - Base: A, - options: MIXIN_OPTIONS = {} -): A { +export function NodeMixin< + DOM extends DOM_TYPES, + A extends AdaptorConstructor, +>(Base: A, options: MIXIN_OPTIONS = {}): A { options = userOptions(defaultOptions({}, NodeMixinOptions), options); return class NodeAdaptor extends Base { @@ -155,7 +157,7 @@ export function NodeMixin>( * * @override */ - public fontSize(node: N) { + public fontSize(node: N) { return options.badCSS ? this.options.fontSize : super.fontSize(node); } @@ -164,14 +166,14 @@ export function NodeMixin>( * * @override */ - public fontFamily(node: N) { + public fontFamily(node: N) { return options.badCSS ? this.options.fontFamily : super.fontFamily(node); } /** * @override */ - public nodeSize(node: N, em: number = 1, local: boolean = null) { + public nodeSize(node: N, em: number = 1, local: boolean = null) { if (!options.badSizes) { return super.nodeSize(node, em, local); } @@ -187,7 +189,7 @@ export function NodeMixin>( /** * @override */ - public nodeBBox(node: N) { + public nodeBBox(node: N) { return options.badSizes ? { left: 0, right: 0, top: 0, bottom: 0 } : super.nodeBBox(node); diff --git a/ts/adaptors/browserAdaptor.ts b/ts/adaptors/browserAdaptor.ts index 6aa2a21fa0..fe89812f9d 100644 --- a/ts/adaptors/browserAdaptor.ts +++ b/ts/adaptors/browserAdaptor.ts @@ -22,6 +22,7 @@ */ import { HTMLAdaptor } from './HTMLAdaptor.js'; +import { HTML_DOM } from '../types/dom/html.js'; // // Let Typescript know about these @@ -43,6 +44,6 @@ declare global { * * @returns {HTMLAdaptor} The newly created adaptor */ -export function browserAdaptor(): HTMLAdaptor { - return new HTMLAdaptor(window); +export function browserAdaptor(): HTMLAdaptor { + return new HTMLAdaptor(window); } diff --git a/ts/adaptors/jsdomAdaptor.ts b/ts/adaptors/jsdomAdaptor.ts index b04525e424..20ab53be42 100644 --- a/ts/adaptors/jsdomAdaptor.ts +++ b/ts/adaptors/jsdomAdaptor.ts @@ -23,23 +23,19 @@ import { HTMLAdaptor } from './HTMLAdaptor.js'; import { NodeMixin, MIXIN_OPTIONS, Constructor } from './NodeMixin.js'; +import { HTML_DOM } from '../types/dom/html.js'; /** * The constructor for an HTMLAdaptor */ -export type HTMLAdaptorConstructor = Constructor< - HTMLAdaptor ->; +export type HTMLAdaptorConstructor = Constructor>; /** * The JsdomAdaptor class */ -export class JsdomAdaptor extends NodeMixin< - HTMLElement, - Text, - Document, - HTMLAdaptorConstructor ->(HTMLAdaptor) {} +export class JsdomAdaptor extends NodeMixin( + HTMLAdaptor +) {} /** * Function for creating an HTML adaptor using jsdom diff --git a/ts/adaptors/linkedomAdaptor.ts b/ts/adaptors/linkedomAdaptor.ts index 75f8fda31c..41d65aad61 100644 --- a/ts/adaptors/linkedomAdaptor.ts +++ b/ts/adaptors/linkedomAdaptor.ts @@ -25,21 +25,18 @@ import { HTMLAdaptor } from './HTMLAdaptor.js'; import { NodeMixin, MIXIN_OPTIONS, Constructor } from './NodeMixin.js'; import { Locale } from '../util/Locale.js'; import { COMPONENT } from './linkedom/__locales__/Component.js'; +import { HTML_DOM } from '../types/dom/html.js'; /** * The constructor for an HTMLAdaptor */ -export type HTMLAdaptorConstructor = Constructor< - HTMLAdaptor ->; +export type HTMLAdaptorConstructor = Constructor>; /** * The LinkedomAdaptor class */ export class LinkedomAdaptor extends NodeMixin< - HTMLElement, - Text, - Document, + HTML_DOM, HTMLAdaptorConstructor >(HTMLAdaptor) { /** diff --git a/ts/adaptors/lite/Parser.ts b/ts/adaptors/lite/Parser.ts index 18a326487f..35b2ec8551 100644 --- a/ts/adaptors/lite/Parser.ts +++ b/ts/adaptors/lite/Parser.ts @@ -28,6 +28,7 @@ import { LiteDocument } from './Document.js'; import { LiteElement } from './Element.js'; import { LiteText, LiteComment } from './Text.js'; import { LiteAdaptor } from '../liteAdaptor.js'; +import { LITE_DOM } from '../../types/dom/lite.js'; /** * Patterns used in parsing serialized HTML @@ -56,7 +57,7 @@ export const PATTERNS = { * Implements a lightweight DOMParser replacement * (Not perfect, but handles most well-formed HTML) */ -export class LiteParser implements MinDOMParser { +export class LiteParser implements MinDOMParser { /** * The list of self-closing tags */ diff --git a/ts/adaptors/liteAdaptor.ts b/ts/adaptors/liteAdaptor.ts index 46cf5dc325..1e86e20338 100644 --- a/ts/adaptors/liteAdaptor.ts +++ b/ts/adaptors/liteAdaptor.ts @@ -31,17 +31,14 @@ import { LiteWindow } from './lite/Window.js'; import { LiteParser } from './lite/Parser.js'; import { Styles } from '../util/Styles.js'; import { OptionList } from '../util/Options.js'; +import { LITE_DOM } from '../types/dom/lite.js'; /************************************************************/ /** * Implements a lightweight DOMAdaptor on liteweight HTML elements */ -export class LiteBase extends AbstractDOMAdaptor< - LiteElement, - LiteText, - LiteDocument -> { +export class LiteBase extends AbstractDOMAdaptor { /** * The document in which the HTML nodes will be created */ @@ -711,12 +708,9 @@ export class LiteBase extends AbstractDOMAdaptor< /** * The LiteAdaptor class (add in the NodeMixin methods and options) */ -export class LiteAdaptor extends NodeMixin< - LiteElement, - LiteText, - LiteDocument, - Constructor ->(LiteBase) {} +export class LiteAdaptor extends NodeMixin>( + LiteBase +) {} /************************************************************/ /** diff --git a/ts/components/package.ts b/ts/components/package.ts index 0948fe599c..5241853b95 100644 --- a/ts/components/package.ts +++ b/ts/components/package.ts @@ -55,14 +55,13 @@ export type PackagePromise = ( /** * The configuration data for a package */ -/* prettier-ignore */ export interface PackageConfig { - ready?: PackageReady; // Function to call when package is loaded successfully - failed?: PackageFailed; // Function to call when package fails to load - checkReady?: () => Promise; // Function called to see if package is fully loaded - // (may cause additional packages to load, for example) - extraLoads?: string[]; // Extra packages to load after this one - rendererExtensions?: string[]; // Font extensions to load when renderer changes + ready?: PackageReady; // Function to call when package is loaded successfully + failed?: PackageFailed; // Function to call when package fails to load + checkReady?: () => Promise; // Function called to see if package is fully loaded + // (May cause additional packages to load, for example) + extraLoads?: string[]; // Extra packages to load after this one + rendererExtensions?: string[]; // Font extensions to load when renderer changes } /** diff --git a/ts/components/startup.ts b/ts/components/startup.ts index bc9f6cae22..236c131500 100644 --- a/ts/components/startup.ts +++ b/ts/components/startup.ts @@ -46,9 +46,7 @@ import { OptionList, OPTIONS } from '../util/Options.js'; import { context } from '../util/context.js'; import { Locale } from '../util/Locale.js'; import { COMPONENT } from '../core/__locales__/Component.js'; -import { DOM, DOM_TYPES, N, T, D, OPTIONAL } from '../types/Types.js'; - -import { TeX } from '../input/tex.js'; +import { DOM as ANY_DOM, DOM_TYPES, N, OPTIONAL } from '../types/Types.js'; /** * The option types for the startup component. @@ -72,48 +70,31 @@ export type STARTUP_OPTIONS = { /** * Generic types for the standard MathJax objects */ -export type MATHDOCUMENT
= MathDocument< - N
, - T
, - D
-> & { - menu?: { loadingPromise: Promise }; - options: { elements?: N
[] }; -}; -export type HANDLER
= Handler, T
, D
>; -export type DOMADAPTOR
= DOMAdaptor< - N
, - T
, - D
->; -export type INPUTJAX
= InputJax< - N
, - T
, - D
->; -export type OUTPUTJAX
= OutputJax< - N
, - T
, - D
->; +export type MATHDOCUMENT = + MathDocument & { + menu?: { loadingPromise: Promise }; + options: { elements?: N[] }; + }; +export type HANDLER = Handler; +export type DOMADAPTOR = DOMAdaptor; +export type INPUTJAX = InputJax; +export type OUTPUTJAX = OutputJax; /* prettier-ignore */ -export type COMMONJAX
= - CommonOutputJax, T
, D
, any, any, any, any, any, any, any, any>; -export type TEX
= TeX, T
, D
>; +export type COMMONJAX = CommonOutputJax; /** * Array of InputJax also with keys using name of jax */ -export type JAXARRAY
= INPUTJAX
[] & { - [name: string]: INPUTJAX
; +export type JAXARRAY = INPUTJAX[] & { + [name: string]: INPUTJAX; }; /** * A function to extend a handler class */ -export type HandlerExtension
= ( - handler: HANDLER
-) => HANDLER
; +export type HandlerExtension = ( + handler: HANDLER +) => HANDLER; /** * The startup object types. @@ -602,7 +583,7 @@ export abstract class Startup { * @param {any=} root The Document to use as the root document (or null to use the configured document) * @returns {MathDocument} The MathDocument with the configured input and output jax */ - public static getDocument(root: any = null): MathDocument { + public static getDocument(root: any = null): MathDocument { return Startup.mathjax.document(root || CONFIG.document, { ...MathJax.config.options, InputJax: Startup.input, @@ -655,7 +636,7 @@ export interface MathJaxConfig extends MJConfig { */ export interface MathJaxObject extends MJObject { config: MathJaxConfig; - startup: STARTUP; + startup: STARTUP; [name: string]: any; // Needed for the methods created by the startup module } diff --git a/ts/core/DOMAdaptor.ts b/ts/core/DOMAdaptor.ts index ea90a537e2..c6448ec1c6 100644 --- a/ts/core/DOMAdaptor.ts +++ b/ts/core/DOMAdaptor.ts @@ -22,6 +22,9 @@ */ import { OptionList } from '../util/Options.js'; +import { DOM_TYPES, N, T, D } from '../types/Types.js'; + +type NT = N | T; /** * The data for an attribute @@ -41,6 +44,11 @@ export type PageBBox = { bottom: number; }; +/** + * Specifier for a (set of) containers + */ +export type ContainerSpec = string | N | N[]; + /** * A minimal webworker interface */ @@ -54,15 +62,13 @@ export interface minWorker { /** * The interface for the DOMAdaptor * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface DOMAdaptor { +export interface DOMAdaptor { /** * Document in which the nodes are to be created */ - document: D; + document: D; /** * True when the adaptor can measure DOM node sizes @@ -72,66 +78,71 @@ export interface DOMAdaptor { /** * @param {string} text The serialized document to be parsed * @param {string} format The format (e.g., 'text/html' or 'text/xhtml') - * @returns {D} The parsed document + * @returns {D} The parsed document */ - parse(text: string, format?: string): D; + parse(text: string, format?: string): D; /** * @param {string} kind The tag name of the HTML node to be created * @param {OptionList} def The properties to set for the created node * @param {(N|T)[]} children The child nodes for the created HTML node * @param {string} ns The namespace in which to create the node - * @returns {N} The generated HTML tree + * @returns {N} The generated HTML tree */ - node(kind: string, def?: OptionList, children?: (N | T)[], ns?: string): N; + node( + kind: string, + def?: OptionList, + children?: NT[], + ns?: string + ): N; /** * @param {string} text The text from which to create an HTML text node - * @returns {T} The generated text node with the given text + * @returns {T} The generated text node with the given text */ - text(text: string): T; + text(text: string): T; /** * @param {D} doc The document whose head is to be obtained - * @returns {N} The document.head element + * @returns {N} The document.head element */ - head(doc?: D): N; + head(doc?: D): N; /** * @param {D} doc The document whose body is to be obtained - * @returns {N} The document.body element + * @returns {N} The document.body element */ - body(doc?: D): N; + body(doc?: D): N; /** * @param {D} doc The document whose documentElement is to be obtained - * @returns {N} The documentElement + * @returns {N} The documentElement */ - root(doc?: D): N; + root(doc?: D): N; /** - * @param {D} doc The document whose doctype is to be obtained + * @param {D} doc The document whose doctype is to be obtained * @returns {string} The DOCTYPE comment */ - doctype(doc?: D): string; + doctype(doc?: D): string; /** * @param {N} node The node to search for tags * @param {string} name The name of the tag to search for * @param {string} ns The namespace to search in (or null for no namespace) - * @returns {N[]} The list of tags found + * @returns {N[]} The list of tags found */ - tags(node: N, name: string, ns?: string): N[]; + tags(node: N, name: string, ns?: string): N[]; /** * Get a list of containers (to be searched for math). These can be * specified by CSS selector, or as actual DOM elements or arrays of such. * - * @param {(string | N | N[])[]} nodes The array of items to make into a container list - * @param {D} document The document in which to search - * @returns {N[]} The array of containers to search + * @param {ContainerSpec[]} nodes The array of items to make into a container list + * @param {D} document The document in which to search + * @returns {N[]} The array of containers to search */ - getElements(nodes: (string | N | N[])[], document: D): N[]; + getElements(nodes: ContainerSpec[], document: D): N[]; /** * Get an element specified by CSS selector. @@ -140,148 +151,148 @@ export interface DOMAdaptor { * @param {D | N} node The document or element in which to search * @returns {N | null} The first matching element */ - getElement(selector: string, node?: D | N): N | null; + getElement(selector: string, node?: D | N): N | null; /** * Determine if a container node contains a given node somewhere in its DOM tree * - * @param {N} container The container to search - * @param {N|T} node The node to look for + * @param {N} container The container to search + * @param {N|T} node The node to look for * @returns {boolean} True if the node is in the container's DOM tree */ - contains(container: N, node: N | T): boolean; + contains(container: N, node: NT): boolean; /** - * @param {N|T} node The HTML node whose parent is to be obtained + * @param {N|T} node The HTML node whose parent is to be obtained * @returns {N} The parent node of the given one */ - parent(node: N | T): N; + parent(node: NT): N; /** - * @param {N} node The HTML node to be appended to - * @param {N|T} child The node or text to be appended + * @param {N} node The HTML node to be appended to + * @param {N|T} child The node or text to be appended * @returns {N|T} The appended node */ - append(node: N, child: N | T): N | T; + append(node: N, child: NT): NT; /** * @param {N|T} nchild The node or text to be inserted * @param {N|T} ochild The node or text where the new child is to be added before it */ - insert(nchild: N | T, ochild: N | T): void; + insert(nchild: NT, ochild: NT): void; /** - * @param {N|T} child The node or text to be removed from its parent + * @param {N|T} child The node or text to be removed from its parent * @returns {N|T} The removed node */ - remove(child: N | T): N | T; + remove(child: NT): NT; /** - * @param {N|T} nnode The node to replace with - * @param {N|T} onode The child to be replaced + * @param {N|T} nnode The node to replace with + * @param {N|T} onode The child to be replaced * @returns {N|T} The removed node */ - replace(nnode: N | T, onode: N | T): N | T; + replace(nnode: NT, onode: NT): NT; /** * @param {N} node The HTML node to be cloned * @param {boolean} deep True if children should be cloned - * @returns {N} The copied node + * @returns {N} The copied node */ - clone(node: N, deep?: boolean): N; + clone(node: N, deep?: boolean): N; /** * @param {T} node The HTML text node to be split * @param {number} n The index of the character where the split will occur */ - split(node: T, n: number): T; + split(node: T, n: number): T; /** * @param {N|T} node The HTML node whose sibling is to be obtained - * @returns {N|T} The node following the given one (or null) + * @returns {N|T} The node following the given one (or null) */ - next(node: N | T): N | T; + next(node: NT): NT; /** * @param {N|T} node The HTML node whose sibling is to be obtained - * @returns {N|T} The node preceding the given one (or null) + * @returns {N|T} The node preceding the given one (or null) */ - previous(node: N | T): N | T; + previous(node: NT): NT; /** * @param {N} node The HTML node whose child is to be obtained - * @returns {N|T} The first child of the given node (or null) + * @returns {N|T} The first child of the given node (or null) */ - firstChild(node: N): N | T; + firstChild(node: N): NT; /** * @param {N} node The HTML node whose child is to be obtained - * @returns {N} The last child of the given node (or null) + * @returns {N} The last child of the given node (or null) */ - lastChild(node: N): N | T; + lastChild(node: N): NT; /** - * @param {N} node The HTML node whose children are to be obtained - * @returns {(N|T)[]} Array of children for the given node (not a live list) + * @param {N} node The HTML node whose children are to be obtained + * @returns {(N|T)[]} Array of children for the given node (not a live list) */ - childNodes(node: N): (N | T)[]; + childNodes(node: N): NT[]; /** - * @param {N} node The HTML node whose child is to be obtained - * @param {number} i The index of the child to return + * @param {N} node The HTML node whose child is to be obtained + * @param {number} i The index of the child to return * @returns {N|T} The i-th child node of the given node (or null) */ - childNode(node: N, i: number): N | T; + childNode(node: N, i: number): NT; /** - * @param {N | T} node The HTML node whose tag or node name is to be obtained - * @returns {string} The tag or node name of the given node + * @param {N|T} node The HTML node whose tag or node name is to be obtained + * @returns {string} The tag or node name of the given node */ - kind(node: N | T): string; + kind(node: NT): string; /** - * @param {N|T} node The HTML node whose value is to be obtained + * @param {N|T} node The HTML node whose value is to be obtained * @returns {string} The value of the given node */ - value(node: N | T): string; + value(node: NT): string; /** - * @param {N} node The HTML node whose text content is to be obtained + * @param {N} node The HTML node whose text content is to be obtained * @returns {string} The text content of the given node */ - textContent(node: N): string; + textContent(node: N): string; /** - * @param {N} node The HTML node whose inner HTML string is to be obtained + * @param {N} node The HTML node whose inner HTML string is to be obtained * @returns {string} The serialized content of the node */ - innerHTML(node: N): string; + innerHTML(node: N): string; /** - * @param {N} node The HTML node whose outer HTML string is to be obtained + * @param {N} node The HTML node whose outer HTML string is to be obtained * @returns {string} The serialized node and its content */ - outerHTML(node: N): string; + outerHTML(node: N): string; /** - * @param {N} node The HTML node whose serialized string is to be obtained + * @param {N} node The HTML node whose serialized string is to be obtained * @returns {string} The serialized node and its content */ - serializeXML(node: N): string; + serializeXML(node: N): string; /** * @param {N} node The HTML node whose property is to be set * @param {string} name The property to set * @param {any} value The property's new value */ - setProperty(node: N, name: string, value: any): void; + setProperty(node: N, name: string, value: any): void; /** * @param {N} node The HTML node whose property is to be retrieved * @param {string} name The property to get * @returns {any} The property's value */ - getProperty(node: N, name: string): any; + getProperty(node: N, name: string): any; /** * @param {N} node The HTML node whose attribute is to be set @@ -290,7 +301,7 @@ export interface DOMAdaptor { * @param {string=} ns The namespace to use for the attribute */ setAttribute( - node: N, + node: N, name: string, value: string | number, ns?: string @@ -300,116 +311,116 @@ export interface DOMAdaptor { * @param {N} node The HTML element whose attributes are to be set * @param {OptionList} def The attributes to set on that node */ - setAttributes(node: N, def: OptionList): void; + setAttributes(node: N, def: OptionList): void; /** * @param {N} node The HTML node whose attribute is to be obtained * @param {string} name The name of the attribute to get - * @returns {string} The value of the given attribute of the given node + * @returns {string} The value of the given attribute of the given node */ - getAttribute(node: N, name: string): string; + getAttribute(node: N, name: string): string; /** * @param {N} node The HTML node whose attribute is to be removed * @param {string} name The name of the attribute to remove */ - removeAttribute(node: N, name: string): void; + removeAttribute(node: N, name: string): void; /** * @param {N} node The HTML node whose attribute is to be tested * @param {string} name The name of the attribute to test - * @returns {boolean} True of the node has the given attribute defined + * @returns {boolean} True of the node has the given attribute defined */ - hasAttribute(node: N, name: string): boolean; + hasAttribute(node: N, name: string): boolean; /** - * @param {N} node The HTML node whose attributes are to be returned - * @returns {AttributeData[]} The list of attributes + * @param {N} node The HTML node whose attributes are to be returned + * @returns {AttributeData[]} The list of attributes */ - allAttributes(node: N): AttributeData[]; + allAttributes(node: N): AttributeData[]; /** * @param {N} node The HTML node whose class is to be augmented * @param {string} name The class to be added */ - addClass(node: N, name: string): void; + addClass(node: N, name: string): void; /** * @param {N} node The HTML node whose class is to be changed * @param {string} name The class to be removed */ - removeClass(node: N, name: string): void; + removeClass(node: N, name: string): void; /** * @param {N} node The HTML node whose class is to be tested * @param {string} name The class to test - * @returns {boolean} True if the node has the given class + * @returns {boolean} True if the node has the given class */ - hasClass(node: N, name: string): boolean; + hasClass(node: N, name: string): boolean; /** - * @param {N} node The HTML node whose class list is needed - * @returns {string[]} An array of the class names for this node + * @param {N} node The HTML node whose class list is needed + * @returns {string[]} An array of the class names for this node */ - allClasses(node: N): string[]; + allClasses(node: N): string[]; /** * @param {N} node The HTML node whose style is to be changed * @param {string} name The style to be set * @param {string} value The new value of the style */ - setStyle(node: N, name: string, value: string): void; + setStyle(node: N, name: string, value: string): void; /** * @param {N} node The HTML node whose style is to be obtained * @param {string} name The style to be obtained - * @returns {string} The value of the style + * @returns {string} The value of the style */ - getStyle(node: N, name: string): string; + getStyle(node: N, name: string): string; /** - * @param {N} node The HTML node whose styles are to be returned - * @returns {string} The cssText for the styles + * @param {N} node The HTML node whose styles are to be returned + * @returns {string} The cssText for the styles */ - allStyles(node: N): string; + allStyles(node: N): string; /** * @param {N} node The stylesheet node where the rule will be added * @param {string[]} rules The rule to add at the beginning of the stylesheet */ - insertRules(node: N, rules: string[]): void; + insertRules(node: N, rules: string[]): void; /** - * @param {N} node The stylesheet node whose rules are to be returned - * @returns {string} The string version of the stylesheet rules + * @param {N} node The stylesheet node whose rules are to be returned + * @returns {string} The string version of the stylesheet rules */ - cssText(node: N): string; + cssText(node: N): string; /** - * @param {N} node The HTML node whose font size is to be determined - * @returns {number} The font size (in pixels) of the node + * @param {N} node The HTML node whose font size is to be determined + * @returns {number} The font size (in pixels) of the node */ - fontSize(node: N): number; + fontSize(node: N): number; /** - * @param {N} node The HTML node whose font family is to be determined - * @returns {string} The font family + * @param {N} node The HTML node whose font family is to be determined + * @returns {string} The font family */ - fontFamily(node: N): string; + fontFamily(node: N): string; /** - * @param {N} node The HTML node whose dimensions are to be determined - * @param {number} em The number of pixels in an em - * @param {boolean} local True if local coordinates are to be used in SVG elements - * @returns {[number, number]} The width and height (in ems) of the element + * @param {N} node The HTML node whose dimensions are to be determined + * @param {number} em The number of pixels in an em + * @param {boolean} local True if local coordinates are to be used in SVG elements + * @returns {[number, number]} The width and height (in ems) of the element */ - nodeSize(node: N, em?: number, local?: boolean): [number, number]; + nodeSize(node: N, em?: number, local?: boolean): [number, number]; /** - * @param {N} node The HTML node whose BBox is to be determined - * @returns {PageBBox} BBox as {left, right, top, bottom} position on the page (in pixels) + * @param {N} node The HTML node whose BBox is to be determined + * @returns {PageBBox} BBox as {left, right, top, bottom} position on the page (in pixels) */ - nodeBBox(node: N): PageBBox; + nodeBBox(node: N): PageBBox; /** * @param {(event: any) => void} listener The event listener for messages from the worker @@ -426,19 +437,15 @@ export interface DOMAdaptor { /** * Abstract DOMAdaptor class for creating HTML elements * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export abstract class AbstractDOMAdaptor implements DOMAdaptor< - N, - T, - D -> { +export abstract class AbstractDOMAdaptor< + DOM extends DOM_TYPES, +> implements DOMAdaptor { /** * The document in which the HTML nodes will be created */ - public document: D; + public document: D; /** * True when the adaptor can measure DOM node sizes @@ -447,16 +454,15 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< /** * @param {D} document The document in which the nodes will be created - * @class */ - constructor(document: D = null) { + constructor(document: D = null) { this.document = document; } /** * @override */ - public abstract parse(text: string, format?: string): D; + public abstract parse(text: string, format?: string): D; /** * @override @@ -464,7 +470,7 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< public node( kind: string, def: OptionList = {}, - children: (N | T)[] = [], + children: NT[] = [], ns?: string ) { const node = this.create(kind, ns); @@ -472,32 +478,32 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< for (const child of children) { this.append(node, child); } - return node as N; + return node as N; } /** - * @param {string} kind The type of the node to create - * @param {string} ns The optional namespace in which to create the node + * @param {string} kind The type of the node to create + * @param {string} ns The optional namespace in which to create the node * @returns {N} The created node */ - protected abstract create(kind: string, ns?: string): N; + protected abstract create(kind: string, ns?: string): N; /** * @override */ - public abstract text(text: string): T; + public abstract text(text: string): T; /** * @override */ - public setProperty(node: N, name: string, value: any) { + public setProperty(node: N, name: string, value: any) { (node as any)[name] = value; } /** * @override */ - public getProperty(node: N, name: string): any { + public getProperty(node: N, name: string): any { return (node as any)[name]; } @@ -505,7 +511,7 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< * @param {N} node The HTML element whose attributes are to be set * @param {OptionList} def The attributes to set on that node */ - public setAttributes(node: N, def: OptionList) { + public setAttributes(node: N, def: OptionList) { if (def.style && typeof def.style !== 'string') { for (const key of Object.keys(def.style)) { this.setStyle( @@ -533,67 +539,70 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< /** * @override */ - public abstract head(doc?: D): N; + public abstract head(doc?: D): N; /** * @override */ - public abstract body(doc?: D): N; + public abstract body(doc?: D): N; /** * @override */ - public abstract root(doc?: D): N; + public abstract root(doc?: D): N; /** * @override */ - public abstract doctype(doc?: D): string; + public abstract doctype(doc?: D): string; /** * @override */ - public abstract tags(node: N, name: string, ns?: string): N[]; + public abstract tags(node: N, name: string, ns?: string): N[]; /** * @override */ - public abstract getElements(nodes: (string | N | N[])[], document: D): N[]; + public abstract getElements( + nodes: ContainerSpec[], + document: D + ): N[]; /** * @override */ - public abstract getElement(selector: string, node?: D | N): N; + public abstract getElement(selector: string, node?: D | N): N; /** * @override */ - public abstract contains(container: N, node: N | T): boolean; + public abstract contains(container: N, node: NT): boolean; /** * @override */ - public abstract parent(node: N | T): N; + public abstract parent(node: NT): N; /** * @override */ - public abstract append(node: N, child: N | T): N | T; + public abstract append(node: N, child: NT): NT; /** * @override */ - public abstract insert(nchild: N | T, ochild: N | T): void; + public abstract insert(nchild: NT, ochild: NT): void; /** * @override */ - public abstract remove(child: N | T): N | T; + public abstract remove(child: NT): NT; /** * @override */ - public replace(nnode: N | T, onode: N | T) { + public replace(nnode: NT, onode: NT) { this.insert(nnode, onode); this.remove(onode); return onode; @@ -602,80 +611,80 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< /** * @override */ - public abstract clone(node: N, deep: boolean): N; + public abstract clone(node: N, deep: boolean): N; /** * @override */ - public abstract split(node: T, n: number): T; + public abstract split(node: T, n: number): T; /** * @override */ - public abstract next(node: N | T): N | T; + public abstract next(node: NT): NT; /** * @override */ - public abstract previous(node: N | T): N | T; + public abstract previous(node: NT): NT; /** * @override */ - public abstract firstChild(node: N): N | T; + public abstract firstChild(node: N): NT; /** * @override */ - public abstract lastChild(node: N): N | T; + public abstract lastChild(node: N): NT; /** * @override */ - public abstract childNodes(node: N): (N | T)[]; + public abstract childNodes(node: N): NT[]; /** * @override */ - public childNode(node: N, i: number) { + public childNode(node: N, i: number) { return this.childNodes(node)[i]; } /** * @override */ - public abstract kind(node: N | T): string; + public abstract kind(node: NT): string; /** * @override */ - public abstract value(node: N | T): string; + public abstract value(node: NT): string; /** * @override */ - public abstract textContent(node: N): string; + public abstract textContent(node: N): string; /** * @override */ - public abstract innerHTML(node: N): string; + public abstract innerHTML(node: N): string; /** * @override */ - public abstract outerHTML(node: N): string; + public abstract outerHTML(node: N): string; /** * @override */ - public abstract serializeXML(node: N): string; + public abstract serializeXML(node: N): string; /** * @override */ public abstract setAttribute( - node: N, + node: N, name: string, value: string, ns?: string @@ -684,42 +693,42 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< /** * @override */ - public abstract getAttribute(node: N, name: string): string; + public abstract getAttribute(node: N, name: string): string; /** * @override */ - public abstract removeAttribute(node: N, name: string): void; + public abstract removeAttribute(node: N, name: string): void; /** * @override */ - public abstract hasAttribute(node: N, name: string): boolean; + public abstract hasAttribute(node: N, name: string): boolean; /** * @override */ - public abstract allAttributes(node: N): AttributeData[]; + public abstract allAttributes(node: N): AttributeData[]; /** * @override */ - public abstract addClass(node: N, name: string): void; + public abstract addClass(node: N, name: string): void; /** * @override */ - public abstract removeClass(node: N, name: string): void; + public abstract removeClass(node: N, name: string): void; /** * @override */ - public abstract hasClass(node: N, name: string): boolean; + public abstract hasClass(node: N, name: string): boolean; /** * @override */ - public allClasses(node: N) { + public allClasses(node: N) { const classes = this.getAttribute(node, 'class'); return !classes ? ([] as string[]) @@ -733,45 +742,45 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< /** * @override */ - public abstract setStyle(node: N, name: string, value: string): void; + public abstract setStyle(node: N, name: string, value: string): void; /** * @override */ - public abstract getStyle(node: N, name: string): string; + public abstract getStyle(node: N, name: string): string; /** * @override */ - public abstract allStyles(node: N): string; + public abstract allStyles(node: N): string; /** * @override */ - public abstract insertRules(node: N, rules: string[]): void; + public abstract insertRules(node: N, rules: string[]): void; /** * @override */ - public cssText(node: N) { + public cssText(node: N) { return this.kind(node) === 'style' ? this.textContent(node) : ''; } /** * @override */ - public abstract fontSize(node: N): number; + public abstract fontSize(node: N): number; /** * @override */ - public abstract fontFamily(node: N): string; + public abstract fontFamily(node: N): string; /** * @override */ public abstract nodeSize( - node: N, + node: N, em?: number, local?: boolean ): [number, number]; @@ -779,7 +788,7 @@ export abstract class AbstractDOMAdaptor implements DOMAdaptor< /** * @override */ - public abstract nodeBBox(node: N): PageBBox; + public abstract nodeBBox(node: N): PageBBox; /** * @override diff --git a/ts/core/FilterFunctions.ts b/ts/core/FilterFunctions.ts index 6a59c815ee..ed7d692fce 100644 --- a/ts/core/FilterFunctions.ts +++ b/ts/core/FilterFunctions.ts @@ -23,26 +23,42 @@ import { MathDocument } from './MathDocument.js'; import { MathItem } from './MathItem.js'; -import { DOM_TYPES, N, T, D } from '../types/Types.js'; +import { DOM_TYPES } from '../types/Types.js'; import { FunctionList } from '../util/FunctionList.js'; /** - * Types for filter functions + * Data passed to a filter */ export type FilterData = { - math: MathItem, T, D>; - document: MathDocument, T, D>; + math: MathItem; + document: MathDocument; data: U; }; + +/** + * A fulter function itself + */ export type FilterFunction = ( arg: FilterData ) => boolean | void; + +/** + * A filter function or one with a priority + */ export type FilterFunctionDef = FilterFunction | [FilterFunction, number]; + +/** + * A list of filter function definitions + */ export type FilterFunctionList = FilterFunctionDef< T, D >[]; + +/** + * A FunctionList of filter functions + */ export type FilterFunctions = FunctionList< FilterFunction >; diff --git a/ts/core/FindMath.ts b/ts/core/FindMath.ts index d7fb08eacd..d990bdcaa0 100644 --- a/ts/core/FindMath.ts +++ b/ts/core/FindMath.ts @@ -23,30 +23,29 @@ import { userOptions, defaultOptions, OptionList } from '../util/Options.js'; import { ProtoItem } from './MathItem.js'; +import { DOM_TYPES, N } from '../types/Types.js'; /*****************************************************************/ /** * The FindMath interface * - * @template N The HTMLElement node class - * @template T The Text node class - * @template _D The Document class + * @template DOM The DOM node types */ -export interface FindMath { +export interface FindMath { /** * One of two possibilities: Look through a DOM element, * or look through an array of strings for delimited math. * * @param {N} node The node to search for math - * @returns {ProtoItem[]} + * @returns {ProtoItem[]} */ - findMath(node: N): ProtoItem[]; + findMath(node: N): ProtoItem[]; /** * * @param {string[]} strings The strings to search for math - * @returns {ProtoItem[]} + * @returns {ProtoItem[]} */ - findMath(strings: string[]): ProtoItem[]; + findMath(strings: string[]): ProtoItem[]; } /*****************************************************************/ @@ -55,11 +54,11 @@ export interface FindMath { */ /** - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export abstract class AbstractFindMath implements FindMath { +export abstract class AbstractFindMath< + DOM extends DOM_TYPES, +> implements FindMath { /** * The default options for FindMath */ @@ -84,5 +83,5 @@ export abstract class AbstractFindMath implements FindMath { * @param {Element | string[]} where The node or string array to search for math * @returns {ProtoItem[]} The array of proto math items found */ - public abstract findMath(where: N | string[]): ProtoItem[]; + public abstract findMath(where: N | string[]): ProtoItem[]; } diff --git a/ts/core/Handler.ts b/ts/core/Handler.ts index aab2e05c92..fc002c714a 100644 --- a/ts/core/Handler.ts +++ b/ts/core/Handler.ts @@ -28,16 +28,15 @@ import { } from './MathDocument.js'; import { OptionList } from '../util/Options.js'; import { DOMAdaptor } from '../core/DOMAdaptor.js'; +import { DOM_TYPES } from '../types/Types.js'; /*****************************************************************/ /** * The Handler interface * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface Handler { +export interface Handler { /** * The name of the handler class */ @@ -46,7 +45,7 @@ export interface Handler { /** * The DOM Adaptor to use for managing HTML elements */ - adaptor: DOMAdaptor; + adaptor: DOMAdaptor; /** * The priority for the handler when handlers are polled @@ -58,12 +57,12 @@ export interface Handler { * The class implementing the MathDocument for this handler * (so it can be subclassed by extensions as needed) */ - documentClass: MathDocumentConstructor>; + documentClass: MathDocumentConstructor, DOM>; /** * Checks to see if the handler can process a given document * - * @param {any} document The document to be processed (string, window, etc.) + * @param {any} document The document to be processed (string, window, etc.) * @returns {boolean} True if this handler can process the given document */ handlesDocument(document: any): boolean; @@ -71,32 +70,32 @@ export interface Handler { /** * Creates a MathDocument for the given handler * - * @param {any} document The document to be handled - * @param {OptionList} options The options for the handling of the document + * @param {any} document The document to be handled + * @param {OptionList} options The options for the handling of the document * @returns {MathDocument} The MathDocument object that manages the processing */ - create(document: any, options: OptionList): MathDocument; + create(document: any, options: OptionList): MathDocument; } /*****************************************************************/ /** * The default MathDocument class (subclasses use their own) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -class DefaultMathDocument extends AbstractMathDocument {} +class DefaultMathDocument< + DOM extends DOM_TYPES, +> extends AbstractMathDocument {} /*****************************************************************/ /** * The Handler interface * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export abstract class AbstractHandler implements Handler { +export abstract class AbstractHandler< + DOM extends DOM_TYPES, +> implements Handler { /** * The name of this class */ @@ -105,7 +104,7 @@ export abstract class AbstractHandler implements Handler { /** * The DOM Adaptor to use for managing HTML elements */ - public adaptor: DOMAdaptor; + public adaptor: DOMAdaptor; /** * The priority for this handler @@ -116,8 +115,10 @@ export abstract class AbstractHandler implements Handler { * The class implementing the MathDocument for this handler * (so it can be subclassed by extensions as needed) */ - public documentClass: MathDocumentConstructor> = - DefaultMathDocument; + public documentClass = DefaultMathDocument as MathDocumentConstructor< + AbstractMathDocument, + DOM + >; /** * @param {DOMAdaptor} adaptor The DOM adaptor @@ -125,7 +126,7 @@ export abstract class AbstractHandler implements Handler { * * @class */ - constructor(adaptor: DOMAdaptor, priority: number = 5) { + constructor(adaptor: DOMAdaptor, priority: number = 5) { this.adaptor = adaptor; this.priority = priority; } @@ -152,6 +153,6 @@ export abstract class AbstractHandler implements Handler { document, this.adaptor, options - ) as MathDocument; + ) as MathDocument; } } diff --git a/ts/core/HandlerList.ts b/ts/core/HandlerList.ts index a4ff9970a7..dd38c9d8c9 100644 --- a/ts/core/HandlerList.ts +++ b/ts/core/HandlerList.ts @@ -27,6 +27,7 @@ import { Handler } from './Handler.js'; import { MathDocument } from './MathDocument.js'; import { Locale } from '../util/Locale.js'; import { COMPONENT } from '../core/__locales__/Component.js'; +import { DOM_TYPES } from '../types/Types.js'; /*****************************************************************/ /** @@ -36,23 +37,23 @@ import { COMPONENT } from '../core/__locales__/Component.js'; * by asking each handler to test if it can handle the document, * and when one can, it is asked to create its associated MathDocument. * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class HandlerList extends PrioritizedList> { +export class HandlerList extends PrioritizedList< + Handler +> { /** * @param {Handler} handler The handler to register - * @returns {Handler} The list item created for the handler + * @returns {Handler} The list item created for the handler */ - public register(handler: Handler): Handler { + public register(handler: Handler): Handler { return this.add(handler, handler.priority); } /** * @param {Handler} handler The handler to remove from the list */ - public unregister(handler: Handler) { + public unregister(handler: Handler) { this.remove(handler); } @@ -60,7 +61,7 @@ export class HandlerList extends PrioritizedList> { * @param {any} document The document (string, window, DOM element, etc) to be handled * @returns {Handler} The handler from the list that can process the given document */ - public handlesDocument(document: any): Handler { + public handlesDocument(document: any): Handler { for (const item of this) { const handler = item.item; if (handler.handlesDocument(document)) { @@ -71,14 +72,14 @@ export class HandlerList extends PrioritizedList> { } /** - * @param {any} document The document to be processed - * @param {OptionList} options The options for the handler + * @param {any} document The document to be processed + * @param {OptionList} options The options for the handler * @returns {MathDocument} The MathDocument created by the handler for this document */ public document( document: any, options: OptionList = null - ): MathDocument { + ): MathDocument { return this.handlesDocument(document).create(document, options); } } diff --git a/ts/core/InputJax.ts b/ts/core/InputJax.ts index 96dbb88706..3be49e4572 100644 --- a/ts/core/InputJax.ts +++ b/ts/core/InputJax.ts @@ -28,18 +28,16 @@ import { MmlFactory } from './MmlTree/MmlFactory.js'; import { userOptions, defaultOptions, OptionList } from '../util/Options.js'; import { FunctionList } from '../util/FunctionList.js'; import { DOMAdaptor } from '../core/DOMAdaptor.js'; -import type { DOM, DOM_TYPES } from '../types/Types.js'; +import type { DOM, DOM_TYPES, N } from '../types/Types.js'; import type { FilterFunctions, FilterFunctionList } from './FilterFunctions.js'; /*****************************************************************/ /** * The InputJax interface * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface InputJax { +export interface InputJax { /** * The name of the input jax subclass (e.g,. 'TeX') */ @@ -59,13 +57,13 @@ export interface InputJax { /** * Lists of pre- and post-filters to call before and after processing the input */ - preFilters: FilterFunctions>; - postFilters: FilterFunctions>; + preFilters: FilterFunctions; + postFilters: FilterFunctions; /** * The DOM adaptor for managing HTML elements */ - adaptor: DOMAdaptor; + adaptor: DOMAdaptor; /** * The MmlFactory for this input jax @@ -75,7 +73,7 @@ export interface InputJax { /** * @param {DOMAdaptor} adaptor The adaptor to use in this jax */ - setAdaptor(adaptor: DOMAdaptor): void; + setAdaptor(adaptor: DOMAdaptor): void; /** * @param {MmlFactory} mmlFactory The MmlFactory to use in this jax @@ -97,25 +95,29 @@ export interface InputJax { /** * Finds the math within the DOM or the list of strings * - * @param {N | string[]} which The element or array of strings to be searched for math + * @param {N|string[]} which The element or array of strings to be searched for math * @param {OptionList} options The options for the search, if any * @returns {ProtoItem[]} Array of proto math items found (further processed by the * handler to produce actual MathItem objects) */ - findMath(which: N | string[], options?: OptionList): ProtoItem[]; + findMath(which: N | string[], options?: OptionList): ProtoItem[]; /** * Convert the math in a math item into the internal format * - * @param {MathItem} math The MathItem whose math content is to processed - * @param {MathDocument} document The MathDocument for this input jax. - * @returns {MmlNode} The resulting internal node tree for the math + * @param {MathItem} math The MathItem whose math content is to processed + * @param {MathDocument} document The MathDocument for this input jax. + * @returns {MmlNode} The resulting internal node tree for the math */ - compile(math: MathItem, document: MathDocument): MmlNode; + compile(math: MathItem, document: MathDocument): MmlNode; } /** * The InputJax option types. + * + * @template DOM The DOM node types + * @template PRE The type of data passed to the pre-filter functions + * @template POST The type of data passed to the post-filter functions */ export type INPUTJAX_OPTIONS< D extends DOM_TYPES = DOM, @@ -130,19 +132,15 @@ export type INPUTJAX_OPTIONS< /** * The abstract InputJax class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types * @template PRE The type of data passed to the pre-filter functions * @template POST The type of data passed to the post-filter functions */ export abstract class AbstractInputJax< - N, - T, - D, + DOM extends DOM_TYPES, PRE = any, POST = PRE, -> implements InputJax { +> implements InputJax { /** * The name of the input jax */ @@ -164,17 +162,17 @@ export abstract class AbstractInputJax< /** * Filters to run on the TeX string before it is processed */ - public preFilters: FilterFunctions>; + public preFilters: FilterFunctions; /** * Filters to run on the generated MathML after the TeX string is processed */ - public postFilters: FilterFunctions>; + public postFilters: FilterFunctions; /** * The DOMAdaptor for the MathDocument for this input jax */ - public adaptor: DOMAdaptor = null; // set by the handler + public adaptor: DOMAdaptor = null; // set by the handler /** * The MathML node factory */ @@ -202,7 +200,7 @@ export abstract class AbstractInputJax< /** * @override */ - public setAdaptor(adaptor: DOMAdaptor) { + public setAdaptor(adaptor: DOMAdaptor) { this.adaptor = adaptor; } @@ -233,16 +231,16 @@ export abstract class AbstractInputJax< /** * @override */ - public findMath(_node: N | string[], _options?: OptionList) { - return [] as ProtoItem[]; + public findMath(_node: N | string[], _options?: OptionList) { + return [] as ProtoItem[]; } /** * @override */ public abstract compile( - math: MathItem, - document: MathDocument + math: MathItem, + document: MathDocument ): MmlNode; /** @@ -255,12 +253,12 @@ export abstract class AbstractInputJax< * @param {any} data Whatever other data is needed * @returns {any} The (possibly modified) data * - * @template D The type of data being passed + * @template DATA The type of data being passed */ protected executeFilters( filters: FunctionList, - math: MathItem, - document: MathDocument, + math: MathItem, + document: MathDocument, data: DATA ): any { const args = { math: math, document: document, data: data }; diff --git a/ts/core/MathDocument.ts b/ts/core/MathDocument.ts index 0822def47d..88eab74ac2 100644 --- a/ts/core/MathDocument.ts +++ b/ts/core/MathDocument.ts @@ -33,12 +33,12 @@ import { MathList, MathListItem, AbstractMathList } from './MathList.js'; import { MathItem, AbstractMathItem, STATE } from './MathItem.js'; import { MmlNode, TextNode } from './MmlTree/MmlNode.js'; import { MmlFactory } from '../core/MmlTree/MmlFactory.js'; -import { DOMAdaptor } from '../core/DOMAdaptor.js'; +import { DOMAdaptor, ContainerSpec } from '../core/DOMAdaptor.js'; import { BitField, BitFieldClass } from '../util/BitField.js'; import { PrioritizedList } from '../util/PrioritizedList.js'; import { localize } from './__locales__/Component.js'; import { mathjax } from '../mathjax.js'; -import { DOM, DOM_TYPES, N, T, D, Constructor } from '../types/Types.js'; +import { DOM, DOM_TYPES, N, D, Constructor } from '../types/Types.js'; /*****************************************************************/ @@ -50,39 +50,32 @@ export type RenderResult = Promise | boolean | void; /** * A function to call while rendering a document (usually calls a MathDocument method) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export type RenderDoc = ( - document: MathDocument +export type RenderDoc = ( + document: MathDocument ) => RenderResult; /** * A function to call while rendering a MathItem (usually calls one of its methods) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export type RenderMath = ( - math: MathItem, - document: MathDocument +export type RenderMath = ( + math: MathItem, + document: MathDocument ) => RenderResult; /** * The data for an action to perform during rendering or conversion * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -/* prettier-ignore */ -export type RenderData = { - id: string, // The name for the action - renderDoc: RenderDoc, // The action to take during a render() call - renderMath: RenderMath, // The action to take during a rerender() or convert() call - convert: boolean // Whether the action is to be used during convert() +export type RenderData = { + id: string; // The name for the action + renderDoc: RenderDoc; // The action to take during a render() call + renderMath: RenderMath; // The action to take during a rerender() or convert() call + convert: boolean; // Whether the action is to be used during convert() }; /** @@ -91,51 +84,50 @@ export type RenderData = { * the remainind data is as described below; if no boolean is given, convert = true * by default) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -/* prettier-ignore */ -export type RenderAction = - [number] | // id (i.e., key) is method name to use - [number, string] | // string is method to call - [number, string, string] | // the strings are methods names for doc and math - [number, RenderDoc, RenderMath] | // explicit functions for doc and math - [number, boolean] | // same as first above, with boolean for convert - [number, string, boolean] | // same as second above, with boolean for convert - [number, string, string, boolean] | // same as third above, with boolean for convert - [number, RenderDoc, RenderMath, boolean]; // same as forth above, with boolean for convert +export type RenderAction = + | [number] // Id (i.e., key) is method name to use + | [number, string] // String is method to call + | [number, string, string] // The strings are methods names for doc and math + | [number, RenderDoc, RenderMath] // Explicit functions for doc and math + | [number, boolean] // Same as first above, with boolean for convert + | [number, string, boolean] // Same as second above, with boolean for convert + | [number, string, string, boolean] // Same as third above, with boolean for convert + | [number, RenderDoc, RenderMath, boolean]; // Same as forth above, with boolean for convert /** * An object representing a collection of rendering actions (id's tied to priority-and-method data) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export type RenderActions = { [id: string]: RenderAction }; +export type RenderActions = { + [id: string]: RenderAction; +}; /** * Implements a prioritized list of render actions. Extensions can add actions to the list * to make it easy to extend the normal typesetting and conversion operations. * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export class RenderList extends PrioritizedList> { +export class RenderList extends PrioritizedList< + RenderData +> { /** * Creates a new RenderList from an initial list of rendering actions * - * @param {RenderActions} actions The list of actions to take during render(), rerender(), and convert() calls - * @returns {RenderList} The newly created prioritied list + * @param {RenderActions} actions The list of actions to take during render(), rerender(), and convert() calls + * @returns {RenderList} The newly created prioritied list + * + * @template DOM The DOM element types */ - public static create( - actions: RenderActions - ): RenderList { - const list = new this(); + public static create( + actions: RenderActions + ): RenderList { + const list = new this(); for (const id of Object.keys(actions)) { - const [action, priority] = this.action(id, actions[id]); + const [action, priority] = this.action(id, actions[id]); if (priority) { list.add(action, priority); } @@ -150,11 +142,13 @@ export class RenderList extends PrioritizedList> { * @param {string} id The id of the action * @param {RenderAction} action The RenderAction defining the action * @returns {[RenderData,number]} The corresponding RenderData definition for the action and its priority + * + * @template DOM The DOM element types */ - public static action( + public static action( id: string, - action: RenderAction - ): [RenderData, number] { + action: RenderAction + ): [RenderData, number] { let renderDoc, renderMath; let convert = true; const priority = action[0]; @@ -181,12 +175,12 @@ export class RenderList extends PrioritizedList> { convert = action[3] as boolean; } [renderDoc, renderMath] = action.slice(1) as [ - RenderDoc, - RenderMath, + RenderDoc, + RenderMath, ]; } return [ - { id, renderDoc, renderMath, convert } as RenderData, + { id, renderDoc, renderMath, convert } as RenderData, priority, ]; } @@ -224,7 +218,7 @@ export class RenderList extends PrioritizedList> { * @param {number=} i The index in the renderAction list to start at */ public renderDoc( - document: MathDocument, + document: MathDocument, start: number = STATE.UNPROCESSED, i: number = 0 ) { @@ -248,8 +242,8 @@ export class RenderList extends PrioritizedList> { * @param {number=} i The index in the renderAction list to start at */ public renderMath( - math: MathItem, - document: MathDocument, + math: MathItem, + document: MathDocument, start: number = STATE.UNPROCESSED, i: number = 0 ) { @@ -276,11 +270,11 @@ export class RenderList extends PrioritizedList> { * @returns {N|MmlNode} The typeset root or the MathML root, whichever is defined */ public renderConvert( - math: MathItem, - document: MathDocument, + math: MathItem, + document: MathDocument, end: number = STATE.LAST, i: number = 0 - ): N | MmlNode { + ): N | MmlNode { let item; while ((item = this.items[i++])) { if (item.priority > end) break; @@ -299,10 +293,10 @@ export class RenderList extends PrioritizedList> { /** * Find an entry in the list with a given ID * - * @param {string} id The id to search for + * @param {string} id The id to search for * @returns {RenderData|null} The data for the given id, if found, or null */ - public findID(id: string): RenderData | null { + public findID(id: string): RenderData | null { for (const item of this.items) { if (item.item.id === id) { return item.item; @@ -318,9 +312,10 @@ export class RenderList extends PrioritizedList> { * The ways of specifying a container (a selector string, an actual node, * or an array of those (e.g., the result of document.getElementsByTagName()) * - * @template N The HTMLElement node class + * @template DOM The DOM element types */ -export type ContainerList = string | N | (string | N | N[])[]; +export type ContainerList = + ContainerSpec | ContainerSpec[]; /** * The options allowed for the reset() method @@ -371,15 +366,13 @@ export const resetAllOptions: ResetList = { * The MathDocument is the main interface for page authors to * interact with MathJax. * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export interface MathDocument { +export interface MathDocument { /** * The document being processed (e.g., DOM document, or Markdown string) */ - document: D; + document: D; /** * The kind of MathDocument (e.g., "HTML") @@ -389,17 +382,17 @@ export interface MathDocument { /** * The options for the document */ - options: DOCUMENT_OPTIONS>; + options: DOCUMENT_OPTIONS; /** * The list of MathItems found in this page */ - math: MathList; + math: MathList; /** * The list of actions to take during a render() or convert() call */ - renderActions: RenderList; + renderActions: RenderList; /** * This object tracks what operations have been performed, so that (when @@ -411,17 +404,17 @@ export interface MathDocument { /** * An array of input jax to run on the document */ - inputJax: InputJax[]; + inputJax: InputJax[]; /** * The output jax to use for the document */ - outputJax: OutputJax; + outputJax: OutputJax; /** * The DOM adaptor to use for input and output */ - adaptor: DOMAdaptor; + adaptor: DOMAdaptor; /** * The MmlFactory to be used for input jax and error processing @@ -474,18 +467,18 @@ export interface MathDocument { * * @param {string} math The math string to convert * @param {OptionList} options The options for the conversion (e.g., format, ex, em, etc.) - * @returns {MmlNode|N} The MmlNode or N node for the converted content + * @returns {MmlNode|N} The MmlNode or N node for the converted content */ - convert(math: string, options?: OptionList): MmlNode | N; + convert(math: string, options?: OptionList): MmlNode | N; /** * Convert a math string to the document's output format * - * @param {string} math The math string to convert - * @param {OptionList} options The options for the conversion (e.g., format, ex, em, etc.) - * @returns {Promise} A promise that resolves when the conversion is complete + * @param {string} math The math string to convert + * @param {OptionList} options The options for the conversion (e.g., format, ex, em, etc.) + * @returns {Promise>} A promise that resolves when the conversion is complete */ - convertPromise(math: string, options?: OptionList): Promise; + convertPromise(math: string, options?: OptionList): Promise>; /** * Perform an action when previous actions are complete. @@ -548,8 +541,8 @@ export interface MathDocument { /** * Removes the typeset math from the document * - * @param {boolean} restore True if the original math should be put - * back into the document as well + * @param {boolean} restore True if the original math should be put + * back into the document as well * @returns {MathDocument} The math document instance */ removeFromDocument(restore?: boolean): this; @@ -558,9 +551,9 @@ export interface MathDocument { * Set the state of the document (allowing you to roll back * the state to a previous one, if needed). * - * @param {number} state The new state of the document - * @param {boolean} restore True if the original math should be put - * back into the document during the rollback + * @param {number} state The new state of the document + * @param {boolean} restore True if the original math should be put + * back into the document during the rollback * @returns {MathDocument} The math document instance */ state(state: number, restore?: boolean): this; @@ -569,7 +562,7 @@ export interface MathDocument { * Clear the processed values so that the document can be reprocessed * * @param {ResetList} options The things to be reset - * @returns {MathDocument} The math document instance + * @returns {MathDocument} The math document instance */ reset(options?: ResetList): this; @@ -589,10 +582,10 @@ export interface MathDocument { /** * Merges a MathList into the list for this document. * - * @param {MathList} list The MathList to be merged into this document's list + * @param {MathList} list The MathList to be merged into this document's list * @returns {MathDocument} The math document instance */ - concat(list: MathList): this; + concat(list: MathList): this; /** * Clear the typeset MathItems that are within the given container @@ -600,18 +593,18 @@ export interface MathDocument { * container has been updated and you want to remove the * associated MathItems) * - * @param {ContainerList} containers The container DOM elements whose math items are to be removed - * @returns {MathItem[]} The removed MathItems + * @param {ContainerList} containers The container DOM elements whose math items are to be removed + * @returns {MathItem[]} The removed MathItems */ - clearMathItemsWithin(containers: ContainerList): MathItem[]; + clearMathItemsWithin(containers: ContainerList): MathItem[]; /** * Get the typeset MathItems that are within a given container. * - * @param {ContainerList} elements The container DOM elements whose math items are to be found - * @returns {MathItem[]} The list of MathItems within that container + * @param {ContainerList} elements The container DOM elements whose math items are to be found + * @returns {MathItem[]} The list of MathItems within that container */ - getMathItemsWithin(elements: ContainerList): MathItem[]; + getMathItemsWithin(elements: ContainerList): MathItem[]; } /*****************************************************************/ @@ -619,15 +612,13 @@ export interface MathDocument { /** * Defaults used when input jax isn't specified * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -class DefaultInputJax extends AbstractInputJax { +class DefaultInputJax extends AbstractInputJax { /** * @override */ - public compile(_math: MathItem) { + public compile(_math: MathItem) { return null as MmlNode; } } @@ -635,69 +626,61 @@ class DefaultInputJax extends AbstractInputJax { /** * Defaults used when ouput jax isn't specified * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -class DefaultOutputJax extends AbstractOutputJax { +class DefaultOutputJax extends AbstractOutputJax { /** * @override */ - public typeset( - _math: MathItem, - _document: MathDocument = null - ) { - return null as N; + public typeset(_math: MathItem, _document: MathDocument = null) { + return null as N; } /** * @override */ - public escaped(_math: MathItem, _document?: MathDocument) { - return null as N; + public escaped(_math: MathItem, _document?: MathDocument) { + return null as N; } } /** * Default for the MathList when one isn't specified * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -class DefaultMathList extends AbstractMathList {} +class DefaultMathList extends AbstractMathList {} /** * Default for the Mathitem when one isn't specified * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -class DefaultMathItem extends AbstractMathItem {} +class DefaultMathItem extends AbstractMathItem {} /*****************************************************************/ /** * The MathDocument option types. + * + * @template DOM The DOM element types */ export type DOCUMENT_OPTIONS = { - OutputJax: OutputJax, T, D>; // instance of an OutputJax for the document - InputJax: - InputJax, T, D> | InputJax, T, D>[]; // instance of an InputJax or an array of them - MmlFactory: MmlFactory; // instance of a MmlFactory for this document - MathList: Constructor, T, D>>; // constructor for a MathList to use for the document - MathItem: Constructor, T, D>>; // constructor for a MathItem to use for the MathList + OutputJax: OutputJax; // Instance of an OutputJax for the document + InputJax: InputJax | InputJax[]; // Instance of an InputJax or an array of them + MmlFactory: MmlFactory; // Instance of a MmlFactory for this document + MathList: Constructor>; // Constructor for a MathList to use for the document + MathItem: Constructor>; // Constructor for a MathItem to use for the MathList compileError: ( - doc: AbstractMathDocument, T, D>, - math: MathItem, T, D>, + doc: AbstractMathDocument, + math: MathItem, err: Error ) => void; typesetError: ( - doc: AbstractMathDocument, T, D>, - math: MathItem, T, D>, + doc: AbstractMathDocument, + math: MathItem, err: Error ) => void; - renderActions: RenderActions, T, D>; + renderActions: RenderActions; }; /** @@ -727,15 +710,11 @@ const options: DOCUMENT_OPTIONS = { /** * Implements the abstract MathDocument class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export abstract class AbstractMathDocument implements MathDocument< - N, - T, - D -> { +export abstract class AbstractMathDocument< + DOM extends DOM_TYPES, +> implements MathDocument { /** * The type of MathDocument */ @@ -760,21 +739,21 @@ export abstract class AbstractMathDocument implements MathDocument< /** * The document managed by this MathDocument */ - public document: D; + public document: D; /** * The actual options for this document (with user-supplied ones merged in) */ - public options: DOCUMENT_OPTIONS>; + public options: DOCUMENT_OPTIONS; /** * The list of MathItems for this document */ - public math: MathList; + public math: MathList; /** * The list of render actions */ - public renderActions: RenderList; + public renderActions: RenderList; /** * The render action promise list @@ -796,17 +775,17 @@ export abstract class AbstractMathDocument implements MathDocument< /** * The list of input jax for the document */ - public inputJax: InputJax[]; + public inputJax: InputJax[]; /** * The output jax for the document */ - public outputJax: OutputJax; + public outputJax: OutputJax; /** * The DOM adaptor for the document */ - public adaptor: DOMAdaptor; + public adaptor: DOMAdaptor; /** * The MathML node factory for the internal MathML representation @@ -819,7 +798,7 @@ export abstract class AbstractMathDocument implements MathDocument< * @param {OptionList} options The options for this document * @class */ - constructor(document: D, adaptor: DOMAdaptor, options: OptionList) { + constructor(document: D, adaptor: DOMAdaptor, options: OptionList) { const CLASS = this.constructor as typeof AbstractMathDocument; this.document = document; this.options = userOptions( @@ -827,12 +806,12 @@ export abstract class AbstractMathDocument implements MathDocument< options ) as DOCUMENT_OPTIONS; this.math = new (this.options.MathList ?? DefaultMathList)(); - this.renderActions = RenderList.create(this.options.renderActions); + this.renderActions = RenderList.create(this.options.renderActions); this._actionPromises = []; this._readyPromise = Promise.resolve(); this.processed = new AbstractMathDocument.ProcessBits(); - this.outputJax = this.options.OutputJax ?? new DefaultOutputJax(); - let inputJax = this.options.InputJax ?? [new DefaultInputJax()]; + this.outputJax = this.options.OutputJax ?? new DefaultOutputJax(); + let inputJax = this.options.InputJax ?? [new DefaultInputJax()]; if (!Array.isArray(inputJax)) { inputJax = [inputJax]; } @@ -866,10 +845,7 @@ export abstract class AbstractMathDocument implements MathDocument< * @override */ public addRenderAction(id: string, ...action: any[]) { - const [fn, p] = RenderList.action( - id, - action as RenderAction - ); + const [fn, p] = RenderList.action(id, action as RenderAction); this.renderActions.add(fn, p); } @@ -932,7 +908,7 @@ export abstract class AbstractMathDocument implements MathDocument< /** * @override */ - public convert(math: string, options: OptionList = {}): MmlNode | N { + public convert(math: string, options: OptionList = {}): MmlNode | N { let { format, display, end, ex, em, containerWidth, scale, family } = userOptions( { @@ -977,7 +953,7 @@ export abstract class AbstractMathDocument implements MathDocument< public convertPromise( math: string, options: OptionList = {} - ): Promise { + ): Promise> { return this.whenReady(() => mathjax.handleRetriesFor(async () => { const node = this.convert(math, options); @@ -1073,12 +1049,12 @@ export abstract class AbstractMathDocument implements MathDocument< */ protected compileAction( action: boolean = true, - item: MathListItem = this.math.first(), - recompile: MathItem[] = [] + item: MathListItem = this.math.first(), + recompile: MathItem[] = [] ): this | Promise { if (this.processed.isSet('compile')) return this; while (!item.isEnd) { - const math = item.data as MathItem; + const math = item.data as MathItem; try { this.compileMath(math); } catch (err) { @@ -1110,7 +1086,7 @@ export abstract class AbstractMathDocument implements MathDocument< */ protected recompileAction( action: boolean, - recompile: MathItem[], + recompile: MathItem[], i: number = 0 ): Promise | void { while (i < recompile.length) { @@ -1134,7 +1110,7 @@ export abstract class AbstractMathDocument implements MathDocument< /** * @param {MathItem} math The item to compile */ - protected compileMath(math: MathItem): void { + protected compileMath(math: MathItem): void { try { math.compile(this); } catch (err) { @@ -1152,7 +1128,7 @@ export abstract class AbstractMathDocument implements MathDocument< * @param {MathItem} math The MathItem producing the error * @param {Error} err The Error object for the error */ - public compileError(math: MathItem, err: Error): void { + public compileError(math: MathItem, err: Error): void { math.root = this.mmlFactory.create('math', null, [ this.mmlFactory.create( 'merror', @@ -1188,11 +1164,11 @@ export abstract class AbstractMathDocument implements MathDocument< */ protected typesetAction( action: boolean = true, - item: MathListItem = this.math.first() + item: MathListItem = this.math.first() ): this | Promise { if (this.processed.isSet('typeset')) return this; while (!item.isEnd) { - const math = item.data as MathItem; + const math = item.data as MathItem; try { math.typeset(this); } catch (err) { @@ -1217,7 +1193,7 @@ export abstract class AbstractMathDocument implements MathDocument< * @param {MathItem} math The MathItem producing the error * @param {Error} err The Error object for the error */ - public typesetError(math: MathItem, err: Error): void { + public typesetError(math: MathItem, err: Error): void { math.typesetRoot = this.adaptor.node( 'mjx-container', { @@ -1345,7 +1321,7 @@ export abstract class AbstractMathDocument implements MathDocument< /** * @override */ - public concat(list: MathList): this { + public concat(list: MathList): this { this.math.merge(list); return this; } @@ -1353,9 +1329,7 @@ export abstract class AbstractMathDocument implements MathDocument< /** * @override */ - public clearMathItemsWithin( - containers: ContainerList - ): MathItem[] { + public clearMathItemsWithin(containers: ContainerList): MathItem[] { const items = this.getMathItemsWithin(containers); for (const item of items.slice(0).reverse()) { item.clear(); @@ -1367,13 +1341,16 @@ export abstract class AbstractMathDocument implements MathDocument< /** * @override */ - public getMathItemsWithin(elements: ContainerList): MathItem[] { + public getMathItemsWithin(elements: ContainerList): MathItem[] { if (!Array.isArray(elements)) { elements = [elements]; } const adaptor = this.adaptor; - const items = [] as MathItem[]; - const containers = adaptor.getElements(elements, this.document); + const items = [] as MathItem[]; + const containers = adaptor.getElements( + elements as ContainerSpec[], + this.document + ); ITEMS: for (const item of this.math) { for (const container of containers) { if (item.start.node && adaptor.contains(container, item.start.node)) { @@ -1390,14 +1367,14 @@ export abstract class AbstractMathDocument implements MathDocument< * The constructor type for a MathDocument * * @template DOC The MathDocument type this constructor is for - * @template DD The DOM types in use + * @template D The DOM types in use */ export interface MathDocumentConstructor< - DOC extends MathDocument, T
, D
>, - DD extends DOM_TYPES = DOM, + DOC extends MathDocument, + D extends DOM_TYPES, > { KIND: string; - OPTIONS: DOCUMENT_OPTIONS
; + OPTIONS: DOCUMENT_OPTIONS; ProcessBits: typeof BitField; new (...args: any[]): DOC; } diff --git a/ts/core/MathItem.ts b/ts/core/MathItem.ts index 2baf975151..8f6c6f3294 100644 --- a/ts/core/MathItem.ts +++ b/ts/core/MathItem.ts @@ -27,6 +27,7 @@ import { OptionList } from '../util/Options.js'; import { MmlNode } from './MmlTree/MmlNode.js'; import { Locale } from '../util/Locale.js'; import { COMPONENT } from './__locales__/Component.js'; +import { DOM_TYPES, N, T } from '../types/Types.js'; /*****************************************************************/ /** @@ -35,14 +36,13 @@ import { COMPONENT } from './__locales__/Component.js'; * an index into a string array, the character position within * the string, and the delimiter at that location). * - * @template N The HTMLElement node class - * @template T The Text node class + * @template DOM The DOM element types */ -export type Location = { +export type Location = { i?: number; n?: number; delim?: string; - node?: N | T; + node?: N | T; }; /*****************************************************************/ @@ -67,11 +67,9 @@ export type Metrics = { * internal format), its typeset version, its bounding box, * and so on. * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export interface MathItem { +export interface MathItem { /** * The string representing the expression to be processed */ @@ -80,7 +78,7 @@ export interface MathItem { /** * The input jax used to process the math */ - inputJax: InputJax; + inputJax: InputJax; /** * Whether the math is in display mode or inline mode @@ -96,8 +94,8 @@ export interface MathItem { * The start and ending locations in the document of * this expression */ - start: Location; - end: Location; + start: Location; + end: Location; /** * The internal format for this expression (once compiled) @@ -107,7 +105,7 @@ export interface MathItem { /** * The typeset version of the expression (once typeset) */ - typesetRoot: N; + typesetRoot: N; /** * The metric information at the location of the math @@ -126,7 +124,7 @@ export interface MathItem { * * @param {MathDocument} document The MathDocument in which the math resides */ - render(document: MathDocument): void; + render(document: MathDocument): void; /** * Rerenders an already rendered item and inserts it into the document @@ -134,7 +132,7 @@ export interface MathItem { * @param {MathDocument} document The MathDocument in which the math resides * @param {number=} start The state to start rerendering at (default = RERENDER) */ - rerender(document: MathDocument, start?: number): void; + rerender(document: MathDocument, start?: number): void; /** * Converts the expression by calling the render actions until the state matches the end state @@ -143,28 +141,28 @@ export interface MathItem { * @param {number=} end The state to end rerendering at (default = LAST) * @returns {MmlNode | N} The typesetRoot or root node of the converted MathItem */ - convert(document: MathDocument, end?: number): MmlNode | N; + convert(document: MathDocument, end?: number): MmlNode | N; /** * Converts the expression into the internal format by calling the input jax * * @param {MathDocument} document The MathDocument in which the math resides */ - compile(document: MathDocument): void; + compile(document: MathDocument): void; /** * Converts the internal format to the typeset version by calling the output jax * * @param {MathDocument} document The MathDocument in which the math resides */ - typeset(document: MathDocument): void; + typeset(document: MathDocument): void; /** * Inserts the typeset version in place of the original form in the document * * @param {MathDocument} document The MathDocument in which the math resides */ - updateDocument(document: MathDocument): void; + updateDocument(document: MathDocument): void; /** * Removes the typeset version from the document, optionally replacing the original @@ -219,18 +217,16 @@ export interface MathItem { * MathItem later (e.g., when the position within a string array * is translated back into the actual node location in the DOM). * - * @template N The HTMLElement node class - * @template T The Text node class + * @template DOM The DOM element types */ -/* prettier-ignore */ -export type ProtoItem = { - math: string; // The math expression itself - start: Location; // The starting location of the math - end: Location; // The ending location of the math - open?: string; // The opening delimiter - close?: string; // The closing delimiter - n?: number; // The index of the string in which this math is found - display: boolean; // True means display mode, false is inline mode +export type ProtoItem = { + math: string; // The math expression itself + start: Location; // The starting location of the math + end: Location; // The ending location of the math + open?: string; // The opening delimiter + close?: string; // The closing delimiter + n?: number; // The index of the string in which this math is found + display: boolean; // True means display mode, false is inline mode }; /** @@ -244,10 +240,10 @@ export type ProtoItem = { * @param {number} end The ending location of the math * @param {boolean} display True means display mode, false is inline mode * @returns {ProtoItem} The proto math item - * @template N The HTMLElement node class - * @template T The Text node class + * + * @template DOM The DOM element types */ -export function protoItem( +export function protoItem( open: string, math: string, close: string, @@ -255,8 +251,8 @@ export function protoItem( start: number, end: number, display: boolean = null -): ProtoItem { - const item: ProtoItem = { +): ProtoItem { + const item: ProtoItem = { open: open, math: math, close: close, @@ -272,11 +268,11 @@ export function protoItem( /** * Implements the MathItem class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types */ -export abstract class AbstractMathItem implements MathItem { +export abstract class AbstractMathItem< + DOM extends DOM_TYPES, +> implements MathItem { /** * The source text for the math (e.g., TeX string) */ @@ -286,7 +282,7 @@ export abstract class AbstractMathItem implements MathItem { * The input jax associated with this item */ - public inputJax: InputJax; + public inputJax: InputJax; /** * True when this math is in display mode @@ -296,11 +292,11 @@ export abstract class AbstractMathItem implements MathItem { /** * Reference to the beginning of the math in the document */ - public start: Location; + public start: Location; /** * Reference to the end of the math in the document */ - public end: Location; + public end: Location; /** * The compiled internal MathML (result of InputJax) @@ -309,7 +305,7 @@ export abstract class AbstractMathItem implements MathItem { /** * The typeset result (result of OutputJax) */ - public typesetRoot: N = null; + public typesetRoot: N = null; /** * The metric information about the surrounding environment @@ -348,10 +344,10 @@ export abstract class AbstractMathItem implements MathItem { */ constructor( math: string, - jax: InputJax, + jax: InputJax, display: boolean = true, - start: Location = { i: 0, n: 0, delim: '' }, - end: Location = { i: 0, n: 0, delim: '' } + start: Location = { i: 0, n: 0, delim: '' }, + end: Location = { i: 0, n: 0, delim: '' } ) { this.math = math; this.inputJax = jax; @@ -368,17 +364,14 @@ export abstract class AbstractMathItem implements MathItem { /** * @override */ - public render(document: MathDocument) { + public render(document: MathDocument) { document.renderActions.renderMath(this, document); } /** * @override */ - public rerender( - document: MathDocument, - start: number = STATE.RERENDER - ) { + public rerender(document: MathDocument, start: number = STATE.RERENDER) { if (this.state() >= start) { this.state(start - 1); } @@ -389,16 +382,16 @@ export abstract class AbstractMathItem implements MathItem { * @override */ public convert( - document: MathDocument, + document: MathDocument, end: number = STATE.LAST - ): MmlNode | N { + ): MmlNode | N { return document.renderActions.renderConvert(this, document, end); } /** * @override */ - public compile(document: MathDocument) { + public compile(document: MathDocument) { if (this.state() < STATE.COMPILED) { this.root = this.inputJax.compile(this, document); this.state(STATE.COMPILED); @@ -408,7 +401,7 @@ export abstract class AbstractMathItem implements MathItem { /** * @override */ - public typeset(document: MathDocument) { + public typeset(document: MathDocument) { if (this.state() < STATE.TYPESET) { this.typesetRoot = document.outputJax[ this.isEscaped ? 'escaped' : 'typeset' @@ -420,7 +413,7 @@ export abstract class AbstractMathItem implements MathItem { /** * @override */ - public updateDocument(_document: MathDocument) {} + public updateDocument(_document: MathDocument) {} /** * @override diff --git a/ts/core/MathList.ts b/ts/core/MathList.ts index 66bce562f6..5b9254bea6 100644 --- a/ts/core/MathList.ts +++ b/ts/core/MathList.ts @@ -23,51 +23,48 @@ import { LinkedList, ListItem } from '../util/LinkedList.js'; import { MathItem } from './MathItem.js'; +import { DOM_TYPES } from '../types/Types.js'; /*****************************************************************/ /** * The MathListItem type (extends ListItem) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export type MathListItem = ListItem>; +export type MathListItem = ListItem>; /*****************************************************************/ /** * The MathList interface (extends LinkedList) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface MathList extends LinkedList> { +export interface MathList extends LinkedList< + MathItem +> { /** * Test if one math item is before the other in the document (a < b) * * @param {MathItem} a The first MathItem * @param {MathItem} b The second MathItem */ - isBefore(a: MathItem, b: MathItem): boolean; + isBefore(a: MathItem, b: MathItem): boolean; } /*****************************************************************/ /** * The MathList abstract class (extends LinkedList) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export abstract class AbstractMathList - extends LinkedList> - implements MathList +export abstract class AbstractMathList + extends LinkedList> + implements MathList { /** * @override */ - public isBefore(a: MathItem, b: MathItem) { + public isBefore(a: MathItem, b: MathItem) { return ( a.start.i < b.start.i || (a.start.i === b.start.i && a.start.n < b.start.n) diff --git a/ts/core/MmlTree/MathMLVisitor.ts b/ts/core/MmlTree/MathMLVisitor.ts index 094c24cace..7fbde77c09 100644 --- a/ts/core/MmlTree/MathMLVisitor.ts +++ b/ts/core/MmlTree/MathMLVisitor.ts @@ -39,9 +39,9 @@ export class MathMLVisitor extends MmlVisitor { /** * Convert the tree rooted at a particular node into DOM nodes. * - * @param {MmlNode} node The node to use as the root of the tree to traverse + * @param {MmlNode} node The node to use as the root of the tree to traverse * @param {Document} document The document in which the nodes are created - * @returns {Node} The MathML DOM nodes representing the internal tree + * @returns {Node} The MathML DOM nodes representing the internal tree */ public visitTree(node: MmlNode, document: Document): Node { this.document = document; @@ -52,7 +52,7 @@ export class MathMLVisitor extends MmlVisitor { } /** - * @param {TextNode} node The text node to visit + * @param {TextNode} node The text node to visit * @param {Element} parent The DOM parent to which this node should be added */ public visitTextNode(node: TextNode, parent: Element) { @@ -60,7 +60,7 @@ export class MathMLVisitor extends MmlVisitor { } /** - * @param {XMLNode} node The XML node to visit + * @param {XMLNode} node The XML node to visit * @param {Element} parent The DOM parent to which this node should be added */ public visitXMLNode(node: XMLNode, parent: Element) { @@ -68,7 +68,7 @@ export class MathMLVisitor extends MmlVisitor { } /** - * @param {HtmlNode} node The HTML node to visit + * @param {HtmlNode} node The HTML node to visit * @param {Element} parent The DOM parent to which this node should be added */ public visitHtmlNode(node: HtmlNode, parent: Element) { @@ -79,7 +79,7 @@ export class MathMLVisitor extends MmlVisitor { * Visit an inferred mrow, but don't add the inferred row itself (since * it is supposed to be inferred). * - * @param {MmlNode} node The inferred mrow to visit + * @param {MmlNode} node The inferred mrow to visit * @param {Element} parent The DOM parent to which this node's children should be added */ public visitInferredMrowNode(node: MmlNode, parent: Element) { @@ -95,7 +95,7 @@ export class MathMLVisitor extends MmlVisitor { * Append its children nodes. * Append the new node to the DOM parent. * - * @param {MmlNode} node The node to visit + * @param {MmlNode} node The node to visit * @param {Element} parent The DOM parent to which this node should be added */ public visitDefault(node: MmlNode, parent: Element) { @@ -109,7 +109,7 @@ export class MathMLVisitor extends MmlVisitor { /** * @param {MmlNode} node The node who attributes are to be copied - * @param {Element} mml The MathML DOM node to which attributes are being added + * @param {Element} mml The MathML DOM node to which attributes are being added */ public addAttributes(node: MmlNode, mml: Element) { const attributes = this.getAttributeList(node); diff --git a/ts/core/MmlTree/MmlNode.ts b/ts/core/MmlTree/MmlNode.ts index a33ba44cf5..09d81022a9 100644 --- a/ts/core/MmlTree/MmlNode.ts +++ b/ts/core/MmlTree/MmlNode.ts @@ -35,6 +35,7 @@ import { MmlFactory } from './MmlFactory.js'; import { DOMAdaptor } from '../DOMAdaptor.js'; import { Locale } from '../../util/Locale.js'; import { COMPONENT } from '../__locales__/Component.js'; +import { DOM } from '../../types/Types.js'; /** * Used in setInheritedAttributes() to pass originating node kind as well as property value @@ -1506,7 +1507,7 @@ export class XMLNode extends AbstractMmlEmptyNode { /** * DOM adaptor for the content */ - protected adaptor: DOMAdaptor = null; + protected adaptor: DOMAdaptor = null; /** * @override @@ -1529,7 +1530,7 @@ export class XMLNode extends AbstractMmlEmptyNode { */ public setXML( xml: Object, // eslint-disable-line @typescript-eslint/no-wrapper-object-types - adaptor: DOMAdaptor = null + adaptor: DOMAdaptor = null ): XMLNode { this.xml = xml; this.adaptor = adaptor; diff --git a/ts/core/MmlTree/MmlNodes/HtmlNode.ts b/ts/core/MmlTree/MmlNodes/HtmlNode.ts index 838d881767..f1ca941cc2 100644 --- a/ts/core/MmlTree/MmlNodes/HtmlNode.ts +++ b/ts/core/MmlTree/MmlNodes/HtmlNode.ts @@ -24,6 +24,7 @@ import { XMLNode } from '../MmlNode.js'; import { DOMAdaptor } from '../../DOMAdaptor.js'; import { PropertyList } from '../../Tree/Node.js'; +import { DOM } from '../../../types/Types.js'; /******************************************************************/ /** @@ -49,12 +50,9 @@ export class HtmlNode extends XMLNode { /** * @param {N} html The HTML content to be saved * @param {DOMAdaptor} adaptor DOM adaptor for the content - * @returns {HtmlNode} The HTML node (for chaining of method calls) + * @returns {HtmlNode} The HTML node (for chaining of method calls) */ - public setHTML( - html: N, - adaptor: DOMAdaptor = null - ): HtmlNode { + public setHTML(html: N, adaptor: DOMAdaptor = null): HtmlNode { // // Test if the HTML element has attributes and wrap in a if not // diff --git a/ts/core/MmlTree/TestMmlVisitor.ts b/ts/core/MmlTree/TestMmlVisitor.ts index 0f64db12fb..2d713d12fa 100644 --- a/ts/core/MmlTree/TestMmlVisitor.ts +++ b/ts/core/MmlTree/TestMmlVisitor.ts @@ -17,7 +17,7 @@ /** * @file A visitor that produces a serilaied MathML string - * that contains addition information about inherited + * that contains additional information about inherited * attributes and internal properties. * (For testing purposes only.) * diff --git a/ts/core/OutputJax.ts b/ts/core/OutputJax.ts index 8d4b514eb2..ccf36a02a9 100644 --- a/ts/core/OutputJax.ts +++ b/ts/core/OutputJax.ts @@ -26,18 +26,16 @@ import { MathDocument } from './MathDocument.js'; import { MathItem } from './MathItem.js'; import { DOMAdaptor } from '../core/DOMAdaptor.js'; import { FunctionList } from '../util/FunctionList.js'; -import type { DOM, DOM_TYPES } from '../types/Types.js'; +import type { DOM, DOM_TYPES, N } from '../types/Types.js'; import type { FilterFunctions, FilterFunctionList } from './FilterFunctions.js'; /*****************************************************************/ /** * The OutputJax interface * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface OutputJax { +export interface OutputJax { /** * The name of this output jax class */ @@ -61,12 +59,12 @@ export interface OutputJax { /** * The DOM adaptor for managing HTML elements */ - adaptor: DOMAdaptor; + adaptor: DOMAdaptor; /** * @param {DOMAdaptor} adaptor The adaptor to use in this jax */ - setAdaptor(adaptor: DOMAdaptor): void; + setAdaptor(adaptor: DOMAdaptor): void; /** * Do any initialization that depends on the document being set up @@ -85,39 +83,39 @@ export interface OutputJax { * * @param {MathItem} math The MathItem to be typeset * @param {MathDocument} document The MathDocument in which the typesetting should occur - * @returns {N} The DOM tree for the typeset math + * @returns {N} The DOM tree for the typeset math */ - typeset(math: MathItem, document?: MathDocument): N; + typeset(math: MathItem, document?: MathDocument): N; /** * Handle an escaped character (e.g., \$ from the TeX input jax preventing it from being a delimiter) * * @param {MathItem} math The MathItem to be escaped * @param {MathDocument} document The MathDocument in which the math occurs - * @returns {N} The DOM tree for the escaped item + * @returns {N} The DOM tree for the escaped item */ - escaped(math: MathItem, document?: MathDocument): N; + escaped(math: MathItem, document?: MathDocument): N; /** * Get the metric information for all math in the given document * * @param {MathDocument} document The MathDocument being processed */ - getMetrics(document: MathDocument): void; + getMetrics(document: MathDocument): void; /** * Produce the stylesheet needed for this output jax * * @param {MathDocument} document The MathDocument being processed */ - styleSheet(document: MathDocument): N; + styleSheet(document: MathDocument): N; /** * Produce any page-specific elements needed for this output jax * * @param {MathDocument} document The MathDocument being processed */ - pageElements(document: MathDocument): N; + pageElements(document: MathDocument): N; } /** @@ -136,11 +134,11 @@ export type OUTPUTJAX_OPTIONS< /** * The OutputJax abstract class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export abstract class AbstractOutputJax implements OutputJax { +export abstract class AbstractOutputJax< + DOM extends DOM_TYPES, +> implements OutputJax { /** * The name for the output jax */ @@ -162,17 +160,17 @@ export abstract class AbstractOutputJax implements OutputJax { /** * Filters to run before the output is processed */ - public preFilters: FilterFunctions>; + public preFilters: FilterFunctions, DOM>; /** * Filters to run after the output is processed */ - public postFilters: FilterFunctions>; + public postFilters: FilterFunctions, DOM>; /** * The MathDocument's DOMAdaptor */ - public adaptor: DOMAdaptor = null; // set by the handler + public adaptor: DOMAdaptor = null; // set by the handler /** * @param {OptionList} options The options for this instance @@ -194,7 +192,7 @@ export abstract class AbstractOutputJax implements OutputJax { /** * @override */ - public setAdaptor(adaptor: DOMAdaptor) { + public setAdaptor(adaptor: DOMAdaptor) { this.adaptor = adaptor; } @@ -212,35 +210,35 @@ export abstract class AbstractOutputJax implements OutputJax { * @override */ public abstract typeset( - math: MathItem, - document?: MathDocument - ): N; + math: MathItem, + document?: MathDocument + ): N; /** * @override */ public abstract escaped( - math: MathItem, - document?: MathDocument - ): N; + math: MathItem, + document?: MathDocument + ): N; /** * @override */ - public getMetrics(_document: MathDocument) {} + public getMetrics(_document: MathDocument) {} /** * @override */ - public styleSheet(_document: MathDocument) { - return null as N; + public styleSheet(_document: MathDocument) { + return null as N; } /** * @override */ - public pageElements(_document: MathDocument) { - return null as N; + public pageElements(_document: MathDocument) { + return null as N; } /** @@ -251,12 +249,12 @@ export abstract class AbstractOutputJax implements OutputJax { * @param {MathItem} math The math item that is being processed * @param {MathDocument} document The math document contaiing the math item * @param {any} data Whatever other data is needed - * @returns {any} The (possibly modified) data + * @returns {any} The (possibly modified) data */ protected executeFilters( filters: FunctionList, - math: MathItem, - document: MathDocument, + math: MathItem, + document: MathDocument, data: any ): any { const args = { math, document, data }; diff --git a/ts/core/Tree/Factory.ts b/ts/core/Tree/Factory.ts index d69c20cdc2..6e04c31638 100644 --- a/ts/core/Tree/Factory.ts +++ b/ts/core/Tree/Factory.ts @@ -36,8 +36,8 @@ export interface FactoryNode { export interface FactoryNodeClass { /** * @param {Factory>} factory The factory for creating more nodes - * @param {any[]} args Any additional arguments needed by the node - * @returns {N} The newly created node + * @param {any[]} args Any additional arguments needed by the node + * @returns {N} The newly created node */ new (factory: Factory>, ...args: any[]): N; } @@ -59,7 +59,7 @@ export interface FactoryNodeClass { export interface Factory> { /** * @param {string} kind The kind of node to create - * @returns {N} The newly created node of the given kind + * @returns {N} The newly created node of the given kind */ create(kind: string): N; @@ -73,7 +73,7 @@ export interface Factory> { /** * @param {string} kind The kind of node whose class is to be returned - * @returns {C} The class object for the given kind + * @returns {C} The class object for the given kind */ getNodeClass(kind: string): C; @@ -83,14 +83,14 @@ export interface Factory> { deleteNodeClass(kind: string): void; /** - * @param {N} node The node to test if it is of a given kind - * @param {string} kind The kind to test for - * @returns {boolean} True if the node is of the given kind, false otherwise + * @param {N} node The node to test if it is of a given kind + * @param {string} kind The kind to test for + * @returns {boolean} True if the node is of the given kind, false otherwise */ nodeIsKind(node: N, kind: string): boolean; /** - * @returns {string[]} The names of all the available kinds of nodes + * @returns {string[]} The names of all the available kinds of nodes */ getKinds(): string[]; } diff --git a/ts/core/Tree/Node.ts b/ts/core/Tree/Node.ts index f61ae7fab2..4e5e9062f3 100644 --- a/ts/core/Tree/Node.ts +++ b/ts/core/Tree/Node.ts @@ -80,7 +80,7 @@ export interface Node, C extends NodeClass> { removeProperty(...names: string[]): void; /** - * @param {string} kind The type of node to test for + * @param {string} kind The type of node to test for * @returns {boolean} True when the node is of the given type */ isKind(kind: string): boolean; @@ -91,27 +91,27 @@ export interface Node, C extends NodeClass> { setChildren(children: N[]): void; /** - * @param {N} child A node to add to this node's children + * @param {N} child A node to add to this node's children * @returns {N} The child node that was added */ appendChild(child: N): N; /** - * @param {N} newChild A child node to be inserted - * @param {N} oldChild A child node to be replaced + * @param {N} newChild A child node to be inserted + * @param {N} oldChild A child node to be replaced * @returns {N} The old child node that was removed */ replaceChild(newChild: N, oldChild: N): N; /** * @param {N} child Child node to be removed - * @returns {N} The old child node that was removed + * @returns {N} The old child node that was removed */ removeChild(child: N): N; /** - * @param {N} child A child node whose index in childNodes is desired - * @returns {number} The index of the child in childNodes, or null if not found + * @param {N} child A child node whose index in childNodes is desired + * @returns {number} The index of the child in childNodes, or null if not found */ childIndex(child: N): number; @@ -121,8 +121,8 @@ export interface Node, C extends NodeClass> { copy(): N; /** - * @param {string} kind The kind of nodes to be located in the tree - * @returns {N[]} An array of nodes that are children (at any depth) of the given kind + * @param {string} kind The kind of nodes to be located in the tree + * @returns {N[]} An array of nodes that are children (at any depth) of the given kind */ findNodes(kind: string): N[]; @@ -143,10 +143,10 @@ export interface Node, C extends NodeClass> { */ export interface NodeClass, C extends NodeClass> { /** - * @param {NodeFactory} factory The NodeFactory to use to create new nodes when needed - * @param {PropertyList} properties Any properties to be added to the node, if any - * @param {N[]} children The initial child nodes, if any - * @returns {N} The newly created node + * @param {NodeFactory} factory The NodeFactory to use to create new nodes when needed + * @param {PropertyList} properties Any properties to be added to the node, if any + * @param {N[]} children The initial child nodes, if any + * @returns {N} The newly created node */ new ( factory: NodeFactory, diff --git a/ts/core/Tree/NodeFactory.ts b/ts/core/Tree/NodeFactory.ts index 034457f667..d0cafbf876 100644 --- a/ts/core/Tree/NodeFactory.ts +++ b/ts/core/Tree/NodeFactory.ts @@ -36,10 +36,10 @@ export interface NodeFactory< C extends FactoryNodeClass, > extends Factory { /** - * @param {string} kind The kind of node to create - * @param {PropertyList} properties The list of initial properties for the node (if any) - * @param {N[]} children The array of initial child nodes (if any) - * @returns {N} The newly created node of the given kind + * @param {string} kind The kind of node to create + * @param {PropertyList} properties The list of initial properties for the node (if any) + * @param {N[]} children The array of initial child nodes (if any) + * @returns {N} The newly created node of the given kind */ create(kind: string, properties?: PropertyList, children?: N[]): N; } diff --git a/ts/core/Tree/Visitor.ts b/ts/core/Tree/Visitor.ts index 82f550fcb9..fdc095406d 100644 --- a/ts/core/Tree/Visitor.ts +++ b/ts/core/Tree/Visitor.ts @@ -56,8 +56,8 @@ export interface Visitor> { /** * Visit the tree rooted at the given node (passing along any needed parameters) * - * @param {N} tree The node that is the root of the tree - * @param {any[]} args The arguments to pass to the visitNode functions + * @param {N} tree The node that is the root of the tree + * @param {any[]} args The arguments to pass to the visitNode functions * @returns {any} Whatever the visitNode function returns for the root tree node */ visitTree(tree: N, ...args: any[]): any; @@ -66,8 +66,8 @@ export interface Visitor> { * Visit a node by calling the visitor function for the given type of node * (passing along any needed parameters) * - * @param {N} node The node to visit - * @param {any[]} args The arguments to pass to the visitor function for this node + * @param {N} node The node to visit + * @param {any[]} args The arguments to pass to the visitor function for this node * @returns {any} Whatever the visitor function returns for this node */ visitNode(node: N, ...args: any[]): any; @@ -75,8 +75,8 @@ export interface Visitor> { /** * The default visitor function for when no node-specific function is defined * - * @param {N} node The node to visit - * @param {any[]} args The arguments to pass to the visitor function for this node + * @param {N} node The node to visit + * @param {any[]} args The arguments to pass to the visitor function for this node * @returns {any} Whatever the visitor function returns for this node */ visitDefault(node: N, ...args: any[]): any; @@ -121,8 +121,8 @@ export abstract class AbstractVisitor< * Visitor functions are named "visitKindNode" where "Kind" is replaced by * the node kind; e.g., visitTextNode for kind = text. * - * @param {string} kind The node kind whose method name is needed - * @returns {string} The name of the visitor method for the given node kind + * @param {string} kind The node kind whose method name is needed + * @returns {string} The name of the visitor method for the given node kind */ protected static methodName(kind: string): string { return ( diff --git a/ts/core/Tree/Wrapper.ts b/ts/core/Tree/Wrapper.ts index 9c5782b038..f9f3e18dd4 100644 --- a/ts/core/Tree/Wrapper.ts +++ b/ts/core/Tree/Wrapper.ts @@ -84,10 +84,10 @@ export interface WrapperClass< W extends Wrapper, > { /** - * @param {WrapperFactory} factory The factory used to create more wrappers - * @param {N} node The node to be wrapped - * @param {any[]} args Any additional arguments needed when creating the wrapper - * @returns {W} The wrapped node + * @param {WrapperFactory} factory The factory used to create more wrappers + * @param {N} node The node to be wrapped + * @param {any[]} args Any additional arguments needed when creating the wrapper + * @returns {W} The wrapped node */ new ( factory: WrapperFactory>, diff --git a/ts/core/Tree/WrapperFactory.ts b/ts/core/Tree/WrapperFactory.ts index ccb34fd220..8e69972706 100644 --- a/ts/core/Tree/WrapperFactory.ts +++ b/ts/core/Tree/WrapperFactory.ts @@ -45,7 +45,7 @@ export interface WrapperFactory< * * @param {N} node The node to be wrapped * @param {any[]} args Any additional arguments needed when wrapping the node - * @returns {TT} The newly wrapped node + * @returns {TT} The newly wrapped node */ wrap(node: N, ...args: any[]): TT; } diff --git a/ts/handlers/html.ts b/ts/handlers/html.ts index 8450354f6d..c6b8dc551d 100644 --- a/ts/handlers/html.ts +++ b/ts/handlers/html.ts @@ -24,21 +24,20 @@ import { mathjax } from '../mathjax.js'; import { HTMLHandler } from './html/HTMLHandler.js'; import { DOMAdaptor } from '../core/DOMAdaptor.js'; +import { DOM_TYPES } from '../types/Types.js'; /** * Create the HTML handler object and register it with MathJax. * - * @param {DOMAdaptor} adaptor The DOM adaptor to use with HTML - * @returns {HTMLHandler} The newly created handler + * @param {DOMAdaptor} adaptor The DOM adaptor to use with HTML + * @returns {HTMLHandler} The newly created handler * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export function RegisterHTMLHandler( - adaptor: DOMAdaptor -): HTMLHandler { - const handler = new HTMLHandler(adaptor); +export function RegisterHTMLHandler( + adaptor: DOMAdaptor +): HTMLHandler { + const handler = new HTMLHandler(adaptor); mathjax.handlers.register(handler); return handler; } diff --git a/ts/handlers/html/HTMLDocument.ts b/ts/handlers/html/HTMLDocument.ts index 73f393da37..38059d561f 100644 --- a/ts/handlers/html/HTMLDocument.ts +++ b/ts/handlers/html/HTMLDocument.ts @@ -39,7 +39,13 @@ import { DOMAdaptor } from '../../core/DOMAdaptor.js'; import { InputJax } from '../../core/InputJax.js'; import { STATE, newState, ProtoItem, Location } from '../../core/MathItem.js'; import { StyleJson } from '../../util/StyleJson.js'; -import { DOM, DOM_TYPES, N, T, D, Constructor } from '../../types/Types.js'; +import { + DOM as ANY_DOM, + DOM_TYPES, + N, + NT, + Constructor, +} from '../../types/Types.js'; /*****************************************************************/ /** @@ -49,10 +55,9 @@ import { DOM, DOM_TYPES, N, T, D, Constructor } from '../../types/Types.js'; * string in the list of strings to be searched for math * (multiple consecutive Text nodes can form a single string). * - * @template N The HTMLElement node class - * @template T The Text node class + * @template DOM The DOM node types */ -export type HTMLNodeArray = [N | T, number][][]; +export type HTMLNodeArray = [NT, number][][]; /** * Add STATE value for adding the stylesheets (after INSERTED) @@ -65,7 +70,7 @@ newState('STYLES', STATE.INSERTED + 1); * The new HTMLDocument option types. */ export type OPTIONS = { - DomStrings: HTMLDomStrings, T, D>; // The DomStrings parser + DomStrings: HTMLDomStrings; // The DomStrings parser }; /** @@ -73,13 +78,13 @@ export type OPTIONS = { */ export interface HTMLDOCUMENT_OPTIONS extends OPTIONS, DOCUMENT_OPTIONS { - MathItem: Constructor, T, D>>; + MathItem: Constructor>; } /** * The HTMLDocument option defaults. */ -const options: OPTIONS = { +const options: OPTIONS = { DomStrings: null, // Use the default DomString parser }; @@ -87,11 +92,11 @@ const options: OPTIONS = { /** * The HTMLDocument class (extends AbstractMathDocument) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class HTMLDocument extends AbstractMathDocument { +export class HTMLDocument< + DOM extends DOM_TYPES, +> extends AbstractMathDocument { /** * The kind of document */ @@ -103,7 +108,7 @@ export class HTMLDocument extends AbstractMathDocument { public static OPTIONS = { ...AbstractMathDocument.OPTIONS, ...options, - renderActions: expandable>({ + renderActions: expandable>({ ...AbstractMathDocument.OPTIONS.renderActions, styles: [STATE.STYLES, '', 'updateStyleSheet', false], // update styles on a rerender() call }), @@ -114,7 +119,7 @@ export class HTMLDocument extends AbstractMathDocument { /** * @override */ - public options: HTMLDOCUMENT_OPTIONS> & { elements?: N[] }; + public options: HTMLDOCUMENT_OPTIONS & { elements?: N[] }; /** * Extra styles to be included in the document's stylesheet (added by extensions) @@ -124,22 +129,17 @@ export class HTMLDocument extends AbstractMathDocument { /** * The DomString parser for locating the text in DOM trees */ - public domStrings: HTMLDomStrings; + public domStrings: HTMLDomStrings; /** * @override * @class * @augments {AbstractMathDocument} */ - constructor( - document: any, - adaptor: DOMAdaptor, - options: OptionList - ) { + constructor(document: any, adaptor: DOMAdaptor, options: OptionList) { const [html, dom] = separateOptions(options, HTMLDomStrings.OPTIONS); super(document, adaptor, html); - this.domStrings = - this.options.DomStrings || new HTMLDomStrings(dom); + this.domStrings = this.options.DomStrings || new HTMLDomStrings(dom); this.domStrings.adaptor = adaptor; this.styles = []; } @@ -159,8 +159,8 @@ export class HTMLDocument extends AbstractMathDocument { N: number, index: number, delim: string, - nodes: HTMLNodeArray - ): Location { + nodes: HTMLNodeArray + ): Location { const adaptor = this.adaptor; const inc = 1 / (nodes[N].length || 1); let i = N; @@ -184,10 +184,10 @@ export class HTMLDocument extends AbstractMathDocument { * @returns {HTMLMathItem} The MathItem for the given proto item */ protected mathItem( - item: ProtoItem, - jax: InputJax, - nodes: HTMLNodeArray - ): HTMLMathItem { + item: ProtoItem, + jax: InputJax, + nodes: HTMLNodeArray + ): HTMLMathItem { const math = item.math; const start = this.findPosition(item.n, item.start.n, item.open, nodes); const end = this.findPosition(item.n, item.end.n, item.close, nodes); @@ -197,7 +197,7 @@ export class HTMLDocument extends AbstractMathDocument { item.display, start, end - ) as HTMLMathItem; + ) as HTMLMathItem; } /** @@ -244,22 +244,22 @@ export class HTMLDocument extends AbstractMathDocument { /** * Get the MathItems from the containers by searching DOM strings * - * @param {InputJax} jax The jax being used - * @param {N[]} containers The containers to be searched in order - * @returns {HTMLMathList} The list of MathItems found + * @param {InputJax} jax The jax being used + * @param {N[]} containers The containers to be searched in order + * @returns {HTMLMathList} The list of MathItems found */ protected findMathFromStrings( - jax: InputJax, - containers: N[] - ): HTMLMathList { + jax: InputJax, + containers: N[] + ): HTMLMathList { const strings = [] as string[]; - const nodes = [] as HTMLNodeArray; + const nodes = [] as HTMLNodeArray; for (const container of containers) { const [slist, nlist] = this.domStrings.find(container); strings.push(...slist); nodes.push(...nlist); } - const list = new this.options.MathList() as HTMLMathList; + const list = new this.options.MathList() as HTMLMathList; for (const math of jax.findMath(strings)) { list.push(this.mathItem(math, jax, nodes)); } @@ -269,15 +269,15 @@ export class HTMLDocument extends AbstractMathDocument { /** * Get the MathItems from the containers by searching DOM elements themselves * - * @param {InputJax} jax The jax being used - * @param {N[]} containers The containers to be searched in order - * @returns {HTMLMathList} The list of MathItems found + * @param {InputJax} jax The jax being used + * @param {N[]} containers The containers to be searched in order + * @returns {HTMLMathList} The list of MathItems found */ protected findMathFromDOM( - jax: InputJax, - containers: N[] - ): HTMLMathList { - const items = [] as HTMLMathItem[]; + jax: InputJax, + containers: N[] + ): HTMLMathList { + const items = [] as HTMLMathItem[]; for (const container of containers) { for (const math of jax.findMath(container)) { items.push( @@ -291,7 +291,7 @@ export class HTMLDocument extends AbstractMathDocument { ); } } - return new this.options.MathList(...items) as HTMLMathList; + return new this.options.MathList(...items) as HTMLMathList; } /** @@ -346,7 +346,7 @@ export class HTMLDocument extends AbstractMathDocument { * @param {string} id The id of the stylesheet to find * @returns {N|null} The stylesheet with the given ID */ - protected findSheet(head: N, id: string): N { + protected findSheet(head: N, id: string): N { if (id) { for (const sheet of this.adaptor.tags(head, 'style')) { if (this.adaptor.getAttribute(sheet, 'id') === id) { @@ -354,7 +354,7 @@ export class HTMLDocument extends AbstractMathDocument { } } } - return null as N; + return null as N; } /** diff --git a/ts/handlers/html/HTMLDomStrings.ts b/ts/handlers/html/HTMLDomStrings.ts index 13c742bbe8..33ea610e0f 100644 --- a/ts/handlers/html/HTMLDomStrings.ts +++ b/ts/handlers/html/HTMLDomStrings.ts @@ -29,26 +29,21 @@ import { expandable, } from '../../util/Options.js'; import { DOMAdaptor } from '../../core/DOMAdaptor.js'; -import { DOM, DOM_TYPES, N, T, D } from '../../types/Types.js'; - +import { DOM, DOM_TYPES, N, T, NT } from '../../types/Types.js'; /** * List of consecutive text nodes and their text lengths * - * @template N The HTMLElement node class - * @template T The Text node class + * @template DOM The DOM node types */ -export type HTMLNodeList = [N | T, number][]; +export type HTMLNodeList = [NT, number][]; /** * The data for HTML to be allowed in TeX expressions * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document node class + * @template DOM The DOM node types */ -export type HTMLTagData = - | string - | ((node: N, adaptor: DOMAdaptor) => string); +export type HTMLTagData = + string | ((node: N, adaptor: DOMAdaptor) => string); /*****************************************************************/ @@ -62,26 +57,36 @@ export type HTMLDOMSTRINGS_OPTIONS = { // Tags to be included in the text (and what text to replace them // with). // - includeHtmlTags: {[tag: string]: HTMLTagData, T, D>}; + includeHtmlTags: { [tag: string]: HTMLTagData }; // // The class name of elements whose contents should NOT be processed // by tex2jax. Note that this is used as a regular expression, so // be sure to quote any regexp special characters. // - ignoreHtmlClass: string, + ignoreHtmlClass: string; // // The class name of elements whose contents SHOULD be processed // when they appear inside ones that are ignored. Note that this is // used as a regular expression, so be sure to quote any regexp // special characters. // - processHtmlClass: string, + processHtmlClass: string; }; const options: HTMLDOMSTRINGS_OPTIONS = { - skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code', - 'math', 'select', 'option', 'mjx-container'], - includeHtmlTags: expandable({br: '\n', wbr: '', '#comment': ''}), + skipHtmlTags: [ + 'script', + 'noscript', + 'style', + 'textarea', + 'pre', + 'code', + 'math', + 'select', + 'option', + 'mjx-container', + ], + includeHtmlTags: expandable({ br: '\n', wbr: '', '#comment': '' }), ignoreHtmlClass: 'mathjax_ignore', processHtmlClass: 'mathjax_process', }; @@ -92,11 +97,9 @@ const options: HTMLDOMSTRINGS_OPTIONS = { * * A class for extracting the text from DOM trees * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class HTMLDomStrings { +export class HTMLDomStrings { /** * The default options for string processing */ @@ -120,18 +123,18 @@ export class HTMLDomStrings { /** * The list of nodes and lengths for the string being constructed */ - protected snodes: HTMLNodeList; + protected snodes: HTMLNodeList; /** * The list of node lists corresponding to the strings in this.strings */ - protected nodes: HTMLNodeList[]; + protected nodes: HTMLNodeList[]; /** * The container nodes that are currently being traversed, and whether their * contents are being ignored or not */ - protected stack: [N | T, boolean][]; + protected stack: [NT, boolean][]; /** * Regular expression for the tags to be skipped @@ -150,11 +153,10 @@ export class HTMLDomStrings { /** * The DOM Adaptor to managing HTML elements */ - public adaptor: DOMAdaptor; + public adaptor: DOMAdaptor; /** * @param {OptionList} options The user-supplied options - * @class */ constructor(options: OptionList = null) { const CLASS = this.constructor as typeof HTMLDomStrings; @@ -204,12 +206,12 @@ export class HTMLDomStrings { * Add more text to the current string, and record the * node and its position in the string. * - * @param {N|T} node The node to be pushed + * @param {N|T} node The node to be pushed * @param {string} text The text to be added (it may not be the actual text * of the node, if it is one of the nodes that gets * translated to text, like
to a newline). */ - protected extendString(node: N | T, text: string) { + protected extendString(node: NT, text: string) { this.snodes.push([node, text.length]); this.string += text; } @@ -217,11 +219,11 @@ export class HTMLDomStrings { /** * Handle a #text node (add its text to the current string) * - * @param {T} node The Text node to process - * @param {boolean} ignore Whether we are currently ignoring content - * @returns {N | T} The next element to process + * @param {T} node The Text node to process + * @param {boolean} ignore Whether we are currently ignoring content + * @returns {NT} The next element to process */ - protected handleText(node: T, ignore: boolean): N | T { + protected handleText(node: T, ignore: boolean): NT { if (!ignore) { this.extendString(node, this.adaptor.value(node)); } @@ -231,11 +233,11 @@ export class HTMLDomStrings { /** * Handle a BR, WBR, or #comment element (or others in the includeHtmlTags object). * - * @param {N} node The node to process - * @param {boolean} ignore Whether we are currently ignoring content - * @returns {N | T} The next element to process + * @param {N} node The node to process + * @param {boolean} ignore Whether we are currently ignoring content + * @returns {NT} The next element to process */ - protected handleTag(node: N, ignore: boolean): N | T { + protected handleTag(node: N, ignore: boolean): NT { if (!ignore) { const text = this.options['includeHtmlTags'][this.adaptor.kind(node)]; if (text instanceof Function) { @@ -261,9 +263,9 @@ export class HTMLDomStrings { * * @param {N} node The node to process * @param {boolean} ignore Whether we are currently ignoring content - * @returns {[N|T, boolean]} The next element to process and whether to ignore its content + * @returns {[N|T, boolean]} The next element to process and whether to ignore its content */ - protected handleContainer(node: N, ignore: boolean): [N | T, boolean] { + protected handleContainer(node: N, ignore: boolean): [NT, boolean] { this.pushString(); const cname = this.adaptor.getAttribute(node, 'class') || ''; const tname = this.adaptor.kind(node) || ''; @@ -290,9 +292,9 @@ export class HTMLDomStrings { * * @param {N} node The node to process * @param {boolean} _ignore Whether we are currently ignoring content - * @returns {N|T} The next element to process + * @returns {N|T} The next element to process */ - protected handleOther(node: N, _ignore: boolean): N | T { + protected handleOther(node: N, _ignore: boolean): NT { this.pushString(); return this.adaptor.next(node); } @@ -312,10 +314,10 @@ export class HTMLDomStrings { * Clear the internal values (so the memory can be freed) * Return the strings and node lists * - * @param {N} node The node to search + * @param {N|T} node The node to search * @returns {[string[], HTMLNodeList[]]} The array of strings and their associated lists of nodes */ - public find(node: N | T): [string[], HTMLNodeList[]] { + public find(node: NT): [string[], HTMLNodeList[]] { this.init(); const stop = this.adaptor.next(node); let ignore = false; @@ -324,13 +326,13 @@ export class HTMLDomStrings { while (node && node !== stop) { const kind = this.adaptor.kind(node); if (kind === '#text') { - node = this.handleText(node as T, ignore); + node = this.handleText(node as T, ignore); } else if (Object.hasOwn(include, kind)) { - node = this.handleTag(node as N, ignore); + node = this.handleTag(node as N, ignore); } else if (kind) { - [node, ignore] = this.handleContainer(node as N, ignore); + [node, ignore] = this.handleContainer(node as N, ignore); } else { - node = this.handleOther(node as N, ignore); + node = this.handleOther(node as N, ignore); } if (!node && this.stack.length) { this.pushString(); @@ -341,7 +343,7 @@ export class HTMLDomStrings { this.pushString(); const result = [this.strings, this.nodes] as [ string[], - HTMLNodeList[], + HTMLNodeList[], ]; this.init(); // free up memory return result; diff --git a/ts/handlers/html/HTMLHandler.ts b/ts/handlers/html/HTMLHandler.ts index cee632875d..8671e0bf8f 100644 --- a/ts/handlers/html/HTMLHandler.ts +++ b/ts/handlers/html/HTMLHandler.ts @@ -24,26 +24,29 @@ import { AbstractHandler } from '../../core/Handler.js'; import { MinHTMLAdaptor } from '../../adaptors/HTMLAdaptor.js'; import { HTMLDocument } from './HTMLDocument.js'; +import { MathDocumentConstructor } from '../../core/MathDocument.js'; import { OptionList } from '../../util/Options.js'; +import { DOM_TYPES, N } from '../../types/Types.js'; /*****************************************************************/ /** * Implements the HTMLHandler class (extends AbstractHandler) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class HTMLHandler extends AbstractHandler { +export class HTMLHandler extends AbstractHandler { /** * The DOMAdaptor for the document being handled */ - public adaptor: MinHTMLAdaptor; // declare a more specific adaptor type + public adaptor: MinHTMLAdaptor; // declare a more specific adaptor type /** * @override */ - public documentClass = HTMLDocument; + public documentClass = HTMLDocument as any as MathDocumentConstructor< + HTMLDocument, + DOM + >; /** * @override @@ -81,10 +84,10 @@ export class HTMLHandler extends AbstractHandler { document instanceof adaptor.window.HTMLElement || document instanceof adaptor.window.DocumentFragment ) { - const child = document as N; + const child = document as N; document = adaptor.parse('', 'text/html'); adaptor.append(adaptor.body(document), child); } - return super.create(document, options) as HTMLDocument; + return super.create(document, options) as HTMLDocument; } } diff --git a/ts/handlers/html/HTMLMathItem.ts b/ts/handlers/html/HTMLMathItem.ts index 2c383b2fd1..d7cfe144a7 100644 --- a/ts/handlers/html/HTMLMathItem.ts +++ b/ts/handlers/html/HTMLMathItem.ts @@ -25,20 +25,19 @@ import { AbstractMathItem, Location, STATE } from '../../core/MathItem.js'; import { DOMAdaptor } from '../../core/DOMAdaptor.js'; import { InputJax } from '../../core/InputJax.js'; import { HTMLDocument } from './HTMLDocument.js'; +import { DOM_TYPES, NT, T } from '../../types/Types.js'; /*****************************************************************/ /** * Implements the HTMLMathItem class (extends AbstractMathItem) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM the DOM node types */ -export class HTMLMathItem extends AbstractMathItem { +export class HTMLMathItem extends AbstractMathItem { /** - * @returns {DOMAdaptor} Easy access to DOM adaptor + * @returns {DOMAdaptor} Easy access to DOM adaptor */ - get adaptor(): DOMAdaptor { + get adaptor(): DOMAdaptor { return this.inputJax.adaptor; } @@ -47,10 +46,10 @@ export class HTMLMathItem extends AbstractMathItem { */ constructor( math: string, - jax: InputJax, + jax: InputJax, display: boolean = true, - start: Location = { node: null, n: 0, delim: '' }, - end: Location = { node: null, n: 0, delim: '' } + start: Location = { node: null, n: 0, delim: '' }, + end: Location = { node: null, n: 0, delim: '' } ) { super(math, jax, display, start, end); } @@ -69,10 +68,10 @@ export class HTMLMathItem extends AbstractMathItem { * * @override */ - public updateDocument(_html: HTMLDocument) { + public updateDocument(_html: HTMLDocument) { if (this.state() < STATE.INSERTED) { if (this.inputJax.processStrings) { - let node = this.start.node as T; + let node = this.start.node as T; if (node === this.end.node) { if ( this.end.n && @@ -81,7 +80,7 @@ export class HTMLMathItem extends AbstractMathItem { this.adaptor.split(this.end.node, this.end.n); } if (this.start.n) { - node = this.adaptor.split(this.start.node as T, this.start.n); + node = this.adaptor.split(this.start.node as T, this.start.n); } if (this.adaptor.parent(node)) { this.adaptor.replace(this.typesetRoot, node); @@ -91,7 +90,7 @@ export class HTMLMathItem extends AbstractMathItem { node = this.adaptor.split(node, this.start.n); } while (node !== this.end.node) { - const next = this.adaptor.next(node) as T; + const next = this.adaptor.next(node) as T; this.adaptor.remove(node); node = next; } @@ -115,7 +114,7 @@ export class HTMLMathItem extends AbstractMathItem { * * @param {HTMLDocument} document The document whose styles are to be updated */ - public updateStyleSheet(document: HTMLDocument) { + public updateStyleSheet(document: HTMLDocument) { document.addStyleSheet(); } @@ -130,7 +129,7 @@ export class HTMLMathItem extends AbstractMathItem { if (this.state() >= STATE.TYPESET) { const adaptor = this.adaptor; const node = this.start.node; - let math: N | T = adaptor.text(''); + let math: NT = adaptor.text(''); if (restore) { const text = this.start.delim + this.math + this.end.delim; if (this.inputJax.processStrings) { diff --git a/ts/handlers/html/HTMLMathList.ts b/ts/handlers/html/HTMLMathList.ts index b9948d52b8..ce86a8437f 100644 --- a/ts/handlers/html/HTMLMathList.ts +++ b/ts/handlers/html/HTMLMathList.ts @@ -22,13 +22,14 @@ */ import { AbstractMathList } from '../../core/MathList.js'; +import { DOM_TYPES } from '../../types/Types.js'; /*****************************************************************/ /** * Implement the HTMLMathList class (extends AbstractMathList) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class HTMLMathList extends AbstractMathList {} +export class HTMLMathList< + DOM extends DOM_TYPES, +> extends AbstractMathList {} diff --git a/ts/input/asciimath.ts b/ts/input/asciimath.ts index c610c010c1..2055b4659f 100644 --- a/ts/input/asciimath.ts +++ b/ts/input/asciimath.ts @@ -26,7 +26,7 @@ import { LegacyAsciiMath } from './asciimath/legacy.js'; import { separateOptions, OptionList } from '../util/Options.js'; import { MathDocument } from '../core/MathDocument.js'; import { MathItem } from '../core/MathItem.js'; -import { DOM, DOM_TYPES, N, T, D } from '../types/Types.js'; +import { DOM, DOM_TYPES } from '../types/Types.js'; import { FindAsciiMath } from './asciimath/FindAsciiMath.js'; @@ -38,7 +38,7 @@ import { FindAsciiMath } from './asciimath/FindAsciiMath.js'; export interface ASCIIMATH_OPTIONS< DOM extends DOM_TYPES, > extends INPUTJAX_OPTIONS { - FindAsciiMath: FindAsciiMath, T, D>; + FindAsciiMath: FindAsciiMath; } /** @@ -53,11 +53,9 @@ const options: ASCIIMATH_OPTIONS = { /** * Implements the AsciiMath class (extends AbstractInputJax) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class AsciiMath extends AbstractInputJax { +export class AsciiMath extends AbstractInputJax { /** * The name of the input jax */ @@ -71,7 +69,7 @@ export class AsciiMath extends AbstractInputJax { /** * The FindMath object used to search for AsciiMath in the document */ - protected findAsciiMath: FindAsciiMath; + protected findAsciiMath: FindAsciiMath; /** * @override @@ -91,7 +89,7 @@ export class AsciiMath extends AbstractInputJax { * * @override */ - public compile(math: MathItem, _document: MathDocument) { + public compile(math: MathItem, _document: MathDocument) { return LegacyAsciiMath.Compile(math.math, math.display); } diff --git a/ts/input/asciimath/FindAsciiMath.ts b/ts/input/asciimath/FindAsciiMath.ts index 96afa521a2..bea704751e 100644 --- a/ts/input/asciimath/FindAsciiMath.ts +++ b/ts/input/asciimath/FindAsciiMath.ts @@ -25,6 +25,7 @@ import { AbstractFindMath } from '../../core/FindMath.js'; import { OptionList } from '../../util/Options.js'; import { quotePattern } from '../../util/string.js'; import { ProtoItem, protoItem } from '../../core/MathItem.js'; +import { DOM_TYPES } from '../../types/Types.js'; /** * Shorthand types for data about end delimiters and delimiter pairs @@ -54,11 +55,11 @@ const options: FINDASCIIMATH_OPTIONS = { * * Locates AsciiMath expressions within strings * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class FindAsciiMath extends AbstractFindMath { +export class FindAsciiMath< + DOM extends DOM_TYPES, +> extends AbstractFindMath { /** * @override */ @@ -129,13 +130,13 @@ export class FindAsciiMath extends AbstractFindMath { n: number, start: RegExpExecArray, end: EndItem - ): ProtoItem { + ): ProtoItem { const [, display, pattern] = end; const i = (pattern.lastIndex = start.index + start[0].length); const match = pattern.exec(text); return !match ? null - : protoItem( + : protoItem( start[0], match.index < i ? '' : text.substring(i, match.index), match[0], @@ -153,7 +154,7 @@ export class FindAsciiMath extends AbstractFindMath { * @param {number} n The index of the string being searched * @param {string} text The string being searched */ - protected findMathInString(math: ProtoItem[], n: number, text: string) { + protected findMathInString(math: ProtoItem[], n: number, text: string) { let start, match; this.start.lastIndex = 0; while ((start = this.start.exec(text))) { @@ -171,7 +172,7 @@ export class FindAsciiMath extends AbstractFindMath { * @override */ public findMath(strings: string[]) { - const math: ProtoItem[] = []; + const math: ProtoItem[] = []; if (this.hasPatterns) { for (let i = 0, m = strings.length; i < m; i++) { this.findMathInString(math, i, strings[i]); diff --git a/ts/input/mathml.ts b/ts/input/mathml.ts index d1ab25d50e..f57f41dea1 100644 --- a/ts/input/mathml.ts +++ b/ts/input/mathml.ts @@ -29,7 +29,7 @@ import { MathItem } from '../core/MathItem.js'; import { DOMAdaptor } from '../core/DOMAdaptor.js'; import { MmlFactory } from '../core/MmlTree/MmlFactory.js'; import { MmlNode } from '../core/MmlTree/MmlNode.js'; -import { DOM, DOM_TYPES, N, T, D } from '../types/Types.js'; +import { DOM, DOM_TYPES, N, D, NT } from '../types/Types.js'; import { FilterFunctions, FilterFunctionList, @@ -51,9 +51,9 @@ export interface MATHML_OPTIONS extends INPUTJAX_OPTIONS< > { parseAs: 'html' | 'xml'; forceReparse: boolean; - mmlFilters: FilterFunctionList | T, DOM>; - FindMathML: FindMathML, T, D>; - MathMLCompile: MathMLCompile, T, D>; + mmlFilters: FilterFunctionList, DOM>; + FindMathML: FindMathML; + MathMLCompile: MathMLCompile; parseError: (node: Node) => void; } @@ -76,14 +76,10 @@ const options: MATHML_OPTIONS = { /** * Implements the MathML class (extends AbstractInputJax) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class MathML extends AbstractInputJax< - N, - T, - D, +export class MathML extends AbstractInputJax< + DOM, string, MmlNode > { @@ -100,22 +96,22 @@ export class MathML extends AbstractInputJax< /** * The FindMathML instance used to locate MathML in the document */ - protected findMathML: FindMathML; + protected findMathML: FindMathML; /** * The MathMLCompile instance used to convert the MathML tree to internal format */ - protected mathml: MathMLCompile; + protected mathml: MathMLCompile; /** * A list of functions to call on the parsed MathML DOM before conversion to internal structure */ - public mmlFilters: FilterFunctions>; + public mmlFilters: FilterFunctions, DOM>; /** * @override */ - public options: MATHML_OPTIONS>; + public options: MATHML_OPTIONS; /** * @override @@ -127,9 +123,8 @@ export class MathML extends AbstractInputJax< MathMLCompile.OPTIONS ); super(mml); - this.findMathML = this.options.FindMathML || new FindMathML(find); - this.mathml = - this.options.MathMLCompile || new MathMLCompile(compile); + this.findMathML = this.options.FindMathML || new FindMathML(find); + this.mathml = this.options.MathMLCompile || new MathMLCompile(compile); this.mmlFilters = new FunctionList(this.options.mmlFilters); } @@ -138,7 +133,7 @@ export class MathML extends AbstractInputJax< * * @override */ - public setAdaptor(adaptor: DOMAdaptor) { + public setAdaptor(adaptor: DOMAdaptor) { super.setAdaptor(adaptor); this.findMathML.adaptor = adaptor; this.mathml.adaptor = adaptor; @@ -177,7 +172,7 @@ export class MathML extends AbstractInputJax< * * @override */ - public compile(math: MathItem, document: MathDocument) { + public compile(math: MathItem, document: MathDocument) { let mml = math.start.node; if ( !mml || @@ -201,15 +196,15 @@ export class MathML extends AbstractInputJax< if (this.adaptor.childNodes(body).length !== 1) { this.error(localize('SingleNode')); } - mml = this.adaptor.remove(this.adaptor.firstChild(body)) as N; + mml = this.adaptor.remove(this.adaptor.firstChild(body)) as N; if (this.adaptor.kind(mml).replace(/^[a-z]+:/, '') !== 'math') { this.error( localize('MathNode', '', `<${this.adaptor.kind(mml)}>`) ); } } - mml = this.executeFilters(this.mmlFilters, math, document, mml); - let root = this.mathml.compile(mml as N); + mml = this.executeFilters>(this.mmlFilters, math, document, mml); + let root = this.mathml.compile(mml as N); root = this.executeFilters(this.postFilters, math, document, root); math.display = root.attributes.get('display') === 'block'; return root; @@ -221,7 +216,7 @@ export class MathML extends AbstractInputJax< * @param {D} doc The document returns from the DOMParser * @returns {D} The document */ - protected checkForErrors(doc: D): D { + protected checkForErrors(doc: D): D { const err = this.adaptor.tags(this.adaptor.body(doc), 'parsererror')[0]; if (err) { if (this.adaptor.textContent(err) === '') { @@ -244,7 +239,7 @@ export class MathML extends AbstractInputJax< /** * @override */ - public findMath(node: N) { + public findMath(node: N) { return this.findMathML.findMath(node); } } diff --git a/ts/input/mathml/FindMathML.ts b/ts/input/mathml/FindMathML.ts index a31c2635db..579c950710 100644 --- a/ts/input/mathml/FindMathML.ts +++ b/ts/input/mathml/FindMathML.ts @@ -25,6 +25,7 @@ import { AbstractFindMath } from '../../core/FindMath.js'; import { DOMAdaptor } from '../../core/DOMAdaptor.js'; import { OptionList } from '../../util/Options.js'; import { ProtoItem } from '../../core/MathItem.js'; +import { DOM_TYPES, N } from '../../types/Types.js'; /** * The MathML namespace @@ -35,11 +36,9 @@ const NAMESPACE = 'http://www.w3.org/1998/Math/MathML'; /** * Implements the FindMathML object (extends AbstractFindMath) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class FindMathML extends AbstractFindMath { +export class FindMathML extends AbstractFindMath { /** * @override */ @@ -48,7 +47,7 @@ export class FindMathML extends AbstractFindMath { /** * The DOMAdaptor for the document being processed */ - public adaptor: DOMAdaptor; + public adaptor: DOMAdaptor; /** * Locates math nodes, possibly with namespace prefixes. @@ -57,8 +56,8 @@ export class FindMathML extends AbstractFindMath { * * @override */ - public findMath(node: N) { - const set = new Set(); + public findMath(node: N) { + const set = new Set>(); this.findMathNodes(node, set); this.findMathPrefixed(node, set); const html = this.adaptor.root(this.adaptor.document); @@ -74,7 +73,7 @@ export class FindMathML extends AbstractFindMath { * @param {N} node The container to seaerch for math * @param {Set} set The set in which to store the math nodes */ - protected findMathNodes(node: N, set: Set) { + protected findMathNodes(node: N, set: Set>) { for (const math of this.adaptor.tags(node, 'math')) { set.add(math); } @@ -83,10 +82,10 @@ export class FindMathML extends AbstractFindMath { /** * Find tags (or whatever prefixes there are) * - * @param {N} node The container to seaerch for math - * @param {Set} set The set in which to store the math nodes + * @param {N} node The container to seaerch for math + * @param {Set} set The set in which to store the math nodes */ - protected findMathPrefixed(node: N, set: Set) { + protected findMathPrefixed(node: N, set: Set>) { const html = this.adaptor.root(this.adaptor.document); for (const attr of this.adaptor.allAttributes(html)) { if (attr.name.substring(0, 6) === 'xmlns:' && attr.value === NAMESPACE) { @@ -101,10 +100,10 @@ export class FindMathML extends AbstractFindMath { /** * Find namespaced math in XHTML documents (is this really needed?) * - * @param {N} node The container to search for math - * @param {Set} set The set in which to store the math nodes + * @param {N} node The container to search for math + * @param {Set} set The set in which to store the math nodes */ - protected findMathNS(node: N, set: Set) { + protected findMathNS(node: N, set: Set>) { for (const math of this.adaptor.tags(node, 'math', NAMESPACE)) { set.add(math); } @@ -113,12 +112,12 @@ export class FindMathML extends AbstractFindMath { /** * Produce the array of proto math items from the node set * - * @param {Set} set The original node set - * @returns {ProtoItem[]} The set of proto math items + * @param {Set} set The original node set + * @returns {ProtoItem[]} The set of proto math items */ - protected processMath(set: Set): ProtoItem[] { + protected processMath(set: Set>): ProtoItem[] { const adaptor = this.adaptor; - const math: ProtoItem[] = []; + const math: ProtoItem[] = []; for (const mml of set.values()) { if (adaptor.kind(adaptor.parent(mml)) === 'mjx-assistive-mml') continue; const display = diff --git a/ts/input/mathml/MathMLCompile.ts b/ts/input/mathml/MathMLCompile.ts index a525c7a6a1..3296588250 100644 --- a/ts/input/mathml/MathMLCompile.ts +++ b/ts/input/mathml/MathMLCompile.ts @@ -36,6 +36,7 @@ import * as Entities from '../../util/Entities.js'; import { DOMAdaptor } from '../../core/DOMAdaptor.js'; import { Locale } from '../../util/Locale.js'; import { COMPONENT } from './__locales__/Component.js'; +import { DOM_TYPES, N } from '../../types/Types.js'; /********************************************************************/ @@ -49,7 +50,7 @@ export type MATHMLCOMPILE_OPTIONS = { allowHtmlInTokenNodes: boolean; // True if HTML is allowed in token nodes fixMisplacedChildren: boolean; // True if we want to use heuristics to try to fix // problems with the tree based on HTML not handling - // self-closing tags properly + // self-closing tags properly verify: VERIFY_OPTIONS; // Options to pass to verifyTree() controlling MathML verification translateEntities: boolean; // True means translate entities in text nodes }; @@ -72,11 +73,9 @@ const options: MATHMLCOMPILE_OPTIONS = { * The class for performing the MathML DOM node to * internal MmlNode conversion. * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class MathMLCompile { +export class MathMLCompile { /** * The default options for this object */ @@ -85,7 +84,7 @@ export class MathMLCompile { /** * The DOMAdaptor for the document being processed */ - public adaptor: DOMAdaptor; + public adaptor: DOMAdaptor; /** * The instance of the MmlFactory object and @@ -117,10 +116,10 @@ export class MathMLCompile { /** * Convert a MathML DOM tree to internal MmlNodes * - * @param {N} node The node to convert to MmlNodes + * @param {N} node The node to convert to MmlNodes * @returns {MmlNode} The MmlNode at the root of the converted tree */ - public compile(node: N): MmlNode { + public compile(node: N): MmlNode { const mml = this.makeNode(node); mml.verifyTree(this.options['verify']); mml.setInheritedAttributes({}, false, 0, false); @@ -134,10 +133,10 @@ export class MathMLCompile { * * FIXME: we should use data-* attributes rather than classes for these * - * @param {N} node The node to convert to an MmlNode + * @param {N} node The node to convert to an MmlNode * @returns {MmlNode} The converted MmlNode */ - public makeNode(node: N): MmlNode { + public makeNode(node: N): MmlNode { const adaptor = this.adaptor; let limits = false; const kind = adaptor.kind(node).replace(/^.*:/, ''); @@ -163,15 +162,15 @@ export class MathMLCompile { /** * Create an actual MmlNode tree from a given DOM node. * - * @param {string} type The type of MmlNode to create - * @param {N} node The original DOM node that is being transcribed - * @param {string} texClass The texClass specified on the node, if any - * @param {boolean} limits True if fixed limits are to be used + * @param {string} type The type of MmlNode to create + * @param {N} node The original DOM node that is being transcribed + * @param {string} texClass The texClass specified on the node, if any + * @param {boolean} limits True if fixed limits are to be used * @returns {MmlNode} The final MmlNode tree */ protected createMml( type: string, - node: N, + node: N, texClass: string, limits: boolean ): MmlNode { @@ -195,14 +194,14 @@ export class MathMLCompile { * * @param {string} type The type of node being requested * @param {N} node The HTML node used to create it. - * @returns {MmlNode} The HtmlNode holding the node (or null) + * @returns {MmlNode} The HtmlNode holding the node (or null) */ - protected unknownNode(type: string, node: N): MmlNode { + protected unknownNode(type: string, node: N): MmlNode { if ( this.factory.getNodeClass('html') && this.options.allowHtmlInTokenNodes ) { - return (this.factory.create('html') as HtmlNode).setHTML( + return (this.factory.create('html') as HtmlNode>).setHTML( node, this.adaptor ); @@ -215,9 +214,9 @@ export class MathMLCompile { * Copy the attributes from a MathML node to an MmlNode. * * @param {MmlNode} mml The MmlNode to which attributes will be added - * @param {N} node The MathML node whose attributes to copy + * @param {N} node The MathML node whose attributes to copy */ - protected addAttributes(mml: MmlNode, node: N) { + protected addAttributes(mml: MmlNode, node: N) { let ignoreVariant = false; for (const attr of this.adaptor.allAttributes(node)) { const name = attr.name; @@ -269,9 +268,9 @@ export class MathMLCompile { /** * Provide a hook for the Safe extension to filter attribute values. * - * @param {string} _name The name of an attribute to filter - * @param {string} value The value to filter - * @returns {string} The filtered value. + * @param {string} _name The name of an attribute to filter + * @param {string} value The value to filter + * @returns {string} The filtered value. */ protected filterAttribute(_name: string, value: string): string { return value; @@ -293,12 +292,12 @@ export class MathMLCompile { * @param {MmlNode} mml The MmlNode to which children will be added * @param {N} node The MathML node whose children are to be copied */ - protected addChildren(mml: MmlNode, node: N) { + protected addChildren(mml: MmlNode, node: N) { if (mml.arity === 0) { return; } const adaptor = this.adaptor; - for (const child of adaptor.childNodes(node) as N[]) { + for (const child of adaptor.childNodes(node) as N[]) { const name = adaptor.kind(child); if (name === '#comment') { continue; @@ -340,7 +339,7 @@ export class MathMLCompile { * @param {MmlNode} mml The MmlNode to which text will be added * @param {N} child The text node whose contents is to be copied */ - protected addText(mml: MmlNode, child: N) { + protected addText(mml: MmlNode, child: N) { let text = this.adaptor.value(child); if ((mml.isToken || mml.getProperty('isChars')) && mml.arity) { if (mml.isToken) { @@ -357,9 +356,9 @@ export class MathMLCompile { * Check for special MJX values in the class and process them * * @param {MmlNode} mml The MmlNode to be modified according to the class markers - * @param {N} node The MathML node whose class is to be processed + * @param {N} node The MathML node whose class is to be processed */ - protected checkClass(mml: MmlNode, node: N) { + protected checkClass(mml: MmlNode, node: N) { const classList = []; for (const name of this.filterClassList(this.adaptor.allClasses(node))) { if (name.substring(0, 4) === 'MJX-') { @@ -383,7 +382,7 @@ export class MathMLCompile { /** * Fix the old incorrect spelling of calligraphic. * - * @param {string} variant The mathvariant name + * @param {string} variant The mathvariant name * @returns {string} The corrected variant */ protected fixCalligraphic(variant: string): string { @@ -393,7 +392,7 @@ export class MathMLCompile { /** * Check to see if an mrow has delimiters at both ends (so looks like an mfenced structure). * - * @param {MmlNode} mml The node to check for mfenced structure + * @param {MmlNode} mml The node to check for mfenced structure */ protected markMrows(mml: MmlNode) { if (mml.isKind('mrow') && !mml.isInferred && mml.childNodes.length >= 2) { @@ -418,7 +417,7 @@ export class MathMLCompile { } /** - * @param {string} text The text to have spacing normalized + * @param {string} text The text to have spacing normalized * @returns {string} The trimmed text */ protected normalizeSpace(text: string): string { @@ -442,8 +441,8 @@ export class MathMLCompile { } } /** - * @param {string} message The error message to produce - * @param {string[]} args The substitution arguments + * @param {string} message The error message to produce + * @param {string[]} args The substitution arguments */ protected error(message: string, ...args: string[]) { Locale.throw(COMPONENT, message, ...args); diff --git a/ts/input/mathml/mml3/mml3-node.ts b/ts/input/mathml/mml3/mml3-node.ts index 7a446dd0d0..4db176c143 100644 --- a/ts/input/mathml/mml3/mml3-node.ts +++ b/ts/input/mathml/mml3/mml3-node.ts @@ -26,21 +26,20 @@ import { MathDocument } from '../../../core/MathDocument.js'; import { mjxRoot } from '#root/root.js'; import { Locale } from '../../../util/Locale.js'; import { COMPONENT } from '../__locales__/Component.js'; +import { DOM_TYPES, N } from '../../../types/Types.js'; /** * Create the transform function that uses Saxon-js to perform the * xslt transformation. * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM element types * - * @returns {(node: N, doc: MathDocument) => N} The transformation function + * @returns {(node: N, doc: MathDocument) => N} The transformation function */ -export function createTransform(): ( - node: N, - doc: MathDocument -) => N { +export function createTransform(): ( + node: N, + doc: MathDocument +) => N { // get the actual require from node. const nodeRequire = eval('require'); try { @@ -64,7 +63,7 @@ export function createTransform(): ( const xslt = nodeRequire( path.resolve(mjxRoot(), 'input', 'mml', 'extensions', 'mml3.sef.json') ); - return (node: N, doc: MathDocument) => { + return (node: N, doc: MathDocument) => { const adaptor = doc.adaptor; let mml = adaptor.outerHTML(node); // @@ -91,7 +90,7 @@ export function createTransform(): ( }).principalResult ) ) - ) as N; + ) as N; } catch (_err) { result = node; } diff --git a/ts/input/mathml/mml3/mml3.ts b/ts/input/mathml/mml3/mml3.ts index 465e877960..55fa446c57 100644 --- a/ts/input/mathml/mml3/mml3.ts +++ b/ts/input/mathml/mml3/mml3.ts @@ -27,6 +27,7 @@ import { MathDocument } from '../../../core/MathDocument.js'; import { Handler } from '../../../core/Handler.js'; import { createTransform } from './mml3-node.js'; import { MathML } from '../../mathml.js'; +import { DOM_TYPES, N } from '../../../types/Types.js'; /** * The mml/mml3 option types. @@ -45,20 +46,20 @@ const options: MML3_OPTIONS = { /** * The data for a MathML prefilter. * - * @template N The HTMLElement node class + * @template DOM The DOM node types * @template T The Text node class * @template D The Document class */ -export type FILTERDATA = { - math: MathItem; - document: MathDocument & { options: MML3_OPTIONS }; - data: N; +export type FILTERDATA = { + math: MathItem; + document: MathDocument & { options: MML3_OPTIONS }; + data: N; }; /** * Class that handles XSLT transform for MathML3 elementary math tags. */ -export class Mml3 { +export class Mml3 { /** * The XSLT transform as a string; */ @@ -68,13 +69,13 @@ export class Mml3 { * The function to convert serialized MathML using the XSLT. * (Different for browser and node environments.) */ - protected transform: (node: N, doc: MathDocument) => N; + protected transform: (node: N, doc: MathDocument) => N; /** * @param {MathDocument} document The MathDocument for the transformation * @class */ - constructor(document: MathDocument) { + constructor(document: MathDocument) { if (typeof XSLTProcessor === 'undefined') { // // For Node, get the trasnform from the external module @@ -90,13 +91,13 @@ export class Mml3 { 'text/xml' ) as any as Node; processor.importStylesheet(parsed); - this.transform = (node: N) => { + this.transform = (node: N) => { const adaptor = document.adaptor; const div = adaptor.node('div', {}, [adaptor.clone(node)]); const dom = adaptor.parse(adaptor.serializeXML(div), 'text/xml'); const mml = processor.transformToDocument( dom as any as Node - ) as any as N; + ) as any as N; return mml ? adaptor.tags(mml, 'math')[0] : node; }; } @@ -107,7 +108,7 @@ export class Mml3 { * * @param {FILTERDATA} args The data from the pre-filter chain. */ - public mmlFilter(args: FILTERDATA) { + public mmlFilter(args: FILTERDATA) { if (args.document.options.enableMml3) { args.data = this.transform(args.data, args.document); } @@ -119,10 +120,12 @@ export class Mml3 { * * @param {Handler} handler The current handler. * @returns {Handler} The provided handler for pipelining. + * + * @template DOM THe DOM node types */ -export function Mml3Handler( - handler: Handler -): Handler { +export function Mml3Handler( + handler: Handler +): Handler { handler.documentClass = class extends handler.documentClass { /** * @override @@ -145,7 +148,7 @@ export function Mml3Handler( if (!jax.options._mml3) { // prevent filter being added twice (e.g., when a11y tools load) const mml3 = new Mml3(this); - (jax as MathML).mmlFilters.add(mml3.mmlFilter.bind(mml3)); + (jax as MathML).mmlFilters.add(mml3.mmlFilter.bind(mml3)); jax.options._mml3 = true; } break; diff --git a/ts/input/tex.ts b/ts/input/tex.ts index 2fb853bcce..e32b7d29af 100644 --- a/ts/input/tex.ts +++ b/ts/input/tex.ts @@ -27,7 +27,7 @@ import { MathDocument } from '../core/MathDocument.js'; import { MathItem } from '../core/MathItem.js'; import { MmlNode } from '../core/MmlTree/MmlNode.js'; import { MmlFactory } from '../core/MmlTree/MmlFactory.js'; -import { DOM, DOM_TYPES, N, T, D } from '../types/Types.js'; +import { DOM, DOM_TYPES } from '../types/Types.js'; import { FindTeX } from './tex/FindTeX.js'; @@ -51,7 +51,7 @@ export interface TEX_OPTIONS extends INPUTJAX_OPTIONS< DOM, ParseOptions > { - FindTeX: FindTeX, T, D>; + FindTeX: FindTeX; packages: string[]; // Maximum size of TeX string to process. maxBuffer: number; @@ -59,7 +59,7 @@ export interface TEX_OPTIONS extends INPUTJAX_OPTIONS< maxTemplateSubtitutions: number; // math-style to use for Latin and Greek letters mathStyle: 'TeX' | 'ISO' | 'French' | 'upright'; - formatError: (jax: TeX, T, D>, err: TexError) => MmlNode; + formatError: (jax: TeX, err: TexError) => MmlNode; } /** @@ -72,21 +72,24 @@ const options: TEX_OPTIONS = { maxBuffer: 5 * 1024, maxTemplateSubtitutions: 10000, mathStyle: 'TeX', - formatError: (jax: TeX, T, D>, err: TexError) => - jax.formatError(err), + formatError: (jax: TeX, err: TexError) => jax.formatError(err), }; +/** + * A generic TeX input jax. + */ +export type TEX = TeX; + /*****************************************************************/ /* * Implements the TeX class (extends AbstractInputJax) + * + * @template DOM The DOM node types */ - -/** - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - */ -export class TeX extends AbstractInputJax { +export class TeX extends AbstractInputJax< + DOM, + ParseOptions +> { /** * Name of input jax. */ @@ -100,7 +103,7 @@ export class TeX extends AbstractInputJax { /** * The FindTeX instance used for locating TeX in strings */ - protected findTeX: FindTeX; + protected findTeX: FindTeX; /** * The configuration of the TeX jax. @@ -130,7 +133,7 @@ export class TeX extends AbstractInputJax { ): ParserConfiguration { const configuration = new ParserConfiguration(packages, ['tex']); configuration.init(); - return configuration; + return configuration as ParserConfiguration; } /** @@ -153,7 +156,7 @@ export class TeX extends AbstractInputJax { /** * @override */ - public options: TEX_OPTIONS>; + public options: TEX_OPTIONS; /** * @override @@ -213,10 +216,7 @@ export class TeX extends AbstractInputJax { /** * @override */ - public compile( - math: MathItem, - document: MathDocument - ): MmlNode { + public compile(math: MathItem, document: MathDocument): MmlNode { this.parseOptions.clear(); this.parseOptions.mathItem = math; this.executeFilters(this.preFilters, math, document, this.parseOptions); diff --git a/ts/input/tex/ColumnParser.ts b/ts/input/tex/ColumnParser.ts index 809b38f7fa..ceccbdc4c8 100644 --- a/ts/input/tex/ColumnParser.ts +++ b/ts/input/tex/ColumnParser.ts @@ -35,22 +35,21 @@ import { COMPONENT } from './__locales__/Component.js'; /** * The state of the columns analyzed so far. */ -/* prettier-ignore */ export type ColumnState = { - parser: TexParser, // the current TexParser - template: string; // the template string for the columns - i: number; // the current location in the template - c: string; // the current column identifier - j: number; // the current column number - calign: string[]; // the column alignments - cwidth: string[]; // the explicit column widths - cspace: string[]; // the column spacing - clines: string[]; // the column lines - cstart: string[]; // the '>' declarations - cend: string[]; // the '<' declarations - cextra: boolean[]; // the extra columns from '@' and '!' declarations - ralign: [string, string, string][]; // the row alignment and column width/align when specified -} + parser: TexParser; // The current TexParser + template: string; // The template string for the columns + i: number; // The current location in the template + c: string; // The current column identifier + j: number; // The current column number + calign: string[]; // The column alignments + cwidth: string[]; // The explicit column widths + cspace: string[]; // The column spacing + clines: string[]; // The column lines + cstart: string[]; // The '>' declarations + cend: string[]; // The '<' declarations + cextra: boolean[]; // The extra columns from '@' and '!' declarations + ralign: [string, string, string][]; // The row alignment and column width/align when specified +}; /** * A function to handle a column declaration diff --git a/ts/input/tex/Configuration.ts b/ts/input/tex/Configuration.ts index a9cb5c6beb..3dae8662fa 100644 --- a/ts/input/tex/Configuration.ts +++ b/ts/input/tex/Configuration.ts @@ -28,7 +28,7 @@ import { TagsClass } from './Tags.js'; import { userOptions, defaultOptions, OptionList } from '../../util/Options.js'; import { SubHandlers } from './MapHandler.js'; import { FunctionList } from '../../util/FunctionList.js'; -import { TeX } from '../tex.js'; +import { TEX } from '../tex.js'; import { PrioritizedList } from '../../util/PrioritizedList.js'; import { TagsFactory } from './Tags.js'; import { Locale } from '../../util/Locale.js'; @@ -41,10 +41,7 @@ export type Processor = [T, number]; export type ProtoProcessor = Processor | T; type ProcessorMethod = (data: any) => void; export type ProcessorList = Processor[]; -export type ConfigMethod = ( - c: ParserConfiguration, - j: TeX -) => void; +export type ConfigMethod = (c: ParserConfiguration, j: TEX) => void; export type InitMethod = (c: ParserConfiguration) => void; export class Configuration { @@ -379,9 +376,9 @@ export class ParserConfiguration { /** * Init method for when the jax is ready * - * @param {TeX} jax The TeX jax for this configuration + * @param {TEX} jax The TeX jax for this configuration */ - public config(jax: TeX) { + public config(jax: TEX) { this.configMethod.execute(this, jax); for (const config of this.configurations) { this.addFilters(jax, config.item); @@ -409,10 +406,10 @@ export class ParserConfiguration { * Sets items, nodes and runs configuration method explicitly. * * @param {string} name The name of the package to add - * @param {TeX} jax The TeX jax where it is being registered + * @param {TEX} jax The TeX jax where it is being registered * @param {OptionList=} options The options for the configuration. */ - public add(name: string, jax: TeX, options: OptionList = {}) { + public add(name: string, jax: TEX, options: OptionList = {}) { const config = this.getPackage(name); this.append(config); this.configurations.add(config, config.priority); @@ -472,10 +469,10 @@ export class ParserConfiguration { /** * Adds pre- and postprocessor as filters to the jax. * - * @param {TeX} jax The TeX Jax. + * @param {TEX} jax The TeX Jax. * @param {Configuration} config The configuration whose processors are added. */ - private addFilters(jax: TeX, config: Configuration) { + private addFilters(jax: TEX, config: Configuration) { for (const [pre, priority] of config.preprocessors) { jax.preFilters.add(pre, priority); } diff --git a/ts/input/tex/FindTeX.ts b/ts/input/tex/FindTeX.ts index 994fe214f5..59f46ee6af 100644 --- a/ts/input/tex/FindTeX.ts +++ b/ts/input/tex/FindTeX.ts @@ -25,6 +25,7 @@ import { AbstractFindMath } from '../../core/FindMath.js'; import { OptionList } from '../../util/Options.js'; import { sortLength, quotePattern } from '../../util/string.js'; import { ProtoItem, protoItem } from '../../core/MathItem.js'; +import { DOM_TYPES } from '../../types/Types.js'; /** * Shorthand types for data about end delimiters and delimiter pairs @@ -67,11 +68,9 @@ const options: FINDTEX_OPTIONS = { */ /** - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class FindTeX extends AbstractFindMath { +export class FindTeX extends AbstractFindMath { /** * the default options */ @@ -186,21 +185,21 @@ export class FindTeX extends AbstractFindMath { * @param {number} n The index of the string being searched * @param {RegExpExecArray} start The result array from the start-delimiter search * @param {EndItem} end The end-delimiter data corresponding to the start delimiter - * @returns {ProtoItem} The proto math item for the math, if found + * @returns {ProtoItem} The proto math item for the math, if found */ protected findEnd( text: string, n: number, start: RegExpExecArray, end: EndItem - ): ProtoItem { + ): ProtoItem { const [close, display, pattern] = end; const i = (pattern.lastIndex = start.index + start[0].length); let match: RegExpExecArray, braces: number = 0; while ((match = pattern.exec(text))) { if ((match[1] || match[0]) === close && braces === 0) { - return protoItem( + return protoItem( start[0], text.substring(i, match.index), match[0], @@ -226,7 +225,7 @@ export class FindTeX extends AbstractFindMath { * @param {number} n The index of the string being searched * @param {string} text The string being searched */ - protected findMathInString(math: ProtoItem[], n: number, text: string) { + protected findMathInString(math: ProtoItem[], n: number, text: string) { let start, match; this.start.lastIndex = 0; while ((start = this.start.exec(text))) { @@ -245,7 +244,7 @@ export class FindTeX extends AbstractFindMath { const math = start[this.sub]; const end = start.index + start[this.sub].length; if (math.length === 2) { - match = protoItem( + match = protoItem( '\\', math.substring(1), '', @@ -254,7 +253,7 @@ export class FindTeX extends AbstractFindMath { end ); } else { - match = protoItem('', math, '', n, start.index, end, false); + match = protoItem('', math, '', n, start.index, end, false); } } else { match = this.findEnd(text, n, start, this.end[start[0]]); @@ -272,7 +271,7 @@ export class FindTeX extends AbstractFindMath { * @override */ public findMath(strings: string[]) { - const math: ProtoItem[] = []; + const math: ProtoItem[] = []; if (this.hasPatterns) { for (let i = 0, m = strings.length; i < m; i++) { this.findMathInString(math, i, strings[i]); diff --git a/ts/input/tex/ParseOptions.ts b/ts/input/tex/ParseOptions.ts index d630d479df..339b932701 100644 --- a/ts/input/tex/ParseOptions.ts +++ b/ts/input/tex/ParseOptions.ts @@ -33,6 +33,7 @@ import { TexConstant } from './TexConstants.js'; import { defaultOptions, OptionList } from '../../util/Options.js'; import { ParserConfiguration } from './Configuration.js'; import { ColumnParser } from './ColumnParser.js'; +import { DOM } from '../../types/Types.js'; const MATHVARIANT = TexConstant.Variant; @@ -128,7 +129,7 @@ export default class ParseOptions { /** * The current MathItem */ - public mathItem: MathItem; + public mathItem: MathItem; /** * The current root node. diff --git a/ts/input/tex/Tags.ts b/ts/input/tex/Tags.ts index 3364433d11..4901c8347d 100644 --- a/ts/input/tex/Tags.ts +++ b/ts/input/tex/Tags.ts @@ -30,6 +30,7 @@ import NodeUtil from './NodeUtil.js'; import { TexConstant } from './TexConstants.js'; import { Locale } from '../../util/Locale.js'; import { COMPONENT } from './__locales__/Component.js'; +import { DOM } from '../../types/Types.js'; /** * Simple class for label objects. @@ -207,13 +208,13 @@ export interface Tags { * * @param {MathItem} math The MathItem for the current equation */ - startEquation(math: MathItem): void; + startEquation(math: MathItem): void; /** * Move equation-specific labels and ids to global ones, * save the counter, and mark the MathItem for redos */ - finishEquation(math: MathItem): void; + finishEquation(math: MathItem): void; /** * Finalizes tag creation. @@ -487,7 +488,7 @@ export class AbstractTags implements Tags { /** * @override */ - public startEquation(math: MathItem) { + public startEquation(math: MathItem) { this.history = []; this.stack = []; this.clearTag(); @@ -506,7 +507,7 @@ export class AbstractTags implements Tags { /** * @override */ - public finishEquation(math: MathItem) { + public finishEquation(math: MathItem) { if (this.redo) { math.inputData.recompile = { state: math.state(), diff --git a/ts/input/tex/autoload/AutoloadConfiguration.ts b/ts/input/tex/autoload/AutoloadConfiguration.ts index 60ccd346e9..fdde3400ae 100644 --- a/ts/input/tex/autoload/AutoloadConfiguration.ts +++ b/ts/input/tex/autoload/AutoloadConfiguration.ts @@ -26,7 +26,7 @@ import { Configuration, ParserConfiguration } from '../Configuration.js'; import TexParser from '../TexParser.js'; import { CommandMap } from '../TokenMap.js'; import { Macro } from '../Token.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import { RequireLoad, @@ -99,9 +99,9 @@ function initAutoload(config: ParserConfiguration) { * (except for \color, which is overridden if present) * * @param {ParserConfiguration} config The parser configuration. - * @param {TeX} jax The current tex input jax. + * @param {TEX} jax The current tex input jax. */ -function configAutoload(config: ParserConfiguration, jax: TeX) { +function configAutoload(config: ParserConfiguration, jax: TEX) { const parser = jax.parseOptions; const macros = parser.handlers.get(HandlerType.MACRO); const environments = parser.handlers.get(HandlerType.ENVIRONMENT); diff --git a/ts/input/tex/bussproofs/BussproofsUtil.ts b/ts/input/tex/bussproofs/BussproofsUtil.ts index 957ff58b21..5b1f5a1990 100644 --- a/ts/input/tex/bussproofs/BussproofsUtil.ts +++ b/ts/input/tex/bussproofs/BussproofsUtil.ts @@ -33,8 +33,10 @@ import { MathDocument } from '../../../core/MathDocument.js'; import { Locale } from '../../../util/Locale.js'; import { COMPONENT } from './__locales__/Component.js'; -type MATHITEM = MathItem; -type MATHDOCUMENT = MathDocument; +import { DOM } from '../../../types/Types.js'; + +type MATHITEM = MathItem; +type MATHDOCUMENT = MathDocument; type FilterData = { math: MATHITEM; diff --git a/ts/input/tex/color/ColorConfiguration.ts b/ts/input/tex/color/ColorConfiguration.ts index 9d13dfa589..ff0e68c349 100644 --- a/ts/input/tex/color/ColorConfiguration.ts +++ b/ts/input/tex/color/ColorConfiguration.ts @@ -26,7 +26,7 @@ import { CommandMap } from '../TokenMap.js'; import { Configuration, ParserConfiguration } from '../Configuration.js'; import { ColorMethods } from './ColorMethods.js'; import { ColorModel } from './ColorUtil.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; export { COMPONENT } from './__locales__/Component.js'; /** @@ -44,12 +44,9 @@ new CommandMap('color', { * Config method for Color package. * * @param {Configuration} _config The current configuration. - * @param {TeX} jax The TeX jax having that configuration + * @param {TEX} jax The TeX jax having that configuration */ -const config = function ( - _config: ParserConfiguration, - jax: TeX -) { +const config = function (_config: ParserConfiguration, jax: TEX) { jax.parseOptions.packageData.set('color', { model: new ColorModel() }); }; diff --git a/ts/input/tex/colortbl/ColortblConfiguration.ts b/ts/input/tex/colortbl/ColortblConfiguration.ts index 99f55cd9ab..bdc506624f 100644 --- a/ts/input/tex/colortbl/ColortblConfiguration.ts +++ b/ts/input/tex/colortbl/ColortblConfiguration.ts @@ -32,7 +32,7 @@ import { CommandMap } from '../TokenMap.js'; import TexParser from '../TexParser.js'; import { texError } from '../TexError.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import { COMPONENT } from './__locales__/Component.js'; export { COMPONENT }; @@ -202,9 +202,9 @@ new CommandMap('colortbl', { * The configuration function for colortbl. * * @param {ParserConfiguration} config The configuration being used. - * @param {TeX} jax The TeX jax using this configuration. + * @param {TEX} jax The TeX jax using this configuration. */ -const config = function (config: ParserConfiguration, jax: TeX) { +const config = function (config: ParserConfiguration, jax: TEX) { // // Make sure color is configured. (It doesn't have to be included in tex.packages) // diff --git a/ts/input/tex/configmacros/ConfigMacrosConfiguration.ts b/ts/input/tex/configmacros/ConfigMacrosConfiguration.ts index ebe632a67b..24b307da3a 100644 --- a/ts/input/tex/configmacros/ConfigMacrosConfiguration.ts +++ b/ts/input/tex/configmacros/ConfigMacrosConfiguration.ts @@ -29,9 +29,7 @@ import ParseMethods from '../ParseMethods.js'; import { Macro } from '../Token.js'; import NewcommandMethods from '../newcommand/NewcommandMethods.js'; import { BeginEnvItem } from '../newcommand/NewcommandItems.js'; -import { TeX } from '../../tex.js'; - -type TEX = TeX; +import { TEX } from '../../tex.js'; /** * The name to use for the macros map @@ -73,7 +71,7 @@ function configmacrosInit(config: ParserConfiguration) { * Create the user-defined macros and environments from their options * * @param {Configuration} _config The configuration object for the input jax - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ function configmacrosConfig(_config: ParserConfiguration, jax: TEX) { configActives(jax); @@ -107,7 +105,7 @@ function setMacros(name: string, map: string, jax: TEX) { /** * Create user-defined active characters from the active option * - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ function configActives(jax: TEX) { setMacros('active', ACTIVEMAP, jax); @@ -116,7 +114,7 @@ function configActives(jax: TEX) { /** * Create user-defined macros from the macros option * - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ function configMacros(jax: TEX) { setMacros('macros', MACROSMAP, jax); @@ -125,7 +123,7 @@ function configMacros(jax: TEX) { /** * Create user-defined environments from the environments option * - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ function configEnvironments(jax: TEX) { const handler = jax.parseOptions.handlers.retrieve( diff --git a/ts/input/tex/mathtools/MathtoolsConfiguration.ts b/ts/input/tex/mathtools/MathtoolsConfiguration.ts index 1cacef0120..44ec54c39c 100644 --- a/ts/input/tex/mathtools/MathtoolsConfiguration.ts +++ b/ts/input/tex/mathtools/MathtoolsConfiguration.ts @@ -28,7 +28,7 @@ import { CommandMap } from '../TokenMap.js'; import NodeUtil from '../NodeUtil.js'; import { expandable, EXPANDABLE_LIST_OF } from '../../../util/Options.js'; import { ParserConfiguration } from '../Configuration.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import ParseOptions from '../ParseOptions.js'; import { NewcommandConfig } from '../newcommand/NewcommandConfiguration.js'; import { NewcommandTables } from '../newcommand/NewcommandUtil.js'; @@ -48,9 +48,9 @@ export { COMPONENT } from './__locales__/Component.js'; * Add any pre-defined paired delimiters, and subclass the configured tag format. * * @param {ParserConfiguration} config The current configuration. - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ -function configMathtools(config: ParserConfiguration, jax: TeX) { +function configMathtools(config: ParserConfiguration, jax: TEX) { NewcommandConfig(config, jax); const parser = jax.parseOptions; const pairedDelims = parser.options.mathtools.pairedDelimiters; diff --git a/ts/input/tex/mathtools/MathtoolsTags.ts b/ts/input/tex/mathtools/MathtoolsTags.ts index 13c18a3172..79c8b2c467 100644 --- a/ts/input/tex/mathtools/MathtoolsTags.ts +++ b/ts/input/tex/mathtools/MathtoolsTags.ts @@ -22,7 +22,7 @@ import { texError } from '../TexError.js'; import { ParserConfiguration } from '../Configuration.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import { AbstractTags, TagsFactory } from '../Tags.js'; import { COMPONENT } from './__locales__/Component.js'; @@ -30,10 +30,9 @@ import { COMPONENT } from './__locales__/Component.js'; /** * The type for the Mathtools tags (including their data). */ -/* prettier-ignore */ export type MathtoolsTags = AbstractTags & { - mtFormats: Map; // name -> [left, right, format] - mtCurrent: [string, string, string]; // [left, right, format] + mtFormats: Map; // name -> [left, right, format] + mtCurrent: [string, string, string]; // [left, right, format] }; /** @@ -46,12 +45,9 @@ let tagID = 0; * that handles the formats created by the \newtagform macro. * * @param {ParserConfiguration} config The current configuration. - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ -export function MathtoolsTagFormat( - config: ParserConfiguration, - jax: TeX -) { +export function MathtoolsTagFormat(config: ParserConfiguration, jax: TEX) { /** * If the tag format is being added by one of the other extensions, * as is done for the 'ams' tags, make sure it is defined so we can create it. diff --git a/ts/input/tex/newcommand/NewcommandConfiguration.ts b/ts/input/tex/newcommand/NewcommandConfiguration.ts index 95004746c8..6db29c57c0 100644 --- a/ts/input/tex/newcommand/NewcommandConfiguration.ts +++ b/ts/input/tex/newcommand/NewcommandConfiguration.ts @@ -21,7 +21,7 @@ * @author v.sorge@mathjax.org (Volker Sorge) */ -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import { HandlerType, ConfigurationType } from '../HandlerTypes.js'; import { Configuration, ParserConfiguration } from '../Configuration.js'; import { BeginEnvItem } from './NewcommandItems.js'; @@ -36,12 +36,9 @@ export { COMPONENT } from './__locales__/Component.js'; * if they aren't already in place. * * @param {ParserConfiguration} _config The parser configuration (ignored) - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ -export function NewcommandConfig( - _config: ParserConfiguration, - jax: TeX -) { +export function NewcommandConfig(_config: ParserConfiguration, jax: TEX) { // // Check if we are already initialzied (since other packages call this) // diff --git a/ts/input/tex/require/RequireConfiguration.ts b/ts/input/tex/require/RequireConfiguration.ts index 8b251d9073..aed9a0790d 100644 --- a/ts/input/tex/require/RequireConfiguration.ts +++ b/ts/input/tex/require/RequireConfiguration.ts @@ -39,6 +39,7 @@ import { Loader, CONFIG as LOADERCONFIG } from '../../../components/loader.js'; import { mathjax } from '../../../mathjax.js'; import { expandable, EXPANDABLE_LIST_OF } from '../../../util/Options.js'; import { MenuMathDocument } from '../../../ui/menu/MenuHandler.js'; +import { DOM } from '../../../types/Types.js'; import { Locale } from '../../../util/Locale.js'; import { COMPONENT } from './__locales__/Component.js'; @@ -55,7 +56,7 @@ const MJCONFIG = MathJax.config; * @param {TeX} jax The TeX jax whose configuration is to be modified * @param {string} name The name of the extension being added (e.g., '[tex]/amscd') */ -function RegisterExtension(jax: TeX, name: string) { +function RegisterExtension(jax: TeX, name: string) { const require = jax.parseOptions.options.require; const required = jax.parseOptions.packageData.get('require') .required as string[]; @@ -90,11 +91,7 @@ function RegisterExtension(jax: TeX, name: string) { * @param {string} name The name of the extension being added (e.g., '[tex]/amscd') * @param {string} extension The name of the configuration handler for the extension. */ -function ProcessExtension( - jax: TeX, - name: string, - extension: string -) { +function ProcessExtension(jax: TeX, name: string, extension: string) { // // If the required file loaded an extension... // @@ -138,7 +135,7 @@ function ProcessExtension( * are complete (or null if no retries) */ function RegisterDependencies( - jax: TeX, + jax: TeX, names: string[] = [] ): Promise { const prefix = jax.parseOptions.options.require.prefix; @@ -182,7 +179,7 @@ export function RequireLoad(parser: TexParser, name: string) { texError(COMPONENT, 'RequireFail', name); } const require = LOADERCONFIG[extension]?.rendererExtensions; - const menu = (MathJax.startup.document as MenuMathDocument)?.menu; + const menu = (MathJax.startup.document as unknown as MenuMathDocument)?.menu; if (require && menu) { menu.addRequiredExtensions(require); } @@ -198,12 +195,11 @@ export function RequireLoad(parser: TexParser, name: string) { * @param {ParserConfiguration} _config The parser configuration. * @param {TeX} jax The current TeX jax. */ -function config(_config: ParserConfiguration, jax: TeX) { - /* prettier-ignore */ +function config(_config: ParserConfiguration, jax: TeX) { jax.parseOptions.packageData.set('require', { - jax: jax, // \require needs access to this - required: [...jax.options.packages], // stores the names of the packages that have been added - configured: new Map() // stores the packages that have been configured + jax: jax, // \require needs access to this + required: [...jax.options.packages], // stores the names of the packages that have been added + configured: new Map(), // stores the packages that have been configured }); const options = jax.parseOptions.options.require; const prefix = options.prefix; diff --git a/ts/input/tex/setoptions/SetOptionsConfiguration.ts b/ts/input/tex/setoptions/SetOptionsConfiguration.ts index 96827d5919..c61721176e 100644 --- a/ts/input/tex/setoptions/SetOptionsConfiguration.ts +++ b/ts/input/tex/setoptions/SetOptionsConfiguration.ts @@ -27,7 +27,7 @@ import { ConfigurationHandler, ParserConfiguration, } from '../Configuration.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import TexParser from '../TexParser.js'; import { CommandMap } from '../TokenMap.js'; import { texError } from '../TexError.js'; @@ -149,12 +149,9 @@ function SetOptions(parser: TexParser, name: string) { * its options, if any. * * @param {ParserConfiguration} _config The current configuration. - * @param {TeX} jax The active tex input jax. + * @param {TEX} jax The active tex input jax. */ -function setoptionsConfig( - _config: ParserConfiguration, - jax: TeX -) { +function setoptionsConfig(_config: ParserConfiguration, jax: TEX) { const setOptionsMap = new CommandMap('setoptions', { setOptions: SetOptions, }); diff --git a/ts/input/tex/tagformat/TagFormatConfiguration.ts b/ts/input/tex/tagformat/TagFormatConfiguration.ts index 84f9180695..c1d7c6e961 100644 --- a/ts/input/tex/tagformat/TagFormatConfiguration.ts +++ b/ts/input/tex/tagformat/TagFormatConfiguration.ts @@ -23,7 +23,7 @@ import { ConfigurationType } from '../HandlerTypes.js'; import { Configuration, ParserConfiguration } from '../Configuration.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import { AbstractTags as _AbstractTags, TagsFactory } from '../Tags.js'; /** @@ -37,12 +37,9 @@ let tagID = 0; * to control the formatting of the tags * * @param {Configuration} config The configuration for the input jax - * @param {TeX} jax The TeX input jax + * @param {TEX} jax The TeX input jax */ -export function tagformatConfig( - config: ParserConfiguration, - jax: TeX -) { +export function tagformatConfig(config: ParserConfiguration, jax: TEX) { /** * If the tag format is being added by one of the other extensions, * as is done for the 'ams' tags, make sure it is defined so we can create it. diff --git a/ts/input/tex/texhtml/TexHtmlConfiguration.ts b/ts/input/tex/texhtml/TexHtmlConfiguration.ts index 4a8ae52f45..1940c601af 100644 --- a/ts/input/tex/texhtml/TexHtmlConfiguration.ts +++ b/ts/input/tex/texhtml/TexHtmlConfiguration.ts @@ -33,6 +33,7 @@ import { HtmlNode } from '../../../core/MmlTree/MmlNodes/HtmlNode.js'; import { HTMLDomStrings } from '../../../handlers/html/HTMLDomStrings.js'; import { DOMAdaptor } from '../../../core/DOMAdaptor.js'; import { COMPONENT } from '../__locales__/Component.js'; +import { DOM } from '../../../types/Types.js'; export const HtmlNodeMethods: { [key: string]: ParseMethod } = { /** @@ -114,10 +115,7 @@ export const TexHtmlConfiguration = Configuration.create('texhtml', { // const include = HTMLDomStrings.OPTIONS.includeHtmlTags; if (!include['tex-html']) { - include['tex-html'] = ( - node: any, - adaptor: DOMAdaptor - ) => { + include['tex-html'] = (node: any, adaptor: DOMAdaptor) => { // // Use the node's serialized contents, and check if there are // nested nodes; if so, mark the one that we are using @@ -136,7 +134,7 @@ export const TexHtmlConfiguration = Configuration.create('texhtml', { } }, [ConfigurationType.PREPROCESSORS]: [ - (data: { document: HTMLDocument; data: ParseOptions }) => { + (data: { document: HTMLDocument; data: ParseOptions }) => { data.data.packageData.set('texhtml', { adaptor: data.document.adaptor }); // save the DOMadaptor }, ], diff --git a/ts/input/tex/textmacros/TextMacrosConfiguration.ts b/ts/input/tex/textmacros/TextMacrosConfiguration.ts index d05e6aebc9..27431049ca 100644 --- a/ts/input/tex/textmacros/TextMacrosConfiguration.ts +++ b/ts/input/tex/textmacros/TextMacrosConfiguration.ts @@ -22,7 +22,7 @@ */ import { HandlerType, ConfigurationType } from '../HandlerTypes.js'; -import { TeX } from '../../tex.js'; +import { TEX } from '../../tex.js'; import TexParser from '../TexParser.js'; import { Configuration, ParserConfiguration } from '../Configuration.js'; import ParseOptions from '../ParseOptions.js'; @@ -132,12 +132,9 @@ export const TextMacrosConfiguration = Configuration.create('textmacros', { [ConfigurationType.PRIORITY]: 1, /** * @param {ParserConfiguration} _config The configuration object we are being configured within - * @param {TeX} jax The TeX input jax in which we are running + * @param {TEX} jax The TeX input jax in which we are running */ - [ConfigurationType.CONFIG]: ( - _config: ParserConfiguration, - jax: TeX - ) => { + [ConfigurationType.CONFIG]: (_config: ParserConfiguration, jax: TEX) => { // // Create the configuration and parseOptions objects for the // internal TextParser and add the textBase configuration. diff --git a/ts/mathjax.ts b/ts/mathjax.ts index ca05cbc2ad..035b87dbc4 100644 --- a/ts/mathjax.ts +++ b/ts/mathjax.ts @@ -28,6 +28,7 @@ import { OptionList } from './util/Options.js'; import { MathDocument } from './core/MathDocument.js'; import { context } from './util/context.js'; import { json } from '#root/json.js'; +import { DOM } from './types/Types.js'; /*****************************************************************/ /** @@ -47,7 +48,7 @@ export const mathjax = { /** * The list of registers document handlers */ - handlers: new HandlerList(), + handlers: new HandlerList(), /** * Creates a MathDocument using a registered handler that knows how to handl it @@ -56,10 +57,7 @@ export const mathjax = { * @param {OptionList} options The options to use for the document (e.g., input and output jax) * @returns {MathDocument} The MathDocument to handle the document */ - document: function ( - document: any, - options: OptionList - ): MathDocument { + document: function (document: any, options: OptionList): MathDocument { return mathjax.handlers.document(document, options); }, diff --git a/ts/output/chtml.ts b/ts/output/chtml.ts index e20f080fff..f2d39f6795 100644 --- a/ts/output/chtml.ts +++ b/ts/output/chtml.ts @@ -42,33 +42,48 @@ import { Usage } from './chtml/Usage.js'; import * as LENGTHS from '../util/lengths.js'; import { unicodeChars } from '../util/string.js'; import { DefaultFont } from './chtml/DefaultFont.js'; -import { DOM, DOM_TYPES, N, T, D } from '../types/Types.js'; +import { DOM_TYPES, N } from '../types/Types.js'; /*****************************************************************/ +/** + * The CHTML font types. + */ +export type CHTML_FONT = { + CC: ChtmlCharOptions; + VV: ChtmlVariantData; + DD: ChtmlDelimiterData; + FD: ChtmlFontData; + FC: ChtmlFontDataClass; +}; + /** * The CHTML option types. */ -export interface CHTML_OPTIONS extends COMMON_OPTIONS< - DOM, - ChtmlWrapper, T, D>, - ChtmlWrapperFactory, T, D>, - ChtmlWrapperClass, T, D>, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass -> { +export type OPTIONS = { adaptiveCSS: boolean; // true means only produce CSS that is used in the processed equations matchFontHeight: boolean; // true to match ex-height of surrounding font -} +}; + +/** + * The CHTML OutputJax option types. + */ +export interface CHTML_OPTIONS + extends + OPTIONS, + COMMON_OPTIONS< + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass + > {} /** * The CHTML option defaults. */ -const options: CHTML_OPTIONS = { - ...CommonOutputJax.OPTIONS, +const options: OPTIONS = { adaptiveCSS: true, matchFontHeight: true, }; @@ -77,32 +92,15 @@ const options: CHTML_OPTIONS = { /** * Implements the CHTML class (extends AbstractOutputJax) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class CHTML extends CommonOutputJax< - // - // The HTMLElement, TextNode, and Document classes (for the DOM implementation in use) - // - N, - T, - D, - // - // The Wrapper type and its Factory and Class (these need to know N, T, and D) - // - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - // - // These are font-related objects that depend on the output jax; e,g. the character options - // for CHTML and SVG output differ (CHTML contains font information, while SVG has path data) - // - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass +export class CHTML extends CommonOutputJax< + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { /** * The name of this output jax @@ -112,12 +110,15 @@ export class CHTML extends CommonOutputJax< /** * @override */ - public options: CHTML_OPTIONS>; + public options: CHTML_OPTIONS; /** * @override */ - public static OPTIONS = options; + public static OPTIONS = { + ...CommonOutputJax.OPTIONS, + ...options, + }; /** * The default styles for CommonHTML @@ -234,7 +235,7 @@ export class CHTML extends CommonOutputJax< /** * The CHTML stylesheet, once it is constructed */ - public chtmlStyles: N = null; + public chtmlStyles: N = null; /** * @override @@ -263,7 +264,7 @@ export class CHTML extends CommonOutputJax< /** * @override */ - public escaped(math: MathItem, html: MathDocument) { + public escaped(math: MathItem, html: MathDocument) { this.setDocument(html); return this.html('span', {}, [this.text(math.math)]); } @@ -271,7 +272,7 @@ export class CHTML extends CommonOutputJax< /** * @override */ - public styleSheet(html: MathDocument) { + public styleSheet(html: MathDocument) { if (this.chtmlStyles) { const styles = new StyleJsonSheet(); if (this.options.adaptiveCSS) { @@ -352,7 +353,7 @@ export class CHTML extends CommonOutputJax< * @param {ChtmlWrapper} wrapper The MML node wrapper whose HTML is to be produced * @param {N} parent The HTML node to contain the HTML */ - public processMath(wrapper: ChtmlWrapper, parent: N) { + public processMath(wrapper: ChtmlWrapper, parent: N) { wrapper.toCHTML([parent]); } @@ -413,7 +414,7 @@ export class CHTML extends CommonOutputJax< * @override */ - public measureTextNode(textNode: N) { + public measureTextNode(textNode: N) { const adaptor = this.adaptor; const text = adaptor.clone(textNode); // diff --git a/ts/output/chtml/FontData.ts b/ts/output/chtml/FontData.ts index 00aa2a9460..650855faf5 100644 --- a/ts/output/chtml/FontData.ts +++ b/ts/output/chtml/FontData.ts @@ -49,12 +49,11 @@ export * from '../common/FontData.js'; /** * Add the extra data needed for CharOptions in CHTML */ -/* prettier-ignore */ export interface ChtmlCharOptions extends CharOptions { - c?: string; // the content value (for css) - f?: string; // the font postfix (for css) - ff?: string; // the full font css class (for extensions) - cmb?: boolean; // true if this is a combining character + c?: string; // The content value (for css) + f?: string; // The font postfix (for css) + ff?: string; // The full font css class (for extensions) + cmb?: boolean; // True if this is a combining character } /** diff --git a/ts/output/chtml/Notation.ts b/ts/output/chtml/Notation.ts index 32b6a7e4aa..554ae03587 100644 --- a/ts/output/chtml/Notation.ts +++ b/ts/output/chtml/Notation.ts @@ -22,14 +22,21 @@ */ import { ChtmlMencloseNTD } from './Wrappers/menclose.js'; +import { DOM_TYPES, N } from '../../types/Types.js'; import * as Notation from '../common/Notation.js'; export * from '../common/Notation.js'; /* * Shorthands for common types */ -export type RENDERER = Notation.Renderer, N>; -export type DEFPAIR = Notation.DefPair, N>; +export type RENDERER = Notation.Renderer< + ChtmlMencloseNTD, + N +>; +export type DEFPAIR = Notation.DefPair< + ChtmlMencloseNTD, + N +>; /** * Create a named element (handled by CSS), and adjust it if thickness is non-standard @@ -38,10 +45,10 @@ export type DEFPAIR = Notation.DefPair, N>; * @param {string} offset The offset direction to adjust if thickness is non-standard * @returns {RENDERER} The renderer function for the given element name */ -export const RenderElement = function ( +export const RenderElement = function ( name: string, offset: string = '' -): RENDERER { +): RENDERER { return ((node, _child) => { const shape = node.adjustBorder(node.html('mjx-' + name)); if (offset) { @@ -52,17 +59,17 @@ export const RenderElement = function ( } } node.adaptor.append(node.dom[0], shape); - }) as Notation.Renderer, N>; + }) as Notation.Renderer, N>; }; /** * @param {Notation.Side} side The side on which a border should appear * @returns {DEFPAIR} The notation definition for the notation having a line on the given side */ -export const Border = function ( +export const Border = function ( side: Notation.Side -): DEFPAIR { - return Notation.CommonBorder, N>((node, child) => { +): DEFPAIR { + return Notation.CommonBorder, N>((node, child) => { node.adaptor.setStyle( child, 'border-' + side, @@ -77,16 +84,18 @@ export const Border = function ( * @param {Notation.Side} side2 The second side to get a border * @returns {DEFPAIR} The notation definition for the notation having lines on two sides */ -export const Border2 = function ( +export const Border2 = function ( name: string, side1: Notation.Side, side2: Notation.Side -): DEFPAIR { - return Notation.CommonBorder2, N>((node, child) => { - const border = node.Em(node.thickness) + ' solid'; - node.adaptor.setStyle(child, 'border-' + side1, border); - node.adaptor.setStyle(child, 'border-' + side2, border); - })(name, side1, side2); +): DEFPAIR { + return Notation.CommonBorder2, N>( + (node, child) => { + const border = node.Em(node.thickness) + ' solid'; + node.adaptor.setStyle(child, 'border-' + side1, border); + node.adaptor.setStyle(child, 'border-' + side2, border); + } + )(name, side1, side2); }; /** @@ -94,11 +103,11 @@ export const Border2 = function ( * @param {number} neg 1 or -1 to use with the angle * @returns {DEFPAIR} The notation definition for the diagonal strike */ -export const DiagonalStrike = function ( +export const DiagonalStrike = function ( name: string, neg: number -): DEFPAIR { - return Notation.CommonDiagonalStrike, N>( +): DEFPAIR { + return Notation.CommonDiagonalStrike, N>( (cname: string) => (node, _child) => { const { w, h, d } = node.getBBox(); const [a, W] = node.getArgMod(w, h + d); @@ -121,10 +130,10 @@ export const DiagonalStrike = function ( * @param {string} name The name of the diagonal arrow to define * @returns {DEFPAIR} The notation definition for the diagonal arrow */ -export const DiagonalArrow = function ( +export const DiagonalArrow = function ( name: string -): DEFPAIR { - return Notation.CommonDiagonalArrow, N>( +): DEFPAIR { + return Notation.CommonDiagonalArrow, N>( (node, arrow) => { node.adaptor.append(node.dom[0], arrow); } @@ -135,8 +144,10 @@ export const DiagonalArrow = function ( * @param {string} name The name of the horizontal or vertical arrow to define * @returns {DEFPAIR} The notation definition for the arrow */ -export const Arrow = function (name: string): DEFPAIR { - return Notation.CommonArrow, N>((node, arrow) => { +export const Arrow = function ( + name: string +): DEFPAIR { + return Notation.CommonArrow, N>((node, arrow) => { node.adaptor.append(node.dom[0], arrow); })(name); }; diff --git a/ts/output/chtml/Wrapper.ts b/ts/output/chtml/Wrapper.ts index 071bb30499..7b22d6ad1c 100644 --- a/ts/output/chtml/Wrapper.ts +++ b/ts/output/chtml/Wrapper.ts @@ -28,17 +28,10 @@ import { StringMap, SPACE, } from '../common/Wrapper.js'; -import { CHTML } from '../chtml.js'; +import { CHTML, CHTML_FONT } from '../chtml.js'; import { ChtmlWrapperFactory } from './WrapperFactory.js'; import { BBox } from '../../util/BBox.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from './FontData.js'; -import { Constructor } from '../../types/Types.js'; +import { DOM_TYPES, N, T, Constructor } from '../../types/Types.js'; export { Constructor } from '../../types/Types.js'; export { StringMap } from '../common/Wrapper.js'; @@ -66,35 +59,23 @@ export const FONTSIZE: StringMap = { /** * Shorthand for making a ChtmlWrapper constructor */ -export type ChtmlConstructor = Constructor>; +export type ChtmlConstructor = Constructor< + ChtmlWrapper +>; /*****************************************************************/ /** * The type of the ChtmlWrapper class (used when creating the wrapper factory for this class) */ -export interface ChtmlWrapperClass extends CommonWrapperClass< - // - // The HTMLElement, TextNode, and Document classes (for the DOM implementation in use) - // - N, - T, - D, - // - // The Wrapper type and its Factory and Class (these need to know N, T, and D) - // - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - // - // These are font-related objects that depend on the output jax; e,g. the character options - // for CHTML and SVG output differ (CHTML contains font information, while SVG has path data) - // - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass +export interface ChtmlWrapperClass< + DOM extends DOM_TYPES, +> extends CommonWrapperClass< + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { /** * If true, this causes a style for the node type to be generated automatically @@ -107,23 +88,15 @@ export interface ChtmlWrapperClass extends CommonWrapperClass< /** * The base ChtmlWrapper class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class ChtmlWrapper extends CommonWrapper< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass +export class ChtmlWrapper extends CommonWrapper< + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { /** * @override @@ -143,7 +116,7 @@ export class ChtmlWrapper extends CommonWrapper< * * @param {N[]} parents The HTML nodes where the output is to be added */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; this.addChildren(this.standardChtmlNodes(parents)); } @@ -154,7 +127,7 @@ export class ChtmlWrapper extends CommonWrapper< * @param {N[]} parents The HTML nodes where the output is to be added * @returns {boolean} True when embellished output is produced, false if not */ - public toEmbellishedCHTML(parents: N[]): boolean { + public toEmbellishedCHTML(parents: N[]): boolean { if (parents.length <= 1 || !this.node.isEmbellished) return false; const adaptor = this.adaptor; parents.forEach((dom) => adaptor.append(dom, this.html('mjx-linestrut'))); @@ -168,7 +141,7 @@ export class ChtmlWrapper extends CommonWrapper< for (const [parent, STYLE] of [ [parents[0], 'before'], [parents[1], 'after'], - ] as [N, string][]) { + ] as [N, string][]) { if (style !== STYLE) { this.toCHTML([parent]); dom.push(this.dom[0]); @@ -186,7 +159,7 @@ export class ChtmlWrapper extends CommonWrapper< /** * @param {N[]} parents The HTML nodes where the children are to be added */ - public addChildren(parents: N[]) { + public addChildren(parents: N[]) { for (const child of this.childNodes) { child.toCHTML(parents); } @@ -200,7 +173,7 @@ export class ChtmlWrapper extends CommonWrapper< * @param {N[]} parents The HTML elements in which the node is to be created * @returns {N[]} The roots of the HTML tree for the wrapped node's output */ - protected standardChtmlNodes(parents: N[]): N[] { + protected standardChtmlNodes(parents: N[]): N[] { this.markUsed(); const chtml = this.createChtmlNodes(parents); this.handleStyles(); @@ -224,7 +197,7 @@ export class ChtmlWrapper extends CommonWrapper< * @param {N[]} parents The HTML elements in which the node is to be created * @returns {N[]} The roots of the HTML tree for the wrapped node's output */ - protected createChtmlNodes(parents: N[]): N[] { + protected createChtmlNodes(parents: N[]): N[] { this.dom = parents.map((_parent) => this.html('mjx-' + this.node.kind)); // FIXME: add segment id parents = this.handleHref(parents); for (const i of parents.keys()) { @@ -239,12 +212,12 @@ export class ChtmlWrapper extends CommonWrapper< * @param {N[]} parents The HTML nodes in which the output is to be placed * @returns {N[]} The roots of the HTML tree for the node's output */ - protected handleHref(parents: N[]): N[] { + protected handleHref(parents: N[]): N[] { const href = this.node.attributes.get('href'); if (!href) return parents; return parents.map( (parent) => - this.adaptor.append(parent, this.html('a', { href: href })) as N + this.adaptor.append(parent, this.html('a', { href: href })) as N ); } @@ -282,7 +255,7 @@ export class ChtmlWrapper extends CommonWrapper< * @param {number} rscale The relatie scale to apply * @returns {N} The HTML node (for chaining) */ - protected setScale(chtml: N, rscale: number): N { + protected setScale(chtml: N, rscale: number): N { const scale = Math.abs(rscale - 1) < 0.001 ? 1 : rscale; if (chtml && scale !== 1) { const size = this.percent(scale); @@ -440,7 +413,7 @@ export class ChtmlWrapper extends CommonWrapper< * @param {string} align The alignment for the node * @param {number} shift The indent (positive or negative) for the node */ - protected setIndent(chtml: N, align: string, shift: number) { + protected setIndent(chtml: N, align: string, shift: number) { const adaptor = this.adaptor; if (align === 'center' || align === 'left') { const L = this.getBBox().L; @@ -488,7 +461,7 @@ export class ChtmlWrapper extends CommonWrapper< 'background-color': 'green', }, }), - ] as N[] + ] as N[] ); const node = this.dom[0] || this.parent.dom[0]; const size = this.adaptor.getAttribute(node, 'size'); @@ -514,7 +487,11 @@ export class ChtmlWrapper extends CommonWrapper< * @param {(N|T)[]} content The child nodes for the created HTML node * @returns {N} The generated HTML tree */ - public html(type: string, def: OptionList = {}, content: (N | T)[] = []): N { + public html( + type: string, + def: OptionList = {}, + content: (N | T)[] = [] + ): N { return this.jax.html(type, def, content); } diff --git a/ts/output/chtml/WrapperFactory.ts b/ts/output/chtml/WrapperFactory.ts index 12ab218614..29063d0c24 100644 --- a/ts/output/chtml/WrapperFactory.ts +++ b/ts/output/chtml/WrapperFactory.ts @@ -21,49 +21,27 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../chtml.js'; +import { CHTML, CHTML_FONT } from '../chtml.js'; import { CommonWrapperFactory } from '../common/WrapperFactory.js'; import { ChtmlWrapper, ChtmlWrapperClass } from './Wrapper.js'; import { ChtmlWrappers } from './Wrappers.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from './FontData.js'; +import { DOM_TYPES } from '../../types/Types.js'; /*****************************************************************/ /** * The ChtmlWrapperFactory class for creating ChtmlWrapper nodes * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class ChtmlWrapperFactory extends CommonWrapperFactory< - // - // The HTMLElement, TextNode, and Document classes (for the DOM implementation in use) - // - N, - T, - D, - // - // The Wrapper type and its Factory and Class (these need to know N, T, and D) - // - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - // - // These are font-related objects that depend on the output jax; e,g. the character options - // for CHTML and SVG output differ (CHTML contains font information, while SVG has path data) - // - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass +export class ChtmlWrapperFactory< + DOM extends DOM_TYPES, +> extends CommonWrapperFactory< + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { /** * The default list of wrapper nodes this factory can create diff --git a/ts/output/chtml/Wrappers.ts b/ts/output/chtml/Wrappers.ts index 270151ca6f..16a60b9de3 100644 --- a/ts/output/chtml/Wrappers.ts +++ b/ts/output/chtml/Wrappers.ts @@ -21,6 +21,7 @@ * @author dpvc@mathjax.org (Davide Cervone) */ +import { DOM } from '../../types/Types.js'; import { ChtmlWrapper, ChtmlWrapperClass } from './Wrapper.js'; import { ChtmlMath } from './Wrappers/math.js'; import { ChtmlMi } from './Wrappers/mi.js'; @@ -59,7 +60,7 @@ import { ChtmlTextNode } from './Wrappers/TextNode.js'; import { ChtmlHtmlNode } from './Wrappers/HtmlNode.js'; export const ChtmlWrappers: { - [kind: string]: ChtmlWrapperClass; + [kind: string]: ChtmlWrapperClass; } = { [ChtmlMath.kind]: ChtmlMath, [ChtmlMrow.kind]: ChtmlMrow, diff --git a/ts/output/chtml/Wrappers/HtmlNode.ts b/ts/output/chtml/Wrappers/HtmlNode.ts index 1dece474ed..8f549f004b 100644 --- a/ts/output/chtml/Wrappers/HtmlNode.ts +++ b/ts/output/chtml/Wrappers/HtmlNode.ts @@ -30,34 +30,31 @@ import { } from './semantics.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { HtmlNode } from '../../../core/MmlTree/MmlNodes/HtmlNode.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlHtmlNode interface for the CHTML HtmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlHtmlNodeNTD extends ChtmlXmlNodeNTD {} +export interface ChtmlHtmlNodeNTD< + DOM extends DOM_TYPES, +> extends ChtmlXmlNodeNTD {} /** * The ChtmlHtmlNodeClass interface for the CHTML HtmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlHtmlNodeClass extends ChtmlXmlNodeClass< - N, - T, - D -> { +export interface ChtmlHtmlNodeClass< + DOM extends DOM_TYPES, +> extends ChtmlXmlNodeClass { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlHtmlNodeNTD; + parent?: ChtmlWrapper + ): ChtmlHtmlNodeNTD; } /*****************************************************************/ @@ -65,21 +62,13 @@ export interface ChtmlHtmlNodeClass extends ChtmlXmlNodeClass< /** * The ChtmlHtmlNode wrapper class for the MmlHtmlNode class */ -export const ChtmlHtmlNode = (function (): ChtmlHtmlNodeClass< - N, - T, - D -> { - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlHtmlNode - extends ChtmlXmlNode - implements ChtmlHtmlNodeNTD - { - /** - * @override - */ - public static kind = HtmlNode.prototype.kind; - }; -})(); +export class ChtmlHtmlNode + // @ts-expect-error Avoid message about base constructors not having the same type + extends ChtmlXmlNode + implements ChtmlHtmlNodeNTD +{ + /** + * @override + */ + public static kind = HtmlNode.prototype.kind; +} diff --git a/ts/output/chtml/Wrappers/TeXAtom.ts b/ts/output/chtml/Wrappers/TeXAtom.ts index b791dc7adf..036294a1f9 100644 --- a/ts/output/chtml/Wrappers/TeXAtom.ts +++ b/ts/output/chtml/Wrappers/TeXAtom.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonTeXAtom, CommonTeXAtomClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/TeXAtom.js'; import { TeXAtom } from '../../../core/MmlTree/MmlNodes/TeXAtom.js'; import { MmlNode, TEXCLASSNAMES } from '../../../core/MmlTree/MmlNode.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlTeXAtom interface for the CHTML TeXAtom wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlTeXAtomNTD +export interface ChtmlTeXAtomNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonTeXAtom< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlTeXAtomClass interface for the CHTML TeXAtom wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlTeXAtomClass +export interface ChtmlTeXAtomClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonTeXAtomClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlTeXAtomNTD; + parent?: ChtmlWrapper + ): ChtmlTeXAtomNTD; } /*****************************************************************/ @@ -101,26 +79,18 @@ export interface ChtmlTeXAtomClass /** * The ChtmlTeXAtom wrapper class for the MmlTeXAtom class */ -export const ChtmlTeXAtom = (function (): ChtmlTeXAtomClass { +export const ChtmlTeXAtom = (function (): ChtmlTeXAtomClass { const Base = CommonTeXAtomMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlTeXAtomClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlTeXAtomClass >(ChtmlWrapper); - // Avoid message about base constructors not having the same type - // (they should both be ChtmlWrapper, but are thought of as different by typescript) - return class ChtmlTeXAtom extends Base implements ChtmlTeXAtomNTD { + return class ChtmlTeXAtom extends Base implements ChtmlTeXAtomNTD { /** * @override */ @@ -129,7 +99,7 @@ export const ChtmlTeXAtom = (function (): ChtmlTeXAtomClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { super.toCHTML(parents); this.dom.forEach((dom) => this.adaptor.setAttribute( @@ -140,4 +110,4 @@ export const ChtmlTeXAtom = (function (): ChtmlTeXAtomClass { ); } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/TextNode.ts b/ts/output/chtml/Wrappers/TextNode.ts index fa74d6350a..ed9d8fed5d 100644 --- a/ts/output/chtml/Wrappers/TextNode.ts +++ b/ts/output/chtml/Wrappers/TextNode.ts @@ -21,17 +21,10 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlCharData, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; +import { ChtmlCharData } from '../FontData.js'; import { CommonTextNode, CommonTextNodeClass, @@ -40,98 +33,67 @@ import { import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { TextNode } from '../../../core/MmlTree/MmlNode.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlTextNode interface for the CHTML TextNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlTextNodeNTD +export interface ChtmlTextNodeNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonTextNode< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlTextNodeClass interface for the CHTML TextNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlTextNodeClass +export interface ChtmlTextNodeClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonTextNodeClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlTextNodeNTD; + parent?: ChtmlWrapper + ): ChtmlTextNodeNTD; } /*****************************************************************/ /** * The ChtmlTextNode wrapper class for the MmlTextNode class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const ChtmlTextNode = (function (): ChtmlTextNodeClass< - N, - T, - D -> { +export const ChtmlTextNode = (function (): ChtmlTextNodeClass { const Base = CommonTextNodeMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlTextNodeClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlTextNodeClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlTextNode extends Base implements ChtmlTextNodeNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlTextNode extends Base implements ChtmlTextNodeNTD { /** * The TextNode wrapper */ @@ -160,7 +122,7 @@ export const ChtmlTextNode = (function (): ChtmlTextNodeClass< /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { this.markUsed(); const parent = parents[0]; const adaptor = this.adaptor; @@ -193,7 +155,7 @@ export const ChtmlTextNode = (function (): ChtmlTextNodeClass< ) ); if (i < m - 1 || bbox.oc) { - adaptor.setAttribute(node as N, 'noic', 'true'); + adaptor.setAttribute(node as N, 'noic', 'true'); } if (H) { // @@ -202,7 +164,7 @@ export const ChtmlTextNode = (function (): ChtmlTextNodeClass< // the parent element). Only fixes the issue within a given // MathML node, but that is useful for \text{} in particular. // - adaptor.setStyle(node as N, 'padding-top', H); + adaptor.setStyle(node as N, 'padding-top', H); } this.font.charUsage.add([variant, n]); } @@ -219,11 +181,11 @@ export const ChtmlTextNode = (function (): ChtmlTextNodeClass< * @param {N} parent The parent node where the text is being added * @returns {string} The new value for utext */ - protected addUtext(utext: string, variant: string, parent: N): string { + protected addUtext(utext: string, variant: string, parent: N): string { if (utext) { this.adaptor.append(parent, this.jax.unknownText(utext, variant)); } return ''; } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/maction.ts b/ts/output/chtml/Wrappers/maction.ts index 06059d3517..a05c755c71 100644 --- a/ts/output/chtml/Wrappers/maction.ts +++ b/ts/output/chtml/Wrappers/maction.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMaction, CommonMactionClass, @@ -43,62 +36,47 @@ import { TooltipData } from '../../common/Wrappers/maction.js'; import { TextNode } from '../../../core/MmlTree/MmlNode.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { MACTION } from '../../../a11y/semantic-enrich/maction.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMaction interface for the CHTML Maction wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMactionNTD +export interface ChtmlMactionNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMaction< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMactionClass interface for the CHTML Maction wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMactionClass +export interface ChtmlMactionClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMactionClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMactionNTD; + parent?: ChtmlWrapper + ): ChtmlMactionNTD; } /*****************************************************************/ @@ -106,27 +84,19 @@ export interface ChtmlMactionClass /** * The ChtmlMaction wrapper class for the MmlMaction class */ -export const ChtmlMaction = (function (): ChtmlMactionClass { +export const ChtmlMaction = (function (): ChtmlMactionClass { const Base = CommonMactionMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMactionClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMactionClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMaction extends Base implements ChtmlMactionNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMaction extends Base implements ChtmlMactionNTD { /** * @override */ @@ -230,8 +200,8 @@ export const ChtmlMaction = (function (): ChtmlMactionClass { }, [node.html('mjx-tip')] ) - ) as N; - tip.toCHTML([adaptor.firstChild(tool) as N]); + ) as N; + tip.toCHTML([adaptor.firstChild(tool) as N]); // // Set up the event handlers to display and remove the tooltip // @@ -268,19 +238,13 @@ export const ChtmlMaction = (function (): ChtmlMactionClass { ], ], ] as ActionDef< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMactionNTD + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMactionNTD >[]); /*************************************************************/ @@ -288,7 +252,7 @@ export const ChtmlMaction = (function (): ChtmlMactionClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; const chtml = this.standardChtmlNodes(parents); const child = this.selected; @@ -296,4 +260,4 @@ export const ChtmlMaction = (function (): ChtmlMactionClass { this.action(this, this.data); } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/math.ts b/ts/output/chtml/Wrappers/math.ts index 0af4d8cb1d..43f131484d 100644 --- a/ts/output/chtml/Wrappers/math.ts +++ b/ts/output/chtml/Wrappers/math.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMath, CommonMathClass, @@ -40,62 +33,47 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMath } from '../../../core/MmlTree/MmlNodes/math.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMath interface for the CHTML Math wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMathNTD +export interface ChtmlMathNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMath< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMathClass interface for the CHTML Math wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMathClass +export interface ChtmlMathClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMathClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMathNTD; + parent?: ChtmlWrapper + ): ChtmlMathNTD; } /*****************************************************************/ @@ -103,30 +81,20 @@ export interface ChtmlMathClass /** * The ChtmlMath wrapper class for the MmlMath class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export const ChtmlMath = (function (): ChtmlMathClass { +export const ChtmlMath = (function (): ChtmlMathClass { const Base = CommonMathMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMathClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMathClass >(ChtmlWrapper); - // Avoid message about base constructors not having the same type - // (they should both be ChtmlWrapper, but are thought of as different by typescript) - return class ChtmlMath extends Base implements ChtmlMathNTD { + return class ChtmlMath extends Base implements ChtmlMathNTD { /** * @override */ @@ -191,7 +159,7 @@ export const ChtmlMath = (function (): ChtmlMathClass { * * @param {N} parent The HTML node to contain the HTML */ - protected handleDisplay(parent: N) { + protected handleDisplay(parent: N) { const adaptor = this.adaptor; const [align, shift] = this.getAlignShift(); if (align !== 'center') { @@ -222,7 +190,7 @@ export const ChtmlMath = (function (): ChtmlMathClass { * * @param {N} parent The HTML node to contain the HTML */ - protected handleInline(parent: N) { + protected handleInline(parent: N) { // // Transfer right margin to container (for things like $x\hskip -2em y$) // @@ -240,7 +208,7 @@ export const ChtmlMath = (function (): ChtmlMathClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { super.toCHTML(parents); const adaptor = this.adaptor; const display = this.node.attributes.get('display') === 'block'; @@ -278,4 +246,4 @@ export const ChtmlMath = (function (): ChtmlMathClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/menclose.ts b/ts/output/chtml/Wrappers/menclose.ts index 4b89f54c64..9262affe97 100644 --- a/ts/output/chtml/Wrappers/menclose.ts +++ b/ts/output/chtml/Wrappers/menclose.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMenclose, CommonMencloseClass, @@ -43,6 +36,7 @@ import * as Notation from '../Notation.js'; import { OptionList } from '../../../util/Options.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { em } from '../../../util/lengths.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ @@ -65,41 +59,33 @@ const ANGLE = Angle(Notation.ARROWDX, Notation.ARROWY); /** * The ChtmlMenclose interface for the CHTML Menclose wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMencloseNTD +export interface ChtmlMencloseNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMenclose< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMsqrtNTD + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMsqrtNTD > { /** * @param {N} node The HTML element whose border width must be * adjusted if the thickness isn't the default * @returns {N} The adjusted element */ - adjustBorder(node: N): N; + adjustBorder(node: N): N; /** * @param {N} shape The svg element whose stroke-thickness must be * adjusted if the thickness isn't the default * @returns {N} The adjusted element */ - adjustThickness(shape: N): N; + adjustThickness(shape: N): N; /** * @param {number} m A number to be shown with a fixed number of digits @@ -120,32 +106,24 @@ export interface ChtmlMencloseNTD /** * The ChtmlMencloseClass interface for the CHTML Menclose wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMencloseClass +export interface ChtmlMencloseClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMencloseClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMencloseNTD; + parent?: ChtmlWrapper + ): ChtmlMencloseNTD; } /*****************************************************************/ @@ -153,36 +131,22 @@ export interface ChtmlMencloseClass /** * The ChtmlMenclose wrapper class for the MmlMenclose class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export const ChtmlMenclose = (function (): ChtmlMencloseClass< - N, - T, - D -> { +export const ChtmlMenclose = (function (): ChtmlMencloseClass { const Base = CommonMencloseMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMsqrtNTD, - ChtmlMencloseClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMsqrtNTD, + ChtmlMencloseClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMenclose extends Base implements ChtmlMencloseNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMenclose extends Base implements ChtmlMencloseNTD { /** * @override */ @@ -358,7 +322,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< /** * @override */ - public static notations: Notation.DefList, N> = + public static notations: Notation.DefList, N> = new Map([ Notation.Border('top'), Notation.Border('right'), @@ -487,11 +451,11 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< const arc1 = adaptor.append( node.dom[0], node.html('mjx-dbox-top') - ) as N; + ) as N; const arc2 = adaptor.append( node.dom[0], node.html('mjx-dbox-bot') - ) as N; + ) as N; const t = node.thickness; const p = node.padding; if (t !== Notation.THICKNESS) { @@ -543,7 +507,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< renderChild: true, }, ], - ] as Notation.DefPair, N>[]); + ] as Notation.DefPair, N>[]); /********************************************************/ @@ -551,7 +515,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< * @param {N} arrow The arrow whose thickness and arrow head is to be adjusted * @param {boolean} double True if the arrow is double-headed */ - protected adjustArrow(arrow: N, double: boolean) { + protected adjustArrow(arrow: N, double: boolean) { const t = this.thickness; const head = this.arrowhead; if ( @@ -565,7 +529,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< const a = Angle(head.dx, head.y); const [line, rthead, rbhead, lthead, lbhead] = this.adaptor.childNodes( arrow - ) as N[]; + ) as N[]; this.adjustHead(rthead, [y, '0', '1px', x], a); this.adjustHead(rbhead, ['1px', '0', y, x], '-' + a); this.adjustHead(lthead, [y, x, '1px', '0'], '-' + a); @@ -578,7 +542,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< * @param {string[]} border The border sizes [T, R, B, L] * @param {string} a The skew angle for the piece */ - protected adjustHead(head: N, border: string[], a: string) { + protected adjustHead(head: N, border: string[], a: string) { if (head) { this.adaptor.setStyle(head, 'border-width', border.join(' ')); this.adaptor.setStyle(head, 'transform', 'skewX(' + a + 'rad)'); @@ -591,7 +555,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< * @param {number} x The arrow head x size * @param {boolean} double True if the arrow is double-headed */ - protected adjustLine(line: N, t: number, x: number, double: boolean) { + protected adjustLine(line: N, t: number, x: number, double: boolean) { this.adaptor.setStyle(line, 'borderTop', this.em(t) + ' solid'); this.adaptor.setStyle(line, 'top', this.em(-t / 2)); this.adaptor.setStyle(line, 'right', this.em(t * (x - 1))); @@ -605,7 +569,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< * @param {string} offset The direction to move the arrow * @param {number} d The distance to translate in that direction */ - protected moveArrow(arrow: N, offset: string, d: number) { + protected moveArrow(arrow: N, offset: string, d: number) { if (!d) return; const transform = this.adaptor.getStyle(arrow, 'transform'); this.adaptor.setStyle( @@ -620,7 +584,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< /** * @override */ - public adjustBorder(node: N): N { + public adjustBorder(node: N): N { if (this.thickness !== Notation.THICKNESS) { this.adaptor.setStyle(node, 'borderWidth', this.em(this.thickness)); } @@ -630,7 +594,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< /** * @override */ - public adjustThickness(shape: N): N { + public adjustThickness(shape: N): N { if (this.thickness !== Notation.THICKNESS) { this.adaptor.setStyle(shape, 'strokeWidth', this.fixed(this.thickness)); } @@ -662,14 +626,14 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { const adaptor = this.adaptor; const chtml = this.standardChtmlNodes(parents); // // Create a box for the child (that can have padding and borders added by the notations) // and add the child HTML into it // - const block = adaptor.append(chtml[0], this.html('mjx-box')) as N; + const block = adaptor.append(chtml[0], this.html('mjx-box')) as N; if (this.renderChild) { this.renderChild(this, block); } else { @@ -705,7 +669,7 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< double: boolean, offset: string = '', dist: number = 0 - ): N { + ): N { const W = this.getBBox().w; const style = { width: this.em(w) } as OptionList; if (W !== w) { @@ -729,4 +693,4 @@ export const ChtmlMenclose = (function (): ChtmlMencloseClass< return arrow; } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mfenced.ts b/ts/output/chtml/Wrappers/mfenced.ts index 5d18bade31..f29aad2422 100644 --- a/ts/output/chtml/Wrappers/mfenced.ts +++ b/ts/output/chtml/Wrappers/mfenced.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMfenced, CommonMfencedClass, @@ -39,62 +32,47 @@ import { import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMfenced } from '../../../core/MmlTree/MmlNodes/mfenced.js'; import { ChtmlInferredMrowNTD } from './mrow.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMfenced interface for the CHTML Mfenced wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMfencedNTD +export interface ChtmlMfencedNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMfenced< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMfencedClass interface for the CHTML Mfenced wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMfencedClass +export interface ChtmlMfencedClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMfencedClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMfencedNTD; + parent?: ChtmlWrapper + ): ChtmlMfencedNTD; } /*****************************************************************/ @@ -102,27 +80,19 @@ export interface ChtmlMfencedClass /** * The ChtmlMfenced wrapper class for the MmlMfenced class */ -export const ChtmlMfenced = (function (): ChtmlMfencedClass { +export const ChtmlMfenced = (function (): ChtmlMfencedClass { const Base = CommonMfencedMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMfencedClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMfencedClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMfenced extends Base implements ChtmlMfencedNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMfenced extends Base implements ChtmlMfencedNTD { /** * @override */ @@ -131,9 +101,9 @@ export const ChtmlMfenced = (function (): ChtmlMfencedClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { const chtml = this.standardChtmlNodes(parents); - (this.mrow as ChtmlInferredMrowNTD).toCHTML(chtml); + (this.mrow as ChtmlInferredMrowNTD).toCHTML(chtml); } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mfrac.ts b/ts/output/chtml/Wrappers/mfrac.ts index 4c655dd594..7c03316f1e 100644 --- a/ts/output/chtml/Wrappers/mfrac.ts +++ b/ts/output/chtml/Wrappers/mfrac.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMfrac, CommonMfracClass, @@ -41,62 +34,47 @@ import { MmlMfrac } from '../../../core/MmlTree/MmlNodes/mfrac.js'; import { ChtmlMoNTD } from './mo.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { OptionList } from '../../../util/Options.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMfrac interface for the CHTML Mfrac wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlMfracNTD +export interface ChtmlMfracNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMfrac< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMfracClass interface for the CHTML Mfrac wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlMfracClass +export interface ChtmlMfracClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMfracClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMfracNTD; + parent?: ChtmlWrapper + ): ChtmlMfracNTD; } /*****************************************************************/ @@ -104,27 +82,19 @@ export interface ChtmlMfracClass /** * The ChtmlMfrac wrapper class for the MmlMfrac class */ -export const ChtmlMfrac = (function (): ChtmlMfracClass { +export const ChtmlMfrac = (function (): ChtmlMfracClass { const Base = CommonMfracMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMfracClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMfracClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMfrac extends Base implements ChtmlMfracNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMfrac extends Base implements ChtmlMfracNTD { /** * @override */ @@ -133,103 +103,101 @@ export const ChtmlMfrac = (function (): ChtmlMfracClass { /** * @override */ - /* prettier-ignore */ public static styles: StyleJson = { 'mjx-frac': { display: 'inline-block', - 'vertical-align': '0.17em', // axis_height - 1.5 * rule_thickness - padding: '0 .22em' // nulldelimiterspace + .1 (for line's -.1em margin) + 'vertical-align': '0.17em', // axis_height - 1.5 * rule_thickness + padding: '0 .22em', // nulldelimiterspace + .1 (for line's -.1em margin) }, 'mjx-frac[type="d"]': { - 'vertical-align': '.04em' // axis_height - 3.5 * rule_thickness + 'vertical-align': '.04em', // axis_height - 3.5 * rule_thickness }, 'mjx-frac[delims]': { - padding: '0 .1em' // .1 (for line's -.1em margin) + padding: '0 .1em', // .1 (for line's -.1em margin) }, 'mjx-frac[atop]': { - padding: '0 .12em' // nulldelimiterspace + padding: '0 .12em', // nulldelimiterspace }, 'mjx-frac[atop][delims]': { - padding: '0' + padding: '0', }, 'mjx-dtable': { display: 'inline-table', - width: '100%' + width: '100%', }, 'mjx-dtable > mjx-line, mjx-dtable > mjx-row': { - 'font-size': '2000%' + 'font-size': '2000%', }, 'mjx-dbox': { display: 'block', - 'font-size': '5%' + 'font-size': '5%', }, 'mjx-num': { display: 'block', - 'text-align': 'center' + 'text-align': 'center', }, 'mjx-den': { display: 'block', - 'text-align': 'center' + 'text-align': 'center', }, 'mjx-mfrac[bevelled] > mjx-num': { - display: 'inline-block' + display: 'inline-block', }, 'mjx-mfrac[bevelled] > mjx-den': { - display: 'inline-block' + display: 'inline-block', }, 'mjx-den[align="right"], mjx-num[align="right"]': { - 'text-align': 'right' + 'text-align': 'right', }, 'mjx-den[align="left"], mjx-num[align="left"]': { - 'text-align': 'left' + 'text-align': 'left', }, 'mjx-nstrut': { display: 'inline-block', - height: '.054em', // num2 - a - 1.5t + height: '.054em', // num2 - a - 1.5t width: 0, - 'vertical-align': '-.054em' // ditto + 'vertical-align': '-.054em', // Ditto }, 'mjx-nstrut[type="d"]': { - height: '.217em', // num1 - a - 3.5t - 'vertical-align': '-.217em', // ditto + height: '.217em', // num1 - a - 3.5t + 'vertical-align': '-.217em', // Ditto }, 'mjx-dstrut': { display: 'inline-block', - height: '.505em', // denom2 + a - 1.5t - width: 0 + height: '.505em', // denom2 + a - 1.5t + width: 0, }, 'mjx-dstrut[type="d"]': { - height: '.726em', // denom1 + a - 3.5t + height: '.726em', // denom1 + a - 3.5t }, 'mjx-line': { display: 'block', 'box-sizing': 'border-box', 'min-height': '1px', - height: '.06em', // t = rule_thickness - 'border-top': '.075em solid', // t * rule_factor (extra thickness as borders tend to be thin) - margin: '.06em -.1em', // t - overflow: 'hidden' + height: '.06em', // t = rule_thickness + 'border-top': '.075em solid', // t * rule_factor (extra thickness as borders tend to be thin) + margin: '.06em -.1em', // t + overflow: 'hidden', }, 'mjx-line[type="d"]': { - margin: '.18em -.1em' // 3t - } - + margin: '.18em -.1em', // 3t + }, }; /** * An mo element to use for bevelled fractions */ - protected bevel: ChtmlMoNTD; + protected bevel: ChtmlMoNTD; /************************************************/ /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; this.standardChtmlNodes(parents); const { linethickness, bevelled } = this.node.attributes.getList( @@ -380,10 +348,10 @@ export const ChtmlMfrac = (function (): ChtmlMfracClass { // Create HTML tree // adaptor.setAttribute(this.dom[0], 'bevelled', 'ture'); - const num = adaptor.append(this.dom[0], this.html('mjx-num')) as N; + const num = adaptor.append(this.dom[0], this.html('mjx-num')) as N; this.childNodes[0].toCHTML([num]); this.bevel.toCHTML(this.dom); - const den = adaptor.append(this.dom[0], this.html('mjx-den')) as N; + const den = adaptor.append(this.dom[0], this.html('mjx-den')) as N; this.childNodes[1].toCHTML([den]); // // Place the parts @@ -400,4 +368,4 @@ export const ChtmlMfrac = (function (): ChtmlMfracClass { adaptor.setStyle(this.bevel.dom[0], 'marginRight', dx); } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mglyph.ts b/ts/output/chtml/Wrappers/mglyph.ts index 00e64a8052..5a30bb1e01 100644 --- a/ts/output/chtml/Wrappers/mglyph.ts +++ b/ts/output/chtml/Wrappers/mglyph.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMglyph, CommonMglyphClass, @@ -40,62 +33,47 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMglyph } from '../../../core/MmlTree/MmlNodes/mglyph.js'; import { ChtmlTextNodeNTD } from './TextNode.js'; import { StyleJson, StyleJsonData } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMglyph interface for the CHTML Mglyph wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM nod types */ -export interface ChtmlMglyphNTD +export interface ChtmlMglyphNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMglyph< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMglyphClass interface for the CHTML Mglyph wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM nod types */ -export interface ChtmlMglyphClass +export interface ChtmlMglyphClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMglyphClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMglyphNTD; + parent?: ChtmlWrapper + ): ChtmlMglyphNTD; } /*****************************************************************/ @@ -103,27 +81,19 @@ export interface ChtmlMglyphClass /** * The ChtmlMglyph wrapper class for the MmlMglyph class */ -export const ChtmlMglyph = (function (): ChtmlMglyphClass { +export const ChtmlMglyph = (function (): ChtmlMglyphClass { const Base = CommonMglyphMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMglyphClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMglyphClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMglyph extends Base implements ChtmlMglyphNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMglyph extends Base implements ChtmlMglyphNTD { /** * @override */ @@ -143,10 +113,10 @@ export const ChtmlMglyph = (function (): ChtmlMglyphClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { const chtml = this.standardChtmlNodes(parents); if (this.charWrapper) { - (this.charWrapper as ChtmlTextNodeNTD).toCHTML(chtml); + (this.charWrapper as ChtmlTextNodeNTD).toCHTML(chtml); return; } const { src, alt } = this.node.attributes.getList('src', 'alt'); @@ -166,4 +136,4 @@ export const ChtmlMglyph = (function (): ChtmlMglyphClass { this.adaptor.append(chtml[0], img); } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mi.ts b/ts/output/chtml/Wrappers/mi.ts index 92e7cbe3b8..1d7a47403b 100644 --- a/ts/output/chtml/Wrappers/mi.ts +++ b/ts/output/chtml/Wrappers/mi.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMi, CommonMiClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mi.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMi } from '../../../core/MmlTree/MmlNodes/mi.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMi interface for the CHTML Mi wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMiNTD +export interface ChtmlMiNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMi< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMiClass interface for the CHTML Mi wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMiClass +export interface ChtmlMiClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMiClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMiNTD; + parent?: ChtmlWrapper + ): ChtmlMiNTD; } /*****************************************************************/ @@ -101,29 +79,21 @@ export interface ChtmlMiClass /** * The ChtmlMi wrapper class for the MmlMi class */ -export const ChtmlMi = (function (): ChtmlMiClass { +export const ChtmlMi = (function (): ChtmlMiClass { const Base = CommonMiMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMiClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMiClass >(ChtmlWrapper); - // Avoid message about base constructors not having the same type - // (they should both be ChtmlWrapper, but are thought of as different by typescript) - return class ChtmlMi extends Base implements ChtmlMiNTD { + return class ChtmlMi extends Base implements ChtmlMiNTD { /** * @override */ public static kind = MmlMi.prototype.kind; }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mmultiscripts.ts b/ts/output/chtml/Wrappers/mmultiscripts.ts index 421ae303b1..e1301b05be 100644 --- a/ts/output/chtml/Wrappers/mmultiscripts.ts +++ b/ts/output/chtml/Wrappers/mmultiscripts.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMmultiscripts, CommonMmultiscriptsClass, @@ -42,100 +35,69 @@ import { MmlMmultiscripts } from '../../../core/MmlTree/MmlNodes/mmultiscripts.j import { BBox } from '../../../util/BBox.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { split } from '../../../util/string.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMmultiscripts interface for the CHTML Mmultiscripts wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM types */ -export interface ChtmlMmultiscriptsNTD +export interface ChtmlMmultiscriptsNTD extends - ChtmlMsubsupNTD, + ChtmlMsubsupNTD, CommonMmultiscripts< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMmultiscriptsClass interface for the CHTML Mmultiscripts wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM types */ -export interface ChtmlMmultiscriptsClass +export interface ChtmlMmultiscriptsClass extends - ChtmlMsubsupClass, + ChtmlMsubsupClass, CommonMmultiscriptsClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMmultiscriptsNTD; + parent?: ChtmlWrapper + ): ChtmlMmultiscriptsNTD; } /*****************************************************************/ /** * The ChtmlMmultiscripts wrapper class for the MmlMmultiscripts class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const ChtmlMmultiscripts = (function < - N, - T, - D, ->(): ChtmlMmultiscriptsClass { +export const ChtmlMmultiscripts = (function (): ChtmlMmultiscriptsClass { const Base = CommonMmultiscriptsMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMmultiscriptsClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMmultiscriptsClass >(ChtmlMsubsup); return class ChtmlMmultiscripts - // @ts-expect-error Avoid message about base constructors not having the - // same type (they should both be ChtmlWrapper, but are thought of - // as different by typescript) + // @ts-expect-error Avoid message about base constructors not having the same type extends Base - implements ChtmlMmultiscriptsNTD + implements ChtmlMmultiscriptsNTD { /** * @override @@ -180,7 +142,7 @@ export const ChtmlMmultiscripts = (function < /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; const chtml = this.standardChtmlNodes(parents); const data = this.scriptData; @@ -244,7 +206,7 @@ export const ChtmlMmultiscripts = (function < * @returns {N} The script table for these scripts */ protected addScripts( - dom: N, + dom: N, u: number, v: number, isPre: boolean, @@ -252,7 +214,7 @@ export const ChtmlMmultiscripts = (function < sup: BBox, i: number, n: number - ): N { + ): N { const adaptor = this.adaptor; const q = u - sup.d + (v - sub.h); // separation of scripts const U = u < 0 && v === 0 ? sub.h + u : u; // vertical offset of table @@ -265,16 +227,16 @@ export const ChtmlMmultiscripts = (function < const m = i + 2 * n; while (i < m) { this.childNodes[i++].toCHTML([ - adaptor.append(subRow, this.html('mjx-cell')) as N, + adaptor.append(subRow, this.html('mjx-cell')) as N, ]); this.childNodes[i++].toCHTML([ - adaptor.append(supRow, this.html('mjx-cell')) as N, + adaptor.append(supRow, this.html('mjx-cell')) as N, ]); } return adaptor.append( dom, this.html(name, tabledef, [supRow, sepRow, subRow]) - ) as N; + ) as N; } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mn.ts b/ts/output/chtml/Wrappers/mn.ts index 4477a37e85..1cd6c54a92 100644 --- a/ts/output/chtml/Wrappers/mn.ts +++ b/ts/output/chtml/Wrappers/mn.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMn, CommonMnClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mn.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMn } from '../../../core/MmlTree/MmlNodes/mn.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMn interface for the CHTML Mn wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMnNTD +export interface ChtmlMnNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMn< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMnClass interface for the CHTML Mn wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMnClass +export interface ChtmlMnClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMnClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMnNTD; + parent?: ChtmlWrapper + ): ChtmlMnNTD; } /*****************************************************************/ @@ -101,29 +79,21 @@ export interface ChtmlMnClass /** * The ChtmlMn wrapper class for the MmlMn class */ -export const ChtmlMn = (function (): ChtmlMnClass { +export const ChtmlMn = (function (): ChtmlMnClass { const Base = CommonMnMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMnClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMnClass >(ChtmlWrapper); - // Avoid message about base constructors not having the same type - // (they should both be ChtmlWrapper, but are thought of as different by typescript) - return class ChtmlMn extends Base implements ChtmlMnNTD { + return class ChtmlMn extends Base implements ChtmlMnNTD { /** * @override */ public static kind = MmlMn.prototype.kind; }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mo.ts b/ts/output/chtml/Wrappers/mo.ts index 7aaaf65927..53d4cd881a 100644 --- a/ts/output/chtml/Wrappers/mo.ts +++ b/ts/output/chtml/Wrappers/mo.ts @@ -21,18 +21,10 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass, StringMap } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - VFUZZ, - HFUZZ, -} from '../FontData.js'; +import { ChtmlCharOptions, VFUZZ, HFUZZ } from '../FontData.js'; import { CharDataArray } from '../../common/FontData.js'; import { CommonMo, @@ -43,62 +35,47 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMo } from '../../../core/MmlTree/MmlNodes/mo.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { DIRECTION } from '../FontData.js'; +import { DOM, DOM_TYPES, N, NT } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMo interface for the CHTML Mo wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMoNTD +export interface ChtmlMoNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMo< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMoClass interface for the CHTML Mo wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMoClass +export interface ChtmlMoClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMoClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMoNTD; + parent?: ChtmlWrapper + ): ChtmlMoNTD; } export type PartData = CharDataArray; @@ -107,32 +84,20 @@ export type PartData = CharDataArray; /** * The ChtmlMo wrapper class for the MmlMo class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const ChtmlMo = (function (): ChtmlMoClass { +export const ChtmlMo = (function (): ChtmlMoClass { const Base = CommonMoMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMoClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMoClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMo extends Base implements ChtmlMoNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMo extends Base implements ChtmlMoNTD { /** * @override */ @@ -191,7 +156,7 @@ export const ChtmlMo = (function (): ChtmlMoClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { const adaptor = this.adaptor; const attributes = this.node.attributes; const symmetric = @@ -247,14 +212,14 @@ export const ChtmlMo = (function (): ChtmlMoClass { * * @param {N} chtml The parent element in which to put the delimiter */ - protected stretchHTML(chtml: N[]) { + protected stretchHTML(chtml: N[]) { const c = this.getText().codePointAt(0); this.font.delimUsage.add(c); this.childNodes[0].markUsed(); const delim = this.stretch; const stretch = delim.stretch; const stretchv = this.font.getStretchVariants(c); - const dom: N[] = []; + const dom: N[] = []; // // Look up the characters to use @@ -317,7 +282,7 @@ export const ChtmlMo = (function (): ChtmlMoClass { parts: PartData[], sn: number[], sv: string[], - dom: N[], + dom: N[], wh: number, ext: number, nl: string = '' @@ -372,7 +337,7 @@ export const ChtmlMo = (function (): ChtmlMoClass { data: PartData, n: number, v: string, - dom: N[], + dom: N[], W: number = 0, Wx: number = 0, nl: string = '', @@ -386,7 +351,7 @@ export const ChtmlMo = (function (): ChtmlMoClass { const font = options.ff || (letter ? `${this.font.cssFontPrefix}-${letter}` : ''); const c = options.c || String.fromCodePoint(n); - let nodes = [] as (N | T)[]; + let nodes = [] as NT[]; if (part === 'mjx-ext' && (Wx || options.dx)) { // // If the top and bottom must overlap, adjust the border sizes and remove the clipping @@ -431,4 +396,4 @@ export const ChtmlMo = (function (): ChtmlMoClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mpadded.ts b/ts/output/chtml/Wrappers/mpadded.ts index 43ab05badf..e564f63280 100644 --- a/ts/output/chtml/Wrappers/mpadded.ts +++ b/ts/output/chtml/Wrappers/mpadded.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass, StringMap } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMpadded, CommonMpaddedClass, @@ -39,62 +32,47 @@ import { import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMpadded } from '../../../core/MmlTree/MmlNodes/mpadded.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMpadded interface for the CHTML Mpadded wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlMpaddedNTD +export interface ChtmlMpaddedNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMpadded< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMpaddedClass interface for the CHTML Mpadded wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlMpaddedClass +export interface ChtmlMpaddedClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMpaddedClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMpaddedNTD; + parent?: ChtmlWrapper + ): ChtmlMpaddedNTD; } /*****************************************************************/ @@ -102,27 +80,19 @@ export interface ChtmlMpaddedClass /** * The ChtmlMpadded wrapper class for the MmlMpadded class */ -export const ChtmlMpadded = (function (): ChtmlMpaddedClass { +export const ChtmlMpadded = (function (): ChtmlMpaddedClass { const Base = CommonMpaddedMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMpaddedClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMpaddedClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMpadded extends Base implements ChtmlMpaddedNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMpadded extends Base implements ChtmlMpaddedNTD { /** * @override */ @@ -144,10 +114,10 @@ export const ChtmlMpadded = (function (): ChtmlMpaddedClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; let chtml = this.standardChtmlNodes(parents); - const content: N[] = []; + const content: N[] = []; const style: StringMap = {}; const [, , W, dh, dd, dw, x, y, dx] = this.getDimens(); // @@ -188,7 +158,7 @@ export const ChtmlMpadded = (function (): ChtmlMpaddedClass { this.adaptor.append( chtml[0], this.html('mjx-block', { style: style }, content) - ) as N, + ) as N, ]; if (this.childNodes[0].childNodes.length) { this.childNodes[0].toCHTML([content[0] || chtml[0]]); @@ -198,4 +168,4 @@ export const ChtmlMpadded = (function (): ChtmlMpaddedClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mroot.ts b/ts/output/chtml/Wrappers/mroot.ts index e4e5c790fe..ad8eb0ceb5 100644 --- a/ts/output/chtml/Wrappers/mroot.ts +++ b/ts/output/chtml/Wrappers/mroot.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMroot, CommonMrootClass, @@ -40,62 +33,47 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { ChtmlMsqrt, ChtmlMsqrtClass, ChtmlMsqrtNTD } from './msqrt.js'; import { BBox } from '../../../util/BBox.js'; import { MmlMroot } from '../../../core/MmlTree/MmlNodes/mroot.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMroot interface for the CHTML Mroot wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMrootNTD +export interface ChtmlMrootNTD extends - ChtmlMsqrtNTD, + ChtmlMsqrtNTD, CommonMroot< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMrootClass interface for the CHTML Mroot wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMrootClass +export interface ChtmlMrootClass extends - ChtmlMsqrtClass, + ChtmlMsqrtClass, CommonMrootClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMrootNTD; + parent?: ChtmlWrapper + ): ChtmlMrootNTD; } /*****************************************************************/ @@ -103,27 +81,19 @@ export interface ChtmlMrootClass /** * The ChtmlMroot wrapper class for the MmlMroot class */ -export const ChtmlMroot = (function (): ChtmlMrootClass { +export const ChtmlMroot = (function (): ChtmlMrootClass { const Base = CommonMrootMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMrootClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMrootClass >(ChtmlMsqrt); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMroot extends Base implements ChtmlMrootNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMroot extends Base implements ChtmlMrootNTD { /** * @override */ @@ -133,8 +103,8 @@ export const ChtmlMroot = (function (): ChtmlMrootClass { * @override */ protected addRoot( - ROOT: N, - root: ChtmlWrapper, + ROOT: N, + root: ChtmlWrapper, sbox: BBox, H: number ) { @@ -145,11 +115,11 @@ export const ChtmlMroot = (function (): ChtmlMrootClass { adaptor.setStyle(ROOT, 'width', this.em(x)); if (dx) { adaptor.setStyle( - adaptor.firstChild(ROOT) as N, + adaptor.firstChild(ROOT) as N, 'paddingLeft', this.em(dx) ); } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mrow.ts b/ts/output/chtml/Wrappers/mrow.ts index e27fb27ceb..fe67b395a7 100644 --- a/ts/output/chtml/Wrappers/mrow.ts +++ b/ts/output/chtml/Wrappers/mrow.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMrow, CommonMrowClass, @@ -47,94 +40,67 @@ import { MmlInferredMrow, } from '../../../core/MmlTree/MmlNodes/mrow.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMrow interface for the CHTML Mrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMrowNTD +export interface ChtmlMrowNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMrow< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMrowClass interface for the CHTML Mrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMrowClass +export interface ChtmlMrowClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMrowClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMrowNTD; + parent?: ChtmlWrapper + ): ChtmlMrowNTD; } /*****************************************************************/ /** * The ChtmlMrow wrapper class for the MmlMrow class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const ChtmlMrow = (function (): ChtmlMrowClass { +export const ChtmlMrow = (function (): ChtmlMrowClass { const Base = CommonMrowMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMrowClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMrowClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMrow extends Base implements ChtmlMrowNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMrow extends Base implements ChtmlMrowNTD { /** * @override */ @@ -210,7 +176,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { const n = (this.linebreakCount = this.isStack ? 0 : this.breakCount); if (n || !this.node.isInferred) { parents = this.standardChtmlNodes(parents); @@ -230,7 +196,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { * @param {N[]} parents The HTML nodes in which to place the lines * @param {number} n The number of lines */ - protected placeLines(parents: N[], n: number) { + protected placeLines(parents: N[], n: number) { this.getBBox(); // make sure we have linebreak information const lines = this.lineBBox; const adaptor = this.adaptor; @@ -267,7 +233,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { /** * @param {N} dom The HTML element for the mrow */ - protected handleVerticalAlign(dom: N) { + protected handleVerticalAlign(dom: N) { if (this.dh) { this.adaptor.setStyle( this.adaptor.parent(dom), @@ -280,7 +246,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { /** * @param {N} dom The HTML element for the mrow */ - protected handleNegativeWidth(dom: N) { + protected handleNegativeWidth(dom: N) { const { w } = this.getBBox(); if (w < 0) { this.adaptor.setStyle(dom, 'width', this.em(Math.max(0, w))); @@ -291,7 +257,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { /** * @override */ - protected createChtmlNodes(parents: N[]): N[] { + protected createChtmlNodes(parents: N[]): N[] { const n = this.linebreakCount; if (!n) return super.createChtmlNodes(parents); // @@ -301,7 +267,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { const kind = this.node.isInferred ? 'mjx-linestack' : 'mjx-' + this.node.kind; - this.dom = [adaptor.append(parents[0], this.html(kind)) as N]; + this.dom = [adaptor.append(parents[0], this.html(kind)) as N]; if (kind === 'mjx-mrow' && !this.isStack) { adaptor.setAttribute(this.dom[0], 'break-top', 'true'); } @@ -320,17 +286,17 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { // Add an href anchor, if needed, and insert the linestack/mrow // this.dom = [ - adaptor.append(this.handleHref(parents)[0], this.dom[0]) as N, + adaptor.append(this.handleHref(parents)[0], this.dom[0]) as N, ]; // // Add the line boxes // - const chtml = Array(n) as N[]; + const chtml = Array(n) as N[]; for (let i = 0; i <= n; i++) { chtml[i] = adaptor.append( this.dom[0], this.html('mjx-linebox', { lineno: i }) - ) as N; + ) as N; } // // Return the line boxes as the parent nodes for their contents @@ -341,7 +307,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { /** * @override */ - public addChildren(parents: N[]) { + public addChildren(parents: N[]) { let i = 0; for (const child of this.childNodes) { const n = child.breakCount; @@ -350,7 +316,7 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { } } }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -358,57 +324,41 @@ export const ChtmlMrow = (function (): ChtmlMrowClass { /** * The ChtmlInferredMrow interface for the CHTML InferredMrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlInferredMrowNTD +export interface ChtmlInferredMrowNTD extends - ChtmlMrowNTD, + ChtmlMrowNTD, CommonInferredMrow< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlInferredMrowClass interface for the CHTML InferredMrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlInferredMrowClass +export interface ChtmlInferredMrowClass extends - ChtmlMrowClass, + ChtmlMrowClass, CommonInferredMrowClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlInferredMrowNTD; + parent?: ChtmlWrapper + ): ChtmlInferredMrowNTD; } /*****************************************************************/ @@ -416,37 +366,25 @@ export interface ChtmlInferredMrowClass /** * The ChtmlInferredMrow wrapper class for the MmlInferredMrow class */ -export const ChtmlInferredMrow = (function (): ChtmlInferredMrowClass< - N, - T, - D -> { +export const ChtmlInferredMrow = (function (): ChtmlInferredMrowClass { const Base = CommonInferredMrowMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlInferredMrowClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlInferredMrowClass >(ChtmlMrow); return class ChtmlInferredMrow - // @ts-expect-error Avoid message about base constructors not having the - // same type (they should both be ChtmlWrapper, but are thought of - // as different by typescript) + // @ts-expect-error Avoid message about base constructors not having the same type extends Base - implements ChtmlInferredMrowNTD + implements ChtmlInferredMrowNTD { /** * @override */ public static kind = MmlInferredMrow.prototype.kind; }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/ms.ts b/ts/output/chtml/Wrappers/ms.ts index dba152e8ac..8f81c86a3e 100644 --- a/ts/output/chtml/Wrappers/ms.ts +++ b/ts/output/chtml/Wrappers/ms.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMs, CommonMsClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/ms.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMs } from '../../../core/MmlTree/MmlNodes/ms.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMs interface for the CHTML Ms wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlMsNTD +export interface ChtmlMsNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMs< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMsClass interface for the CHTML Ms wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM THe DOM node types */ -export interface ChtmlMsClass +export interface ChtmlMsClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMsClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMsNTD; + parent?: ChtmlWrapper + ): ChtmlMsNTD; } /*****************************************************************/ @@ -101,30 +79,22 @@ export interface ChtmlMsClass /** * The ChtmlMs wrapper class for the MmlMs class */ -export const ChtmlMs = (function (): ChtmlMsClass { +export const ChtmlMs = (function (): ChtmlMsClass { const Base = CommonMsMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMsClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMsClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMs extends Base implements ChtmlMsNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMs extends Base implements ChtmlMsNTD { /** * @override */ public static kind = MmlMs.prototype.kind; }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mspace.ts b/ts/output/chtml/Wrappers/mspace.ts index a7a0296503..92158d9713 100644 --- a/ts/output/chtml/Wrappers/mspace.ts +++ b/ts/output/chtml/Wrappers/mspace.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMspace, CommonMspaceClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mspace.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMspace } from '../../../core/MmlTree/MmlNodes/mspace.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMspace interface for the CHTML Mspace wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMspaceNTD +export interface ChtmlMspaceNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMspace< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMspaceClass interface for the CHTML Mspace wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMspaceClass +export interface ChtmlMspaceClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMspaceClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMspaceNTD; + parent?: ChtmlWrapper + ): ChtmlMspaceNTD; } /*****************************************************************/ @@ -101,27 +79,19 @@ export interface ChtmlMspaceClass /** * The ChtmlMspace wrapper class for the MmlMspace class */ -export const ChtmlMspace = (function (): ChtmlMspaceClass { +export const ChtmlMspace = (function (): ChtmlMspaceClass { const Base = CommonMspaceMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMspaceClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMspaceClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMspace extends Base implements ChtmlMspaceNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMspace extends Base implements ChtmlMspaceNTD { /** * @override */ @@ -130,7 +100,7 @@ export const ChtmlMspace = (function (): ChtmlMspaceClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (parents.length > 1) { parents.forEach((dom) => this.adaptor.append(dom, this.html('mjx-linestrut')) @@ -154,4 +124,4 @@ export const ChtmlMspace = (function (): ChtmlMspaceClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/msqrt.ts b/ts/output/chtml/Wrappers/msqrt.ts index 1156acf8c0..166a691231 100644 --- a/ts/output/chtml/Wrappers/msqrt.ts +++ b/ts/output/chtml/Wrappers/msqrt.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMsqrt, CommonMsqrtClass, @@ -41,62 +34,47 @@ import { ChtmlMoNTD } from './mo.js'; import { BBox } from '../../../util/BBox.js'; import { MmlMsqrt } from '../../../core/MmlTree/MmlNodes/msqrt.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMsqrt interface for the CHTML Msqrt wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsqrtNTD +export interface ChtmlMsqrtNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMsqrt< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMsqrtClass interface for the CHTML Msqrt wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsqrtClass +export interface ChtmlMsqrtClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMsqrtClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMsqrtNTD; + parent?: ChtmlWrapper + ): ChtmlMsqrtNTD; } /*****************************************************************/ @@ -104,31 +82,21 @@ export interface ChtmlMsqrtClass /** * The ChtmlMsqrt wrapper class for the MmlMsqrt class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export const ChtmlMsqrt = (function (): ChtmlMsqrtClass { +export const ChtmlMsqrt = (function (): ChtmlMsqrtClass { const Base = CommonMsqrtMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMsqrtClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMsqrtClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMsqrt extends Base implements ChtmlMsqrtNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMsqrt extends Base implements ChtmlMsqrtNTD { /** * @override */ @@ -164,8 +132,8 @@ export const ChtmlMsqrt = (function (): ChtmlMsqrtClass { /** * @override */ - public toCHTML(parents: N[]) { - const surd = this.surd as ChtmlMoNTD; + public toCHTML(parents: N[]) { + const surd = this.surd as ChtmlMoNTD; const base = this.childNodes[this.base]; // // Get the parameters for the spacing of the parts @@ -182,7 +150,7 @@ export const ChtmlMsqrt = (function (): ChtmlMsqrtClass { const CHTML = this.standardChtmlNodes(parents); let SURD, BASE, ROOT, root; if (this.root != null) { - ROOT = adaptor.append(CHTML[0], this.html('mjx-root')) as N; + ROOT = adaptor.append(CHTML[0], this.html('mjx-root')) as N; root = this.childNodes[this.root]; } const SQRT = adaptor.append( @@ -191,7 +159,7 @@ export const ChtmlMsqrt = (function (): ChtmlMsqrtClass { (SURD = this.html('mjx-surd')), (BASE = this.html('mjx-box', { style: { paddingTop: this.em(q) } })), ]) - ) as N; + ) as N; if (t !== 0.06) { adaptor.setStyle( BASE, @@ -224,10 +192,10 @@ export const ChtmlMsqrt = (function (): ChtmlMsqrtClass { * @param {number} _H The height of the root as a whole */ protected addRoot( - _ROOT: N, - _root: ChtmlWrapper, + _ROOT: N, + _root: ChtmlWrapper, _sbox: BBox, _H: number ) {} }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/msubsup.ts b/ts/output/chtml/Wrappers/msubsup.ts index e0f2db2cf8..98aadcac23 100644 --- a/ts/output/chtml/Wrappers/msubsup.ts +++ b/ts/output/chtml/Wrappers/msubsup.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMsub, CommonMsubClass, @@ -55,62 +48,47 @@ import { MmlMsup, } from '../../../core/MmlTree/MmlNodes/msubsup.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMsub interface for the CHTML Msub wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsubNTD +export interface ChtmlMsubNTD extends - ChtmlScriptbaseNTD, + ChtmlScriptbaseNTD, CommonMsub< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMsubClass interface for the CHTML Msub wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsubClass +export interface ChtmlMsubClass extends - ChtmlScriptbaseClass, + ChtmlScriptbaseClass, CommonMsubClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMsubNTD; + parent?: ChtmlWrapper + ): ChtmlMsubNTD; } /*****************************************************************/ @@ -118,33 +96,25 @@ export interface ChtmlMsubClass /** * The ChtmlMsub wrapper class for the MmlMsub class */ -export const ChtmlMsub = (function (): ChtmlMsubClass { +export const ChtmlMsub = (function (): ChtmlMsubClass { const Base = CommonMsubMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMsubClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMsubClass >(ChtmlScriptbase); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMsub extends Base implements ChtmlMsubNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMsub extends Base implements ChtmlMsubNTD { /** * @override */ public static kind = MmlMsub.prototype.kind; }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -152,57 +122,41 @@ export const ChtmlMsub = (function (): ChtmlMsubClass { /** * The ChtmlMsup interface for the CHTML Msup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsupNTD +export interface ChtmlMsupNTD extends - ChtmlScriptbaseNTD, + ChtmlScriptbaseNTD, CommonMsup< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMsupClass interface for the CHTML Msup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsupClass +export interface ChtmlMsupClass extends - ChtmlScriptbaseClass, + ChtmlScriptbaseClass, CommonMsupClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMsupNTD; + parent?: ChtmlWrapper + ): ChtmlMsupNTD; } /*****************************************************************/ @@ -210,33 +164,25 @@ export interface ChtmlMsupClass /** * The ChtmlMsup wrapper class for the MmlMsup class */ -export const ChtmlMsup = (function (): ChtmlMsupClass { +export const ChtmlMsup = (function (): ChtmlMsupClass { const Base = CommonMsupMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMsupClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMsupClass >(ChtmlScriptbase); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMsup extends Base implements ChtmlMsupNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMsup extends Base implements ChtmlMsupNTD { /** * @override */ public static kind = MmlMsup.prototype.kind; }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -244,57 +190,41 @@ export const ChtmlMsup = (function (): ChtmlMsupClass { /** * The ChtmlMsubsup interface for the CHTML Msubsup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsubsupNTD +export interface ChtmlMsubsupNTD extends - ChtmlScriptbaseNTD, + ChtmlScriptbaseNTD, CommonMsubsup< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMsubsupClass interface for the CHTML Msubsup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMsubsupClass +export interface ChtmlMsubsupClass extends - ChtmlScriptbaseClass, + ChtmlScriptbaseClass, CommonMsubsupClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMsubsupNTD; + parent?: ChtmlWrapper + ): ChtmlMsubsupNTD; } /*****************************************************************/ @@ -302,27 +232,19 @@ export interface ChtmlMsubsupClass /** * The ChtmlMsubsup wrapper class for the MmlMsubsup class */ -export const ChtmlMsubsup = (function (): ChtmlMsubsupClass { +export const ChtmlMsubsup = (function (): ChtmlMsubsupClass { const Base = CommonMsubsupMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMsubsupClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMsubsupClass >(ChtmlScriptbase); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMsubsup extends Base implements ChtmlMsubsupNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMsubsup extends Base implements ChtmlMsubsupNTD { /** * @override */ @@ -345,7 +267,7 @@ export const ChtmlMsubsup = (function (): ChtmlMsubsupClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; const adaptor = this.adaptor; const chtml = this.standardChtmlNodes(parents); @@ -356,7 +278,7 @@ export const ChtmlMsubsup = (function (): ChtmlMsubsupClass { const stack = adaptor.append( chtml[chtml.length - 1], this.html('mjx-script', { style }) - ) as N; + ) as N; sup.toCHTML([stack]); adaptor.append( stack, @@ -383,4 +305,4 @@ export const ChtmlMsubsup = (function (): ChtmlMsubsupClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mtable.ts b/ts/output/chtml/Wrappers/mtable.ts index 81518779a1..7e958831e9 100644 --- a/ts/output/chtml/Wrappers/mtable.ts +++ b/ts/output/chtml/Wrappers/mtable.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMtable, CommonMtableClass, @@ -42,73 +35,58 @@ import { ChtmlMtrNTD } from './mtr.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { isPercent } from '../../../util/string.js'; import { OptionList } from '../../../util/Options.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMtable interface for the CHTML Mtable wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtableNTD +export interface ChtmlMtableNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMtable< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMtrNTD + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMtrNTD > { /** * The column for labels */ - labels: N; + labels: N; /** * The inner table DOM node */ - itable: N; + itable: N; } /** * The ChtmlMtableClass interface for the CHTML Mtable wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtableClass +export interface ChtmlMtableClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMtableClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMtableNTD; + parent?: ChtmlWrapper + ): ChtmlMtableNTD; } /*****************************************************************/ @@ -116,28 +94,20 @@ export interface ChtmlMtableClass /** * The ChtmlMtable wrapper class for the MmlMtable class */ -export const ChtmlMtable = (function (): ChtmlMtableClass { +export const ChtmlMtable = (function (): ChtmlMtableClass { const Base = CommonMtableMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMtrNTD, - ChtmlMtableClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMtrNTD, + ChtmlMtableClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMtable extends Base implements ChtmlMtableNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMtable extends Base implements ChtmlMtableNTD { /** * @override */ @@ -212,12 +182,12 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { /** * @override */ - public labels: N; + public labels: N; /** * @override */ - public itable: N; + public itable: N; /******************************************************************/ @@ -225,9 +195,9 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { * @override */ constructor( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent: ChtmlWrapper = null + parent: ChtmlWrapper = null ) { super(factory, node, parent); this.itable = this.html('mjx-itable'); @@ -248,7 +218,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { // // Create the rows inside an mjx-itable (which will be used to center the table on the math axis) // @@ -297,7 +267,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { */ protected padRows() { const adaptor = this.adaptor; - for (const row of adaptor.childNodes(this.itable) as N[]) { + for (const row of adaptor.childNodes(this.itable) as N[]) { while (adaptor.childNodes(row).length < this.numCols) { adaptor.append(row, this.html('mjx-mtd', { extra: true })); } @@ -339,7 +309,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { // const styleNode = cell ? cell.dom[0] - : (this.adaptor.childNodes(row.dom[0])[i] as N); + : (this.adaptor.childNodes(row.dom[0])[i] as N); if ((i > 1 && lspace !== '0.4em') || (lspace !== '0' && i === 1)) { this.adaptor.setStyle(styleNode, 'paddingLeft', lspace); } @@ -361,7 +331,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { const lines = this.getColumnAttributes('columnlines'); for (const row of this.childNodes) { let i = 0; - const cells = this.adaptor.childNodes(row.dom[0]).slice(1) as N[]; + const cells = this.adaptor.childNodes(row.dom[0]).slice(1) as N[]; for (const cell of cells) { const line = lines[i++]; if (line === 'none') continue; @@ -376,7 +346,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { protected handleColumnWidths() { for (const row of this.childNodes) { let i = 0; - for (const cell of this.adaptor.childNodes(row.dom[0]) as N[]) { + for (const cell of this.adaptor.childNodes(row.dom[0]) as N[]) { const w = this.cWidths[i++]; if (w !== null) { const width = typeof w === 'number' ? this.em(w) : w; @@ -445,7 +415,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { for (const row of this.childNodes.slice(1)) { const line = lines[i++]; if (line === 'none') continue; - for (const cell of this.adaptor.childNodes(row.dom[0]) as N[]) { + for (const cell of this.adaptor.childNodes(row.dom[0]) as N[]) { this.adaptor.setStyle(cell, 'borderTop', '.07em ' + line); } } @@ -484,7 +454,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { * @param {ChtmlWrapper} row The row whose height is to be set * @param {number} HD The height to be set for the row */ - protected setRowHeight(row: ChtmlWrapper, HD: number) { + protected setRowHeight(row: ChtmlWrapper, HD: number) { this.adaptor.setStyle(row.dom[0], 'height', this.em(HD)); } @@ -496,11 +466,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { * @param {number} HD The total height+depth for the row * @param {number} D The new depth for the row */ - protected setRowBaseline( - row: ChtmlWrapper, - HD: number, - D: number - ) { + protected setRowBaseline(row: ChtmlWrapper, HD: number, D: number) { const ralign = row.node.attributes.get('rowalign') as string; // // Loop through the cells and set the strut height and depth. @@ -521,7 +487,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { * @returns {boolean} True if no other cells in this row need to be processed */ protected setCellBaseline( - cell: ChtmlWrapper, + cell: ChtmlWrapper, ralign: string, HD: number, D: number @@ -529,7 +495,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { const calign = cell.node.attributes.get('rowalign'); if (calign === 'baseline' || calign === 'axis') { const adaptor = this.adaptor; - const child = adaptor.lastChild(cell.dom[0]) as N; + const child = adaptor.lastChild(cell.dom[0]) as N; adaptor.setStyle(child, 'height', this.em(HD)); adaptor.setStyle(child, 'verticalAlign', this.em(-D)); const row = cell.parent; @@ -573,7 +539,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { if (W === 'auto') return; W = this.em(this.length2em(W) + 2 * this.fLine); } - const table = adaptor.firstChild(dom) as N; + const table = adaptor.firstChild(dom) as N; adaptor.setStyle(table, 'width', W); adaptor.setStyle(table, 'minWidth', this.em(w)); if (L || R) { @@ -646,7 +612,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { // Handle indentation // if (shift) { - const table = adaptor.firstChild(this.dom[0]) as N; + const table = adaptor.firstChild(this.dom[0]) as N; this.setIndent(table, align, shift); } // @@ -717,7 +683,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { // and line thickness for each non-labeled row. // let h = this.fLine; - let current = adaptor.firstChild(this.labels) as N; + let current = adaptor.firstChild(this.labels) as N; for (let i = 0; i < this.numRows; i++) { const row = this.childNodes[i]; if (row.node.isKind('mlabeledtr')) { @@ -732,7 +698,7 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { 'height', this.em((equal ? HD : H[i] + D[i]) + space[i] + space[i + 1]) ); - current = adaptor.next(current) as N; + current = adaptor.next(current) as N; h = this.rLines[i]; } else { h += @@ -744,4 +710,4 @@ export const ChtmlMtable = (function (): ChtmlMtableClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mtd.ts b/ts/output/chtml/Wrappers/mtd.ts index 1a230905e9..885c14a389 100644 --- a/ts/output/chtml/Wrappers/mtd.ts +++ b/ts/output/chtml/Wrappers/mtd.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMtd, CommonMtdClass, @@ -39,62 +32,47 @@ import { import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMtd } from '../../../core/MmlTree/MmlNodes/mtd.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMtd interface for the CHTML Mtd wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtdNTD +export interface ChtmlMtdNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMtd< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMtdClass interface for the CHTML Mtd wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtdClass +export interface ChtmlMtdClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMtdClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMtdNTD; + parent?: ChtmlWrapper + ): ChtmlMtdNTD; } /*****************************************************************/ @@ -102,26 +80,18 @@ export interface ChtmlMtdClass /** * The ChtmlMtd wrapper class for the MmlMtd class */ -export const ChtmlMtd = (function (): ChtmlMtdClass { +export const ChtmlMtd = (function (): ChtmlMtdClass { const Base = CommonMtdMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMtdClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMtdClass >(ChtmlWrapper); - // Avoid message about base constructors not having the same type - // (they should both be ChtmlWrapper, but are thought of as different by typescript) - return class ChtmlMtd extends Base implements ChtmlMtdNTD { + return class ChtmlMtd extends Base implements ChtmlMtdNTD { /** * @override */ @@ -187,7 +157,7 @@ export const ChtmlMtd = (function (): ChtmlMtdClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { super.toCHTML(parents); const ralign = this.node.attributes.get('rowalign') as string; const calign = this.node.attributes.get('columnalign') as string; @@ -212,4 +182,4 @@ export const ChtmlMtd = (function (): ChtmlMtdClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mtext.ts b/ts/output/chtml/Wrappers/mtext.ts index 4a74f32d2e..33042c444d 100644 --- a/ts/output/chtml/Wrappers/mtext.ts +++ b/ts/output/chtml/Wrappers/mtext.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMtext, CommonMtextClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mtext.js'; import { MmlNode, TextNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMtext } from '../../../core/MmlTree/MmlNodes/mtext.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMtext interface for the CHTML Mtext wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtextNTD +export interface ChtmlMtextNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMtext< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMtextClass interface for the CHTML Mtext wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtextClass +export interface ChtmlMtextClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMtextClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMtextNTD; + parent?: ChtmlWrapper + ): ChtmlMtextNTD; } /*****************************************************************/ @@ -101,27 +79,19 @@ export interface ChtmlMtextClass /** * The ChtmlMtext wrapper class for the MmlMtext class */ -export const ChtmlMtext = (function (): ChtmlMtextClass { +export const ChtmlMtext = (function (): ChtmlMtextClass { const Base = CommonMtextMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMtextClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMtextClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMtext extends Base implements ChtmlMtextNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMtext extends Base implements ChtmlMtextNTD { /** * @override */ @@ -130,7 +100,7 @@ export const ChtmlMtext = (function (): ChtmlMtextClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { // // If no breakpoints, do the usual thing // @@ -184,4 +154,4 @@ export const ChtmlMtext = (function (): ChtmlMtextClass { } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/mtr.ts b/ts/output/chtml/Wrappers/mtr.ts index 431b7715bc..1778cf1dd2 100644 --- a/ts/output/chtml/Wrappers/mtr.ts +++ b/ts/output/chtml/Wrappers/mtr.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMtr, CommonMtrClass, @@ -44,62 +37,47 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMtr, MmlMlabeledtr } from '../../../core/MmlTree/MmlNodes/mtr.js'; import { ChtmlMtableNTD } from './mtable.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMtr interface for the CHTML Mtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtrNTD +export interface ChtmlMtrNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonMtr< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMtrClass interface for the CHTML Mtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMtrClass +export interface ChtmlMtrClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonMtrClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMtrNTD; + parent?: ChtmlWrapper + ): ChtmlMtrNTD; } /*****************************************************************/ @@ -107,27 +85,19 @@ export interface ChtmlMtrClass /** * The ChtmlMtr wrapper class for the MmlMtr class */ -export const ChtmlMtr = (function (): ChtmlMtrClass { +export const ChtmlMtr = (function (): ChtmlMtrClass { const Base = CommonMtrMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMtrClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMtrClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMtr extends Base implements ChtmlMtrNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMtr extends Base implements ChtmlMtrNTD { /** * @override */ @@ -160,7 +130,7 @@ export const ChtmlMtr = (function (): ChtmlMtrClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { super.toCHTML(parents); const align = this.node.attributes.get('rowalign') as string; if (align !== 'baseline') { @@ -170,63 +140,47 @@ export const ChtmlMtr = (function (): ChtmlMtrClass { this.adaptor.setStyle(this.dom[0], 'height', this.em(h + d)); } }; -})(); +})(); /*****************************************************************/ /** * The ChtmlMlabeledtr interface for the CHTML Mlabeledtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMlabeledtrNTD +export interface ChtmlMlabeledtrNTD extends - ChtmlMtrNTD, + ChtmlMtrNTD, CommonMlabeledtr< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMlabeledtrClass interface for the CHTML Mlabeledtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMlabeledtrClass +export interface ChtmlMlabeledtrClass extends - ChtmlMtrClass, + ChtmlMtrClass, CommonMlabeledtrClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMlabeledtrNTD; + parent?: ChtmlWrapper + ): ChtmlMlabeledtrNTD; } /*****************************************************************/ @@ -234,36 +188,19 @@ export interface ChtmlMlabeledtrClass /** * The ChtmlMlabeledtr wrapper class for the MmlMlabeledtr class */ -export const ChtmlMlabeledtr = (function (): ChtmlMlabeledtrClass< - N, - T, - D -> { +export const ChtmlMlabeledtr = (function (): ChtmlMlabeledtrClass { const Base = CommonMlabeledtrMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMlabeledtrClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMlabeledtrClass >(ChtmlMtr); - // Avoid message about base constructors not having the same type - // (they should both be ChtmlWrapper, but are thought of as different by typescript) - return class ChtmlMlabeledtr - // @ts-expect-error Avoid message about base constructors not having the - // same type (they should both be ChtmlWrapper, but are thought of - // as different by typescript) - extends Base - implements ChtmlMlabeledtrNTD - { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMlabeledtr extends Base implements ChtmlMlabeledtrNTD { /** * @override */ @@ -296,9 +233,9 @@ export const ChtmlMlabeledtr = (function (): ChtmlMlabeledtrClass< /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { super.toCHTML(parents); - const child = this.adaptor.firstChild(this.dom[0]) as N; + const child = this.adaptor.firstChild(this.dom[0]) as N; if (child) { // // Remove label and put it into the labels box inside a row @@ -308,10 +245,7 @@ export const ChtmlMlabeledtr = (function (): ChtmlMlabeledtrClass< const attr = align !== 'baseline' && align !== 'axis' ? { rowalign: align } : {}; const row = this.html('mjx-mtr', attr, [child]); - this.adaptor.append( - (this.parent as ChtmlMtableNTD).labels, - row - ); + this.adaptor.append((this.parent as ChtmlMtableNTD).labels, row); } } @@ -323,4 +257,4 @@ export const ChtmlMlabeledtr = (function (): ChtmlMlabeledtrClass< this.jax.wrapperUsage.add(ChtmlMtr.kind); } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/munderover.ts b/ts/output/chtml/Wrappers/munderover.ts index ad2f75d6da..846ef82da7 100644 --- a/ts/output/chtml/Wrappers/munderover.ts +++ b/ts/output/chtml/Wrappers/munderover.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonMunder, CommonMunderClass, @@ -61,62 +54,47 @@ import { ChtmlMsubsupNTD, } from './msubsup.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlMunder interface for the CHTML Munder wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMunderNTD +export interface ChtmlMunderNTD extends - ChtmlMsubNTD, + ChtmlMsubNTD, CommonMunder< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMunderClass interface for the CHTML Munder wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMunderClass +export interface ChtmlMunderClass extends - ChtmlMsubClass, + ChtmlMsubClass, CommonMunderClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMunderNTD; + parent?: ChtmlWrapper + ): ChtmlMunderNTD; } /*****************************************************************/ @@ -124,27 +102,19 @@ export interface ChtmlMunderClass /** * The ChtmlMunder wrapper class for the MmlMunder class */ -export const ChtmlMunder = (function (): ChtmlMunderClass { +export const ChtmlMunder = (function (): ChtmlMunderClass { const Base = CommonMunderMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMunderClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMunderClass >(ChtmlMsub); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMunder extends Base implements ChtmlMunderNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMunder extends Base implements ChtmlMunderNTD { /** * @override */ @@ -171,7 +141,7 @@ export const ChtmlMunder = (function (): ChtmlMunderClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; if (this.hasMovableLimits()) { super.toCHTML(parents); @@ -180,13 +150,13 @@ export const ChtmlMunder = (function (): ChtmlMunderClass { } this.dom = this.standardChtmlNodes(parents); const base = this.adaptor.append( - this.adaptor.append(this.dom[0], this.html('mjx-row')) as N, + this.adaptor.append(this.dom[0], this.html('mjx-row')) as N, this.html('mjx-base') - ) as N; + ) as N; const under = this.adaptor.append( - this.adaptor.append(this.dom[0], this.html('mjx-row')) as N, + this.adaptor.append(this.dom[0], this.html('mjx-row')) as N, this.html('mjx-under') - ) as N; + ) as N; this.baseChild.toCHTML([base]); this.scriptChild.toCHTML([under]); const basebox = this.baseChild.getOuterBBox(); @@ -203,7 +173,7 @@ export const ChtmlMunder = (function (): ChtmlMunderClass { this.adjustUnderDepth(under, underbox); } }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -211,57 +181,41 @@ export const ChtmlMunder = (function (): ChtmlMunderClass { /** * The ChtmlMover interface for the CHTML Mover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMoverNTD +export interface ChtmlMoverNTD extends - ChtmlMsupNTD, + ChtmlMsupNTD, CommonMover< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMoverClass interface for the CHTML Mover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMoverClass +export interface ChtmlMoverClass extends - ChtmlMsupClass, + ChtmlMsupClass, CommonMoverClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMoverNTD; + parent?: ChtmlWrapper + ): ChtmlMoverNTD; } /*****************************************************************/ @@ -269,27 +223,19 @@ export interface ChtmlMoverClass /** * The ChtmlMover wrapper class for the MmlMover class */ -export const ChtmlMover = (function (): ChtmlMoverClass { +export const ChtmlMover = (function (): ChtmlMoverClass { const Base = CommonMoverMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMoverClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMoverClass >(ChtmlMsup); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlMover extends Base implements ChtmlMoverNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMover extends Base implements ChtmlMoverNTD { /** * @override */ @@ -313,7 +259,7 @@ export const ChtmlMover = (function (): ChtmlMoverClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; if (this.hasMovableLimits()) { super.toCHTML(parents); @@ -321,8 +267,14 @@ export const ChtmlMover = (function (): ChtmlMoverClass { return; } this.dom = this.standardChtmlNodes(parents); - const over = this.adaptor.append(this.dom[0], this.html('mjx-over')) as N; - const base = this.adaptor.append(this.dom[0], this.html('mjx-base')) as N; + const over = this.adaptor.append( + this.dom[0], + this.html('mjx-over') + ) as N; + const base = this.adaptor.append( + this.dom[0], + this.html('mjx-base') + ) as N; this.scriptChild.toCHTML([over]); this.baseChild.toCHTML([base]); const overbox = this.scriptChild.getOuterBBox(); @@ -338,7 +290,7 @@ export const ChtmlMover = (function (): ChtmlMoverClass { this.adjustOverDepth(over, overbox); } }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -346,57 +298,41 @@ export const ChtmlMover = (function (): ChtmlMoverClass { /** * The ChtmlMunderover interface for the CHTML Munderover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMunderoverNTD +export interface ChtmlMunderoverNTD extends - ChtmlMsubsupNTD, + ChtmlMsubsupNTD, CommonMunderover< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlMunderoverClass interface for the CHTML Munderover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlMunderoverClass +export interface ChtmlMunderoverClass extends - ChtmlMsubsupClass, + ChtmlMsubsupClass, CommonMunderoverClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlMunderoverNTD; + parent?: ChtmlWrapper + ): ChtmlMunderoverNTD; } /*****************************************************************/ @@ -404,34 +340,19 @@ export interface ChtmlMunderoverClass /** * The ChtmlMunderover wrapper class for the MmlMunderover class */ -export const ChtmlMunderover = (function (): ChtmlMunderoverClass< - N, - T, - D -> { +export const ChtmlMunderover = (function (): ChtmlMunderoverClass { const Base = CommonMunderoverMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlMunderoverClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlMunderoverClass >(ChtmlMsubsup); - return class ChtmlMunderover - // @ts-expect-error Avoid message about base constructors not having the - // same type (they should both be ChtmlWrapper, but are thought of - // as different by typescript) - extends Base - implements ChtmlMunderoverNTD - { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlMunderover extends Base implements ChtmlMunderoverNTD { /** * @override */ @@ -454,7 +375,7 @@ export const ChtmlMunderover = (function (): ChtmlMunderoverClass< /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; if (this.hasMovableLimits()) { super.toCHTML(parents); @@ -462,19 +383,22 @@ export const ChtmlMunderover = (function (): ChtmlMunderoverClass< return; } this.dom = this.standardChtmlNodes(parents); - const over = this.adaptor.append(this.dom[0], this.html('mjx-over')) as N; + const over = this.adaptor.append( + this.dom[0], + this.html('mjx-over') + ) as N; const table = this.adaptor.append( - this.adaptor.append(this.dom[0], this.html('mjx-box')) as N, + this.adaptor.append(this.dom[0], this.html('mjx-box')) as N, this.html('mjx-munder') - ) as N; + ) as N; const base = this.adaptor.append( - this.adaptor.append(table, this.html('mjx-row')) as N, + this.adaptor.append(table, this.html('mjx-row')) as N, this.html('mjx-base') - ) as N; + ) as N; const under = this.adaptor.append( - this.adaptor.append(table, this.html('mjx-row')) as N, + this.adaptor.append(table, this.html('mjx-row')) as N, this.html('mjx-under') - ) as N; + ) as N; this.overChild.toCHTML([over]); this.baseChild.toCHTML([base]); this.underChild.toCHTML([under]); @@ -499,4 +423,4 @@ export const ChtmlMunderover = (function (): ChtmlMunderoverClass< this.adjustUnderDepth(under, underbox); } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/scriptbase.ts b/ts/output/chtml/Wrappers/scriptbase.ts index 55e60484ac..24c000ab17 100644 --- a/ts/output/chtml/Wrappers/scriptbase.ts +++ b/ts/output/chtml/Wrappers/scriptbase.ts @@ -24,16 +24,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonScriptbase, CommonScriptbaseClass, @@ -43,125 +36,91 @@ import { ChtmlMsubsup } from './msubsup.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { BBox } from '../../../util/BBox.js'; import { StyleJsonData } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The ChtmlScriptbase interface for the CHTML Scriptbase wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlScriptbaseNTD +export interface ChtmlScriptbaseNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonScriptbase< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { /** * @param {N[]} nodes The HTML elements to be centered in a stack * @param {number[]} dx The x offsets needed to center the elements */ - setDeltaW(nodes: N[], dx: number[]): void; + setDeltaW(nodes: N[], dx: number[]): void; /** * @param {N} over The HTML element for the overscript * @param {BBox} overbox The bbox for the overscript */ - adjustOverDepth(over: N, overbox: BBox): void; + adjustOverDepth(over: N, overbox: BBox): void; /** * @param {N} under The HTML element for the underscript * @param {BBox} underbox The bbox for the underscript */ - adjustUnderDepth(under: N, underbox: BBox): void; + adjustUnderDepth(under: N, underbox: BBox): void; /** * @param {N} base The HTML element for the base * @param {BBox} basebox The bbox for the base */ - adjustBaseHeight(base: N, basebox: BBox): void; + adjustBaseHeight(base: N, basebox: BBox): void; } /** * The ChtmlScriptbaseClass interface for the CHTML Scriptbase wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlScriptbaseClass +export interface ChtmlScriptbaseClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonScriptbaseClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlScriptbaseNTD; + parent?: ChtmlWrapper + ): ChtmlScriptbaseNTD; } /*****************************************************************/ /** * The ChtmlScriptbase wrapper class for the MmlScriptbase class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< - N, - T, - D -> { +export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass { const Base = CommonScriptbaseMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlScriptbaseClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlScriptbaseClass >(ChtmlWrapper); - return class ChtmlScriptbase - // @ts-expect-error Avoid message about base constructors not having the - // same type (they should both be ChtmlWrapper, but are thought of - // as different by typescript) - extends Base - implements ChtmlScriptbaseNTD - { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlScriptbase extends Base implements ChtmlScriptbaseNTD { /** * @override */ @@ -173,7 +132,7 @@ export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< * * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; this.dom = this.standardChtmlNodes(parents); const [x, v] = this.getOffset(); @@ -185,7 +144,7 @@ export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< this.baseChild.toCHTML(this.dom); const dom = this.dom[this.dom.length - 1]; this.scriptChild.toCHTML([ - this.adaptor.append(dom, this.html('mjx-script', { style })) as N, + this.adaptor.append(dom, this.html('mjx-script', { style })) as N, ]); } @@ -203,7 +162,7 @@ export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< * @param {N[]} nodes The HTML elements to be centered in a stack * @param {number[]} dx The x offsets needed to center the elements */ - public setDeltaW(nodes: N[], dx: number[]) { + public setDeltaW(nodes: N[], dx: number[]) { for (let i = 0; i < dx.length; i++) { if (dx[i]) { this.adaptor.setStyle(nodes[i], 'paddingLeft', this.em(dx[i])); @@ -215,7 +174,7 @@ export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< * @param {N} over The HTML element for the overscript * @param {BBox} overbox The bbox for the overscript */ - public adjustOverDepth(over: N, overbox: BBox) { + public adjustOverDepth(over: N, overbox: BBox) { if (overbox.d >= 0) return; this.adaptor.setStyle( over, @@ -228,7 +187,7 @@ export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< * @param {N} under The HTML element for the underscript * @param {BBox} underbox The bbox for the underscript */ - public adjustUnderDepth(under: N, underbox: BBox) { + public adjustUnderDepth(under: N, underbox: BBox) { if (underbox.d >= 0) return; const adaptor = this.adaptor; const v = this.em(underbox.d); @@ -236,18 +195,18 @@ export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< style: { 'margin-bottom': v, 'vertical-align': v }, }); for (const child of adaptor.childNodes( - adaptor.firstChild(under) as N - ) as N[]) { + adaptor.firstChild(under) as N + ) as N[]) { adaptor.append(box, child); } - adaptor.append(adaptor.firstChild(under) as N, box); + adaptor.append(adaptor.firstChild(under) as N, box); } /** * @param {N} base The HTML element for the base * @param {BBox} basebox The bbox for the base */ - public adjustBaseHeight(base: N, basebox: BBox) { + public adjustBaseHeight(base: N, basebox: BBox) { if (this.node.attributes.get('accent')) { const minH = this.font.params.x_height * this.baseScale; if (basebox.h < minH) { @@ -257,4 +216,4 @@ export const ChtmlScriptbase = (function (): ChtmlScriptbaseClass< } } }; -})(); +})(); diff --git a/ts/output/chtml/Wrappers/semantics.ts b/ts/output/chtml/Wrappers/semantics.ts index 24f5310328..99b2705992 100644 --- a/ts/output/chtml/Wrappers/semantics.ts +++ b/ts/output/chtml/Wrappers/semantics.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CHTML } from '../../chtml.js'; +import { CHTML, CHTML_FONT } from '../../chtml.js'; import { ChtmlWrapper, ChtmlWrapperClass } from '../Wrapper.js'; import { ChtmlWrapperFactory } from '../WrapperFactory.js'; -import { - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, -} from '../FontData.js'; import { CommonSemantics, CommonSemanticsClass, @@ -51,6 +44,7 @@ import { import { XMLNode } from '../../../core/MmlTree/MmlNode.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { StyleList } from '../../../util/Styles.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; export type FontStyles = { 'font-family': string; @@ -61,57 +55,41 @@ export type FontStyles = { /** * The ChtmlSemantics interface for the CHTML Semantics wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlSemanticsNTD +export interface ChtmlSemanticsNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonSemantics< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > {} /** * The ChtmlSemanticsClass interface for the CHTML Semantics wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlSemanticsClass +export interface ChtmlSemanticsClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonSemanticsClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlSemanticsNTD; + parent?: ChtmlWrapper + ): ChtmlSemanticsNTD; } /*****************************************************************/ @@ -119,33 +97,18 @@ export interface ChtmlSemanticsClass /** * The ChtmlSemantics wrapper class for the MmlSemantics class */ -export const ChtmlSemantics = (function (): ChtmlSemanticsClass< - N, - T, - D -> { +export const ChtmlSemantics = (function (): ChtmlSemanticsClass { const Base = CommonSemanticsMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlSemanticsClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlSemanticsClass >(ChtmlWrapper); - // Avoid message about base constructors not having the same type - // (they should both be ChtmlWrapper, but are thought of as different by typescript) - return class ChtmlSemantics - extends Base - implements ChtmlSemanticsNTD - { + return class ChtmlSemantics extends Base implements ChtmlSemanticsNTD { /** * @override */ @@ -154,7 +117,7 @@ export const ChtmlSemantics = (function (): ChtmlSemanticsClass< /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { if (this.toEmbellishedCHTML(parents)) return; const chtml = this.standardChtmlNodes(parents); if (this.childNodes.length) { @@ -162,92 +125,72 @@ export const ChtmlSemantics = (function (): ChtmlSemanticsClass< } } }; -})(); +})(); /*****************************************************************/ /** * The ChtmlAnnotation wrapper for the MmlAnnotation class */ -export const ChtmlAnnotation = (function (): ChtmlWrapperClass< - N, - T, - D -> { - return class ChtmlAnnotation extends ChtmlWrapper { - /** - * @override - */ - public static kind = MmlAnnotation.prototype.kind; +export class ChtmlAnnotation extends ChtmlWrapper { + /** + * @override + */ + public static kind = MmlAnnotation.prototype.kind; - /** - * @override - */ - public toCHTML(parents: N[]) { - // FIXME: output as plain text - super.toCHTML(parents); - } + /** + * @override + */ + public toCHTML(parents: N[]) { + // FIXME: output as plain text + super.toCHTML(parents); + } - /** - * @override - */ - public computeBBox() { - // FIXME: compute using the DOM, if possible - return this.bbox; - } - }; -})(); + /** + * @override + */ + public computeBBox() { + // FIXME: compute using the DOM, if possible + return this.bbox; + } +} /*****************************************************************/ /** * The ChtmlAnnotationXML wrapper for the MmlAnnotationXML class */ -export const ChtmlAnnotationXML = (function (): ChtmlWrapperClass< - N, - T, - D -> { - return class ChtmlAnnotationXML extends ChtmlWrapper { - /** - * @override - */ - public static kind = MmlAnnotationXML.prototype.kind; +export class ChtmlAnnotationXML extends ChtmlWrapper { + /** + * @override + */ + public static kind = MmlAnnotationXML.prototype.kind; - /** - * @override - */ - public static styles: StyleJson = { - 'mjx-annotation-xml': { - 'font-family': 'initial', - 'line-height': 'normal', - }, - }; + /** + * @override + */ + public static styles: StyleJson = { + 'mjx-annotation-xml': { + 'font-family': 'initial', + 'line-height': 'normal', + }, }; -})(); +} /*****************************************************************/ /** * The ChtmlXmlNode interface for the CHTML XmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlXmlNodeNTD +export interface ChtmlXmlNodeNTD extends - ChtmlWrapper, + ChtmlWrapper, CommonXmlNode< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { /** * @returns {FontStyles} the font family and size data @@ -258,58 +201,42 @@ export interface ChtmlXmlNodeNTD /** * The ChtmlXmlNodeClass interface for the CHTML XmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface ChtmlXmlNodeClass +export interface ChtmlXmlNodeClass extends - ChtmlWrapperClass, + ChtmlWrapperClass, CommonXmlNodeClass< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass > { new ( - factory: ChtmlWrapperFactory, + factory: ChtmlWrapperFactory, node: MmlNode, - parent?: ChtmlWrapper - ): ChtmlXmlNodeNTD; + parent?: ChtmlWrapper + ): ChtmlXmlNodeNTD; } /** * The ChtmlXmlNode wrapper for the XMLNode class */ -export const ChtmlXmlNode = (function (): ChtmlWrapperClass { +export const ChtmlXmlNode = (function (): ChtmlXmlNodeClass { const Base = CommonXmlNodeMixin< - N, - T, - D, - CHTML, - ChtmlWrapper, - ChtmlWrapperFactory, - ChtmlWrapperClass, - ChtmlCharOptions, - ChtmlVariantData, - ChtmlDelimiterData, - ChtmlFontData, - ChtmlFontDataClass, - ChtmlXmlNodeClass + DOM, + CHTML_FONT, + CHTML, + ChtmlWrapper, + ChtmlWrapperFactory, + ChtmlWrapperClass, + ChtmlXmlNodeClass >(ChtmlWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be ChtmlWrapper, but are thought of as - // different by typescript) - return class ChtmlXmlNode extends Base implements ChtmlXmlNodeNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class ChtmlXmlNode extends Base implements ChtmlXmlNodeNTD { /** * @override */ @@ -318,9 +245,9 @@ export const ChtmlXmlNode = (function (): ChtmlWrapperClass { /** * @override */ - public toCHTML(parents: N[]) { + public toCHTML(parents: N[]) { this.markUsed(); - this.dom = [this.adaptor.append(parents[0], this.getHTML()) as N]; + this.dom = [this.adaptor.append(parents[0], this.getHTML()) as N]; } /** @@ -335,7 +262,7 @@ export const ChtmlXmlNode = (function (): ChtmlWrapperClass { /** * @override */ - public addHDW(html: N, styles: StyleList): N { + public addHDW(html: N, styles: StyleList): N { const scale = this.jax.options.scale; const { h, d, w } = this.bbox; const rscale = scale * this.metrics.scale; @@ -355,4 +282,4 @@ export const ChtmlXmlNode = (function (): ChtmlWrapperClass { ); } }; -})(); +})(); diff --git a/ts/output/common.ts b/ts/output/common.ts index 8920d8c68e..bf65071780 100644 --- a/ts/output/common.ts +++ b/ts/output/common.ts @@ -46,7 +46,7 @@ import { StyleList, Styles } from '../util/Styles.js'; import { StyleJson, StyleJsonSheet } from '../util/StyleJson.js'; import { BBox } from '../util/BBox.js'; import { SEM } from '../a11y/semantic-enrich/strings.js'; -import { DOM, DOM_TYPES, N, T, D, EMPTY } from '../types/Types.js'; +import { DOM, DOM_TYPES, N, T, EMPTY } from '../types/Types.js'; /*****************************************************************/ @@ -58,8 +58,8 @@ export interface ExtendedMetrics extends Metrics { * Maps linking a node to the test node it contains, * and a map linking a node to the metrics within that node. */ -export type MetricMap = Map; -type MetricDomMap = Map; +export type MetricMap = Map, ExtendedMetrics>; +type MetricDomMap = Map, N>; /** * Maps for unknown characters @@ -72,80 +72,71 @@ export const FONTPATH = '@mathjax/%%FONT%%-font'; /*****************************************************************/ +/** + * The font data for the common classes. + */ +export type COMMON_FONT = { + CC: CharOptions; + VV: VariantData; + DD: DelimiterData; + FD: FontData; + FC: FontDataClass; +}; + +/*****************************************************************/ + /** * The option types for linebreaking. */ -/* prettier-ignore */ export type LINEBREAKS = { - inline: boolean; // true for browser-based breaking of inline equations - width: string; // a fixed size or a percentage of the container width - lineleading: number; // the default lineleading in em units - LinebreakVisitor: // The LinebreakVisitor to use - typeof LinebreakVisitor; + inline: boolean; // true for browser-based breaking of inline equations + width: string; // a fixed size or a percentage of the container width + lineleading: number; // the default lineleading in em units + LinebreakVisitor: typeof LinebreakVisitor; // The LinebreakVisitor to use }; /** * The option types for the common output jax. */ -/* prettier-ignore */ export interface COMMON_OPTIONS< DOM extends DOM_TYPES, - WW extends CommonWrapper< - N, T, D, - CommonOutputJax, T, D, WW, WF, WC, CC, VV, DD, FD, FC>, - WW, WF, WC, CC, VV, DD, FD, FC - >, - WF extends CommonWrapperFactory< - N, T, D, - CommonOutputJax, T, D, WW, WF, WC, CC, VV, DD, FD, FC>, - WW, WF, WC, CC, VV, DD, FD, FC - >, - WC extends CommonWrapperClass< - N, T, D, - CommonOutputJax, T, D, WW, WF, WC, CC, VV, DD, FD, FC>, - WW, WF, WC, CC, VV, DD, FD, FC - >, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, > extends OUTPUTJAX_OPTIONS { - scale: number; // global scaling factor for all expressions - minScale: number; // smallest scaling factor to use - mtextInheritFont: boolean; // true to make mtext elements use surrounding font - merrorInheritFont: boolean; // true to make merror text use surrounding font - mtextFont: string; // font to use for mtext, if not inheriting (empty means use MathJax fonts) - merrorFont: string; // font to use for merror, if not inheriting (empty means use MathJax fonts) - mathmlSpacing: boolean; // true for MathML spacing rules, false for TeX rules - skipAttributes: EMPTY; // RFDa and other attributes NOT to copy to the output - exFactor: number; // default size of ex in em units - displayAlign: // default for indentalign when set to 'auto' - 'left' | 'center' | 'right' | 'auto'; - displayIndent: string; // default for indentshift when set to 'auto' - displayOverflow: // default for how to handle wide expressions + scale: number; // Global scaling factor for all expressions + minScale: number; // Smallest scaling factor to use + mtextInheritFont: boolean; // True to make mtext elements use surrounding font + merrorInheritFont: boolean; // True to make merror text use surrounding font + mtextFont: string; // Font to use for mtext, if not inheriting (empty means use MathJax fonts) + merrorFont: string; // Font to use for merror, if not inheriting (empty means use MathJax fonts) + mathmlSpacing: boolean; // True for MathML spacing rules, false for TeX rules + skipAttributes: EMPTY; // RFDa and other attributes NOT to copy to the output + exFactor: number; // Default size of ex in em units + // Default for indentalign when set to 'auto' + displayAlign: 'left' | 'center' | 'right' | 'auto'; + displayIndent: string; // Default for indentshift when set to 'auto' + // Default for how to handle wide expressions + displayOverflow: 'overflow' | 'scroll' | 'scale' | 'truncate' | 'elide' | 'linebreak'; - linebreaks: LINEBREAKS; // the line-breaking options - font: string; // the font component to load - fontExtensions: string[]; // the font extensions to load - htmlHDW: // How to handle data-mjx-hdw attributes - 'auto' | 'use' | 'force' | 'ignore'; - wrapperFactory: // The wrapper factory to use - CommonWrapperFactory< - N, T, D, - CommonOutputJax, T, D, WW, WF, WC, CC, VV, DD, FD, FC>, - WW, WF, WC, CC, VV, DD, FD, FC - >, - fontData: // The FontData object to use - FontData | typeof FontData; - fontPath: string; // The path to the font definitions - styleJson: StyleJsonSheet; // The StyleJsonSheet object to use + linebreaks: LINEBREAKS; // The line-breaking options + font: string; // The font component to load + fontExtensions: string[]; // The font extensions to load + // How to handle data-mjx-hdw attributes + htmlHDW: 'auto' | 'use' | 'force' | 'ignore'; + wrapperFactory: WF; // The wrapper factory to use + // The FontData object to use + fontData: FONT['FC'] | typeof FontData; + fontPath: string; // The path to the font definitions + styleJson: StyleJsonSheet; // The StyleJsonSheet object to use } /** * The default options. */ -const options: COMMON_OPTIONS = { +const options: COMMON_OPTIONS = { ...AbstractOutputJax.OPTIONS, scale: 1, minScale: 0.5, @@ -179,47 +170,16 @@ const options: COMMON_OPTIONS = { /** * The CommonOutputJax class on which the CHTML and SVG jax are built * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM ... */ export abstract class CommonOutputJax< - N, - T, - D, - /* prettier-ignore */ - WW extends CommonWrapper< - N, T, D, - CommonOutputJax, - WW, WF, WC, CC, VV, DD, FD, FC - >, - /* prettier-ignore */ - WF extends CommonWrapperFactory< - N, T, D, - CommonOutputJax, - WW, WF, WC, CC, VV, DD, FD, FC - >, - /* prettier-ignore */ - WC extends CommonWrapperClass< - N, T, D, - CommonOutputJax, - WW, WF, WC, CC, VV, DD, FD, FC - >, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends AbstractOutputJax { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends AbstractOutputJax { /** * The name of this output jax */ @@ -265,11 +225,7 @@ export abstract class CommonOutputJax< /** * The font to use for generic extensions */ - public static genericFont: FontDataClass< - CharOptions, - VariantData, - DelimiterData - >; + public static genericFont: COMMON_FONT['FC']; /** * Used for collecting styles needed for the output jax @@ -279,17 +235,17 @@ export abstract class CommonOutputJax< /** * The MathDocument for the math we find */ - public document: MathDocument; + public document: MathDocument; /** * the MathItem currently being processed */ - public math: MathItem; + public math: MathItem; /** * The container element for the math */ - public container: N; + public container: N; /** * The top-level table, if any @@ -304,7 +260,7 @@ export abstract class CommonOutputJax< /** * The data for the font in use */ - public font: FD; + public font: FONT['FD']; /** * The wrapper factory for the MathML nodes @@ -314,12 +270,7 @@ export abstract class CommonOutputJax< /** * The linebreak visitor to use for automatic linebreaks */ - /* prettier-ignore */ - public linebreaks: Linebreaks< - N, T, D, - CommonOutputJax, - WW, WF, WC, CC, VV, DD, FD, FC - >; + public linebreaks: Linebreaks; /** * @returns {boolean} True when in-line breaks need to be forced (e.g., for @@ -344,12 +295,12 @@ export abstract class CommonOutputJax< /** * Node used to test for in-line metric data */ - public testInline: N; + public testInline: N; /** * Node used to test for display metric data */ - public testDisplay: N; + public testDisplay: N; /** * Cache of unknonw character bounding boxes for this element @@ -359,7 +310,7 @@ export abstract class CommonOutputJax< /** * @override */ - public options: COMMON_OPTIONS, WW, WF, WC, CC, VV, DD, FD, FC>; + public options: COMMON_OPTIONS; /*****************************************************************/ @@ -369,13 +320,13 @@ export abstract class CommonOutputJax< * * @param {OptionList} options The configuration options * @param {CommonWrapperFactory} defaultFactory The default wrapper factory class - * @param {FC} defaultFont The default FontData constructor + * @param {FONT['FC']} defaultFont The default FontData constructor * @class */ constructor( options: OptionList = {}, defaultFactory: typeof CommonWrapperFactory = null, - defaultFont: FC = null + defaultFont: FONT['FC'] = null ) { const [fontClass, font] = options.fontData instanceof FontData @@ -388,18 +339,14 @@ export abstract class CommonOutputJax< super(jaxOptions); this.factory = (this.options.wrapperFactory as any) || - /* prettier-ignore */ - new defaultFactory< - N, T, D, - CommonOutputJax, - WW, WF, WC, CC, VV, DD, FD, FC - >(); - this.factory.jax = this; + new defaultFactory(); + this.factory.jax = this as any as JX; this.styleJson = this.options.styleJson || new StyleJsonSheet(); this.font = font || new fontClass(fontOptions); this.font.setOptions({ mathmlSpacing: this.options.mathmlSpacing }); - /* prettier-ignore */ - (this.constructor as typeof CommonOutputJax).genericFont = fontClass; + ( + this.constructor as typeof CommonOutputJax + ).genericFont = fontClass; this.unknownCache = new Map(); const linebreaks = (this.options.linebreaks.LinebreakVisitor || LinebreakVisitor) as typeof Linebreaks; @@ -409,7 +356,7 @@ export abstract class CommonOutputJax< /** * @override */ - public setAdaptor(adaptor: DOMAdaptor) { + public setAdaptor(adaptor: DOMAdaptor) { super.setAdaptor(adaptor); // // Set the htmlHDW option based on the adaptor's ability to measure nodes @@ -427,7 +374,7 @@ export abstract class CommonOutputJax< * @returns {string[]} New CSS rules needed for the font */ public addExtension( - font: FontExtensionData, + font: FontExtensionData, prefix: string = '' ): string[] { return this.font.addExtension(font, prefix); @@ -443,11 +390,11 @@ export abstract class CommonOutputJax< * * @override */ - public typeset(math: MathItem, html: MathDocument) { + public typeset(math: MathItem, html: MathDocument) { /* prettier-ignore */ - const CLASS = (this.constructor as typeof CommonOutputJax); + const CLASS = this.constructor as typeof CommonOutputJax; const generic = CLASS.genericFont; - CLASS.genericFont = this.font.constructor as FontDataClass; + CLASS.genericFont = this.font.constructor as FONT['FC']; this.setDocument(html); const node = this.createNode(); try { @@ -459,9 +406,9 @@ export abstract class CommonOutputJax< } /** - * @returns {N} The container DOM node for the typeset math + * @returns {N} The container DOM node for the typeset math */ - protected createNode(): N { + protected createNode(): N { const jax = (this.constructor as typeof CommonOutputJax).NAME; return this.html('mjx-container', { class: 'MathJax', @@ -471,10 +418,10 @@ export abstract class CommonOutputJax< } /** - * @param {N} node The container whose scale is to be set + * @param {N} node The container whose scale is to be set * @param {WW} wrapper The wrapper for the math element being scaled */ - protected setScale(node: N, wrapper: WW) { + protected setScale(node: N, wrapper: WW) { let scale = this.getInitialScale() * this.options.scale; if ( wrapper.node.attributes.get('overflow') === 'scale' && @@ -510,13 +457,13 @@ export abstract class CommonOutputJax< * Execute the post-filters * * @param {MathItem} math The math item to convert - * @param {N} node The contaier to place the result into + * @param {N} node The contaier to place the result into * @param {MathDocument} html The document containing the math */ public toDOM( - math: MathItem, - node: N, - html: MathDocument = null + math: MathItem, + node: N, + html: MathDocument = null ) { this.setDocument(html); this.math = math; @@ -564,9 +511,9 @@ export abstract class CommonOutputJax< * This is the actual typesetting function supplied by the subclass * * @param {WW} wrapper The wrapped intenral MathML node of the root math element to process - * @param {N} node The container node where the math is to be typeset + * @param {N} node The container node where the math is to be typeset */ - public abstract processMath(wrapper: WW, node: N): void; + public abstract processMath(wrapper: WW, node: N): void; /*****************************************************************/ @@ -575,7 +522,7 @@ export abstract class CommonOutputJax< * @param {MathDocument} html The MathDocument for the math * @returns {BBox} The bounding box */ - public getBBox(math: MathItem, html: MathDocument): BBox { + public getBBox(math: MathItem, html: MathDocument): BBox { this.setDocument(html); this.math = math; math.root.setTeXclass(null); @@ -693,7 +640,7 @@ export abstract class CommonOutputJax< * @param {MmlNode} node The parent node to mark * @param {MmlNode} child The child node to mark * @param {MmlNode} mo The core mo to mark - * @returns {boolean} The modified marked variable + * @returns {boolean} The modified marked variable */ protected markInlineBreak( marked: boolean, @@ -744,7 +691,7 @@ export abstract class CommonOutputJax< /** * @override */ - public getMetrics(html: MathDocument) { + public getMetrics(html: MathDocument) { this.setDocument(html); const adaptor = this.adaptor; const maps = this.getMetricMaps(html); @@ -766,11 +713,11 @@ export abstract class CommonOutputJax< } /** - * @param {N} node The container node whose metrics are to be measured + * @param {N} node The container node whose metrics are to be measured * @param {boolean} display True if the metrics are for displayed math - * @returns {Metrics} Object containing em, ex, containerWidth, etc. + * @returns {Metrics} Object containing em, ex, containerWidth, etc. */ - public getMetricsFor(node: N, display: boolean): ExtendedMetrics { + public getMetricsFor(node: N, display: boolean): ExtendedMetrics { const getFamily = this.options.mtextInheritFont || this.options.merrorInheritFont; const test = this.getTestElement(node, display); @@ -783,13 +730,13 @@ export abstract class CommonOutputJax< * Get a MetricMap for the math list * * @param {MathDocument} html The math document whose math list is to be processed. - * @returns {MetricMap[]} The node-to-metrics maps for all the containers that have math + * @returns {MetricMap[]} The node-to-metrics maps for all the containers that have math */ - protected getMetricMaps(html: MathDocument): MetricMap[] { + protected getMetricMaps(html: MathDocument): MetricMap[] { const adaptor = this.adaptor; const domMaps = [ - new Map() as MetricDomMap, - new Map() as MetricDomMap, + new Map() as MetricDomMap, + new Map() as MetricDomMap, ]; // // Add the test elements all at once (so only one reflow) @@ -812,7 +759,7 @@ export abstract class CommonOutputJax< // const getFamily = this.options.mtextInheritFont || this.options.merrorInheritFont; - const maps = [new Map() as MetricMap, new Map() as MetricMap]; + const maps = [new Map() as MetricMap, new Map() as MetricMap]; for (const i of maps.keys()) { for (const node of domMaps[i].keys()) { maps[i].set(node, this.measureMetrics(domMaps[i].get(node), getFamily)); @@ -830,11 +777,11 @@ export abstract class CommonOutputJax< } /** - * @param {N} node The math element to be measured - * @param {boolean} display Is the element in display math? - * @returns {N} The test elements that were added + * @param {N} node The math element to be measured + * @param {boolean} display Is the element in display math? + * @returns {N} The test elements that were added */ - protected getTestElement(node: N, display: boolean): N { + protected getTestElement(node: N, display: boolean): N { const adaptor = this.adaptor; if (!this.testInline) { this.testInline = this.html( @@ -885,38 +832,38 @@ export abstract class CommonOutputJax< adaptor.setStyle(this.testDisplay, 'display', 'table'); adaptor.setStyle(this.testDisplay, 'margin-right', ''); adaptor.setStyle( - adaptor.firstChild(this.testDisplay) as N, + adaptor.firstChild(this.testDisplay) as N, 'display', 'none' ); - const right = adaptor.lastChild(this.testDisplay) as N; + const right = adaptor.lastChild(this.testDisplay) as N; adaptor.setStyle(right, 'display', 'table-cell'); adaptor.setStyle(right, 'width', '10000em'); adaptor.setStyle(right, 'float', ''); } return adaptor.append( node, - adaptor.clone(display ? this.testDisplay : this.testInline) as N - ) as N; + adaptor.clone(display ? this.testDisplay : this.testInline) as N + ) as N; } /** - * @param {N} node The test node to measure + * @param {N} node The test node to measure * @param {boolean} getFamily True if font family of surroundings is to be determined - * @returns {ExtendedMetrics} The metric data for the given node + * @returns {ExtendedMetrics} The metric data for the given node */ - protected measureMetrics(node: N, getFamily: boolean): ExtendedMetrics { + protected measureMetrics(node: N, getFamily: boolean): ExtendedMetrics { const adaptor = this.adaptor; const family = getFamily ? adaptor.fontFamily(node) : ''; const em = adaptor.fontSize(node); - const [w, h] = adaptor.nodeSize(adaptor.childNode(node, 1) as N); + const [w, h] = adaptor.nodeSize(adaptor.childNode(node, 1) as N); const ex = w ? h / 60 : em * this.options.exFactor; const containerWidth = !w ? 1000000 : adaptor.getStyle(node, 'display') === 'table' - ? adaptor.nodeSize(adaptor.lastChild(node) as N)[0] - 1 - : adaptor.nodeBBox(adaptor.lastChild(node) as N).left - - adaptor.nodeBBox(adaptor.firstChild(node) as N).left - + ? adaptor.nodeSize(adaptor.lastChild(node) as N)[0] - 1 + : adaptor.nodeBBox(adaptor.lastChild(node) as N).left - + adaptor.nodeBBox(adaptor.firstChild(node) as N).left - 2; const scale = Math.max( this.options.minScale, @@ -932,7 +879,7 @@ export abstract class CommonOutputJax< /** * @override */ - public styleSheet(html: MathDocument) { + public styleSheet(html: MathDocument) { this.setDocument(html); // // Start with the common styles @@ -960,7 +907,7 @@ export abstract class CommonOutputJax< const sheet = this.html('style', { id: 'MJX-styles' }, [ this.text('\n' + this.styleJson.cssText + '\n'), ]); - return sheet as N; + return sheet as N; } /** @@ -987,10 +934,7 @@ export abstract class CommonOutputJax< CLASS: typeof CommonWrapper, styles: StyleJsonSheet ) { - CLASS.addStyles>( - styles, - this - ); + CLASS.addStyles>(styles, this); } /** @@ -1005,7 +949,7 @@ export abstract class CommonOutputJax< /** * @param {MathDocument} html The document to be used */ - protected setDocument(html: MathDocument) { + protected setDocument(html: MathDocument) { if (html) { this.document = html; this.adaptor.document = html.document; @@ -1017,30 +961,30 @@ export abstract class CommonOutputJax< * @param {OptionList} def The properties to set on the HTML node * @param {(N|T)[]} content Array of child nodes to set for the HTML node * @param {string} ns The namespace for the element - * @returns {N} The newly created DOM tree + * @returns {N} The newly created DOM tree */ public html( type: string, def: OptionList = {}, - content: (N | T)[] = [], + content: (N | T)[] = [], ns?: string - ): N { + ): N { return this.adaptor.node(type, def, content, ns); } /** * @param {string} text The text string for which to make a text node * - * @returns {T} A text node with the given text + * @returns {T} A text node with the given text */ - public text(text: string): T { + public text(text: string): T { return this.adaptor.text(text); } /** * @param {number} m A number to be shown with a fixed number of digits * @param {number=} n The number of digits to use - * @returns {string} The formatted number + * @returns {string} The formatted number */ public fixed(m: number, n: number = 3): string { if (Math.abs(m) < 0.0006) { @@ -1060,9 +1004,9 @@ export abstract class CommonOutputJax< * * @param {string} text The text to be displayed * @param {string} variant The name of the variant for the text - * @returns {N} The text element containing the text + * @returns {N} The text element containing the text */ - public abstract unknownText(text: string, variant: string): N; + public abstract unknownText(text: string, variant: string): N; /** * Measure text from a specific font, or that isn't in the MathJax font @@ -1070,7 +1014,7 @@ export abstract class CommonOutputJax< * @param {string} text The text to measure * @param {string} variant The variant for the text * @param {CssFontData} font The family, italic, and bold data for explicit fonts - * @returns {UnknownBBox} The width, height, and depth of the text (in ems) + * @returns {UnknownBBox} The width, height, and depth of the text (in ems) */ public measureText( text: string, @@ -1089,14 +1033,14 @@ export abstract class CommonOutputJax< * Get the size of a text node, caching the result, and using * a cached result, if there is one. * - * @param {N} text The text element to measure + * @param {N} text The text element to measure * @param {string} chars The string contained in the text node * @param {string} variant The variant for the text * @param {CssFontData} font The family, italic, and bold data for explicit fonts - * @returns {UnknownBBox} The width, height and depth for the text + * @returns {UnknownBBox} The width, height and depth for the text */ public measureTextNodeWithCache( - text: N, + text: N, chars: string, variant: string, font: CssFontData = ['', false, false] @@ -1121,15 +1065,15 @@ export abstract class CommonOutputJax< * Measure the width of a text element by placing it in the page * and looking up its size (fake the height and depth, since we can't measure that) * - * @param {N} text The text element to measure - * @returns {UnknownBBox} The width, height and depth for the text (in ems) + * @param {N} text The text element to measure + * @returns {UnknownBBox} The width, height and depth for the text (in ems) */ - public abstract measureTextNode(text: N): UnknownBBox; + public abstract measureTextNode(text: N): UnknownBBox; /** * @param {CssFontData} font The family, style, and weight for the given font * @param {StyleList} styles The style object to add the font data to - * @returns {StyleList} The modified (or initialized) style object + * @returns {StyleList} The modified (or initialized) style object */ public cssFontStyles(font: CssFontData, styles: StyleList = {}): StyleList { const [family, italic, bold] = font; @@ -1141,7 +1085,7 @@ export abstract class CommonOutputJax< /** * @param {Styles} styles The style object to query - * @returns {CssFontData} The family, italic, and boolean values + * @returns {CssFontData} The family, italic, and boolean values */ public getFontData(styles: Styles): CssFontData { if (!styles) { diff --git a/ts/output/common/FontData.ts b/ts/output/common/FontData.ts index d7b17cbc4c..892f7e80bd 100644 --- a/ts/output/common/FontData.ts +++ b/ts/output/common/FontData.ts @@ -41,15 +41,14 @@ export const HFUZZ = 0.07; // overlap for horizontal stretchy glyphs /** * The extra options allowed in a CharData array */ -/* prettier-ignore */ export interface CharOptions { - ic?: number; // italic correction value - oc?: number; // original ic for -tex-mit font - sk?: number; // skew value - dx?: number; // offset for combining characters - unknown?: boolean; // true if not found in the given variant - smp?: number; // Math Alphanumeric codepoint this char is mapped to - hd?: [number, number]; // the original height and depth for an extender + ic?: number; // Italic correction value + oc?: number; // Original ic for -tex-mit font + sk?: number; // Skew value + dx?: number; // Offset for combining characters + unknown?: boolean; // True if not found in the given variant + smp?: number; // Math Alphanumeric codepoint this char is mapped to + hd?: [number, number]; // The original height and depth for an extender } /****************************************************************************/ @@ -135,22 +134,21 @@ export type CssFontMap = { /** * Data needed for stretchy vertical and horizontal characters */ -/* prettier-ignore */ export type DelimiterData = { - dir: string; // vertical or horizontal direction - sizes?: number[]; // Array of fixed sizes for this character - variants?: number[]; // The variants in which the different sizes can be found (if not the default) - schar?: number[]; // The character number to use for each size (if different from the default) - stretch?: number[]; // The unicode code points for the parts of multi-character versions [beg, ext, end, mid?] - stretchv?: number[]; // the variants to use for the stretchy characters (index into variant name array) - HDW?: number[]; // [h, d, w] (for vertical, h and d are the normal size, w is the multi-character width, - // for horizontal, h and d are the multi-character ones, w is for the normal size). - hd?: number[]; // The extender's original [h, d] values - ext?: number; // The extenders left- plus right-bearing - min?: number; // The minimum size a multi-character version can be - c?: number; // The character number (for aliased delimiters) - fullExt?: [number, number] // When present, extenders must be full sized, and the first number is - // the size of the extender, while the second is the total size of the ends + dir: string; // Vertical or horizontal direction + sizes?: number[]; // Array of fixed sizes for this character + variants?: number[]; // The variants in which the different sizes can be found (if not the default) + schar?: number[]; // The character number to use for each size (if different from the default) + stretch?: number[]; // The unicode code points for the parts of multi-character versions [beg, ext, end, mid?] + stretchv?: number[]; // The variants to use for the stretchy characters (index into variant name array) + HDW?: number[]; // [h, d, w] (for vertical, h and d are the normal size, w is the multi-character width, + // For horizontal, h and d are the multi-character ones, w is for the normal size). + hd?: number[]; // The extender's original [h, d] values + ext?: number; // The extenders left- plus right-bearing + min?: number; // The minimum size a multi-character version can be + c?: number; // The character number (for aliased delimiters) + fullExt?: [number, number]; // When present, extenders must be full sized, and the first number is + // The size of the extender, while the second is the total size of the ends }; /** @@ -286,15 +284,14 @@ export type DynamicFileDef = [string, DynamicVariants, DynamicRanges?]; /** * Data stored about a dynamic font */ -/* prettier-ignore */ export type DynamicFile = { - extension: string; // name of the extension for this file (or blank) - file: string; // file containing the character data - variants: DynamicVariants; // characters in each variant in the file - delimiters: DynamicRanges; // delimiters in the file - setup: DynamicSetup; // setup function to call to add the characters to the font - promise: Promise; // promise for when the file is loaded - failed: boolean; // true when loading has failed + extension: string; // Name of the extension for this file (or blank) + file: string; // File containing the character data + variants: DynamicVariants; // Characters in each variant in the file + delimiters: DynamicRanges; // Delimiters in the file + setup: DynamicSetup; // Setup function to call to add the characters to the font + promise: Promise; // Promise for when the file is loaded + failed: boolean; // True when loading has failed }; /** @@ -514,88 +511,83 @@ export class FontData< /** * Character ranges to remap into Math Alphanumerics */ - /* prettier-ignore */ public static SmpRanges = [ - [0, 0x41, 0x5A], // Upper-case alpha - [1, 0x61, 0x7A], // Lower-case alpha - [2, 0x391, 0x3A9], // Upper-case Greek - [3, 0x3B1, 0x3C9], // Lower-case Greek - [4, 0x30, 0x39] // Numbers + [0, 0x41, 0x5a], // Upper-case alpha + [1, 0x61, 0x7a], // Lower-case alpha + [2, 0x391, 0x3a9], // Upper-case Greek + [3, 0x3b1, 0x3c9], // Lower-case Greek + [4, 0x30, 0x39], // Numbers ]; /** * Characters to map back to other Unicode positions * (holes in the Math Alphanumeric ranges) */ - /* prettier-ignore */ public static SmpRemap: SmpMap = { - 0x1D455: 0x210E, // PLANCK CONSTANT - 0x1D49D: 0x212C, // SCRIPT CAPITAL B - 0x1D4A0: 0x2130, // SCRIPT CAPITAL E - 0x1D4A1: 0x2131, // SCRIPT CAPITAL F - 0x1D4A3: 0x210B, // SCRIPT CAPITAL H - 0x1D4A4: 0x2110, // SCRIPT CAPITAL I - 0x1D4A7: 0x2112, // SCRIPT CAPITAL L - 0x1D4A8: 0x2133, // SCRIPT CAPITAL M - 0x1D4AD: 0x211B, // SCRIPT CAPITAL R - 0x1D4BA: 0x212F, // SCRIPT SMALL E - 0x1D4BC: 0x210A, // SCRIPT SMALL G - 0x1D4C4: 0x2134, // SCRIPT SMALL O - 0x1D506: 0x212D, // BLACK-LETTER CAPITAL C - 0x1D50B: 0x210C, // BLACK-LETTER CAPITAL H - 0x1D50C: 0x2111, // BLACK-LETTER CAPITAL I - 0x1D515: 0x211C, // BLACK-LETTER CAPITAL R - 0x1D51D: 0x2128, // BLACK-LETTER CAPITAL Z - 0x1D53A: 0x2102, // DOUBLE-STRUCK CAPITAL C - 0x1D53F: 0x210D, // DOUBLE-STRUCK CAPITAL H - 0x1D545: 0x2115, // DOUBLE-STRUCK CAPITAL N - 0x1D547: 0x2119, // DOUBLE-STRUCK CAPITAL P - 0x1D548: 0x211A, // DOUBLE-STRUCK CAPITAL Q - 0x1D549: 0x211D, // DOUBLE-STRUCK CAPITAL R - 0x1D551: 0x2124, // DOUBLE-STRUCK CAPITAL Z + 0x1d455: 0x210e, // Planck CONSTANT + 0x1d49d: 0x212c, // Script CAPITAL B + 0x1d4a0: 0x2130, // Script CAPITAL E + 0x1d4a1: 0x2131, // Script CAPITAL F + 0x1d4a3: 0x210b, // Script CAPITAL H + 0x1d4a4: 0x2110, // Script CAPITAL I + 0x1d4a7: 0x2112, // Script CAPITAL L + 0x1d4a8: 0x2133, // Script CAPITAL M + 0x1d4ad: 0x211b, // Script CAPITAL R + 0x1d4ba: 0x212f, // Script SMALL E + 0x1d4bc: 0x210a, // Script SMALL G + 0x1d4c4: 0x2134, // Script SMALL O + 0x1d506: 0x212d, // Black-LETTER CAPITAL C + 0x1d50b: 0x210c, // Black-LETTER CAPITAL H + 0x1d50c: 0x2111, // Black-LETTER CAPITAL I + 0x1d515: 0x211c, // Black-LETTER CAPITAL R + 0x1d51d: 0x2128, // Black-LETTER CAPITAL Z + 0x1d53a: 0x2102, // Double-STRUCK CAPITAL C + 0x1d53f: 0x210d, // Double-STRUCK CAPITAL H + 0x1d545: 0x2115, // Double-STRUCK CAPITAL N + 0x1d547: 0x2119, // Double-STRUCK CAPITAL P + 0x1d548: 0x211a, // Double-STRUCK CAPITAL Q + 0x1d549: 0x211d, // Double-STRUCK CAPITAL R + 0x1d551: 0x2124, // Double-STRUCK CAPITAL Z }; /** * Greek upper-case variants */ - /* prettier-ignore */ public static SmpRemapGreekU: SmpMap = { - 0x2207: 0x19, // nabla - 0x03F4: 0x11 // theta symbol + 0x2207: 0x19, // Nabla + 0x03f4: 0x11, // Theta symbol }; /** * Greek lower-case variants */ - /* prettier-ignore */ public static SmpRemapGreekL: SmpMap = { - 0x3D1: 0x1B, // theta symbol - 0x3D5: 0x1D, // phi symbol - 0x3D6: 0x1F, // omega symbol - 0x3F0: 0x1C, // kappa symbol - 0x3F1: 0x1E, // rho symbol - 0x3F5: 0x1A, // lunate epsilon symbol - 0x2202: 0x19 // partial differential + 0x3d1: 0x1b, // theta symbol + 0x3d5: 0x1d, // phi symbol + 0x3d6: 0x1f, // omega symbol + 0x3f0: 0x1c, // kappa symbol + 0x3f1: 0x1e, // rho symbol + 0x3f5: 0x1a, // lunate epsilon symbol + 0x2202: 0x19, // partial differential }; /** * The default remappings */ - /* prettier-ignore */ public static defaultAccentMap: RemapMap = { - 0x005E: '\u02C6', // hat - 0x007E: '\u02DC', // tilde - 0x0300: '\u02CB', // grave accent - 0x0301: '\u02CA', // acute accent - 0x0302: '\u02C6', // curcumflex - 0x0303: '\u02DC', // tilde accent - 0x0304: '\u02C9', // macron - 0x0306: '\u02D8', // breve - 0x0307: '\u02D9', // dot - 0x0308: '\u00A8', // diaresis - 0x030A: '\u02DA', // ring above - 0x030C: '\u02C7', // caron - 0x2192: '\u20D7' + 0x005e: '\u02C6', // Hat + 0x007e: '\u02DC', // Tilde + 0x0300: '\u02CB', // Grave accent + 0x0301: '\u02CA', // Acute accent + 0x0302: '\u02C6', // Curcumflex + 0x0303: '\u02DC', // Tilde accent + 0x0304: '\u02C9', // Macron + 0x0306: '\u02D8', // Breve + 0x0307: '\u02D9', // Dot + 0x0308: '\u00A8', // Diaresis + 0x030a: '\u02DA', // Ring above + 0x030c: '\u02C7', // Caron + 0x2192: '\u20D7', // Vector }; /** @@ -648,11 +640,11 @@ export class FontData< delimiterfactor: 901, delimitershortfall: .3, - rule_factor: 1.25, // multiply surd_height and rule_thickness by this for CHTML - min_rule_thickness: 1.25, // in pixels - separation_factor: 1.75, // expansion factor for spacing e.g. between accents and base - extra_ic: .033, // extra spacing for scripts (compensate for not having actual ic values) - extender_factor: .333 // factor to adjust between full stretchy height/depth and extender height/depth + rule_factor: 1.25, // Multiply surd_height and rule_thickness by this for CHTML + min_rule_thickness: 1.25, // In pixels + separation_factor: 1.75, // Expansion factor for spacing e.g. between accents and base + extra_ic: .033, // Extra spacing for scripts (compensate for not having actual ic values) + extender_factor: .333, // Factor to adjust between full stretchy height/depth and extender height/depth }; /** @@ -753,8 +745,8 @@ export class FontData< } /** - * @param {CharMap} font The font to check - * @param {number} n The character to get options for + * @param {CharMap} font The font to check + * @param {number} n The character to get options for * @returns {CharOptions} The options for the character */ public static charOptions( @@ -778,8 +770,8 @@ export class FontData< /** * Define the dynamic file information. * - * @param {DynamicFileDef[]} dynamicFiles The definitions to make - * @param {string} extension The name of the extension for this file (or empty) + * @param {DynamicFileDef[]} dynamicFiles The definitions to make + * @param {string} extension The name of the extension for this file (or empty) * @returns {DynamicFileList} The object of dynamic file data */ public static defineDynamicFiles( @@ -806,11 +798,12 @@ export class FontData< /** * Create the setup function for a given dynamically loaded file * - * @param {string} extension The name of the font extension for this file - * @param {string} file The file being loaded - * @param {CharMapMap} variants The character data to be added - * @param {DelimiterMap} delimiters The delimiter data to be added - * @param {string[]} fonts The fonts to add CSS to + * @param {string} extension The name of the font extension for this file + * @param {string} file The file being loaded + * @param {CharMapMap} variants The character data to be added + * @param {DelimiterMap} delimiters The delimiter data to be added + * @param {string[]} fonts The fonts to add CSS to + * * @template C The CharOptions type * @template D The DelimiterData type */ @@ -968,7 +961,7 @@ export class FontData< * * @param {FontExtensionData} data The data for the font extension to merge into this font. * @param {string} prefix The [prefix] to add to all component names - * @returns {string[]} The new CSS rules needed for this extension + * @returns {string[]} The new CSS rules needed for this extension */ public addExtension( data: FontExtensionData, @@ -1063,7 +1056,7 @@ export class FontData< * @param {string} name The new variant to create * @param {string} inherit The variant to use if a character is not in this one * @param {string} link A variant to search before the inherit one (but only - * its top-level object). + * its top-level object). */ public createVariant( name: string, @@ -1089,8 +1082,8 @@ export class FontData< * Create the mapping from Basic Latin and Greek blocks to * the Math Alphanumeric block for a given variant. * - * @param {CharMap} chars The character mapping to fill. - * @param {string} name The new variant name. + * @param {CharMap} chars The character mapping to fill. + * @param {string} name The new variant name. */ protected remapSmpChars(chars: CharMap, name: string) { const CLASS = this.CLASS; @@ -1122,7 +1115,7 @@ export class FontData< } /** - * @param {number} n Math Alphanumerics position for this remapping + * @param {number} n Math Alphanumerics position for this remapping * @returns {CharDataArray} The character data for the remapping */ protected smpChar(n: number): CharDataArray { @@ -1133,7 +1126,7 @@ export class FontData< * Create a collection of variants * * @param {string[][]} variants Array of [name, inherit?, link?] values for - * the variants to define + * the variants to define */ public createVariants(variants: string[][]) { for (const variant of variants) { @@ -1219,7 +1212,7 @@ export class FontData< * * @param {DynamicRanges} ranges The ranges to be flattened * @param {DynamicFile} dynamic The DynamicFile to tie to the ranges - * @returns {DynamicCharMap} The map from character positions to dynamic file + * @returns {DynamicCharMap} The map from character positions to dynamic file */ protected flattenRanges( ranges: DynamicRanges, @@ -1240,7 +1233,7 @@ export class FontData< /** * @param {DynamicFile} dynamic The data for the dynamic file - * @returns {string} The prefixed name for the file + * @returns {string} The prefixed name for the file */ protected dynamicFileName(dynamic: DynamicFile): string { const prefix = !dynamic.extension @@ -1256,7 +1249,7 @@ export class FontData< * and do any associated setup that needs access to the FontData instance. * * @param {DynamicFile} dynamic The data for the file to load - * @returns {Promise} The promise that is resolved when the file is loaded + * @returns {Promise} The promise that is resolved when the file is loaded */ public async loadDynamicFile(dynamic: DynamicFile): Promise { if (dynamic.failed) { @@ -1352,8 +1345,8 @@ export class FontData< public addDynamicFontCss(_fonts: string[], _root?: string) {} /** - * @param {number} n The delimiter character number whose data is desired - * @returns {DelimiterData} The data for that delimiter (or undefined) + * @param {number} n The delimiter character number whose data is desired + * @returns {DelimiterData} The data for that delimiter (or undefined) */ public getDelimiter(n: number): DelimiterData { const delim = this.delimiters[n]; @@ -1370,8 +1363,8 @@ export class FontData< } /** - * @param {number} n The delimiter character number whose variant is needed - * @param {number} i The index in the size array of the size whose variant is needed + * @param {number} n The delimiter character number whose variant is needed + * @param {number} i The index in the size array of the size whose variant is needed * @returns {string} The variant of the i-th size for delimiter n */ public getSizeVariant(n: number, i: number): string { @@ -1383,8 +1376,8 @@ export class FontData< } /** - * @param {number} n The delimiter character number whose variant is needed - * @param {number} i The index in the stretch array of the part whose variant is needed + * @param {number} n The delimiter character number whose variant is needed + * @param {number} i The index in the stretch array of the part whose variant is needed * @returns {string} The variant of the i-th part for delimiter n */ public getStretchVariant(n: number, i: number): string { @@ -1393,7 +1386,7 @@ export class FontData< } /** - * @param {number} n The delimiter character number whose variants are needed + * @param {number} n The delimiter character number whose variants are needed * @returns {string[]} The variants for the parts of the delimiter */ public getStretchVariants(n: number): string[] { @@ -1403,7 +1396,7 @@ export class FontData< /** * @param {string} name The variant whose character data is being querried * @param {number} n The unicode number for the character to be found - * @returns {CharDataArray} The data for the given character (or undefined) + * @returns {CharDataArray} The data for the given character (or undefined) */ public getChar(name: string, n: number): CharDataArray { const char = this.variant[name].chars[n]; @@ -1437,7 +1430,7 @@ export class FontData< /** * @param {string} name The name of the variant whose data is to be obtained - * @returns {V} The data for the requested variant (or undefined) + * @returns {V} The data for the requested variant (or undefined) */ public getVariant(name: string): V { return this.variant[name]; @@ -1445,7 +1438,7 @@ export class FontData< /** * @param {string} variant The name of the variant whose data is to be obtained - * @returns {CssFontData} The CSS data for the requested variant + * @returns {CssFontData} The CSS data for the requested variant */ public getCssFont(variant: string): CssFontData { return this.cssFontMap[variant] || ['serif', false, false]; @@ -1453,7 +1446,7 @@ export class FontData< /** * @param {string} family The font camily to use - * @returns {string} The family with the css prefix + * @returns {string} The family with the css prefix */ public getFamily(family: string): string { return this.cssFamilyPrefix ? this.cssFamilyPrefix + ', ' + family : family; @@ -1462,7 +1455,7 @@ export class FontData< /** * @param {string} name The name of the map to query * @param {number} c The character to remap - * @returns {string} The remapped character (or the original) + * @returns {string} The remapped character (or the original) */ public getRemappedChar(name: string, c: number): string { const map = this.remapChars[name] || ({} as RemapMap); diff --git a/ts/output/common/LinebreakVisitor.ts b/ts/output/common/LinebreakVisitor.ts index cc219e35b2..87a6cb4668 100644 --- a/ts/output/common/LinebreakVisitor.ts +++ b/ts/output/common/LinebreakVisitor.ts @@ -22,15 +22,8 @@ */ import { AbstractVisitor } from '../../core/Tree/Visitor.js'; -import { CommonOutputJax } from '../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../common.js'; import { CommonWrapperFactory } from './WrapperFactory.js'; -import { - FontData, - FontDataClass, - DelimiterData, - VariantData, - CharOptions, -} from './FontData.js'; import { CommonWrapper, CommonWrapperClass } from './Wrapper.js'; import { CommonMo } from './Wrappers/mo.js'; import { CommonMspace } from './Wrappers/mspace.js'; @@ -46,6 +39,7 @@ import { LineBBox } from './LineBBox.js'; import { TEXCLASS } from '../../core/MmlTree/MmlNode.js'; import { OPTABLE } from '../../core/MmlTree/OperatorDictionary.js'; import { MmlNode, TextNode } from '../../core/MmlTree/MmlNode.js'; +import { DOM_TYPES } from '../../types/Types.js'; /************************************************************************************/ @@ -69,17 +63,16 @@ export type BreakData = [[WW, IndexData], number, number, number, number]; /** * The data used for a line-breaking operation */ -/* prettier-ignore */ export interface StateData { - breaks: Set<[WW, IndexData]>; // The breakpoints to use and the break index (for mtext) - potential: BreakData[]; // The list of best breakpoints so far - width: number; // The maximum width for the lines - w: number; // The accumulated width since the last best breakpoint - prevWidth: number; // The width of the previous line - prevBreak: BreakData; // The most recent breakpoint used - depth: number; // The nesting depth of the active node - mathWidth: number; // The full width of the unbroken math - mathLeft: number; // The amount of width left after the most recent break + breaks: Set<[WW, IndexData]>; // The breakpoints to use and the break index (for mtext) + potential: BreakData[]; // The list of best breakpoints so far + width: number; // The maximum width for the lines + w: number; // The accumulated width since the last best breakpoint + prevWidth: number; // The width of the previous line + prevBreak: BreakData; // The most recent breakpoint used + depth: number; // The nesting depth of the active node + mathWidth: number; // The full width of the unbroken math + mathLeft: number; // The amount of width left after the most recent break } /************************************************************************************/ @@ -87,32 +80,19 @@ export interface StateData { /** * A do-nothing linebreaker for use when automatic linebreaks are not requested * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export class Linebreaks< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, > extends AbstractVisitor { /** * Break a line to the given width @@ -129,33 +109,20 @@ export class Linebreaks< */ /** - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export class LinebreakVisitor< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends Linebreaks { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends Linebreaks { /** * Penalty functions for the various linebreak values */ @@ -173,7 +140,7 @@ export class LinebreakVisitor< protected FACTORS: { [key: string]: ( p: number, - mo?: CommonMo + mo?: CommonMo ) => number; } = { // @@ -249,10 +216,7 @@ export class LinebreakVisitor< // Adjust for mspace width // space: (p, node) => { - /* prettier-ignore */ - const mspace = node as any as CommonMspace< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const mspace = node as any as CommonMspace; if (!mspace.canBreak) return NOBREAK; const w = mspace.getBBox().w; return w < 0 ? NOBREAK : w < 1 ? p : p - 100 * (w + 4); @@ -528,10 +492,7 @@ export class LinebreakVisitor< * @param {number} _i The line within that node to break */ public visitMoNode(wrapper: WW, _i: number) { - /* prettier-ignore */ - const mo = wrapper as any as CommonMo< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const mo = wrapper as any as CommonMo; const bbox = LineBBox.from( mo.getOuterBBox(), mo.linebreakOptions.lineleading @@ -567,9 +528,7 @@ export class LinebreakVisitor< * @param {CommonMo} mo The mo whose penalty is to be computed * @returns {number} The computed penalty */ - protected moPenalty( - mo: CommonMo - ): number { + protected moPenalty(mo: CommonMo): number { const { linebreak, fence, form } = mo.node.attributes.getList( 'linebreak', 'fence', @@ -600,7 +559,7 @@ export class LinebreakVisitor< * @returns {MmlNode | null} The core mo if it exists */ protected getPrevious( - mo: CommonMo + mo: CommonMo ): MmlNode | null { let child = mo.node; let parent = child.parent; @@ -623,10 +582,7 @@ export class LinebreakVisitor< */ public visitMspaceNode(wrapper: WW, i: number) { const bbox = wrapper.getLineBBox(i); - /* prettier-ignore */ - const mspace = wrapper as any as CommonMspace< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const mspace = wrapper as any as CommonMspace; if (mspace.canBreak) { const penalty = this.mspacePenalty(mspace); bbox.getIndentData(wrapper.node); @@ -647,7 +603,7 @@ export class LinebreakVisitor< * @returns {number} The computed penalty */ protected mspacePenalty( - mspace: CommonMspace + mspace: CommonMspace ): number { const linebreak = mspace.node.attributes.get('linebreak'); const FACTORS = this.FACTORS; @@ -671,10 +627,7 @@ export class LinebreakVisitor< this.visitDefault(wrapper, i); return; } - /* prettier-ignore */ - const mtext = wrapper as any as CommonMtext< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const mtext = wrapper as any as CommonMtext; mtext.clearBreakPoints(); const space = mtext.textWidth(' '); const bbox = wrapper.getBBox(); @@ -755,10 +708,7 @@ export class LinebreakVisitor< * @param {number} i The line within that node to break */ public visitMfracNode(wrapper: WW, i: number) { - /* prettier-ignore */ - const mfrac = wrapper as any as CommonMfrac< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const mfrac = wrapper as any as CommonMfrac; if ( !mfrac.node.attributes.get('bevelled') && mfrac.getOuterBBox().w > this.state.width @@ -777,10 +727,7 @@ export class LinebreakVisitor< */ public visitMsqrtNode(wrapper: WW, i: number) { if (wrapper.getOuterBBox().w > this.state.width) { - /* prettier-ignore */ - const msqrt = wrapper as any as CommonMsqrt< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const msqrt = wrapper as any as CommonMsqrt; const base = msqrt.childNodes[msqrt.base]; this.breakToWidth(base, this.state.width - msqrt.rootWidth()); msqrt.getStretchedSurd(); @@ -804,10 +751,7 @@ export class LinebreakVisitor< */ public visitMsubNode(wrapper: WW, i: number) { this.visitDefault(wrapper, i); - /* prettier-ignore */ - const msub = wrapper as any as CommonMsub< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const msub = wrapper as any as CommonMsub; const x = msub.getOffset()[0]; const sbox = msub.scriptChild.getOuterBBox(); const [L, R] = this.getBorderLR(wrapper); @@ -823,10 +767,7 @@ export class LinebreakVisitor< */ public visitMsupNode(wrapper: WW, i: number) { this.visitDefault(wrapper, i); - /* prettier-ignore */ - const msup = wrapper as any as CommonMsup< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const msup = wrapper as any as CommonMsup; const x = msup.getOffset()[0]; const sbox = msup.scriptChild.getOuterBBox(); const [L, R] = this.getBorderLR(wrapper); @@ -842,10 +783,7 @@ export class LinebreakVisitor< */ public visitMsubsupNode(wrapper: WW, i: number) { this.visitDefault(wrapper, i); - /* prettier-ignore */ - const msubsup = wrapper as any as CommonMsubsup< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const msubsup = wrapper as any as CommonMsubsup; const subbox = msubsup.subChild.getOuterBBox(); const supbox = msubsup.supChild.getOuterBBox(); const x = msubsup.getAdjustedIc(); @@ -862,9 +800,7 @@ export class LinebreakVisitor< */ public visitMmultiscriptsNode(wrapper: WW, i: number) { /* prettier-ignore */ - const mmultiscripts = wrapper as any as CommonMmultiscripts< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const mmultiscripts = wrapper as any as CommonMmultiscripts< DOM, FONT, JX, WW, WF, WC>; const data = mmultiscripts.scriptData; if (data.numPrescripts) { const w = Math.max( @@ -896,10 +832,7 @@ export class LinebreakVisitor< * @param {number} i The line within that node to break */ public visitMfencedNode(wrapper: WW, i: number) { - /* prettier-ignore */ - const mfenced = wrapper as any as CommonMfenced< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const mfenced = wrapper as any as CommonMfenced; const bbox = wrapper.getLineBBox(i); const [L, R] = this.getBorderLR(wrapper); if (i === 0) { @@ -918,10 +851,7 @@ export class LinebreakVisitor< * @param {number} i The line within that node to break */ public visitMactionNode(wrapper: WW, i: number) { - /* prettier-ignore */ - const maction = wrapper as any as CommonMaction< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + const maction = wrapper as any as CommonMaction; const bbox = wrapper.getLineBBox(i); const [L, R] = this.getBorderLR(wrapper); if (i === 0) { diff --git a/ts/output/common/Notation.ts b/ts/output/common/Notation.ts index 1897737618..6eaef3c108 100644 --- a/ts/output/common/Notation.ts +++ b/ts/output/common/Notation.ts @@ -23,6 +23,8 @@ import { CommonWrapper } from './Wrapper.js'; import { CommonMenclose } from './Wrappers/menclose.js'; +import { DOM } from '../../types/Types.js'; +import { COMMON_FONT as FONT } from '../common.js'; /*****************************************************************/ @@ -41,15 +43,12 @@ export const SOLID = THICKNESS + 'em solid'; // a solid border * Shorthand for CommonMenclose */ /* prettier-ignore */ -export type Menclose = - CommonMenclose; +export type Menclose = CommonMenclose; /** * Shorthand for CommonWrapper */ -/* prettier-ignore */ -export type AnyWrapper = - CommonWrapper; +export type AnyWrapper = CommonWrapper; /** * Top, right, bottom, left padding data @@ -59,7 +58,8 @@ export type PaddingData = [number, number, number, number]; /** * The functions used for notation definitions * - * @template N The DOM node class + * @template W The menclose wrapper class + * @template N The DOM node class */ export type Renderer = (node: W, child: N) => void; export type BBoxExtender = (node: W) => PaddingData; @@ -72,14 +72,13 @@ export type Initializer = (node: W) => void; * @template W The menclose wrapper class * @template N The DOM node class */ -/* prettier-ignore */ export type NotationDef = { - renderer: Renderer; // renders the DOM nodes for the notation - bbox: BBoxExtender; // gives the offsets to the child bounding box: [top, right, bottom, left] - border?: BBoxBorder; // gives the amount of the bbox offset that is due to borders on the child - renderChild?: boolean; // true if the notation is used to render the child directly (e.g., radical) - init?: Initializer; // function to be called during wrapper construction - remove?: string; // list of notations that are suppressed by this one + renderer: Renderer; // Renders the DOM nodes for the notation + bbox: BBoxExtender; // Gives the offsets to the child bounding box: [top, right, bottom, left] + border?: BBoxBorder; // Gives the amount of the bbox offset that is due to borders on the child + renderChild?: boolean; // True if the notation is used to render the child directly (e.g., radical) + init?: Initializer; // Function to be called during wrapper construction + remove?: string; // List of notations that are suppressed by this one }; /** @@ -147,7 +146,7 @@ export const arrowHead = (node: Menclose): number => { * @param {PaddingData} TRBL The arrow head data * @returns {PaddingData} The adjusted arrow head */ -export const arrowBBoxHD = (node: Menclose, TRBL: PaddingData) => { +export const arrowBBoxHD = (node: Menclose, TRBL: PaddingData): PaddingData => { if (node.childNodes[0]) { const { h, d } = node.childNodes[0].getBBox(); TRBL[0] = TRBL[2] = Math.max( @@ -165,7 +164,7 @@ export const arrowBBoxHD = (node: Menclose, TRBL: PaddingData) => { * @param {PaddingData} TRBL The arrow head data * @returns {PaddingData} The adjusted arrow head */ -export const arrowBBoxW = (node: Menclose, TRBL: PaddingData) => { +export const arrowBBoxW = (node: Menclose, TRBL: PaddingData): PaddingData => { if (node.childNodes[0]) { const { w } = node.childNodes[0].getBBox(); TRBL[1] = TRBL[3] = Math.max(0, node.thickness * node.arrowhead.y - w / 2); diff --git a/ts/output/common/Wrapper.ts b/ts/output/common/Wrapper.ts index 0de08b3cef..29c1d346a0 100644 --- a/ts/output/common/Wrapper.ts +++ b/ts/output/common/Wrapper.ts @@ -38,7 +38,7 @@ import * as LENGTHS from '../../util/lengths.js'; import { Styles } from '../../util/Styles.js'; import { StyleJson, StyleJsonSheet } from '../../util/StyleJson.js'; import { OptionList, lookup } from '../../util/Options.js'; -import { CommonOutputJax } from '../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../common.js'; import { CommonWrapperFactory } from './WrapperFactory.js'; import { CommonMo } from './Wrappers/mo.js'; import { CommonMrow } from './Wrappers/mrow.js'; @@ -46,16 +46,8 @@ import { BBox } from '../../util/BBox.js'; import { LineBBox } from './LineBBox.js'; import { Linebreaks } from './LinebreakVisitor.js'; import { LINEBREAKS as LINEBREAK_OPTIONS } from '../common.js'; -import { - FontData, - FontDataClass, - DelimiterData, - VariantData, - CharOptions, - CharDataArray, - DIRECTION, - NOSTRETCH, -} from './FontData.js'; +import { CharDataArray, DIRECTION, NOSTRETCH } from './FontData.js'; +import { DOM_TYPES, N, T, NT } from '../../types/Types.js'; import { Locale } from '../../util/Locale.js'; import { COMPONENT } from '../../core/__locales__/Component.js'; @@ -123,68 +115,43 @@ export type StyleData = { /** * Generic CommonWrapper constructor * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export type CommonWrapperConstructor< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, /* prettier-ignore */ - CW extends CommonWrapper< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - > = CommonWrapper, + CW extends CommonWrapper + = CommonWrapper, > = new (factory: WF, node: MmlNode, parent?: WW) => CW; /*********************************************************/ /** * The CommonWrapper class interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonWrapperClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, > extends WrapperClass { /** * The wrapper kind @@ -240,32 +207,20 @@ export interface CommonWrapperClass< /** * The base CommonWrapper class * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export class CommonWrapper< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, > extends AbstractWrapper { /** * The wrapper kind @@ -375,7 +330,7 @@ export class CommonWrapper< /** * The DOM tree generated for this wrapper */ - public dom: N[] = null; + public dom: N[] = null; /** * Styles that must be handled directly by the wrappers (mostly having to do with fonts) @@ -419,12 +374,12 @@ export class CommonWrapper< /** * Delimiter data for stretching this node (NOSTRETCH means not yet determined) */ - public stretch: DD = NOSTRETCH as DD; + public stretch: FONT['DD'] = NOSTRETCH; /** * Easy access to the font parameters */ - public font: FD = null; + public font: FONT['FD'] = null; /** * Easy access to the output jax for this node @@ -440,7 +395,7 @@ export class CommonWrapper< * * @returns {DOMAdaptor} The DOMAdaptor object */ - get adaptor(): DOMAdaptor { + get adaptor(): DOMAdaptor { return this.factory.jax.adaptor; } @@ -467,12 +422,7 @@ export class CommonWrapper< * * @returns {Linebreaks} The linebreak visitor */ - /* prettier-ignore */ - get linebreaks(): Linebreaks< - N, T, D, - CommonOutputJax, - WW, WF, WC, CC, VV, DD, FD, FC - > { + get linebreaks(): Linebreaks { return this.jax.linebreaks; } @@ -503,9 +453,7 @@ export class CommonWrapper< ? this.coreMO().embellishedBreakCount : node.arity < 0 && !node.linebreakContainer && - /* prettier-ignore */ - (this.childNodes[0] as any as - CommonMrow) + (this.childNodes[0] as any as CommonMrow) .isStack ? this.childNodes[0].breakCount : 0; @@ -1143,11 +1091,10 @@ export class CommonWrapper< /** * @returns {CommonMo} The wrapper for this node's core node */ - public coreMO(): CommonMo { + public coreMO(): CommonMo { /* prettier-ignore */ - return this.jax.nodeMap.get(this.node.coreMO()) as any as CommonMo< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >; + return this.jax.nodeMap.get(this.node.coreMO()) as + any as CommonMo; } /** @@ -1196,7 +1143,7 @@ export class CommonWrapper< * @returns {boolean} Whether the node can stretch in that direction */ public canStretch(direction: string): boolean { - this.stretch = NOSTRETCH as DD; + this.stretch = NOSTRETCH; if (this.node.isEmbellished) { const core = this.core(); if (core && core.node !== this.node) { @@ -1393,7 +1340,9 @@ export class CommonWrapper< // the Math Alphabet mapping for this character. // Otherwise use the original code point, n. // - chars = chars.map((n) => (map[n] as CharDataArray)?.[3]?.smp || n); + chars = chars.map( + (n) => (map[n] as CharDataArray)?.[3]?.smp || n + ); } return chars; } @@ -1441,9 +1390,7 @@ export class CommonWrapper< * @param {string} text The text for the wrapped element * @returns {CommonMo} The wrapped MmlMo node */ - protected createMo( - text: string - ): CommonMo { + protected createMo(text: string): CommonMo { const mmlFactory = (this.node as AbstractMmlNode).factory; const textNode = (mmlFactory.create('text') as TextNode).setText(text); const mml = mmlFactory.create('mo', { stretchy: true }, [textNode]); @@ -1451,7 +1398,7 @@ export class CommonWrapper< mml.parent = this.node.parent; const node = this.wrap(mml); node.parent = this as any as WW; - return node as any as CommonMo; + return node as any as CommonMo; } /** @@ -1459,12 +1406,15 @@ export class CommonWrapper< * @param {number} n The number of the character to look up * @returns {CharDataArray} The full CharData object, with CharOptions guaranteed to be defined */ - protected getVariantChar(variant: string, n: number): CharDataArray { + protected getVariantChar( + variant: string, + n: number + ): CharDataArray { const char = this.font.getChar(variant, n) || [0, 0, 0, { unknown: true }]; if (char.length === 3) { (char as any)[3] = {}; } - return char as [number, number, number, CC]; + return char as [number, number, number, FONT['CC']]; } /*******************************************************************/ @@ -1478,7 +1428,11 @@ export class CommonWrapper< * @param {(N|T)[]} content The child nodes for the created HTML node * @returns {N} The generated HTML tree */ - public html(type: string, def: OptionList = {}, content: (N | T)[] = []): N { + public html( + type: string, + def: OptionList = {}, + content: NT[] = [] + ): N { return this.jax.html(type, def, content); } @@ -1486,7 +1440,7 @@ export class CommonWrapper< * @param {string} text The text from which to create an HTML text node * @returns {T} The generated text node with the given text */ - public text(text: string): T { + public text(text: string): T { return this.jax.text(text); } } diff --git a/ts/output/common/WrapperFactory.ts b/ts/output/common/WrapperFactory.ts index e62de56f25..7a289a104f 100644 --- a/ts/output/common/WrapperFactory.ts +++ b/ts/output/common/WrapperFactory.ts @@ -21,57 +21,39 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { CommonOutputJax } from '../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../common.js'; import { AbstractWrapperFactory } from '../../core/Tree/WrapperFactory.js'; import { CommonWrapper, CommonWrapperClass } from './Wrapper.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from './FontData.js'; import { MmlNode, MmlNodeClass } from '../../core/MmlTree/MmlNode.js'; +import { DOM as ANY_DOM, DOM_TYPES } from '../../types/Types.js'; /*****************************************************************/ /** * The OutputWrapperFactory class for creating OutputWrapper nodes * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export class CommonWrapperFactory< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, > extends AbstractWrapperFactory { /** * The default list of wrapper nodes this factory can create * (filled in by subclasses) */ - /* prettier-ignore */ public static defaultNodes: { - [kind: string]: CommonWrapperClass; + /* prettier-ignore */ + [kind: string]: CommonWrapperClass; } = {}; /** diff --git a/ts/output/common/Wrappers/TeXAtom.ts b/ts/output/common/Wrappers/TeXAtom.ts index e37efbd727..db17244098 100644 --- a/ts/output/common/Wrappers/TeXAtom.ts +++ b/ts/output/common/Wrappers/TeXAtom.ts @@ -27,78 +27,48 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonTeXAtom interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonTeXAtom< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper {} /** * The CommonTeXAtomClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonTeXAtomClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -106,41 +76,28 @@ export interface CommonTeXAtomClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The Mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The Mixin interface to create */ export function CommonTeXAtomMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonTeXAtomMixin extends Base - implements CommonTeXAtom + implements CommonTeXAtom { /** * @override diff --git a/ts/output/common/Wrappers/TextNode.ts b/ts/output/common/Wrappers/TextNode.ts index ba88486bb3..04d1799a4e 100644 --- a/ts/output/common/Wrappers/TextNode.ts +++ b/ts/output/common/Wrappers/TextNode.ts @@ -27,49 +27,31 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { BBox } from '../../../util/BBox.js'; import { TextNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMo } from '../../../core/MmlTree/MmlNodes/mo.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonTextNode interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonTextNode< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * @param {string} text The text to remap * @param {string} variant The variant for the character @@ -81,33 +63,21 @@ export interface CommonTextNode< /** * The CommonTextNodeClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonTextNodeClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -115,41 +85,28 @@ export interface CommonTextNodeClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonTextNodeMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonTextNodeMixin extends Base - implements CommonTextNode + implements CommonTextNode { /** * @override diff --git a/ts/output/common/Wrappers/XmlNode.ts b/ts/output/common/Wrappers/XmlNode.ts index 8b3e177188..f8b6548a37 100644 --- a/ts/output/common/Wrappers/XmlNode.ts +++ b/ts/output/common/Wrappers/XmlNode.ts @@ -28,50 +28,37 @@ import { } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax, ExtendedMetrics, UnknownBBox } from '../../common.js'; + CommonOutputJax, + ExtendedMetrics, + UnknownBBox, + COMMON_FONT, +} from '../../common.js'; import { MmlNode, XMLNode } from '../../../core/MmlTree/MmlNode.js'; import { BBox } from '../../../util/BBox.js'; import { StyleList } from '../../../util/Styles.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { split } from '../../../util/string.js'; +import { DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonXmlNode interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonXmlNode< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The relative scaling from the root to this node */ @@ -80,13 +67,13 @@ export interface CommonXmlNode< /** * @returns {N} The HTML for the node */ - getHTML(): N; + getHTML(): N; /** * @param {N} html The html to adjust if using or forcing HDW * @param {StyleList} styles The styles object to add to, as needed */ - addHDW(html: N, styles: StyleList): N; + addHDW(html: N, styles: StyleList): N; /** * @param {N} xml The XML tree to check @@ -94,7 +81,7 @@ export interface CommonXmlNode< * @param {string} force The second (optional) xmlHDW value to check * @returns {string} The data-mjx-hdw value, if the options are met */ - getHDW(xml: N, use: string, force?: string): string; + getHDW(xml: N, use: string, force?: string): string; /** * @param {string} hdw The data-mjx-hdw string to split @@ -106,33 +93,21 @@ export interface CommonXmlNode< /** * The CommonXmlNodeClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonXmlNodeClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -140,41 +115,28 @@ export interface CommonXmlNodeClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The Mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The Mixin interface to create */ export function CommonXmlNodeMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { abstract class CommonXmlNodeMixin extends Base - implements CommonXmlNode + implements CommonXmlNode { /** * Don't set up inline-block styles for this @@ -226,7 +188,7 @@ export function CommonXmlNodeMixin< * @override */ public computeBBox(bbox: BBox, _recompute: boolean = false) { - const xml = (this.node as XMLNode).getXML() as N; + const xml = (this.node as XMLNode).getXML() as N; const hdw = this.getHDW(xml, 'use', 'force'); const { h, d, w } = hdw ? this.splitHDW(hdw) : this.measureXmlNode(xml); bbox.w = w; @@ -237,9 +199,9 @@ export function CommonXmlNodeMixin< /** * @override */ - public getHTML(): N { + public getHTML(): N { const adaptor = this.adaptor; - let html = adaptor.clone((this.node as XMLNode).getXML() as N); + let html = adaptor.clone((this.node as XMLNode).getXML() as N); const styles = this.getFontStyles(); const hdw = this.getHDW(html, 'force'); if (hdw || this.jax.options.scale !== 1) { @@ -255,12 +217,12 @@ export function CommonXmlNodeMixin< /** * @override */ - abstract addHDW(html: N, _styles: StyleList): N; + abstract addHDW(html: N, _styles: StyleList): N; /** * @override */ - public getHDW(xml: N, use: string, force: string = use): string { + public getHDW(xml: N, use: string, force: string = use): string { const option = this.jax.options.htmlHDW; const hdw = this.adaptor.getAttribute(xml, 'data-mjx-hdw') as string; return hdw && (option === use || option === force) ? hdw : null; @@ -299,7 +261,7 @@ export function CommonXmlNodeMixin< * @param {N} xml The xml content node to be measured * @returns {UnknownBBox} The width, height, and depth of the content */ - public measureXmlNode(xml: N): UnknownBBox { + public measureXmlNode(xml: N): UnknownBBox { const adaptor = this.adaptor; const content = this.html( 'mjx-xml-block', diff --git a/ts/output/common/Wrappers/maction.ts b/ts/output/common/Wrappers/maction.ts index 35a50e050d..52b6771834 100644 --- a/ts/output/common/Wrappers/maction.ts +++ b/ts/output/common/Wrappers/maction.ts @@ -27,14 +27,7 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMaction } from '../../../core/MmlTree/MmlNodes/maction.js'; import { TextNode } from '../../../core/MmlTree/MmlNode.js'; @@ -42,113 +35,77 @@ import { STATE } from '../../../core/MathItem.js'; import { mathjax } from '../../../mathjax.js'; import { BBox } from '../../../util/BBox.js'; import { split } from '../../../util/string.js'; +import { DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The types needed to define the actiontypes * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The Font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type * * @template MA The Maction type */ export type ActionData = { [name: string]: any }; export type ActionHandler< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - MA extends CommonMaction, + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + MA extends CommonMaction, > = (node: MA, data?: ActionData) => void; export type ActionPair< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - MA extends CommonMaction, -> = [ - ActionHandler, - ActionData, -]; + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + MA extends CommonMaction, +> = [ActionHandler, ActionData]; export type ActionMap< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - MA extends CommonMaction, -> = Map>; + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + MA extends CommonMaction, +> = Map>; export type ActionDef< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - MA extends CommonMaction, -> = [ - string, - [ActionHandler, ActionData], -]; + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + MA extends CommonMaction, +> = [string, [ActionHandler, ActionData]]; export type EventHandler = (event: Event) => void; /** * Data used for tooltip actions */ -/* prettier-ignore */ export const TooltipData = { - dx: '.2em', // x-offset of tooltip from right side of maction bbox - dy: '.1em', // y-offset of tooltip from bottom of maction bbox + dx: '.2em', // x-offset of tooltip from right side of maction bbox + dy: '.1em', // y-offset of tooltip from bottom of maction bbox - postDelay: 600, // milliseconds before tooltip posts - clearDelay: 100, // milliseconds before tooltip is removed + postDelay: 600, // milliseconds before tooltip posts + clearDelay: 100, // milliseconds before tooltip is removed - hoverTimer: new Map(), // timers for posting tooltips - clearTimer: new Map(), // timers for removing tooltips + hoverTimer: new Map(), // timers for posting tooltips + clearTimer: new Map(), // timers for removing tooltips /* * clear the timers if any are active @@ -162,48 +119,35 @@ export const TooltipData = { clearTimeout(data.hoverTimer.get(node)); data.hoverTimer.delete(node); } - } - + }, }; /*****************************************************************/ /** * The CommonMaction interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMaction< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The handler for the specified actiontype */ /* prettier-ignore */ action: ActionHandler< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC, - CommonMaction + DOM, FONT, JX, WW, WF, WC, + CommonMaction >; /** * The data for the specified actiontype @@ -242,7 +186,7 @@ export interface CommonMaction< * @param {N=} dom The DOM node. If not provided goes over all elements of *the dom tree of this wrapper. */ - setEventHandler(type: string, handler: EventHandler, dom?: N): void; + setEventHandler(type: string, handler: EventHandler, dom?: N): void; /** * Public access to em method (for use in notation functions) @@ -262,39 +206,27 @@ export interface CommonMaction< /** * The CommonMaction class interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font node types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMactionClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass { /** * The valid action types and their handlers */ /* prettier-ignore */ - actions: ActionMap + actions: ActionMap >; } @@ -304,46 +236,32 @@ export interface CommonMactionClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMactionMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMactionMixin extends Base - implements CommonMaction + implements CommonMaction { /** * @override */ - /* prettier-ignore */ public static actions = new Map([ [ 'toggle', @@ -404,7 +322,7 @@ export function CommonMactionMixin< [ 'tooltip', - [(_node, _data) => {}, {}] // overriden in by subclasses + [(_node, _data) => {}, {}], // overriden in by subclasses ], [ @@ -446,16 +364,22 @@ export function CommonMactionMixin< }, ], ], - ]) as ActionMap + ]) as ActionMap< + DOM, + FONT, + JX, + WW, + WF, + WC, + CommonMaction >; /** * @override */ /* prettier-ignore */ - public action: ActionHandler + public action: ActionHandler >; /** @@ -507,18 +431,16 @@ export function CommonMactionMixin< */ constructor(factory: WF, node: MmlNode, parent: WW = null) { super(factory, node, parent); - const actions = - /* prettier-ignore */ - (this.constructor as - CommonMactionClass) - .actions; + const actions = ( + this.constructor as CommonMactionClass + ).actions; const action = this.node.attributes.get('actiontype') as string; const [handler, data] = /* prettier-ignore */ actions.get(action) || [ ((_node, _data) => {}) as ActionHandler< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC, - CommonMaction + DOM, FONT, JX, WW, WF, WC, + CommonMaction >, {}, ]; @@ -554,7 +476,11 @@ export function CommonMactionMixin< /** * @override */ - public setEventHandler(type: string, handler: EventHandler, dom: N = null) { + public setEventHandler( + type: string, + handler: EventHandler, + dom: N = null + ) { (dom ? [dom] : this.dom).forEach((node) => (node as any).addEventListener(type, handler) ); diff --git a/ts/output/common/Wrappers/math.ts b/ts/output/common/Wrappers/math.ts index 1ec78a3328..534417e2b4 100644 --- a/ts/output/common/Wrappers/math.ts +++ b/ts/output/common/Wrappers/math.ts @@ -27,120 +27,74 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMath interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMath< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper {} /** * The CommonMathClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMathClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** * The CommonMath wrapper mixin for the MmlMath object * - * @param {CommonWrapperConstructor} Base The constructor class to extend - * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @param {CommonWrapperConstructor} Base The constructor class to extend + * @returns {B} The mixin constructor + * + * @template DOM The DOM node types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type * - * @template B The mixin interface to create + * @template B The mixin interface to create */ export function CommonMathMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMathMixin extends Base - implements CommonMath + implements CommonMath { /** * @override diff --git a/ts/output/common/Wrappers/menclose.ts b/ts/output/common/Wrappers/menclose.ts index 7c85148cd1..791291ebcc 100644 --- a/ts/output/common/Wrappers/menclose.ts +++ b/ts/output/common/Wrappers/menclose.ts @@ -27,62 +27,44 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMsqrt } from './msqrt.js'; import * as Notation from '../Notation.js'; import { BBox } from '../../../util/BBox.js'; import { MmlNode, AbstractMmlNode } from '../../../core/MmlTree/MmlNode.js'; import { split } from '../../../util/string.js'; +import { DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMenclose interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type * * @template S The msqrt wrapper type */ export interface CommonMenclose< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - S extends CommonMsqrt, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + S extends CommonMsqrt, +> extends CommonWrapper { /** * The notations active on this menclose, if any */ - notations: Notation.List; + notations: Notation.List>; /** * The notation to use for the child, if any */ - renderChild: Notation.Renderer; + renderChild: Notation.Renderer>; /** * A fake msqrt for radial notation (if used) @@ -177,7 +159,7 @@ export interface CommonMenclose< double: boolean, offset?: string, trans?: number - ): N; + ): N; /** * Get the angle and width of a diagonal arrow, plus the x and y extension @@ -214,37 +196,25 @@ export interface CommonMenclose< /** * The CommonMenclose class interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMencloseClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass { /** * The definitions of the various notations */ - notations: Notation.DefList; + notations: Notation.DefList>; } /*****************************************************************/ @@ -253,53 +223,40 @@ export interface CommonMencloseClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template S The msqrt wrapper class - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template S The msqrt wrapper class + * @template B The mixin interface to create */ export function CommonMencloseMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - S extends CommonMsqrt, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + S extends CommonMsqrt, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMencloseMixin extends Base - implements CommonMenclose + implements CommonMenclose { /** * @override */ - public notations: Notation.List = {}; + public notations: Notation.List> = {}; /** * @override */ - public renderChild: Notation.Renderer = null; + public renderChild: Notation.Renderer> = null; /** * @override @@ -356,11 +313,8 @@ export function CommonMencloseMixin< * @override */ public getNotations() { - /* prettier-ignore */ const Notations = ( - this.constructor as CommonMencloseClass< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - > + this.constructor as CommonMencloseClass ).notations; for (const name of split( this.node.attributes.get('notation') as string @@ -468,8 +422,8 @@ export function CommonMencloseMixin< _double: boolean, _offset: string = '', _dist: number = 0 - ): N { - return null as N; + ): N { + return null as N; } /** diff --git a/ts/output/common/Wrappers/mfenced.ts b/ts/output/common/Wrappers/mfenced.ts index 0fd507f144..927dab38ca 100644 --- a/ts/output/common/Wrappers/mfenced.ts +++ b/ts/output/common/Wrappers/mfenced.ts @@ -27,54 +27,36 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonInferredMrow } from './mrow.js'; import { MmlNode, AbstractMmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMfenced } from '../../../core/MmlTree/MmlNodes/mfenced.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMfenced interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMfenced< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * An mrow to use for the layout of the mfenced */ - mrow: CommonInferredMrow; + mrow: CommonInferredMrow; /** * Creates the mrow wrapper to use for the layout @@ -99,33 +81,21 @@ export interface CommonMfenced< /** * The CommonMfencedClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMfencedClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -133,48 +103,33 @@ export interface CommonMfencedClass< * * @param {CommonWrapperConstructor} Base The constructor class * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMfencedMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMfencedMixin extends Base - implements CommonMfenced + implements CommonMfenced { /** * @override */ - /* prettier-ignore */ - public mrow: - CommonInferredMrow = null; + public mrow: CommonInferredMrow = null; /** * @override diff --git a/ts/output/common/Wrappers/mfrac.ts b/ts/output/common/Wrappers/mfrac.ts index 8e20241dc5..08eef9eefb 100644 --- a/ts/output/common/Wrappers/mfrac.ts +++ b/ts/output/common/Wrappers/mfrac.ts @@ -27,54 +27,36 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMo } from './mo.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { BBox } from '../../../util/BBox.js'; import { DIRECTION } from '../FontData.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMfrac interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMfrac< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * Wrapper for to use for bevelled fraction */ - bevel: CommonMo; + bevel: CommonMo; /** * Padding around fractions @@ -146,33 +128,21 @@ export interface CommonMfrac< /** * The CommonMfracClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMfracClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -180,46 +150,33 @@ export interface CommonMfracClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMfracMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMfracMixin extends Base - implements CommonMfrac + implements CommonMfrac { /** * @override */ - public bevel: CommonMo = null; + public bevel: CommonMo = null; /** * @override diff --git a/ts/output/common/Wrappers/mglyph.ts b/ts/output/common/Wrappers/mglyph.ts index 25a03562fe..9f044b0a01 100644 --- a/ts/output/common/Wrappers/mglyph.ts +++ b/ts/output/common/Wrappers/mglyph.ts @@ -27,49 +27,31 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonTextNode } from './TextNode.js'; import { MmlNode, TextNode } from '../../../core/MmlTree/MmlNode.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMglyph interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMglyph< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The image's width converted to em's */ @@ -86,7 +68,7 @@ export interface CommonMglyph< /** * TextNode used for deprecated fontfamily/index use case */ - charWrapper: CommonTextNode; + charWrapper: CommonTextNode; /** * Obtain the width, height, and valign. @@ -101,33 +83,21 @@ export interface CommonMglyph< /** * The CommonMglyphClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMglyphClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -135,41 +105,28 @@ export interface CommonMglyphClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMglyphMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMglyphMixin extends Base - implements CommonMglyph + implements CommonMglyph { /** * @override @@ -187,9 +144,7 @@ export function CommonMglyphMixin< /** * @override */ - /* prettier-ignore */ - public charWrapper: - CommonTextNode; + public charWrapper: CommonTextNode; /** * @override diff --git a/ts/output/common/Wrappers/mi.ts b/ts/output/common/Wrappers/mi.ts index b99a5febdb..08a60b81ce 100644 --- a/ts/output/common/Wrappers/mi.ts +++ b/ts/output/common/Wrappers/mi.ts @@ -27,78 +27,48 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMi interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMi< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper {} /** * The CommonMiClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMiClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -106,41 +76,28 @@ export interface CommonMiClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMiMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMiMixin extends Base - implements CommonMi + implements CommonMi { /** * @override diff --git a/ts/output/common/Wrappers/mmultiscripts.ts b/ts/output/common/Wrappers/mmultiscripts.ts index 1b84105d9a..8a451b3f86 100644 --- a/ts/output/common/Wrappers/mmultiscripts.ts +++ b/ts/output/common/Wrappers/mmultiscripts.ts @@ -23,30 +23,23 @@ import { CommonWrapper, CommonWrapperClass, Constructor } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMsubsup, CommonMsubsupClass } from './msubsup.js'; import { BBox } from '../../../util/BBox.js'; import { LineBBox } from '../LineBBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The data about the scripts and base */ -/* prettier-ignore */ export type ScriptData = { base: BBox; - sub: BBox; // combined bbox for all subscripts - sup: BBox; // combined bbox for all superscripts - psub: BBox; // combined bbox for all presubscripts - psup: BBox; // combined bbox for all presuperscripts + sub: BBox; // Combined bbox for all subscripts + sup: BBox; // Combined bbox for all superscripts + psub: BBox; // Combined bbox for all presubscripts + psup: BBox; // Combined bbox for all presuperscripts numPrescripts: number; numScripts: number; }; @@ -84,33 +77,21 @@ export const ScriptNames = ['sup', 'sup', 'psup', 'psub'] as ScriptDataName[]; /** * The CommonMmultiscripts interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMmultiscripts< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMsubsup { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMsubsup { /** * The cached data for the various bounding boxes */ @@ -181,33 +162,21 @@ export interface CommonMmultiscripts< /** * The CommonMmlultisciptsClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMmultiscriptsClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMsubsupClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMsubsupClass {} /*****************************************************************/ /** @@ -215,41 +184,28 @@ export interface CommonMmultiscriptsClass< * * @param {Constructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMmultiscriptsMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonMsubsupClass, ->( - Base: Constructor> -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonMsubsupClass, +>(Base: Constructor>): B { return class CommonMmultiscriptsMixin extends Base - implements CommonMmultiscripts + implements CommonMmultiscripts { /** * @override diff --git a/ts/output/common/Wrappers/mn.ts b/ts/output/common/Wrappers/mn.ts index 751edf68fd..1f487db8d3 100644 --- a/ts/output/common/Wrappers/mn.ts +++ b/ts/output/common/Wrappers/mn.ts @@ -27,77 +27,47 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMn interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMn< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper {} /** * The CommonMnClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMnClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -105,41 +75,28 @@ export interface CommonMnClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMnMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMnMixin extends Base - implements CommonMn + implements CommonMn { /** * @override diff --git a/ts/output/common/Wrappers/mo.ts b/ts/output/common/Wrappers/mo.ts index 7e48428fa4..482448c4d5 100644 --- a/ts/output/common/Wrappers/mo.ts +++ b/ts/output/common/Wrappers/mo.ts @@ -27,52 +27,35 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { DelimiterData } from '../FontData.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { MmlNode, TEXCLASS } from '../../../core/MmlTree/MmlNode.js'; import { MmlMo } from '../../../core/MmlTree/MmlNodes/mo.js'; import { BBox } from '../../../util/BBox.js'; import { LineBBox } from '../LineBBox.js'; import { unicodeChars } from '../../../util/string.js'; import { DIRECTION, NOSTRETCH } from '../FontData.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMo interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMo< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The font size that a stretched operator uses. * If -1, then stretch arbitrarily, and bbox gives the actual height, depth, width @@ -92,7 +75,7 @@ export interface CommonMo< /** * The linebreakmultchar used for breaking an invisible times */ - multChar: CommonMo; + multChar: CommonMo; /** * Value is 1 if this embellished mo is a breakpoint, 0 otherwise @@ -198,33 +181,21 @@ export interface CommonMo< /** * The CommonMoClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMoClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -232,41 +203,28 @@ export interface CommonMoClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMoMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMoMixin extends Base - implements CommonMo + implements CommonMo { /** * @override @@ -286,7 +244,7 @@ export function CommonMoMixin< /** * The linebreakmultchar used for breaking an invisible times */ - public multChar: CommonMo; + public multChar: CommonMo; /** * @override @@ -387,7 +345,7 @@ export function CommonMoMixin< const C = this.getText().codePointAt(0); let delim = this.stretch; if (this.size) { - this.stretch = delim = this.font.getDelimiter(C) as DD; + this.stretch = delim = this.font.getDelimiter(C) as FONT['DD']; this.size = null; } const c = delim.c || C; @@ -671,7 +629,7 @@ export function CommonMoMixin< const delim = this.font.getDelimiter(c.codePointAt(0)); this.stretch = ( delim && delim.dir === direction ? delim : NOSTRETCH - ) as DD; + ) as FONT['DD']; return this.stretch.dir !== DIRECTION.None; } diff --git a/ts/output/common/Wrappers/mpadded.ts b/ts/output/common/Wrappers/mpadded.ts index 807485f8ad..d82848ff69 100644 --- a/ts/output/common/Wrappers/mpadded.ts +++ b/ts/output/common/Wrappers/mpadded.ts @@ -27,48 +27,30 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { BBox } from '../../../util/BBox.js'; import { Property } from '../../../core/Tree/Node.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMpadded interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMpadded< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * Get the content bounding box, and the change in size and offsets * as specified by the parameters @@ -101,33 +83,21 @@ export interface CommonMpadded< /** * The CommonMpaddedClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMpaddedClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -135,41 +105,28 @@ export interface CommonMpaddedClass< * * @param {CommonWrapperConstructor} Base The constructor class * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMpaddedMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMpaddedMixin extends Base - implements CommonMpadded + implements CommonMpadded { get containerWidth(): number { const attributes = this.node.attributes; diff --git a/ts/output/common/Wrappers/mroot.ts b/ts/output/common/Wrappers/mroot.ts index 0c5038b37a..c9311b4c0b 100644 --- a/ts/output/common/Wrappers/mroot.ts +++ b/ts/output/common/Wrappers/mroot.ts @@ -23,79 +23,49 @@ import { CommonWrapper, CommonWrapperClass, Constructor } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMsqrt, CommonMsqrtClass } from './msqrt.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMroot interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMroot< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMsqrt {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMsqrt {} /** * The CommonMrootClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMrootClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMsqrtClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMsqrtClass {} /*****************************************************************/ /** @@ -103,41 +73,28 @@ export interface CommonMrootClass< * * @param {Constructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMrootMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonMsqrtClass, ->( - Base: Constructor> -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonMsqrtClass, +>(Base: Constructor>): B { return class CommonMrootMixin extends Base - implements CommonMroot + implements CommonMroot { /** * @override diff --git a/ts/output/common/Wrappers/mrow.ts b/ts/output/common/Wrappers/mrow.ts index c328d88349..d48ede06e0 100644 --- a/ts/output/common/Wrappers/mrow.ts +++ b/ts/output/common/Wrappers/mrow.ts @@ -27,50 +27,32 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { BBox } from '../../../util/BBox.js'; import { LineBBox } from '../LineBBox.js'; import { DIRECTION } from '../FontData.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMrow interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMrow< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * True if this mrow is not the top-level linebreak mrow */ @@ -91,33 +73,21 @@ export interface CommonMrow< /** * The CommonMrowClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMrowClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -125,41 +95,28 @@ export interface CommonMrowClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMrowMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMrowMixin extends Base - implements CommonMrow + implements CommonMrow { /** * @override @@ -456,64 +413,40 @@ export function CommonMrowMixin< /** * The CommonInferredMrow interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonInferredMrow< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMrow {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMrow {} /** * The CommonInferredMrowClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonInferredMrowClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMrowClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMrowClass {} /*****************************************************************/ /** @@ -521,45 +454,34 @@ export interface CommonInferredMrowClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonInferredMrowMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonMrowClass, + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonMrowClass, >( /* prettier-ignore */ Base: CommonWrapperConstructor< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC, - CommonMrow + DOM, FONT, JX, WW, WF, WC, + CommonMrow > ): B { return class CommonInferredMrowMixin extends Base - implements CommonInferredMrow + implements CommonInferredMrow { /** * Since inferred rows don't produce a container node, we can't diff --git a/ts/output/common/Wrappers/ms.ts b/ts/output/common/Wrappers/ms.ts index bbdc2e1c1c..e2877bc3e4 100644 --- a/ts/output/common/Wrappers/ms.ts +++ b/ts/output/common/Wrappers/ms.ts @@ -27,47 +27,29 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMs interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMs< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * Create a text wrapper with the given text; * @@ -80,33 +62,21 @@ export interface CommonMs< /** * The CommonMsClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -114,41 +84,28 @@ export interface CommonMsClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMsMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMsMixin extends Base - implements CommonMs + implements CommonMs { /** * Create a text wrapper with the given text; diff --git a/ts/output/common/Wrappers/mspace.ts b/ts/output/common/Wrappers/mspace.ts index 255c150a7e..8b2c34bfbb 100644 --- a/ts/output/common/Wrappers/mspace.ts +++ b/ts/output/common/Wrappers/mspace.ts @@ -27,50 +27,32 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMspace } from '../../../core/MmlTree/MmlNodes/mspace.js'; import { BBox } from '../../../util/BBox.js'; import { LineBBox } from '../LineBBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMspance interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMspace< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * True when mspace is allowed to break */ @@ -92,33 +74,21 @@ export interface CommonMspace< /** * The CommonMspaceClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMspaceClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -126,41 +96,28 @@ export interface CommonMspaceClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMspaceMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMspaceMixin extends Base - implements CommonMspace + implements CommonMspace { /** * @override diff --git a/ts/output/common/Wrappers/msqrt.ts b/ts/output/common/Wrappers/msqrt.ts index 1ec9bdc986..9869ed5d4b 100644 --- a/ts/output/common/Wrappers/msqrt.ts +++ b/ts/output/common/Wrappers/msqrt.ts @@ -27,50 +27,32 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMo } from './mo.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { BBox } from '../../../util/BBox.js'; import { DIRECTION } from '../FontData.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMsqrt interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsqrt< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The index of the base of the root in childNodes */ @@ -84,7 +66,7 @@ export interface CommonMsqrt< /** * The surd node */ - surd: CommonMo; + surd: CommonMo; /** * The requested height of the stretched surd character @@ -127,33 +109,21 @@ export interface CommonMsqrt< /** * The CommonMsqrtClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsqrtClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -161,41 +131,28 @@ export interface CommonMsqrtClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMsqrtMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMsqrtMixin extends Base - implements CommonMsqrt + implements CommonMsqrt { /** * @override @@ -214,7 +171,7 @@ export function CommonMsqrtMixin< /** * @override */ - public surd: CommonMo; + public surd: CommonMo; /** * @override diff --git a/ts/output/common/Wrappers/msubsup.ts b/ts/output/common/Wrappers/msubsup.ts index 1f2fc83e43..f98aa37ba5 100644 --- a/ts/output/common/Wrappers/msubsup.ts +++ b/ts/output/common/Wrappers/msubsup.ts @@ -24,14 +24,7 @@ import { CommonWrapper, CommonWrapperClass } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonScriptbase, CommonScriptbaseClass, @@ -43,111 +36,75 @@ import { MmlMsub, MmlMsup, } from '../../../core/MmlTree/MmlNodes/msubsup.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMsub interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsub< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbase {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbase {} /** * The CommonMsubClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsubClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbaseClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbaseClass {} /*****************************************************************/ /** * The CommonMsub wrapper mixin for the MmlMsub object * - * @param {CommonScriptbaseConstructor} Base The constructor class to extend - * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @param {CommonScriptbaseConstructor} Base The constructor class to extend + * @returns {B} The mixin constructor + * + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type * - * @template B The mixin interface to create + * @template B The mixin interface to create */ export function CommonMsubMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonScriptbaseClass, ->( - Base: CommonScriptbaseConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonScriptbaseClass, +>(Base: CommonScriptbaseConstructor): B { return class CommonMsubMixin extends Base - implements CommonMsub + implements CommonMsub { /** * Do not include italic correction @@ -177,106 +134,69 @@ export function CommonMsubMixin< /** * The CommonMsup interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsup< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbase {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbase {} /** * The CommonMsupClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsupClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbaseClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbaseClass {} /*****************************************************************/ /** * The CommonMsup wrapper mixin for the MmlMsup object * - * @param {CommonScriptbaseConstructor} Base The constructor class to extend - * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @param {CommonScriptbaseConstructor} Base The constructor class to extend + * @returns {B} The mixin constructor * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMsupMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonScriptbaseClass, ->( - Base: CommonScriptbaseConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonScriptbaseClass, +>(Base: CommonScriptbaseConstructor): B { return class CommonMsupMixin extends Base - implements CommonMsup + implements CommonMsup { /** * @override @@ -301,33 +221,21 @@ export function CommonMsupMixin< /** * The CommonMsubsup interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsubsup< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbase { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbase { /** * Cached values for the script offsets and separation (so if they are * computed in computeBBox(), they don't have to be recomputed during output) @@ -349,7 +257,7 @@ export interface CommonMsubsup< * * @param {BBox} subbox The bounding box of the superscript * @param {BBox} supbox The bounding box of the subscript - * @returns {number[]} The vertical offsets for super and subscripts, and the space between them + * @returns {number[]} The vertical offsets for super and subscripts, and the space between them */ getUVQ(subbox?: BBox, supbox?: BBox): number[]; } @@ -357,75 +265,50 @@ export interface CommonMsubsup< /** * The CommonMsubsupClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMsubsupClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbaseClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbaseClass {} /*****************************************************************/ /** * The CommomMsubsup wrapper for the MmlMsubsup object * - * @param {CommonScriptbaseConstructor} Base The constructor class to extend - * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @param {CommonScriptbaseConstructor} Base The constructor class to extend + * @returns {B} The mixin constructor + * + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type * - * @template B The mixin interface to create + * @template B The mixin interface to create */ export function CommonMsubsupMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonScriptbaseClass, ->( - Base: CommonScriptbaseConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonScriptbaseClass, +>(Base: CommonScriptbaseConstructor): B { return class CommonMsubsupMixin extends Base - implements CommonMsubsup + implements CommonMsubsup { /** * Do not include italic correction diff --git a/ts/output/common/Wrappers/mtable.ts b/ts/output/common/Wrappers/mtable.ts index 384fb2b463..24c7be91f1 100644 --- a/ts/output/common/Wrappers/mtable.ts +++ b/ts/output/common/Wrappers/mtable.ts @@ -27,14 +27,7 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMtr } from './mtr.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { BBox } from '../../../util/BBox.js'; @@ -42,6 +35,7 @@ import { DIRECTION } from '../FontData.js'; import { split, isPercent } from '../../../util/string.js'; import { sum, max } from '../../../util/numeric.js'; import { Styles, TRBL } from '../../../util/Styles.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** @@ -74,36 +68,24 @@ export const BREAK_BELOW = 0.333; /** * The CommonMtable interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type * - * @template R The class for table rows + * @template R The class for table rows */ export interface CommonMtable< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - R extends CommonMtr, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + R extends CommonMtr, +> extends CommonWrapper { /** * The number of columns in the table */ @@ -447,33 +429,21 @@ export interface CommonMtable< /** * The CommonMtableClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMtableClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -481,43 +451,30 @@ export interface CommonMtableClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template R The table row class - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template R The table row class + * @template B The mixin interface to create */ export function CommonMtableMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - R extends CommonMtr, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + R extends CommonMtr, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMtableMixin extends Base - implements CommonMtable + implements CommonMtable { /** * @override diff --git a/ts/output/common/Wrappers/mtd.ts b/ts/output/common/Wrappers/mtd.ts index 5bc8f244f4..74c2fb1e96 100644 --- a/ts/output/common/Wrappers/mtd.ts +++ b/ts/output/common/Wrappers/mtd.ts @@ -27,79 +27,49 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMtable } from '../../common/Wrappers/mtable.js'; import { CommonMtr } from '../../common/Wrappers/mtr.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMtd interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMtd< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper {} /** * The CommonMtdClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMtdClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -107,41 +77,28 @@ export interface CommonMtdClass< * * @param {CommonWrapperConstructor} Base The constructor class * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMtdMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMtdMixin extends Base - implements CommonMtd + implements CommonMtd { /** * @override @@ -162,14 +119,16 @@ export function CommonMtdMixin< * @override */ public getWrapWidth(_j: number) { - /* prettier-ignore */ - const table = this.parent.parent as any as - CommonMtable - >; - /* prettier-ignore */ - const row = this.parent as any as - CommonMtr; + const table = this.parent.parent as any as CommonMtable< + DOM, + FONT, + JX, + WW, + WF, + WC, + CommonMtr + >; + const row = this.parent as any as CommonMtr; const i = this.node.childPosition() - (row.labeled ? 1 : 0); return ( typeof table.cWidths[i] === 'number' diff --git a/ts/output/common/Wrappers/mtext.ts b/ts/output/common/Wrappers/mtext.ts index 174fb5e5b7..baf3c5a369 100644 --- a/ts/output/common/Wrappers/mtext.ts +++ b/ts/output/common/Wrappers/mtext.ts @@ -27,49 +27,31 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { TextNode } from '../../../core/MmlTree/MmlNode.js'; import { IndexData } from '../LinebreakVisitor.js'; import { LineBBox } from '../LineBBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMtext interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMtext< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The list of breakpoints within the text */ @@ -106,33 +88,21 @@ export interface CommonMtext< /** * The CommonMtextClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMtextClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass { /** * The font-family, weight, and style to use for the variants when mtextInheritFont * is true or mtextFont is specified. If not in this list, then the font's @@ -144,45 +114,32 @@ export interface CommonMtextClass< /*****************************************************************/ /** -b * The CommonMtext wrapper mixin for the MmlMtext object + * The CommonMtext wrapper mixin for the MmlMtext object * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMtextMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMtextMixin extends Base - implements CommonMtext + implements CommonMtext { /** * @override diff --git a/ts/output/common/Wrappers/mtr.ts b/ts/output/common/Wrappers/mtr.ts index a768bd58ea..1f08d6df1a 100644 --- a/ts/output/common/Wrappers/mtr.ts +++ b/ts/output/common/Wrappers/mtr.ts @@ -29,48 +29,30 @@ import { Constructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { BBox } from '../../../util/BBox.js'; import { DIRECTION } from '../FontData.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMtr interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMtr< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The number of mtd's in the mtr */ @@ -111,33 +93,21 @@ export interface CommonMtr< /** * The CommonMtrClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMtrClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -145,41 +115,28 @@ export interface CommonMtrClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMtrMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonMtrMixin extends Base - implements CommonMtr + implements CommonMtr { /** * @override @@ -285,64 +242,40 @@ export function CommonMtrMixin< /** * The CommonMlabeledtr interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMlabeledtr< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMtr {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMtr {} /** * The CommonMlabeledtrClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMlabeledtrClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonMtrClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonMtrClass {} /*****************************************************************/ /** @@ -350,41 +283,28 @@ export interface CommonMlabeledtrClass< * * @param {Constructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMlabeledtrMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonMtrClass, ->( - Base: Constructor> -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonMtrClass, +>(Base: Constructor>): B { return class CommonMlabeledtrMixin extends Base - implements CommonMlabeledtr + implements CommonMlabeledtr { /** * @override diff --git a/ts/output/common/Wrappers/munderover.ts b/ts/output/common/Wrappers/munderover.ts index e7ee1fa2b3..4b19ee7878 100644 --- a/ts/output/common/Wrappers/munderover.ts +++ b/ts/output/common/Wrappers/munderover.ts @@ -24,14 +24,7 @@ import { CommonWrapper, CommonWrapperClass } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonScriptbase, CommonScriptbaseClass, @@ -43,69 +36,46 @@ import { MmlMover, } from '../../../core/MmlTree/MmlNodes/munderover.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonMunder interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMunder< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbase {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbase {} /** * The CommonMunderClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMunderClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbaseClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbaseClass {} /*****************************************************************/ /** @@ -113,41 +83,28 @@ export interface CommonMunderClass< * * @param {CommonScriptbaseConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMunderMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonScriptbaseClass, ->( - Base: CommonScriptbaseConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonScriptbaseClass, +>(Base: CommonScriptbaseConstructor): B { return class CommonMunderMixin extends Base - implements CommonMunder + implements CommonMunder { /** * @override @@ -194,64 +151,40 @@ export function CommonMunderMixin< /** * The CommonMover interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMover< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbase {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbase {} /** * The CommonMoverClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMoverClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbaseClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbaseClass {} /*****************************************************************/ /** @@ -259,40 +192,28 @@ export interface CommonMoverClass< * * @param {CommonScriptbaseConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type - * @template B The mixin interface to create + * + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMoverMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonScriptbaseConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonScriptbaseConstructor): B { return class CommonMoverMixin extends Base - implements CommonMover + implements CommonMover { /** * @override @@ -342,33 +263,21 @@ export function CommonMoverMixin< /** * The CommonMunderover interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMunderover< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbase { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbase { /* * The wrapped under node */ @@ -383,33 +292,21 @@ export interface CommonMunderover< /** * The CommonMunderoverClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonMunderoverClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonScriptbaseClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonScriptbaseClass {} /*****************************************************************/ /** @@ -417,41 +314,28 @@ export interface CommonMunderoverClass< * * @param {CommonScriptbaseConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonMunderoverMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonScriptbaseConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonScriptbaseConstructor): B { return class CommonMunderoverMixin extends Base - implements CommonMunderover + implements CommonMunderover { /* * @override diff --git a/ts/output/common/Wrappers/scriptbase.ts b/ts/output/common/Wrappers/scriptbase.ts index b3318e1c67..e9752af629 100644 --- a/ts/output/common/Wrappers/scriptbase.ts +++ b/ts/output/common/Wrappers/scriptbase.ts @@ -31,14 +31,7 @@ import { Constructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { CommonMunderover } from './munderover.js'; import { CommonMo } from './mo.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; @@ -48,38 +41,27 @@ import { BBox } from '../../../util/BBox.js'; import { LineBBox } from '../LineBBox.js'; import { DIRECTION } from '../FontData.js'; import { SEM } from '../../../a11y/semantic-enrich/strings.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonScriptbase interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonScriptbase< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper { /** * The core mi or mo of the base (or the base itself if there isn't one) */ @@ -163,7 +145,7 @@ export interface CommonScriptbase< * * @param {WW} fence The potential fence * @param {string} id The fencepointer id - * @returns {WW} The original fence the scripts belong to + * @returns {WW} The original fence the scripts belong to */ getBaseFence(fence: WW, id: string): WW; @@ -184,7 +166,7 @@ export interface CommonScriptbase< /** * @returns {boolean} True if the base is an mi, mn, or mo (not a largeop) consisting of - * a single unstretched character + * a single unstretched character */ isCharBase(): boolean; @@ -195,7 +177,7 @@ export interface CommonScriptbase< /** * @param {WW} script The script node to check for being a line - * @returns {boolean} True if the script is U+2015 + * @returns {boolean} True if the script is U+2015 */ isLineAccent(script: WW): boolean; @@ -251,7 +233,7 @@ export interface CommonScriptbase< * * @param {BBox} basebox The bounding box of the base * @param {BBox} overbox The bounding box of the overscript - * @returns {number[]} The separation between their boxes, and the offset of the overscript + * @returns {number[]} The separation between their boxes, and the offset of the overscript */ getOverKU(basebox: BBox, overbox: BBox): number[]; @@ -260,21 +242,21 @@ export interface CommonScriptbase< * * @param {BBox} basebox The bounding box of the base * @param {BBox} underbox The bounding box of the underscript - * @returns {number[]} The separation between their boxes, and the offset of the underscript + * @returns {number[]} The separation between their boxes, and the offset of the underscript */ getUnderKV(basebox: BBox, underbox: BBox): number[]; /** * @param {BBox[]} boxes The bounding boxes whose offsets are to be computed * @param {number[]=} delta The initial x offsets of the boxes - * @returns {number[]} The actual offsets needed to center the boxes in the stack + * @returns {number[]} The actual offsets needed to center the boxes in the stack */ getDeltaW(boxes: BBox[], delta?: number[]): number[]; /** * @param {WW} script The child that is above or below the base * @param {boolean=} noskew Whether to ignore the skew amount - * @returns {number} The offset for under and over + * @returns {number} The offset for under and over */ getDelta(script: WW, noskew?: boolean): number; @@ -288,7 +270,7 @@ export interface CommonScriptbase< * Add the scripts into the given bounding box for msub and msup (overridden by msubsup) * * @param {BBox} bbox The bounding box to augment - * @returns {BBox} The modified bounding box + * @returns {BBox} The modified bounding box */ appendScripts(bbox: BBox): BBox; } @@ -296,33 +278,21 @@ export interface CommonScriptbase< /** * The CommonScriptbaseClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonScriptbaseClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass { /** * Set to true for munderover/munder/mover/msup (Appendix G 13) */ @@ -332,35 +302,23 @@ export interface CommonScriptbaseClass< /** * Shorthand for the CommonScriptbase constructor * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type * - * @template B The mixin interface being created + * @template B The mixin interface being created */ export type CommonScriptbaseConstructor< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> = Constructor>; + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> = Constructor>; /*****************************************************************/ /** @@ -369,41 +327,28 @@ export type CommonScriptbaseConstructor< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonScriptbaseMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonScriptbaseMixin extends Base - implements CommonScriptbase + implements CommonScriptbase { /** * Set to false for msubsup/msub (Appendix G 13) @@ -493,11 +438,8 @@ export function CommonScriptbaseMixin< node.isKind('mphantom') || node.isKind('semantics'))) || (node.isKind('munderover') && - /* prettier-ignore */ - ( - core as any as - CommonMunderover - ).isMathAccent)) + (core as any as CommonMunderover) + .isMathAccent)) ) { this.setBaseAccentsFor(core); core = core.childNodes[0]; @@ -604,9 +546,7 @@ export function CommonScriptbaseMixin< } else if (this.node.isKind('munder')) { this.isLineBelow = this.isLineAccent(this.scriptChild); } else { - /* prettier-ignore */ - const mml = this as any as CommonMunderover< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC>; + const mml = this as any as CommonMunderover; this.isLineAbove = this.isLineAccent(mml.overChild); this.isLineBelow = this.isLineAccent(mml.underChild); } @@ -651,9 +591,7 @@ export function CommonScriptbaseMixin< const largeop = !!this.baseCore.node.attributes.get('largeop'); const sized = !!( this.baseCore.node.isKind('mo') && - /* prettier-ignore */ - (this.baseCore as any as - CommonMo).size + (this.baseCore as any as CommonMo).size ); const scale = this.baseScale; return this.baseIsChar && !largeop && !sized && scale === 1 ? 0 : n; @@ -877,13 +815,8 @@ export function CommonScriptbaseMixin< this.baseRemoveIc = !this.isLineAbove && !this.isLineBelow && - (!( - /* prettier-ignore */ - (this.constructor as CommonScriptbaseClass< - N, T, D, JX, WW, WF, WC, CC, VV, DD, FD, FC - >) - .useIC - ) || + (!(this.constructor as CommonScriptbaseClass) + .useIC || this.isMathAccent); } diff --git a/ts/output/common/Wrappers/semantics.ts b/ts/output/common/Wrappers/semantics.ts index 309f9c454e..f46136b58b 100644 --- a/ts/output/common/Wrappers/semantics.ts +++ b/ts/output/common/Wrappers/semantics.ts @@ -27,78 +27,48 @@ import { CommonWrapperConstructor, } from '../Wrapper.js'; import { CommonWrapperFactory } from '../WrapperFactory.js'; -import { - CharOptions, - VariantData, - DelimiterData, - FontData, - FontDataClass, -} from '../FontData.js'; -import { CommonOutputJax } from '../../common.js'; +import { CommonOutputJax, COMMON_FONT } from '../../common.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The CommonSemantics interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonSemantics< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapper {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapper {} /** * The CommonSemanticsClass interface * - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type */ export interface CommonSemanticsClass< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, -> extends CommonWrapperClass {} + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, +> extends CommonWrapperClass {} /*****************************************************************/ /** @@ -106,41 +76,28 @@ export interface CommonSemanticsClass< * * @param {CommonWrapperConstructor} Base The constructor class to extend * @returns {B} The mixin constructor - * @template N The DOM node type - * @template T The DOM text node type - * @template D The DOM document type - * @template JX The OutputJax type - * @template WW The Wrapper type - * @template WF The WrapperFactory type - * @template WC The WrapperClass type - * @template CC The CharOptions type - * @template VV The VariantData type - * @template DD The DelimiterData type - * @template FD The FontData type - * @template FC The FontDataClass type * - * @template B The mixin interface to create + * @template DOM The DOM node types + * @template FONT The font data types + * @template JX The OutputJax type + * @template WW The Wrapper type + * @template WF The WrapperFactory type + * @template WC The WrapperClass type + * + * @template B The mixin interface to create */ export function CommonSemanticsMixin< - N, - T, - D, - JX extends CommonOutputJax, - WW extends CommonWrapper, - WF extends CommonWrapperFactory, - WC extends CommonWrapperClass, - CC extends CharOptions, - VV extends VariantData, - DD extends DelimiterData, - FD extends FontData, - FC extends FontDataClass, - B extends CommonWrapperClass, ->( - Base: CommonWrapperConstructor -): B { + DOM extends DOM_TYPES, + FONT extends COMMON_FONT, + JX extends CommonOutputJax, + WW extends CommonWrapper, + WF extends CommonWrapperFactory, + WC extends CommonWrapperClass, + B extends CommonWrapperClass, +>(Base: CommonWrapperConstructor): B { return class CommonSemanticsMixin extends Base - implements CommonSemantics + implements CommonSemantics { /** * @override diff --git a/ts/output/svg.ts b/ts/output/svg.ts index 4a045b23be..e120908e7a 100644 --- a/ts/output/svg.ts +++ b/ts/output/svg.ts @@ -40,7 +40,7 @@ import { unicodeChars } from '../util/string.js'; import * as LENGTHS from '../util/lengths.js'; import { SPACE } from './common/Wrapper.js'; import { DefaultFont } from './svg/DefaultFont.js'; -import { DOM, DOM_TYPES, N, T, D } from '../types/Types.js'; +import { DOM_TYPES, N, NT } from '../types/Types.js'; export const SVGNS = 'http://www.w3.org/2000/svg'; export const XLINKNS = 'http://www.w3.org/1999/xlink'; @@ -48,30 +48,42 @@ export const XLINKNS = 'http://www.w3.org/1999/xlink'; /*****************************************************************/ /** - * The SVG option types. + * The CHTML font types. */ -export interface SVG_OPTIONS extends COMMON_OPTIONS< - DOM, - SvgWrapper, T, D>, - SvgWrapperFactory, T, D>, - SvgWrapperClass, T, D>, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass -> { +export type SVG_FONT = { + CC: SvgCharOptions; + VV: SvgVariantData; + DD: SvgDelimiterData; + FD: SvgFontData; + FC: SvgFontDataClass; +}; + +export type OPTIONS = { blacker: number; // Stroke-width to use for SVG character paths (in thousands of an em) fontCache: 'local' | 'global' | 'none'; // The type of character cache to use localID: string; // ID to use for local font cache (for single equation processing) useXlink: boolean; // true to include xlink namespace for hrefs, false to not -} +}; + +/** + * The SVG option types. + */ +export interface SVG_OPTIONS + extends + OPTIONS, + COMMON_OPTIONS< + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass + > {} /** * The svg option defaults. */ -const options: SVG_OPTIONS = { - ...CommonOutputJax.OPTIONS, +const options: OPTIONS = { blacker: 3, fontCache: 'local', localID: null, @@ -82,32 +94,15 @@ const options: SVG_OPTIONS = { /** * Implements the SVG class (extends AbstractOutputJax) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class SVG extends CommonOutputJax< - // - // The HTMLElement, TextNode, and Document classes (for the DOM implementation in use) - // - N, - T, - D, - // - // The Wrapper type and its Factory and Class (these need to know N, T, and D) - // - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - // - // These are font-related objects that depend on the output jax; e,g. the character options - // for CHTML and SVG output differ (CHTML contains font information, while SVG has path data) - // - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass +export class SVG extends CommonOutputJax< + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { /** * The name of the output jax @@ -117,8 +112,10 @@ export class SVG extends CommonOutputJax< /** * @override */ - /* prettier-ignore */ - public static OPTIONS = options; + public static OPTIONS = { + ...CommonOutputJax.OPTIONS, + ...options, + }; /** * The default styles for SVG @@ -178,7 +175,7 @@ export class SVG extends CommonOutputJax< /** * Stores the information about the cached character glyphs */ - public fontCache: FontCache; + public fontCache: FontCache; /** * Minimum width for tables with labels, @@ -192,12 +189,12 @@ export class SVG extends CommonOutputJax< /** * The SVG stylesheet, once it is constructed */ - public svgStyles: N = null; + public svgStyles: N = null; /** * @override */ - public options: SVG_OPTIONS> & { matchFontHeight: boolean }; + public options: SVG_OPTIONS & { matchFontHeight: boolean }; /** * @override @@ -236,7 +233,7 @@ export class SVG extends CommonOutputJax< /** * @override */ - public escaped(math: MathItem, html: MathDocument) { + public escaped(math: MathItem, html: MathDocument) { this.setDocument(html); return this.html('span', {}, [this.text(math.math)]); } @@ -244,7 +241,7 @@ export class SVG extends CommonOutputJax< /** * @override */ - public styleSheet(html: MathDocument) { + public styleSheet(html: MathDocument) { if (this.svgStyles) { return this.svgStyles; // stylesheet is already added to the document } @@ -268,7 +265,7 @@ export class SVG extends CommonOutputJax< /** * @override */ - public pageElements(html: MathDocument) { + public pageElements(html: MathDocument) { if (this.options.fontCache === 'global' && !this.findCache(html)) { return this.svg( 'svg', @@ -280,7 +277,7 @@ export class SVG extends CommonOutputJax< [this.fontCache.getCache()] ); } - return null as N; + return null as N; } /** @@ -289,7 +286,7 @@ export class SVG extends CommonOutputJax< * @param {MathDocument} html The document to search * @returns {boolean} True if a font cache already exists in the page */ - protected findCache(html: MathDocument): boolean { + protected findCache(html: MathDocument): boolean { const adaptor = this.adaptor; const svgs = adaptor.tags(adaptor.body(html.document), 'svg'); for (let i = svgs.length - 1; i >= 0; i--) { @@ -308,10 +305,10 @@ export class SVG extends CommonOutputJax< } /** - * @param {SvgWrapper} wrapper The MML node wrapper whose SVG is to be produced - * @param {N} parent The HTML node to contain the SVG + * @param {SvgWrapper} wrapper The MML node wrapper whose SVG is to be produced + * @param {N} parent The HTML node to contain the SVG */ - public processMath(wrapper: SvgWrapper, parent: N) { + public processMath(wrapper: SvgWrapper, parent: N) { // // Cache the container (tooltips process into separate containers) // @@ -335,9 +332,9 @@ export class SVG extends CommonOutputJax< /** * @param {SvgWrapper} wrapper The wrapped math to process - * @returns {[N, N]} The svg and g nodes for the math + * @returns {[N, N]} The svg and g nodes for the math */ - protected createRoot(wrapper: SvgWrapper): [N, N] { + protected createRoot(wrapper: SvgWrapper): [N, N] { const { w, h, d, pwidth } = wrapper.getOuterBBox(); const [svg, g] = this.createSVG(h, d, w); if (pwidth) { @@ -370,9 +367,9 @@ export class SVG extends CommonOutputJax< * @param {number} h The height of the SVG to create * @param {number} d The depth of the SVG to create * @param {number} w The width of the SVG to create - * @returns {[N, N]} The svg element and its initial g child + * @returns {[N, N]} The svg element and its initial g child */ - protected createSVG(h: number, d: number, w: number): [N, N] { + protected createSVG(h: number, d: number, w: number): [N, N] { const px = this.math.metrics.em / 1000; const W = Math.max(w, px); // make sure we are at least one px wide (needed for e.g. \llap) const H = Math.max(h + d, px); // make sure we are at least one px tall (needed for e.g., \smash) @@ -384,7 +381,7 @@ export class SVG extends CommonOutputJax< fill: 'currentColor', 'stroke-width': 0, transform: 'scale(1,-1)', - }) as N; + }) as N; // // The svg element with its viewBox, size and alignment // @@ -409,7 +406,7 @@ export class SVG extends CommonOutputJax< }, [g] ) - ) as N; + ) as N; if (W === 0.001) { adaptor.setAttribute(svg, 'preserveAspectRatio', 'xMidYMid slice'); if (w < 0) { @@ -430,7 +427,7 @@ export class SVG extends CommonOutputJax< * @param {N} svg The main svg element for the typeet math * @param {N} g The group in which the math is typeset */ - protected typesetSvg(wrapper: SvgWrapper, svg: N, g: N) { + protected typesetSvg(wrapper: SvgWrapper, svg: N, g: N) { const adaptor = this.adaptor; // // Typeset the math and add minWidth (from mtables), or set the alignment and indentation @@ -458,7 +455,7 @@ export class SVG extends CommonOutputJax< * @param {string} align The alignment for the node * @param {number} shift The indent (positive or negative) for the node */ - protected setIndent(svg: N, align: string, shift: number) { + protected setIndent(svg: N, align: string, shift: number) { if (align === 'center' || align === 'left') { this.adaptor.setStyle(svg, 'margin-left', this.ex(shift)); } @@ -468,19 +465,25 @@ export class SVG extends CommonOutputJax< } /** - * @param {SvgWrapper} wrapper The MML node wrapper whose SVG gets inline breaks - * @param {N} svg The SVG node that is breaking - * @param {N} g The group in which the math is typeset + * @param {SvgWrapper} wrapper The MML node wrapper whose SVG gets inline breaks + * @param {N} svg The SVG node that is breaking + * @param {N} g The group in which the math is typeset */ - protected handleInlineBreaks(wrapper: SvgWrapper, svg: N, g: N) { + protected handleInlineBreaks( + wrapper: SvgWrapper, + svg: N, + g: N + ) { const n = wrapper.childNodes[0].breakCount; if (!n) return; // // Find the math element and the lines that it contains // const adaptor = this.adaptor; - const math = adaptor.firstChild(g) as N; - const lines = adaptor.childNodes(adaptor.firstChild(math) as N) as N[]; + const math = adaptor.firstChild(g) as N; + const lines = adaptor.childNodes( + adaptor.firstChild(math) as N + ) as N[]; const lineBBox = wrapper.childNodes[0].lineBBox; // // Remove content from original SVG other than , if any @@ -495,7 +498,7 @@ export class SVG extends CommonOutputJax< const [mml, mo] = wrapper.childNodes[0].getBreakNode(line); const { scale } = mml.getBBox(); const [nsvg, ng] = this.createSVG(h * scale, d * scale, w * scale); - const nmath = adaptor.append(ng, adaptor.clone(math, false)) as N; + const nmath = adaptor.append(ng, adaptor.clone(math, false)) as N; for (const child of adaptor.childNodes(lines[i])) { adaptor.append(nmath, child); } @@ -527,7 +530,7 @@ export class SVG extends CommonOutputJax< // if (adaptor.childNodes(svg).length) { adaptor.append( - adaptor.firstChild(adaptor.parent(svg)) as N, + adaptor.firstChild(adaptor.parent(svg)) as N, adaptor.firstChild(svg) ); } @@ -539,7 +542,7 @@ export class SVG extends CommonOutputJax< * @param {number} dimen The size of the break * @param {boolean} forced Whether the break is forced or not */ - protected addInlineBreak(nsvg: N, dimen: number, forced: boolean) { + protected addInlineBreak(nsvg: N, dimen: number, forced: boolean) { const adaptor = this.adaptor; const space = LENGTHS.em(dimen); if (!forced) { @@ -563,7 +566,7 @@ export class SVG extends CommonOutputJax< } /** - * @param {number} m A number to be shown in ex + * @param {number} m A number to be shown in ex * @returns {string} The number with units of ex */ public ex(m: number): string { @@ -576,23 +579,23 @@ export class SVG extends CommonOutputJax< /** * @param {string} kind The kind of node to create * @param {OptionList} properties The properties to set for the element - * @param {(N|T)[]} children The child nodes for this node - * @returns {N} The newly created node in the SVG namespace + * @param {NT[]} children The child nodes for this node + * @returns {N} The newly created node in the SVG namespace */ public svg( kind: string, properties: OptionList = {}, - children: (N | T)[] = [] - ): N { + children: NT[] = [] + ): N { return this.html(kind, properties, children, SVGNS); } /** * @param {string} text The text to be displayed * @param {string} variant The name of the variant for the text - * @returns {N} The text element containing the text + * @returns {N} The text element containing the text */ - public unknownText(text: string, variant: string): N { + public unknownText(text: string, variant: string): N { const metrics = this.math.metrics; const scale = (this.font.params.x_height / metrics.ex) * metrics.em * 1000; const svg = this.svg( @@ -625,10 +628,10 @@ export class SVG extends CommonOutputJax< * Measure the width of a text element by placing it in the page * and looking up its size (fake the height and depth, since we can't measure that) * - * @param {N} text The text element to measure - * @returns {object} The width, height and depth for the text + * @param {N} text The text element to measure + * @returns {object} The width, height and depth for the text */ - public measureTextNode(text: N): UnknownBBox { + public measureTextNode(text: N): UnknownBBox { const adaptor = this.adaptor; text = adaptor.clone(text); adaptor.removeAttribute(text, 'transform'); diff --git a/ts/output/svg/FontCache.ts b/ts/output/svg/FontCache.ts index 7e19bf108d..cc09bc7b59 100644 --- a/ts/output/svg/FontCache.ts +++ b/ts/output/svg/FontCache.ts @@ -22,17 +22,16 @@ */ import { SVG } from '../svg.js'; +import { DOM_TYPES, N } from '../../types/Types.js'; /** - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class FontCache { +export class FontCache { /** * The SVG jax that owns this cache */ - protected jax: SVG; + protected jax: SVG; /** * The cache of font character IDs to their paths @@ -42,7 +41,7 @@ export class FontCache { /** * The SVG element for storing the cache */ - protected defs: N = null; + protected defs: N = null; /** * A string to use to make per-equation cache IDs unique @@ -57,7 +56,7 @@ export class FontCache { /** * @param {SVG} jax The SVG jax owning this font cache */ - constructor(jax: SVG) { + constructor(jax: SVG) { this.jax = jax; } @@ -116,7 +115,7 @@ export class FontCache { * * @returns {N} The definitions */ - public getCache(): N { + public getCache(): N { return this.defs; } } diff --git a/ts/output/svg/Notation.ts b/ts/output/svg/Notation.ts index a1f01ccf9c..69330045a8 100644 --- a/ts/output/svg/Notation.ts +++ b/ts/output/svg/Notation.ts @@ -22,6 +22,7 @@ */ import { SvgMencloseNTD } from './Wrappers/menclose.js'; +import { DOM, DOM_TYPES, N } from '../../types/Types.js'; import * as Notation from '../common/Notation.js'; export * from '../common/Notation.js'; @@ -30,13 +31,19 @@ export * from '../common/Notation.js'; /** * Shorthand for Svgmenclose */ -export type Menclose = SvgMencloseNTD; +export type Menclose = SvgMencloseNTD; /* * Shorthands for common types */ -export type RENDERER = Notation.Renderer, N>; -export type DEFPAIR = Notation.DefPair, N>; +export type RENDERER = Notation.Renderer< + SvgMencloseNTD, + N +>; +export type DEFPAIR = Notation.DefPair< + SvgMencloseNTD, + N +>; /** * The kinds of lines that can be drawn @@ -118,10 +125,10 @@ export const lineOffset = function ( * @param {string} offset The direction to offset * @returns {RENDERER} The renderer function for the given line */ -export const RenderLine = function ( +export const RenderLine = function ( line: LineName, offset: string = '' -): RENDERER { +): RENDERER { return (node, _child) => { const L = node.line(lineData(node, line, offset)); node.adaptor.append(node.dom[0], L); @@ -132,28 +139,28 @@ export const RenderLine = function ( /** * @param {Notation.Side} side The kind of line (side, diagonal, etc.) - * @returns {DEFPAIR} The notation definition for the notation having a line on the given side + * @returns {DEFPAIR} The notation definition for the notation having a line on the given side */ -export const Border = function ( +export const Border = function ( side: Notation.Side -): DEFPAIR { - return Notation.CommonBorder, N>((node, _child) => { +): DEFPAIR { + return Notation.CommonBorder, N>((node, _child) => { node.adaptor.append(node.dom[0], node.line(lineData(node, side))); })(side); }; /** - * @param {string} name The name of the notation to define + * @param {string} name The name of the notation to define * @param {Notation.Side} side1 The first side to get a border * @param {Notation.Side} side2 The second side to get a border - * @returns {DEFPAIR} The notation definition for the notation having lines on two sides + * @returns {DEFPAIR} The notation definition for the notation having lines on two sides */ -export const Border2 = function ( +export const Border2 = function ( name: string, side1: Notation.Side, side2: Notation.Side -): DEFPAIR { - return Notation.CommonBorder2, N>((node, _child) => { +): DEFPAIR { + return Notation.CommonBorder2, N>((node, _child) => { node.adaptor.append(node.dom[0], node.line(lineData(node, side1))); node.adaptor.append(node.dom[0], node.line(lineData(node, side2))); })(name, side1, side2); @@ -165,10 +172,10 @@ export const Border2 = function ( * @param {LineName} name The name of the diagonal strike to define * @returns {DEFPAIR} The notation definition for the diagonal strike */ -export const DiagonalStrike = function ( +export const DiagonalStrike = function ( name: LineName -): DEFPAIR { - return Notation.CommonDiagonalStrike, N>( +): DEFPAIR { + return Notation.CommonDiagonalStrike, N>( (_cname: string) => (node, _child) => { node.adaptor.append(node.dom[0], node.line(lineData(node, name))); } @@ -181,10 +188,10 @@ export const DiagonalStrike = function ( * @param {string} name The name of the diagonal arrow to define * @returns {DEFPAIR} The notation definition for the diagonal arrow */ -export const DiagonalArrow = function ( +export const DiagonalArrow = function ( name: string -): DEFPAIR { - return Notation.CommonDiagonalArrow, N>( +): DEFPAIR { + return Notation.CommonDiagonalArrow, N>( (node, arrow) => { node.adaptor.append(node.dom[0], arrow); } @@ -195,8 +202,10 @@ export const DiagonalArrow = function ( * @param {string} name The name of the horizontal or vertical arrow to define * @returns {DEFPAIR} The notation definition for the arrow */ -export const Arrow = function (name: string): DEFPAIR { - return Notation.CommonArrow, N>((node, arrow) => { +export const Arrow = function ( + name: string +): DEFPAIR { + return Notation.CommonArrow, N>((node, arrow) => { node.adaptor.append(node.dom[0], arrow); })(name); }; diff --git a/ts/output/svg/Wrapper.ts b/ts/output/svg/Wrapper.ts index 800965dec2..632a71d22b 100644 --- a/ts/output/svg/Wrapper.ts +++ b/ts/output/svg/Wrapper.ts @@ -28,15 +28,10 @@ import { CommonWrapperClass, CommonWrapperConstructor, } from '../common/Wrapper.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from './FontData.js'; -import { SVG, XLINKNS } from '../svg.js'; +import { SvgFontData } from './FontData.js'; +import { SVG, SVG_FONT, XLINKNS } from '../svg.js'; import { SvgWrapperFactory } from './WrapperFactory.js'; +import { DOM_TYPES, N, NT } from '../../types/Types.js'; export { Constructor, StringMap } from '../common/Wrapper.js'; @@ -45,71 +40,43 @@ export { Constructor, StringMap } from '../common/Wrapper.js'; /** * Shorthand for makeing an SvgWrapper constructor */ -export type SvgConstructor = CommonWrapperConstructor< - // - // The HTMLElement, TextNode, and Document classes (for the DOM implementation in use) - // - N, - T, - D, - // - // The Wrapper type and its Factory and Class (these need to know N, T, and D) - // - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - // - // These are font-related objects that depend on the output jax; e,g. the character options - // for CHTML and SVG output differ (CHTML contains font information, while SVG has path data) - // - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass +export type SvgConstructor = CommonWrapperConstructor< + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass >; /*****************************************************************/ /** * The type of the SvgWrapper class (used when creating the wrapper factory for this class) */ -export interface SvgWrapperClass extends CommonWrapperClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass +export interface SvgWrapperClass< + DOM extends DOM_TYPES, +> extends CommonWrapperClass< + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /*****************************************************************/ /** * The base SvgWrapper class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class SvgWrapper extends CommonWrapper< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass +export class SvgWrapper extends CommonWrapper< + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { /** * The kind of wrapper @@ -141,9 +108,9 @@ export class SvgWrapper extends CommonWrapper< /** * Create the HTML for the wrapped node. * - * @param {N[]} parents The HTML nodes where the output is to be added + * @param {N[]} parents The HTML nodes where the output is to be added */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; this.addChildren(this.standardSvgNodes(parents)); } @@ -151,10 +118,10 @@ export class SvgWrapper extends CommonWrapper< /** * Create the HTML for an embellished mo, if this is one. * - * @param {N[]} parents The HTML nodes where the output is to be added + * @param {N[]} parents The HTML nodes where the output is to be added * @returns {boolean} True when embellished output is produced, false if not */ - public toEmbellishedSVG(parents: N[]): boolean { + public toEmbellishedSVG(parents: N[]): boolean { if ( parents.length <= 1 || !this.node.isEmbellished || @@ -172,7 +139,7 @@ export class SvgWrapper extends CommonWrapper< for (const [parent, STYLE] of [ [parents[0], 'before'], [parents[1], 'after'], - ] as [N, string][]) { + ] as [N, string][]) { if (style !== STYLE) { this.toSVG([parent]); dom.push(this.dom[0]); @@ -186,9 +153,9 @@ export class SvgWrapper extends CommonWrapper< } /** - * @param {N[]} parents The element in which to add the children + * @param {N[]} parents The element in which to add the children */ - public addChildren(parents: N[]) { + public addChildren(parents: N[]) { let x = 0; for (const child of this.childNodes) { child.toSVG(parents); @@ -206,9 +173,9 @@ export class SvgWrapper extends CommonWrapper< * Create the standard SVG element for the given wrapped node. * * @param {N[]} parents The HTML elements in which the node is to be created - * @returns {N[]} The roots of the HTML trees for the wrapped node's output + * @returns {N[]} The roots of the HTML trees for the wrapped node's output */ - protected standardSvgNodes(parents: N[]): N[] { + protected standardSvgNodes(parents: N[]): N[] { const svg = this.createSvgNodes(parents); this.handleStyles(); this.handleScale(); @@ -220,9 +187,9 @@ export class SvgWrapper extends CommonWrapper< /** * @param {N[]} parents The HTML elements in which the node is to be created - * @returns {N[]} The roots of the HTML tree for the wrapped node's output + * @returns {N[]} The roots of the HTML tree for the wrapped node's output */ - protected createSvgNodes(parents: N[]): N[] { + protected createSvgNodes(parents: N[]): N[] { this.dom = parents.map((_parent) => this.svg('g', { 'data-mml-node': this.node.kind }) ); // FIXME: add segment id @@ -237,15 +204,18 @@ export class SvgWrapper extends CommonWrapper< * Add an anchor for hrefs and insert hot boxes into the DOM containers * * @param {N[]} parents The HTML nodes in which the output is to be placed - * @returns {N[]} The roots of the HTML tree for the node's output + * @returns {N[]} The roots of the HTML tree for the node's output */ - protected handleHref(parents: N[]): N[] { + protected handleHref(parents: N[]): N[] { const href = this.node.attributes.get('href'); if (!href) return parents; let i = 0; const isEmbellished = this.node.isEmbellished && !this.node.isKind('mo'); return parents.map((parent) => { - parent = this.adaptor.append(parent, this.svg('a', { href: href })) as N; + parent = this.adaptor.append( + parent, + this.svg('a', { href: href }) + ) as N; const { h, d, w } = isEmbellished ? this.getOuterBBox() : this.getLineBBox(i); @@ -380,7 +350,7 @@ export class SvgWrapper extends CommonWrapper< [outerLB, outerRB, innerRB, innerLB], [outerLB, outerLT, innerLT, innerLB], ]; - const child = adaptor.firstChild(dom) as N; + const child = adaptor.firstChild(dom) as N; const dx = L * this.dx; for (const i of [0, 1, 2, 3]) { if (!border.width[i] || (i === 3 && !L) || (i === 1 && !R)) continue; @@ -414,8 +384,8 @@ export class SvgWrapper extends CommonWrapper< protected addBorderSolid( path: number[][], color: string, - child: N, - parent: N, + child: N, + parent: N, dx: number ) { const border = this.svg('polygon', { @@ -443,7 +413,7 @@ export class SvgWrapper extends CommonWrapper< * @param {number} t The thickness for the border line * @param {number} i The side being drawn * @param {N} parent The parent container - * @param {number} dx The offset of the node + * @param {number} dx The offset of the node */ protected addBorderBroken( path: number[][], @@ -451,7 +421,7 @@ export class SvgWrapper extends CommonWrapper< style: string, t: number, i: number, - parent: N, + parent: N, dx: number ) { const dot = style === 'dotted'; @@ -533,7 +503,7 @@ export class SvgWrapper extends CommonWrapper< * @param {number} y The y-offset for the element * @param {N} element The element to be placed */ - public place(x: number, y: number, element: N = null) { + public place(x: number, y: number, element: N = null) { if (!element) { x += this.dx * this.bbox.rscale; } @@ -558,8 +528,8 @@ export class SvgWrapper extends CommonWrapper< * a element (e.g., when mtextInheritFont is true), so add a text * element to help Safari get the right location. * - * @param {number} y The current offset of the element - * @returns {number} The new offset for the element if it has an id + * @param {number} y The current offset of the element + * @returns {number} The new offset for the element if it has an id */ protected handleId(y: number): number { if (!this.node.attributes || !this.node.attributes.get('id')) { @@ -591,43 +561,43 @@ export class SvgWrapper extends CommonWrapper< /** * Return the first child element, skipping id align boxes and href hit boxes * - * @param {N} dom The dom element - * @returns {N} The first "real" child element + * @param {N} dom The dom element + * @returns {N} The first "real" child element */ - public firstChild(dom: N = this.dom[0]): N { + public firstChild(dom: N = this.dom[0]): N { const adaptor = this.adaptor; let child = adaptor.firstChild(dom); if ( child && adaptor.kind(child) === 'text' && - adaptor.getAttribute(child as N, 'data-id-align') + adaptor.getAttribute(child as N, 'data-id-align') ) { - child = adaptor.firstChild(adaptor.next(child) as N); + child = adaptor.firstChild(adaptor.next(child) as N); } if ( child && adaptor.kind(child) === 'rect' && - adaptor.getAttribute(child as N, 'data-hitbox') + adaptor.getAttribute(child as N, 'data-hitbox') ) { child = adaptor.next(child); } - return child as N; + return child as N; } /** - * @param {number} n The character number - * @param {number} x The x-position of the character - * @param {number} y The y-position of the character - * @param {N} parent The container for the character - * @param {string} variant The variant to use for the character - * @param {boolean} buffer True to collect unknown characters into one text element + * @param {number} n The character number + * @param {number} x The x-position of the character + * @param {number} y The y-position of the character + * @param {N} parent The container for the character + * @param {string} variant The variant to use for the character + * @param {boolean} buffer True to collect unknown characters into one text element * @returns {number} The width of the character */ public placeChar( n: number, x: number, y: number, - parent: N, + parent: N, variant: string = null, buffer: boolean = false ): number { @@ -647,7 +617,7 @@ export class SvgWrapper extends CommonWrapper< this.place( x, y, - this.adaptor.append(parent, this.charNode(variant, C, path)) as N + this.adaptor.append(parent, this.charNode(variant, C, path)) as N ); return w + dx; } @@ -655,7 +625,7 @@ export class SvgWrapper extends CommonWrapper< const g = this.adaptor.append( parent, this.svg('g', { 'data-c': C }) - ) as N; + ) as N; this.place(x + dx, y, g); x = 0; for (const n of this.unicodeChars(data.c, variant)) { @@ -673,7 +643,12 @@ export class SvgWrapper extends CommonWrapper< * @param {string} variant The variant to use for the string * @returns {number} The computed width of the text */ - protected addUtext(x: number, y: number, parent: N, variant: string): number { + protected addUtext( + x: number, + y: number, + parent: N, + variant: string + ): number { const c = this.utext; if (!c) { return 0; @@ -682,7 +657,7 @@ export class SvgWrapper extends CommonWrapper< const text = this.adaptor.append( parent, this.jax.unknownText(c, variant) - ) as N; + ) as N; this.place(x, y, text); return this.jax.measureTextNodeWithCache(text, c, variant).w; } @@ -691,9 +666,9 @@ export class SvgWrapper extends CommonWrapper< * @param {string} variant The name of the variant being used * @param {string} C The hex string for the character code * @param {string} path The data from the character - * @returns {N} The or node for the glyph + * @returns {N} The or node for the glyph */ - protected charNode(variant: string, C: string, path: string): N { + protected charNode(variant: string, C: string, path: string): N { const cache = this.jax.options.fontCache; return cache !== 'none' ? this.useNode(variant, C, path) @@ -703,9 +678,9 @@ export class SvgWrapper extends CommonWrapper< /** * @param {string} C The hex string for the character code * @param {string} path The data from the character - * @returns {N} The for the glyph + * @returns {N} The for the glyph */ - protected pathNode(C: string, path: string): N { + protected pathNode(C: string, path: string): N { return this.svg('path', { 'data-c': C, d: path }); } @@ -713,9 +688,9 @@ export class SvgWrapper extends CommonWrapper< * @param {string} variant The name of the variant being used * @param {string} C The hex string for the character code * @param {string} path The data from the character - * @returns {N} The node for the glyph + * @returns {N} The node for the glyph */ - protected useNode(variant: string, C: string, path: string): N { + protected useNode(variant: string, C: string, path: string): N { const use = this.svg('use', { 'data-c': C }); const id = '#' + this.jax.fontCache.cachePath(variant, C, path); this.adaptor.setAttribute( @@ -751,7 +726,7 @@ export class SvgWrapper extends CommonWrapper< width: this.fixed(w), y: this.fixed(-d), }), - ] as N[]); + ] as N[]); const node = this.dom[0] || this.parent.dom[0]; this.adaptor.append(node, box); } @@ -764,26 +739,34 @@ export class SvgWrapper extends CommonWrapper< /** * @param {string} type The tag name of the HTML node to be created * @param {OptionList} def The properties to set for the created node - * @param {(N|T)[]} content The child nodes for the created HTML node - * @returns {N} The generated HTML tree + * @param {(NT)[]} content The child nodes for the created HTML node + * @returns {N} The generated HTML tree */ - public html(type: string, def: OptionList = {}, content: (N | T)[] = []): N { + public html( + type: string, + def: OptionList = {}, + content: NT[] = [] + ): N { return this.jax.html(type, def, content); } /** * @param {string} type The tag name of the svg node to be created * @param {OptionList} def The properties to set for the created node - * @param {(N|T)[]} content The child nodes for the created SVG node - * @returns {N} The generated SVG tree + * @param {(NT)[]} content The child nodes for the created SVG node + * @returns {N} The generated SVG tree */ - public svg(type: string, def: OptionList = {}, content: (N | T)[] = []): N { + public svg( + type: string, + def: OptionList = {}, + content: NT[] = [] + ): N { return this.jax.svg(type, def, content); } /** - * @param {number} x The dimension to display - * @param {number=} n The number of digits to display + * @param {number} x The dimension to display + * @param {number=} n The number of digits to display * @returns {string} The dimension with the given number of digits (minus trailing zeros) */ public fixed(x: number, n: number = 1): string { diff --git a/ts/output/svg/WrapperFactory.ts b/ts/output/svg/WrapperFactory.ts index 5e2f65b244..3ff0ea42ba 100644 --- a/ts/output/svg/WrapperFactory.ts +++ b/ts/output/svg/WrapperFactory.ts @@ -21,49 +21,27 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../svg.js'; +import { SVG, SVG_FONT } from '../svg.js'; import { CommonWrapperFactory } from '../common/WrapperFactory.js'; import { SvgWrapper, SvgWrapperClass } from './Wrapper.js'; import { SvgWrappers } from './Wrappers.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from './FontData.js'; +import { DOM_TYPES } from '../../types/Types.js'; /*****************************************************************/ /* * The SvgWrapperFactory class for creating SvgWrapper nodes * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class SvgWrapperFactory extends CommonWrapperFactory< - // - // The HTMLElement, TextNode, and Document classes (for the DOM implementation in use) - // - N, - T, - D, - // - // The Wrapper type and its Factory and Class (these need to know N, T, and D) - // - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - // - // These are font-related objects that depend on the output jax; e,g. the character options - // for CHTML and SVG output differ (CHTML contains font information, while SVG has path data) - // - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass +export class SvgWrapperFactory< + DOM extends DOM_TYPES, +> extends CommonWrapperFactory< + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { /** * The default list of wrapper nodes this factory can create diff --git a/ts/output/svg/Wrappers.ts b/ts/output/svg/Wrappers.ts index 71f828062d..56587fc437 100644 --- a/ts/output/svg/Wrappers.ts +++ b/ts/output/svg/Wrappers.ts @@ -57,8 +57,9 @@ import { SvgMglyph } from './Wrappers/mglyph.js'; import { SvgTeXAtom } from './Wrappers/TeXAtom.js'; import { SvgTextNode } from './Wrappers/TextNode.js'; import { SvgHtmlNode } from './Wrappers/HtmlNode.js'; +import { DOM } from '../../types/Types.js'; -export const SvgWrappers: { [kind: string]: SvgWrapperClass } = { +export const SvgWrappers: { [kind: string]: SvgWrapperClass } = { [SvgMath.kind]: SvgMath, [SvgMrow.kind]: SvgMrow, [SvgInferredMrow.kind]: SvgInferredMrow, diff --git a/ts/output/svg/Wrappers/HtmlNode.ts b/ts/output/svg/Wrappers/HtmlNode.ts index ed629b3b91..9fb085933f 100644 --- a/ts/output/svg/Wrappers/HtmlNode.ts +++ b/ts/output/svg/Wrappers/HtmlNode.ts @@ -26,30 +26,31 @@ import { SvgWrapperFactory } from '../WrapperFactory.js'; import { SvgXmlNode, SvgXmlNodeNTD, SvgXmlNodeClass } from './semantics.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { HtmlNode } from '../../../core/MmlTree/MmlNodes/HtmlNode.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgHtmlNode interface for the SVG HtmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgHtmlNodeNTD extends SvgXmlNodeNTD {} +export interface SvgHtmlNodeNTD< + DOM extends DOM_TYPES, +> extends SvgXmlNodeNTD {} /** * The SvgHtmlNodeClass interface for the SVG HtmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgHtmlNodeClass extends SvgXmlNodeClass { +export interface SvgHtmlNodeClass< + DOM extends DOM_TYPES, +> extends SvgXmlNodeClass { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgHtmlNodeNTD; + parent?: SvgWrapper + ): SvgHtmlNodeNTD; } /*****************************************************************/ @@ -57,17 +58,10 @@ export interface SvgHtmlNodeClass extends SvgXmlNodeClass { /** * The SvgHtmlNode wrapper class for the MmlHtmlNode class */ -export const SvgHtmlNode = (function (): SvgHtmlNodeClass { - return class SvgHtmlNode - // @ts-expect-error Avoid message about SvgXmlNode constructors not having - // the same type (they should both be SvgWrapper, but are thought - // of as different by typescript) - extends SvgXmlNode - implements SvgHtmlNodeNTD - { - /** - * @override - */ - public static kind = HtmlNode.prototype.kind; - }; -})(); +// @ts-expect-error Avoid message about base constructors not having the same type +export class SvgHtmlNode extends SvgXmlNode implements SvgHtmlNodeNTD { + /** + * @override + */ + public static kind = HtmlNode.prototype.kind; +} diff --git a/ts/output/svg/Wrappers/TeXAtom.ts b/ts/output/svg/Wrappers/TeXAtom.ts index 1ea01292a0..1d9856afb0 100644 --- a/ts/output/svg/Wrappers/TeXAtom.ts +++ b/ts/output/svg/Wrappers/TeXAtom.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonTeXAtom, CommonTeXAtomClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/TeXAtom.js'; import { TeXAtom } from '../../../core/MmlTree/MmlNodes/TeXAtom.js'; import { MmlNode, TEXCLASSNAMES } from '../../../core/MmlTree/MmlNode.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgTeXAtom interface for the SVG TeXAtom wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgTeXAtomNTD +export interface SvgTeXAtomNTD extends - SvgWrapper, + SvgWrapper, CommonTeXAtom< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgTeXAtomClass interface for the SVG TeXAtom wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgTeXAtomClass +export interface SvgTeXAtomClass extends - SvgWrapperClass, + SvgWrapperClass, CommonTeXAtomClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgTeXAtomNTD; + parent?: SvgWrapper + ): SvgTeXAtomNTD; } /*****************************************************************/ @@ -101,26 +79,18 @@ export interface SvgTeXAtomClass /** * The SvgTeXAtom wrapper for the MmlTeXAtom class */ -export const SvgTeXAtom = (function (): SvgTeXAtomClass { +export const SvgTeXAtom = (function (): SvgTeXAtomClass { const Base = CommonTeXAtomMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgTeXAtomClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgTeXAtomClass >(SvgWrapper); - // Avoid message about base constructors not having the same type - // (they should both be SvgWrapper, but are thought of as different by typescript) - return class SvgTeXAtom extends Base implements SvgTeXAtomNTD { + return class SvgTeXAtom extends Base implements SvgTeXAtomNTD { /** * @override */ @@ -129,7 +99,7 @@ export const SvgTeXAtom = (function (): SvgTeXAtomClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { super.toSVG(parents); this.adaptor.setAttribute( this.dom[0], @@ -137,5 +107,5 @@ export const SvgTeXAtom = (function (): SvgTeXAtomClass { TEXCLASSNAMES[this.node.texClass] ); } - } as any as SvgTeXAtomClass; -})(); + } as any as SvgTeXAtomClass; +})(); diff --git a/ts/output/svg/Wrappers/TextNode.ts b/ts/output/svg/Wrappers/TextNode.ts index 803a605cdc..68bc16c5e5 100644 --- a/ts/output/svg/Wrappers/TextNode.ts +++ b/ts/output/svg/Wrappers/TextNode.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonTextNode, CommonTextNodeClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/TextNode.js'; import { MmlNode, TextNode } from '../../../core/MmlTree/MmlNode.js'; import { StyleJsonSheet } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgTextNode interface for the SVG TextNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgTextNodeNTD +export interface SvgTextNodeNTD extends - SvgWrapper, + SvgWrapper, CommonTextNode< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgTextNodeClass interface for the SVG TextNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgTextNodeClass +export interface SvgTextNodeClass extends - SvgWrapperClass, + SvgWrapperClass, CommonTextNodeClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgTextNodeNTD; + parent?: SvgWrapper + ): SvgTextNodeNTD; } /*****************************************************************/ @@ -101,27 +79,19 @@ export interface SvgTextNodeClass /** * The SvgTextNode wrapper for the MmlTextNode class */ -export const SvgTextNode = (function (): SvgTextNodeClass { +export const SvgTextNode = (function (): SvgTextNodeClass { const Base = CommonTextNodeMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgTextNodeClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgTextNodeClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgTextNode extends Base implements SvgTextNodeNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgTextNode extends Base implements SvgTextNodeNTD { /** * @override */ @@ -130,7 +100,7 @@ export const SvgTextNode = (function (): SvgTextNodeClass { /** * @override */ - public static addStyles>( + public static addStyles>( styles: StyleJsonSheet, jax: JX ) { @@ -145,14 +115,17 @@ export const SvgTextNode = (function (): SvgTextNodeClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const adaptor = this.adaptor; const variant = this.parent.variant; const text = (this.node as TextNode).getText(); if (text.length === 0) return; if (variant === '-explicitFont') { this.dom = [ - adaptor.append(parents[0], this.jax.unknownText(text, variant)) as N, + adaptor.append( + parents[0], + this.jax.unknownText(text, variant) + ) as N, ]; } else { const chars = this.remappedText(text, variant); @@ -161,7 +134,7 @@ export const SvgTextNode = (function (): SvgTextNodeClass { adaptor.append( parents[0], this.svg('g', { 'data-mml-node': 'text' }) - ) as N, + ) as N, ]; } else { this.dom = parents; @@ -174,4 +147,4 @@ export const SvgTextNode = (function (): SvgTextNodeClass { } } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/maction.ts b/ts/output/svg/Wrappers/maction.ts index 2a616e7024..0c918a043f 100644 --- a/ts/output/svg/Wrappers/maction.ts +++ b/ts/output/svg/Wrappers/maction.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMaction, CommonMactionClass, @@ -46,94 +39,67 @@ import { } from '../../../core/MmlTree/MmlNode.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { MACTION } from '../../../a11y/semantic-enrich/maction.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMaction interface for the SVG maction wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMactionNTD +export interface SvgMactionNTD extends - SvgWrapper, + SvgWrapper, CommonMaction< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMactionClass interface for the SVG maction wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMactionClass +export interface SvgMactionClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMactionClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMactionNTD; + parent?: SvgWrapper + ): SvgMactionNTD; } /*****************************************************************/ /** * The SvgMaction wrapper for the MmlMaction class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const SvgMaction = (function (): SvgMactionClass { +export const SvgMaction = (function (): SvgMactionClass { const Base = CommonMactionMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMactionClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMactionClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMaction extends Base implements SvgMactionNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMaction extends Base implements SvgMactionNTD { /** * @override */ @@ -244,10 +210,10 @@ export const SvgMaction = (function (): SvgMactionClass { node.svg('foreignObject', { style: { display: 'none' } }, [ tool, ]) - ) as N; + ) as N; node.jax.processMath( node.jax.factory.wrap(math), - adaptor.firstChild(tool) as N + adaptor.firstChild(tool) as N ); node.childNodes[1].node.parent = node.node; // @@ -299,19 +265,13 @@ export const SvgMaction = (function (): SvgMactionClass { ], ], ] as ActionDef< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMactionNTD + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMactionNTD >[]); /*************************************************************/ @@ -319,7 +279,7 @@ export const SvgMaction = (function (): SvgMactionClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; const svg = this.standardSvgNodes(parents); const child = this.selected; @@ -346,4 +306,4 @@ export const SvgMaction = (function (): SvgMactionClass { this.action(this, this.data); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/math.ts b/ts/output/svg/Wrappers/math.ts index a0e319cf6b..45134348ad 100644 --- a/ts/output/svg/Wrappers/math.ts +++ b/ts/output/svg/Wrappers/math.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMath, CommonMathClass, @@ -41,62 +34,47 @@ import { MmlMath } from '../../../core/MmlTree/MmlNodes/math.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { BBox } from '../../../util/BBox.js'; import { ZeroFontDataUrl } from './zero.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The Svgmath interface for the SVG math wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMathNTD +export interface SvgMathNTD extends - SvgWrapper, + SvgWrapper, CommonMath< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgmathClass interface for the SVG math wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMathClass +export interface SvgMathClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMathClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMathNTD; + parent?: SvgWrapper + ): SvgMathNTD; } /*****************************************************************/ @@ -104,26 +82,18 @@ export interface SvgMathClass /** * The SvgMath wrapper for the MmlMath class */ -export const SvgMath = (function (): SvgMathClass { +export const SvgMath = (function (): SvgMathClass { const Base = CommonMathMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMathClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMathClass >(SvgWrapper); - // Avoid message about base constructors not having the same type - // (they should both be SvgWrapper, but are thought of as different by typescript) - return class SvgMath extends Base implements SvgMathNTD { + return class SvgMath extends Base implements SvgMathNTD { /** * @override */ @@ -211,7 +181,7 @@ export const SvgMath = (function (): SvgMathClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { super.toSVG(parents); const adaptor = this.adaptor; const display = this.node.attributes.get('display') === 'block'; @@ -236,4 +206,4 @@ export const SvgMath = (function (): SvgMathClass { ); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/menclose.ts b/ts/output/svg/Wrappers/menclose.ts index b7ed4e89b3..800d495545 100644 --- a/ts/output/svg/Wrappers/menclose.ts +++ b/ts/output/svg/Wrappers/menclose.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMenclose, CommonMencloseClass, @@ -41,32 +34,25 @@ import { MmlMenclose } from '../../../core/MmlTree/MmlNodes/menclose.js'; import * as Notation from '../Notation.js'; import { SvgMsqrtNTD } from './msqrt.js'; import { OptionList } from '../../../util/Options.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMenclose interface for the SVG menclose wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMencloseNTD +export interface SvgMencloseNTD extends - SvgWrapper, + SvgWrapper, CommonMenclose< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMsqrtNTD + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMsqrtNTD > { /** * Create a line element @@ -74,7 +60,7 @@ export interface SvgMencloseNTD * @param {number[]} pq The coordinates of the endpoints, [x1, y1, x2, y2] * @returns {N} The newly created line element */ - line(pq: [number, number, number, number]): N; + line(pq: [number, number, number, number]): N; /** * Create a rectangle element @@ -85,7 +71,7 @@ export interface SvgMencloseNTD * @param {number=} r The corner radius for a rounded rectangle * @returns {N} The newly created line element */ - box(w: number, h: number, d: number, r?: number): N; + box(w: number, h: number, d: number, r?: number): N; /** * Create an ellipse element @@ -95,7 +81,7 @@ export interface SvgMencloseNTD * @param {number} d The depth of the ellipse * @returns {N} The newly created ellipse node */ - ellipse(w: number, h: number, d: number): N; + ellipse(w: number, h: number, d: number): N; /** * Create a path element from the commands that specify it @@ -104,7 +90,7 @@ export interface SvgMencloseNTD * @param {(string|number)[]} P The list of commands and coordinates for the path * @returns {N} The newly created path */ - path(join: string, ...P: (string | number)[]): N; + path(join: string, ...P: (string | number)[]): N; /** * Create a filled path element from the commands the specify it @@ -113,38 +99,30 @@ export interface SvgMencloseNTD * @param {(string|number)[]} P The list of commands and coordinates for the path * @returns {N} The newly created path */ - fill(...P: (string | number)[]): N; + fill(...P: (string | number)[]): N; } /** * The SvgMencloseClass interface for the SVG menclose wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMencloseClass +export interface SvgMencloseClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMencloseClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMencloseNTD; + parent?: SvgWrapper + ): SvgMencloseNTD; } /*****************************************************************/ @@ -152,28 +130,20 @@ export interface SvgMencloseClass /** * The SvgMenclose wrapper for the MmlMenclose class */ -export const SvgMenclose = (function (): SvgMencloseClass { +export const SvgMenclose = (function (): SvgMencloseClass { const Base = CommonMencloseMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMsqrtNTD, - SvgMencloseClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMsqrtNTD, + SvgMencloseClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMenclose extends Base implements SvgMencloseNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMenclose extends Base implements SvgMencloseNTD { /** * @override */ @@ -182,7 +152,7 @@ export const SvgMenclose = (function (): SvgMencloseClass { /** * The definitions of the various notations */ - public static notations: Notation.DefList = new Map([ + public static notations: Notation.DefList> = new Map([ Notation.Border('top'), Notation.Border('right'), Notation.Border('bottom'), @@ -346,14 +316,14 @@ export const SvgMenclose = (function (): SvgMencloseClass { renderChild: true, }, ], - ] as Notation.DefPair[]); + ] as Notation.DefPair>[]); /********************************************************/ /** * @override */ - public line(pq: [number, number, number, number]): N { + public line(pq: [number, number, number, number]): N { const [x1, y1, x2, y2] = pq; return this.svg('line', { x1: this.fixed(x1), @@ -367,7 +337,7 @@ export const SvgMenclose = (function (): SvgMencloseClass { /** * @override */ - public box(w: number, h: number, d: number, r: number = 0): N { + public box(w: number, h: number, d: number, r: number = 0): N { const t = this.thickness; const def: OptionList = { x: this.fixed(t / 2), @@ -386,7 +356,7 @@ export const SvgMenclose = (function (): SvgMencloseClass { /** * @override */ - public ellipse(w: number, h: number, d: number): N { + public ellipse(w: number, h: number, d: number): N { const t = this.thickness; return this.svg('ellipse', { rx: this.fixed((w - t) / 2), @@ -401,7 +371,7 @@ export const SvgMenclose = (function (): SvgMencloseClass { /** * @override */ - public path(join: string, ...P: (string | number)[]): N { + public path(join: string, ...P: (string | number)[]): N { return this.svg('path', { d: P.map((x) => (typeof x === 'string' ? x : this.fixed(x))).join(' '), style: { 'stroke-width': this.fixed(this.thickness) }, @@ -414,7 +384,7 @@ export const SvgMenclose = (function (): SvgMencloseClass { /** * @override */ - public fill(...P: (string | number)[]): N { + public fill(...P: (string | number)[]): N { return this.svg('path', { d: P.map((x) => (typeof x === 'string' ? x : this.fixed(x))).join(' '), }); @@ -425,44 +395,97 @@ export const SvgMenclose = (function (): SvgMencloseClass { /** * @override */ - /* prettier-ignore */ - public arrow(W: number, a: number, double: boolean, offset: string = '', dist: number = 0): N { - const {w, h, d} = this.getBBox(); + public arrow( + W: number, + a: number, + double: boolean, + offset: string = '', + dist: number = 0 + ): N { + const { w, h, d } = this.getBBox(); const dw = (W - w) / 2; const m = (h - d) / 2; const t = this.thickness; const t2 = t / 2; - const [x, y, dx] = [t * this.arrowhead.x, t * this.arrowhead.y, t * this.arrowhead.dx]; - const arrow = - (double ? - this.fill( - 'M', w + dw, m, // point of arrow - 'l', -(x + dx), y, 'l', dx, t2 - y, // upper right head - 'L', x - dw, m + t2, // upper side of shaft - 'l', dx, y - t2, 'l', -(x + dx), - y, // left point - 'l', x + dx, -y, 'l', -dx, y - t2, // lower left head - 'L', w + dw - x, m - t2, // lower side of shaft - 'l', -dx, t2 - y, 'Z' // lower head - ) : - this.fill( - 'M', w + dw, m, // point of arrow - 'l', -(x + dx), y, 'l', dx, t2 - y, // upper head - 'L', -dw, m + t2, 'l', 0, -t, // upper side of shaft - 'L', w + dw - x, m - t2, // lower side of shaft - 'l', -dx, t2 - y, 'Z' // lower head - )); + const [x, y, dx] = [ + t * this.arrowhead.x, + t * this.arrowhead.y, + t * this.arrowhead.dx, + ]; + const arrow = double + ? this.fill( + 'M', + w + dw, + m, // Point of arrow + 'l', + -(x + dx), + y, + 'l', + dx, + t2 - y, // Upper right head + 'L', + x - dw, + m + t2, // Upper side of shaft + 'l', + dx, + y - t2, + 'l', + -(x + dx), + -y, // Left point + 'l', + x + dx, + -y, + 'l', + -dx, + y - t2, // Lower left head + 'L', + w + dw - x, + m - t2, // Lower side of shaft + 'l', + -dx, + t2 - y, + 'Z' // Lower head + ) + : this.fill( + 'M', + w + dw, + m, // Point of arrow + 'l', + -(x + dx), + y, + 'l', + dx, + t2 - y, // Upper head + 'L', + -dw, + m + t2, + 'l', + 0, + -t, // Upper side of shaft + 'L', + w + dw - x, + m - t2, // Lower side of shaft + 'l', + -dx, + t2 - y, + 'Z' // Lower head + ); const transform = []; if (dist) { - transform.push(offset === 'X' ? `translate(${this.fixed(-dist)} 0)` : `translate(0 ${this.fixed(dist)})`); + transform.push( + offset === 'X' + ? `translate(${this.fixed(-dist)} 0)` + : `translate(0 ${this.fixed(dist)})` + ); } if (a) { - const A = this.jax.fixed(-a * 180 / Math.PI); + const A = this.jax.fixed((-a * 180) / Math.PI); transform.push(`rotate(${A} ${this.fixed(w / 2)} ${this.fixed(m)})`); } if (transform.length) { this.adaptor.setAttribute(arrow, 'transform', transform.join(' ')); } - return arrow as N; + return arrow as N; } /********************************************************/ @@ -470,7 +493,7 @@ export const SvgMenclose = (function (): SvgMencloseClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const svg = this.standardSvgNodes(parents); // // Create a box at the correct position and add the children @@ -480,7 +503,7 @@ export const SvgMenclose = (function (): SvgMencloseClass { if (left > 0) { def.transform = 'translate(' + this.fixed(left) + ', 0)'; } - const block = this.adaptor.append(svg[0], this.svg('g', def)) as N; + const block = this.adaptor.append(svg[0], this.svg('g', def)) as N; if (this.renderChild) { this.renderChild(this, block); } else { @@ -498,4 +521,4 @@ export const SvgMenclose = (function (): SvgMencloseClass { } } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/merror.ts b/ts/output/svg/Wrappers/merror.ts index 3b023d23fe..480aa165d6 100644 --- a/ts/output/svg/Wrappers/merror.ts +++ b/ts/output/svg/Wrappers/merror.ts @@ -26,30 +26,29 @@ import { SvgWrapperFactory } from '../WrapperFactory.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMerror } from '../../../core/MmlTree/MmlNodes/merror.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMerror interface for the Svg merror wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMerrorNTD extends SvgWrapper {} +export interface SvgMerrorNTD extends SvgWrapper {} /** * The SvgMerrorClass interface for the SVG merror wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMerrorClass extends SvgWrapperClass { +export interface SvgMerrorClass< + DOM extends DOM_TYPES, +> extends SvgWrapperClass { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMerrorNTD; + parent?: SvgWrapper + ): SvgMerrorNTD; } /*****************************************************************/ @@ -57,53 +56,48 @@ export interface SvgMerrorClass extends SvgWrapperClass { /** * The SvgMerror wrapper class for the MmlMerror class */ -export const SvgMerror = (function (): SvgMerrorClass { - return class SvgMerror - extends SvgWrapper - implements SvgMerrorNTD - { - /** - * @override - */ - public static kind = MmlMerror.prototype.kind; +export class SvgMerror extends SvgWrapper implements SvgMerrorNTD { + /** + * @override + */ + public static kind = MmlMerror.prototype.kind; - /** - * @override - */ - public static styles: StyleJson = { - 'g[data-mml-node="merror"] > g': { - fill: 'red', - stroke: 'red', - }, - 'g[data-mml-node="merror"] > rect[data-background]': { - fill: 'yellow', - stroke: 'none', - }, - }; + /** + * @override + */ + public static styles: StyleJson = { + 'g[data-mml-node="merror"] > g': { + fill: 'red', + stroke: 'red', + }, + 'g[data-mml-node="merror"] > rect[data-background]': { + fill: 'yellow', + stroke: 'none', + }, + }; - /** - * @override - */ - public toSVG(parents: N[]) { - const svg = this.standardSvgNodes(parents); - const { h, d, w } = this.getBBox(); + /** + * @override + */ + public toSVG(parents: N[]) { + const svg = this.standardSvgNodes(parents); + const { h, d, w } = this.getBBox(); + this.adaptor.append( + this.dom[0], + this.svg('rect', { + 'data-background': true, + width: this.fixed(w), + height: this.fixed(h + d), + y: this.fixed(-d), + }) + ); + const title = this.node.attributes.get('title') as string; + if (title) { this.adaptor.append( this.dom[0], - this.svg('rect', { - 'data-background': true, - width: this.fixed(w), - height: this.fixed(h + d), - y: this.fixed(-d), - }) + this.svg('title', {}, [this.adaptor.text(title)]) ); - const title = this.node.attributes.get('title') as string; - if (title) { - this.adaptor.append( - this.dom[0], - this.svg('title', {}, [this.adaptor.text(title)]) - ); - } - this.addChildren(svg); } - }; -})(); + this.addChildren(svg); + } +} diff --git a/ts/output/svg/Wrappers/mfenced.ts b/ts/output/svg/Wrappers/mfenced.ts index 261395fe6d..08f525eea2 100644 --- a/ts/output/svg/Wrappers/mfenced.ts +++ b/ts/output/svg/Wrappers/mfenced.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMfenced, CommonMfencedClass, @@ -39,62 +32,47 @@ import { import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMfenced } from '../../../core/MmlTree/MmlNodes/mfenced.js'; import { SvgInferredMrowNTD } from './mrow.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMfenced interface for the SVG mfenced wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMfencedNTD +export interface SvgMfencedNTD extends - SvgWrapper, + SvgWrapper, CommonMfenced< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMfencedClass interface for the SVG mfenced wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMfencedClass +export interface SvgMfencedClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMfencedClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMfencedNTD; + parent?: SvgWrapper + ): SvgMfencedNTD; } /*****************************************************************/ @@ -102,27 +80,19 @@ export interface SvgMfencedClass /** * The SvgMfenced wrapper class for the MmlMfenced class */ -export const SvgMfenced = (function (): SvgMfencedClass { +export const SvgMfenced = (function (): SvgMfencedClass { const Base = CommonMfencedMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMfencedClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMfencedClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMfenced extends Base implements SvgMfencedNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMfenced extends Base implements SvgMfencedNTD { /** * @override */ @@ -131,12 +101,12 @@ export const SvgMfenced = (function (): SvgMfencedClass { /** * An mrow used to render the result */ - public mrow: SvgInferredMrowNTD; + public mrow: SvgInferredMrowNTD; /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const svg = this.standardSvgNodes(parents); this.setChildrenParent(this.mrow); // temporarily change parents to the mrow this.mrow.toSVG(svg); @@ -146,10 +116,10 @@ export const SvgMfenced = (function (): SvgMfencedClass { /** * @param {SvgWrapper} parent The parent to use for the fenced children */ - protected setChildrenParent(parent: SvgWrapper) { + protected setChildrenParent(parent: SvgWrapper) { for (const child of this.childNodes) { child.parent = parent; } } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mfrac.ts b/ts/output/svg/Wrappers/mfrac.ts index 1fbeef63ac..7bcafabcbd 100644 --- a/ts/output/svg/Wrappers/mfrac.ts +++ b/ts/output/svg/Wrappers/mfrac.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMfrac, CommonMfracClass, @@ -39,62 +32,47 @@ import { import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMfrac } from '../../../core/MmlTree/MmlNodes/mfrac.js'; import { SvgMoNTD } from './mo.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMfrac interface for the SVG Mfrac wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMfracNTD +export interface SvgMfracNTD extends - SvgWrapper, + SvgWrapper, CommonMfrac< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMfracClass interface for the SVG Mfrac wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMfracClass +export interface SvgMfracClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMfracClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMfracNTD; + parent?: SvgWrapper + ): SvgMfracNTD; } /*****************************************************************/ @@ -102,27 +80,19 @@ export interface SvgMfracClass /** * The SvgMfrac wrapper class for the MmlMfrac class */ -export const SvgMfrac = (function (): SvgMfracClass { +export const SvgMfrac = (function (): SvgMfracClass { const Base = CommonMfracMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMfracClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMfracClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMfrac extends Base implements SvgMfracNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMfrac extends Base implements SvgMfracNTD { /** * @override */ @@ -131,14 +101,14 @@ export const SvgMfrac = (function (): SvgMfracClass { /** * An mo element used to render bevelled fractions */ - protected bevel: SvgMoNTD; + protected bevel: SvgMoNTD; /************************************************/ /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; this.standardSvgNodes(parents); const { linethickness, bevelled } = this.node.attributes.getList( @@ -260,4 +230,4 @@ export const SvgMfrac = (function (): SvgMfracClass { ); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mglyph.ts b/ts/output/svg/Wrappers/mglyph.ts index d379568309..d71b7a0306 100644 --- a/ts/output/svg/Wrappers/mglyph.ts +++ b/ts/output/svg/Wrappers/mglyph.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMglyph, CommonMglyphClass, @@ -40,62 +33,47 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMglyph } from '../../../core/MmlTree/MmlNodes/mglyph.js'; import { SvgTextNodeNTD } from './TextNode.js'; import { OptionList } from '../../../util/Options.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMglyph interface for the SVG Mglyph wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMglyphNTD +export interface SvgMglyphNTD extends - SvgWrapper, + SvgWrapper, CommonMglyph< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMglyphClass interface for the SVG Mglyph wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMglyphClass +export interface SvgMglyphClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMglyphClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMglyphNTD; + parent?: SvgWrapper + ): SvgMglyphNTD; } /*****************************************************************/ @@ -103,27 +81,19 @@ export interface SvgMglyphClass /** * The SvgMglyph wrapper class for the MmlMglyph class */ -export const SvgMglyph = (function (): SvgMglyphClass { +export const SvgMglyph = (function (): SvgMglyphClass { const Base = CommonMglyphMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMglyphClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMglyphClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMglyph extends Base implements SvgMglyphNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMglyph extends Base implements SvgMglyphNTD { /** * @override */ @@ -132,10 +102,10 @@ export const SvgMglyph = (function (): SvgMglyphClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const svg = this.standardSvgNodes(parents); if (this.charWrapper) { - (this.charWrapper as SvgTextNodeNTD).toSVG(svg); + (this.charWrapper as SvgTextNodeNTD).toSVG(svg); return; } const { src, alt } = this.node.attributes.getList('src', 'alt'); @@ -154,4 +124,4 @@ export const SvgMglyph = (function (): SvgMglyphClass { this.adaptor.append(svg[0], img); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mi.ts b/ts/output/svg/Wrappers/mi.ts index 32522d0c08..f15b4b68f4 100644 --- a/ts/output/svg/Wrappers/mi.ts +++ b/ts/output/svg/Wrappers/mi.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMi, CommonMiClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mi.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMi } from '../../../core/MmlTree/MmlNodes/mi.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMi interface for the SVG Mi wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMiNTD +export interface SvgMiNTD extends - SvgWrapper, + SvgWrapper, CommonMi< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMiClass interface for the SVG Mi wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMiClass +export interface SvgMiClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMiClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMiNTD; + parent?: SvgWrapper + ): SvgMiNTD; } /*****************************************************************/ @@ -101,29 +79,21 @@ export interface SvgMiClass /** * The SvgMi wrapper class for the MmlMi class */ -export const SvgMi = (function (): SvgMiClass { +export const SvgMi = (function (): SvgMiClass { const Base = CommonMiMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMiClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMiClass >(SvgWrapper); - // Avoid message about base constructors not having the same type - // (they should both be SvgWrapper, but are thought of as different by typescript) - return class SvgMi extends Base implements SvgMiNTD { + return class SvgMi extends Base implements SvgMiNTD { /** * @override */ public static kind = MmlMi.prototype.kind; }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mmultiscripts.ts b/ts/output/svg/Wrappers/mmultiscripts.ts index d930e4d70c..579d815c70 100644 --- a/ts/output/svg/Wrappers/mmultiscripts.ts +++ b/ts/output/svg/Wrappers/mmultiscripts.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMmultiscripts, CommonMmultiscriptsClass, @@ -40,6 +33,7 @@ import { SvgMsubsup, SvgMsubsupNTD, SvgMsubsupClass } from './msubsup.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMmultiscripts } from '../../../core/MmlTree/MmlNodes/mmultiscripts.js'; import { split } from '../../../util/string.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ @@ -70,95 +64,63 @@ export function AlignX(align: string): AlignFunction { /** * The SvgMmultiscripts interface for the SVG Mmultiscripts wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMmultiscriptsNTD +export interface SvgMmultiscriptsNTD extends - SvgMsubsupNTD, + SvgMsubsupNTD, CommonMmultiscripts< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMmultiscriptsClass interface for the SVG Mmultiscripts wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMmultiscriptsClass +export interface SvgMmultiscriptsClass extends - SvgMsubsupClass, + SvgMsubsupClass, CommonMmultiscriptsClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMmultiscriptsNTD; + parent?: SvgWrapper + ): SvgMmultiscriptsNTD; } /*****************************************************************/ /** * The SvgMmultiscripts wrapper class for the MmlMmultiscripts class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const SvgMmultiscripts = (function (): SvgMmultiscriptsClass< - N, - T, - D -> { +export const SvgMmultiscripts = (function (): SvgMmultiscriptsClass { const Base = CommonMmultiscriptsMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMmultiscriptsClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMmultiscriptsClass >(SvgMsubsup); return class SvgMmultiscripts - // @ts-expect-error Avoid message about base constructors not having the - // same type (they should both be SvgWrapper, but are thought of as - // different by typescript) + // @ts-expect-error Avoid message about base constructors not having the same type extends Base - implements SvgMmultiscriptsNTD + implements SvgMmultiscriptsNTD { /** * @override @@ -168,7 +130,7 @@ export const SvgMmultiscripts = (function (): SvgMmultiscriptsClass< /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; const svg = this.standardSvgNodes(parents); const data = this.scriptData; @@ -224,7 +186,7 @@ export const SvgMmultiscripts = (function (): SvgMmultiscriptsClass< * @returns {number} The right-hand offset of the scripts */ protected addScripts( - svg: N, + svg: N, x: number, u: number, v: number, @@ -234,8 +196,8 @@ export const SvgMmultiscripts = (function (): SvgMmultiscriptsClass< ): number { const adaptor = this.adaptor; const alignX = AlignX(align); - const supRow = adaptor.append(svg, this.svg('g')) as N; - const subRow = adaptor.append(svg, this.svg('g')) as N; + const supRow = adaptor.append(svg, this.svg('g')) as N; + const subRow = adaptor.append(svg, this.svg('g')) as N; this.place(x, u, supRow); this.place(x, v, subRow); const m = i + 2 * n; @@ -254,4 +216,4 @@ export const SvgMmultiscripts = (function (): SvgMmultiscriptsClass< return x + dx; } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mn.ts b/ts/output/svg/Wrappers/mn.ts index 9b157f46f3..7929f6eb6b 100644 --- a/ts/output/svg/Wrappers/mn.ts +++ b/ts/output/svg/Wrappers/mn.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMn, CommonMnClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mn.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMn } from '../../../core/MmlTree/MmlNodes/mn.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMn interface for the SVG Mn wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMnNTD +export interface SvgMnNTD extends - SvgWrapper, + SvgWrapper, CommonMn< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMnClass interface for the SVG Mn wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMnClass +export interface SvgMnClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMnClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMnNTD; + parent?: SvgWrapper + ): SvgMnNTD; } /*****************************************************************/ @@ -101,29 +79,21 @@ export interface SvgMnClass /** * The SvgMn wrapper class for the MmlMn class */ -export const SvgMn = (function (): SvgMnClass { +export const SvgMn = (function (): SvgMnClass { const Base = CommonMnMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMnClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMnClass >(SvgWrapper); - // Avoid message about base constructors not having the same type - // (they should both be SvgWrapper, but are thought of as different by typescript) - return class SvgMn extends Base implements SvgMnNTD { + return class SvgMn extends Base implements SvgMnNTD { /** * @override */ public static kind = MmlMn.prototype.kind; }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mo.ts b/ts/output/svg/Wrappers/mo.ts index 16e4766388..3b40dd1ba2 100644 --- a/ts/output/svg/Wrappers/mo.ts +++ b/ts/output/svg/Wrappers/mo.ts @@ -21,18 +21,10 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - VFUZZ, - HFUZZ, -} from '../FontData.js'; +import { SvgCharOptions, VFUZZ, HFUZZ } from '../FontData.js'; import { CommonMo, CommonMoClass, @@ -42,94 +34,67 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMo } from '../../../core/MmlTree/MmlNodes/mo.js'; import { BBox } from '../../../util/BBox.js'; import { DIRECTION, SvgCharData } from '../FontData.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMo interface for the SVG Mo wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMoNTD +export interface SvgMoNTD extends - SvgWrapper, + SvgWrapper, CommonMo< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMoClass interface for the SVG Mo wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMoClass +export interface SvgMoClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMoClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMoNTD; + parent?: SvgWrapper + ): SvgMoNTD; } /*****************************************************************/ /** * The SvgMo wrapper class for the MmlMo class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const SvgMo = (function (): SvgMoClass { +export const SvgMo = (function (): SvgMoClass { const Base = CommonMoMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMoClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMoClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMo extends Base implements SvgMoNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMo extends Base implements SvgMoNTD { /** * @override */ @@ -138,7 +103,7 @@ export const SvgMo = (function (): SvgMoClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const attributes = this.node.attributes; const symmetric = (attributes.get('symmetric') as boolean) && @@ -207,7 +172,7 @@ export const SvgMo = (function (): SvgMoClass { * * @returns {string[]} The variants array */ - protected getStretchVariants() { + protected getStretchVariants(): string[] { const c = this.stretch.c || this.getText().codePointAt(0); const variants = [] as string[]; for (const i of this.stretch.stretch.keys()) { @@ -291,7 +256,7 @@ export const SvgMo = (function (): SvgMoClass { variant: string, x: number, y: number, - parent: N = null + parent: N = null ): number { if (parent) { return this.placeChar(n, x, y, parent, variant); @@ -360,7 +325,7 @@ export const SvgMo = (function (): SvgMoClass { this.addGlyph(n, v, 0, 0, svg); const glyph = adaptor.lastChild(svg); adaptor.setAttribute( - glyph as N, + glyph as N, 'transform', `scale(1,${this.jax.fixed(s)})` ); @@ -447,7 +412,7 @@ export const SvgMo = (function (): SvgMoClass { this.addGlyph(n, v, 0, 0, svg); const glyph = adaptor.lastChild(svg); adaptor.setAttribute( - glyph as N, + glyph as N, 'transform', `scale(${this.jax.fixed(s)},1)` ); @@ -484,4 +449,4 @@ export const SvgMo = (function (): SvgMoClass { return [(W - w) / 2, (W + w) / 2]; } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mpadded.ts b/ts/output/svg/Wrappers/mpadded.ts index 929091704c..ad4c9caffc 100644 --- a/ts/output/svg/Wrappers/mpadded.ts +++ b/ts/output/svg/Wrappers/mpadded.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMpadded, CommonMpaddedClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mpadded.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMpadded } from '../../../core/MmlTree/MmlNodes/mpadded.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMpadded interface for the SVG Mpadded wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMpaddedNTD +export interface SvgMpaddedNTD extends - SvgWrapper, + SvgWrapper, CommonMpadded< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMpaddedClass interface for the SVG Mpadded wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMpaddedClass +export interface SvgMpaddedClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMpaddedClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMpaddedNTD; + parent?: SvgWrapper + ): SvgMpaddedNTD; } /*****************************************************************/ @@ -101,27 +79,19 @@ export interface SvgMpaddedClass /** * The SvgMpadded wrapper class for the MmlMpadded class */ -export const SvgMpadded = (function (): SvgMpaddedClass { +export const SvgMpadded = (function (): SvgMpaddedClass { const Base = CommonMpaddedMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMpaddedClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMpaddedClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMpadded extends Base implements SvgMpaddedaNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMpadded extends Base implements SvgMpaddedaNTD { /** * @override */ @@ -130,7 +100,7 @@ export const SvgMpadded = (function (): SvgMpaddedClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; let svg = this.standardSvgNodes(parents); const [, , , , , dw, x, y, dx] = this.getDimens(); @@ -144,10 +114,10 @@ export const SvgMpadded = (function (): SvgMpaddedClass { // use relative positioning to move the contents // if (X || y) { - svg = [this.adaptor.append(svg[0], this.svg('g')) as N]; + svg = [this.adaptor.append(svg[0], this.svg('g')) as N]; this.place(X, y, svg[0]); } this.addChildren(svg); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mphantom.ts b/ts/output/svg/Wrappers/mphantom.ts index 8b1d1c3f30..3997dfce52 100644 --- a/ts/output/svg/Wrappers/mphantom.ts +++ b/ts/output/svg/Wrappers/mphantom.ts @@ -25,30 +25,31 @@ import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMphantom } from '../../../core/MmlTree/MmlNodes/mphantom.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMphantom interface for the SVG Mphantom wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMphantomNTD extends SvgWrapper {} +export interface SvgMphantomNTD< + DOM extends DOM_TYPES, +> extends SvgWrapper {} /** * The SvgMphantomClass interface for the SVG Mphantom wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMphantomClass extends SvgWrapperClass { +export interface SvgMphantomClass< + DOM extends DOM_TYPES, +> extends SvgWrapperClass { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMphantomNTD; + parent?: SvgWrapper + ): SvgMphantomNTD; } /*****************************************************************/ @@ -56,21 +57,19 @@ export interface SvgMphantomClass extends SvgWrapperClass { /** * The SvgMphantom wrapper class for the MmlMphantom class */ -export const SvgMphantom = (function (): SvgMphantomClass { - return class SvgMphantom - extends SvgWrapper - implements SvgMphantomNTD - { - /** - * @override - */ - public static kind = MmlMphantom.prototype.kind; +export class SvgMphantom + extends SvgWrapper + implements SvgMphantomNTD +{ + /** + * @override + */ + public static kind = MmlMphantom.prototype.kind; - /** - * @override - */ - public toSVG(parents: N[]) { - this.standardSvgNodes(parents); - } - }; -})(); + /** + * @override + */ + public toSVG(parents: N[]) { + this.standardSvgNodes(parents); + } +} diff --git a/ts/output/svg/Wrappers/mroot.ts b/ts/output/svg/Wrappers/mroot.ts index ff7028b113..82eb360bd7 100644 --- a/ts/output/svg/Wrappers/mroot.ts +++ b/ts/output/svg/Wrappers/mroot.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMroot, CommonMrootClass, @@ -40,62 +33,47 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMroot } from '../../../core/MmlTree/MmlNodes/mroot.js'; import { SvgMsqrt, SvgMsqrtClass, SvgMsqrtNTD } from './msqrt.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMroot interface for the SVG Mroot wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMrootNTD +export interface SvgMrootNTD extends - SvgMsqrtNTD, + SvgMsqrtNTD, CommonMroot< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMrootClass interface for the SVG Mroot wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMrootClass +export interface SvgMrootClass extends - SvgMsqrtClass, + SvgMsqrtClass, CommonMrootClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMrootNTD; + parent?: SvgWrapper + ): SvgMrootNTD; } /*****************************************************************/ @@ -103,27 +81,19 @@ export interface SvgMrootClass /** * The SvgMroot wrapper class for the MmlMroot class */ -export const SvgMroot = (function (): SvgMrootClass { +export const SvgMroot = (function (): SvgMrootClass { const Base = CommonMrootMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMrootClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMrootClass >(SvgMsqrt); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMroot extends Base implements SvgMrootNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMroot extends Base implements SvgMrootNTD { /** * @override */ @@ -133,8 +103,8 @@ export const SvgMroot = (function (): SvgMrootClass { * @override */ protected addRoot( - ROOT: N[], - root: SvgWrapper, + ROOT: N[], + root: SvgWrapper, sbox: BBox, H: number ) { @@ -145,4 +115,4 @@ export const SvgMroot = (function (): SvgMrootClass { return x; } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mrow.ts b/ts/output/svg/Wrappers/mrow.ts index 33e6ee3e41..c6290b0e43 100644 --- a/ts/output/svg/Wrappers/mrow.ts +++ b/ts/output/svg/Wrappers/mrow.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMrow, CommonMrowClass, @@ -44,94 +37,67 @@ import { MmlInferredMrow, } from '../../../core/MmlTree/MmlNodes/mrow.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMrow interface for the SVG Mrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMrowNTD +export interface SvgMrowNTD extends - SvgWrapper, + SvgWrapper, CommonMrow< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMrowClass interface for the SVG Mrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMrowClass +export interface SvgMrowClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMrowClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMrowNTD; + parent?: SvgWrapper + ): SvgMrowNTD; } /*****************************************************************/ /** * The SvgMrow wrapper for the MmlMrow type - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const SvgMrow = (function (): SvgMrowClass { +export const SvgMrow = (function (): SvgMrowClass { const Base = CommonMrowMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMrowClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMrowClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMrow extends Base implements SvgMrowNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMrow extends Base implements SvgMrowNTD { /** * @override */ @@ -146,7 +112,7 @@ export const SvgMrow = (function (): SvgMrowClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { this.getBBox(); const n = (this.linebreakCount = this.isStack ? 0 : this.breakCount); parents = @@ -163,12 +129,12 @@ export const SvgMrow = (function (): SvgMrowClass { * @param {N[]} parents The HTML nodes in which to place the lines * @returns {N[]} The augmented nodes array */ - protected getSvgNodes(parents: N[]) { + protected getSvgNodes(parents: N[]): N[] { if (this.dh) { const g = this.svg('g', { transform: `translate(0 ${this.fixed(this.dh)})`, }); - parents = [this.adaptor.append(parents[0], g) as N]; + parents = [this.adaptor.append(parents[0], g) as N]; } this.dom = parents; return parents; @@ -177,7 +143,7 @@ export const SvgMrow = (function (): SvgMrowClass { /** * @param {N[]} parents The HTML nodes in which to place the lines */ - protected placeLines(parents: N[]) { + protected placeLines(parents: N[]) { const lines = this.lineBBox; const display = this.jax.math.display; let y = this.dh; @@ -194,7 +160,7 @@ export const SvgMrow = (function (): SvgMrowClass { /** * @override */ - protected createSvgNodes(parents: N[]): N[] { + protected createSvgNodes(parents: N[]): N[] { const n = this.linebreakCount; if (!n) return super.createSvgNodes(parents); // @@ -204,22 +170,22 @@ export const SvgMrow = (function (): SvgMrowClass { const def = this.node.isInferred ? { 'data-mjx-linestack': true } : { 'data-mml-node': this.node.kind }; - this.dom = [adaptor.append(parents[0], this.svg('g', def)) as N]; + this.dom = [adaptor.append(parents[0], this.svg('g', def)) as N]; // // Add an href anchor, if needed, and insert the linestack/mrow // this.dom = [ - adaptor.append(this.handleHref(parents)[0], this.dom[0]) as N, + adaptor.append(this.handleHref(parents)[0], this.dom[0]) as N, ]; // // Add the line boxes // - const svg = Array(n) as N[]; + const svg = Array(n) as N[]; for (let i = 0; i <= n; i++) { svg[i] = adaptor.append( this.dom[0], this.svg('g', { 'data-mjx-linebox': true, 'data-mjx-lineno': i }) - ) as N; + ) as N; } // // Return the line boxes as the parent nodes for their contents @@ -230,7 +196,7 @@ export const SvgMrow = (function (): SvgMrowClass { /** * @override */ - public addChildren(parents: N[]) { + public addChildren(parents: N[]) { let x = 0; let i = 0; const isEmbellished = this.node.isEmbellished; @@ -260,7 +226,7 @@ export const SvgMrow = (function (): SvgMrowClass { } } }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -268,57 +234,41 @@ export const SvgMrow = (function (): SvgMrowClass { /** * The SvgInferredMrow interface for the SVG InferredMrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgInferredMrowNTD +export interface SvgInferredMrowNTD extends - SvgMrowNTD, + SvgMrowNTD, CommonInferredMrow< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgInferredMrowClass interface for the SVG InferredMrow wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgInferredMrowClass +export interface SvgInferredMrowClass extends - SvgMrowClass, + SvgMrowClass, CommonInferredMrowClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapper, + factory: SvgWrapper, node: MmlNode, - parent?: SvgWrapper - ): SvgInferredMrowNTD; + parent?: SvgWrapper + ): SvgInferredMrowNTD; } /*****************************************************************/ @@ -326,38 +276,22 @@ export interface SvgInferredMrowClass /** * The SvgInferredMrow wrapper for the MmlInferredMrow class */ -export const SvgInferredMrow = (function (): SvgInferredMrowClass< - N, - T, - D -> { +export const SvgInferredMrow = (function (): SvgInferredMrowClass { const Base = CommonInferredMrowMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgInferredMrowClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgInferredMrowClass >(SvgMrow); - return class SvgInferredMrowNTD - // @ts-expect-error Avoid message about base constructors not having the - // same type (they should both be SvgWrapper, but are thought of as - // different by typescript) - extends Base - // @ts-expect-error Avoid messages of use of typeof - implements SvgInferredMrow - { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgInferredMrowNTD extends Base implements SvgInferredMrow { /** * The inferred-mrow wrapper */ public static kind = MmlInferredMrow.prototype.kind; }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/ms.ts b/ts/output/svg/Wrappers/ms.ts index 5691791a7b..74b065b591 100644 --- a/ts/output/svg/Wrappers/ms.ts +++ b/ts/output/svg/Wrappers/ms.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMs, CommonMsClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/ms.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMs } from '../../../core/MmlTree/MmlNodes/ms.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMs interface for the SVG Ms wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM nodes */ -export interface SvgMsNTD +export interface SvgMsNTD extends - SvgWrapper, + SvgWrapper, CommonMs< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMsClass interface for the SVG Ms wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM nodes */ -export interface SvgMsClass +export interface SvgMsClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMsClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMsNTD; + parent?: SvgWrapper + ): SvgMsNTD; } /*****************************************************************/ @@ -101,30 +79,22 @@ export interface SvgMsClass /** * The SvgMs wrapper class for the MmlMs class */ -export const SvgMs = (function (): SvgMsClass { +export const SvgMs = (function (): SvgMsClass { const Base = CommonMsMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMsClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMsClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMs extends Base implements SvgMsNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMs extends Base implements SvgMsNTD { /** * @override */ public static kind = MmlMs.prototype.kind; }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mspace.ts b/ts/output/svg/Wrappers/mspace.ts index f282b9bcfc..0d21cdd667 100644 --- a/ts/output/svg/Wrappers/mspace.ts +++ b/ts/output/svg/Wrappers/mspace.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMspace, CommonMspaceClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mspace.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMspace } from '../../../core/MmlTree/MmlNodes/mspace.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMspace interface for the SVG Mspace wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMspaceNTD +export interface SvgMspaceNTD extends - SvgWrapper, + SvgWrapper, CommonMspace< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMspaceClass interface for the SVG Mspace wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMspaceClass +export interface SvgMspaceClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMspaceClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMspaceNTD; + parent?: SvgWrapper + ): SvgMspaceNTD; } /*****************************************************************/ @@ -101,30 +79,22 @@ export interface SvgMspaceClass /** * The SvgMspace wrapper class for the MmlMspace class */ -export const SvgMspace = (function (): SvgMspaceClass { +export const SvgMspace = (function (): SvgMspaceClass { const Base = CommonMspaceMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMspaceClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMspaceClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMspace extends Base implements SvgMspaceNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMspace extends Base implements SvgMspaceNTD { /** * @override */ public static kind = MmlMspace.prototype.kind; }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/msqrt.ts b/ts/output/svg/Wrappers/msqrt.ts index c9280914bb..d5aa84729e 100644 --- a/ts/output/svg/Wrappers/msqrt.ts +++ b/ts/output/svg/Wrappers/msqrt.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMsqrt, CommonMsqrtClass, @@ -40,31 +33,24 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMsqrt } from '../../../core/MmlTree/MmlNodes/msqrt.js'; import { SvgMoNTD } from './mo.js'; import { BBox } from '../../../util/BBox.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMsqrt interface for the SVG Msqrt wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsqrtNTD +export interface SvgMsqrtNTD extends - SvgWrapper, + SvgWrapper, CommonMsqrt< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { /** * Indent due to root @@ -75,64 +61,44 @@ export interface SvgMsqrtNTD /** * The SvgMsqrtClass interface for the SVG Msqrt wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsqrtClass +export interface SvgMsqrtClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMsqrtClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMsqrtNTD; + parent?: SvgWrapper + ): SvgMsqrtNTD; } /*****************************************************************/ /** * The SvgMsqrt wrapper for the MmlMsqrt class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const SvgMsqrt = (function (): SvgMsqrtClass { +export const SvgMsqrt = (function (): SvgMsqrtClass { const Base = CommonMsqrtMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMsqrtClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMsqrtClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMsqrt extends Base implements SvgMsqrtNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMsqrt extends Base implements SvgMsqrtNTD { /** * @override */ @@ -153,8 +119,8 @@ export const SvgMsqrt = (function (): SvgMsqrtClass { * @returns {number} The offset required by the root */ protected addRoot( - _ROOT: N[], - _root: SvgWrapper, + _ROOT: N[], + _root: SvgWrapper, _sbox: BBox, _H: number ): number { @@ -166,8 +132,8 @@ export const SvgMsqrt = (function (): SvgMsqrtClass { /** * @override */ - public toSVG(parents: N[]) { - const surd = this.surd as SvgMoNTD; + public toSVG(parents: N[]) { + const surd = this.surd as SvgMoNTD; const base = this.childNodes[this.base]; const root = this.root ? this.childNodes[this.root] : null; // @@ -184,7 +150,7 @@ export const SvgMsqrt = (function (): SvgMsqrtClass { const SVG = this.standardSvgNodes(parents); surd.toSVG(SVG); const dx = this.addRoot(SVG, root, sbox, H); - const BASE = this.adaptor.append(SVG[0], this.svg('g')) as N; + const BASE = this.adaptor.append(SVG[0], this.svg('g')) as N; base.toSVG([BASE]); // // Place the children @@ -202,4 +168,4 @@ export const SvgMsqrt = (function (): SvgMsqrtClass { ); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/msubsup.ts b/ts/output/svg/Wrappers/msubsup.ts index 230f54ef3a..0a07798fb2 100644 --- a/ts/output/svg/Wrappers/msubsup.ts +++ b/ts/output/svg/Wrappers/msubsup.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMsub, CommonMsubClass, @@ -54,62 +47,47 @@ import { MmlMsub, MmlMsup, } from '../../../core/MmlTree/MmlNodes/msubsup.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMsub interface for the SVG Msub wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsubNTD +export interface SvgMsubNTD extends - SvgScriptbaseNTD, + SvgScriptbaseNTD, CommonMsub< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMsubClass interface for the SVG Msub wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsubClass +export interface SvgMsubClass extends - SvgScriptbaseClass, + SvgScriptbaseClass, CommonMsubClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMsubNTD; + parent?: SvgWrapper + ): SvgMsubNTD; } /*****************************************************************/ @@ -117,89 +95,65 @@ export interface SvgMsubClass /** * The SvgMsub wrapper class for the MmlMsub class */ -export const SvgMsub = (function (): SvgMsubClass { +export const SvgMsub = (function (): SvgMsubClass { const Base = CommonMsubMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMsubClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMsubClass >(SvgScriptbase); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMsub extends Base implements SvgMsubNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMsub extends Base implements SvgMsubNTD { /** * @override */ public static kind = MmlMsub.prototype.kind; }; -})(); +})(); /*****************************************************************/ /** * The SvgMsup interface for the SVG Msup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsupNTD +export interface SvgMsupNTD extends - SvgScriptbaseNTD, + SvgScriptbaseNTD, CommonMsup< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMsupClass interface for the SVG Msup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsupClass +export interface SvgMsupClass extends - SvgScriptbaseClass, + SvgScriptbaseClass, CommonMsupClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMsupNTD; + parent?: SvgWrapper + ): SvgMsupNTD; } /*****************************************************************/ @@ -207,89 +161,65 @@ export interface SvgMsupClass /** * The SvgMsup wrapper class for the MmlMsup class */ -export const SvgMsup = (function (): SvgMsupClass { +export const SvgMsup = (function (): SvgMsupClass { const Base = CommonMsupMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMsupClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMsupClass >(SvgScriptbase); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMsup extends Base implements SvgMsupNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMsup extends Base implements SvgMsupNTD { /** * @override */ public static kind = MmlMsup.prototype.kind; }; -})(); +})(); /*****************************************************************/ /** * The SvgMglyph interface for the SVG Msubsup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsubsupNTD +export interface SvgMsubsupNTD extends - SvgScriptbaseNTD, + SvgScriptbaseNTD, CommonMsubsup< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMsubsupClass interface for the SVG Msubsup wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMsubsupClass +export interface SvgMsubsupClass extends - SvgScriptbaseClass, + SvgScriptbaseClass, CommonMsubsupClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMsubsupNTD; + parent?: SvgWrapper + ): SvgMsubsupNTD; } /*****************************************************************/ @@ -297,27 +227,19 @@ export interface SvgMsubsupClass /** * The SvgMsubsup wrapper class for the MmlMsubsup class */ -export const SvgMsubsup = (function (): SvgMsubsupClass { +export const SvgMsubsup = (function (): SvgMsubsupClass { const Base = CommonMsubsupMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMsubsupClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMsubsupClass >(SvgScriptbase); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMsubsup extends Base implements SvgMsubsupNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMsubsup extends Base implements SvgMsubsupNTD { /** * @override */ @@ -326,7 +248,7 @@ export const SvgMsubsup = (function (): SvgMsubsupClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; const svg = this.standardSvgNodes(parents); const [base, sup, sub] = [this.baseChild, this.supChild, this.subChild]; @@ -344,4 +266,4 @@ export const SvgMsubsup = (function (): SvgMsubsupClass { sup.place(w + x, u); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mtable.ts b/ts/output/svg/Wrappers/mtable.ts index cc32ed917e..44043ae992 100644 --- a/ts/output/svg/Wrappers/mtable.ts +++ b/ts/output/svg/Wrappers/mtable.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMtable, CommonMtableClass, @@ -42,6 +35,7 @@ import { SvgMtrNTD } from './mtr.js'; import { SvgMtdNTD } from './mtd.js'; import { OptionList } from '../../../util/Options.js'; import { StyleJson } from '../../../util/StyleJson.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; const CLASSPREFIX = 'mjx-'; @@ -49,96 +43,68 @@ const CLASSPREFIX = 'mjx-'; /** * The SvgMtable interface for the SVG Mtable wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMtableNTD +export interface SvgMtableNTD extends - SvgWrapper, + SvgWrapper, CommonMtable< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMtrNTD + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMtrNTD > { /** * The column for labels */ - labels: N; + labels: N; } /** * The SvgMtableClass interface for the SVG Mtable wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMtableClass +export interface SvgMtableClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMtableClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMtableNTD; + parent?: SvgWrapper + ): SvgMtableNTD; } /*****************************************************************/ /** * The SvgMtable wrapper class for the MmlMtable class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const SvgMtable = (function (): SvgMtableClass { +export const SvgMtable = (function (): SvgMtableClass { const Base = CommonMtableMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMtrNTD, - SvgMtableClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMtrNTD, + SvgMtableClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMtable extends Base implements SvgMtableNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMtable extends Base implements SvgMtableNTD { /** * @override */ @@ -175,14 +141,14 @@ export const SvgMtable = (function (): SvgMtableClass { /** * @override */ - public labels: N; + public labels: N; /******************************************************************/ /** * @param {N} svg The container in which to place the rows */ - protected placeRows(svg: N) { + protected placeRows(svg: N) { const equal = this.node.attributes.get('equalrows') as boolean; const { H, D } = this.getTableData(); const HD = this.getEqualRowHeight(); @@ -190,7 +156,7 @@ export const SvgMtable = (function (): SvgMtableClass { const rLines = [this.fLine, ...this.rLines, this.fLine]; let y = this.getBBox().h - rLines[0]; for (let i = 0; i < this.numRows; i++) { - const row = this.childNodes[i] as SvgMtrNTD; + const row = this.childNodes[i] as SvgMtrNTD; [row.H, row.D] = this.getRowHD(equal, HD, H[i], D[i]); [row.tSpace, row.bSpace] = [rSpace[i], rSpace[i + 1]]; [row.tLine, row.bLine] = [rLines[i], rLines[i + 1]]; @@ -234,7 +200,7 @@ export const SvgMtable = (function (): SvgMtableClass { * * @param {N} svg The container for the table */ - protected handleColumnLines(svg: N) { + protected handleColumnLines(svg: N) { if (this.node.attributes.get('columnlines') === 'none') return; const lines = this.getColumnAttributes('columnlines'); if (!lines) return; @@ -256,7 +222,7 @@ export const SvgMtable = (function (): SvgMtableClass { * * @param {N} svg The container for the table */ - protected handleRowLines(svg: N) { + protected handleRowLines(svg: N) { if (this.node.attributes.get('rowlines') === 'none') return; const lines = this.getRowAttributes('rowlines'); if (!lines) return; @@ -281,7 +247,7 @@ export const SvgMtable = (function (): SvgMtableClass { * * @param {N} svg The container for the table */ - protected handleFrame(svg: N) { + protected handleFrame(svg: N) { if (this.frame && this.fLine) { const { h, d, w } = this.getBBox(); const style = this.node.attributes.get('frame') as string; @@ -293,7 +259,7 @@ export const SvgMtable = (function (): SvgMtableClass { * @param {N} svg The svg element * @returns {number} The x-adjustement needed to handle the true size of percentage-width tables */ - protected handlePWidth(svg: N): number { + protected handlePWidth(svg: N): number { if (!this.pWidth) { return 0; } @@ -332,7 +298,12 @@ export const SvgMtable = (function (): SvgMtableClass { * @param {string} style The border style for the frame * @returns {N} The SVG element for the frame */ - protected makeFrame(w: number, h: number, d: number, style: string): N { + protected makeFrame( + w: number, + h: number, + d: number, + style: string + ): N { const t = this.fLine; return this.svg( 'rect', @@ -353,7 +324,7 @@ export const SvgMtable = (function (): SvgMtableClass { * @param {number} t The line thickness * @returns {N} The SVG element for the line */ - protected makeVLine(x: number, style: string, t: number): N { + protected makeVLine(x: number, style: string, t: number): N { const { h, d } = this.getBBox(); const dt = style === 'dotted' ? t / 2 : 0; const X = this.fixed(x + t / 2); @@ -376,7 +347,7 @@ export const SvgMtable = (function (): SvgMtableClass { * @param {number} t The line thickness * @returns {N} The SVG element for the line */ - protected makeHLine(y: number, style: string, t: number): N { + protected makeHLine(y: number, style: string, t: number): N { const w = this.getBBox().w; const dt = style === 'dotted' ? t / 2 : 0; const Y = this.fixed(y - t / 2); @@ -423,7 +394,7 @@ export const SvgMtable = (function (): SvgMtableClass { * @param {N} _parent The parent containing the the table * @param {number} dx The adjustement for percentage width tables */ - protected handleLabels(svg: N, _parent: N, dx: number) { + protected handleLabels(svg: N, _parent: N, dx: number) { if (!this.hasLabels) return; const labels = this.labels; const attributes = this.node.attributes; @@ -457,11 +428,11 @@ export const SvgMtable = (function (): SvgMtableClass { // and line thickness for each non-labeled row. // let y = h - this.fLine; - let current = adaptor.firstChild(this.labels) as N; + let current = adaptor.firstChild(this.labels) as N; for (let i = 0; i < this.numRows; i++) { - const row = this.childNodes[i] as SvgMtrNTD; + const row = this.childNodes[i] as SvgMtrNTD; if (row.node.isKind('mlabeledtr')) { - const cell = row.childNodes[0] as SvgMtdNTD; + const cell = row.childNodes[0] as SvgMtdNTD; y -= space[i] + row.H; row.placeCell(cell, { x: 0, @@ -473,7 +444,7 @@ export const SvgMtable = (function (): SvgMtableClass { rLine: 0, }); y -= row.D + space[i + 1] + this.rLines[i]; - current = adaptor.next(current) as N; + current = adaptor.next(current) as N; } else { y -= space[i] + row.H + row.D + space[i + 1] + this.rLines[i]; } @@ -487,7 +458,7 @@ export const SvgMtable = (function (): SvgMtableClass { * @param {N} labels The group of labels * @param {string} side The side alignment (left or right) */ - protected topTable(svg: N, labels: N, side: string) { + protected topTable(svg: N, labels: N, side: string) { const adaptor = this.adaptor; const { h, d, w, L, R } = this.getBBox(); const W = L + (this.pWidth || w) + R; @@ -539,7 +510,7 @@ export const SvgMtable = (function (): SvgMtableClass { * @param {string} side The side alignment (left or right) * @param {number} dx The adjustement for percentage width tables */ - protected subTable(svg: N, labels: N, side: string, dx: number) { + protected subTable(svg: N, labels: N, side: string, dx: number) { const adaptor = this.adaptor; const { w, L, R } = this.getBBox(); const W = L + (this.pWidth || w) + R; @@ -570,9 +541,9 @@ export const SvgMtable = (function (): SvgMtableClass { * @override */ constructor( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent: SvgWrapper = null + parent: SvgWrapper = null ) { super(factory, node, parent); const def: OptionList = { 'data-labels': true }; @@ -585,7 +556,7 @@ export const SvgMtable = (function (): SvgMtableClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const svg = this.standardSvgNodes(parents)[0]; this.placeRows(svg); this.handleColumnLines(svg); @@ -595,4 +566,4 @@ export const SvgMtable = (function (): SvgMtableClass { this.handleLabels(svg, parents[0], dx); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mtd.ts b/ts/output/svg/Wrappers/mtd.ts index 1471ba6ca1..7ca672ffca 100644 --- a/ts/output/svg/Wrappers/mtd.ts +++ b/ts/output/svg/Wrappers/mtd.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMtd, CommonMtdClass, @@ -38,31 +31,24 @@ import { } from '../../common/Wrappers/mtd.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMtd } from '../../../core/MmlTree/MmlNodes/mtd.js'; +import { DOM, DOM_TYPES } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMtd interface for the SVG Mtd wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMtdNTD +export interface SvgMtdNTD extends - SvgWrapper, + SvgWrapper, CommonMtd< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { /** * @param {number} x The x offset of the left side of the cell @@ -92,32 +78,24 @@ export interface SvgMtdNTD /** * The SvgMtdClass interface for the SVG Mtd wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMtdClass +export interface SvgMtdClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMtdClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMtdNTD; + parent?: SvgWrapper + ): SvgMtdNTD; } /*****************************************************************/ @@ -125,27 +103,19 @@ export interface SvgMtdClass /** * The SvgMtd wrapper class for the MmlMtd class */ -export const SvgMtd = (function (): SvgMtdClass { +export const SvgMtd = (function (): SvgMtdClass { const Base = CommonMtdMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMtdClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMtdClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMtd extends Base implements SvgMtdNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMtd extends Base implements SvgMtdNTD { /** * @override */ @@ -190,4 +160,4 @@ export const SvgMtd = (function (): SvgMtdClass { } } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mtext.ts b/ts/output/svg/Wrappers/mtext.ts index b140c54d27..4ae049eb64 100644 --- a/ts/output/svg/Wrappers/mtext.ts +++ b/ts/output/svg/Wrappers/mtext.ts @@ -21,16 +21,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMtext, CommonMtextClass, @@ -38,62 +31,47 @@ import { } from '../../common/Wrappers/mtext.js'; import { MmlNode, TextNode } from '../../../core/MmlTree/MmlNode.js'; import { MmlMtext } from '../../../core/MmlTree/MmlNodes/mtext.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMtext interface for the SVG Mtext wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM types */ -export interface SvgMtextNTD +export interface SvgMtextNTD extends - SvgWrapper, + SvgWrapper, CommonMtext< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMtextClass interface for the SVG Mtext wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM types */ -export interface SvgMtextClass +export interface SvgMtextClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMtextClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMtextNTD; + parent?: SvgWrapper + ): SvgMtextNTD; } /*****************************************************************/ @@ -101,27 +79,19 @@ export interface SvgMtextClass /** * The SvgMtext wrapper class for the MmlMtext class */ -export const SvgMtext = (function (): SvgMtextClass { +export const SvgMtext = (function (): SvgMtextClass { const Base = CommonMtextMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMtextClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMtextClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMtext extends Base implements SvgMtextNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMtext extends Base implements SvgMtextNTD { /** * @override */ @@ -130,7 +100,7 @@ export const SvgMtext = (function (): SvgMtextClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { // // If no breakpoints, do the usual thing // @@ -190,4 +160,4 @@ export const SvgMtext = (function (): SvgMtextClass { } } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/mtr.ts b/ts/output/svg/Wrappers/mtr.ts index 889c35e922..1d44d85764 100644 --- a/ts/output/svg/Wrappers/mtr.ts +++ b/ts/output/svg/Wrappers/mtr.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonMtr, CommonMtrClass, @@ -44,6 +37,7 @@ import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; import { SvgMtdNTD } from './mtd.js'; import { SvgMtableNTD } from './mtable.js'; import { MmlMtr, MmlMlabeledtr } from '../../../core/MmlTree/MmlNodes/mtr.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /** * The data needed for placeCell() @@ -62,26 +56,18 @@ export type SizeData = { /** * The SvgMtr interface for the SVG Mtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMtrNTD +export interface SvgMtrNTD extends - SvgWrapper, + SvgWrapper, CommonMtr< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { /** * The height of the row @@ -113,70 +99,50 @@ export interface SvgMtrNTD * @param {SizeData} sizes The positioning information * @returns {number} The new x position */ - placeCell(cell: SvgMtdNTD, sizes: SizeData): number; + placeCell(cell: SvgMtdNTD, sizes: SizeData): number; } /** * The SvgMtrClass interface for the SVG Mtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMtrClass +export interface SvgMtrClass extends - SvgWrapperClass, + SvgWrapperClass, CommonMtrClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMtrNTD; + parent?: SvgWrapper + ): SvgMtrNTD; } /*****************************************************************/ /** * The SvgMtr wrapper class for the MmlMtr class - * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class */ -export const SvgMtr = (function (): SvgMtrClass { +export const SvgMtr = (function (): SvgMtrClass { const Base = CommonMtrMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMtrClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMtrClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMtr extends Base implements SvgMtrNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMtr extends Base implements SvgMtrNTD { /** * @override */ @@ -210,7 +176,7 @@ export const SvgMtr = (function (): SvgMtrClass { /** * @override */ - public placeCell(cell: SvgMtdNTD, sizes: SizeData): number { + public placeCell(cell: SvgMtdNTD, sizes: SizeData): number { const { x, y, lSpace, w, rSpace, lLine, rLine } = sizes; const scale = 1 / this.getBBox().rscale; const [h, d] = [this.H * scale, this.D * scale]; @@ -231,15 +197,15 @@ export const SvgMtr = (function (): SvgMtrClass { * * @param {N[]} svg The containers for the table */ - protected placeCells(svg: N[]) { - const parent = this.parent as SvgMtableNTD; + protected placeCells(svg: N[]) { + const parent = this.parent as SvgMtableNTD; const cSpace = parent.getColumnHalfSpacing(); const cLines = [parent.fLine, ...parent.cLines, parent.fLine]; const cWidth = parent.getComputedWidths(); const scale = 1 / this.getBBox().rscale; let x = cLines[0]; for (let i = 0; i < this.numCells; i++) { - const child = this.getChild(i) as SvgMtdNTD; + const child = this.getChild(i) as SvgMtdNTD; child.toSVG(svg); x += this.placeCell(child, { x: x, @@ -272,7 +238,7 @@ export const SvgMtr = (function (): SvgMtrClass { adaptor.setAttribute( child, 'width', - this.fixed((this.parent as SvgMtableNTD).getWidth() * scale) + this.fixed((this.parent as SvgMtableNTD).getWidth() * scale) ); adaptor.setAttribute( child, @@ -287,69 +253,53 @@ export const SvgMtr = (function (): SvgMtrClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const svg = this.standardSvgNodes(parents); this.placeCells(svg); this.placeColor(); } }; -})(); +})(); /*****************************************************************/ /** * The SvgMlabeledtr interface for the SVG Mlabeledtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMlabeledtrNTD +export interface SvgMlabeledtrNTD extends - SvgMtrNTD, + SvgMtrNTD, CommonMlabeledtr< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMlabeledtrClass interface for the SVG Mlabeledtr wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgMlabeledtrClass +export interface SvgMlabeledtrClass extends - SvgMtrClass, + SvgMtrClass, CommonMlabeledtrClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMlabeledtrNTD; + parent?: SvgWrapper + ): SvgMlabeledtrNTD; } /*****************************************************************/ @@ -357,31 +307,19 @@ export interface SvgMlabeledtrClass /** * The SvgMlabeledtr wrapper class for the MmlMlabeledtr class */ -export const SvgMlabeledtr = (function (): SvgMlabeledtrClass< - N, - T, - D -> { +export const SvgMlabeledtr = (function (): SvgMlabeledtrClass { const Base = CommonMlabeledtrMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMlabeledtrClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMlabeledtrClass >(SvgMtr); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMlabeledtr extends Base implements SvgMlabeledtrNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMlabeledtr extends Base implements SvgMlabeledtrNTD { /** * @override */ @@ -390,12 +328,12 @@ export const SvgMlabeledtr = (function (): SvgMlabeledtrClass< /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { super.toSVG(parents); const child = this.childNodes[0]; if (child) { - child.toSVG([(this.parent as SvgMtableNTD).labels]); + child.toSVG([(this.parent as SvgMtableNTD).labels]); } } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/munderover.ts b/ts/output/svg/Wrappers/munderover.ts index c6cae1aefd..ff2c6882f8 100644 --- a/ts/output/svg/Wrappers/munderover.ts +++ b/ts/output/svg/Wrappers/munderover.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { SvgMsub, SvgMsubClass, @@ -60,62 +53,47 @@ import { MmlMunder, MmlMover, } from '../../../core/MmlTree/MmlNodes/munderover.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgMunder interface for the SVG Munder wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgMunderNTD +export interface SvgMunderNTD extends - SvgMsubNTD, + SvgMsubNTD, CommonMunder< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMunderClass interface for the SVG Munder wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgMunderClass +export interface SvgMunderClass extends - SvgMsubClass, + SvgMsubClass, CommonMunderClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMunderNTD; + parent?: SvgWrapper + ): SvgMunderNTD; } /*****************************************************************/ @@ -123,27 +101,19 @@ export interface SvgMunderClass /** * The SvgMunder wrapper class for the MmlMunder class */ -export const SvgMunder = (function (): SvgMunderClass { +export const SvgMunder = (function (): SvgMunderClass { const Base = CommonMunderMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMunderClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMunderClass >(SvgMsub); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMunder extends Base implements SvgMunderNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMunder extends Base implements SvgMunderNTD { /** * @override */ @@ -152,7 +122,7 @@ export const SvgMunder = (function (): SvgMunderClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; if (this.hasMovableLimits()) { super.toSVG(parents); @@ -176,7 +146,7 @@ export const SvgMunder = (function (): SvgMunderClass { script.place(sx, v); } }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -184,57 +154,41 @@ export const SvgMunder = (function (): SvgMunderClass { /** * The SvgMover interface for the SVG Mover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgMoverNTD +export interface SvgMoverNTD extends - SvgMsupNTD, + SvgMsupNTD, CommonMover< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMoverClass interface for the SVG Mover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgMoverClass +export interface SvgMoverClass extends - SvgMsupClass, + SvgMsupClass, CommonMoverClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMoverNTD; + parent?: SvgWrapper + ): SvgMoverNTD; } /*****************************************************************/ @@ -242,27 +196,19 @@ export interface SvgMoverClass /** * The SvgMover wrapper class for the MmlMover class */ -export const SvgMover = (function (): SvgMoverClass { +export const SvgMover = (function (): SvgMoverClass { const Base = CommonMoverMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMoverClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMoverClass >(SvgMsup); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMover extends Base implements SvgMoverNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMover extends Base implements SvgMoverNTD { /** * @override */ @@ -271,7 +217,7 @@ export const SvgMover = (function (): SvgMoverClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; if (this.hasMovableLimits()) { super.toSVG(parents); @@ -292,7 +238,7 @@ export const SvgMover = (function (): SvgMoverClass { script.place(sx, u); } }; -})(); +})(); /*****************************************************************/ /*****************************************************************/ @@ -300,57 +246,41 @@ export const SvgMover = (function (): SvgMoverClass { /** * The SvgMunderover interface for the SVG Munderover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgMunderoverNTD +export interface SvgMunderoverNTD extends - SvgMsubsupNTD, + SvgMsubsupNTD, CommonMunderover< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgMunderoverClass interface for the SVG Munderover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM Node types */ -export interface SvgMunderoverClass +export interface SvgMunderoverClass extends - SvgMsubsupClass, + SvgMsubsupClass, CommonMunderoverClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgMunderoverNTD; + parent?: SvgWrapper + ): SvgMunderoverNTD; } /*****************************************************************/ @@ -358,31 +288,19 @@ export interface SvgMunderoverClass /** * The SvgMunderover wrapper class for the MmlMunderover class */ -export const SvgMunderover = (function (): SvgMunderoverClass< - N, - T, - D -> { +export const SvgMunderover = (function (): SvgMunderoverClass { const Base = CommonMunderoverMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgMunderoverClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgMunderoverClass >(SvgMsubsup); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgMunderover extends Base implements SvgMunderoverNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgMunderover extends Base implements SvgMunderoverNTD { /** * @override */ @@ -391,7 +309,7 @@ export const SvgMunderover = (function (): SvgMunderoverClass< /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; if (this.hasMovableLimits()) { super.toSVG(parents); @@ -427,4 +345,4 @@ export const SvgMunderover = (function (): SvgMunderoverClass< over.place(ox, u); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/scriptbase.ts b/ts/output/svg/Wrappers/scriptbase.ts index 581078f522..4845581cbb 100644 --- a/ts/output/svg/Wrappers/scriptbase.ts +++ b/ts/output/svg/Wrappers/scriptbase.ts @@ -24,78 +24,56 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonScriptbase, CommonScriptbaseClass, CommonScriptbaseMixin, } from '../../common/Wrappers/scriptbase.js'; import { MmlNode } from '../../../core/MmlTree/MmlNode.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgScriptbase interface for the SVG msub/msup/msubsup/munder/mover/munderover wrappers * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgScriptbaseNTD +export interface SvgScriptbaseNTD extends - SvgWrapper, + SvgWrapper, CommonScriptbase< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgScriptbaseClass interface for the SVG msub/msup/msubsup/munder/mover/munderover wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgScriptbaseClass +export interface SvgScriptbaseClass extends - SvgWrapperClass, + SvgWrapperClass, CommonScriptbaseClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgScriptbaseNTD; + parent?: SvgWrapper + ): SvgScriptbaseNTD; } /*****************************************************************/ @@ -103,31 +81,19 @@ export interface SvgScriptbaseClass /** * The SvgScriptbase wrapper class for the msub/msup/msubsup/munder/mover/munderover class */ -export const SvgScriptbase = (function (): SvgScriptbaseClass< - N, - T, - D -> { +export const SvgScriptbase = (function (): SvgScriptbaseClass { const Base = CommonScriptbaseMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgScriptbaseClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgScriptbaseClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgScriptbase extends Base implements SvgScriptbaseNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgScriptbase extends Base implements SvgScriptbaseNTD { /** * @override */ @@ -139,7 +105,7 @@ export const SvgScriptbase = (function (): SvgScriptbaseClass< * * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; const svg = this.standardSvgNodes(parents); const w = this.getBaseWidth(); @@ -150,4 +116,4 @@ export const SvgScriptbase = (function (): SvgScriptbaseClass< this.scriptChild.place(w + x, v); } }; -})(); +})(); diff --git a/ts/output/svg/Wrappers/semantics.ts b/ts/output/svg/Wrappers/semantics.ts index 27fd64ab48..7e6094ea3d 100644 --- a/ts/output/svg/Wrappers/semantics.ts +++ b/ts/output/svg/Wrappers/semantics.ts @@ -22,16 +22,9 @@ * @author dpvc@mathjax.org (Davide Cervone) */ -import { SVG } from '../../svg.js'; +import { SVG, SVG_FONT } from '../../svg.js'; import { SvgWrapper, SvgWrapperClass } from '../Wrapper.js'; import { SvgWrapperFactory } from '../WrapperFactory.js'; -import { - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, -} from '../FontData.js'; import { CommonSemantics, CommonSemanticsClass, @@ -51,62 +44,47 @@ import { import { XMLNode } from '../../../core/MmlTree/MmlNode.js'; import { StyleJson } from '../../../util/StyleJson.js'; import { StyleList } from '../../../util/Styles.js'; +import { DOM, DOM_TYPES, N } from '../../../types/Types.js'; /*****************************************************************/ /** * The SvgSemantics interface for the SVG Semantics wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgSemanticsNTD +export interface SvgSemanticsNTD extends - SvgWrapper, + SvgWrapper, CommonSemantics< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgSemanticsClass interface for the SVG Semantics wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgSemanticsClass +export interface SvgSemanticsClass extends - SvgWrapperClass, + SvgWrapperClass, CommonSemanticsClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgSemanticsNTD; + parent?: SvgWrapper + ): SvgSemanticsNTD; } /*****************************************************************/ @@ -114,26 +92,18 @@ export interface SvgSemanticsClass /** * The SvgSemantics wrapper class for the MmlSemantics class */ -export const SvgSemantics = (function (): SvgSemanticsClass { +export const SvgSemantics = (function (): SvgSemanticsClass { const Base = CommonSemanticsMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgSemanticsClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgSemanticsClass >(SvgWrapper); - // Avoid message about base constructors not having the same type - // (they should both be SvgWrapper, but are thought of as different by typescript) - return class SvgSemantics extends Base implements SvgSemanticsNTD { + return class SvgSemantics extends Base implements SvgSemanticsNTD { /** * @override */ @@ -142,7 +112,7 @@ export const SvgSemantics = (function (): SvgSemanticsClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { if (this.toEmbellishedSVG(parents)) return; const svg = this.standardSvgNodes(parents); if (this.childNodes.length) { @@ -150,147 +120,114 @@ export const SvgSemantics = (function (): SvgSemanticsClass { } } }; -})(); +})(); /*****************************************************************/ /** * The SvgAnnotation wrapper for the MmlAnnotation object */ -export const SvgAnnotation = (function (): SvgWrapperClass { - return class SvgAnnotation extends SvgWrapper { - /** - * The annotation wrapper - */ - public static kind = MmlAnnotation.prototype.kind; +export class SvgAnnotation extends SvgWrapper { + /** + * The annotation wrapper + */ + public static kind = MmlAnnotation.prototype.kind; - /** - * @override - */ - public toSVG(parents: N[]) { - // FIXME: output as plain text - super.toSVG(parents); - } + /** + * @override + */ + public toSVG(parents: N[]) { + // FIXME: output as plain text + super.toSVG(parents); + } - /** - * @override - */ - public computeBBox() { - // FIXME: compute using the DOM, if possible - return this.bbox; - } - }; -})(); + /** + * @override + */ + public computeBBox() { + // FIXME: compute using the DOM, if possible + return this.bbox; + } +} /*****************************************************************/ /** * The SvgAnnotationXML wrapper for the MmlAnnotationXML object */ -export const SvgAnnotationXML = (function (): SvgWrapperClass< - N, - T, - D -> { - return class SvgAnnotationXML extends SvgWrapper { - /** - * The annotation-xml wrapper - */ - public static kind = MmlAnnotationXML.prototype.kind; +export class SvgAnnotationXML extends SvgWrapper { + /** + * The annotation-xml wrapper + */ + public static kind = MmlAnnotationXML.prototype.kind; - /** - * @override - */ - public static styles: StyleJson = { - 'foreignObject[data-mjx-xml]': { - 'font-family': 'initial', - 'line-height': 'normal', - overflow: 'visible', - }, - }; + /** + * @override + */ + public static styles: StyleJson = { + 'foreignObject[data-mjx-xml]': { + 'font-family': 'initial', + 'line-height': 'normal', + overflow: 'visible', + }, }; -})(); +} /*****************************************************************/ /** * The SvgXmlNode interface for the SVG XmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgXmlNodeNTD +export interface SvgXmlNodeNTD extends - SvgWrapper, + SvgWrapper, CommonXmlNode< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > {} /** * The SvgXmlNodeClass interface for the SVG XmlNode wrapper * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface SvgXmlNodeClass +export interface SvgXmlNodeClass extends - SvgWrapperClass, + SvgWrapperClass, CommonXmlNodeClass< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass > { new ( - factory: SvgWrapperFactory, + factory: SvgWrapperFactory, node: MmlNode, - parent?: SvgWrapper - ): SvgXmlNodeNTD; + parent?: SvgWrapper + ): SvgXmlNodeNTD; } /** * The SvgXmlNode wrapper for the XMLNode object */ - -export const SvgXmlNode = (function (): SvgXmlNodeClass { +export const SvgXmlNode = (function (): SvgXmlNodeClass { const Base = CommonXmlNodeMixin< - N, - T, - D, - SVG, - SvgWrapper, - SvgWrapperFactory, - SvgWrapperClass, - SvgCharOptions, - SvgVariantData, - SvgDelimiterData, - SvgFontData, - SvgFontDataClass, - SvgXmlNodeClass + DOM, + SVG_FONT, + SVG, + SvgWrapper, + SvgWrapperFactory, + SvgWrapperClass, + SvgXmlNodeClass >(SvgWrapper); - // @ts-expect-error Avoid message about base constructors not having the same - // type (they should both be SvgWrapper, but are thought of as - // different by typescript) - return class SvgXmlNode extends Base implements SvgXmlNodeNTD { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgXmlNode extends Base implements SvgXmlNodeNTD { /** * The XMLNode wrapper */ @@ -309,7 +246,7 @@ export const SvgXmlNode = (function (): SvgXmlNodeClass { /** * @override */ - public toSVG(parents: N[]) { + public toSVG(parents: N[]) { const metrics = this.jax.math.metrics; const em = metrics.em * metrics.scale * this.rscale; const scale = this.fixed(1 / em, 3); @@ -329,14 +266,14 @@ export const SvgXmlNode = (function (): SvgXmlNodeClass { }, [this.getHTML()] ) - ) as N, + ) as N, ]; } /** * @override */ - public addHDW(html: N, styles: StyleList): N { + public addHDW(html: N, styles: StyleList): N { html = this.html('mjx-html-holder', { style: styles }, [html]); const { h, d, w } = this.getBBox(); const scale = this.metrics.scale; @@ -348,4 +285,4 @@ export const SvgXmlNode = (function (): SvgXmlNodeClass { return html; } }; -})(); +})(); diff --git a/ts/types/Components.ts b/ts/types/Components.ts index 5de7dc243e..70a9d565f6 100644 --- a/ts/types/Components.ts +++ b/ts/types/Components.ts @@ -31,9 +31,6 @@ import type { EMPTY_COMPONENT, INPUTJAX, OUTPUTJAX, - N, - T, - D, } from './Types.js'; import type { STARTUP_TYPES } from '../components/startup.js'; @@ -187,31 +184,25 @@ export type COMPONENTS = { 'output/svg': OUTPUTJAX<'svg', SVG_OPTIONS, DOM>; 'a11y/semantic-enrich': - | DOC_OPTIONS> - | DOC_TYPE, T, D>>; - 'a11y/assistive-mml': - | DOC_OPTIONS - | DOC_TYPE, T, D>>; + DOC_OPTIONS> | DOC_TYPE>; + 'a11y/assisitive-mml': + DOC_OPTIONS | DOC_TYPE>; 'a11y/complexity': | 'a11y/semantic-enrich' | DOC_OPTIONS - | DOC_TYPE, T, D>>; + | DOC_TYPE>; 'a11y/speech': | 'a11y/semantic-enrich' | DOC_OPTIONS> - | DOC_TYPE, T, D>>; + | DOC_TYPE>; 'a11y/explorer': | 'a11y/speech' | DOC_OPTIONS | DOC_TYPE; 'ui/menu': DOC_OPTIONS | DOC_TYPE; - 'ui/lazy': - | DOC_OPTIONS> - | DOC_TYPE, T, D>>; - 'ui/safe': - | DOC_OPTIONS - | DOC_TYPE, T, D>>; + 'ui/lazy': DOC_OPTIONS> | DOC_TYPE>; + 'ui/safe': DOC_OPTIONS | DOC_TYPE>; 'ui/no-dark-mode': EMPTY_COMPONENT<'ui/no-dark-mode'>; 'adaptors/liteDOM': EMPTY_COMPONENT<'adaptors/liteDOM'>; diff --git a/ts/types/Types.ts b/ts/types/Types.ts index fb9e0c6b73..22072e0afa 100644 --- a/ts/types/Types.ts +++ b/ts/types/Types.ts @@ -29,9 +29,9 @@ import type { mathjax } from '../mathjax.js'; * The types for node, text, and document */ export type DOM_TYPES = { - N: any; - T: any; - D: any; + N: unknown; + T: unknown; + D: unknown; }; /** @@ -41,6 +41,8 @@ export type N = DOM['N']; export type T = DOM['T']; export type D = DOM['D']; +export type NT = N | T; + /** * A DOM_TYPES instance */ diff --git a/ts/ui/dialog/DraggableDialog.ts b/ts/ui/dialog/DraggableDialog.ts index 5b4431b52c..0ab8bc6aba 100644 --- a/ts/ui/dialog/DraggableDialog.ts +++ b/ts/ui/dialog/DraggableDialog.ts @@ -25,8 +25,9 @@ import { DOMAdaptor } from '../../core/DOMAdaptor.js'; import { StyleJson, StyleJsonSheet } from '../../util/StyleJson.js'; import { context } from '../../util/context.js'; import { localize } from '../../core/__locales__/Component.js'; +import { HTML_DOM } from '../../types/dom/html.js'; -export type ADAPTOR = DOMAdaptor; +export type ADAPTOR = DOMAdaptor; export type Action = ( dialog: DraggableDialog, diff --git a/ts/ui/lazy/LazyHandler.ts b/ts/ui/lazy/LazyHandler.ts index 23d83c75a5..7c476d816b 100644 --- a/ts/ui/lazy/LazyHandler.ts +++ b/ts/ui/lazy/LazyHandler.ts @@ -33,11 +33,10 @@ import { } from '../../handlers/html/HTMLDocument.js'; import { HTMLMathItem } from '../../handlers/html/HTMLMathItem.js'; import { HTMLHandler } from '../../handlers/html/HTMLHandler.js'; -// import { EnrichedMathItem } from '../../a11y/semantic-enrich.js'; import { SpeechMathItem } from '../../a11y/speech.js'; import { expandable } from '../../util/Options.js'; import { StyleJson } from '../../util/StyleJson.js'; -import { DOM, DOM_TYPES, N, T, D, Constructor } from '../../types/Types.js'; +import { DOM, DOM_TYPES, N, Constructor } from '../../types/Types.js'; /** * Add the needed function to the window object. @@ -59,8 +58,10 @@ export type LazySet = Set; /** * The data to map expression marker IDs back to their MathItem. + * + * @template DOM The DOM node types */ -export class LazyList { +export class LazyList { /** * The next ID to use */ @@ -69,15 +70,15 @@ export class LazyList { /** * The map from IDs to MathItems */ - protected items: Map> = new Map(); + protected items: Map> = new Map(); /** * Add a MathItem to the list and return its ID * * @param {LazyMathItem} math The item to add - * @returns {string} The id for the newly added item + * @returns {string} The id for the newly added item */ - public add(math: LazyMathItem): string { + public add(math: LazyMathItem): string { const id = String(this.id++); this.items.set(id, math); return id; @@ -86,10 +87,10 @@ export class LazyList { /** * Get the MathItem with the given ID * - * @param {string} id The ID of the MathItem to get + * @param {string} id The ID of the MathItem to get * @returns {LazyMathItem} The MathItem having that ID (if any) */ - public get(id: string): LazyMathItem { + public get(id: string): LazyMathItem { return this.items.get(id); } @@ -113,17 +114,17 @@ newState('LAZYALWAYS', STATE.FINDMATH + 3); */ export const LAZYID = 'data-mjx-lazy'; -export type HTMLSpeechItem = HTMLMathItem & - SpeechMathItem; +export type HTMLSpeechItem = HTMLMathItem & + SpeechMathItem; /** * The properties added to MathItem for lazy typesetting * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface LazyMathItem extends HTMLSpeechItem { +export interface LazyMathItem< + DOM extends DOM_TYPES, +> extends HTMLSpeechItem { /** * True when the MathItem needs to be lazy compiled */ @@ -137,7 +138,7 @@ export interface LazyMathItem extends HTMLSpeechItem { /** * The DOM node used to mark the location of the math to be lazy typeset */ - lazyMarker: N; + lazyMarker: N; /** * True if this item is a TeX MathItem @@ -148,20 +149,16 @@ export interface LazyMathItem extends HTMLSpeechItem { /** * The mixin for adding lazy typesetting to MathItems * - * @param {B} BaseMathItem The MathItem class to be extended - * @returns {LazyMathItem} The augmented MathItem class + * @param {B} BaseMathItem The MathItem class to be extended + * @returns {LazyMathItem} The augmented MathItem class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathItem class to extend + * @template DOM The DOM node types + * @template B The MathItem class to extend */ export function LazyMathItemMixin< - N, - T, - D, - B extends Constructor>, ->(BaseMathItem: B): Constructor> & B { + DOM extends DOM_TYPES, + B extends Constructor>, +>(BaseMathItem: B): Constructor> & B { return class extends BaseMathItem { /** * True when this item should be skipped during compilation @@ -179,7 +176,7 @@ export function LazyMathItemMixin< /** * The marker DOM node for this item. */ - public lazyMarker: N; + public lazyMarker: N; /** * True if this is a TeX expression. @@ -209,7 +206,7 @@ export function LazyMathItemMixin< * * @override */ - public compile(document: LazyMathDocument) { + public compile(document: LazyMathDocument) { if (!this.lazyCompile) { super.compile(document); return; @@ -238,7 +235,7 @@ export function LazyMathItemMixin< * * @override */ - public typeset(document: LazyMathDocument) { + public typeset(document: LazyMathDocument) { if (!this.lazyTypeset) { super.typeset(document); return; @@ -262,7 +259,7 @@ export function LazyMathItemMixin< * * @override */ - public updateDocument(document: LazyMathDocument) { + public updateDocument(document: LazyMathDocument) { super.updateDocument(document); if (this.lazyTypeset) { document.lazyObserver.observe(this.lazyMarker as any as Element); @@ -274,7 +271,7 @@ export function LazyMathItemMixin< * * @override */ - public attachSpeech = (document: LazyMathDocument) => { + public attachSpeech = (document: LazyMathDocument) => { if (this.state() >= STATE.ATTACHSPEECH) return; if (!this.lazyTypeset) { super.attachSpeech?.(document); @@ -299,7 +296,7 @@ export type OPTIONS = { */ export interface LAZY_OPTIONS extends OPTIONS, HTMLDOCUMENT_OPTIONS { - MathItem: Constructor, T, D>>; + MathItem: Constructor>; } /** @@ -315,15 +312,15 @@ const options: OPTIONS = { /** * The properties added to MathDocument for lazy typesetting * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export interface LazyMathDocument extends HTMLDocument { +export interface LazyMathDocument< + DOM extends DOM_TYPES, +> extends HTMLDocument { /** * @override */ - options: LAZY_OPTIONS>; + options: LAZY_OPTIONS; /** * The Intersection Observer used to track the appearance of the expression markers @@ -333,12 +330,12 @@ export interface LazyMathDocument extends HTMLDocument { /** * The mapping of markers to MathItems */ - lazyList: LazyList; + lazyList: LazyList; /** * The containers whose contents should always be typeset */ - lazyAlwaysContainers: N[]; + lazyAlwaysContainers: N[]; /** * A function that will typeset all the remaining expressions (e.g., for printing) @@ -354,22 +351,16 @@ export interface LazyMathDocument extends HTMLDocument { /** * The mixin for adding lazy typesetting to MathDocuments * - * @param {B} BaseDocument The MathDocument class to be extended - * @returns {LazyMathDocument} The Lazy MathDocument class + * @param {B} BaseDocument The MathDocument class to be extended + * @returns {LazyMathDocument} The Lazy MathDocument class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The MathDocument class to extend + * @template DOM The DOM node types + * @template B The MathDocument class to extend */ export function LazyMathDocumentMixin< - N, - T, - D, - B extends MathDocumentConstructor, DOM>, ->( - BaseDocument: B -): MathDocumentConstructor, DOM> & B { + DOM extends DOM_TYPES, + B extends MathDocumentConstructor, DOM>, +>(BaseDocument: B): MathDocumentConstructor, DOM> & B { return class BaseClass extends BaseDocument { /** * @override @@ -377,7 +368,7 @@ export function LazyMathDocumentMixin< public static OPTIONS = { ...BaseDocument.OPTIONS, ...options, - renderActions: expandable>({ + renderActions: expandable>({ ...BaseDocument.OPTIONS.renderActions, lazyAlways: [STATE.LAZYALWAYS, 'lazyAlways', '', false], }), @@ -386,7 +377,7 @@ export function LazyMathDocumentMixin< /** * @override */ - public options: LAZY_OPTIONS>; + public options: LAZY_OPTIONS; /** * The Intersection Observer used to track the appearance of the expression markers @@ -396,12 +387,12 @@ export function LazyMathDocumentMixin< /** * The mapping of markers to MathItems */ - public lazyList: LazyList; + public lazyList: LazyList; /** * The containers whose contents should always be typeset */ - public lazyAlwaysContainers: N[] = null; + public lazyAlwaysContainers: N[] = null; /** * Index of last container where math was found in lazyAlwaysContainers @@ -459,10 +450,8 @@ export function LazyMathDocumentMixin< // Use the LazyMathItem for math items // this.options.MathItem = LazyMathItemMixin< - N, - T, - D, - Constructor & SpeechMathItem> + DOM, + Constructor & SpeechMathItem> >(this.options.MathItem); // // Allocate a process bit for lazyAlways @@ -478,7 +467,7 @@ export function LazyMathDocumentMixin< this.lazyObserve.bind(this), { rootMargin: this.options.lazyMargin } ); - this.lazyList = new LazyList(); + this.lazyList = new LazyList(); const callback = this.lazyHandleSet.bind(this); this.lazyProcessSet = window && window.requestIdleCallback @@ -507,7 +496,7 @@ export function LazyMathDocumentMixin< if (!this.lazyAlwaysContainers || this.processed.isSet('lazyAlways')) return; for (const item of this.math) { - const math = item as LazyMathItem; + const math = item as LazyMathItem; if (math.lazyTypeset && this.lazyIsAlways(math)) { math.lazyCompile = math.lazyTypeset = false; } @@ -520,10 +509,10 @@ export function LazyMathDocumentMixin< * (start looking using the last container where math was found, * in case the next math is in the same container). * - * @param {LazyMathItem} math The MathItem to test - * @returns {boolean} True if one of the document's containers holds the MathItem + * @param {LazyMathItem} math The MathItem to test + * @returns {boolean} True if one of the document's containers holds the MathItem */ - protected lazyIsAlways(math: LazyMathItem): boolean { + protected lazyIsAlways(math: LazyMathItem): boolean { if (math.state() < STATE.LAZYALWAYS) { math.state(STATE.LAZYALWAYS); const node = math.start.node; @@ -566,7 +555,7 @@ export function LazyMathDocumentMixin< // Loop through all the math... // for (const item of this.math) { - const math = item as LazyMathItem; + const math = item as LazyMathItem; // // If it is not lazy compile or typeset, skip it. // @@ -638,7 +627,10 @@ export function LazyMathDocumentMixin< */ protected lazyObserve(entries: IntersectionObserverEntry[]) { for (const entry of entries) { - const id = this.adaptor.getAttribute(entry.target as any as N, LAZYID); + const id = this.adaptor.getAttribute( + entry.target as any as N, + LAZYID + ); const math = this.lazyList.get(id); if (!math) continue; if (!entry.isIntersecting) { @@ -680,7 +672,7 @@ export function LazyMathDocumentMixin< * * @param {LazySet} set The set of math items to update * @param {number} state The state needed for the items - * @returns {number} The updated state based on the items + * @returns {number} The updated state based on the items */ protected resetStates(set: LazySet, state: number): number { for (const id of set.values()) { @@ -706,14 +698,14 @@ export function LazyMathDocumentMixin< * Mark any TeX items (earlier than the ones in the set) to be compiled. * * @param {LazySet} set The set of items that are newly visible - * @returns {boolean} True if there are TeX items to be typeset + * @returns {boolean} True if there are TeX items to be typeset */ protected compileEarlierItems(set: LazySet): boolean { const math = this.earliestTex(set); if (!math) return false; let compile = false; for (const item of this.math) { - const earlier = item as LazyMathItem; + const earlier = item as LazyMathItem; if (earlier === math || !earlier?.lazyCompile || !earlier.lazyTex) { break; } @@ -730,10 +722,10 @@ export function LazyMathDocumentMixin< /** * Find the earliest TeX math item in the set, if any. * - * @param {LazySet} set The set of newly visble math items + * @param {LazySet} set The set of newly visble math items * @returns {LazyMathItem} The earliest TeX math item in the set, if any */ - protected earliestTex(set: LazySet): LazyMathItem { + protected earliestTex(set: LazySet): LazyMathItem { let min: number = null; let minMath = null; for (const id of set.values()) { @@ -752,12 +744,10 @@ export function LazyMathDocumentMixin< * * @override */ - public clearMathItemsWithin(containers: ContainerList) { - const items = super.clearMathItemsWithin(containers) as LazyMathItem< - N, - T, - D - >[]; + public clearMathItemsWithin(containers: ContainerList) { + const items = super.clearMathItemsWithin( + containers + ) as LazyMathItem[]; for (const math of items) { const marker = math.lazyMarker; if (marker) { @@ -795,25 +785,21 @@ export function LazyMathDocumentMixin< * Add lazy typesetting support to a Handler instance * * @param {HTMLHandler} handler The Handler instance to enhance - * @returns {HTMLHandler} The handler that was modified (for purposes of chaining extensions) + * @returns {HTMLHandler} The handler that was modified (for purposes of chaining extensions) * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export function LazyHandler( - handler: HTMLHandler -): HTMLHandler { +export function LazyHandler( + handler: HTMLHandler +): HTMLHandler { // // Only update the document class if we can handle IntersectionObservers // if (typeof IntersectionObserver !== 'undefined') { handler.documentClass = LazyMathDocumentMixin< - N, - T, - D, - MathDocumentConstructor> - >(handler.documentClass) as typeof HTMLDocument; + DOM, + MathDocumentConstructor, DOM> + >(handler.documentClass as any); } return handler; } diff --git a/ts/ui/menu/MJContextMenu.ts b/ts/ui/menu/MJContextMenu.ts index d2d3f0de3f..58f5884b79 100644 --- a/ts/ui/menu/MJContextMenu.ts +++ b/ts/ui/menu/MJContextMenu.ts @@ -26,6 +26,7 @@ import { OptionList } from '../../util/Options.js'; import { JaxList } from './Menu.js'; import { localize } from './__locales__/Component.js'; import { ExplorerMathItem } from '../../a11y/explorer.js'; +import { HTML_DOM } from '../../types/dom/html.js'; import { ContextMenu, @@ -82,7 +83,7 @@ export class MJContextMenu extends ContextMenu { /** * The MathItem that has posted the menu */ - public mathItem: MathItem = null; + public mathItem: MathItem = null; /** * Records the mathItem's nofocus value when a SelectInfo dialog is opened diff --git a/ts/ui/menu/Menu.ts b/ts/ui/menu/Menu.ts index fc189af8d2..475013704d 100644 --- a/ts/ui/menu/Menu.ts +++ b/ts/ui/menu/Menu.ts @@ -50,6 +50,7 @@ import { MmlVisitor } from './MmlVisitor.js'; import { MenuMathDocument } from './MenuHandler.js'; import * as MenuUtil from './MenuUtil.js'; import { locales } from './locales.js'; +import { HTML_DOM } from '../../types/dom/html.js'; import { Parser, Rule, CssStyles, Submenu } from './mj-context-menu.js'; @@ -72,10 +73,10 @@ const XMLDECLARATION = ''; /*==========================================================================*/ -export type HTMLMATHITEM = MathItem; +export type HTMLMATHITEM = MathItem; export type JaxList = { - [name: string]: OutputJax; + [name: string]: OutputJax; }; type A11Y = Partial; @@ -251,7 +252,7 @@ export class Menu { /** * A MathML serializer that has options corresponding to the menu settings */ - public MmlVisitor = new MmlVisitor(); + public MmlVisitor = new MmlVisitor(); /** * The MathDocument in which we are working @@ -1120,8 +1121,8 @@ export class Menu { * @returns {OutputJax} The adjusted output jax. */ protected applyRendererOptions( - output: OutputJax - ): OutputJax { + output: OutputJax + ): OutputJax { const settings = this.settings; const options = output.options; options.scale = settings.scale; @@ -1610,7 +1611,7 @@ export class Menu { cache: 'local' | 'global' | 'none', breaks: boolean ): Promise { - const jax = this.jax.SVG as SVG; + const jax = this.jax.SVG as SVG; const div = jax.html('div'); if (cache === 'global') { jax.options.fontCache = 'local'; diff --git a/ts/ui/menu/MenuHandler.ts b/ts/ui/menu/MenuHandler.ts index 1a965ca1e0..54ae9e4a86 100644 --- a/ts/ui/menu/MenuHandler.ts +++ b/ts/ui/menu/MenuHandler.ts @@ -46,7 +46,7 @@ import type { } from '../../a11y/speech.js'; import type { EXPLORER_OPTIONS } from '../../a11y/explorer.ts'; import { expandable } from '../../util/Options.js'; -import { DOM, Constructor } from '../../types/Types.js'; +import { Constructor } from '../../types/Types.js'; import { HTML_DOM } from '../../types/dom/html.js'; import { Menu, OPTIONS as SETTINGS } from './Menu.js'; @@ -59,9 +59,9 @@ import '../../a11y/speech/SpeechMenu.js'; */ /* prettier-ignore */ export type A11yMathItem = - SpeechMathItem & - ComplexityMathItem & - AssistiveMmlMathItem; + SpeechMathItem & + ComplexityMathItem & + AssistiveMmlMathItem; /** * Constructor for base MathItem for MenuMathItem @@ -75,16 +75,16 @@ export type A11yMathItemConstructor = { */ /* prettier-ignore */ export type A11yMathDocument = - ComplexityMathDocument & - SpeechMathDocument & - AssistiveMmlMathDocument; + ComplexityMathDocument & + SpeechMathDocument & + AssistiveMmlMathDocument; /** * Constructor for base document for MenuMathDocument */ export type A11yDocumentConstructor = MathDocumentConstructor< A11yMathDocument, - DOM + HTML_DOM >; /*==========================================================================*/ @@ -119,7 +119,7 @@ export interface MenuMathItem extends A11yMathItem { * The mixin for adding context menus to MathItems * * @param {B} BaseMathItem The MathItem class to be extended - * @returns {MenuMathItem} The extended MathItem class + * @returns {MenuMathItem} The extended MathItem class * * @template B The MathItem class to extend */ @@ -244,8 +244,8 @@ export interface MenuMathDocument extends A11yMathDocument { /** * The mixin for adding context menus to MathDocuments * - * @param {B} BaseDocument The MathDocument class to be extended - * @returns {MenuMathDocument} The extended MathDocument class + * @param {B} BaseDocument The MathDocument class to be extended + * @returns {MenuMathDocument} The extended MathDocument class * * @template B The MathDocument class to extend */ @@ -265,7 +265,7 @@ export function MenuMathDocumentMixin( a11y: (BaseDocument.OPTIONS as SPEECH_OPTIONS).a11y || expandable({}), - renderActions: expandable>({ + renderActions: expandable>({ ...BaseDocument.OPTIONS.renderActions, addMenu: [STATE.CONTEXT_MENU], getMenus: [STATE.INSERTED + 5, false], @@ -392,11 +392,9 @@ export function MenuMathDocumentMixin( * Add context-menu support to a Handler instance * * @param {Handler} handler The Handler instance to enhance - * @returns {Handler} The handler that was modified (for purposes of chaining extensions) + * @returns {Handler} The handler that was modified (for purposes of chaining extensions) */ -export function MenuHandler( - handler: Handler -): Handler { +export function MenuHandler(handler: Handler): Handler { handler.documentClass = MenuMathDocumentMixin( handler.documentClass as any ); diff --git a/ts/ui/menu/MmlVisitor.ts b/ts/ui/menu/MmlVisitor.ts index 91fc882f93..a9678760ef 100644 --- a/ts/ui/menu/MmlVisitor.ts +++ b/ts/ui/menu/MmlVisitor.ts @@ -26,17 +26,16 @@ import { MmlNode } from '../../core/MmlTree/MmlNode.js'; import { PropertyList } from '../../core/Tree/Node.js'; import { SerializedMmlVisitor } from '../../core/MmlTree/SerializedMmlVisitor.js'; import { OptionList, userOptions } from '../../util/Options.js'; +import { DOM_TYPES } from '../../types/Types.js'; /*==========================================================================*/ /** * The visitor to serialize MathML * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class MmlVisitor extends SerializedMmlVisitor { +export class MmlVisitor extends SerializedMmlVisitor { /** * The options controlling the serialization */ @@ -50,7 +49,7 @@ export class MmlVisitor extends SerializedMmlVisitor { /** * The MathItem currently being processed */ - public mathItem: MathItem = null; + public mathItem: MathItem = null; /** * @param {MmlNode} node The internal MathML node to serialize @@ -60,7 +59,7 @@ export class MmlVisitor extends SerializedMmlVisitor { */ public visitTree( node: MmlNode, - math: MathItem = null, + math: MathItem = null, options: OptionList = {} ) { this.mathItem = math; diff --git a/ts/ui/no-dark-mode/no-dark-mode.ts b/ts/ui/no-dark-mode/no-dark-mode.ts index 9ebbe51538..6957fa008a 100644 --- a/ts/ui/no-dark-mode/no-dark-mode.ts +++ b/ts/ui/no-dark-mode/no-dark-mode.ts @@ -24,6 +24,7 @@ import { MathJax } from '../../components/global.js'; import { MathJaxObject } from '../../components/startup.js'; import { AbstractHandler } from '../../core/Handler.js'; +import { DOM } from '../../types/Types.js'; [ [ @@ -47,7 +48,7 @@ import { AbstractHandler } from '../../core/Handler.js'; 'mjx-ignore' ] = { ignore: 1 }; (MathJax as MathJaxObject).startup.extendHandler( - (handler: AbstractHandler) => { + (handler: AbstractHandler) => { delete (handler.documentClass as any).speechStyles[ '@media (prefers-color-scheme: dark) /* explorer */' ]; diff --git a/ts/ui/safe/SafeHandler.ts b/ts/ui/safe/SafeHandler.ts index 7549026337..2ea280e69c 100644 --- a/ts/ui/safe/SafeHandler.ts +++ b/ts/ui/safe/SafeHandler.ts @@ -28,7 +28,7 @@ import { DOCUMENT_OPTIONS, } from '../../core/MathDocument.js'; import { Handler } from '../../core/Handler.js'; -import { DOM, DOM_TYPES, Constructor } from '../../types/Types.js'; +import { DOM_TYPES, Constructor } from '../../types/Types.js'; import { Safe } from './safe.js'; @@ -81,38 +81,31 @@ const options: OPTIONS = { /** * The properties needed in the MathDocument for sanitizing the internal MathML + * + * @template DOM The DOM node types */ -export interface SafeMathDocument extends AbstractMathDocument< - N, - T, - D -> { +export interface SafeMathDocument< + DOM extends DOM_TYPES, +> extends AbstractMathDocument { /** * The Safe object for this document */ - safe: Safe; + safe: Safe; } /** * The mixin for adding safe render action to MathDocuments * - * @param {B} BaseDocument The MathDocument class to be extended - * @returns {SafeMathDocument} The extended MathDocument class + * @param {B} BaseDocument The MathDocument class to be extended + * @returns {SafeMathDocument} The extended MathDocument class * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class - * @template B The Base document + * @template DOM The DOM node types + * @template B The Base document */ export function SafeMathDocumentMixin< - N, - T, - D, - B extends MathDocumentConstructor< - AbstractMathDocument, - DOM - >, ->(BaseDocument: B): Constructor> & B { + DOM extends DOM_TYPES, + B extends MathDocumentConstructor, DOM>, +>(BaseDocument: B): Constructor> & B { return class extends BaseDocument { /** * @override @@ -122,12 +115,12 @@ export function SafeMathDocumentMixin< ...options, }; - public options: SAFE_OPTIONS>; + public options: SAFE_OPTIONS; /** * An instance of the Safe object */ - public safe: Safe; + public safe: Safe; /** * Extend the MathItem class used for this MathDocument @@ -154,13 +147,13 @@ export function SafeMathDocumentMixin< /** * @param {object} data The argument containing math item and document - * @param {MathItem} data.math The math item to sanitize - * @param {SafeMathDocument} data.document The document to use for the + * @param {MathItem} data.math The math item to sanitize + * @param {SafeMathDocument} data.document The document to use for the * filter (note: this has been bound to the input jax) */ protected sanitize(data: { - math: MathItem; - document: SafeMathDocument; + math: MathItem; + document: SafeMathDocument; }) { data.math.root = (this as any).parseOptions.root; data.document.safe.sanitize(data.math, data.document); @@ -176,9 +169,12 @@ export function SafeMathDocumentMixin< * @param {Handler} handler The Handler instance to enhance * @returns {Handler} The handler that was modified (for purposes of chaining extensions) */ -export function SafeHandler( - handler: Handler -): Handler { - handler.documentClass = SafeMathDocumentMixin(handler.documentClass); +export function SafeHandler( + handler: Handler +): Handler { + handler.documentClass = SafeMathDocumentMixin< + DOM, + MathDocumentConstructor, DOM> + >(handler.documentClass); return handler; } diff --git a/ts/ui/safe/SafeMethods.ts b/ts/ui/safe/SafeMethods.ts index d8cb4442a0..3adcc94b7a 100644 --- a/ts/ui/safe/SafeMethods.ts +++ b/ts/ui/safe/SafeMethods.ts @@ -23,23 +23,25 @@ import { length2em } from '../../util/lengths.js'; import { Safe, FilterFunction } from './safe.js'; +import { DOM, DOM_TYPES, N } from '../../types/Types.js'; /** * The default attribute-filtering functions */ -export const SafeMethods: { [name: string]: FilterFunction } = { +export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter HREF URL's * - * @param {Safe} safe The Safe object being used - * @param {string} url The URL being tested - * @returns {string|null} The URL if OK and null if not + * @param {Safe} safe The Safe object being used + * @param {string} url The URL being tested + * @returns {string|null} The URL if OK and null if not * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterURL(safe: Safe, url: string): string | null { + filterURL( + safe: Safe, + url: string + ): string | null { const protocol = (url.match(/^\s*([a-z\n\r]+):/i) || [null, ''])[1] .replace(/[\n\r]/g, '') .toLowerCase(); @@ -53,15 +55,16 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter a class list * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} list The class list being tested * @returns {string|null} The class list if OK and null if not * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterClassList(safe: Safe, list: string): string | null { + filterClassList( + safe: Safe, + list: string + ): string | null { const classes = list.trim().replace(/\s\s+/g, ' ').split(/ /); return classes .map((name) => this.filterClass(safe, name) || '') @@ -73,15 +76,16 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter a class name * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} CLASS The class being tested - * @returns {string|null} The class if OK and null if not + * @returns {string|null} The class if OK and null if not * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterClass(safe: Safe, CLASS: string): string | null { + filterClass( + safe: Safe, + CLASS: string + ): string | null { const allow = safe.allow.classes; return allow === 'all' || (allow === 'safe' && CLASS.match(safe.options.classPattern)) @@ -92,15 +96,13 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter ids * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} id The id being tested * @returns {string|null} The id if OK and null if not * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterID(safe: Safe, id: string): string | null { + filterID(safe: Safe, id: string): string | null { const allow = safe.allow.cssIDs; return allow === 'all' || (allow === 'safe' && id.match(safe.options.idPattern)) @@ -111,15 +113,13 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter style strings * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} styles The style string being tested * @returns {string} The sanitized style string * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterStyles(safe: Safe, styles: string): string { + filterStyles(safe: Safe, styles: string): string { if (safe.allow.styles === 'all') return styles; if (safe.allow.styles !== 'safe') return null; const adaptor = safe.adaptor; @@ -163,19 +163,17 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter an individual name:value style pair * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} style The style name being tested * @param {N} div The temp DIV node containing the style object to be tested * @returns {string|null} The sanitized style string or null if invalid * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterStyle( - safe: Safe, + filterStyle( + safe: Safe, style: string, - div: N + div: N ): string | null { const value = safe.adaptor.getStyle(div, style); if ( @@ -197,21 +195,19 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter a style's value, handling compound values (e.g., borders that have widths as well as styles and colors) * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} style The style name being tested * @param {string} value The value of the style to test * @param {N} div The temp DIV node containing the style object to be tested * @returns {string|null} The sanitized style string or null if invalid * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterStyleValue( - safe: Safe, + filterStyleValue( + safe: Safe, style: string, value: string, - div: N + div: N ): string | null { const name = safe.options.styleLengths[style]; if (!name) { @@ -235,17 +231,15 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter a length value * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} style The style name being tested * @param {string} value The value of the style to test * @returns {string|null} The sanitized length value * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterStyleLength( - safe: Safe, + filterStyleLength( + safe: Safe, style: string, value: string ): string | null { @@ -263,30 +257,32 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter a font size * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} size The font size to test * @returns {string|null} The sanitized style string or null if invalid * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterFontSize(safe: Safe, size: string): string | null { + filterFontSize( + safe: Safe, + size: string + ): string | null { return this.filterStyleLength(safe, 'fontSize', size); }, /** * Filter scriptsizemultiplier * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} size The script size multiplier to test * @returns {string} The sanitized size * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterSizeMultiplier(safe: Safe, size: string): string { + filterSizeMultiplier( + safe: Safe, + size: string + ): string { const [m, M] = safe.options.scriptsizemultiplierRange || [ -Infinity, Infinity, @@ -297,16 +293,14 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter scriptLevel * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} level The scriptlevel to test * @returns {string|null} The sanitized scriptlevel or null * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterScriptLevel( - safe: Safe, + filterScriptLevel( + safe: Safe, level: string ): string | null { const [m, M] = safe.options.scriptlevelRange || [-Infinity, Infinity]; @@ -316,17 +310,15 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter a data-* attribute * - * @param {Safe} safe The Safe object being used + * @param {Safe} safe The Safe object being used * @param {string} value The attribute's value * @param {string} id The attribute's id (e.g., data-mjx-variant) * @returns {number|null} The sanitized value or null * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterData( - safe: Safe, + filterData( + safe: Safe, value: string, id: string ): string | null { @@ -336,17 +328,15 @@ export const SafeMethods: { [name: string]: FilterFunction } = { /** * Filter an on* attribute (don't allow them) * - * @param {Safe} _safe The Safe object being used + * @param {Safe} _safe The Safe object being used * @param {string} _value The attribute's value * @param {string} _id The attribute's id (e.g., data-mjx-variant) * @returns {string|null} The sanitized value or null * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ - filterListeners( - _safe: Safe, + filterListeners( + _safe: Safe, _value: string, _id: string ): string | null { diff --git a/ts/ui/safe/safe.ts b/ts/ui/safe/safe.ts index 43c23a6d69..bf857b7151 100644 --- a/ts/ui/safe/safe.ts +++ b/ts/ui/safe/safe.ts @@ -29,20 +29,22 @@ import { OptionList, expandable } from '../../util/Options.js'; import { DOMAdaptor } from '../../core/DOMAdaptor.js'; import { SafeMethods } from './SafeMethods.js'; import type { OPTIONS, SAFE_LIST, LENGTH_LIST } from './SafeHandler.js'; +import type { DOM_TYPES } from '../../types/Types.js'; /** * Function type for filtering attributes * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export type FilterFunction = ( - safe: Safe, +export type FilterFunction = ( + safe: Safe, value: Property, ...args: any[] ) => Property; +/** + * The default options for the safe extension + */ const options: OPTIONS['safeOptions'] = { allow: { // @@ -144,11 +146,9 @@ const options: OPTIONS['safeOptions'] = { /** * The Safe object for sanitizing the internal MathML representation of an expression * - * @template N The HTMLElement node class - * @template T The Text node class - * @template D The Document class + * @template DOM The DOM node types */ -export class Safe { +export class Safe { /** * The options controlling the handling of the safe extension */ @@ -189,20 +189,20 @@ export class Safe { /** * The DOM adaptor from the document */ - public adaptor: DOMAdaptor; + public adaptor: DOMAdaptor; /** * The methods for filtering the MathML attributes */ - public filterMethods: { [name: string]: FilterFunction } = { + public filterMethods: { [name: string]: FilterFunction } = { ...SafeMethods, }; /** - * @param {MathDocument} document The MathDocument we are sanitizing - * @param {OptionList} options The safeOptions from the document + * @param {MathDocument} document The MathDocument we are sanitizing + * @param {OptionList} options The safeOptions from the document */ - constructor(document: MathDocument, options: OptionList) { + constructor(document: MathDocument, options: OptionList) { this.adaptor = document.adaptor; this.options = options; this.allow = this.options.allow; @@ -211,15 +211,15 @@ export class Safe { /** * Sanitize a MathItem's root MathML tree * - * @param {MathItem} math The MathItem to sanitize - * @param {MathDocument} document The MathDocument in which it lives + * @param {MathItem} math The MathItem to sanitize + * @param {MathDocument} document The MathDocument in which it lives */ - public sanitize(math: MathItem, document: MathDocument) { + public sanitize(math: MathItem, document: MathDocument) { try { math.root.walkTree(this.sanitizeNode.bind(this)); } catch (err) { document.options.compileError( - document as AbstractMathDocument, + document as AbstractMathDocument, math, err ); @@ -256,8 +256,8 @@ export class Safe { /** * Sanitize a MathML input attribute * - * @param {string} id The name of the attribute - * @param {string} value The value of the attribute + * @param {string} id The name of the attribute + * @param {string} value The value of the attribute * @returns {string|null} The sanitized value */ public mmlAttribute(id: string, value: string): string | null { @@ -283,7 +283,7 @@ export class Safe { * Sanitize a list of class names * * @param {string[]} list The list of class names - * @returns {string[]} The sanitized list + * @returns {string[]} The sanitized list */ public mmlClassList(list: string[]): string[] { return list From 5f7dc8a633349bba7edc8b39e4a1cafcf0d767a8 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 2 Sep 2026 14:53:53 -0400 Subject: [PATCH 2/3] Resolve problems with CJS build --- components/mjs/output/util.d.ts | 5 +++-- ts/output/chtml/Wrappers/HtmlNode.ts | 18 +++++++++--------- ts/output/svg/Wrappers/HtmlNode.ts | 16 +++++++++------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/components/mjs/output/util.d.ts b/components/mjs/output/util.d.ts index 11012bffcf..8ff3a250fa 100644 --- a/components/mjs/output/util.d.ts +++ b/components/mjs/output/util.d.ts @@ -1,5 +1,6 @@ import { OutputJax } from '@mathjax/src/mjs/core/OutputJax.js'; import { Font } from '@mathjax/src/mjs/output/common/FontData.js'; +import { DOM_TYPES } from '@mathjax/src/mjs/types/Types.js'; export function configFont( font: string, @@ -18,9 +19,9 @@ export function configExtensions( export const OutputUtil: { - config( + config( jax: string, - jaxClass: OutputJax, + jaxClass: OutputJax, defaultFont: Font, fontClass: any, ): void, diff --git a/ts/output/chtml/Wrappers/HtmlNode.ts b/ts/output/chtml/Wrappers/HtmlNode.ts index 8f549f004b..81c7c3628e 100644 --- a/ts/output/chtml/Wrappers/HtmlNode.ts +++ b/ts/output/chtml/Wrappers/HtmlNode.ts @@ -62,13 +62,13 @@ export interface ChtmlHtmlNodeClass< /** * The ChtmlHtmlNode wrapper class for the MmlHtmlNode class */ -export class ChtmlHtmlNode +export const ChtmlHtmlNode = (function (): ChtmlHtmlNodeClass { // @ts-expect-error Avoid message about base constructors not having the same type - extends ChtmlXmlNode - implements ChtmlHtmlNodeNTD -{ - /** - * @override - */ - public static kind = HtmlNode.prototype.kind; -} + return class ChtmlHtmlNode extends ChtmlXmlNode implements ChtmlHtmlNodeNTD + { + /** + * @override + */ + public static kind = HtmlNode.prototype.kind; + } +})(); diff --git a/ts/output/svg/Wrappers/HtmlNode.ts b/ts/output/svg/Wrappers/HtmlNode.ts index 9fb085933f..1a6f848e03 100644 --- a/ts/output/svg/Wrappers/HtmlNode.ts +++ b/ts/output/svg/Wrappers/HtmlNode.ts @@ -58,10 +58,12 @@ export interface SvgHtmlNodeClass< /** * The SvgHtmlNode wrapper class for the MmlHtmlNode class */ -// @ts-expect-error Avoid message about base constructors not having the same type -export class SvgHtmlNode extends SvgXmlNode implements SvgHtmlNodeNTD { - /** - * @override - */ - public static kind = HtmlNode.prototype.kind; -} +export const SvgHtmlNode = (function (): SvgHtmlNodeClass { + // @ts-expect-error Avoid message about base constructors not having the same type + return class SvgHtmlNode extends SvgXmlNode implements SvgHtmlNodeNTD { + /** + * @override + */ + public static kind = HtmlNode.prototype.kind; + } +})(); From b99d9f80c2b882b9636c91c404afc1266ea8eee4 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 2 Sep 2026 14:59:17 -0400 Subject: [PATCH 3/3] Fix issue with compiling test suite --- testsuite/src/setupTex.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testsuite/src/setupTex.ts b/testsuite/src/setupTex.ts index f88459e6c7..6824ee76d7 100644 --- a/testsuite/src/setupTex.ts +++ b/testsuite/src/setupTex.ts @@ -28,9 +28,10 @@ import { throwTexErrors, throwCompileErrors, } from './traps.js'; +import { DOM } from '#js/types/Types.js'; declare const MathJax: any; -type MATHITEM = MathItem; +type MATHITEM = MathItem; type PackageList = (string | [string, number])[]; Locale.asyncLoad = asyncLoad;