site/node_modules/mathjax-full/js/input/mathml/mml3/mml3.js

133 lines
30 KiB
JavaScript
Raw Normal View History

2024-10-14 06:09:33 +00:00
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Mml3Handler = exports.Mml3 = void 0;
var mml3_node_js_1 = require("./mml3-node.js");
var Mml3 = (function () {
function Mml3(document) {
if (typeof XSLTProcessor === 'undefined') {
this.transform = (0, mml3_node_js_1.createTransform)();
}
else {
var processor_1 = new XSLTProcessor();
var parsed = document.adaptor.parse(Mml3.XSLT, 'text/xml');
processor_1.importStylesheet(parsed);
this.transform = function (node) {
var adaptor = document.adaptor;
var div = adaptor.node('div', {}, [adaptor.clone(node)]);
var mml = processor_1.transformToDocument(div);
return adaptor.tags(mml, 'math')[0];
};
}
}
Mml3.prototype.mmlFilter = function (args) {
if (args.document.options.enableMml3) {
args.data = this.transform(args.data, args.document);
}
};
return Mml3;
}());
exports.Mml3 = Mml3;
function Mml3Handler(handler) {
var _a;
handler.documentClass = (_a = (function (_super) {
__extends(class_1, _super);
function class_1() {
var e_1, _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
try {
for (var _b = __values(_this.inputJax || []), _c = _b.next(); !_c.done; _c = _b.next()) {
var jax = _c.value;
if (jax.name === 'MathML') {
if (!jax.options._mml3) {
var mml3 = new Mml3(_this);
jax.mmlFilters.add(mml3.mmlFilter.bind(mml3));
jax.options._mml3 = true;
}
break;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
return _this;
}
return class_1;
}(handler.documentClass)),
_a.OPTIONS = __assign(__assign({}, handler.documentClass.OPTIONS), { enableMml3: true }),
_a);
return handler;
}
exports.Mml3Handler = Mml3Handler;
Mml3.XSLT = "\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n\t\txmlns:m=\"http://www.w3.org/1998/Math/MathML\"\n\t\txmlns:c=\"http://exslt.org/common\"\n\t\texclude-result-prefixes=\"m c\">\n<xsl:output indent=\"yes\" omit-xml-declaration=\"yes\"/>\n<xsl:output indent=\"yes\" omit-xml-declaration=\"yes\"/>\n<xsl:template match=\"*\">\n <xsl:copy>\n <xsl:copy-of select=\"@*\"/>\n <xsl:apply-templates/>\n </xsl:copy>\n</xsl:template>\n<xsl:template match=\"m:*[@dir='rtl']\" priority=\"10\">\n <xsl:apply-templates mode=\"rtl\" select=\".\"/>\n</xsl:template>\n<xsl:template match=\"@*\" mode=\"rtl\">\n <xsl:copy-of select=\".\"/>\n <xsl:attribute name=\"dir\">ltr</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"*\" mode=\"rtl\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*\" mode=\"rtl\"/>\n <xsl:for-each select=\"node()\">\n <xsl:sort data-type=\"number\" order=\"descending\" select=\"position()\"/>\n <xsl:text> </xsl:text>\n <xsl:apply-templates mode=\"rtl\" select=\".\"/>\n </xsl:for-each>\n </xsl:copy>\n</xsl:template>\n<xsl:template match=\"@open\" mode=\"rtl\">\n <xsl:attribute name=\"close\"><xsl:value-of select=\".\"/></xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@open[.='(']\" mode=\"rtl\">\n <xsl:attribute name=\"close\">)</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@open[.=')']\" mode=\"rtl\">\n <xsl:attribute name=\"close\">(</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@open[.='[']\" mode=\"rtl\">\n <xsl:attribute name=\"close\">]</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@open[.=']']\" mode=\"rtl\">\n <xsl:attribute name=\"close\">[</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@open[.='{']\" mode=\"rtl\">\n <xsl:attribute name=\"close\">}</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@open[.='}']\" mode=\"rtl\">\n <xsl:attribute name=\"close\">{</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@close\" mode=\"rtl\">\n <xsl:attribute name=\"open\"><xsl:value-of select=\".\"/></xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@close[.='(']\" mode=\"rtl\">\n <xsl:attribute name=\"open\">)</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@close[.=')']\" mode=\"rtl\">\n <xsl:attribute name=\"open\">(</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@close[.='[']\" mode=\"rtl\">\n <xsl:attribute name=\"open\">]</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@close[.=']']\" mode=\"rtl\">\n <xsl:attribute name=\"open\">[</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@close[.='{']\" mode=\"rtl\">\n <xsl:attribute name=\"open\">}</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"@close[.='}']\" mode=\"rtl\">\n <xsl:attribute name=\"open\">{</xsl:attribute>\n</xsl:template>\n<xsl:template match=\"m:mfrac[@bevelled='true']\" mode=\"rtl\">\n <m:mrow>\n <m:msub><m:mi></m:mi><xsl:apply-templates select=\"*[2]\" mode=\"rtl\"/></m:msub>\n <m:mo>&#x5c;</m:mo>\n <m:msup><m:mi></m:mi><xsl:apply-templates select=\"*[1]\" mode=\"rtl\"/></m:msup>\n </m:mrow>\n</xsl:template>\n<xsl:template match=\"m:mfrac\" mode=\"rtl\">\n <xsl:copy>\n <xsl:apply-templates mode=\"rtl\" select=\"@*|*\"/>\n </xsl:copy>\n</xsl:template>\n<xsl:template match=\"m:mroot\" mode=\"rtl\">\n <m:msup>\n <m:menclose notation=\"top right\">\n <xsl:apply-templates mode=\"rtl\" select=\"@*|*[1]\"/>\n </m:menclose>\n <xsl:apply-templates mode=\"rtl\" select=\"*[2]\"/>\n </m:msup>\n</xsl:template>\n<xsl:template match=\"m:msqrt\" mode=\"rtl\">\n <m:menclose notation=\"top right\">\n <xsl:apply-templates mode=\"rtl\" select=\"@*|*[1]\"/>\n </m:menclose>\n</xsl:template>\n<xsl:template match=\"m:mtable|m:munder|m:mover|m:munderover\" mode=\"rtl\" priority=\"2\">\n <xsl:copy>\n <xsl:apply-templates select=\"@*\" mode=\"rtl\"/>\n <xsl:apply-templates mode=\"rtl\">\n </xsl:apply-templates>\n </xsl:copy>\n</xsl:template>\n<xsl:template match=\"m:msup\" mode=\"rtl\" priority=\"2\">\n <m:mmultiscripts>\n <xsl:apply-templates select=\"*[1]\" mode=\"rtl\"/>\n <m:mprescripts/>\n <m:
//# sourceMappingURL=mml3.js.map