UNPKG

speech-rule-engine

Version:

A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.

111 lines 4.66 kB
"use strict"; 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.SvgV3Highlighter = void 0; const DomUtil = __importStar(require("../common/dom_util.js")); const XpathUtil = __importStar(require("../common/xpath_util.js")); const color_picker_js_1 = require("./color_picker.js"); const svg_highlighter_js_1 = require("./svg_highlighter.js"); class SvgV3Highlighter extends svg_highlighter_js_1.SvgHighlighter { constructor() { super(); this.mactionName = 'maction'; } highlightNode(node) { let info; if (this.isHighlighted(node)) { info = { node: node, background: this.colorString().background, foreground: this.colorString().foreground }; return info; } if (node.tagName === 'svg' || node.tagName === 'MJX-CONTAINER') { 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 = (document !== null && document !== void 0 ? document : DomUtil).createElementNS('http://www.w3.org/2000/svg', 'rect'); rect.setAttribute('sre-highlighter-added', 'true'); const padding = 40; const 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); node.setAttribute(this.ATTR, 'true'); node.parentNode.insertBefore(rect, node); info = { node: node, foreground: node.getAttribute('fill') }; if (node.nodeName === 'rect') { const picker = new color_picker_js_1.ColorPicker({ alpha: 0, color: 'white' }); node.setAttribute('fill', picker.rgba().background); } else { node.setAttribute('fill', this.colorString().foreground); } return info; } unhighlightNode(info) { const previous = info.node.previousSibling; if (previous && previous.hasAttribute('sre-highlighter-added')) { info.foreground ? info.node.setAttribute('fill', info.foreground) : info.node.removeAttribute('fill'); info.node.parentNode.removeChild(previous); return; } info.node.style.backgroundColor = info.background; info.node.style.color = info.foreground; } isMactionNode(node) { return node.getAttribute('data-mml-node') === this.mactionName; } getMactionNodes(node) { return Array.from(XpathUtil.evalXPath(`.//*[@data-mml-node="${this.mactionName}"]`, node)); } } exports.SvgV3Highlighter = SvgV3Highlighter; //# sourceMappingURL=svg_v3_highlighter.js.map