1
0

add initial marp implementation with sample content and build configuration

This commit is contained in:
2025-09-13 18:13:22 +02:00
parent dcacc9b409
commit e5f219507f
10319 changed files with 1402023 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
import { KeyCode } from '../common/event_util.js';
import { Highlighter } from '../highlighter/highlighter.js';
import { AxisMap } from '../rule_engine/dynamic_cstr.js';
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
import { SemanticNode } from '../semantic_tree/semantic_node.js';
import { SemanticSkeleton } from '../semantic_tree/semantic_skeleton.js';
import { SpeechGenerator } from '../speech_generator/speech_generator.js';
import { Focus } from './focus.js';
import { Levels } from './levels.js';
import { RebuildStree } from './rebuild_stree.js';
import { Walker, WalkerMoves } from './walker.js';
export declare abstract class AbstractWalker<T> implements Walker {
node: Element;
generator: SpeechGenerator;
highlighter: Highlighter;
static ID_COUNTER: number;
static SRE_ID_ATTR: string;
modifier: boolean;
id: any;
rootNode: Element;
rootId: string;
skeleton: SemanticSkeleton;
keyMapping: Map<KeyCode, () => any>;
moved: WalkerMoves;
cursors: {
focus: Focus;
levels: Levels<T>;
undo: boolean;
}[];
levels: any;
private xmlString_;
private xml_;
private rebuilt_;
private focus_;
private active_;
abstract findFocusOnLevel(id: number): Focus;
abstract initLevels(): Levels<T>;
abstract combineContentChildren(type: SemanticType, role: SemanticRole, content: string[], children: string[]): T[];
constructor(node: Element, generator: SpeechGenerator, highlighter: Highlighter, xml: string);
getXml(): Element;
getRebuilt(): RebuildStree;
isActive(): boolean;
activate(): void;
deactivate(): void;
getFocus(update?: boolean): Focus;
setFocus(focus: Focus): void;
getDepth(): number;
isSpeech(): boolean;
focusDomNodes(): Element[];
focusSemanticNodes(): SemanticNode[];
speech(): string;
move(key: KeyCode): boolean;
protected up(): Focus | null;
protected down(): Focus | null;
protected left(): Focus | null;
protected right(): Focus | null;
protected repeat(): Focus | null;
protected depth(): Focus | null;
protected home(): Focus | null;
getBySemanticId(id: string): Element;
primaryId(): string;
expand(): Focus;
expandable(node: Element): boolean;
collapsible(node: Element): boolean;
restoreState(): void;
updateFocus(): void;
protected rebuildStree(): void;
previousLevel(): string | null;
nextLevel(): T[];
singletonFocus(id: string): Focus;
private retrieveVisuals;
private subtreeIds;
focusFromId(id: string, ids: string[]): Focus;
protected summary(): Focus | null;
protected detail(): Focus | null;
protected specialMove(): string | null;
virtualize(opt_undo?: boolean): Focus;
previous(): Focus;
undo(): Focus;
update(options: AxisMap): void;
nextRules(): Focus;
previousRules(): Focus;
refocus(): void;
private toggleActive_;
private mergePrefix_;
private prefix_;
private postfix_;
private depth_;
private actionable_;
private summary_;
private detail_;
}

View File

