speech-rule-engine
Version:
A standalone speech rule engine for XML structures, based on the original engine from ChromeVox.
83 lines • 3.3 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.HtmlHighlighter = void 0;
const DomUtil = __importStar(require("../common/dom_util.js"));
const abstract_highlighter_js_1 = require("./abstract_highlighter.js");
class HtmlHighlighter extends abstract_highlighter_js_1.AbstractHighlighter {
constructor() {
super();
this.mactionName = 'maction';
}
highlightNode(node) {
const info = {
node: node,
foreground: node.style.color,
position: node.style.position
};
const color = this.color.rgb();
node.style.color = color.foreground;
node.style.position = 'relative';
const bbox = node.bbox;
if (bbox && bbox.w) {
const vpad = 0.05;
const hpad = 0;
const span = DomUtil.createElement('span');
const left = parseFloat(node.style.paddingLeft || '0');
span.style.backgroundColor = color.background;
span.style.opacity = color.alphaback.toString();
span.style.display = 'inline-block';
span.style.height = bbox.h + bbox.d + 2 * vpad + 'em';
span.style.verticalAlign = -bbox.d + 'em';
span.style.marginTop = span.style.marginBottom = -vpad + 'em';
span.style.width = bbox.w + 2 * hpad + 'em';
span.style.marginLeft = left - hpad + 'em';
span.style.marginRight = -bbox.w - hpad - left + 'em';
node.parentNode.insertBefore(span, node);
info.box = span;
}
return info;
}
unhighlightNode(info) {
const node = info.node;
node.style.color = info.foreground;
node.style.position = info.position;
if (info.box) {
info.box.parentNode.removeChild(info.box);
}
}
}
exports.HtmlHighlighter = HtmlHighlighter;
//# sourceMappingURL=html_highlighter.js.map