add initial marp implementation with sample content and build configuration
This commit is contained in:
3
node_modules/speech-rule-engine/js/common/base_util.d.ts
generated
vendored
Normal file
3
node_modules/speech-rule-engine/js/common/base_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare function removeEmpty(strs: string[]): string[];
|
||||
export declare function interleaveLists(list1: any[], list2: any[]): any[];
|
||||
export declare function setdifference(a: any[], b: any[]): any[];
|
||||
29
node_modules/speech-rule-engine/js/common/base_util.js
generated
vendored
Normal file
29
node_modules/speech-rule-engine/js/common/base_util.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.removeEmpty = removeEmpty;
|
||||
exports.interleaveLists = interleaveLists;
|
||||
exports.setdifference = setdifference;
|
||||
function removeEmpty(strs) {
|
||||
return strs.filter((str) => str);
|
||||
}
|
||||
function interleaveLists(list1, list2) {
|
||||
const result = [];
|
||||
while (list1.length || list2.length) {
|
||||
if (list1.length) {
|
||||
result.push(list1.shift());
|
||||
}
|
||||
if (list2.length) {
|
||||
result.push(list2.shift());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function setdifference(a, b) {
|
||||
if (!a) {
|
||||
return [];
|
||||
}
|
||||
if (!b) {
|
||||
return a;
|
||||
}
|
||||
return a.filter((x) => b.indexOf(x) < 0);
|
||||
}
|
||||
5
node_modules/speech-rule-engine/js/common/browser_util.d.ts
generated
vendored
Normal file
5
node_modules/speech-rule-engine/js/common/browser_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export declare function detectIE(): boolean;
|
||||
export declare function detectEdge(): boolean;
|
||||
export declare const mapsForIE: {
|
||||
[key: string]: any;
|
||||
};
|
||||
65
node_modules/speech-rule-engine/js/common/browser_util.js
generated
vendored
Normal file
65
node_modules/speech-rule-engine/js/common/browser_util.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mapsForIE = void 0;
|
||||
exports.detectIE = detectIE;
|
||||
exports.detectEdge = detectEdge;
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
const xpath_util_js_1 = require("./xpath_util.js");
|
||||
function detectIE() {
|
||||
const isIE = typeof window !== 'undefined' &&
|
||||
'ActiveXObject' in window &&
|
||||
'clipboardData' in window;
|
||||
if (!isIE) {
|
||||
return false;
|
||||
}
|
||||
loadMapsForIE();
|
||||
loadWGXpath();
|
||||
return true;
|
||||
}
|
||||
function detectEdge() {
|
||||
var _a;
|
||||
const isEdge = typeof window !== 'undefined' &&
|
||||
'MSGestureEvent' in window &&
|
||||
((_a = window.chrome) === null || _a === void 0 ? void 0 : _a.loadTimes) === null;
|
||||
if (!isEdge) {
|
||||
return false;
|
||||
}
|
||||
document.evaluate = null;
|
||||
loadWGXpath(true);
|
||||
return true;
|
||||
}
|
||||
exports.mapsForIE = null;
|
||||
function loadWGXpath(opt_isEdge) {
|
||||
loadScript(system_external_js_1.SystemExternal.WGXpath);
|
||||
installWGXpath(opt_isEdge);
|
||||
}
|
||||
function installWGXpath(opt_isEdge, opt_count) {
|
||||
let count = opt_count || 1;
|
||||
if (typeof wgxpath === 'undefined' && count < 10) {
|
||||
setTimeout(function () {
|
||||
installWGXpath(opt_isEdge, count++);
|
||||
}, 200);
|
||||
return;
|
||||
}
|
||||
if (count >= 10) {
|
||||
return;
|
||||
}
|
||||
system_external_js_1.SystemExternal.wgxpath = wgxpath;
|
||||
opt_isEdge
|
||||
? system_external_js_1.SystemExternal.wgxpath.install({ document: document })
|
||||
: system_external_js_1.SystemExternal.wgxpath.install();
|
||||
xpath_util_js_1.xpath.evaluate = document.evaluate;
|
||||
xpath_util_js_1.xpath.result = XPathResult;
|
||||
xpath_util_js_1.xpath.createNSResolver = document.createNSResolver;
|
||||
}
|
||||
function loadMapsForIE() {
|
||||
loadScript(system_external_js_1.SystemExternal.mathmapsIePath);
|
||||
}
|
||||
function loadScript(src) {
|
||||
const scr = system_external_js_1.SystemExternal.document.createElement('script');
|
||||
scr.type = 'text/javascript';
|
||||
scr.src = src;
|
||||
system_external_js_1.SystemExternal.document.head
|
||||
? system_external_js_1.SystemExternal.document.head.appendChild(scr)
|
||||
: system_external_js_1.SystemExternal.document.body.appendChild(scr);
|
||||
}
|
||||
20
node_modules/speech-rule-engine/js/common/cli.d.ts
generated
vendored
Normal file
20
node_modules/speech-rule-engine/js/common/cli.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
export declare class Cli {
|
||||
static process: any;
|
||||
static commander: any;
|
||||
setup: {
|
||||
[key: string]: string | boolean;
|
||||
};
|
||||
processors: string[];
|
||||
dp: DOMParser;
|
||||
private output;
|
||||
constructor();
|
||||
set(arg: string, value: string | boolean, _def: string): void;
|
||||
processor(processor: string): void;
|
||||
private loadLocales;
|
||||
enumerate(all?: boolean): Promise<void>;
|
||||
execute(input: string): void;
|
||||
readline(): void;
|
||||
commandLine(): Promise<void>;
|
||||
private runProcessors_;
|
||||
private readExpression_;
|
||||
}
|
||||
249
node_modules/speech-rule-engine/js/common/cli.js
generated
vendored
Normal file
249
node_modules/speech-rule-engine/js/common/cli.js
generated
vendored
Normal file
@@ -0,0 +1,249 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Cli = void 0;
|
||||
const dynamic_cstr_js_1 = require("../rule_engine/dynamic_cstr.js");
|
||||
const MathCompoundStore = require("../rule_engine/math_compound_store.js");
|
||||
const speech_rule_engine_js_1 = require("../rule_engine/speech_rule_engine.js");
|
||||
const clearspeak_preferences_js_1 = require("../speech_rules/clearspeak_preferences.js");
|
||||
const debugger_js_1 = require("./debugger.js");
|
||||
const engine_js_1 = require("./engine.js");
|
||||
const EngineConst = require("./engine_const.js");
|
||||
const ProcessorFactory = require("./processor_factory.js");
|
||||
const System = require("./system.js");
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
const variables_js_1 = require("./variables.js");
|
||||
class Cli {
|
||||
constructor() {
|
||||
this.setup = {
|
||||
mode: EngineConst.Mode.SYNC
|
||||
};
|
||||
this.processors = [];
|
||||
this.output = Cli.process.stdout;
|
||||
this.dp = new system_external_js_1.SystemExternal.xmldom.DOMParser({
|
||||
onError: (_key, _msg) => {
|
||||
throw new engine_js_1.SREError('XML DOM error!');
|
||||
}
|
||||
});
|
||||
}
|
||||
set(arg, value, _def) {
|
||||
this.setup[arg] = typeof value === 'undefined' ? true : value;
|
||||
}
|
||||
processor(processor) {
|
||||
this.processors.push(processor);
|
||||
}
|
||||
loadLocales() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
for (const loc of variables_js_1.Variables.LOCALES.keys()) {
|
||||
yield System.setupEngine({ locale: loc });
|
||||
}
|
||||
});
|
||||
}
|
||||
enumerate() {
|
||||
return __awaiter(this, arguments, void 0, function* (all = false) {
|
||||
const promise = System.setupEngine(this.setup);
|
||||
const order = dynamic_cstr_js_1.DynamicCstr.DEFAULT_ORDER.slice(0, -1);
|
||||
return (all ? this.loadLocales() : promise).then(() => engine_js_1.EnginePromise.getall().then(() => {
|
||||
const length = order.map((x) => x.length);
|
||||
const maxLength = (obj, index) => {
|
||||
length[index] = Math.max.apply(null, Object.keys(obj)
|
||||
.map((x) => x.length)
|
||||
.concat(length[index]));
|
||||
};
|
||||
const compStr = (str, length) => str + new Array(length - str.length + 1).join(' ');
|
||||
let dynamic = speech_rule_engine_js_1.SpeechRuleEngine.getInstance().enumerate();
|
||||
dynamic = MathCompoundStore.enumerate(dynamic);
|
||||
const table = [];
|
||||
maxLength(dynamic, 0);
|
||||
for (const [ax1, dyna1] of Object.entries(dynamic)) {
|
||||
let clear1 = true;
|
||||
maxLength(dyna1, 1);
|
||||
for (const [ax2, dyna2] of Object.entries(dyna1)) {
|
||||
let clear2 = true;
|
||||
maxLength(dyna2, 2);
|
||||
for (const [ax3, dyna3] of Object.entries(dyna2)) {
|
||||
const styles = Object.keys(dyna3).sort();
|
||||
if (ax3 === 'clearspeak') {
|
||||
let clear3 = true;
|
||||
const prefs = clearspeak_preferences_js_1.ClearspeakPreferences.getLocalePreferences(dynamic)[ax1];
|
||||
if (!prefs) {
|
||||
continue;
|
||||
}
|
||||
for (const dyna4 of Object.values(prefs)) {
|
||||
table.push([
|
||||
compStr(clear1 ? ax1 : '', length[0]),
|
||||
compStr(clear2 ? ax2 : '', length[1]),
|
||||
compStr(clear3 ? ax3 : '', length[2]),
|
||||
dyna4.join(', ')
|
||||
]);
|
||||
clear1 = false;
|
||||
clear2 = false;
|
||||
clear3 = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
table.push([
|
||||
compStr(clear1 ? ax1 : '', length[0]),
|
||||
compStr(clear2 ? ax2 : '', length[1]),
|
||||
compStr(ax3, length[2]),
|
||||
styles.join(', ')
|
||||
]);
|
||||
}
|
||||
clear1 = false;
|
||||
clear2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
let i = 0;
|
||||
const header = order.map((x) => compStr(x, length[i++]));
|
||||
const markdown = Cli.commander.opts().pprint;
|
||||
const separator = length.map((x) => new Array(x + 1).join(markdown ? '-' : '='));
|
||||
if (!markdown) {
|
||||
separator[i - 1] = separator[i - 1] + '========================';
|
||||
}
|
||||
table.unshift(separator);
|
||||
table.unshift(header);
|
||||
let output = table.map((x) => x.join(' | '));
|
||||
if (markdown) {
|
||||
output = output.map((x) => `| ${x} |`);
|
||||
output.unshift(`# Options SRE v${System.version}\n`);
|
||||
}
|
||||
console.info(output.join('\n'));
|
||||
}));
|
||||
});
|
||||
}
|
||||
execute(input) {
|
||||
engine_js_1.EnginePromise.getall().then(() => {
|
||||
this.runProcessors_((proc, file) => this.output.write(System.processFile(proc, file) + '\n'), input);
|
||||
});
|
||||
}
|
||||
readline() {
|
||||
Cli.process.stdin.setEncoding('utf8');
|
||||
const inter = system_external_js_1.SystemExternal.extRequire('readline').createInterface({
|
||||
input: Cli.process.stdin,
|
||||
output: this.output
|
||||
});
|
||||
let input = '';
|
||||
inter.on('line', ((expr) => {
|
||||
input += expr;
|
||||
if (this.readExpression_(input)) {
|
||||
inter.close();
|
||||
}
|
||||
}).bind(this));
|
||||
inter.on('close', (() => {
|
||||
this.runProcessors_((proc, expr) => {
|
||||
inter.output.write(ProcessorFactory.output(proc, expr) + '\n');
|
||||
}, input);
|
||||
System.engineReady().then(() => debugger_js_1.Debugger.getInstance().exit(() => System.exit(0)));
|
||||
}).bind(this));
|
||||
}
|
||||
commandLine() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const commander = Cli.commander;
|
||||
const system = System;
|
||||
const set = ((key) => {
|
||||
return (val, def) => this.set(key, val, def);
|
||||
}).bind(this);
|
||||
const processor = this.processor.bind(this);
|
||||
commander
|
||||
.version(system.version)
|
||||
.usage('[options] <file ...>')
|
||||
.option('-i, --input [name]', 'Input file [name]. (Deprecated)')
|
||||
.option('-o, --output [name]', 'Output file [name]. Defaults to stdout.')
|
||||
.option('-d, --domain [name]', 'Speech rule set [name]. See --options' + ' for details.', set(dynamic_cstr_js_1.Axis.DOMAIN), dynamic_cstr_js_1.DynamicCstr.DEFAULT_VALUES[dynamic_cstr_js_1.Axis.DOMAIN])
|
||||
.option('-s, --style [name]', 'Speech style [name]. See --options' + ' for details.', set(dynamic_cstr_js_1.Axis.STYLE), dynamic_cstr_js_1.DynamicCstr.DEFAULT_VALUES[dynamic_cstr_js_1.Axis.STYLE])
|
||||
.option('-c, --locale [code]', 'Locale [code].', set(dynamic_cstr_js_1.Axis.LOCALE), dynamic_cstr_js_1.DynamicCstr.DEFAULT_VALUES[dynamic_cstr_js_1.Axis.LOCALE])
|
||||
.option('-b, --modality [name]', 'Modality [name].', set(dynamic_cstr_js_1.Axis.MODALITY), dynamic_cstr_js_1.DynamicCstr.DEFAULT_VALUES[dynamic_cstr_js_1.Axis.MODALITY])
|
||||
.option('-k, --markup [name]', 'Generate speech output with markup tags.', set('markup'), 'none')
|
||||
.option('-e, --automark', 'Automatically set marks for external reference.', set('automark'))
|
||||
.option('-L, --linebreaks', 'Linebreak marking in 2D output.', set('linebreaks'))
|
||||
.option('-r, --rate [value]', 'Base rate [value] for tagged speech' + ' output.', set('rate'), '100')
|
||||
.option('-p, --speech', 'Generate speech output (default).', () => processor('speech'))
|
||||
.option('-a, --audit', 'Generate auditory descriptions (JSON format).', () => processor('description'))
|
||||
.option('-j, --json', 'Generate JSON of semantic tree.', () => processor('json'))
|
||||
.option('-x, --xml', 'Generate XML of semantic tree.', () => processor('semantic'))
|
||||
.option('-m, --mathml', 'Generate enriched MathML.', () => processor('enriched'))
|
||||
.option('-u, --rebuild', 'Rebuild semantic tree from enriched MathML.', () => processor('rebuild'))
|
||||
.option('-t, --latex', 'Accepts LaTeX input for certain locale/modality combinations.', () => processor('latex'))
|
||||
.option('-g, --generate <depth>', 'Include generated speech in enriched' +
|
||||
' MathML (with -m option only).', set('speech'), 'none')
|
||||
.option('-w, --structure', 'Include structure attribute in enriched' +
|
||||
' MathML (with -m option only).', set('structure'))
|
||||
.option('-A, --aria', 'Include aria tree annotations' +
|
||||
' MathML (with -m and -w option only).', set('aria'))
|
||||
.option('-P, --pprint', 'Pretty print output whenever possible.', set('pprint'))
|
||||
.option('-f, --rules [name]', 'Loads a local rule file [name].', set('rules'))
|
||||
.option('-C, --subiso [name]', 'Supplementary country code (or similar) for the given locale.', set('subiso'))
|
||||
.option('-N, --number', 'Translate number to word.', () => processor('number'))
|
||||
.option('-O, --ordinal', 'Translate number to ordinal.', () => processor('ordinal'), 'ordinal')
|
||||
.option('-S, --numeric', 'Translate number to numeric ordinal.', () => processor('numericOrdinal'))
|
||||
.option('-F, --vulgar', 'Translate vulgar fraction to word. Provide vulgar fraction as slash seperated numbers.', () => processor('vulgar'))
|
||||
.option('-v, --verbose', 'Verbose mode.')
|
||||
.option('-l, --log [name]', 'Log file [name].')
|
||||
.option('--opt', 'List engine setup options. Output as markdown with -P option.')
|
||||
.option('--opt-all', 'List engine setup options for all available locales. Output as markdown with -P option.')
|
||||
.on('option:opt', () => {
|
||||
this.enumerate().then(() => System.exit(0));
|
||||
})
|
||||
.on('option:opt-all', () => {
|
||||
this.enumerate(true).then(() => System.exit(0));
|
||||
})
|
||||
.parse(Cli.process.argv);
|
||||
yield System.engineReady().then(() => System.setupEngine(this.setup));
|
||||
const options = Cli.commander.opts();
|
||||
if (options.output) {
|
||||
this.output = system_external_js_1.SystemExternal.fs.createWriteStream(options.output);
|
||||
}
|
||||
if (options.verbose) {
|
||||
yield debugger_js_1.Debugger.getInstance().init(options.log);
|
||||
}
|
||||
if (options.input) {
|
||||
this.execute(options.input);
|
||||
}
|
||||
if (Cli.commander.args.length) {
|
||||
Cli.commander.args.forEach(this.execute.bind(this));
|
||||
System.engineReady().then(() => debugger_js_1.Debugger.getInstance().exit(() => System.exit(0)));
|
||||
}
|
||||
else {
|
||||
this.readline();
|
||||
}
|
||||
});
|
||||
}
|
||||
runProcessors_(processor, input) {
|
||||
try {
|
||||
if (!this.processors.length) {
|
||||
this.processors.push('speech');
|
||||
}
|
||||
if (input) {
|
||||
this.processors.forEach((proc) => processor(proc, input));
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err.name + ': ' + err.message);
|
||||
debugger_js_1.Debugger.getInstance().exit(() => Cli.process.exit(1));
|
||||
}
|
||||
}
|
||||
readExpression_(input) {
|
||||
try {
|
||||
const testInput = input.replace(/(&|#|;)/g, '');
|
||||
this.dp.parseFromString(testInput, 'text/xml');
|
||||
}
|
||||
catch (_err) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
exports.Cli = Cli;
|
||||
Cli.process = system_external_js_1.SystemExternal.extRequire('process');
|
||||
Cli.commander = system_external_js_1.SystemExternal.documentSupported
|
||||
? null
|
||||
: system_external_js_1.SystemExternal.extRequire('commander').program;
|
||||
15
node_modules/speech-rule-engine/js/common/debugger.d.ts
generated
vendored
Normal file
15
node_modules/speech-rule-engine/js/common/debugger.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
export declare class Debugger {
|
||||
private static instance;
|
||||
private isActive_;
|
||||
private outputFunction_;
|
||||
private fileHandle;
|
||||
private stream_;
|
||||
static getInstance(): Debugger;
|
||||
init(opt_file?: string): any;
|
||||
output(...args: any[]): void;
|
||||
generateOutput(func: () => string[]): void;
|
||||
exit(callback?: () => any): void;
|
||||
private constructor();
|
||||
private startDebugFile_;
|
||||
private output_;
|
||||
}
|
||||
65
node_modules/speech-rule-engine/js/common/debugger.js
generated
vendored
Normal file
65
node_modules/speech-rule-engine/js/common/debugger.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Debugger = void 0;
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
class Debugger {
|
||||
static getInstance() {
|
||||
Debugger.instance = Debugger.instance || new Debugger();
|
||||
return Debugger.instance;
|
||||
}
|
||||
init(opt_file) {
|
||||
if (opt_file) {
|
||||
this.startDebugFile_(opt_file);
|
||||
}
|
||||
this.isActive_ = true;
|
||||
return this.fileHandle;
|
||||
}
|
||||
output(...args) {
|
||||
if (this.isActive_) {
|
||||
this.output_(args);
|
||||
}
|
||||
}
|
||||
generateOutput(func) {
|
||||
if (this.isActive_) {
|
||||
this.output_(func.apply(func, []));
|
||||
}
|
||||
}
|
||||
exit(callback = () => { }) {
|
||||
this.fileHandle.then(() => {
|
||||
if (this.isActive_ && this.stream_) {
|
||||
this.stream_.end('', '', callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
constructor() {
|
||||
this.isActive_ = false;
|
||||
this.outputFunction_ = console.info;
|
||||
this.fileHandle = Promise.resolve();
|
||||
this.stream_ = null;
|
||||
}
|
||||
startDebugFile_(filename) {
|
||||
this.fileHandle = system_external_js_1.SystemExternal.fs.promises.open(filename, 'w');
|
||||
this.fileHandle = this.fileHandle.then((handle) => {
|
||||
this.stream_ = handle.createWriteStream(filename);
|
||||
this.outputFunction_ = function (...args) {
|
||||
this.stream_.write(args.join(' '));
|
||||
this.stream_.write('\n');
|
||||
}.bind(this);
|
||||
this.stream_.on('error', function (_error) {
|
||||
console.info('Invalid log file. Debug information sent to console.');
|
||||
this.outputFunction_ = console.info;
|
||||
}.bind(this));
|
||||
this.stream_.on('finish', function () {
|
||||
console.info('Finalizing debug file.');
|
||||
});
|
||||
});
|
||||
}
|
||||
output_(outputList) {
|
||||
if (console.info === this.outputFunction_) {
|
||||
this.outputFunction_.apply(console, ['Speech Rule Engine Debugger:'].concat(outputList));
|
||||
return;
|
||||
}
|
||||
this.fileHandle.then(() => this.outputFunction_.apply(this.outputFunction_, ['Speech Rule Engine Debugger:'].concat(outputList)));
|
||||
}
|
||||
}
|
||||
exports.Debugger = Debugger;
|
||||
27
node_modules/speech-rule-engine/js/common/dom_util.d.ts
generated
vendored
Normal file
27
node_modules/speech-rule-engine/js/common/dom_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
export declare function toArray(nodeList: NodeList | NamedNodeMap): any[];
|
||||
export declare function parseInput(input: string): Element;
|
||||
export declare enum NodeType {
|
||||
ELEMENT_NODE = 1,
|
||||
ATTRIBUTE_NODE = 2,
|
||||
TEXT_NODE = 3,
|
||||
CDATA_SECTION_NODE = 4,
|
||||
ENTITY_REFERENCE_NODE = 5,
|
||||
ENTITY_NODE = 6,
|
||||
PROCESSING_INSTRUCTION_NODE = 7,
|
||||
COMMENT_NODE = 8,
|
||||
DOCUMENT_NODE = 9,
|
||||
DOCUMENT_TYPE_NODE = 10,
|
||||
DOCUMENT_FRAGMENT_NODE = 11,
|
||||
NOTATION_NODE = 12
|
||||
}
|
||||
export declare function replaceNode(oldNode: Node, newNode: Node): void;
|
||||
export declare function createElement(tag: string): Element;
|
||||
export declare function createElementNS(url: string, tag: string): Element;
|
||||
export declare function createTextNode(content: string): Text;
|
||||
export declare function formatXml(xml: string): string;
|
||||
export declare function querySelectorAllByAttr(node: Element, attr: string): Element[];
|
||||
export declare function querySelectorAllByAttrValue(node: Element, attr: string, value: string): Element[];
|
||||
export declare function querySelectorAll(node: Element, tag: string): Element[];
|
||||
export declare function tagName(node: Element): string;
|
||||
export declare function cloneNode(node: Element): Element;
|
||||
export declare function serializeXml(node: Element): string;
|
||||
172
node_modules/speech-rule-engine/js/common/dom_util.js
generated
vendored
Normal file
172
node_modules/speech-rule-engine/js/common/dom_util.js
generated
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.NodeType = void 0;
|
||||
exports.toArray = toArray;
|
||||
exports.parseInput = parseInput;
|
||||
exports.replaceNode = replaceNode;
|
||||
exports.createElement = createElement;
|
||||
exports.createElementNS = createElementNS;
|
||||
exports.createTextNode = createTextNode;
|
||||
exports.formatXml = formatXml;
|
||||
exports.querySelectorAllByAttr = querySelectorAllByAttr;
|
||||
exports.querySelectorAllByAttrValue = querySelectorAllByAttrValue;
|
||||
exports.querySelectorAll = querySelectorAll;
|
||||
exports.tagName = tagName;
|
||||
exports.cloneNode = cloneNode;
|
||||
exports.serializeXml = serializeXml;
|
||||
const engine_js_1 = require("./engine.js");
|
||||
const EngineConst = require("../common/engine_const.js");
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
const XpathUtil = require("./xpath_util.js");
|
||||
function toArray(nodeList) {
|
||||
const nodeArray = [];
|
||||
for (let i = 0, m = nodeList.length; i < m; i++) {
|
||||
nodeArray.push(nodeList[i]);
|
||||
}
|
||||
return nodeArray;
|
||||
}
|
||||
function trimInput(input) {
|
||||
input = input.replace(/ /g, ' ');
|
||||
return input.replace(/>[ \f\n\r\t\v\u200b]+</g, '><').trim();
|
||||
}
|
||||
function parseInput(input) {
|
||||
const dp = new system_external_js_1.SystemExternal.xmldom.DOMParser();
|
||||
const clean_input = trimInput(input);
|
||||
const allValues = clean_input.match(/&(?!lt|gt|amp|quot|apos)\w+;/g);
|
||||
const html = !!allValues;
|
||||
if (!clean_input) {
|
||||
throw new Error('Empty input!');
|
||||
}
|
||||
try {
|
||||
const doc = dp.parseFromString(clean_input, html ? 'text/html' : 'text/xml');
|
||||
if (engine_js_1.Engine.getInstance().mode === EngineConst.Mode.HTTP) {
|
||||
XpathUtil.xpath.currentDocument = doc;
|
||||
return html ? doc.body.childNodes[0] : doc.documentElement;
|
||||
}
|
||||
return doc.documentElement;
|
||||
}
|
||||
catch (err) {
|
||||
throw new engine_js_1.SREError('Illegal input: ' + err.message);
|
||||
}
|
||||
}
|
||||
var NodeType;
|
||||
(function (NodeType) {
|
||||
NodeType[NodeType["ELEMENT_NODE"] = 1] = "ELEMENT_NODE";
|
||||
NodeType[NodeType["ATTRIBUTE_NODE"] = 2] = "ATTRIBUTE_NODE";
|
||||
NodeType[NodeType["TEXT_NODE"] = 3] = "TEXT_NODE";
|
||||
NodeType[NodeType["CDATA_SECTION_NODE"] = 4] = "CDATA_SECTION_NODE";
|
||||
NodeType[NodeType["ENTITY_REFERENCE_NODE"] = 5] = "ENTITY_REFERENCE_NODE";
|
||||
NodeType[NodeType["ENTITY_NODE"] = 6] = "ENTITY_NODE";
|
||||
NodeType[NodeType["PROCESSING_INSTRUCTION_NODE"] = 7] = "PROCESSING_INSTRUCTION_NODE";
|
||||
NodeType[NodeType["COMMENT_NODE"] = 8] = "COMMENT_NODE";
|
||||
NodeType[NodeType["DOCUMENT_NODE"] = 9] = "DOCUMENT_NODE";
|
||||
NodeType[NodeType["DOCUMENT_TYPE_NODE"] = 10] = "DOCUMENT_TYPE_NODE";
|
||||
NodeType[NodeType["DOCUMENT_FRAGMENT_NODE"] = 11] = "DOCUMENT_FRAGMENT_NODE";
|
||||
NodeType[NodeType["NOTATION_NODE"] = 12] = "NOTATION_NODE";
|
||||
})(NodeType || (exports.NodeType = NodeType = {}));
|
||||
function replaceNode(oldNode, newNode) {
|
||||
if (!oldNode.parentNode) {
|
||||
return;
|
||||
}
|
||||
oldNode.parentNode.insertBefore(newNode, oldNode);
|
||||
oldNode.parentNode.removeChild(oldNode);
|
||||
}
|
||||
function createElement(tag) {
|
||||
return system_external_js_1.SystemExternal.document.createElement(tag);
|
||||
}
|
||||
function createElementNS(url, tag) {
|
||||
return system_external_js_1.SystemExternal.document.createElementNS(url, tag);
|
||||
}
|
||||
function createTextNode(content) {
|
||||
return system_external_js_1.SystemExternal.document.createTextNode(content);
|
||||
}
|
||||
function formatXml(xml) {
|
||||
let formatted = '';
|
||||
let reg = /(>)(<)(\/*)/g;
|
||||
xml = xml.replace(reg, '$1\r\n$2$3');
|
||||
let pad = 0;
|
||||
let split = xml.split('\r\n');
|
||||
reg = /(\.)*(<)(\/*)/g;
|
||||
split = split
|
||||
.map((x) => x.replace(reg, '$1\r\n$2$3').split('\r\n'))
|
||||
.reduce((x, y) => x.concat(y), []);
|
||||
while (split.length) {
|
||||
let node = split.shift();
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
let indent = 0;
|
||||
if (node.match(/^<\w[^>/]*>[^>]+$/)) {
|
||||
const match = matchingStartEnd(node, split[0]);
|
||||
if (match[0]) {
|
||||
if (match[1]) {
|
||||
node = node + split.shift().slice(0, -match[1].length);
|
||||
if (match[1].trim()) {
|
||||
split.unshift(match[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
node = node + split.shift();
|
||||
}
|
||||
}
|
||||
else {
|
||||
indent = 1;
|
||||
}
|
||||
}
|
||||
else if (node.match(/^<\/\w/)) {
|
||||
if (pad !== 0) {
|
||||
pad -= 1;
|
||||
}
|
||||
}
|
||||
else if (node.match(/^<\w[^>]*[^/]>.*$/)) {
|
||||
indent = 1;
|
||||
}
|
||||
else if (node.match(/^<\w[^>]*\/>.+$/)) {
|
||||
const position = node.indexOf('>') + 1;
|
||||
const rest = node.slice(position);
|
||||
if (rest.trim()) {
|
||||
split.unshift();
|
||||
}
|
||||
node = node.slice(0, position) + rest;
|
||||
}
|
||||
else {
|
||||
indent = 0;
|
||||
}
|
||||
formatted += new Array(pad + 1).join(' ') + node + '\r\n';
|
||||
pad += indent;
|
||||
}
|
||||
return formatted;
|
||||
}
|
||||
function matchingStartEnd(start, end) {
|
||||
if (!end) {
|
||||
return [false, ''];
|
||||
}
|
||||
const tag1 = start.match(/^<([^> ]+).*>/);
|
||||
const tag2 = end.match(/^<\/([^>]+)>(.*)/);
|
||||
return tag1 && tag2 && tag1[1] === tag2[1] ? [true, tag2[2]] : [false, ''];
|
||||
}
|
||||
function querySelectorAllByAttr(node, attr) {
|
||||
return node.querySelectorAll
|
||||
? toArray(node.querySelectorAll(`[${attr}]`))
|
||||
: XpathUtil.evalXPath(`.//*[@${attr}]`, node);
|
||||
}
|
||||
function querySelectorAllByAttrValue(node, attr, value) {
|
||||
return node.querySelectorAll
|
||||
? toArray(node.querySelectorAll(`[${attr}="${value}"]`))
|
||||
: XpathUtil.evalXPath(`.//*[@${attr}="${value}"]`, node);
|
||||
}
|
||||
function querySelectorAll(node, tag) {
|
||||
return node.querySelectorAll
|
||||
? toArray(node.querySelectorAll(tag))
|
||||
: XpathUtil.evalXPath(`.//${tag}`, node);
|
||||
}
|
||||
function tagName(node) {
|
||||
return node.tagName.toUpperCase();
|
||||
}
|
||||
function cloneNode(node) {
|
||||
return node.cloneNode(true);
|
||||
}
|
||||
function serializeXml(node) {
|
||||
const xmls = new system_external_js_1.SystemExternal.xmldom.XMLSerializer();
|
||||
return xmls.serializeToString(node);
|
||||
}
|
||||
78
node_modules/speech-rule-engine/js/common/engine.d.ts
generated
vendored
Normal file
78
node_modules/speech-rule-engine/js/common/engine.d.ts
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
import { AuditoryDescription } from '../audio/auditory_description.js';
|
||||
import * as Dcstr from '../rule_engine/dynamic_cstr.js';
|
||||
import * as EngineConst from './engine_const.js';
|
||||
export declare class SREError extends Error {
|
||||
message: string;
|
||||
name: string;
|
||||
constructor(message?: string);
|
||||
}
|
||||
export declare class Engine {
|
||||
static BINARY_FEATURES: string[];
|
||||
static STRING_FEATURES: string[];
|
||||
private static instance;
|
||||
customLoader: (locale: string) => Promise<string>;
|
||||
evaluator: (p1: string, p2: Dcstr.DynamicCstr) => string | null;
|
||||
defaultParser: Dcstr.DynamicCstrParser;
|
||||
parser: Dcstr.DynamicCstrParser;
|
||||
parsers: {
|
||||
[key: string]: Dcstr.DynamicCstrParser;
|
||||
};
|
||||
dynamicCstr: Dcstr.DynamicCstr;
|
||||
comparator: Dcstr.Comparator;
|
||||
mode: EngineConst.Mode;
|
||||
init: boolean;
|
||||
delay: boolean;
|
||||
comparators: {
|
||||
[key: string]: () => Dcstr.Comparator;
|
||||
};
|
||||
domain: string;
|
||||
style: string;
|
||||
_defaultLocale: string;
|
||||
set defaultLocale(loc: string);
|
||||
get defaultLocale(): string;
|
||||
locale: string;
|
||||
subiso: string;
|
||||
modality: string;
|
||||
speech: EngineConst.Speech;
|
||||
markup: EngineConst.Markup;
|
||||
mark: boolean;
|
||||
automark: boolean;
|
||||
character: boolean;
|
||||
cleanpause: boolean;
|
||||
cayleyshort: boolean;
|
||||
linebreaks: boolean;
|
||||
rate: string;
|
||||
walker: string;
|
||||
structure: boolean;
|
||||
aria: boolean;
|
||||
ruleSets: string[];
|
||||
strict: boolean;
|
||||
isIE: boolean;
|
||||
isEdge: boolean;
|
||||
pprint: boolean;
|
||||
config: boolean;
|
||||
rules: string;
|
||||
prune: string;
|
||||
static getInstance(): Engine;
|
||||
static defaultEvaluator(str: string, _cstr: Dcstr.DynamicCstr): string;
|
||||
static nodeEvaluator: (node: Element) => AuditoryDescription[];
|
||||
static evaluateNode(node: Element): AuditoryDescription[];
|
||||
getRate(): number;
|
||||
setDynamicCstr(opt_dynamic?: Dcstr.AxisMap): void;
|
||||
private constructor();
|
||||
configurate(feature: {
|
||||
[key: string]: boolean | string;
|
||||
}): void;
|
||||
setCustomLoader(fn: any): void;
|
||||
}
|
||||
export default Engine;
|
||||
export declare class EnginePromise {
|
||||
static loaded: {
|
||||
[locale: string]: [boolean, boolean];
|
||||
};
|
||||
static promises: {
|
||||
[locale: string]: Promise<string>;
|
||||
};
|
||||
static get(locale?: string): Promise<string>;
|
||||
static getall(): Promise<string[]>;
|
||||
}
|
||||
181
node_modules/speech-rule-engine/js/common/engine.js
generated
vendored
Normal file
181
node_modules/speech-rule-engine/js/common/engine.js
generated
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.EnginePromise = exports.Engine = exports.SREError = void 0;
|
||||
const Dcstr = require("../rule_engine/dynamic_cstr.js");
|
||||
const EngineConst = require("./engine_const.js");
|
||||
const debugger_js_1 = require("./debugger.js");
|
||||
const variables_js_1 = require("./variables.js");
|
||||
class SREError extends Error {
|
||||
constructor(message = '') {
|
||||
super();
|
||||
this.message = message;
|
||||
this.name = 'SRE Error';
|
||||
}
|
||||
}
|
||||
exports.SREError = SREError;
|
||||
class Engine {
|
||||
set defaultLocale(loc) {
|
||||
this._defaultLocale = variables_js_1.Variables.ensureLocale(loc, this._defaultLocale);
|
||||
}
|
||||
get defaultLocale() {
|
||||
return this._defaultLocale;
|
||||
}
|
||||
static getInstance() {
|
||||
Engine.instance = Engine.instance || new Engine();
|
||||
return Engine.instance;
|
||||
}
|
||||
static defaultEvaluator(str, _cstr) {
|
||||
return str;
|
||||
}
|
||||
static evaluateNode(node) {
|
||||
return Engine.nodeEvaluator(node);
|
||||
}
|
||||
getRate() {
|
||||
const numeric = parseInt(this.rate, 10);
|
||||
return isNaN(numeric) ? 100 : numeric;
|
||||
}
|
||||
setDynamicCstr(opt_dynamic) {
|
||||
if (this.defaultLocale) {
|
||||
Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE] = this.defaultLocale;
|
||||
}
|
||||
if (opt_dynamic) {
|
||||
const keys = Object.keys(opt_dynamic);
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const feature = keys[i];
|
||||
if (Dcstr.DynamicCstr.DEFAULT_ORDER.indexOf(feature) !== -1) {
|
||||
const value = opt_dynamic[feature];
|
||||
this[feature] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
EngineConst.DOMAIN_TO_STYLES[this.domain] = this.style;
|
||||
const dynamic = [this.locale, this.modality, this.domain, this.style].join('.');
|
||||
const fallback = Dcstr.DynamicProperties.createProp([Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE]], [Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.MODALITY]], [Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.DOMAIN]], [Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.STYLE]]);
|
||||
const comparator = this.comparators[this.domain];
|
||||
const parser = this.parsers[this.domain];
|
||||
this.parser = parser ? parser : this.defaultParser;
|
||||
this.dynamicCstr = this.parser.parse(dynamic);
|
||||
this.dynamicCstr.updateProperties(fallback.getProperties());
|
||||
this.comparator = comparator
|
||||
? comparator()
|
||||
: new Dcstr.DefaultComparator(this.dynamicCstr);
|
||||
}
|
||||
constructor() {
|
||||
this.customLoader = null;
|
||||
this.parsers = {};
|
||||
this.comparator = null;
|
||||
this.mode = EngineConst.Mode.SYNC;
|
||||
this.init = true;
|
||||
this.delay = false;
|
||||
this.comparators = {};
|
||||
this.domain = 'mathspeak';
|
||||
this.style = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.STYLE];
|
||||
this._defaultLocale = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE];
|
||||
this.locale = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.LOCALE];
|
||||
this.subiso = '';
|
||||
this.modality = Dcstr.DynamicCstr.DEFAULT_VALUES[Dcstr.Axis.MODALITY];
|
||||
this.speech = EngineConst.Speech.NONE;
|
||||
this.markup = EngineConst.Markup.NONE;
|
||||
this.mark = true;
|
||||
this.automark = false;
|
||||
this.character = true;
|
||||
this.cleanpause = true;
|
||||
this.cayleyshort = true;
|
||||
this.linebreaks = false;
|
||||
this.rate = '100';
|
||||
this.walker = 'Table';
|
||||
this.structure = false;
|
||||
this.aria = false;
|
||||
this.ruleSets = [];
|
||||
this.strict = false;
|
||||
this.isIE = false;
|
||||
this.isEdge = false;
|
||||
this.pprint = false;
|
||||
this.config = false;
|
||||
this.rules = '';
|
||||
this.prune = '';
|
||||
this.locale = this.defaultLocale;
|
||||
this.evaluator = Engine.defaultEvaluator;
|
||||
this.defaultParser = new Dcstr.DynamicCstrParser(Dcstr.DynamicCstr.DEFAULT_ORDER);
|
||||
this.parser = this.defaultParser;
|
||||
this.dynamicCstr = Dcstr.DynamicCstr.defaultCstr();
|
||||
}
|
||||
configurate(feature) {
|
||||
if (this.mode === EngineConst.Mode.HTTP && !this.config) {
|
||||
configBlocks(feature);
|
||||
this.config = true;
|
||||
}
|
||||
configFeature(feature);
|
||||
}
|
||||
setCustomLoader(fn) {
|
||||
if (fn) {
|
||||
this.customLoader = fn;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.Engine = Engine;
|
||||
Engine.BINARY_FEATURES = [
|
||||
'automark',
|
||||
'mark',
|
||||
'character',
|
||||
'cleanpause',
|
||||
'strict',
|
||||
'structure',
|
||||
'aria',
|
||||
'pprint',
|
||||
'cayleyshort',
|
||||
'linebreaks'
|
||||
];
|
||||
Engine.STRING_FEATURES = [
|
||||
'markup',
|
||||
'style',
|
||||
'domain',
|
||||
'speech',
|
||||
'walker',
|
||||
'defaultLocale',
|
||||
'locale',
|
||||
'delay',
|
||||
'modality',
|
||||
'rate',
|
||||
'rules',
|
||||
'subiso',
|
||||
'prune'
|
||||
];
|
||||
Engine.nodeEvaluator = function (_node) {
|
||||
return [];
|
||||
};
|
||||
exports.default = Engine;
|
||||
function configFeature(feature) {
|
||||
if (typeof SREfeature !== 'undefined') {
|
||||
for (const [name, feat] of Object.entries(SREfeature)) {
|
||||
feature[name] = feat;
|
||||
}
|
||||
}
|
||||
}
|
||||
function configBlocks(feature) {
|
||||
const scripts = document.documentElement.querySelectorAll('script[type="text/x-sre-config"]');
|
||||
for (let i = 0, m = scripts.length; i < m; i++) {
|
||||
let inner;
|
||||
try {
|
||||
inner = scripts[i].innerHTML;
|
||||
const config = JSON.parse(inner);
|
||||
for (const [key, val] of Object.entries(config)) {
|
||||
feature[key] = val;
|
||||
}
|
||||
}
|
||||
catch (_err) {
|
||||
debugger_js_1.Debugger.getInstance().output('Illegal configuration ', inner);
|
||||
}
|
||||
}
|
||||
}
|
||||
class EnginePromise {
|
||||
static get(locale = Engine.getInstance().locale) {
|
||||
return EnginePromise.promises[locale] || Promise.resolve('');
|
||||
}
|
||||
static getall() {
|
||||
return Promise.all(Object.values(EnginePromise.promises));
|
||||
}
|
||||
}
|
||||
exports.EnginePromise = EnginePromise;
|
||||
EnginePromise.loaded = {};
|
||||
EnginePromise.promises = {};
|
||||
32
node_modules/speech-rule-engine/js/common/engine_const.d.ts
generated
vendored
Normal file
32
node_modules/speech-rule-engine/js/common/engine_const.d.ts
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
export declare enum Mode {
|
||||
SYNC = "sync",
|
||||
ASYNC = "async",
|
||||
HTTP = "http"
|
||||
}
|
||||
export declare enum personalityProps {
|
||||
PITCH = "pitch",
|
||||
RATE = "rate",
|
||||
VOLUME = "volume",
|
||||
PAUSE = "pause",
|
||||
JOIN = "join",
|
||||
LAYOUT = "layout"
|
||||
}
|
||||
export declare const personalityPropList: personalityProps[];
|
||||
export declare enum Speech {
|
||||
NONE = "none",
|
||||
SHALLOW = "shallow",
|
||||
DEEP = "deep"
|
||||
}
|
||||
export declare enum Markup {
|
||||
NONE = "none",
|
||||
LAYOUT = "layout",
|
||||
COUNTING = "counting",
|
||||
PUNCTUATION = "punctuation",
|
||||
SSML = "ssml",
|
||||
ACSS = "acss",
|
||||
SABLE = "sable",
|
||||
VOICEXML = "voicexml"
|
||||
}
|
||||
export declare const DOMAIN_TO_STYLES: {
|
||||
[key: string]: string;
|
||||
};
|
||||
46
node_modules/speech-rule-engine/js/common/engine_const.js
generated
vendored
Normal file
46
node_modules/speech-rule-engine/js/common/engine_const.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DOMAIN_TO_STYLES = exports.Markup = exports.Speech = exports.personalityPropList = exports.personalityProps = exports.Mode = void 0;
|
||||
var Mode;
|
||||
(function (Mode) {
|
||||
Mode["SYNC"] = "sync";
|
||||
Mode["ASYNC"] = "async";
|
||||
Mode["HTTP"] = "http";
|
||||
})(Mode || (exports.Mode = Mode = {}));
|
||||
var personalityProps;
|
||||
(function (personalityProps) {
|
||||
personalityProps["PITCH"] = "pitch";
|
||||
personalityProps["RATE"] = "rate";
|
||||
personalityProps["VOLUME"] = "volume";
|
||||
personalityProps["PAUSE"] = "pause";
|
||||
personalityProps["JOIN"] = "join";
|
||||
personalityProps["LAYOUT"] = "layout";
|
||||
})(personalityProps || (exports.personalityProps = personalityProps = {}));
|
||||
exports.personalityPropList = [
|
||||
personalityProps.PITCH,
|
||||
personalityProps.RATE,
|
||||
personalityProps.VOLUME,
|
||||
personalityProps.PAUSE,
|
||||
personalityProps.JOIN
|
||||
];
|
||||
var Speech;
|
||||
(function (Speech) {
|
||||
Speech["NONE"] = "none";
|
||||
Speech["SHALLOW"] = "shallow";
|
||||
Speech["DEEP"] = "deep";
|
||||
})(Speech || (exports.Speech = Speech = {}));
|
||||
var Markup;
|
||||
(function (Markup) {
|
||||
Markup["NONE"] = "none";
|
||||
Markup["LAYOUT"] = "layout";
|
||||
Markup["COUNTING"] = "counting";
|
||||
Markup["PUNCTUATION"] = "punctuation";
|
||||
Markup["SSML"] = "ssml";
|
||||
Markup["ACSS"] = "acss";
|
||||
Markup["SABLE"] = "sable";
|
||||
Markup["VOICEXML"] = "voicexml";
|
||||
})(Markup || (exports.Markup = Markup = {}));
|
||||
exports.DOMAIN_TO_STYLES = {
|
||||
mathspeak: 'default',
|
||||
clearspeak: 'default'
|
||||
};
|
||||
3
node_modules/speech-rule-engine/js/common/engine_setup.d.ts
generated
vendored
Normal file
3
node_modules/speech-rule-engine/js/common/engine_setup.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export declare function setup(feature: {
|
||||
[key: string]: boolean | string;
|
||||
}): Promise<string>;
|
||||
108
node_modules/speech-rule-engine/js/common/engine_setup.js
generated
vendored
Normal file
108
node_modules/speech-rule-engine/js/common/engine_setup.js
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.setup = setup;
|
||||
const L10n = require("../l10n/l10n.js");
|
||||
const MathMap = require("../speech_rules/math_map.js");
|
||||
const BrowserUtil = require("./browser_util.js");
|
||||
const debugger_js_1 = require("./debugger.js");
|
||||
const engine_js_1 = require("./engine.js");
|
||||
const FileUtil = require("./file_util.js");
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
const MATHSPEAK_ONLY = ['ca', 'da', 'es'];
|
||||
const EN_RULES = [
|
||||
'chromevox',
|
||||
'clearspeak',
|
||||
'mathspeak',
|
||||
'emacspeak',
|
||||
'html'
|
||||
];
|
||||
function ensureDomain(feature) {
|
||||
if ((feature.modality && feature.modality !== 'speech') ||
|
||||
(!feature.modality && engine_js_1.Engine.getInstance().modality !== 'speech')) {
|
||||
return;
|
||||
}
|
||||
if (!feature.domain) {
|
||||
return;
|
||||
}
|
||||
if (feature.domain === 'default') {
|
||||
feature.domain = 'mathspeak';
|
||||
return;
|
||||
}
|
||||
const locale = (feature.locale || engine_js_1.Engine.getInstance().locale);
|
||||
const domain = feature.domain;
|
||||
if (MATHSPEAK_ONLY.indexOf(locale) !== -1) {
|
||||
if (domain !== 'mathspeak') {
|
||||
feature.domain = 'mathspeak';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (locale === 'en') {
|
||||
if (EN_RULES.indexOf(domain) === -1) {
|
||||
feature.domain = 'mathspeak';
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (domain !== 'mathspeak' && domain !== 'clearspeak') {
|
||||
feature.domain = 'mathspeak';
|
||||
}
|
||||
}
|
||||
function setup(feature) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
ensureDomain(feature);
|
||||
const engine = engine_js_1.Engine.getInstance();
|
||||
const setIf = (feat) => {
|
||||
if (typeof feature[feat] !== 'undefined') {
|
||||
engine[feat] = !!feature[feat];
|
||||
}
|
||||
};
|
||||
const setMulti = (feat) => {
|
||||
if (typeof feature[feat] !== 'undefined') {
|
||||
engine[feat] = feature[feat];
|
||||
}
|
||||
};
|
||||
setMulti('mode');
|
||||
engine.configurate(feature);
|
||||
engine_js_1.Engine.BINARY_FEATURES.forEach(setIf);
|
||||
engine_js_1.Engine.STRING_FEATURES.forEach(setMulti);
|
||||
if (feature.debug) {
|
||||
debugger_js_1.Debugger.getInstance().init();
|
||||
}
|
||||
if (feature.json) {
|
||||
system_external_js_1.SystemExternal.jsonPath = FileUtil.makePath(feature.json);
|
||||
}
|
||||
if (feature.xpath) {
|
||||
system_external_js_1.SystemExternal.WGXpath = feature.xpath;
|
||||
}
|
||||
engine.setCustomLoader(feature.custom);
|
||||
setupBrowsers(engine);
|
||||
L10n.setLocale();
|
||||
engine.setDynamicCstr();
|
||||
if (engine.init) {
|
||||
engine_js_1.EnginePromise.promises['init'] = new Promise((res, _rej) => {
|
||||
setTimeout(() => {
|
||||
res('init');
|
||||
}, 10);
|
||||
});
|
||||
engine.init = false;
|
||||
return engine_js_1.EnginePromise.get();
|
||||
}
|
||||
if (engine.delay) {
|
||||
engine.delay = false;
|
||||
return engine_js_1.EnginePromise.get();
|
||||
}
|
||||
return MathMap.loadLocale();
|
||||
});
|
||||
}
|
||||
function setupBrowsers(engine) {
|
||||
engine.isIE = BrowserUtil.detectIE();
|
||||
engine.isEdge = BrowserUtil.detectEdge();
|
||||
}
|
||||
80
node_modules/speech-rule-engine/js/common/event_util.d.ts
generated
vendored
Normal file
80
node_modules/speech-rule-engine/js/common/event_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
export declare enum KeyCode {
|
||||
ENTER = 13,
|
||||
ESC = 27,
|
||||
SPACE = 32,
|
||||
PAGE_UP = 33,
|
||||
PAGE_DOWN = 34,
|
||||
END = 35,
|
||||
HOME = 36,
|
||||
LEFT = 37,
|
||||
UP = 38,
|
||||
RIGHT = 39,
|
||||
DOWN = 40,
|
||||
TAB = 9,
|
||||
LESS = 188,
|
||||
GREATER = 190,
|
||||
DASH = 189,
|
||||
ZERO = 48,
|
||||
ONE = 49,
|
||||
TWO = 50,
|
||||
THREE = 51,
|
||||
FOUR = 52,
|
||||
FIVE = 53,
|
||||
SIX = 54,
|
||||
SEVEN = 55,
|
||||
EIGHT = 56,
|
||||
NINE = 57,
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90
|
||||
}
|
||||
export declare const Move: Map<number, string>;
|
||||
declare enum EventType {
|
||||
CLICK = "click",
|
||||
DBLCLICK = "dblclick",
|
||||
MOUSEDOWN = "mousedown",
|
||||
MOUSEUP = "mouseup",
|
||||
MOUSEOVER = "mouseover",
|
||||
MOUSEOUT = "mouseout",
|
||||
MOUSEMOVE = "mousemove",
|
||||
SELECTSTART = "selectstart",
|
||||
KEYPRESS = "keypress",
|
||||
KEYDOWN = "keydown",
|
||||
KEYUP = "keyup",
|
||||
TOUCHSTART = "touchstart",
|
||||
TOUCHMOVE = "touchmove",
|
||||
TOUCHEND = "touchend",
|
||||
TOUCHCANCEL = "touchcancel"
|
||||
}
|
||||
export declare class Event {
|
||||
src: Node;
|
||||
type: EventType;
|
||||
callback: EventListener;
|
||||
constructor(src: Node, type: EventType, callback: EventListener);
|
||||
add(): void;
|
||||
remove(): void;
|
||||
}
|
||||
export {};
|
||||
142
node_modules/speech-rule-engine/js/common/event_util.js
generated
vendored
Normal file
142
node_modules/speech-rule-engine/js/common/event_util.js
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Event = exports.Move = exports.KeyCode = void 0;
|
||||
var KeyCode;
|
||||
(function (KeyCode) {
|
||||
KeyCode[KeyCode["ENTER"] = 13] = "ENTER";
|
||||
KeyCode[KeyCode["ESC"] = 27] = "ESC";
|
||||
KeyCode[KeyCode["SPACE"] = 32] = "SPACE";
|
||||
KeyCode[KeyCode["PAGE_UP"] = 33] = "PAGE_UP";
|
||||
KeyCode[KeyCode["PAGE_DOWN"] = 34] = "PAGE_DOWN";
|
||||
KeyCode[KeyCode["END"] = 35] = "END";
|
||||
KeyCode[KeyCode["HOME"] = 36] = "HOME";
|
||||
KeyCode[KeyCode["LEFT"] = 37] = "LEFT";
|
||||
KeyCode[KeyCode["UP"] = 38] = "UP";
|
||||
KeyCode[KeyCode["RIGHT"] = 39] = "RIGHT";
|
||||
KeyCode[KeyCode["DOWN"] = 40] = "DOWN";
|
||||
KeyCode[KeyCode["TAB"] = 9] = "TAB";
|
||||
KeyCode[KeyCode["LESS"] = 188] = "LESS";
|
||||
KeyCode[KeyCode["GREATER"] = 190] = "GREATER";
|
||||
KeyCode[KeyCode["DASH"] = 189] = "DASH";
|
||||
KeyCode[KeyCode["ZERO"] = 48] = "ZERO";
|
||||
KeyCode[KeyCode["ONE"] = 49] = "ONE";
|
||||
KeyCode[KeyCode["TWO"] = 50] = "TWO";
|
||||
KeyCode[KeyCode["THREE"] = 51] = "THREE";
|
||||
KeyCode[KeyCode["FOUR"] = 52] = "FOUR";
|
||||
KeyCode[KeyCode["FIVE"] = 53] = "FIVE";
|
||||
KeyCode[KeyCode["SIX"] = 54] = "SIX";
|
||||
KeyCode[KeyCode["SEVEN"] = 55] = "SEVEN";
|
||||
KeyCode[KeyCode["EIGHT"] = 56] = "EIGHT";
|
||||
KeyCode[KeyCode["NINE"] = 57] = "NINE";
|
||||
KeyCode[KeyCode["A"] = 65] = "A";
|
||||
KeyCode[KeyCode["B"] = 66] = "B";
|
||||
KeyCode[KeyCode["C"] = 67] = "C";
|
||||
KeyCode[KeyCode["D"] = 68] = "D";
|
||||
KeyCode[KeyCode["E"] = 69] = "E";
|
||||
KeyCode[KeyCode["F"] = 70] = "F";
|
||||
KeyCode[KeyCode["G"] = 71] = "G";
|
||||
KeyCode[KeyCode["H"] = 72] = "H";
|
||||
KeyCode[KeyCode["I"] = 73] = "I";
|
||||
KeyCode[KeyCode["J"] = 74] = "J";
|
||||
KeyCode[KeyCode["K"] = 75] = "K";
|
||||
KeyCode[KeyCode["L"] = 76] = "L";
|
||||
KeyCode[KeyCode["M"] = 77] = "M";
|
||||
KeyCode[KeyCode["N"] = 78] = "N";
|
||||
KeyCode[KeyCode["O"] = 79] = "O";
|
||||
KeyCode[KeyCode["P"] = 80] = "P";
|
||||
KeyCode[KeyCode["Q"] = 81] = "Q";
|
||||
KeyCode[KeyCode["R"] = 82] = "R";
|
||||
KeyCode[KeyCode["S"] = 83] = "S";
|
||||
KeyCode[KeyCode["T"] = 84] = "T";
|
||||
KeyCode[KeyCode["U"] = 85] = "U";
|
||||
KeyCode[KeyCode["V"] = 86] = "V";
|
||||
KeyCode[KeyCode["W"] = 87] = "W";
|
||||
KeyCode[KeyCode["X"] = 88] = "X";
|
||||
KeyCode[KeyCode["Y"] = 89] = "Y";
|
||||
KeyCode[KeyCode["Z"] = 90] = "Z";
|
||||
})(KeyCode || (exports.KeyCode = KeyCode = {}));
|
||||
exports.Move = new Map([
|
||||
[13, 'ENTER'],
|
||||
[27, 'ESC'],
|
||||
[32, 'SPACE'],
|
||||
[33, 'PAGE_UP'],
|
||||
[34, 'PAGE_DOWN'],
|
||||
[35, 'END'],
|
||||
[36, 'HOME'],
|
||||
[37, 'LEFT'],
|
||||
[38, 'UP'],
|
||||
[39, 'RIGHT'],
|
||||
[40, 'DOWN'],
|
||||
[9, 'TAB'],
|
||||
[188, 'LESS'],
|
||||
[190, 'GREATER'],
|
||||
[189, 'DASH'],
|
||||
[48, 'ZERO'],
|
||||
[49, 'ONE'],
|
||||
[50, 'TWO'],
|
||||
[51, 'THREE'],
|
||||
[52, 'FOUR'],
|
||||
[53, 'FIVE'],
|
||||
[54, 'SIX'],
|
||||
[55, 'SEVEN'],
|
||||
[56, 'EIGHT'],
|
||||
[57, 'NINE'],
|
||||
[65, 'A'],
|
||||
[66, 'B'],
|
||||
[67, 'C'],
|
||||
[68, 'D'],
|
||||
[69, 'E'],
|
||||
[70, 'F'],
|
||||
[71, 'G'],
|
||||
[72, 'H'],
|
||||
[73, 'I'],
|
||||
[74, 'J'],
|
||||
[75, 'K'],
|
||||
[76, 'L'],
|
||||
[77, 'M'],
|
||||
[78, 'N'],
|
||||
[79, 'O'],
|
||||
[80, 'P'],
|
||||
[81, 'Q'],
|
||||
[82, 'R'],
|
||||
[83, 'S'],
|
||||
[84, 'T'],
|
||||
[85, 'U'],
|
||||
[86, 'V'],
|
||||
[87, 'W'],
|
||||
[88, 'X'],
|
||||
[89, 'Y'],
|
||||
[90, 'Z']
|
||||
]);
|
||||
var EventType;
|
||||
(function (EventType) {
|
||||
EventType["CLICK"] = "click";
|
||||
EventType["DBLCLICK"] = "dblclick";
|
||||
EventType["MOUSEDOWN"] = "mousedown";
|
||||
EventType["MOUSEUP"] = "mouseup";
|
||||
EventType["MOUSEOVER"] = "mouseover";
|
||||
EventType["MOUSEOUT"] = "mouseout";
|
||||
EventType["MOUSEMOVE"] = "mousemove";
|
||||
EventType["SELECTSTART"] = "selectstart";
|
||||
EventType["KEYPRESS"] = "keypress";
|
||||
EventType["KEYDOWN"] = "keydown";
|
||||
EventType["KEYUP"] = "keyup";
|
||||
EventType["TOUCHSTART"] = "touchstart";
|
||||
EventType["TOUCHMOVE"] = "touchmove";
|
||||
EventType["TOUCHEND"] = "touchend";
|
||||
EventType["TOUCHCANCEL"] = "touchcancel";
|
||||
})(EventType || (EventType = {}));
|
||||
class Event {
|
||||
constructor(src, type, callback) {
|
||||
this.src = src;
|
||||
this.type = type;
|
||||
this.callback = callback;
|
||||
}
|
||||
add() {
|
||||
this.src.addEventListener(this.type, this.callback);
|
||||
}
|
||||
remove() {
|
||||
this.src.removeEventListener(this.type, this.callback);
|
||||
}
|
||||
}
|
||||
exports.Event = Event;
|
||||
2
node_modules/speech-rule-engine/js/common/file_util.d.ts
generated
vendored
Normal file
2
node_modules/speech-rule-engine/js/common/file_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare function makePath(path: string): string;
|
||||
export declare function localePath(locale: string, ext?: string): string;
|
||||
13
node_modules/speech-rule-engine/js/common/file_util.js
generated
vendored
Normal file
13
node_modules/speech-rule-engine/js/common/file_util.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makePath = makePath;
|
||||
exports.localePath = localePath;
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
function makePath(path) {
|
||||
return path.match('/$') ? path : path + '/';
|
||||
}
|
||||
function localePath(locale, ext = 'json') {
|
||||
return (makePath(system_external_js_1.SystemExternal.jsonPath) +
|
||||
locale +
|
||||
(ext.match(/^\./) ? ext : '.' + ext));
|
||||
}
|
||||
1
node_modules/speech-rule-engine/js/common/mathjax.d.ts
generated
vendored
Normal file
1
node_modules/speech-rule-engine/js/common/mathjax.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
22
node_modules/speech-rule-engine/js/common/mathjax.js
generated
vendored
Normal file
22
node_modules/speech-rule-engine/js/common/mathjax.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const engine_js_1 = require("./engine.js");
|
||||
const EngineConst = require("../common/engine_const.js");
|
||||
const System = require("./system.js");
|
||||
(function () {
|
||||
const SIGNAL = MathJax.Callback.Signal('Sre');
|
||||
MathJax.Extension.Sre = {
|
||||
version: System.version,
|
||||
signal: SIGNAL,
|
||||
ConfigSre: function () {
|
||||
engine_js_1.EnginePromise.getall().then(() => MathJax.Callback.Queue(MathJax.Hub.Register.StartupHook('mml Jax Ready', {}), ['Post', MathJax.Hub.Startup.signal, 'Sre Ready']));
|
||||
}
|
||||
};
|
||||
System.setupEngine({
|
||||
mode: EngineConst.Mode.HTTP,
|
||||
json: MathJax.Ajax.config.path['SRE'] + '/mathmaps',
|
||||
xpath: MathJax.Ajax.config.path['SRE'] + '/wgxpath.install.js',
|
||||
semantics: true
|
||||
});
|
||||
MathJax.Extension.Sre.ConfigSre();
|
||||
})();
|
||||
34
node_modules/speech-rule-engine/js/common/processor.d.ts
generated
vendored
Normal file
34
node_modules/speech-rule-engine/js/common/processor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Highlighter } from '../highlighter/highlighter.js';
|
||||
import { SpeechGenerator } from '../speech_generator/speech_generator.js';
|
||||
import { Walker } from '../walker/walker.js';
|
||||
import { KeyCode } from './event_util.js';
|
||||
export declare class Processor<T> {
|
||||
name: string;
|
||||
static LocalState: {
|
||||
walker: Walker;
|
||||
speechGenerator: SpeechGenerator;
|
||||
highlighter: Highlighter;
|
||||
};
|
||||
process: (p1: string) => T;
|
||||
postprocess: (p1: T, p2: string) => T;
|
||||
print: (p1: T) => string;
|
||||
pprint: (p1: T) => string;
|
||||
processor: (p1: string) => T;
|
||||
private static stringify_;
|
||||
constructor(name: string, methods: {
|
||||
processor: (p1: string) => T;
|
||||
postprocessor?: (p1: T, p2: string) => T;
|
||||
print?: (p1: T) => string;
|
||||
pprint?: (p1: T) => string;
|
||||
});
|
||||
}
|
||||
export declare class KeyProcessor<T> extends Processor<T> {
|
||||
key: (p1: KeyCode | string) => KeyCode;
|
||||
private static getKey_;
|
||||
constructor(name: string, methods: {
|
||||
processor: (p1: string) => T;
|
||||
key?: (p1: KeyCode | string) => KeyCode;
|
||||
print?: (p1: T) => string;
|
||||
pprint?: (p1: T) => string;
|
||||
});
|
||||
}
|
||||
37
node_modules/speech-rule-engine/js/common/processor.js
generated
vendored
Normal file
37
node_modules/speech-rule-engine/js/common/processor.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.KeyProcessor = exports.Processor = void 0;
|
||||
const event_util_js_1 = require("./event_util.js");
|
||||
class Processor {
|
||||
static stringify_(x) {
|
||||
return x ? x.toString() : x;
|
||||
}
|
||||
constructor(name, methods) {
|
||||
this.name = name;
|
||||
this.process = methods.processor;
|
||||
this.postprocess =
|
||||
methods.postprocessor || ((x, _y) => x);
|
||||
this.processor = this.postprocess
|
||||
? function (x) {
|
||||
return this.postprocess(this.process(x), x);
|
||||
}
|
||||
: this.process;
|
||||
this.print = methods.print || Processor.stringify_;
|
||||
this.pprint = methods.pprint || this.print;
|
||||
}
|
||||
}
|
||||
exports.Processor = Processor;
|
||||
Processor.LocalState = { walker: null, speechGenerator: null, highlighter: null };
|
||||
class KeyProcessor extends Processor {
|
||||
static getKey_(key) {
|
||||
return typeof key === 'string'
|
||||
?
|
||||
event_util_js_1.KeyCode[key.toUpperCase()]
|
||||
: key;
|
||||
}
|
||||
constructor(name, methods) {
|
||||
super(name, methods);
|
||||
this.key = methods.key || KeyProcessor.getKey_;
|
||||
}
|
||||
}
|
||||
exports.KeyProcessor = KeyProcessor;
|
||||
4
node_modules/speech-rule-engine/js/common/processor_factory.d.ts
generated
vendored
Normal file
4
node_modules/speech-rule-engine/js/common/processor_factory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { KeyCode } from './event_util.js';
|
||||
export declare function process<T>(name: string, expr: string): T;
|
||||
export declare function output(name: string, expr: string): string;
|
||||
export declare function keypress(name: string, expr: KeyCode | string): string;
|
||||
261
node_modules/speech-rule-engine/js/common/processor_factory.js
generated
vendored
Normal file
261
node_modules/speech-rule-engine/js/common/processor_factory.js
generated
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.process = process;
|
||||
exports.output = output;
|
||||
exports.keypress = keypress;
|
||||
const AuralRendering = require("../audio/aural_rendering.js");
|
||||
const Enrich = require("../enrich_mathml/enrich.js");
|
||||
const HighlighterFactory = require("../highlighter/highlighter_factory.js");
|
||||
const locale_js_1 = require("../l10n/locale.js");
|
||||
const Semantic = require("../semantic_tree/semantic.js");
|
||||
const SpeechGeneratorFactory = require("../speech_generator/speech_generator_factory.js");
|
||||
const SpeechGeneratorUtil = require("../speech_generator/speech_generator_util.js");
|
||||
const WalkerFactory = require("../walker/walker_factory.js");
|
||||
const WalkerUtil = require("../walker/walker_util.js");
|
||||
const rebuild_stree_js_1 = require("../walker/rebuild_stree.js");
|
||||
const DomUtil = require("./dom_util.js");
|
||||
const engine_js_1 = require("./engine.js");
|
||||
const EngineConst = require("../common/engine_const.js");
|
||||
const processor_js_1 = require("./processor.js");
|
||||
const XpathUtil = require("./xpath_util.js");
|
||||
const PROCESSORS = new Map();
|
||||
function set(processor) {
|
||||
PROCESSORS.set(processor.name, processor);
|
||||
}
|
||||
function get(name) {
|
||||
const processor = PROCESSORS.get(name);
|
||||
if (!processor) {
|
||||
throw new engine_js_1.SREError('Unknown processor ' + name);
|
||||
}
|
||||
return processor;
|
||||
}
|
||||
function process(name, expr) {
|
||||
const processor = get(name);
|
||||
try {
|
||||
return processor.processor(expr);
|
||||
}
|
||||
catch (_e) {
|
||||
throw new engine_js_1.SREError('Processing error for expression ' + expr);
|
||||
}
|
||||
}
|
||||
function print(name, data) {
|
||||
const processor = get(name);
|
||||
return engine_js_1.Engine.getInstance().pprint
|
||||
? processor.pprint(data)
|
||||
: processor.print(data);
|
||||
}
|
||||
function output(name, expr) {
|
||||
const processor = get(name);
|
||||
try {
|
||||
const data = processor.processor(expr);
|
||||
return engine_js_1.Engine.getInstance().pprint
|
||||
? processor.pprint(data)
|
||||
: processor.print(data);
|
||||
}
|
||||
catch (_e) {
|
||||
console.log(_e);
|
||||
throw new engine_js_1.SREError('Processing error for expression ' + expr);
|
||||
}
|
||||
}
|
||||
function keypress(name, expr) {
|
||||
const processor = get(name);
|
||||
const key = processor instanceof processor_js_1.KeyProcessor ? processor.key(expr) : expr;
|
||||
const data = processor.processor(key);
|
||||
return engine_js_1.Engine.getInstance().pprint
|
||||
? processor.pprint(data)
|
||||
: processor.print(data);
|
||||
}
|
||||
set(new processor_js_1.Processor('semantic', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
return Semantic.xmlTree(mml);
|
||||
},
|
||||
postprocessor: function (xml, _expr) {
|
||||
const setting = engine_js_1.Engine.getInstance().speech;
|
||||
if (setting === EngineConst.Speech.NONE) {
|
||||
return xml;
|
||||
}
|
||||
const clone = DomUtil.cloneNode(xml);
|
||||
let speech = SpeechGeneratorUtil.computeMarkup(clone);
|
||||
if (setting === EngineConst.Speech.SHALLOW) {
|
||||
xml.setAttribute('speech', AuralRendering.finalize(speech));
|
||||
return xml;
|
||||
}
|
||||
const nodesXml = XpathUtil.evalXPath('.//*[@id]', xml);
|
||||
const nodesClone = XpathUtil.evalXPath('.//*[@id]', clone);
|
||||
for (let i = 0, orig, node; (orig = nodesXml[i]), (node = nodesClone[i]); i++) {
|
||||
speech = SpeechGeneratorUtil.computeMarkup(node);
|
||||
orig.setAttribute('speech', AuralRendering.finalize(speech));
|
||||
}
|
||||
return xml;
|
||||
},
|
||||
pprint: function (tree) {
|
||||
return DomUtil.formatXml(tree.toString());
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('speech', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const xml = Semantic.xmlTree(mml);
|
||||
const descrs = SpeechGeneratorUtil.computeSpeech(xml);
|
||||
return AuralRendering.finalize(AuralRendering.markup(descrs));
|
||||
},
|
||||
pprint: function (speech) {
|
||||
const str = speech.toString();
|
||||
return AuralRendering.isXml() ? DomUtil.formatXml(str) : str;
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('json', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const stree = Semantic.getTree(mml);
|
||||
return stree.toJson();
|
||||
},
|
||||
postprocessor: function (json, expr) {
|
||||
const setting = engine_js_1.Engine.getInstance().speech;
|
||||
if (setting === EngineConst.Speech.NONE) {
|
||||
return json;
|
||||
}
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const xml = Semantic.xmlTree(mml);
|
||||
const speech = SpeechGeneratorUtil.computeMarkup(xml);
|
||||
if (setting === EngineConst.Speech.SHALLOW) {
|
||||
json.stree.speech = AuralRendering.finalize(speech);
|
||||
return json;
|
||||
}
|
||||
const addRec = (json) => {
|
||||
const node = XpathUtil.evalXPath(`.//*[@id=${json.id}]`, xml)[0];
|
||||
const speech = SpeechGeneratorUtil.computeMarkup(node);
|
||||
json.speech = AuralRendering.finalize(speech);
|
||||
if (json.children) {
|
||||
json.children.forEach(addRec);
|
||||
}
|
||||
};
|
||||
addRec(json.stree);
|
||||
return json;
|
||||
},
|
||||
print: function (json) {
|
||||
return JSON.stringify(json);
|
||||
},
|
||||
pprint: function (json) {
|
||||
return JSON.stringify(json, null, 2);
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('description', {
|
||||
processor: function (expr) {
|
||||
const mml = DomUtil.parseInput(expr);
|
||||
const xml = Semantic.xmlTree(mml);
|
||||
const descrs = SpeechGeneratorUtil.computeSpeech(xml);
|
||||
return descrs;
|
||||
},
|
||||
print: function (descrs) {
|
||||
return JSON.stringify(descrs);
|
||||
},
|
||||
pprint: function (descrs) {
|
||||
return JSON.stringify(descrs, null, 2);
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('enriched', {
|
||||
processor: function (expr) {
|
||||
return Enrich.semanticMathmlSync(expr);
|
||||
},
|
||||
postprocessor: function (enr, _expr) {
|
||||
const root = WalkerUtil.getSemanticRoot(enr);
|
||||
let generator;
|
||||
switch (engine_js_1.Engine.getInstance().speech) {
|
||||
case EngineConst.Speech.NONE:
|
||||
break;
|
||||
case EngineConst.Speech.SHALLOW:
|
||||
generator = SpeechGeneratorFactory.generator('Adhoc');
|
||||
generator.getSpeech(root, enr);
|
||||
break;
|
||||
case EngineConst.Speech.DEEP:
|
||||
generator = SpeechGeneratorFactory.generator('Tree');
|
||||
generator.getSpeech(enr, enr);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return enr;
|
||||
},
|
||||
pprint: function (tree) {
|
||||
return DomUtil.formatXml(tree.toString());
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('rebuild', {
|
||||
processor: function (expr) {
|
||||
const rebuilt = new rebuild_stree_js_1.RebuildStree(DomUtil.parseInput(expr));
|
||||
return rebuilt.stree.xml();
|
||||
},
|
||||
pprint: function (tree) {
|
||||
return DomUtil.formatXml(tree.toString());
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('walker', {
|
||||
processor: function (expr) {
|
||||
const generator = SpeechGeneratorFactory.generator('Node');
|
||||
processor_js_1.Processor.LocalState.speechGenerator = generator;
|
||||
generator.setOptions({
|
||||
modality: engine_js_1.Engine.getInstance().modality,
|
||||
locale: engine_js_1.Engine.getInstance().locale,
|
||||
domain: engine_js_1.Engine.getInstance().domain,
|
||||
style: engine_js_1.Engine.getInstance().style
|
||||
});
|
||||
processor_js_1.Processor.LocalState.highlighter = HighlighterFactory.highlighter({ color: 'black' }, { color: 'white' }, { renderer: 'NativeMML' });
|
||||
const node = process('enriched', expr);
|
||||
const eml = print('enriched', node);
|
||||
processor_js_1.Processor.LocalState.walker = WalkerFactory.walker(engine_js_1.Engine.getInstance().walker, node, generator, processor_js_1.Processor.LocalState.highlighter, eml);
|
||||
return processor_js_1.Processor.LocalState.walker;
|
||||
},
|
||||
print: function (_walker) {
|
||||
return processor_js_1.Processor.LocalState.walker.speech();
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.KeyProcessor('move', {
|
||||
processor: function (direction) {
|
||||
if (!processor_js_1.Processor.LocalState.walker) {
|
||||
return null;
|
||||
}
|
||||
const move = processor_js_1.Processor.LocalState.walker.move(direction);
|
||||
return move === false
|
||||
? AuralRendering.error(direction)
|
||||
: processor_js_1.Processor.LocalState.walker.speech();
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('number', {
|
||||
processor: function (numb) {
|
||||
const num = parseInt(numb, 10);
|
||||
return isNaN(num) ? '' : locale_js_1.LOCALE.NUMBERS.numberToWords(num);
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('ordinal', {
|
||||
processor: function (numb) {
|
||||
const num = parseInt(numb, 10);
|
||||
return isNaN(num) ? '' : locale_js_1.LOCALE.NUMBERS.wordOrdinal(num);
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('numericOrdinal', {
|
||||
processor: function (numb) {
|
||||
const num = parseInt(numb, 10);
|
||||
return isNaN(num) ? '' : locale_js_1.LOCALE.NUMBERS.numericOrdinal(num);
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('vulgar', {
|
||||
processor: function (numb) {
|
||||
const [en, den] = numb.split('/').map((x) => parseInt(x, 10));
|
||||
return isNaN(en) || isNaN(den)
|
||||
? ''
|
||||
: process('speech', `<mfrac><mn>${en}</mn><mn>${den}</mn></mfrac>`);
|
||||
}
|
||||
}));
|
||||
set(new processor_js_1.Processor('latex', {
|
||||
processor: function (ltx) {
|
||||
if (engine_js_1.Engine.getInstance().modality !== 'braille' ||
|
||||
engine_js_1.Engine.getInstance().locale !== 'euro') {
|
||||
console.info('LaTeX input currently only works for Euro Braille output.' +
|
||||
' Please use the latex-to-speech package from npm for general' +
|
||||
' LaTeX input to SRE.');
|
||||
}
|
||||
return process('speech', `<math data-latex="${ltx}"></math>`);
|
||||
}
|
||||
}));
|
||||
28
node_modules/speech-rule-engine/js/common/system.d.ts
generated
vendored
Normal file
28
node_modules/speech-rule-engine/js/common/system.d.ts
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { AuditoryDescription } from '../audio/auditory_description.js';
|
||||
import { KeyCode } from './event_util.js';
|
||||
import * as FileUtil from './file_util.js';
|
||||
import { standardLoader } from '../speech_rules/math_map.js';
|
||||
export declare const version: string;
|
||||
export declare function setupEngine(feature: {
|
||||
[key: string]: boolean | string;
|
||||
}): Promise<string>;
|
||||
export declare function engineSetup(): {
|
||||
[key: string]: boolean | string;
|
||||
};
|
||||
export declare function engineReady(): Promise<any>;
|
||||
export declare const localeLoader: typeof standardLoader;
|
||||
export declare function toSpeech(expr: string): string;
|
||||
export declare function toSemantic(expr: string): Node;
|
||||
export declare function toJson(expr: string): any;
|
||||
export declare function toDescription(expr: string): AuditoryDescription[];
|
||||
export declare function toEnriched(expr: string): Element;
|
||||
export declare function number(expr: string): string;
|
||||
export declare function ordinal(expr: string): string;
|
||||
export declare function numericOrdinal(expr: string): string;
|
||||
export declare function vulgar(expr: string): string;
|
||||
export declare const file: Record<string, (input: string, output?: string) => any>;
|
||||
export declare function processFile(processor: string, input: string, opt_output?: string): string | Promise<string>;
|
||||
export declare function walk(expr: string): string;
|
||||
export declare function move(direction: KeyCode | string): string | null;
|
||||
export declare function exit(opt_value?: number): void;
|
||||
export declare const localePath: typeof FileUtil.localePath;
|
||||
173
node_modules/speech-rule-engine/js/common/system.js
generated
vendored
Normal file
173
node_modules/speech-rule-engine/js/common/system.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.localePath = exports.file = exports.localeLoader = exports.version = void 0;
|
||||
exports.setupEngine = setupEngine;
|
||||
exports.engineSetup = engineSetup;
|
||||
exports.engineReady = engineReady;
|
||||
exports.toSpeech = toSpeech;
|
||||
exports.toSemantic = toSemantic;
|
||||
exports.toJson = toJson;
|
||||
exports.toDescription = toDescription;
|
||||
exports.toEnriched = toEnriched;
|
||||
exports.number = number;
|
||||
exports.ordinal = ordinal;
|
||||
exports.numericOrdinal = numericOrdinal;
|
||||
exports.vulgar = vulgar;
|
||||
exports.processFile = processFile;
|
||||
exports.walk = walk;
|
||||
exports.move = move;
|
||||
exports.exit = exit;
|
||||
const engine_js_1 = require("./engine.js");
|
||||
const engine_setup_js_1 = require("./engine_setup.js");
|
||||
const EngineConst = require("./engine_const.js");
|
||||
const FileUtil = require("./file_util.js");
|
||||
const ProcessorFactory = require("./processor_factory.js");
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
const variables_js_1 = require("./variables.js");
|
||||
const math_map_js_1 = require("../speech_rules/math_map.js");
|
||||
exports.version = variables_js_1.Variables.VERSION;
|
||||
function setupEngine(feature) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return (0, engine_setup_js_1.setup)(feature);
|
||||
});
|
||||
}
|
||||
function engineSetup() {
|
||||
const engineFeatures = ['mode'].concat(engine_js_1.Engine.STRING_FEATURES, engine_js_1.Engine.BINARY_FEATURES);
|
||||
const engine = engine_js_1.Engine.getInstance();
|
||||
const features = {};
|
||||
engineFeatures.forEach(function (x) {
|
||||
features[x] = engine[x];
|
||||
});
|
||||
features.json = system_external_js_1.SystemExternal.jsonPath;
|
||||
features.xpath = system_external_js_1.SystemExternal.WGXpath;
|
||||
features.rules = engine.ruleSets.slice();
|
||||
return features;
|
||||
}
|
||||
function engineReady() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
return setupEngine({}).then(() => engine_js_1.EnginePromise.getall());
|
||||
});
|
||||
}
|
||||
exports.localeLoader = math_map_js_1.standardLoader;
|
||||
function toSpeech(expr) {
|
||||
return processString('speech', expr);
|
||||
}
|
||||
function toSemantic(expr) {
|
||||
return processString('semantic', expr);
|
||||
}
|
||||
function toJson(expr) {
|
||||
return processString('json', expr);
|
||||
}
|
||||
function toDescription(expr) {
|
||||
return processString('description', expr);
|
||||
}
|
||||
function toEnriched(expr) {
|
||||
return processString('enriched', expr);
|
||||
}
|
||||
function number(expr) {
|
||||
return processString('number', expr);
|
||||
}
|
||||
function ordinal(expr) {
|
||||
return processString('ordinal', expr);
|
||||
}
|
||||
function numericOrdinal(expr) {
|
||||
return processString('numericOrdinal', expr);
|
||||
}
|
||||
function vulgar(expr) {
|
||||
return processString('vulgar', expr);
|
||||
}
|
||||
function processString(processor, input) {
|
||||
return ProcessorFactory.process(processor, input);
|
||||
}
|
||||
exports.file = {};
|
||||
exports.file.toSpeech = function (input, opt_output) {
|
||||
return processFile('speech', input, opt_output);
|
||||
};
|
||||
exports.file.toSemantic = function (input, opt_output) {
|
||||
return processFile('semantic', input, opt_output);
|
||||
};
|
||||
exports.file.toJson = function (input, opt_output) {
|
||||
return processFile('json', input, opt_output);
|
||||
};
|
||||
exports.file.toDescription = function (input, opt_output) {
|
||||
return processFile('description', input, opt_output);
|
||||
};
|
||||
exports.file.toEnriched = function (input, opt_output) {
|
||||
return processFile('enriched', input, opt_output);
|
||||
};
|
||||
function processFile(processor, input, opt_output) {
|
||||
switch (engine_js_1.Engine.getInstance().mode) {
|
||||
case EngineConst.Mode.ASYNC:
|
||||
return processFileAsync(processor, input, opt_output);
|
||||
case EngineConst.Mode.SYNC:
|
||||
return processFileSync(processor, input, opt_output);
|
||||
default:
|
||||
throw new engine_js_1.SREError(`Can process files in ${engine_js_1.Engine.getInstance().mode} mode`);
|
||||
}
|
||||
}
|
||||
function processFileSync(processor, input, opt_output) {
|
||||
const expr = inputFileSync_(input);
|
||||
const result = ProcessorFactory.output(processor, expr);
|
||||
if (opt_output) {
|
||||
try {
|
||||
system_external_js_1.SystemExternal.fs.writeFileSync(opt_output, result);
|
||||
}
|
||||
catch (_err) {
|
||||
throw new engine_js_1.SREError('Can not write to file: ' + opt_output);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function inputFileSync_(file) {
|
||||
let expr;
|
||||
try {
|
||||
expr = system_external_js_1.SystemExternal.fs.readFileSync(file, { encoding: 'utf8' });
|
||||
}
|
||||
catch (_err) {
|
||||
throw new engine_js_1.SREError('Can not open file: ' + file);
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
function processFileAsync(processor, file, output) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const expr = yield system_external_js_1.SystemExternal.fs.promises.readFile(file, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
const result = ProcessorFactory.output(processor, expr);
|
||||
if (output) {
|
||||
try {
|
||||
system_external_js_1.SystemExternal.fs.promises.writeFile(output, result);
|
||||
}
|
||||
catch (_err) {
|
||||
throw new engine_js_1.SREError('Can not write to file: ' + output);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
}
|
||||
function walk(expr) {
|
||||
return ProcessorFactory.output('walker', expr);
|
||||
}
|
||||
function move(direction) {
|
||||
return ProcessorFactory.keypress('move', direction);
|
||||
}
|
||||
function exit(opt_value) {
|
||||
const value = opt_value || 0;
|
||||
engine_js_1.EnginePromise.getall().then(() => process.exit(value));
|
||||
}
|
||||
exports.localePath = FileUtil.localePath;
|
||||
if (system_external_js_1.SystemExternal.documentSupported) {
|
||||
setupEngine({ mode: EngineConst.Mode.HTTP }).then(() => setupEngine({}));
|
||||
}
|
||||
else {
|
||||
setupEngine({ mode: EngineConst.Mode.SYNC }).then(() => setupEngine({ mode: EngineConst.Mode.ASYNC }));
|
||||
}
|
||||
16
node_modules/speech-rule-engine/js/common/system_external.d.ts
generated
vendored
Normal file
16
node_modules/speech-rule-engine/js/common/system_external.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export declare class SystemExternal {
|
||||
static nodeRequire(): any;
|
||||
static extRequire(library: string): any;
|
||||
static windowSupported: boolean;
|
||||
static documentSupported: boolean;
|
||||
static xmldom: any;
|
||||
static document: Document;
|
||||
static xpath: any;
|
||||
static mathmapsIePath: string;
|
||||
static fs: any;
|
||||
static url: string;
|
||||
static jsonPath: any;
|
||||
static WGXpath: string;
|
||||
static wgxpath: any;
|
||||
}
|
||||
export default SystemExternal;
|
||||
67
node_modules/speech-rule-engine/js/common/system_external.js
generated
vendored
Normal file
67
node_modules/speech-rule-engine/js/common/system_external.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.SystemExternal = void 0;
|
||||
const variables_js_1 = require("./variables.js");
|
||||
class SystemExternal {
|
||||
static nodeRequire() {
|
||||
return eval('require');
|
||||
}
|
||||
static extRequire(library) {
|
||||
if (typeof process !== 'undefined' && typeof require !== 'undefined') {
|
||||
return SystemExternal.nodeRequire()(library);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
exports.SystemExternal = SystemExternal;
|
||||
SystemExternal.windowSupported = (() => !(typeof window === 'undefined'))();
|
||||
SystemExternal.documentSupported = (() => SystemExternal.windowSupported &&
|
||||
!(typeof window.document === 'undefined'))();
|
||||
SystemExternal.xmldom = SystemExternal.documentSupported
|
||||
? window
|
||||
: SystemExternal.extRequire('@xmldom/xmldom');
|
||||
SystemExternal.document = SystemExternal.documentSupported
|
||||
? window.document
|
||||
: new SystemExternal.xmldom.DOMImplementation().createDocument('', '', 0);
|
||||
SystemExternal.xpath = SystemExternal.documentSupported
|
||||
? document
|
||||
: (function () {
|
||||
const window = { document: {}, XPathResult: {} };
|
||||
const wgx = SystemExternal.extRequire('wicked-good-xpath');
|
||||
wgx.install(window);
|
||||
window.document.XPathResult = window.XPathResult;
|
||||
return window.document;
|
||||
})();
|
||||
SystemExternal.mathmapsIePath = 'https://cdn.jsdelivr.net/npm/sre-mathmaps-ie@' +
|
||||
variables_js_1.Variables.VERSION +
|
||||
'mathmaps_ie.js';
|
||||
SystemExternal.fs = SystemExternal.documentSupported
|
||||
? null
|
||||
: SystemExternal.extRequire('fs');
|
||||
SystemExternal.url = variables_js_1.Variables.url;
|
||||
SystemExternal.jsonPath = (function () {
|
||||
if (SystemExternal.documentSupported) {
|
||||
return SystemExternal.url;
|
||||
}
|
||||
if (process.env.SRE_JSON_PATH || global.SRE_JSON_PATH) {
|
||||
return process.env.SRE_JSON_PATH || global.SRE_JSON_PATH;
|
||||
}
|
||||
try {
|
||||
const path = SystemExternal.nodeRequire().resolve('speech-rule-engine');
|
||||
return path.replace(/sre\.js$/, '') + 'mathmaps';
|
||||
}
|
||||
catch (_err) {
|
||||
}
|
||||
try {
|
||||
const path = SystemExternal.nodeRequire().resolve('.');
|
||||
return path.replace(/sre\.js$/, '') + 'mathmaps';
|
||||
}
|
||||
catch (_err) {
|
||||
}
|
||||
return typeof __dirname !== 'undefined'
|
||||
? __dirname + (__dirname.match(/lib?$/) ? '/mathmaps' : '/lib/mathmaps')
|
||||
: process.cwd() + '/lib/mathmaps';
|
||||
})();
|
||||
SystemExternal.WGXpath = variables_js_1.Variables.WGXpath;
|
||||
SystemExternal.wgxpath = null;
|
||||
exports.default = SystemExternal;
|
||||
8
node_modules/speech-rule-engine/js/common/variables.d.ts
generated
vendored
Normal file
8
node_modules/speech-rule-engine/js/common/variables.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export declare class Variables {
|
||||
static readonly VERSION: string;
|
||||
static readonly LOCALES: Map<string, string>;
|
||||
static ensureLocale(loc: string, def: string): string;
|
||||
static readonly mathjaxVersion: string;
|
||||
static readonly url: string;
|
||||
static readonly WGXpath: string;
|
||||
}
|
||||
37
node_modules/speech-rule-engine/js/common/variables.js
generated
vendored
Normal file
37
node_modules/speech-rule-engine/js/common/variables.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Variables = void 0;
|
||||
class Variables {
|
||||
static ensureLocale(loc, def) {
|
||||
if (!Variables.LOCALES.get(loc)) {
|
||||
console.error(`Locale ${loc} does not exist! Using` +
|
||||
` ${Variables.LOCALES.get(def)} instead.`);
|
||||
return def;
|
||||
}
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
exports.Variables = Variables;
|
||||
Variables.VERSION = '4.1.2';
|
||||
Variables.LOCALES = new Map([
|
||||
['af', 'Africaans'],
|
||||
['ca', 'Catalan'],
|
||||
['da', 'Danish'],
|
||||
['de', 'German'],
|
||||
['en', 'English'],
|
||||
['es', 'Spanish'],
|
||||
['euro', 'Euro'],
|
||||
['fr', 'French'],
|
||||
['hi', 'Hindi'],
|
||||
['it', 'Italian'],
|
||||
['ko', 'Korean'],
|
||||
['nb', 'Bokmål'],
|
||||
['nn', 'Nynorsk'],
|
||||
['sv', 'Swedish'],
|
||||
['nemeth', 'Nemeth']
|
||||
]);
|
||||
Variables.mathjaxVersion = '4.0.0-beta.5';
|
||||
Variables.url = 'https://cdn.jsdelivr.net/npm/speech-rule-engine@' +
|
||||
Variables.VERSION +
|
||||
'/lib/mathmaps';
|
||||
Variables.WGXpath = 'https://cdn.jsdelivr.net/npm/wicked-good-xpath@1.3.0/dist/wgxpath.install.js';
|
||||
16
node_modules/speech-rule-engine/js/common/xpath_util.d.ts
generated
vendored
Normal file
16
node_modules/speech-rule-engine/js/common/xpath_util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export declare const xpath: {
|
||||
currentDocument: Document;
|
||||
evaluate: (x: string, node: Element, nsr: Resolver, rt: number, result: XPathResult) => XPathResult;
|
||||
result: any;
|
||||
createNSResolver: (nodeResolver: Element) => XPathNSResolver;
|
||||
};
|
||||
export declare function resolveNameSpace(prefix: string): string;
|
||||
declare class Resolver {
|
||||
lookupNamespaceURI: any;
|
||||
constructor();
|
||||
}
|
||||
export declare function evalXPath(expression: string, rootNode: Element): Element[];
|
||||
export declare function evaluateBoolean(expression: string, rootNode: Element): boolean;
|
||||
export declare function evaluateString(expression: string, rootNode: Element): string;
|
||||
export declare function updateEvaluator(node: Element): void;
|
||||
export {};
|
||||
96
node_modules/speech-rule-engine/js/common/xpath_util.js
generated
vendored
Normal file
96
node_modules/speech-rule-engine/js/common/xpath_util.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.xpath = void 0;
|
||||
exports.resolveNameSpace = resolveNameSpace;
|
||||
exports.evalXPath = evalXPath;
|
||||
exports.evaluateBoolean = evaluateBoolean;
|
||||
exports.evaluateString = evaluateString;
|
||||
exports.updateEvaluator = updateEvaluator;
|
||||
const engine_js_1 = require("./engine.js");
|
||||
const EngineConst = require("../common/engine_const.js");
|
||||
const system_external_js_1 = require("./system_external.js");
|
||||
function xpathSupported() {
|
||||
if (typeof XPathResult === 'undefined') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.xpath = {
|
||||
currentDocument: null,
|
||||
evaluate: xpathSupported()
|
||||
? document.evaluate
|
||||
: system_external_js_1.SystemExternal.xpath.evaluate,
|
||||
result: xpathSupported() ? XPathResult : system_external_js_1.SystemExternal.xpath.XPathResult,
|
||||
createNSResolver: xpathSupported()
|
||||
? document.createNSResolver
|
||||
: system_external_js_1.SystemExternal.xpath.createNSResolver
|
||||
};
|
||||
const nameSpaces = {
|
||||
xhtml: 'http://www.w3.org/1999/xhtml',
|
||||
mathml: 'http://www.w3.org/1998/Math/MathML',
|
||||
mml: 'http://www.w3.org/1998/Math/MathML',
|
||||
svg: 'http://www.w3.org/2000/svg'
|
||||
};
|
||||
function resolveNameSpace(prefix) {
|
||||
return nameSpaces[prefix] || null;
|
||||
}
|
||||
class Resolver {
|
||||
constructor() {
|
||||
this.lookupNamespaceURI = resolveNameSpace;
|
||||
}
|
||||
}
|
||||
function evaluateXpath(expression, rootNode, type) {
|
||||
return engine_js_1.Engine.getInstance().mode === EngineConst.Mode.HTTP &&
|
||||
!engine_js_1.Engine.getInstance().isIE &&
|
||||
!engine_js_1.Engine.getInstance().isEdge
|
||||
? exports.xpath.currentDocument.evaluate(expression, rootNode, resolveNameSpace, type, null)
|
||||
: exports.xpath.evaluate(expression, rootNode, new Resolver(), type, null);
|
||||
}
|
||||
function evalXPath(expression, rootNode) {
|
||||
let iterator;
|
||||
try {
|
||||
iterator = evaluateXpath(expression, rootNode, exports.xpath.result.ORDERED_NODE_ITERATOR_TYPE);
|
||||
}
|
||||
catch (_err) {
|
||||
return [];
|
||||
}
|
||||
const results = [];
|
||||
for (let xpathNode = iterator.iterateNext(); xpathNode; xpathNode = iterator.iterateNext()) {
|
||||
results.push(xpathNode);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function evaluateBoolean(expression, rootNode) {
|
||||
let result;
|
||||
try {
|
||||
result = evaluateXpath(expression, rootNode, exports.xpath.result.BOOLEAN_TYPE);
|
||||
}
|
||||
catch (_err) {
|
||||
return false;
|
||||
}
|
||||
return result.booleanValue;
|
||||
}
|
||||
function evaluateString(expression, rootNode) {
|
||||
let result;
|
||||
try {
|
||||
result = evaluateXpath(expression, rootNode, exports.xpath.result.STRING_TYPE);
|
||||
}
|
||||
catch (_err) {
|
||||
return '';
|
||||
}
|
||||
return result.stringValue;
|
||||
}
|
||||
function updateEvaluator(node) {
|
||||
if (engine_js_1.Engine.getInstance().mode !== EngineConst.Mode.HTTP)
|
||||
return;
|
||||
let parent = node;
|
||||
while (parent && !parent.evaluate) {
|
||||
parent = parent.parentNode;
|
||||
}
|
||||
if (parent && parent.evaluate) {
|
||||
exports.xpath.currentDocument = parent;
|
||||
}
|
||||
else if (node.ownerDocument) {
|
||||
exports.xpath.currentDocument = node.ownerDocument;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user