@@ -0,0 +1,474 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractWalker = void 0;
const auditory_description_js_1 = require("../audio/auditory_description.js");
const AuralRendering = require("../audio/aural_rendering.js");
const DomUtil = require("../common/dom_util.js");
const engine_setup_js_1 = require("../common/engine_setup.js");
const event_util_js_1 = require("../common/event_util.js");
const enrich_attr_js_1 = require("../enrich_mathml/enrich_attr.js");
const locale_js_1 = require("../l10n/locale.js");
const grammar_js_1 = require("../rule_engine/grammar.js");
const semantic_skeleton_js_1 = require("../semantic_tree/semantic_skeleton.js");
const SpeechGeneratorFactory = require("../speech_generator/speech_generator_factory.js");
const SpeechGeneratorUtil = require("../speech_generator/speech_generator_util.js");
const focus_js_1 = require("./focus.js");
const rebuild_stree_js_1 = require("./rebuild_stree.js");
const walker_js_1 = require("./walker.js");
const WalkerUtil = require("./walker_util.js");
const XpathUtil = require("../common/xpath_util.js");
class AbstractWalker {
constructor(node, generator, highlighter, xml) {
this.node = node;
this.generator = generator;
this.highlighter = highlighter;
this.modifier = false;
this.keyMapping = new Map([
[event_util_js_1.KeyCode.UP, this.up.bind(this)],
[event_util_js_1.KeyCode.DOWN, this.down.bind(this)],
[event_util_js_1.KeyCode.RIGHT, this.right.bind(this)],
[event_util_js_1.KeyCode.LEFT, this.left.bind(this)],
[event_util_js_1.KeyCode.TAB, this.repeat.bind(this)],
[event_util_js_1.KeyCode.DASH, this.expand.bind(this)],
[event_util_js_1.KeyCode.SPACE, this.depth.bind(this)],
[event_util_js_1.KeyCode.HOME, this.home.bind(this)],
[event_util_js_1.KeyCode.X, this.summary.bind(this)],
[event_util_js_1.KeyCode.Z, this.detail.bind(this)],
[event_util_js_1.KeyCode.V, this.virtualize.bind(this)],
[event_util_js_1.KeyCode.P, this.previous.bind(this)],
[event_util_js_1.KeyCode.U, this.undo.bind(this)],
[event_util_js_1.KeyCode.LESS, this.previousRules.bind(this)],
[event_util_js_1.KeyCode.GREATER, this.nextRules.bind(this)]
]);
this.cursors = [];
this.xml_ = null;
this.rebuilt_ = null;
this.focus_ = null;
this.active_ = false;
if (this.node.id) {
this.id = this.node.id;
}
else if (this.node.hasAttribute(AbstractWalker.SRE_ID_ATTR)) {
this.id = this.node.getAttribute(AbstractWalker.SRE_ID_ATTR);
}
else {
this.node.setAttribute(AbstractWalker.SRE_ID_ATTR, AbstractWalker.ID_COUNTER.toString());
this.id = AbstractWalker.ID_COUNTER++;
}
this.rootNode = WalkerUtil.getSemanticRoot(node);
this.rootId = this.rootNode.getAttribute(enrich_attr_js_1.Attribute.ID);
this.xmlString_ = xml;
this.moved = walker_js_1.WalkerMoves.ENTER;
}
getXml() {
if (!this.xml_) {
this.xml_ = DomUtil.parseInput(this.xmlString_);
}
return this.xml_;
}
getRebuilt() {
if (!this.rebuilt_) {
this.rebuildStree();
}
return this.rebuilt_;
}
isActive() {
return this.active_;
}
activate() {
if (this.isActive()) {
return;
}
this.toggleActive_();
}
deactivate() {
if (!this.isActive()) {
return;
}
walker_js_1.WalkerState.setState(this.id, this.primaryId());
this.toggleActive_();
}
getFocus(update = false) {
if (this.rootId === null) {
this.getRebuilt();
}
if (!this.focus_) {
this.focus_ = this.singletonFocus(this.rootId);
}
if (update) {
this.updateFocus();
}
return this.focus_;
}
setFocus(focus) {
this.focus_ = focus;
}
getDepth() {
return this.levels.depth() - 1;
}
isSpeech() {
return this.generator.modality === enrich_attr_js_1.Attribute.SPEECH;
}
focusDomNodes() {
return this.getFocus().getDomNodes();
}
focusSemanticNodes() {
return this.getFocus().getSemanticNodes();
}
speech() {
const nodes = this.focusDomNodes();
if (!nodes.length) {
return '';
}
const special = this.specialMove();
if (special !== null) {
return special;
}
switch (this.moved) {
case walker_js_1.WalkerMoves.DEPTH:
return this.depth_();
case walker_js_1.WalkerMoves.SUMMARY:
return this.summary_();
case walker_js_1.WalkerMoves.DETAIL:
return this.detail_();
default: {
const speech = [];
const snodes = this.focusSemanticNodes();
for (let i = 0, l = nodes.length; i < l; i++) {
const node = nodes[i];
const snode = snodes[i];
speech.push(node
? this.generator.getSpeech(node, this.getXml(), this.node)
: SpeechGeneratorUtil.recomputeMarkup(snode));
}
return this.mergePrefix_(speech);
}
}
}
move(key) {
const direction = this.keyMapping.get(key);
if (!direction) {
return null;
}
const focus = direction();
if (!focus || focus === this.getFocus()) {
return false;
}
this.setFocus(focus);
if (this.moved === walker_js_1.WalkerMoves.HOME) {
this.levels = this.initLevels();
}
return true;
}
up() {
this.moved = walker_js_1.WalkerMoves.UP;
return this.getFocus();
}
down() {
this.moved = walker_js_1.WalkerMoves.DOWN;
return this.getFocus();
}
left() {
this.moved = walker_js_1.WalkerMoves.LEFT;
return this.getFocus();
}
right() {
this.moved = walker_js_1.WalkerMoves.RIGHT;
return this.getFocus();
}
repeat() {
this.moved = walker_js_1.WalkerMoves.REPEAT;
return this.getFocus().clone();
}
depth() {
this.moved = this.isSpeech() ? walker_js_1.WalkerMoves.DEPTH : walker_js_1.WalkerMoves.REPEAT;
return this.getFocus().clone();
}
home() {
this.moved = walker_js_1.WalkerMoves.HOME;
const focus = this.singletonFocus(this.rootId);
return focus;
}
getBySemanticId(id) {
return WalkerUtil.getBySemanticId(this.node, id);
}
primaryId() {
return this.getFocus().getSemanticPrimary().id.toString();
}
expand() {
const primary = this.getFocus().getDomPrimary();
const expandable = this.actionable_(primary);
if (!expandable) {
return this.getFocus();
}
this.moved = walker_js_1.WalkerMoves.EXPAND;
expandable.dispatchEvent(new Event('click'));
return this.getFocus().clone();
}
expandable(node) {
const parent = !!this.actionable_(node);
return parent && node.childNodes.length === 0;
}
collapsible(node) {
const parent = !!this.actionable_(node);
return parent && node.childNodes.length > 0;
}
restoreState() {
if (!this.highlighter) {
return;
}
const state = walker_js_1.WalkerState.getState(this.id);
if (!state) {
return;
}
let node = this.getRebuilt().nodeDict[state];
const path = [];
while (node) {
path.push(node.id);
node = node.parent;
}
path.pop();
while (path.length > 0) {
this.down();
const id = path.pop();
const focus = this.findFocusOnLevel(id);
if (!focus) {
break;
}
this.setFocus(focus);
}
this.moved = walker_js_1.WalkerMoves.ENTER;
}
updateFocus() {
this.setFocus(focus_js_1.Focus.factory(this.getFocus().getSemanticPrimary().id.toString(), this.getFocus()
.getSemanticNodes()
.map((x) => x.id.toString()), this.getRebuilt(), this.node));
}
rebuildStree() {
this.rebuilt_ = new rebuild_stree_js_1.RebuildStree(this.getXml());
this.rootId = this.rebuilt_.stree.root.id.toString();
this.generator.setRebuilt(this.rebuilt_);
this.skeleton = semantic_skeleton_js_1.SemanticSkeleton.fromTree(this.rebuilt_.stree);
this.skeleton.populate();
this.focus_ = this.singletonFocus(this.rootId);
this.levels = this.initLevels();
SpeechGeneratorUtil.connectMactions(this.node, this.getXml(), this.rebuilt_.xml);
}
previousLevel() {
const dnode = this.getFocus().getDomPrimary();
return dnode
? WalkerUtil.getAttribute(dnode, enrich_attr_js_1.Attribute.PARENT)
: this.getFocus().getSemanticPrimary().parent.id.toString();
}
nextLevel() {
const dnode = this.getFocus().getDomPrimary();
let children;
let content;
if (dnode) {
children = WalkerUtil.splitAttribute(WalkerUtil.getAttribute(dnode, enrich_attr_js_1.Attribute.CHILDREN));
content = WalkerUtil.splitAttribute(WalkerUtil.getAttribute(dnode, enrich_attr_js_1.Attribute.CONTENT));
const type = WalkerUtil.getAttribute(dnode, enrich_attr_js_1.Attribute.TYPE);
const role = WalkerUtil.getAttribute(dnode, enrich_attr_js_1.Attribute.ROLE);
return this.combineContentChildren(type, role, content, children);
}
const toIds = (x) => x.id.toString();
const snode = this.getRebuilt().nodeDict[this.primaryId()];
children = snode.childNodes.map(toIds);
content = snode.contentNodes.map(toIds);
if (children.length === 0) {
return [];
}
return this.combineContentChildren(snode.type, snode.role, content, children);
}
singletonFocus(id) {
this.getRebuilt();
const ids = this.retrieveVisuals(id);
return this.focusFromId(id, ids);
}
retrieveVisuals(id) {
if (!this.skeleton) {
return [id];
}
const num = parseInt(id, 10);
const semStree = this.skeleton.subtreeNodes(num);
if (!semStree.length) {
return [id];
}
semStree.unshift(num);
const mmlStree = {};
const result = [];
XpathUtil.updateEvaluator(this.getXml());
for (const child of semStree) {
if (mmlStree[child]) {
continue;
}
result.push(child.toString());
mmlStree[child] = true;
this.subtreeIds(child, mmlStree);
}
return result;
}
subtreeIds(id, nodes) {
const xmlRoot = XpathUtil.evalXPath(`//*[@data-semantic-id="${id}"]`, this.getXml());
const xpath = XpathUtil.evalXPath('*//@data-semantic-id', xmlRoot[0]);
xpath.forEach((x) => (nodes[parseInt(x.textContent, 10)] = true));
}
focusFromId(id, ids) {
return focus_js_1.Focus.factory(id, ids, this.getRebuilt(), this.node);
}
summary() {
this.moved = this.isSpeech() ? walker_js_1.WalkerMoves.SUMMARY : walker_js_1.WalkerMoves.REPEAT;
return this.getFocus().clone();
}
detail() {
this.moved = this.isSpeech() ? walker_js_1.WalkerMoves.DETAIL : walker_js_1.WalkerMoves.REPEAT;
return this.getFocus().clone();
}
specialMove() {
return null;
}
virtualize(opt_undo) {
this.cursors.push({
focus: this.getFocus(),
levels: this.levels,
undo: opt_undo || !this.cursors.length
});
this.levels = this.levels.clone();
return this.getFocus().clone();
}
previous() {
const previous = this.cursors.pop();
if (!previous) {
return this.getFocus();
}
this.levels = previous.levels;
return previous.focus;
}
undo() {
let previous;
do {
previous = this.cursors.pop();
} while (previous && !previous.undo);
if (!previous) {
return this.getFocus();
}
this.levels = previous.levels;
return previous.focus;
}
update(options) {
(0, engine_setup_js_1.setup)(options).then(() => SpeechGeneratorFactory.generator('Tree').getSpeech(this.node, this.getXml()));
}
nextRules() {
this.generator.nextRules();
const options = this.generator.getOptions();
if (options.modality !== 'speech') {
return this.getFocus();
}
this.update(options);
this.moved = walker_js_1.WalkerMoves.REPEAT;
return this.getFocus().clone();
}
previousRules() {
var _a;
this.generator.nextStyle((_a = this.getFocus().getSemanticPrimary()) === null || _a === void 0 ? void 0 : _a.id.toString());
const options = this.generator.getOptions();
if (options.modality !== 'speech') {
return this.getFocus();
}
this.update(options);
this.moved = walker_js_1.WalkerMoves.REPEAT;
return this.getFocus().clone();
}
refocus() {
let focus = this.getFocus();
let last;
while (!focus.getNodes().length) {
last = this.levels.peek();
const up = this.up();
if (!up) {
break;
}
this.setFocus(up);
focus = this.getFocus(true);
}
this.levels.push(last);
this.setFocus(focus);
}
toggleActive_() {
this.active_ = !this.active_;
}
mergePrefix_(speech, pre = []) {
const prefix = this.isSpeech() ? this.prefix_() : '';
if (prefix) {
speech.unshift(prefix);
}
const postfix = this.isSpeech() ? this.postfix_() : '';
if (postfix) {
speech.push(postfix);
}
return AuralRendering.finalize(AuralRendering.merge(pre.concat(speech)));
}
prefix_() {
const nodes = this.getFocus().getDomNodes();
const snodes = this.getFocus().getSemanticNodes();
return nodes[0]
? WalkerUtil.getAttribute(nodes[0], enrich_attr_js_1.Attribute.PREFIX)
: SpeechGeneratorUtil.retrievePrefix(snodes[0]);
}
postfix_() {
const nodes = this.getFocus().getDomNodes();
return nodes[0]
? WalkerUtil.getAttribute(nodes[0], enrich_attr_js_1.Attribute.POSTFIX)
: '';
}
depth_() {
const oldDepth = grammar_js_1.Grammar.getInstance().getParameter('depth');
grammar_js_1.Grammar.getInstance().setParameter('depth', true);
const primary = this.getFocus().getDomPrimary();
const expand = this.expandable(primary)
? locale_js_1.LOCALE.MESSAGES.navigate.EXPANDABLE
: this.collapsible(primary)
? locale_js_1.LOCALE.MESSAGES.navigate.COLLAPSIBLE
: '';
const level = locale_js_1.LOCALE.MESSAGES.navigate.LEVEL + ' ' + this.getDepth();
const snodes = this.getFocus().getSemanticNodes();
const prefix = SpeechGeneratorUtil.retrievePrefix(snodes[0]);
const audio = [
new auditory_description_js_1.AuditoryDescription({ text: level, personality: {} }),
new auditory_description_js_1.AuditoryDescription({ text: prefix, personality: {} }),
new auditory_description_js_1.AuditoryDescription({ text: expand, personality: {} })
];
grammar_js_1.Grammar.getInstance().setParameter('depth', oldDepth);
return AuralRendering.finalize(AuralRendering.markup(audio));
}
actionable_(node) {
const parent = node === null || node === void 0 ? void 0 : node.parentNode;
return parent && this.highlighter.isMactionNode(parent) ? parent : null;
}
summary_() {
const sprimary = this.getFocus().getSemanticPrimary();
const sid = sprimary.id.toString();
const snode = this.getRebuilt().xml.getAttribute('id') === sid
? this.getRebuilt().xml
: DomUtil.querySelectorAllByAttrValue(this.getRebuilt().xml, 'id', sid)[0];
const summary = SpeechGeneratorUtil.retrieveSummary(snode);
const speech = this.mergePrefix_([summary]);
return speech;
}
detail_() {
const sprimary = this.getFocus().getSemanticPrimary();
const sid = sprimary.id.toString();
const snode = this.getRebuilt().xml.getAttribute('id') === sid
? this.getRebuilt().xml
: DomUtil.querySelectorAllByAttrValue(this.getRebuilt().xml, 'id', sid)[0];
const oldAlt = snode.getAttribute('alternative');
snode.removeAttribute('alternative');
const detail = SpeechGeneratorUtil.computeMarkup(snode);
const speech = this.mergePrefix_([detail]);
snode.setAttribute('alternative', oldAlt);
return speech;
}
}
exports.AbstractWalker = AbstractWalker;
AbstractWalker.ID_COUNTER = 0;
AbstractWalker.SRE_ID_ATTR = 'sre-explorer-id';

