site/node_modules/mathjax-full/js/input/tex/NodeUtil.js

220 lines
7.4 KiB
JavaScript
Raw Permalink Normal View History

2024-10-14 06:09:33 +00:00
"use strict";
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.");
};
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));
};
Object.defineProperty(exports, "__esModule", { value: true });
var MmlNode_js_1 = require("../../core/MmlTree/MmlNode.js");
var mo_js_1 = require("../../core/MmlTree/MmlNodes/mo.js");
var NodeUtil;
(function (NodeUtil) {
var attrs = new Map([
['autoOP', true],
['fnOP', true],
['movesupsub', true],
['subsupOK', true],
['texprimestyle', true],
['useHeight', true],
['variantForm', true],
['withDelims', true],
['mathaccent', true],
['open', true],
['close', true]
]);
function createEntity(code) {
return String.fromCodePoint(parseInt(code, 16));
}
NodeUtil.createEntity = createEntity;
function getChildren(node) {
return node.childNodes;
}
NodeUtil.getChildren = getChildren;
function getText(node) {
return node.getText();
}
NodeUtil.getText = getText;
function appendChildren(node, children) {
var e_1, _a;
try {
for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
var child = children_1_1.value;
node.appendChild(child);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
}
finally { if (e_1) throw e_1.error; }
}
}
NodeUtil.appendChildren = appendChildren;
function setAttribute(node, attribute, value) {
node.attributes.set(attribute, value);
}
NodeUtil.setAttribute = setAttribute;
function setProperty(node, property, value) {
node.setProperty(property, value);
}
NodeUtil.setProperty = setProperty;
function setProperties(node, properties) {
var e_2, _a;
try {
for (var _b = __values(Object.keys(properties)), _c = _b.next(); !_c.done; _c = _b.next()) {
var name_1 = _c.value;
var value = properties[name_1];
if (name_1 === 'texClass') {
node.texClass = value;
node.setProperty(name_1, value);
}
else if (name_1 === 'movablelimits') {
node.setProperty('movablelimits', value);
if (node.isKind('mo') || node.isKind('mstyle')) {
node.attributes.set('movablelimits', value);
}
}
else if (name_1 === 'inferred') {
}
else if (attrs.has(name_1)) {
node.setProperty(name_1, value);
}
else {
node.attributes.set(name_1, value);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
}
NodeUtil.setProperties = setProperties;
function getProperty(node, property) {
return node.getProperty(property);
}
NodeUtil.getProperty = getProperty;
function getAttribute(node, attr) {
return node.attributes.get(attr);
}
NodeUtil.getAttribute = getAttribute;
function removeProperties(node) {
var properties = [];
for (var _i = 1; _i < arguments.length; _i++) {
properties[_i - 1] = arguments[_i];
}
node.removeProperty.apply(node, __spreadArray([], __read(properties), false));
}
NodeUtil.removeProperties = removeProperties;
function getChildAt(node, position) {
return node.childNodes[position];
}
NodeUtil.getChildAt = getChildAt;
function setChild(node, position, child) {
var children = node.childNodes;
children[position] = child;
if (child) {
child.parent = node;
}
}
NodeUtil.setChild = setChild;
function copyChildren(oldNode, newNode) {
var children = oldNode.childNodes;
for (var i = 0; i < children.length; i++) {
setChild(newNode, i, children[i]);
}
}
NodeUtil.copyChildren = copyChildren;
function copyAttributes(oldNode, newNode) {
newNode.attributes = oldNode.attributes;
setProperties(newNode, oldNode.getAllProperties());
}
NodeUtil.copyAttributes = copyAttributes;
function isType(node, kind) {
return node.isKind(kind);
}
NodeUtil.isType = isType;
function isEmbellished(node) {
return node.isEmbellished;
}
NodeUtil.isEmbellished = isEmbellished;
function getTexClass(node) {
return node.texClass;
}
NodeUtil.getTexClass = getTexClass;
function getCoreMO(node) {
return node.coreMO();
}
NodeUtil.getCoreMO = getCoreMO;
function isNode(item) {
return item instanceof MmlNode_js_1.AbstractMmlNode || item instanceof MmlNode_js_1.AbstractMmlEmptyNode;
}
NodeUtil.isNode = isNode;
function isInferred(node) {
return node.isInferred;
}
NodeUtil.isInferred = isInferred;
function getForm(node) {
var e_3, _a;
if (!isType(node, 'mo')) {
return null;
}
var mo = node;
var forms = mo.getForms();
try {
for (var forms_1 = __values(forms), forms_1_1 = forms_1.next(); !forms_1_1.done; forms_1_1 = forms_1.next()) {
var form = forms_1_1.value;
var symbol = mo_js_1.MmlMo.OPTABLE[form][mo.getText()];
if (symbol) {
return symbol;
}
}
}
catch (e_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (forms_1_1 && !forms_1_1.done && (_a = forms_1.return)) _a.call(forms_1);
}
finally { if (e_3) throw e_3.error; }
}
return null;
}
NodeUtil.getForm = getForm;
})(NodeUtil || (NodeUtil = {}));
exports.default = NodeUtil;
//# sourceMappingURL=NodeUtil.js.map