mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-06 03:38:39 +00:00
make all classes in domTree.js PascalCase and make them named exports (#1636)
* make all classes in domTree.js PascalCase and make them named exports * add eslint rule to enforce capitalization, fix failures * address feedback
This commit is contained in:
committed by
ylemkimon
parent
ead04e5a29
commit
b2432e8ad2
@@ -25,6 +25,7 @@
|
|||||||
"keyword-spacing": 2,
|
"keyword-spacing": 2,
|
||||||
"linebreak-style": [2, "unix"],
|
"linebreak-style": [2, "unix"],
|
||||||
"max-len": [2, 84, 4, { "ignoreUrls": true, "ignorePattern": "\\brequire\\([\"']|eslint-disable" }],
|
"max-len": [2, 84, 4, { "ignoreUrls": true, "ignorePattern": "\\brequire\\([\"']|eslint-disable" }],
|
||||||
|
"new-cap": 2,
|
||||||
"no-alert": 2,
|
"no-alert": 2,
|
||||||
"no-array-constructor": 2,
|
"no-array-constructor": 2,
|
||||||
"no-console": 2,
|
"no-console": 2,
|
||||||
|
@@ -12,7 +12,7 @@ const selenium = require("selenium-webdriver");
|
|||||||
const firefox = require("selenium-webdriver/firefox");
|
const firefox = require("selenium-webdriver/firefox");
|
||||||
|
|
||||||
const webpack = require('webpack');
|
const webpack = require('webpack');
|
||||||
const webpackDevServer = require("webpack-dev-server");
|
const WebpackDevServer = require("webpack-dev-server");
|
||||||
const webpackConfig = require("../../webpack.dev")[0];
|
const webpackConfig = require("../../webpack.dev")[0];
|
||||||
const data = require("../../test/screenshotter/ss_data");
|
const data = require("../../test/screenshotter/ss_data");
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ function startServer() {
|
|||||||
}
|
}
|
||||||
const port = Math.floor(Math.random() * (maxPort - minPort)) + minPort;
|
const port = Math.floor(Math.random() * (maxPort - minPort)) + minPort;
|
||||||
const compiler = webpack(webpackConfig);
|
const compiler = webpack(webpackConfig);
|
||||||
const wds = new webpackDevServer(compiler, webpackConfig.devServer);
|
const wds = new WebpackDevServer(compiler, webpackConfig.devServer);
|
||||||
const server = wds.listen(port);
|
const server = wds.listen(port);
|
||||||
server.once("listening", function() {
|
server.once("listening", function() {
|
||||||
devServer = wds;
|
devServer = wds;
|
||||||
|
@@ -268,5 +268,6 @@ function fftImage(image) {
|
|||||||
// Create a new matrix of preconfigured dimensions, initialized to zero
|
// Create a new matrix of preconfigured dimensions, initialized to zero
|
||||||
function createMatrix() {
|
function createMatrix() {
|
||||||
const array = new Float64Array(alignWidth * alignHeight);
|
const array = new Float64Array(alignWidth * alignHeight);
|
||||||
|
/* eslint-disable-next-line new-cap */
|
||||||
return new ndarray(array, [alignWidth, alignHeight]);
|
return new ndarray(array, [alignWidth, alignHeight]);
|
||||||
}
|
}
|
||||||
|
20
katex.js
20
katex.js
@@ -14,7 +14,14 @@ import Settings from "./src/Settings";
|
|||||||
import {buildTree, buildHTMLTree} from "./src/buildTree";
|
import {buildTree, buildHTMLTree} from "./src/buildTree";
|
||||||
import parseTree from "./src/parseTree";
|
import parseTree from "./src/parseTree";
|
||||||
import buildCommon from "./src/buildCommon";
|
import buildCommon from "./src/buildCommon";
|
||||||
import domTree from "./src/domTree";
|
import {
|
||||||
|
Span,
|
||||||
|
Anchor,
|
||||||
|
SymbolNode,
|
||||||
|
SvgNode,
|
||||||
|
PathNode,
|
||||||
|
LineNode,
|
||||||
|
} from "./src/domTree";
|
||||||
import utils from "./src/utils";
|
import utils from "./src/utils";
|
||||||
|
|
||||||
import type {SettingsOptions} from "./src/Settings";
|
import type {SettingsOptions} from "./src/Settings";
|
||||||
@@ -90,7 +97,7 @@ const renderError = function(
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
const node = buildCommon.makeSpan(["katex-error"],
|
const node = buildCommon.makeSpan(["katex-error"],
|
||||||
[new domTree.symbolNode(expression)]);
|
[new SymbolNode(expression)]);
|
||||||
node.setAttribute("title", error.toString());
|
node.setAttribute("title", error.toString());
|
||||||
node.setAttribute("style", `color:${options.errorColor}`);
|
node.setAttribute("style", `color:${options.errorColor}`);
|
||||||
return node;
|
return node;
|
||||||
@@ -196,5 +203,12 @@ export default {
|
|||||||
* The internal tree representation is unstable and is very likely
|
* The internal tree representation is unstable and is very likely
|
||||||
* to change. Use at your own risk.
|
* to change. Use at your own risk.
|
||||||
*/
|
*/
|
||||||
__domTree: domTree,
|
__domTree: {
|
||||||
|
Span,
|
||||||
|
Anchor,
|
||||||
|
SymbolNode,
|
||||||
|
SvgNode,
|
||||||
|
PathNode,
|
||||||
|
LineNode,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@@ -5,13 +5,13 @@
|
|||||||
* different kinds of domTree nodes in a consistent manner.
|
* different kinds of domTree nodes in a consistent manner.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import domTree from "./domTree";
|
import {SymbolNode, Anchor, Span, PathNode, SvgNode} from "./domTree";
|
||||||
import {getCharacterMetrics} from "./fontMetrics";
|
import {getCharacterMetrics} from "./fontMetrics";
|
||||||
import symbols, {ligatures} from "./symbols";
|
import symbols, {ligatures} from "./symbols";
|
||||||
import utils from "./utils";
|
import utils from "./utils";
|
||||||
import {wideCharacterFont} from "./wide-character";
|
import {wideCharacterFont} from "./wide-character";
|
||||||
import {calculateSize} from "./units";
|
import {calculateSize} from "./units";
|
||||||
import * as tree from "./tree";
|
import {DocumentFragment} from "./tree";
|
||||||
|
|
||||||
import type Options from "./Options";
|
import type Options from "./Options";
|
||||||
import type {ParseNode} from "./parseNode";
|
import type {ParseNode} from "./parseNode";
|
||||||
@@ -65,7 +65,7 @@ const makeSymbol = function(
|
|||||||
mode: Mode,
|
mode: Mode,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
classes?: string[],
|
classes?: string[],
|
||||||
): domTree.symbolNode {
|
): SymbolNode {
|
||||||
const lookup = lookupSymbol(value, fontName, mode);
|
const lookup = lookupSymbol(value, fontName, mode);
|
||||||
const metrics = lookup.metrics;
|
const metrics = lookup.metrics;
|
||||||
value = lookup.value;
|
value = lookup.value;
|
||||||
@@ -76,7 +76,7 @@ const makeSymbol = function(
|
|||||||
if (mode === "text") {
|
if (mode === "text") {
|
||||||
italic = 0;
|
italic = 0;
|
||||||
}
|
}
|
||||||
symbolNode = new domTree.symbolNode(
|
symbolNode = new SymbolNode(
|
||||||
value, metrics.height, metrics.depth, italic, metrics.skew,
|
value, metrics.height, metrics.depth, italic, metrics.skew,
|
||||||
metrics.width, classes);
|
metrics.width, classes);
|
||||||
} else {
|
} else {
|
||||||
@@ -84,7 +84,7 @@ const makeSymbol = function(
|
|||||||
typeof console !== "undefined" && console.warn(
|
typeof console !== "undefined" && console.warn(
|
||||||
"No character metrics for '" + value + "' in style '" +
|
"No character metrics for '" + value + "' in style '" +
|
||||||
fontName + "'");
|
fontName + "'");
|
||||||
symbolNode = new domTree.symbolNode(value, 0, 0, 0, 0, 0, classes);
|
symbolNode = new SymbolNode(value, 0, 0, 0, 0, 0, classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options) {
|
if (options) {
|
||||||
@@ -112,7 +112,7 @@ const mathsym = function(
|
|||||||
mode: Mode,
|
mode: Mode,
|
||||||
options?: Options,
|
options?: Options,
|
||||||
classes?: string[] = [],
|
classes?: string[] = [],
|
||||||
): domTree.symbolNode {
|
): SymbolNode {
|
||||||
// Decide what font to render the symbol in by its entry in the symbols
|
// Decide what font to render the symbol in by its entry in the symbols
|
||||||
// table.
|
// table.
|
||||||
// Have a special case for when the value = \ because the \ is used as a
|
// Have a special case for when the value = \ because the \ is used as a
|
||||||
@@ -141,7 +141,7 @@ const mathDefault = function(
|
|||||||
options: Options,
|
options: Options,
|
||||||
classes: string[],
|
classes: string[],
|
||||||
type: NodeType,
|
type: NodeType,
|
||||||
): domTree.symbolNode {
|
): SymbolNode {
|
||||||
if (type === "mathord") {
|
if (type === "mathord") {
|
||||||
const fontLookup = mathit(value, mode, options, classes);
|
const fontLookup = mathit(value, mode, options, classes);
|
||||||
return makeSymbol(value, fontLookup.fontName, mode, options,
|
return makeSymbol(value, fontLookup.fontName, mode, options,
|
||||||
@@ -235,7 +235,7 @@ const makeOrd = function<NODETYPE: "spacing" | "mathord" | "textord">(
|
|||||||
group: ParseNode<NODETYPE>,
|
group: ParseNode<NODETYPE>,
|
||||||
options: Options,
|
options: Options,
|
||||||
type: "mathord" | "textord",
|
type: "mathord" | "textord",
|
||||||
): HtmlDocumentFragment | domTree.symbolNode {
|
): HtmlDocumentFragment | SymbolNode {
|
||||||
const mode = group.mode;
|
const mode = group.mode;
|
||||||
const text = group.text;
|
const text = group.text;
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ const tryCombineChars = function(chars: HtmlDomNode[]): HtmlDomNode[] {
|
|||||||
* children.
|
* children.
|
||||||
*/
|
*/
|
||||||
const sizeElementFromChildren = function(
|
const sizeElementFromChildren = function(
|
||||||
elem: DomSpan | domTree.anchor | HtmlDocumentFragment,
|
elem: DomSpan | Anchor | HtmlDocumentFragment,
|
||||||
) {
|
) {
|
||||||
let height = 0;
|
let height = 0;
|
||||||
let depth = 0;
|
let depth = 0;
|
||||||
@@ -347,7 +347,7 @@ const makeSpan = function(
|
|||||||
options?: Options,
|
options?: Options,
|
||||||
style?: CssStyle,
|
style?: CssStyle,
|
||||||
): DomSpan {
|
): DomSpan {
|
||||||
const span = new domTree.span(classes, children, options, style);
|
const span = new Span(classes, children, options, style);
|
||||||
|
|
||||||
sizeElementFromChildren(span);
|
sizeElementFromChildren(span);
|
||||||
|
|
||||||
@@ -358,10 +358,10 @@ const makeSpan = function(
|
|||||||
// This is also a separate method for typesafety.
|
// This is also a separate method for typesafety.
|
||||||
const makeSvgSpan = (
|
const makeSvgSpan = (
|
||||||
classes?: string[],
|
classes?: string[],
|
||||||
children?: domTree.svgNode[],
|
children?: SvgNode[],
|
||||||
options?: Options,
|
options?: Options,
|
||||||
style?: CssStyle,
|
style?: CssStyle,
|
||||||
): SvgSpan => new domTree.span(classes, children, options, style);
|
): SvgSpan => new Span(classes, children, options, style);
|
||||||
|
|
||||||
const makeLineSpan = function(
|
const makeLineSpan = function(
|
||||||
className: string,
|
className: string,
|
||||||
@@ -385,7 +385,7 @@ const makeAnchor = function(
|
|||||||
children: HtmlDomNode[],
|
children: HtmlDomNode[],
|
||||||
options: Options,
|
options: Options,
|
||||||
) {
|
) {
|
||||||
const anchor = new domTree.anchor(href, classes, children, options);
|
const anchor = new Anchor(href, classes, children, options);
|
||||||
|
|
||||||
sizeElementFromChildren(anchor);
|
sizeElementFromChildren(anchor);
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ const makeAnchor = function(
|
|||||||
const makeFragment = function(
|
const makeFragment = function(
|
||||||
children: HtmlDomNode[],
|
children: HtmlDomNode[],
|
||||||
): HtmlDocumentFragment {
|
): HtmlDocumentFragment {
|
||||||
const fragment = new tree.documentFragment(children);
|
const fragment = new DocumentFragment(children);
|
||||||
|
|
||||||
sizeElementFromChildren(fragment);
|
sizeElementFromChildren(fragment);
|
||||||
|
|
||||||
@@ -594,7 +594,7 @@ const makeVList = function(params: VListParam, options: Options): DomSpan {
|
|||||||
|
|
||||||
// Safari wants the first row to have inline content; otherwise it
|
// Safari wants the first row to have inline content; otherwise it
|
||||||
// puts the bottom of the *second* row on the baseline.
|
// puts the bottom of the *second* row on the baseline.
|
||||||
const topStrut = makeSpan(["vlist-s"], [new domTree.symbolNode("\u200b")]);
|
const topStrut = makeSpan(["vlist-s"], [new SymbolNode("\u200b")]);
|
||||||
|
|
||||||
rows = [makeSpan(["vlist-r"], [vlist, topStrut]),
|
rows = [makeSpan(["vlist-r"], [vlist, topStrut]),
|
||||||
makeSpan(["vlist-r"], [depthStrut])];
|
makeSpan(["vlist-r"], [depthStrut])];
|
||||||
@@ -762,8 +762,8 @@ const svgData: {
|
|||||||
const staticSvg = function(value: string, options: Options): SvgSpan {
|
const staticSvg = function(value: string, options: Options): SvgSpan {
|
||||||
// Create a span with inline SVG for the element.
|
// Create a span with inline SVG for the element.
|
||||||
const [pathName, width, height] = svgData[value];
|
const [pathName, width, height] = svgData[value];
|
||||||
const path = new domTree.pathNode(pathName);
|
const path = new PathNode(pathName);
|
||||||
const svgNode = new domTree.svgNode([path], {
|
const svgNode = new SvgNode([path], {
|
||||||
"width": width + "em",
|
"width": width + "em",
|
||||||
"height": height + "em",
|
"height": height + "em",
|
||||||
// Override CSS rule `.katex svg { width: 100% }`
|
// Override CSS rule `.katex svg { width: 100% }`
|
||||||
|
@@ -9,12 +9,12 @@
|
|||||||
import ParseError from "./ParseError";
|
import ParseError from "./ParseError";
|
||||||
import Style from "./Style";
|
import Style from "./Style";
|
||||||
import buildCommon from "./buildCommon";
|
import buildCommon from "./buildCommon";
|
||||||
import domTree from "./domTree";
|
import {Anchor} from "./domTree";
|
||||||
import utils, {assert} from "./utils";
|
import utils, {assert} from "./utils";
|
||||||
import {checkNodeType} from "./parseNode";
|
import {checkNodeType} from "./parseNode";
|
||||||
import {spacings, tightSpacings} from "./spacingData";
|
import {spacings, tightSpacings} from "./spacingData";
|
||||||
import {_htmlGroupBuilders as groupBuilders} from "./defineFunction";
|
import {_htmlGroupBuilders as groupBuilders} from "./defineFunction";
|
||||||
import * as tree from "./tree";
|
import {DocumentFragment} from "./tree";
|
||||||
|
|
||||||
import type Options from "./Options";
|
import type Options from "./Options";
|
||||||
import type {AnyParseNode} from "./parseNode";
|
import type {AnyParseNode} from "./parseNode";
|
||||||
@@ -91,7 +91,7 @@ export const buildExpression = function(
|
|||||||
const rawGroups: HtmlDomNode[] = [];
|
const rawGroups: HtmlDomNode[] = [];
|
||||||
for (let i = 0; i < expression.length; i++) {
|
for (let i = 0; i < expression.length; i++) {
|
||||||
const output = buildGroup(expression[i], options);
|
const output = buildGroup(expression[i], options);
|
||||||
if (output instanceof tree.documentFragment) {
|
if (output instanceof DocumentFragment) {
|
||||||
const children: HtmlDomNode[] = output.children;
|
const children: HtmlDomNode[] = output.children;
|
||||||
rawGroups.push(...children);
|
rawGroups.push(...children);
|
||||||
} else {
|
} else {
|
||||||
@@ -190,8 +190,8 @@ const getOutermostNode = function(
|
|||||||
node: HtmlDomNode,
|
node: HtmlDomNode,
|
||||||
side: Side,
|
side: Side,
|
||||||
): HtmlDomNode {
|
): HtmlDomNode {
|
||||||
if (node instanceof tree.documentFragment ||
|
if (node instanceof DocumentFragment ||
|
||||||
node instanceof domTree.anchor) {
|
node instanceof Anchor) {
|
||||||
const children = node.children;
|
const children = node.children;
|
||||||
if (children.length) {
|
if (children.length) {
|
||||||
if (side === "right") {
|
if (side === "right") {
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
import ParseError from "./ParseError";
|
import ParseError from "./ParseError";
|
||||||
import Style from "./Style";
|
import Style from "./Style";
|
||||||
|
|
||||||
import domTree from "./domTree";
|
import {PathNode, SvgNode, SymbolNode} from "./domTree";
|
||||||
import buildCommon from "./buildCommon";
|
import buildCommon from "./buildCommon";
|
||||||
import {getCharacterMetrics} from "./fontMetrics";
|
import {getCharacterMetrics} from "./fontMetrics";
|
||||||
import symbols from "./symbols";
|
import symbols from "./symbols";
|
||||||
@@ -125,7 +125,7 @@ const mathrmSize = function(
|
|||||||
size: number,
|
size: number,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
options: Options,
|
options: Options,
|
||||||
): domTree.symbolNode {
|
): SymbolNode {
|
||||||
return buildCommon.makeSymbol(value, "Size" + size + "-Regular",
|
return buildCommon.makeSymbol(value, "Size" + size + "-Regular",
|
||||||
mode, options);
|
mode, options);
|
||||||
};
|
};
|
||||||
@@ -391,9 +391,9 @@ const sqrtSvg = function(
|
|||||||
-294.333-240-727l-212 -643 -85 170c-4-3.333-8.333-7.667-13 -13l-13-13l77-155
|
-294.333-240-727l-212 -643 -85 170c-4-3.333-8.333-7.667-13 -13l-13-13l77-155
|
||||||
77-156c66 199.333 139 419.667 219 661 l218 661zM702 ${vbPad}H400000v40H742z`;
|
77-156c66 199.333 139 419.667 219 661 l218 661zM702 ${vbPad}H400000v40H742z`;
|
||||||
}
|
}
|
||||||
const pathNode = new domTree.pathNode(sqrtName, alternate);
|
const pathNode = new PathNode(sqrtName, alternate);
|
||||||
|
|
||||||
const svg = new domTree.svgNode([pathNode], {
|
const svg = new SvgNode([pathNode], {
|
||||||
// Note: 1000:1 ratio of viewBox to document em width.
|
// Note: 1000:1 ratio of viewBox to document em width.
|
||||||
"width": "400em",
|
"width": "400em",
|
||||||
"height": height + "em",
|
"height": height + "em",
|
||||||
|
@@ -15,7 +15,7 @@ import {scriptFromCodepoint} from "./unicodeScripts";
|
|||||||
import utils from "./utils";
|
import utils from "./utils";
|
||||||
import svgGeometry from "./svgGeometry";
|
import svgGeometry from "./svgGeometry";
|
||||||
import type Options from "./Options";
|
import type Options from "./Options";
|
||||||
import * as tree from "./tree";
|
import {DocumentFragment} from "./tree";
|
||||||
|
|
||||||
import type {VirtualNode} from "./tree";
|
import type {VirtualNode} from "./tree";
|
||||||
|
|
||||||
@@ -139,12 +139,12 @@ export interface HtmlDomNode extends VirtualNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Span wrapping other DOM nodes.
|
// Span wrapping other DOM nodes.
|
||||||
export type DomSpan = span<HtmlDomNode>;
|
export type DomSpan = Span<HtmlDomNode>;
|
||||||
// Span wrapping an SVG node.
|
// Span wrapping an SVG node.
|
||||||
export type SvgSpan = span<svgNode>;
|
export type SvgSpan = Span<SvgNode>;
|
||||||
|
|
||||||
export type SvgChildNode = pathNode | lineNode;
|
export type SvgChildNode = PathNode | LineNode;
|
||||||
export type documentFragment = tree.documentFragment<HtmlDomNode>;
|
export type documentFragment = DocumentFragment<HtmlDomNode>;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,7 +156,7 @@ export type documentFragment = tree.documentFragment<HtmlDomNode>;
|
|||||||
* otherwise. This typesafety is important when HTML builders access a span's
|
* otherwise. This typesafety is important when HTML builders access a span's
|
||||||
* children.
|
* children.
|
||||||
*/
|
*/
|
||||||
class span<ChildType: VirtualNode> implements HtmlDomNode {
|
export class Span<ChildType: VirtualNode> implements HtmlDomNode {
|
||||||
children: ChildType[];
|
children: ChildType[];
|
||||||
attributes: {[string]: string};
|
attributes: {[string]: string};
|
||||||
classes: string[];
|
classes: string[];
|
||||||
@@ -211,7 +211,7 @@ class span<ChildType: VirtualNode> implements HtmlDomNode {
|
|||||||
* This node represents an anchor (<a>) element with a hyperlink. See `span`
|
* This node represents an anchor (<a>) element with a hyperlink. See `span`
|
||||||
* for further details.
|
* for further details.
|
||||||
*/
|
*/
|
||||||
class anchor implements HtmlDomNode {
|
export class Anchor implements HtmlDomNode {
|
||||||
children: HtmlDomNode[];
|
children: HtmlDomNode[];
|
||||||
attributes: {[string]: string};
|
attributes: {[string]: string};
|
||||||
classes: string[];
|
classes: string[];
|
||||||
@@ -265,7 +265,7 @@ const iCombinations = {
|
|||||||
* to a single text node, or a span with a single text node in it, depending on
|
* to a single text node, or a span with a single text node in it, depending on
|
||||||
* whether it has CSS classes, styles, or needs italic correction.
|
* whether it has CSS classes, styles, or needs italic correction.
|
||||||
*/
|
*/
|
||||||
class symbolNode implements HtmlDomNode {
|
export class SymbolNode implements HtmlDomNode {
|
||||||
text: string;
|
text: string;
|
||||||
height: number;
|
height: number;
|
||||||
depth: number;
|
depth: number;
|
||||||
@@ -319,7 +319,7 @@ class symbolNode implements HtmlDomNode {
|
|||||||
|
|
||||||
tryCombine(sibling: HtmlDomNode): boolean {
|
tryCombine(sibling: HtmlDomNode): boolean {
|
||||||
if (!sibling
|
if (!sibling
|
||||||
|| !(sibling instanceof symbolNode)
|
|| !(sibling instanceof SymbolNode)
|
||||||
|| this.italic > 0
|
|| this.italic > 0
|
||||||
|| createClass(this.classes) !== createClass(sibling.classes)
|
|| createClass(this.classes) !== createClass(sibling.classes)
|
||||||
|| this.skew !== sibling.skew
|
|| this.skew !== sibling.skew
|
||||||
@@ -427,7 +427,7 @@ class symbolNode implements HtmlDomNode {
|
|||||||
/**
|
/**
|
||||||
* SVG nodes are used to render stretchy wide elements.
|
* SVG nodes are used to render stretchy wide elements.
|
||||||
*/
|
*/
|
||||||
class svgNode implements VirtualNode {
|
export class SvgNode implements VirtualNode {
|
||||||
children: SvgChildNode[];
|
children: SvgChildNode[];
|
||||||
attributes: {[string]: string};
|
attributes: {[string]: string};
|
||||||
|
|
||||||
@@ -476,7 +476,7 @@ class svgNode implements VirtualNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class pathNode implements VirtualNode {
|
export class PathNode implements VirtualNode {
|
||||||
pathName: string;
|
pathName: string;
|
||||||
alternate: ?string;
|
alternate: ?string;
|
||||||
|
|
||||||
@@ -507,7 +507,7 @@ class pathNode implements VirtualNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class lineNode implements VirtualNode {
|
export class LineNode implements VirtualNode {
|
||||||
attributes: {[string]: string};
|
attributes: {[string]: string};
|
||||||
|
|
||||||
constructor(attributes?: {[string]: string}) {
|
constructor(attributes?: {[string]: string}) {
|
||||||
@@ -545,8 +545,8 @@ class lineNode implements VirtualNode {
|
|||||||
|
|
||||||
export function assertSymbolDomNode(
|
export function assertSymbolDomNode(
|
||||||
group: HtmlDomNode,
|
group: HtmlDomNode,
|
||||||
): symbolNode {
|
): SymbolNode {
|
||||||
if (group instanceof symbolNode) {
|
if (group instanceof SymbolNode) {
|
||||||
return group;
|
return group;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Expected symbolNode but got ${String(group)}.`);
|
throw new Error(`Expected symbolNode but got ${String(group)}.`);
|
||||||
@@ -555,19 +555,10 @@ export function assertSymbolDomNode(
|
|||||||
|
|
||||||
export function assertSpan(
|
export function assertSpan(
|
||||||
group: HtmlDomNode,
|
group: HtmlDomNode,
|
||||||
): span<HtmlDomNode> {
|
): Span<HtmlDomNode> {
|
||||||
if (group instanceof span) {
|
if (group instanceof Span) {
|
||||||
return group;
|
return group;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Expected span<HtmlDomNode> but got ${String(group)}.`);
|
throw new Error(`Expected span<HtmlDomNode> but got ${String(group)}.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
|
||||||
span,
|
|
||||||
anchor,
|
|
||||||
symbolNode,
|
|
||||||
svgNode,
|
|
||||||
pathNode,
|
|
||||||
lineNode,
|
|
||||||
};
|
|
||||||
|
@@ -18,7 +18,7 @@ const htmlBuilder = (group, options) => {
|
|||||||
// To accomplish this, we wrap the results in a fragment, so the inner
|
// To accomplish this, we wrap the results in a fragment, so the inner
|
||||||
// elements will be able to directly interact with their neighbors. For
|
// elements will be able to directly interact with their neighbors. For
|
||||||
// example, `\color{red}{2 +} 3` has the same spacing as `2 + 3`
|
// example, `\color{red}{2 +} 3` has the same spacing as `2 + 3`
|
||||||
return new buildCommon.makeFragment(elements);
|
return buildCommon.makeFragment(elements);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mathmlBuilder = (group, options) => {
|
const mathmlBuilder = (group, options) => {
|
||||||
|
@@ -28,7 +28,7 @@ defineFunction({
|
|||||||
},
|
},
|
||||||
htmlBuilder: (group, options) => {
|
htmlBuilder: (group, options) => {
|
||||||
const elements = html.buildExpression(group.body, options, false);
|
const elements = html.buildExpression(group.body, options, false);
|
||||||
return new buildCommon.makeAnchor(group.href, [], elements, options);
|
return buildCommon.makeAnchor(group.href, [], elements, options);
|
||||||
},
|
},
|
||||||
mathmlBuilder: (group, options) => {
|
mathmlBuilder: (group, options) => {
|
||||||
const math = mml.buildExpressionRow(group.body, options);
|
const math = mml.buildExpressionRow(group.body, options);
|
||||||
|
@@ -26,7 +26,7 @@ defineFunction({
|
|||||||
options,
|
options,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
return new buildCommon.makeFragment(elements);
|
return buildCommon.makeFragment(elements);
|
||||||
},
|
},
|
||||||
mathmlBuilder: (group, options) => {
|
mathmlBuilder: (group, options) => {
|
||||||
return mml.buildExpressionRow(group.mathml, options);
|
return mml.buildExpressionRow(group.mathml, options);
|
||||||
|
@@ -41,7 +41,7 @@ defineFunction({
|
|||||||
options,
|
options,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
return new buildCommon.makeFragment(elements);
|
return buildCommon.makeFragment(elements);
|
||||||
},
|
},
|
||||||
mathmlBuilder: (group, options) => {
|
mathmlBuilder: (group, options) => {
|
||||||
const body = chooseMathStyle(group, options);
|
const body = chooseMathStyle(group, options);
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
// Limits, symbols
|
// Limits, symbols
|
||||||
import defineFunction, {ordargument} from "../defineFunction";
|
import defineFunction, {ordargument} from "../defineFunction";
|
||||||
import buildCommon from "../buildCommon";
|
import buildCommon from "../buildCommon";
|
||||||
import domTree from "../domTree";
|
import {SymbolNode} from "../domTree";
|
||||||
import * as mathMLTree from "../mathMLTree";
|
import * as mathMLTree from "../mathMLTree";
|
||||||
import utils from "../utils";
|
import utils from "../utils";
|
||||||
import Style from "../Style";
|
import Style from "../Style";
|
||||||
@@ -91,7 +91,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
|
|||||||
} else if (group.body) {
|
} else if (group.body) {
|
||||||
// If this is a list, compose that list.
|
// If this is a list, compose that list.
|
||||||
const inner = html.buildExpression(group.body, options, true);
|
const inner = html.buildExpression(group.body, options, true);
|
||||||
if (inner.length === 1 && inner[0] instanceof domTree.symbolNode) {
|
if (inner.length === 1 && inner[0] instanceof SymbolNode) {
|
||||||
base = inner[0];
|
base = inner[0];
|
||||||
base.classes[0] = "mop"; // replace old mclass
|
base.classes[0] = "mop"; // replace old mclass
|
||||||
} else {
|
} else {
|
||||||
@@ -112,7 +112,7 @@ export const htmlBuilder: HtmlBuilderSupSub<"op"> = (grp, options) => {
|
|||||||
// If content of op is a single symbol, shift it vertically.
|
// If content of op is a single symbol, shift it vertically.
|
||||||
let baseShift = 0;
|
let baseShift = 0;
|
||||||
let slant = 0;
|
let slant = 0;
|
||||||
if ((base instanceof domTree.symbolNode
|
if ((base instanceof SymbolNode
|
||||||
|| group.name === "\\oiint" || group.name === "\\oiiint")
|
|| group.name === "\\oiint" || group.name === "\\oiiint")
|
||||||
&& !group.suppressBaseShift) {
|
&& !group.suppressBaseShift) {
|
||||||
// We suppress the shift of the base of \overset and \underset. Otherwise,
|
// We suppress the shift of the base of \overset and \underset. Otherwise,
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
import defineFunction, {ordargument} from "../defineFunction";
|
import defineFunction, {ordargument} from "../defineFunction";
|
||||||
import buildCommon from "../buildCommon";
|
import buildCommon from "../buildCommon";
|
||||||
import mathMLTree from "../mathMLTree";
|
import mathMLTree from "../mathMLTree";
|
||||||
import domTree from "../domTree";
|
import {SymbolNode} from "../domTree";
|
||||||
|
|
||||||
import * as html from "../buildHTML";
|
import * as html from "../buildHTML";
|
||||||
import * as mml from "../buildMathML";
|
import * as mml from "../buildMathML";
|
||||||
@@ -46,7 +46,7 @@ defineFunction({
|
|||||||
|
|
||||||
for (let i = 0; i < expression.length; i++) {
|
for (let i = 0; i < expression.length; i++) {
|
||||||
const child = expression[i];
|
const child = expression[i];
|
||||||
if (child instanceof domTree.symbolNode) {
|
if (child instanceof SymbolNode) {
|
||||||
// Per amsopn package,
|
// Per amsopn package,
|
||||||
// change minus to hyphen and \ast to asterisk
|
// change minus to hyphen and \ast to asterisk
|
||||||
child.text = child.text.replace(/\u2212/, "-")
|
child.text = child.text.replace(/\u2212/, "-")
|
||||||
|
@@ -30,7 +30,7 @@ defineFunction({
|
|||||||
|
|
||||||
// \phantom isn't supposed to affect the elements it contains.
|
// \phantom isn't supposed to affect the elements it contains.
|
||||||
// See "color" for more details.
|
// See "color" for more details.
|
||||||
return new buildCommon.makeFragment(elements);
|
return buildCommon.makeFragment(elements);
|
||||||
},
|
},
|
||||||
mathmlBuilder: (group, options) => {
|
mathmlBuilder: (group, options) => {
|
||||||
const inner = mml.buildExpression(group.body, options);
|
const inner = mml.buildExpression(group.body, options);
|
||||||
|
@@ -5,7 +5,7 @@ import mathMLTree from "../mathMLTree";
|
|||||||
import delimiter from "../delimiter";
|
import delimiter from "../delimiter";
|
||||||
import Style from "../Style";
|
import Style from "../Style";
|
||||||
|
|
||||||
import * as tree from "../tree";
|
import {DocumentFragment} from "../tree";
|
||||||
import * as html from "../buildHTML";
|
import * as html from "../buildHTML";
|
||||||
import * as mml from "../buildMathML";
|
import * as mml from "../buildMathML";
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ defineFunction({
|
|||||||
|
|
||||||
// Some groups can return document fragments. Handle those by wrapping
|
// Some groups can return document fragments. Handle those by wrapping
|
||||||
// them in a span.
|
// them in a span.
|
||||||
if (inner instanceof tree.documentFragment) {
|
if (inner instanceof DocumentFragment) {
|
||||||
inner = buildCommon.makeSpan([], [inner], options);
|
inner = buildCommon.makeSpan([], [inner], options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import {defineFunctionBuilders} from "../defineFunction";
|
import {defineFunctionBuilders} from "../defineFunction";
|
||||||
import buildCommon from "../buildCommon";
|
import buildCommon from "../buildCommon";
|
||||||
import domTree from "../domTree";
|
import {SymbolNode} from "../domTree";
|
||||||
import mathMLTree from "../mathMLTree";
|
import mathMLTree from "../mathMLTree";
|
||||||
import utils from "../utils";
|
import utils from "../utils";
|
||||||
import Style from "../Style";
|
import Style from "../Style";
|
||||||
@@ -117,7 +117,7 @@ defineFunctionBuilders({
|
|||||||
const isOiint =
|
const isOiint =
|
||||||
group.base && group.base.type === "op" && group.base.name &&
|
group.base && group.base.type === "op" && group.base.name &&
|
||||||
(group.base.name === "\\oiint" || group.base.name === "\\oiiint");
|
(group.base.name === "\\oiint" || group.base.name === "\\oiiint");
|
||||||
if (base instanceof domTree.symbolNode || isOiint) {
|
if (base instanceof SymbolNode || isOiint) {
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
marginLeft = -base.italic + "em";
|
marginLeft = -base.italic + "em";
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import utils from "./utils";
|
import utils from "./utils";
|
||||||
import * as tree from "./tree";
|
import {DocumentFragment} from "./tree";
|
||||||
|
|
||||||
import type {VirtualNode} from "./tree";
|
import type {VirtualNode} from "./tree";
|
||||||
|
|
||||||
@@ -31,9 +31,9 @@ export interface MathDomNode extends VirtualNode {
|
|||||||
toText(): string;
|
toText(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type documentFragment = tree.documentFragment<MathDomNode>;
|
export type documentFragment = DocumentFragment<MathDomNode>;
|
||||||
export function newDocumentFragment(children: MathDomNode[]): documentFragment {
|
export function newDocumentFragment(children: MathDomNode[]): documentFragment {
|
||||||
return new tree.documentFragment(children);
|
return new DocumentFragment(children);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
* and other CSS trickery.
|
* and other CSS trickery.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import domTree from "./domTree";
|
import {LineNode, PathNode, SvgNode} from "./domTree";
|
||||||
import buildCommon from "./buildCommon";
|
import buildCommon from "./buildCommon";
|
||||||
import mathMLTree from "./mathMLTree";
|
import mathMLTree from "./mathMLTree";
|
||||||
import utils from "./utils";
|
import utils from "./utils";
|
||||||
@@ -220,8 +220,8 @@ const svgSpan = function(
|
|||||||
pathName = "tilde" + imgIndex;
|
pathName = "tilde" + imgIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const path = new domTree.pathNode(pathName);
|
const path = new PathNode(pathName);
|
||||||
const svgNode = new domTree.svgNode([path], {
|
const svgNode = new SvgNode([path], {
|
||||||
"width": "100%",
|
"width": "100%",
|
||||||
"height": height + "em",
|
"height": height + "em",
|
||||||
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
|
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
|
||||||
@@ -260,9 +260,9 @@ const svgSpan = function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < numSvgChildren; i++) {
|
for (let i = 0; i < numSvgChildren; i++) {
|
||||||
const path = new domTree.pathNode(paths[i]);
|
const path = new PathNode(paths[i]);
|
||||||
|
|
||||||
const svgNode = new domTree.svgNode([path], {
|
const svgNode = new SvgNode([path], {
|
||||||
"width": "400em",
|
"width": "400em",
|
||||||
"height": height + "em",
|
"height": height + "em",
|
||||||
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
|
"viewBox": `0 0 ${viewBoxWidth} ${viewBoxHeight}`,
|
||||||
@@ -326,7 +326,7 @@ const encloseSpan = function(
|
|||||||
|
|
||||||
const lines = [];
|
const lines = [];
|
||||||
if (/^[bx]cancel$/.test(label)) {
|
if (/^[bx]cancel$/.test(label)) {
|
||||||
lines.push(new domTree.lineNode({
|
lines.push(new LineNode({
|
||||||
"x1": "0",
|
"x1": "0",
|
||||||
"y1": "0",
|
"y1": "0",
|
||||||
"x2": "100%",
|
"x2": "100%",
|
||||||
@@ -336,7 +336,7 @@ const encloseSpan = function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (/^x?cancel$/.test(label)) {
|
if (/^x?cancel$/.test(label)) {
|
||||||
lines.push(new domTree.lineNode({
|
lines.push(new LineNode({
|
||||||
"x1": "0",
|
"x1": "0",
|
||||||
"y1": "100%",
|
"y1": "100%",
|
||||||
"x2": "100%",
|
"x2": "100%",
|
||||||
@@ -345,7 +345,7 @@ const encloseSpan = function(
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const svgNode = new domTree.svgNode(lines, {
|
const svgNode = new SvgNode(lines, {
|
||||||
"width": "100%",
|
"width": "100%",
|
||||||
"height": totalHeight + "em",
|
"height": totalHeight + "em",
|
||||||
});
|
});
|
||||||
|
@@ -18,7 +18,7 @@ export interface VirtualNode {
|
|||||||
* placed into the DOM doesn't have any representation itself. It only contains
|
* placed into the DOM doesn't have any representation itself. It only contains
|
||||||
* children and doesn't have any DOM node properties.
|
* children and doesn't have any DOM node properties.
|
||||||
*/
|
*/
|
||||||
export class documentFragment<ChildType: VirtualNode>
|
export class DocumentFragment<ChildType: VirtualNode>
|
||||||
implements HtmlDomNode, MathDomNode {
|
implements HtmlDomNode, MathDomNode {
|
||||||
children: ChildType[];
|
children: ChildType[];
|
||||||
// HtmlDomNode
|
// HtmlDomNode
|
||||||
|
@@ -31,6 +31,7 @@ const printActualErrorMessage = error => {
|
|||||||
const {message, stack} = separateMessageFromStack(error.stack);
|
const {message, stack} = separateMessageFromStack(error.stack);
|
||||||
return (
|
return (
|
||||||
'Instead, it threw:\n' +
|
'Instead, it threw:\n' +
|
||||||
|
/* eslint-disable-next-line new-cap */
|
||||||
RECEIVED_COLOR(
|
RECEIVED_COLOR(
|
||||||
` ${message}` +
|
` ${message}` +
|
||||||
formatStackTrace(
|
formatStackTrace(
|
||||||
|
Reference in New Issue
Block a user