View File

@@ -0,0 +1,17 @@
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
import { AbstractWalker } from './abstract_walker.js';
import { Focus } from './focus.js';
import { Levels } from './levels.js';
export declare class DummyWalker extends AbstractWalker<void> {
up(): Focus;
down(): Focus;
left(): Focus;
right(): Focus;
repeat(): Focus;
depth(): Focus;
home(): Focus;
getDepth(): number;
initLevels(): Levels<void>;
combineContentChildren(_type: SemanticType, _role: SemanticRole, _content: string[], _children: string[]): void[];
findFocusOnLevel(_id: number): Focus;
}

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DummyWalker = void 0;
const abstract_walker_js_1 = require("./abstract_walker.js");
class DummyWalker extends abstract_walker_js_1.AbstractWalker {
up() {
return null;
}
down() {
return null;
}
left() {
return null;
}
right() {
return null;
}
repeat() {
return null;
}
depth() {
return null;
}
home() {
return null;
}
getDepth() {
return 0;
}
initLevels() {
return null;
}
combineContentChildren(_type, _role, _content, _children) {
return [];
}
findFocusOnLevel(_id) {
return null;
}
}
exports.DummyWalker = DummyWalker;

20
node_modules/speech-rule-engine/js/walker/focus.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import { SemanticNode } from '../semantic_tree/semantic_node.js';
import { RebuildStree } from './rebuild_stree.js';
export declare class Focus {
private nodes;
private primary;
private domNodes;
private domPrimary_;
private allNodes;
static factory(primaryId: string, nodeIds: string[], rebuilt: RebuildStree, dom: Element): Focus;
private static generateAllVisibleNodes_;
private static getAllVisibleNodes;
constructor(nodes: SemanticNode[], primary: SemanticNode);
getSemanticPrimary(): SemanticNode;
getSemanticNodes(): SemanticNode[];
getNodes(): Element[];
getDomNodes(): (Element | null)[];
getDomPrimary(): Element;
toString(): string;
clone(): Focus;
}

