mavon-editor
Version:
Vue markdown editor
1,379 lines (1,181 loc) • 652 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["katex"] = factory();
else
root["katex"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 63);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_slicedToArray__ = __webpack_require__(57);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_slicedToArray___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_slicedToArray__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_get_iterator__ = __webpack_require__(18);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_get_iterator___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_get_iterator__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__domTree__ = __webpack_require__(12);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__fontMetrics__ = __webpack_require__(30);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__symbols__ = __webpack_require__(28);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__utils__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__stretchy__ = __webpack_require__(13);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__units__ = __webpack_require__(19);
/* eslint no-console:0 */
/**
* This module contains general functions that can be used for building
* different kinds of domTree nodes in a consistent manner.
*/
// The following have to be loaded from Main-Italic font, using class mainit
var mainitLetters = ["\\imath", "ı", // dotless i
"\\jmath", "ȷ", // dotless j
"\\pounds", "\\mathsterling", "\\textsterling", "£"];
/**
* Looks up the given symbol in fontMetrics, after applying any symbol
* replacements defined in symbol.js
*/
var lookupSymbol = function lookupSymbol(value,
// TODO(#963): Use a union type for this.
fontFamily, mode) {
// Replace the value with its replaced value from symbol.js
if (__WEBPACK_IMPORTED_MODULE_4__symbols__["a" /* default */][mode][value] && __WEBPACK_IMPORTED_MODULE_4__symbols__["a" /* default */][mode][value].replace) {
value = __WEBPACK_IMPORTED_MODULE_4__symbols__["a" /* default */][mode][value].replace;
}
return {
value: value,
metrics: __WEBPACK_IMPORTED_MODULE_3__fontMetrics__["a" /* default */].getCharacterMetrics(value, fontFamily, mode)
};
};
/**
* Makes a symbolNode after translation via the list of symbols in symbols.js.
* Correctly pulls out metrics for the character, and optionally takes a list of
* classes to be attached to the node.
*
* TODO: make argument order closer to makeSpan
* TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
* should if present come first in `classes`.
* TODO(#953): Make `options` mandatory and always pass it in.
*/
var makeSymbol = function makeSymbol(value, fontFamily, mode, options, classes) {
var lookup = lookupSymbol(value, fontFamily, mode);
var metrics = lookup.metrics;
value = lookup.value;
var symbolNode = void 0;
if (metrics) {
var italic = metrics.italic;
if (mode === "text") {
italic = 0;
}
symbolNode = new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].symbolNode(value, metrics.height, metrics.depth, italic, metrics.skew, metrics.width, classes);
} else {
// TODO(emily): Figure out a good way to only print this in development
typeof console !== "undefined" && console.warn("No character metrics for '" + value + "' in style '" + fontFamily + "'");
symbolNode = new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].symbolNode(value, 0, 0, 0, 0, 0, classes);
}
if (options) {
symbolNode.maxFontSize = options.sizeMultiplier;
if (options.style.isTight()) {
symbolNode.classes.push("mtight");
}
var color = options.getColor();
if (color) {
symbolNode.style.color = color;
}
}
return symbolNode;
};
/**
* Makes a symbol in Main-Regular or AMS-Regular.
* Used for rel, bin, open, close, inner, and punct.
*
* TODO(#953): Make `options` mandatory and always pass it in.
*/
var mathsym = function mathsym(value, mode, options) {
var classes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
// Decide what font to render the symbol in by its entry in the symbols
// table.
// Have a special case for when the value = \ because the \ is used as a
// textord in unsupported command errors but cannot be parsed as a regular
// text ordinal and is therefore not present as a symbol in the symbols
// table for text, as well as a special case for boldsymbol because it
// can be used for bold + and -
if (options && options.fontFamily && options.fontFamily === "boldsymbol" && lookupSymbol(value, "Main-Bold", mode).metrics) {
return makeSymbol(value, "Main-Bold", mode, options, classes.concat(["mathbf"]));
} else if (value === "\\" || __WEBPACK_IMPORTED_MODULE_4__symbols__["a" /* default */][mode][value].font === "main") {
return makeSymbol(value, "Main-Regular", mode, options, classes);
} else {
return makeSymbol(value, "AMS-Regular", mode, options, classes.concat(["amsrm"]));
}
};
/**
* Makes a symbol in the default font for mathords and textords.
*/
var mathDefault = function mathDefault(value, mode, options, classes, type) {
if (type === "mathord") {
var fontLookup = mathit(value, mode, options, classes);
return makeSymbol(value, fontLookup.fontName, mode, options, classes.concat([fontLookup.fontClass]));
} else if (type === "textord") {
var font = __WEBPACK_IMPORTED_MODULE_4__symbols__["a" /* default */][mode][value] && __WEBPACK_IMPORTED_MODULE_4__symbols__["a" /* default */][mode][value].font;
if (font === "ams") {
var _fontName = retrieveTextFontName("amsrm", options.fontWeight, options.fontShape);
return makeSymbol(value, _fontName, mode, options, classes.concat("amsrm", options.fontWeight, options.fontShape));
} else {
// if (font === "main") {
var _fontName2 = retrieveTextFontName("textrm", options.fontWeight, options.fontShape);
return makeSymbol(value, _fontName2, mode, options, classes.concat(options.fontWeight, options.fontShape));
}
} else {
throw new Error("unexpected type: " + type + " in mathDefault");
}
};
/**
* Determines which of the two font names (Main-Italic and Math-Italic) and
* corresponding style tags (mainit or mathit) to use for font "mathit",
* depending on the symbol. Use this function instead of fontMap for font
* "mathit".
*/
var mathit = function mathit(value, mode, options, classes) {
if (/[0-9]/.test(value.charAt(0)) ||
// glyphs for \imath and \jmath do not exist in Math-Italic so we
// need to use Main-Italic instead
__WEBPACK_IMPORTED_MODULE_5__utils__["a" /* default */].contains(mainitLetters, value)) {
return {
fontName: "Main-Italic",
fontClass: "mainit"
};
} else {
return {
fontName: "Math-Italic",
fontClass: "mathit"
};
}
};
/**
* Determines which of the two font names (Main-Bold and Math-BoldItalic) and
* corresponding style tags (mathbf or boldsymbol) to use for font "boldsymbol",
* depending on the symbol. Use this function instead of fontMap for font
* "boldsymbol".
*/
var boldsymbol = function boldsymbol(value, mode, options, classes) {
if (lookupSymbol(value, "Math-BoldItalic", mode).metrics) {
return {
fontName: "Math-BoldItalic",
fontClass: "boldsymbol"
};
} else {
// Some glyphs do not exist in Math-BoldItalic so we need to use
// Main-Bold instead.
return {
fontName: "Main-Bold",
fontClass: "mathbf"
};
}
};
/**
* Makes either a mathord or textord in the correct font and color.
*/
var makeOrd = function makeOrd(group, options, type) {
var mode = group.mode;
var value = group.value;
var classes = ["mord"];
var fontFamily = options.fontFamily;
if (fontFamily) {
var _fontName3 = void 0;
var fontClasses = void 0;
if (fontFamily === "boldsymbol") {
var fontData = boldsymbol(value, mode, options, classes);
_fontName3 = fontData.fontName;
fontClasses = [fontData.fontClass];
} else if (fontFamily === "mathit" || __WEBPACK_IMPORTED_MODULE_5__utils__["a" /* default */].contains(mainitLetters, value)) {
var _fontData = mathit(value, mode, options, classes);
_fontName3 = _fontData.fontName;
fontClasses = [_fontData.fontClass];
} else if (fontFamily.indexOf("math") !== -1 || mode === "math") {
// To support old font functions (i.e. \rm \sf etc.) or math mode.
_fontName3 = fontMap[fontFamily].fontName;
fontClasses = [fontFamily];
} else {
_fontName3 = retrieveTextFontName(fontFamily, options.fontWeight, options.fontShape);
fontClasses = [fontFamily, options.fontWeight, options.fontShape];
}
if (lookupSymbol(value, _fontName3, mode).metrics) {
return makeSymbol(value, _fontName3, mode, options, classes.concat(fontClasses));
} else {
return mathDefault(value, mode, options, classes, type);
}
} else {
return mathDefault(value, mode, options, classes, type);
}
};
/**
* Combine as many characters as possible in the given array of characters
* via their tryCombine method.
*/
var tryCombineChars = function tryCombineChars(chars) {
for (var i = 0; i < chars.length - 1; i++) {
if (chars[i].tryCombine(chars[i + 1])) {
chars.splice(i + 1, 1);
i--;
}
}
return chars;
};
/**
* Calculate the height, depth, and maxFontSize of an element based on its
* children.
*/
var sizeElementFromChildren = function sizeElementFromChildren(elem) {
var height = 0;
var depth = 0;
var maxFontSize = 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_get_iterator___default()(elem.children), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var child = _step.value;
if (child.height > height) {
height = child.height;
}
if (child.depth > depth) {
depth = child.depth;
}
if (child.maxFontSize > maxFontSize) {
maxFontSize = child.maxFontSize;
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
elem.height = height;
elem.depth = depth;
elem.maxFontSize = maxFontSize;
};
/**
* Makes a span with the given list of classes, list of children, and options.
*
* TODO(#953): Ensure that `options` is always provided (currently some call
* sites don't pass it) and make the type below mandatory.
* TODO: add a separate argument for math class (e.g. `mop`, `mbin`), which
* should if present come first in `classes`.
*/
var makeSpan = function makeSpan(classes, children, options, style) {
var span = new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].span(classes, children, options, style);
sizeElementFromChildren(span);
return span;
};
var makeLineSpan = function makeLineSpan(className, options) {
// Return a span with an SVG image of a horizontal line. The SVG path
// fills the middle fifth of the span. We want an extra tall span
// because Chrome will sometimes not display a span that is 0.04em tall.
var lineHeight = options.fontMetrics().defaultRuleThickness;
var line = __WEBPACK_IMPORTED_MODULE_6__stretchy__["a" /* default */].ruleSpan(className, lineHeight, options);
line.height = lineHeight;
line.style.height = 5 * line.height + "em";
line.maxFontSize = 1.0;
return line;
};
/**
* Makes an anchor with the given href, list of classes, list of children,
* and options.
*/
var makeAnchor = function makeAnchor(href, classes, children, options) {
var anchor = new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].anchor(href, classes, children, options);
sizeElementFromChildren(anchor);
return anchor;
};
/**
* Makes a document fragment with the given list of children.
*/
var makeFragment = function makeFragment(children) {
var fragment = new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].documentFragment(children);
sizeElementFromChildren(fragment);
return fragment;
};
// These are exact object types to catch typos in the names of the optional fields.
// A list of child or kern nodes to be stacked on top of each other (i.e. the
// first element will be at the bottom, and the last at the top).
// Computes the updated `children` list and the overall depth.
//
// This helper function for makeVList makes it easier to enforce type safety by
// allowing early exits (returns) in the logic.
var getVListChildrenAndDepth = function getVListChildrenAndDepth(params) {
if (params.positionType === "individualShift") {
var oldChildren = params.children;
var _children = [oldChildren[0]];
// Add in kerns to the list of params.children to get each element to be
// shifted to the correct specified shift
var _depth = -oldChildren[0].shift - oldChildren[0].elem.depth;
var currPos = _depth;
for (var i = 1; i < oldChildren.length; i++) {
var diff = -oldChildren[i].shift - currPos - oldChildren[i].elem.depth;
var _size = diff - (oldChildren[i - 1].elem.height + oldChildren[i - 1].elem.depth);
currPos = currPos + diff;
_children.push({ type: "kern", size: _size });
_children.push(oldChildren[i]);
}
return { children: _children, depth: _depth };
}
var depth = void 0;
if (params.positionType === "top") {
// We always start at the bottom, so calculate the bottom by adding up
// all the sizes
var bottom = params.positionData;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_get_iterator___default()(params.children), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var child = _step2.value;
bottom -= child.type === "kern" ? child.size : child.elem.height + child.elem.depth;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
depth = bottom;
} else if (params.positionType === "bottom") {
depth = -params.positionData;
} else {
var firstChild = params.children[0];
if (firstChild.type !== "elem") {
throw new Error('First child must have type "elem".');
}
if (params.positionType === "shift") {
depth = -firstChild.elem.depth - params.positionData;
} else if (params.positionType === "firstBaseline") {
depth = -firstChild.elem.depth;
} else {
throw new Error("Invalid positionType " + params.positionType + ".");
}
}
return { children: params.children, depth: depth };
};
/**
* Makes a vertical list by stacking elements and kerns on top of each other.
* Allows for many different ways of specifying the positioning method.
*
* See VListParam documentation above.
*/
var makeVList = function makeVList(params, options) {
var _getVListChildrenAndD = getVListChildrenAndDepth(params),
children = _getVListChildrenAndD.children,
depth = _getVListChildrenAndD.depth;
// Create a strut that is taller than any list item. The strut is added to
// each item, where it will determine the item's baseline. Since it has
// `overflow:hidden`, the strut's top edge will sit on the item's line box's
// top edge and the strut's bottom edge will sit on the item's baseline,
// with no additional line-height spacing. This allows the item baseline to
// be positioned precisely without worrying about font ascent and
// line-height.
var pstrutSize = 0;
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_get_iterator___default()(children), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var child = _step3.value;
if (child.type === "elem") {
var _elem = child.elem;
pstrutSize = Math.max(pstrutSize, _elem.maxFontSize, _elem.height);
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
pstrutSize += 2;
var pstrut = makeSpan(["pstrut"], []);
pstrut.style.height = pstrutSize + "em";
// Create a new list of actual children at the correct offsets
var realChildren = [];
var minPos = depth;
var maxPos = depth;
var currPos = depth;
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
try {
for (var _iterator4 = __WEBPACK_IMPORTED_MODULE_1_babel_runtime_core_js_get_iterator___default()(children), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var _child = _step4.value;
if (_child.type === "kern") {
currPos += _child.size;
} else {
var _elem2 = _child.elem;
var classes = _child.wrapperClasses || [];
var style = _child.wrapperStyle || {};
var childWrap = makeSpan(classes, [pstrut, _elem2], undefined, style);
childWrap.style.top = -pstrutSize - currPos - _elem2.depth + "em";
if (_child.marginLeft) {
childWrap.style.marginLeft = _child.marginLeft;
}
if (_child.marginRight) {
childWrap.style.marginRight = _child.marginRight;
}
realChildren.push(childWrap);
currPos += _elem2.height + _elem2.depth;
}
minPos = Math.min(minPos, currPos);
maxPos = Math.max(maxPos, currPos);
}
// The vlist contents go in a table-cell with `vertical-align:bottom`.
// This cell's bottom edge will determine the containing table's baseline
// without overly expanding the containing line-box.
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
}
var vlist = makeSpan(["vlist"], realChildren);
vlist.style.height = maxPos + "em";
// A second row is used if necessary to represent the vlist's depth.
var rows = void 0;
if (minPos < 0) {
var depthStrut = makeSpan(["vlist"], []);
depthStrut.style.height = -minPos + "em";
// Safari wants the first row to have inline content; otherwise it
// puts the bottom of the *second* row on the baseline.
var topStrut = makeSpan(["vlist-s"], [new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].symbolNode("\u200B")]);
rows = [makeSpan(["vlist-r"], [vlist, topStrut]), makeSpan(["vlist-r"], [depthStrut])];
} else {
rows = [makeSpan(["vlist-r"], [vlist])];
}
var vtable = makeSpan(["vlist-t"], rows);
if (rows.length === 2) {
vtable.classes.push("vlist-t2");
}
vtable.height = maxPos;
vtable.depth = -minPos;
return vtable;
};
// Converts verb group into body string, dealing with \verb* form
var makeVerb = function makeVerb(group, options) {
// TODO(#892): Make ParseNode type-safe and confirm `group.type` to guarantee
// that `group.value.body` is of type string.
var text = group.value.body;
if (group.value.star) {
text = text.replace(/ /g, "\u2423"); // Open Box
} else {
text = text.replace(/ /g, '\xA0'); // No-Break Space
// (so that, in particular, spaces don't coalesce)
}
return text;
};
// Glue is a concept from TeX which is a flexible space between elements in
// either a vertical or horizontal list. In KaTeX, at least for now, it's
// static space between elements in a horizontal layout.
var makeGlue = function makeGlue(measurement, options) {
// Make an empty span for the rule
var rule = makeSpan(["mord", "rule"], [], options);
var size = Object(__WEBPACK_IMPORTED_MODULE_7__units__["a" /* calculateSize */])(measurement, options);
rule.style.marginRight = size + "em";
return rule;
};
// Takes an Options object, and returns the appropriate fontLookup
var retrieveTextFontName = function retrieveTextFontName(fontFamily, fontWeight, fontShape) {
var baseFontName = retrieveBaseFontName(fontFamily);
var fontStylesName = retrieveFontStylesName(fontWeight, fontShape);
return baseFontName + "-" + fontStylesName;
};
var retrieveBaseFontName = function retrieveBaseFontName(font) {
var baseFontName = "";
switch (font) {
case "amsrm":
baseFontName = "AMS";
break;
case "textrm":
baseFontName = "Main";
break;
case "textsf":
baseFontName = "SansSerif";
break;
case "texttt":
baseFontName = "Typewriter";
break;
default:
throw new Error("Invalid font provided: " + font);
}
return baseFontName;
};
var retrieveFontStylesName = function retrieveFontStylesName(fontWeight, fontShape) {
var fontStylesName = '';
if (fontWeight === "textbf") {
fontStylesName += "Bold";
}
if (fontShape === "textit") {
fontStylesName += "Italic";
}
return fontStylesName || "Regular";
};
// A map of spacing functions to their attributes, like size and corresponding
// CSS class
var spacingFunctions = {
"\\qquad": {
size: "2em",
className: "qquad"
},
"\\quad": {
size: "1em",
className: "quad"
},
"\\enspace": {
size: "0.5em",
className: "enspace"
},
"\\;": {
size: "0.277778em",
className: "thickspace"
},
"\\:": {
size: "0.22222em",
className: "mediumspace"
},
"\\,": {
size: "0.16667em",
className: "thinspace"
},
"\\!": {
size: "-0.16667em",
className: "negativethinspace"
}
};
/**
* Maps TeX font commands to objects containing:
* - variant: string used for "mathvariant" attribute in buildMathML.js
* - fontName: the "style" parameter to fontMetrics.getCharacterMetrics
*/
// A map between tex font commands an MathML mathvariant attribute values
var fontMap = {
// styles
"mathbf": {
variant: "bold",
fontName: "Main-Bold"
},
"mathrm": {
variant: "normal",
fontName: "Main-Regular"
},
"textit": {
variant: "italic",
fontName: "Main-Italic"
},
// "mathit" and "boldsymbol" are missing because they require the use of two
// fonts: Main-Italic and Math-Italic for "mathit", and Math-BoldItalic and
// Main-Bold for "boldsymbol". This is handled by a special case in makeOrd
// which ends up calling mathit and boldsymbol.
// families
"mathbb": {
variant: "double-struck",
fontName: "AMS-Regular"
},
"mathcal": {
variant: "script",
fontName: "Caligraphic-Regular"
},
"mathfrak": {
variant: "fraktur",
fontName: "Fraktur-Regular"
},
"mathscr": {
variant: "script",
fontName: "Script-Regular"
},
"mathsf": {
variant: "sans-serif",
fontName: "SansSerif-Regular"
},
"mathtt": {
variant: "monospace",
fontName: "Typewriter-Regular"
}
};
var svgData = {
// path, width, height
vec: ["vec", 0.471, 0.714] // values from the font glyph
};
var staticSvg = function staticSvg(value, options) {
// Create a span with inline SVG for the element.
var _svgData$value = __WEBPACK_IMPORTED_MODULE_0_babel_runtime_helpers_slicedToArray___default()(svgData[value], 3),
pathName = _svgData$value[0],
width = _svgData$value[1],
height = _svgData$value[2];
var path = new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].pathNode(pathName);
var svgNode = new __WEBPACK_IMPORTED_MODULE_2__domTree__["a" /* default */].svgNode([path], {
"width": width + "em",
"height": height + "em",
// Override CSS rule `.katex svg { width: 100% }`
"style": "width:" + width + "em",
"viewBox": "0 0 " + 1000 * width + " " + 1000 * height,
"preserveAspectRatio": "xMinYMin"
});
var span = makeSpan(["overlay"], [svgNode], options);
span.height = height;
span.style.height = height + "em";
span.style.width = width + "em";
return span;
};
/* harmony default export */ __webpack_exports__["a"] = ({
fontMap: fontMap,
makeSymbol: makeSymbol,
mathsym: mathsym,
makeSpan: makeSpan,
makeLineSpan: makeLineSpan,
makeAnchor: makeAnchor,
makeFragment: makeFragment,
makeVList: makeVList,
makeOrd: makeOrd,
makeVerb: makeVerb,
makeGlue: makeGlue,
staticSvg: staticSvg,
svgData: svgData,
tryCombineChars: tryCombineChars,
spacingFunctions: spacingFunctions
});
/***/ }),
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_get_iterator__ = __webpack_require__(18);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_get_iterator___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_get_iterator__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_babel_runtime_helpers_classCallCheck__ = __webpack_require__(7);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_babel_runtime_helpers_classCallCheck___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_babel_runtime_helpers_classCallCheck__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_babel_runtime_helpers_createClass__ = __webpack_require__(10);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2_babel_runtime_helpers_createClass___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_2_babel_runtime_helpers_createClass__);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__utils__ = __webpack_require__(5);
/**
* These objects store data about MathML nodes. This is the MathML equivalent
* of the types in domTree.js. Since MathML handles its own rendering, and
* since we're mainly using MathML to improve accessibility, we don't manage
* any of the styling state that the plain DOM nodes do.
*
* The `toNode` and `toMarkup` functions work simlarly to how they do in
* domTree.js, creating namespaced DOM nodes and HTML text markup respectively.
*/
/**
* MathML node types used in KaTeX. For a complete list of MathML nodes, see
* https://developer.mozilla.org/en-US/docs/Web/MathML/Element.
*/
/**
* This node represents a general purpose MathML node of any type. The
* constructor requires the type of node to create (for example, `"mo"` or
* `"mspace"`, corresponding to `<mo>` and `<mspace>` tags).
*/
var MathNode = function () {
function MathNode(type, children) {
__WEBPACK_IMPORTED_MODULE_1_babel_runtime_helpers_classCallCheck___default()(this, MathNode);
this.type = type;
this.attributes = {};
this.children = children || [];
}
/**
* Sets an attribute on a MathML node. MathML depends on attributes to convey a
* semantic content, so this is used heavily.
*/
__WEBPACK_IMPORTED_MODULE_2_babel_runtime_helpers_createClass___default()(MathNode, [{
key: "setAttribute",
value: function setAttribute(name, value) {
this.attributes[name] = value;
}
/**
* Converts the math node into a MathML-namespaced DOM element.
*/
}, {
key: "toNode",
value: function toNode() {
var node = document.createElementNS("http://www.w3.org/1998/Math/MathML", this.type);
for (var attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
node.setAttribute(attr, this.attributes[attr]);
}
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = __WEBPACK_IMPORTED_MODULE_0_babel_runtime_core_js_get_iterator___default()(this.children), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var child = _step.value;
node.appendChild(child.toNode());
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return node;
}
/**
* Converts the math node into an HTML markup string.
*/
}, {
key: "toMarkup",
value: function toMarkup() {
var markup = "<" + this.type;
// Add the attributes
for (var attr in this.attributes) {
if (Object.prototype.hasOwnProperty.call(this.attributes, attr)) {
markup += " " + attr + "=\"";
markup += __WEBPACK_IMPORTED_MODULE_3__utils__["a" /* default */].escape(this.attributes[attr]);
markup += "\"";
}
}
markup += ">";
for (var i = 0; i < this.children.length; i++) {
markup += this.children[i].toMarkup();
}
markup += "</" + this.type + ">";
return markup;
}
/**
* Converts the math node into a string, similar to innerText.
*/
}, {
key: "toText",
value: function toText() {
if (this.type === "mspace") {
if (this.attributes.width === "0.16667em") {
return "\u2006";
} else {
// TODO: Use other space characters for different widths.
// https://github.com/Khan/KaTeX/issues/1036
return " ";
}
}
return this.children.map(function (child) {
return child.toText();
}).join("");
}
}]);
return MathNode;
}();
/**
* This node represents a piece of text.
*/
var TextNode = function () {
function TextNode(text) {
__WEBPACK_IMPORTED_MODULE_1_babel_runtime_helpers_classCallCheck___default()(this, TextNode);
this.text = text;
}
/**
* Converts the text node into a DOM text node.
*/
__WEBPACK_IMPORTED_MODULE_2_babel_runtime_helpers_createClass___default()(TextNode, [{
key: "toNode",
value: function toNode() {
return document.createTextNode(this.text);
}
/**
* Converts the text node into HTML markup (which is just the text itself).
*/
}, {
key: "toMarkup",
value: function toMarkup() {
return __WEBPACK_IMPORTED_MODULE_3__utils__["a" /* default */].escape(this.text);
}
/**
* Converts the text node into a string (which is just the text iteself).
*/
}, {
key: "toText",
value: function toText() {
return this.text;
}
}]);
return TextNode;
}();
/* harmony default export */ __webpack_exports__["a"] = ({
MathNode: MathNode,
TextNode: TextNode
});
/***/ }),
/* 2 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "e", function() { return makeText; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "d", function() { return groupTypes; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return buildExpression; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return buildGroup; });
/* harmony export (immutable) */ __webpack_exports__["c"] = buildMathML;
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__buildCommon__ = __webpack_require__(0);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__fontMetrics__ = __webpack_require__(30);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__mathMLTree__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__ParseError__ = __webpack_require__(6);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__Style__ = __webpack_require__(9);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__symbols__ = __webpack_require__(28);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__utils__ = __webpack_require__(5);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__stretchy__ = __webpack_require__(13);
/**
* WARNING: New methods on groupTypes should be added to src/functions.
*
* This file converts a parse tree into a cooresponding MathML tree. The main
* entry point is the `buildMathML` function, which takes a parse tree from the
* parser.
*/
/**
* Takes a symbol and converts it into a MathML text node after performing
* optional replacement from symbols.js.
*/
var makeText = function makeText(text, mode) {
if (__WEBPACK_IMPORTED_MODULE_5__symbols__["a" /* default */][mode][text] && __WEBPACK_IMPORTED_MODULE_5__symbols__["a" /* default */][mode][text].replace) {
text = __WEBPACK_IMPORTED_MODULE_5__symbols__["a" /* default */][mode][text].replace;
}
return new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].TextNode(text);
};
/**
* Returns the math variant as a string or null if none is required.
*/
var getVariant = function getVariant(group, options) {
var font = options.fontFamily;
if (!font) {
return null;
}
var mode = group.mode;
if (font === "mathit") {
return "italic";
} else if (font === "boldsymbol") {
return "bold-italic";
}
var value = group.value;
if (__WEBPACK_IMPORTED_MODULE_6__utils__["a" /* default */].contains(["\\imath", "\\jmath"], value)) {
return null;
}
if (__WEBPACK_IMPORTED_MODULE_5__symbols__["a" /* default */][mode][value] && __WEBPACK_IMPORTED_MODULE_5__symbols__["a" /* default */][mode][value].replace) {
value = __WEBPACK_IMPORTED_MODULE_5__symbols__["a" /* default */][mode][value].replace;
}
var fontName = __WEBPACK_IMPORTED_MODULE_0__buildCommon__["a" /* default */].fontMap[font].fontName;
if (__WEBPACK_IMPORTED_MODULE_1__fontMetrics__["a" /* default */].getCharacterMetrics(value, fontName, mode)) {
return __WEBPACK_IMPORTED_MODULE_0__buildCommon__["a" /* default */].fontMap[font].variant;
}
return null;
};
/**
* Functions for handling the different types of groups found in the parse
* tree. Each function should take a parse group and return a MathML node.
*/
var groupTypes = {};
var defaultVariant = {
"mi": "italic",
"mn": "normal",
"mtext": "normal"
};
groupTypes.mathord = function (group, options) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mi", [makeText(group.value, group.mode)]);
var variant = getVariant(group, options) || "italic";
if (variant !== defaultVariant[node.type]) {
node.setAttribute("mathvariant", variant);
}
return node;
};
groupTypes.textord = function (group, options) {
var text = makeText(group.value, group.mode);
var variant = getVariant(group, options) || "normal";
var node = void 0;
if (group.mode === 'text') {
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mtext", [text]);
} else if (/[0-9]/.test(group.value)) {
// TODO(kevinb) merge adjacent <mn> nodes
// do it as a post processing step
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mn", [text]);
} else if (group.value === "\\prime") {
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mo", [text]);
} else {
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mi", [text]);
}
if (variant !== defaultVariant[node.type]) {
node.setAttribute("mathvariant", variant);
}
return node;
};
groupTypes.bin = function (group, options) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mo", [makeText(group.value, group.mode)]);
var variant = getVariant(group, options);
if (variant === "bold-italic") {
node.setAttribute("mathvariant", variant);
}
return node;
};
groupTypes.rel = function (group) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mo", [makeText(group.value, group.mode)]);
return node;
};
groupTypes.open = function (group) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mo", [makeText(group.value, group.mode)]);
return node;
};
groupTypes.close = function (group) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mo", [makeText(group.value, group.mode)]);
return node;
};
groupTypes.inner = function (group) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mo", [makeText(group.value, group.mode)]);
return node;
};
groupTypes.punct = function (group) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mo", [makeText(group.value, group.mode)]);
node.setAttribute("separator", "true");
return node;
};
groupTypes.ordgroup = function (group, options) {
var inner = buildExpression(group.value, options);
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mrow", inner);
return node;
};
groupTypes.supsub = function (group, options) {
// Is the inner group a relevant horizonal brace?
var isBrace = false;
var isOver = void 0;
var isSup = void 0;
if (group.value.base) {
if (group.value.base.value.type === "horizBrace") {
isSup = group.value.sup ? true : false;
if (isSup === group.value.base.value.isOver) {
isBrace = true;
isOver = group.value.base.value.isOver;
}
}
}
var removeUnnecessaryRow = true;
var children = [buildGroup(group.value.base, options, removeUnnecessaryRow)];
if (group.value.sub) {
children.push(buildGroup(group.value.sub, options, removeUnnecessaryRow));
}
if (group.value.sup) {
children.push(buildGroup(group.value.sup, options, removeUnnecessaryRow));
}
var nodeType = void 0;
if (isBrace) {
nodeType = isOver ? "mover" : "munder";
} else if (!group.value.sub) {
var base = group.value.base;
if (base && base.value.limits && options.style === __WEBPACK_IMPORTED_MODULE_4__Style__["a" /* default */].DISPLAY) {
nodeType = "mover";
} else {
nodeType = "msup";
}
} else if (!group.value.sup) {
var _base = group.value.base;
if (_base && _base.value.limits && options.style === __WEBPACK_IMPORTED_MODULE_4__Style__["a" /* default */].DISPLAY) {
nodeType = "munder";
} else {
nodeType = "msub";
}
} else {
var _base2 = group.value.base;
if (_base2 && _base2.value.limits && options.style === __WEBPACK_IMPORTED_MODULE_4__Style__["a" /* default */].DISPLAY) {
nodeType = "munderover";
} else {
nodeType = "msubsup";
}
}
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode(nodeType, children);
return node;
};
groupTypes.spacing = function (group) {
var node = void 0;
if (group.value === "\\ " || group.value === "\\space" || group.value === " " || group.value === "~") {
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mtext", [new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].TextNode("\xA0")]);
} else {
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mspace");
node.setAttribute("width", __WEBPACK_IMPORTED_MODULE_0__buildCommon__["a" /* default */].spacingFunctions[group.value].size);
}
return node;
};
groupTypes.horizBrace = function (group, options) {
var accentNode = __WEBPACK_IMPORTED_MODULE_7__stretchy__["a" /* default */].mathMLnode(group.value.label);
return new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode(group.value.isOver ? "mover" : "munder", [buildGroup(group.value.base, options), accentNode]);
};
groupTypes.xArrow = function (group, options) {
var arrowNode = __WEBPACK_IMPORTED_MODULE_7__stretchy__["a" /* default */].mathMLnode(group.value.label);
var node = void 0;
var lowerNode = void 0;
if (group.value.body) {
var upperNode = buildGroup(group.value.body, options);
if (group.value.below) {
lowerNode = buildGroup(group.value.below, options);
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("munderover", [arrowNode, lowerNode, upperNode]);
} else {
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mover", [arrowNode, upperNode]);
}
} else if (group.value.below) {
lowerNode = buildGroup(group.value.below, options);
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("munder", [arrowNode, lowerNode]);
} else {
node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mover", [arrowNode]);
}
return node;
};
groupTypes.mclass = function (group, options) {
var inner = buildExpression(group.value.value, options);
return new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mstyle", inner);
};
groupTypes.raisebox = function (group, options) {
var node = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mpadded", [buildGroup(group.value.body, options)]);
var dy = group.value.dy.value.number + group.value.dy.value.unit;
node.setAttribute("voffset", dy);
return node;
};
/**
* Takes a list of nodes, builds them, and returns a list of the generated
* MathML nodes. A little simpler than the HTML version because we don't do any
* previous-node handling.
*/
var buildExpression = function buildExpression(expression, options) {
var groups = [];
for (var i = 0; i < expression.length; i++) {
var group = expression[i];
groups.push(buildGroup(group, options));
}
// TODO(kevinb): combine \\not with mrels and mords
return groups;
};
/**
* Takes a group from the parser and calls the appropriate groupTypes function
* on it to produce a MathML node.
*/
var buildGroup = function buildGroup(group, options) {
var removeUnnecessaryRow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (!group) {
return new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mrow");
}
if (groupTypes[group.type]) {
// Call the groupTypes function
var result = groupTypes[group.type](group, options);
if (removeUnnecessaryRow) {
if (result.type === "mrow" && result.children.length === 1) {
return result.children[0];
}
}
return result;
} else {
throw new __WEBPACK_IMPORTED_MODULE_3__ParseError__["a" /* default */]("Got group of unknown type: '" + group.type + "'");
}
};
/**
* Takes a full parse tree and settings and builds a MathML representation of
* it. In particular, we put the elements from building the parse tree into a
* <semantics> tag so we can also include that TeX source as an annotation.
*
* Note that we actually return a domTree element with a `<math>` inside it so
* we can do appropriate styling.
*/
function buildMathML(tree, texExpression, options) {
var expression = buildExpression(tree, options);
// Wrap up the expression in an mrow so it is presented in the semantics
// tag correctly.
var wrapper = new __WEBPACK_IMPORTED_MODULE_2__mathMLTree__["a" /* default */].MathNode("mrow", expression);
// Build a TeX annotation of the source
var a