speech-rule-engine
Version:
A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.
121 lines • 4.71 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SvgHighlighter = void 0;
const DomUtil = __importStar(require("../common/dom_util.js"));
const abstract_highlighter_js_1 = require("./abstract_highlighter.js");
class SvgHighlighter extends abstract_highlighter_js_1.AbstractHighlighter {
constructor() {
super();
this.mactionName = 'mjx-svg-maction';
}
highlightNode(node) {
let info;
if (this.isHighlighted(node)) {
info = {
node: node.previousSibling || node,
background: node.style.backgroundColor,
foreground: node.style.color
};
return info;
}
if (node.tagName === 'svg') {
const info = {
node: node,
background: node.style.backgroundColor,
foreground: node.style.color
};
node.style.backgroundColor = this.colorString().background;
node.style.color = this.colorString().foreground;
return info;
}
const rect = DomUtil.createElementNS('http://www.w3.org/2000/svg', 'rect');
const padding = 40;
let bbox;
if (node.nodeName === 'use') {
const g = DomUtil.createElementNS('http://www.w3.org/2000/svg', 'g');
node.parentNode.insertBefore(g, node);
g.appendChild(node);
bbox = g.getBBox();
g.parentNode.replaceChild(node, g);
}
else {
bbox = node.getBBox();
}
rect.setAttribute('x', (bbox.x - padding).toString());
rect.setAttribute('y', (bbox.y - padding).toString());
rect.setAttribute('width', (bbox.width + 2 * padding).toString());
rect.setAttribute('height', (bbox.height + 2 * padding).toString());
const transform = node.getAttribute('transform');
if (transform) {
rect.setAttribute('transform', transform);
}
rect.setAttribute('fill', this.colorString().background);
rect.setAttribute(this.ATTR, 'true');
node.parentNode.insertBefore(rect, node);
info = { node: rect, foreground: node.getAttribute('fill') };
node.setAttribute('fill', this.colorString().foreground);
return info;
}
setHighlighted(node) {
if (node.tagName === 'svg') {
super.setHighlighted(node);
}
}
unhighlightNode(info) {
if ('background' in info) {
info.node.style.backgroundColor = info.background;
info.node.style.color = info.foreground;
return;
}
info.foreground
? info.node.nextSibling.setAttribute('fill', info.foreground)
: info.node.nextSibling.removeAttribute('fill');
info.node.parentNode.removeChild(info.node);
}
isMactionNode(node) {
let className = node.className || node.getAttribute('class');
if (!className) {
return false;
}
className =
className.baseVal !== undefined
? className.baseVal
: className;
return className ? !!className.match(new RegExp(this.mactionName)) : false;
}
}
exports.SvgHighlighter = SvgHighlighter;
//# sourceMappingURL=svg_highlighter.js.map