83
node_modules/speech-rule-engine/js/walker/focus.js generated vendored Normal file
View File

@@ -0,0 +1,83 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Focus = void 0;
const WalkerUtil = require("./walker_util.js");
class Focus {
static factory(primaryId, nodeIds, rebuilt, dom) {
const idFunc = (id) => WalkerUtil.getBySemanticId(dom, id);
const dict = rebuilt.nodeDict;
const node = idFunc(primaryId);
const nodes = nodeIds.map(idFunc);
const snodes = nodeIds.map(function (primaryId) {
return dict[primaryId];
});
const focus = new Focus(snodes, dict[primaryId]);
focus.domNodes = nodes;
focus.domPrimary_ = node;
focus.allNodes = Focus.generateAllVisibleNodes_(nodeIds, nodes, dict, dom);
return focus;
}
static generateAllVisibleNodes_(ids, nodes, dict, domNode) {
let result = [];
for (let i = 0, l = ids.length; i < l; i++) {
if (nodes[i]) {
const allNodes = Focus.getAllVisibleNodes([ids[i]], domNode);
if (allNodes.length) {
result = result.concat(allNodes);
}
else {
result.push(nodes[i]);
}
continue;
}
const virtual = dict[ids[i]];
if (!virtual) {
continue;
}
const childIds = virtual.childNodes.map((x) => x.id.toString());
const children = Focus.getAllVisibleNodes(childIds, domNode);
result = result.concat(Focus.generateAllVisibleNodes_(childIds, children, dict, domNode));
}
return result;
}
static getAllVisibleNodes(ids, domNode) {
let result = [];
for (const id of ids) {
result = result.concat(WalkerUtil.getAllBySemanticId(domNode, id));
}
return result;
}
constructor(nodes, primary) {
this.nodes = nodes;
this.primary = primary;
this.domNodes = [];
this.domPrimary_ = null;
this.allNodes = [];
}
getSemanticPrimary() {
return this.primary;
}
getSemanticNodes() {
return this.nodes;
}
getNodes() {
return this.allNodes;
}
getDomNodes() {
return this.domNodes;
}
getDomPrimary() {
return this.domPrimary_;
}
toString() {
return 'Primary:' + this.domPrimary_ + ' Nodes:' + this.domNodes;
}
clone() {
const focus = new Focus(this.nodes, this.primary);
focus.domNodes = this.domNodes;
focus.domPrimary_ = this.domPrimary_;
focus.allNodes = this.allNodes;
return focus;
}
}
exports.Focus = Focus;

12
node_modules/speech-rule-engine/js/walker/levels.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
export declare class Levels<T> {
private level_;
push(level: T[]): void;
pop(): T[];
peek(): T[];
indexOf(element: T): number | null;
find(pred: (p1: T) => boolean): T | null;
get(index: number): T | null;
depth(): number;
clone(): Levels<T>;
toString(): string;
}

57
node_modules/speech-rule-engine/js/walker/levels.js generated vendored Normal file
View File

@@ -0,0 +1,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Levels = void 0;
class Levels {
constructor() {
this.level_ = [];
}
push(level) {
this.level_.push(level);
}
pop() {
return this.level_.pop();
}
peek() {
return this.level_[this.level_.length - 1] || null;
}
indexOf(element) {
const last = this.peek();
return !last ? null : last.indexOf(element);
}
find(pred) {
const last = this.peek();
if (!last) {
return null;
}
for (let i = 0, l = last.length; i < l; i++) {
if (pred(last[i])) {
return last[i];
}
}
return null;
}
get(index) {
const last = this.peek();
return !last || index < 0 || index >= last.length ? null : last[index];
}
depth() {
return this.level_.length;
}
clone() {
const levels = new Levels();
levels.level_ = this.level_.slice(0);
return levels;
}
toString() {
let str = '';
for (let i = 0, level; (level = this.level_[i]); i++) {
str +=
'\n' +
level.map(function (x) {
return x.toString();
});
}
return str;
}
}
exports.Levels = Levels;

View File

@@ -0,0 +1,30 @@
import { SemanticRole } from '../semantic_tree/semantic_meaning.js';
import { SemanticNode } from '../semantic_tree/semantic_node.js';
import { SemanticNodeFactory } from '../semantic_tree/semantic_node_factory.js';
import { Sexp } from '../semantic_tree/semantic_skeleton.js';
import { SemanticTree } from '../semantic_tree/semantic_tree.js';
export declare class RebuildStree {
mathml: Element;
factory: SemanticNodeFactory;
nodeDict: {
[key: string]: SemanticNode;
};
mmlRoot: Element;
streeRoot: SemanticNode;
stree: SemanticTree;
xml: Element;
static textContent(snode: SemanticNode, node: Element, ignore?: boolean): void;
static isPunctuated(collapsed: Sexp): boolean;
constructor(mathml: Element);
getTree(): SemanticTree;
assembleTree(node: Element): SemanticNode;
makeNode(node: Element): SemanticNode;
makePunctuation(id: number): SemanticNode;
makePunctuated(snode: SemanticNode, collapsed: any, role: SemanticRole): void;
makeEmpty(snode: SemanticNode, collapsed: number, role: SemanticRole): void;
makeIndex(snode: SemanticNode, collapsed: Sexp, role: SemanticRole): void;
postProcess(snode: SemanticNode, collapsed: string): SemanticNode;
createNode(id: number): SemanticNode;
private collapsedChildren_;
private setParent;
}

View File

