123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- "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
|