@@ -0,0 +1,198 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RebuildStree = void 0;
const enrich_attr_js_1 = require("../enrich_mathml/enrich_attr.js");
const semantic_attr_js_1 = require("../semantic_tree/semantic_attr.js");
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
const semantic_node_factory_js_1 = require("../semantic_tree/semantic_node_factory.js");
const semantic_skeleton_js_1 = require("../semantic_tree/semantic_skeleton.js");
const semantic_tree_js_1 = require("../semantic_tree/semantic_tree.js");
const WalkerUtil = require("./walker_util.js");
class RebuildStree {
static textContent(snode, node, ignore) {
if (!ignore && node.textContent) {
snode.textContent = node.textContent;
return;
}
const operator = WalkerUtil.splitAttribute(WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.OPERATOR));
if (operator.length > 1) {
snode.textContent = operator[1];
}
}
static isPunctuated(collapsed) {
return (!semantic_skeleton_js_1.SemanticSkeleton.simpleCollapseStructure(collapsed) &&
collapsed[1] &&
semantic_skeleton_js_1.SemanticSkeleton.contentCollapseStructure(collapsed[1]));
}
constructor(mathml) {
this.mathml = mathml;
this.factory = new semantic_node_factory_js_1.SemanticNodeFactory();
this.nodeDict = {};
this.mmlRoot = WalkerUtil.getSemanticRoot(mathml);
this.streeRoot = this.assembleTree(this.mmlRoot);
this.stree = semantic_tree_js_1.SemanticTree.fromNode(this.streeRoot, this.mathml);
this.xml = this.stree.xml();
}
getTree() {
return this.stree;
}
assembleTree(node) {
const snode = this.makeNode(node);
const children = WalkerUtil.splitAttribute(WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.CHILDREN));
const content = WalkerUtil.splitAttribute(WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.CONTENT));
if (content.length === 0 && children.length === 0) {
RebuildStree.textContent(snode, node);
return snode;
}
if (content.length > 0) {
const fcontent = WalkerUtil.getBySemanticId(this.mathml, content[0]);
if (fcontent) {
RebuildStree.textContent(snode, fcontent, true);
}
}
snode.contentNodes = content.map((id) => this.setParent(id, snode));
snode.childNodes = children.map((id) => this.setParent(id, snode));
const collapsed = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.COLLAPSED);
return collapsed ? this.postProcess(snode, collapsed) : snode;
}
makeNode(node) {
const type = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.TYPE);
const role = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.ROLE);
const font = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.FONT);
const annotation = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.ANNOTATION) || '';
const attributes = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.ATTRIBUTES) || '';
const id = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.ID);
const embellished = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.EMBELLISHED);
const fencepointer = WalkerUtil.getAttribute(node, enrich_attr_js_1.Attribute.FENCEPOINTER);
const snode = this.createNode(parseInt(id, 10));
snode.type = type;
snode.role = role;
snode.font = font ? font : semantic_meaning_js_1.SemanticFont.UNKNOWN;
snode.parseAnnotation(annotation);
snode.parseAttributes(attributes);
if (fencepointer) {
snode.fencePointer = fencepointer;
}
if (embellished) {
snode.embellished = embellished;
}
return snode;
}
makePunctuation(id) {
const node = this.createNode(id);
node.updateContent(semantic_attr_js_1.NamedSymbol.invisibleComma);
node.role = semantic_meaning_js_1.SemanticRole.DUMMY;
return node;
}
makePunctuated(snode, collapsed, role) {
const punctuated = this.createNode(collapsed[0]);
punctuated.type = semantic_meaning_js_1.SemanticType.PUNCTUATED;
punctuated.embellished = snode.embellished;
punctuated.fencePointer = snode.fencePointer;
punctuated.role = role;
const cont = collapsed.splice(1, 1)[0].slice(1);
punctuated.contentNodes = cont.map(this.makePunctuation.bind(this));
this.collapsedChildren_(collapsed);
}
makeEmpty(snode, collapsed, role) {
const empty = this.createNode(collapsed);
empty.type = semantic_meaning_js_1.SemanticType.EMPTY;
empty.embellished = snode.embellished;
empty.fencePointer = snode.fencePointer;
empty.role = role;
}
makeIndex(snode, collapsed, role) {
if (RebuildStree.isPunctuated(collapsed)) {
this.makePunctuated(snode, collapsed, role);
collapsed = collapsed[0];
return;
}
if (semantic_skeleton_js_1.SemanticSkeleton.simpleCollapseStructure(collapsed) &&
!this.nodeDict[collapsed.toString()]) {
this.makeEmpty(snode, collapsed, role);
}
}
postProcess(snode, collapsed) {
const array = semantic_skeleton_js_1.SemanticSkeleton.fromString(collapsed).array;
if (snode.type === semantic_meaning_js_1.SemanticRole.SUBSUP) {
const subscript = this.createNode(array[1][0]);
subscript.type = semantic_meaning_js_1.SemanticType.SUBSCRIPT;
subscript.role = semantic_meaning_js_1.SemanticRole.SUBSUP;
snode.type = semantic_meaning_js_1.SemanticType.SUPERSCRIPT;
subscript.embellished = snode.embellished;
subscript.fencePointer = snode.fencePointer;
this.makeIndex(snode, array[1][2], semantic_meaning_js_1.SemanticRole.RIGHTSUB);
this.makeIndex(snode, array[2], semantic_meaning_js_1.SemanticRole.RIGHTSUPER);
this.collapsedChildren_(array);
return snode;
}
if (snode.type === semantic_meaning_js_1.SemanticType.SUBSCRIPT) {
this.makeIndex(snode, array[2], semantic_meaning_js_1.SemanticRole.RIGHTSUB);
this.collapsedChildren_(array);
return snode;
}
if (snode.type === semantic_meaning_js_1.SemanticType.SUPERSCRIPT) {
this.makeIndex(snode, array[2], semantic_meaning_js_1.SemanticRole.RIGHTSUPER);
this.collapsedChildren_(array);
return snode;
}
if (snode.type === semantic_meaning_js_1.SemanticType.TENSOR) {
this.makeIndex(snode, array[2], semantic_meaning_js_1.SemanticRole.LEFTSUB);
this.makeIndex(snode, array[3], semantic_meaning_js_1.SemanticRole.LEFTSUPER);
this.makeIndex(snode, array[4], semantic_meaning_js_1.SemanticRole.RIGHTSUB);
this.makeIndex(snode, array[5], semantic_meaning_js_1.SemanticRole.RIGHTSUPER);
this.collapsedChildren_(array);
return snode;
}
if (snode.type === semantic_meaning_js_1.SemanticType.PUNCTUATED) {
if (RebuildStree.isPunctuated(array)) {
const cont = array.splice(1, 1)[0].slice(1);
snode.contentNodes = cont.map(this.makePunctuation.bind(this));
}
return snode;
}
if (snode.type === semantic_meaning_js_1.SemanticRole.UNDEROVER) {
const score = this.createNode(array[1][0]);
if (snode.childNodes[1].role === semantic_meaning_js_1.SemanticRole.OVERACCENT) {
score.type = semantic_meaning_js_1.SemanticType.OVERSCORE;
snode.type = semantic_meaning_js_1.SemanticType.UNDERSCORE;
}
else {
score.type = semantic_meaning_js_1.SemanticType.UNDERSCORE;
snode.type = semantic_meaning_js_1.SemanticType.OVERSCORE;
}
score.role = semantic_meaning_js_1.SemanticRole.UNDEROVER;
score.embellished = snode.embellished;
score.fencePointer = snode.fencePointer;
this.collapsedChildren_(array);
return snode;
}
return snode;
}
createNode(id) {
const node = this.factory.makeNode(id);
this.nodeDict[id.toString()] = node;
return node;
}
collapsedChildren_(collapsed) {
const recurseCollapsed = (coll) => {
const parent = this.nodeDict[coll[0]];
parent.childNodes = [];
for (let j = 1, l = coll.length; j < l; j++) {
const id = coll[j];
parent.childNodes.push(semantic_skeleton_js_1.SemanticSkeleton.simpleCollapseStructure(id)
? this.nodeDict[id]
: recurseCollapsed(id));
}
return parent;
};
recurseCollapsed(collapsed);
}
setParent(id, snode) {
const mml = WalkerUtil.getBySemanticId(this.mathml, id);
const sn = this.assembleTree(mml);
sn.parent = snode;
return sn;
}
}
exports.RebuildStree = RebuildStree;

View File

@@ -0,0 +1,22 @@
import { Highlighter } from '../highlighter/highlighter.js';
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
import { SpeechGenerator } from '../speech_generator/speech_generator.js';
import { AbstractWalker } from './abstract_walker.js';
import { Focus } from './focus.js';
import { Levels } from './levels.js';
export declare class SemanticWalker extends AbstractWalker<Focus> {
node: Element;
generator: SpeechGenerator;
highlighter: Highlighter;
levels: Levels<Focus>;
constructor(node: Element, generator: SpeechGenerator, highlighter: Highlighter, xml: string);
initLevels(): Levels<Focus>;
up(): Focus;
down(): Focus;
combineContentChildren(type: SemanticType, role: SemanticRole, content: string[], children: string[]): Focus[];
combinePunctuations(children: string[], content: string[], prepunct: string[], acc: Focus[]): Focus[];
makePairList(children: string[], content: string[]): Focus[];
left(): Focus;
right(): Focus;
findFocusOnLevel(id: number): Focus;
}

View File

@@ -0,0 +1,146 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SemanticWalker = void 0;
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
const abstract_walker_js_1 = require("./abstract_walker.js");
const levels_js_1 = require("./levels.js");
class SemanticWalker extends abstract_walker_js_1.AbstractWalker {
constructor(node, generator, highlighter, xml) {
super(node, generator, highlighter, xml);
this.node = node;
this.generator = generator;
this.highlighter = highlighter;
this.levels = null;
this.restoreState();
}
initLevels() {
const levels = new levels_js_1.Levels();
levels.push([this.getFocus()]);
return levels;
}
up() {
super.up();
const parent = this.previousLevel();
if (!parent) {
return null;
}
this.levels.pop();
const found = this.levels.find(function (focus) {
return focus.getSemanticNodes().some(function (node) {
return node.id.toString() === parent;
});
});
return found;
}
down() {
super.down();
const children = this.nextLevel();
if (children.length === 0) {
return null;
}
this.levels.push(children);
return children[0];
}
combineContentChildren(type, role, content, children) {
switch (type) {
case semantic_meaning_js_1.SemanticType.RELSEQ:
case semantic_meaning_js_1.SemanticType.INFIXOP:
case semantic_meaning_js_1.SemanticType.MULTIREL:
return this.makePairList(children, content);
case semantic_meaning_js_1.SemanticType.PREFIXOP:
return [this.focusFromId(children[0], content.concat(children))];
case semantic_meaning_js_1.SemanticType.POSTFIXOP:
return [this.focusFromId(children[0], children.concat(content))];
case semantic_meaning_js_1.SemanticType.MATRIX:
case semantic_meaning_js_1.SemanticType.VECTOR:
case semantic_meaning_js_1.SemanticType.FENCED:
return [
this.focusFromId(children[0], [content[0], children[0], content[1]])
];
case semantic_meaning_js_1.SemanticType.CASES:
return [this.focusFromId(children[0], [content[0], children[0]])];
case semantic_meaning_js_1.SemanticType.PUNCTUATED:
if (role === semantic_meaning_js_1.SemanticRole.TEXT) {
return children.map(this.singletonFocus.bind(this));
}
if (children.length === content.length) {
return content.map(this.singletonFocus.bind(this));
}
return this.combinePunctuations(children, content, [], []);
case semantic_meaning_js_1.SemanticType.APPL:
return [
this.focusFromId(children[0], [children[0], content[0]]),
this.singletonFocus(children[1])
];
case semantic_meaning_js_1.SemanticType.ROOT:
return [
this.singletonFocus(children[0]),
this.singletonFocus(children[1])
];
default:
return children.map(this.singletonFocus.bind(this));
}
}
combinePunctuations(children, content, prepunct, acc) {
if (children.length === 0) {
return acc;
}
const child = children.shift();
const cont = content.shift();
if (child === cont) {
prepunct.push(cont);
return this.combinePunctuations(children, content, prepunct, acc);
}
else {
content.unshift(cont);
prepunct.push(child);
if (children.length === content.length) {
acc.push(this.focusFromId(child, prepunct.concat(content)));
return acc;
}
else {
acc.push(this.focusFromId(child, prepunct));
return this.combinePunctuations(children, content, [], acc);
}
}
}
makePairList(children, content) {
if (children.length === 0) {
return [];
}
if (children.length === 1) {
return [this.singletonFocus(children[0])];
}
const result = [this.singletonFocus(children.shift())];
for (let i = 0, l = children.length; i < l; i++) {
result.push(this.focusFromId(children[i], [content[i], children[i]]));
}
return result;
}
left() {
super.left();
const index = this.levels.indexOf(this.getFocus());
if (index === null) {
return null;
}
const ids = this.levels.get(index - 1);
return ids ? ids : null;
}
right() {
super.right();
const index = this.levels.indexOf(this.getFocus());
if (index === null) {
return null;
}
const ids = this.levels.get(index + 1);
return ids ? ids : null;
}
findFocusOnLevel(id) {
const focus = this.levels.find((x) => {
const pid = x.getSemanticPrimary().id;
return pid === id;
});
return focus;
}
}
exports.SemanticWalker = SemanticWalker;

View File

@@ -0,0 +1,21 @@
import { Highlighter } from '../highlighter/highlighter.js';
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
import { SpeechGenerator } from '../speech_generator/speech_generator.js';
import { AbstractWalker } from './abstract_walker.js';
import { Levels } from './levels.js';
export declare class SyntaxWalker extends AbstractWalker<string> {
node: Element;
generator: SpeechGenerator;
highlighter: Highlighter;
levels: Levels<string>;
constructor(node: Element, generator: SpeechGenerator, highlighter: Highlighter, xml: string);
initLevels(): Levels<string>;
up(): import("./focus.js").Focus;
down(): import("./focus.js").Focus;
combineContentChildren(type: SemanticType, role: SemanticRole, content: string[], children: string[]): string[];
left(): import("./focus.js").Focus;
right(): import("./focus.js").Focus;
findFocusOnLevel(id: number): import("./focus.js").Focus;
focusDomNodes(): Element[];
focusSemanticNodes(): import("../semantic_tree/semantic_node.js").SemanticNode[];
}

View File

@@ -0,0 +1,103 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SyntaxWalker = void 0;
const base_util_js_1 = require("../common/base_util.js");
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
const abstract_walker_js_1 = require("./abstract_walker.js");
const levels_js_1 = require("./levels.js");
class SyntaxWalker extends abstract_walker_js_1.AbstractWalker {
constructor(node, generator, highlighter, xml) {
super(node, generator, highlighter, xml);
this.node = node;
this.generator = generator;
this.highlighter = highlighter;
this.levels = null;
this.restoreState();
}
initLevels() {
const levels = new levels_js_1.Levels();
levels.push([this.primaryId()]);
return levels;
}
up() {
super.up();
const parent = this.previousLevel();
if (!parent) {
return null;
}
this.levels.pop();
return this.singletonFocus(parent);
}
down() {
super.down();
const children = this.nextLevel();
if (children.length === 0) {
return null;
}
const focus = this.singletonFocus(children[0]);
if (focus) {
this.levels.push(children);
}
return focus;
}
combineContentChildren(type, role, content, children) {
switch (type) {
case semantic_meaning_js_1.SemanticType.RELSEQ:
case semantic_meaning_js_1.SemanticType.INFIXOP:
case semantic_meaning_js_1.SemanticType.MULTIREL:
return (0, base_util_js_1.interleaveLists)(children, content);
case semantic_meaning_js_1.SemanticType.PREFIXOP:
return content.concat(children);
case semantic_meaning_js_1.SemanticType.POSTFIXOP:
return children.concat(content);
case semantic_meaning_js_1.SemanticType.MATRIX:
case semantic_meaning_js_1.SemanticType.VECTOR:
case semantic_meaning_js_1.SemanticType.FENCED:
children.unshift(content[0]);
children.push(content[1]);
return children;
case semantic_meaning_js_1.SemanticType.CASES:
children.unshift(content[0]);
return children;
case semantic_meaning_js_1.SemanticType.PUNCTUATED:
if (role === semantic_meaning_js_1.SemanticRole.TEXT) {
return (0, base_util_js_1.interleaveLists)(children, content);
}
return children;
case semantic_meaning_js_1.SemanticType.APPL:
return [children[0], content[0], children[1]];
case semantic_meaning_js_1.SemanticType.ROOT:
return [children[0], children[1]];
default:
return children;
}
}
left() {
super.left();
const index = this.levels.indexOf(this.primaryId());
if (index === null) {
return null;
}
const id = this.levels.get(index - 1);
return id ? this.singletonFocus(id) : null;
}
right() {
super.right();
const index = this.levels.indexOf(this.primaryId());
if (index === null) {
return null;
}
const id = this.levels.get(index + 1);
return id ? this.singletonFocus(id) : null;
}
findFocusOnLevel(id) {
return this.singletonFocus(id.toString());
}
focusDomNodes() {
return [this.getFocus().getDomPrimary()];
}
focusSemanticNodes() {
return [this.getFocus().getSemanticPrimary()];
}
}
exports.SyntaxWalker = SyntaxWalker;

View File

@@ -0,0 +1,28 @@
import { KeyCode } from '../common/event_util.js';
import { Highlighter } from '../highlighter/highlighter.js';
import { SemanticRole, SemanticType } from '../semantic_tree/semantic_meaning.js';
import { SpeechGenerator } from '../speech_generator/speech_generator.js';
import { Focus } from './focus.js';
import { SyntaxWalker } from './syntax_walker.js';
export declare class TableWalker extends SyntaxWalker {
node: Element;
generator: SpeechGenerator;
highlighter: Highlighter;
static ELIGIBLE_CELL_ROLES: SemanticRole[];
static ELIGIBLE_TABLE_TYPES: SemanticType[];
firstJump: Focus;
private key_;
private row_;
private currentTable_;
constructor(node: Element, generator: SpeechGenerator, highlighter: Highlighter, xml: string);
move(key: KeyCode): boolean;
up(): Focus;
down(): Focus;
protected jumpCell(): Focus | null;
undo(): Focus;
private eligibleCell_;
private verticalMove_;
private jumpCell_;
private isLegalJump_;
private isInTable_;
}

View File

@@ -0,0 +1,168 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableWalker = void 0;
const DomUtil = require("../common/dom_util.js");
const event_util_js_1 = require("../common/event_util.js");
const semantic_meaning_js_1 = require("../semantic_tree/semantic_meaning.js");
const syntax_walker_js_1 = require("./syntax_walker.js");
const walker_js_1 = require("./walker.js");
class TableWalker extends syntax_walker_js_1.SyntaxWalker {
constructor(node, generator, highlighter, xml) {
super(node, generator, highlighter, xml);
this.node = node;
this.generator = generator;
this.highlighter = highlighter;
this.firstJump = null;
this.key_ = null;
this.row_ = 0;
this.currentTable_ = null;
this.keyMapping.set(event_util_js_1.KeyCode.ZERO, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.ONE, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.TWO, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.THREE, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.FOUR, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.FIVE, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.SIX, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.SEVEN, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.EIGHT, this.jumpCell.bind(this));
this.keyMapping.set(event_util_js_1.KeyCode.NINE, this.jumpCell.bind(this));
}
move(key) {
this.key_ = key;
const result = super.move(key);
this.modifier = false;
return result;
}
up() {
this.moved = walker_js_1.WalkerMoves.UP;
return this.eligibleCell_() ? this.verticalMove_(false) : super.up();
}
down() {
this.moved = walker_js_1.WalkerMoves.DOWN;
return this.eligibleCell_() ? this.verticalMove_(true) : super.down();
}
jumpCell() {
if (!this.isInTable_() || this.key_ === null) {
return this.getFocus();
}
if (this.moved === walker_js_1.WalkerMoves.ROW) {
this.moved = walker_js_1.WalkerMoves.CELL;
const column = this.key_ - event_util_js_1.KeyCode.ZERO;
if (!this.isLegalJump_(this.row_, column)) {
return this.getFocus();
}
return this.jumpCell_(this.row_, column);
}
const row = this.key_ - event_util_js_1.KeyCode.ZERO;
if (row > this.currentTable_.childNodes.length) {
return this.getFocus();
}
this.row_ = row;
this.moved = walker_js_1.WalkerMoves.ROW;
return this.getFocus().clone();
}
undo() {
const focus = super.undo();
if (focus === this.firstJump) {
this.firstJump = null;
}
return focus;
}
eligibleCell_() {
const primary = this.getFocus().getSemanticPrimary();
return (this.modifier &&
primary.type === semantic_meaning_js_1.SemanticType.CELL &&
TableWalker.ELIGIBLE_CELL_ROLES.indexOf(primary.role) !== -1);
}
verticalMove_(direction) {
const parent = this.previousLevel();
if (!parent) {
return null;
}
const origFocus = this.getFocus();
const origIndex = this.levels.indexOf(this.primaryId());
const origLevel = this.levels.pop();
const parentIndex = this.levels.indexOf(parent);
const row = this.levels.get(direction ? parentIndex + 1 : parentIndex - 1);
if (!row) {
this.levels.push(origLevel);
return null;
}
this.setFocus(this.singletonFocus(row));
const children = this.nextLevel();
const newNode = children[origIndex];
if (!newNode) {
this.setFocus(origFocus);
this.levels.push(origLevel);
return null;
}
this.levels.push(children);
return this.singletonFocus(children[origIndex]);
}
jumpCell_(row, column) {
if (!this.firstJump) {
this.firstJump = this.getFocus();
this.virtualize(true);
}
else {
this.virtualize(false);
}
const id = this.currentTable_.id.toString();
let level;
do {
level = this.levels.pop();
} while (level.indexOf(id) === -1);
this.levels.push(level);
this.setFocus(this.singletonFocus(id));
this.levels.push(this.nextLevel());
const semRow = this.currentTable_.childNodes[row - 1];
this.setFocus(this.singletonFocus(semRow.id.toString()));
this.levels.push(this.nextLevel());
return this.singletonFocus(semRow.childNodes[column - 1].id.toString());
}
isLegalJump_(row, column) {
const xmlTable = DomUtil.querySelectorAllByAttrValue(this.getRebuilt().xml, 'id', this.currentTable_.id.toString())[0];
if (!xmlTable || xmlTable.hasAttribute('alternative')) {
return false;
}
const rowNode = this.currentTable_.childNodes[row - 1];
if (!rowNode) {
return false;
}
const xmlRow = DomUtil.querySelectorAllByAttrValue(xmlTable, 'id', rowNode.id.toString())[0];
if (!xmlRow || xmlRow.hasAttribute('alternative')) {
return false;
}
return !!(rowNode && rowNode.childNodes[column - 1]);
}
isInTable_() {
let snode = this.getFocus().getSemanticPrimary();
while (snode) {
if (TableWalker.ELIGIBLE_TABLE_TYPES.indexOf(snode.type) !== -1) {
this.currentTable_ = snode;
return true;
}
snode = snode.parent;
}
return false;
}
}
exports.TableWalker = TableWalker;
TableWalker.ELIGIBLE_CELL_ROLES = [
semantic_meaning_js_1.SemanticRole.DETERMINANT,
semantic_meaning_js_1.SemanticRole.ROWVECTOR,
semantic_meaning_js_1.SemanticRole.BINOMIAL,
semantic_meaning_js_1.SemanticRole.SQUAREMATRIX,
semantic_meaning_js_1.SemanticRole.MULTILINE,
semantic_meaning_js_1.SemanticRole.MATRIX,
semantic_meaning_js_1.SemanticRole.VECTOR,
semantic_meaning_js_1.SemanticRole.CASES,
semantic_meaning_js_1.SemanticRole.TABLE
];
TableWalker.ELIGIBLE_TABLE_TYPES = [
semantic_meaning_js_1.SemanticType.MULTILINE,
semantic_meaning_js_1.SemanticType.MATRIX,
semantic_meaning_js_1.SemanticType.VECTOR,
semantic_meaning_js_1.SemanticType.CASES,
semantic_meaning_js_1.SemanticType.TABLE
];

40
node_modules/speech-rule-engine/js/walker/walker.d.ts generated vendored Normal file
View File

@@ -0,0 +1,40 @@
import { KeyCode } from '../common/event_util.js';
import { AxisMap } from '../rule_engine/dynamic_cstr.js';
import { Focus } from './focus.js';
import { RebuildStree } from './rebuild_stree.js';
export interface Walker {
modifier: boolean;
isActive(): boolean;
activate(): void;
deactivate(): void;
speech(): string;
getXml(): Element;
getRebuilt(): RebuildStree;
getFocus(opt_update?: boolean): Focus;
setFocus(focus: Focus): void;
getDepth(): number;
move(key: KeyCode): boolean | null;
update(options: AxisMap): void;
refocus(): void;
}
export declare enum WalkerMoves {
UP = "up",
DOWN = "down",
LEFT = "left",
RIGHT = "right",
REPEAT = "repeat",
DEPTH = "depth",
ENTER = "enter",
EXPAND = "expand",
HOME = "home",
SUMMARY = "summary",
DETAIL = "detail",
ROW = "row",
CELL = "cell"
}
export declare class WalkerState {
private static STATE;
static resetState(id: string): void;
static setState(id: string, value: string): void;
static getState(id: string): string;
}

32
node_modules/speech-rule-engine/js/walker/walker.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalkerState = exports.WalkerMoves = void 0;
var WalkerMoves;
(function (WalkerMoves) {
WalkerMoves["UP"] = "up";
WalkerMoves["DOWN"] = "down";
WalkerMoves["LEFT"] = "left";
WalkerMoves["RIGHT"] = "right";
WalkerMoves["REPEAT"] = "repeat";
WalkerMoves["DEPTH"] = "depth";
WalkerMoves["ENTER"] = "enter";
WalkerMoves["EXPAND"] = "expand";
WalkerMoves["HOME"] = "home";
WalkerMoves["SUMMARY"] = "summary";
WalkerMoves["DETAIL"] = "detail";
WalkerMoves["ROW"] = "row";
WalkerMoves["CELL"] = "cell";
})(WalkerMoves || (exports.WalkerMoves = WalkerMoves = {}));
class WalkerState {
static resetState(id) {
delete WalkerState.STATE[id];
}
static setState(id, value) {
WalkerState.STATE[id] = value;
}
static getState(id) {
return WalkerState.STATE[id];
}
}
exports.WalkerState = WalkerState;
WalkerState.STATE = {};

View File

@@ -0,0 +1,4 @@
import { Highlighter } from '../highlighter/highlighter.js';
import { SpeechGenerator } from '../speech_generator/speech_generator.js';
import { Walker } from './walker.js';
export declare function walker(type: string, node: Element, generator: SpeechGenerator, highlighter: Highlighter, xml: string): Walker;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.walker = walker;
const dummy_walker_js_1 = require("./dummy_walker.js");
const semantic_walker_js_1 = require("./semantic_walker.js");
const syntax_walker_js_1 = require("./syntax_walker.js");
const table_walker_js_1 = require("./table_walker.js");
function walker(type, node, generator, highlighter, xml) {
const constructor = walkerMapping[type.toLowerCase()] || walkerMapping['dummy'];
return constructor(node, generator, highlighter, xml);
}
const walkerMapping = {
dummy: (p1, p2, p3, p4) => new dummy_walker_js_1.DummyWalker(p1, p2, p3, p4),
semantic: (p1, p2, p3, p4) => new semantic_walker_js_1.SemanticWalker(p1, p2, p3, p4),
syntax: (p1, p2, p3, p4) => new syntax_walker_js_1.SyntaxWalker(p1, p2, p3, p4),
table: (p1, p2, p3, p4) => new table_walker_js_1.TableWalker(p1, p2, p3, p4)
};

View File

@@ -0,0 +1,6 @@
import { Attribute } from '../enrich_mathml/enrich_attr.js';
export declare function splitAttribute(attr: string | null): string[];
export declare function getAttribute(node: Element, attr: Attribute): string;
export declare function getSemanticRoot(node: Element): Element;
export declare function getBySemanticId(root: Element, id: string): Element;
export declare function getAllBySemanticId(root: Element, id: string): Element[];

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.splitAttribute = splitAttribute;
exports.getAttribute = getAttribute;
exports.getSemanticRoot = getSemanticRoot;
exports.getBySemanticId = getBySemanticId;
exports.getAllBySemanticId = getAllBySemanticId;
const DomUtil = require("../common/dom_util.js");
const enrich_attr_js_1 = require("../enrich_mathml/enrich_attr.js");
function splitAttribute(attr) {
return !attr ? [] : attr.split(/,/);
}
function getAttribute(node, attr) {
return node.getAttribute(attr);
}
function getSemanticRoot(node) {
if (node.hasAttribute(enrich_attr_js_1.Attribute.TYPE) &&
!node.hasAttribute(enrich_attr_js_1.Attribute.PARENT)) {
return node;
}
const semanticNodes = DomUtil.querySelectorAllByAttr(node, enrich_attr_js_1.Attribute.TYPE);
for (let i = 0, semanticNode; (semanticNode = semanticNodes[i]); i++) {
if (!semanticNode.hasAttribute(enrich_attr_js_1.Attribute.PARENT)) {
return semanticNode;
}
}
return node;
}
function getBySemanticId(root, id) {
if (root.getAttribute(enrich_attr_js_1.Attribute.ID) === id) {
return root;
}
return DomUtil.querySelectorAllByAttrValue(root, enrich_attr_js_1.Attribute.ID, id)[0];
}
function getAllBySemanticId(root, id) {
if (root.getAttribute(enrich_attr_js_1.Attribute.ID) === id) {
return [root];
}
return DomUtil.querySelectorAllByAttrValue(root, enrich_attr_js_1.Attribute.ID, id);
}