explorer.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __assign = (this && this.__assign) || function () {
  18. __assign = Object.assign || function(t) {
  19. for (var s, i = 1, n = arguments.length; i < n; i++) {
  20. s = arguments[i];
  21. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  22. t[p] = s[p];
  23. }
  24. return t;
  25. };
  26. return __assign.apply(this, arguments);
  27. };
  28. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  29. if (k2 === undefined) k2 = k;
  30. var desc = Object.getOwnPropertyDescriptor(m, k);
  31. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  32. desc = { enumerable: true, get: function() { return m[k]; } };
  33. }
  34. Object.defineProperty(o, k2, desc);
  35. }) : (function(o, m, k, k2) {
  36. if (k2 === undefined) k2 = k;
  37. o[k2] = m[k];
  38. }));
  39. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  40. Object.defineProperty(o, "default", { enumerable: true, value: v });
  41. }) : function(o, v) {
  42. o["default"] = v;
  43. });
  44. var __importStar = (this && this.__importStar) || function (mod) {
  45. if (mod && mod.__esModule) return mod;
  46. var result = {};
  47. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  48. __setModuleDefault(result, mod);
  49. return result;
  50. };
  51. var __values = (this && this.__values) || function(o) {
  52. var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
  53. if (m) return m.call(o);
  54. if (o && typeof o.length === "number") return {
  55. next: function () {
  56. if (o && i >= o.length) o = void 0;
  57. return { value: o && o[i++], done: !o };
  58. }
  59. };
  60. throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
  61. };
  62. var __read = (this && this.__read) || function (o, n) {
  63. var m = typeof Symbol === "function" && o[Symbol.iterator];
  64. if (!m) return o;
  65. var i = m.call(o), r, ar = [], e;
  66. try {
  67. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  68. }
  69. catch (error) { e = { error: error }; }
  70. finally {
  71. try {
  72. if (r && !r.done && (m = i["return"])) m.call(i);
  73. }
  74. finally { if (e) throw e.error; }
  75. }
  76. return ar;
  77. };
  78. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  79. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  80. if (ar || !(i in from)) {
  81. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  82. ar[i] = from[i];
  83. }
  84. }
  85. return to.concat(ar || Array.prototype.slice.call(from));
  86. };
  87. var __importDefault = (this && this.__importDefault) || function (mod) {
  88. return (mod && mod.__esModule) ? mod : { "default": mod };
  89. };
  90. Object.defineProperty(exports, "__esModule", { value: true });
  91. exports.setA11yOption = exports.setA11yOptions = exports.ExplorerHandler = exports.ExplorerMathDocumentMixin = exports.ExplorerMathItemMixin = void 0;
  92. var MathItem_js_1 = require("../core/MathItem.js");
  93. var semantic_enrich_js_1 = require("./semantic-enrich.js");
  94. var Options_js_1 = require("../util/Options.js");
  95. var SerializedMmlVisitor_js_1 = require("../core/MmlTree/SerializedMmlVisitor.js");
  96. var MJContextMenu_js_1 = require("../ui/menu/MJContextMenu.js");
  97. var ke = __importStar(require("./explorer/KeyExplorer.js"));
  98. var me = __importStar(require("./explorer/MouseExplorer.js"));
  99. var TreeExplorer_js_1 = require("./explorer/TreeExplorer.js");
  100. var Region_js_1 = require("./explorer/Region.js");
  101. var sre_js_1 = __importDefault(require("./sre.js"));
  102. (0, MathItem_js_1.newState)('EXPLORER', 160);
  103. function ExplorerMathItemMixin(BaseMathItem, toMathML) {
  104. return (function (_super) {
  105. __extends(class_1, _super);
  106. function class_1() {
  107. var _this = _super !== null && _super.apply(this, arguments) || this;
  108. _this.explorers = {};
  109. _this.attached = [];
  110. _this.restart = [];
  111. _this.refocus = false;
  112. _this.savedId = null;
  113. return _this;
  114. }
  115. class_1.prototype.explorable = function (document, force) {
  116. if (force === void 0) { force = false; }
  117. if (this.state() >= MathItem_js_1.STATE.EXPLORER)
  118. return;
  119. if (!this.isEscaped && (document.options.enableExplorer || force)) {
  120. var node = this.typesetRoot;
  121. var mml = toMathML(this.root);
  122. if (this.savedId) {
  123. this.typesetRoot.setAttribute('sre-explorer-id', this.savedId);
  124. this.savedId = null;
  125. }
  126. this.explorers = initExplorers(document, node, mml);
  127. this.attachExplorers(document);
  128. }
  129. this.state(MathItem_js_1.STATE.EXPLORER);
  130. };
  131. class_1.prototype.attachExplorers = function (document) {
  132. var e_1, _a, e_2, _b;
  133. this.attached = [];
  134. var keyExplorers = [];
  135. try {
  136. for (var _c = __values(Object.keys(this.explorers)), _d = _c.next(); !_d.done; _d = _c.next()) {
  137. var key = _d.value;
  138. var explorer = this.explorers[key];
  139. if (explorer instanceof ke.AbstractKeyExplorer) {
  140. explorer.AddEvents();
  141. explorer.stoppable = false;
  142. keyExplorers.unshift(explorer);
  143. }
  144. if (document.options.a11y[key]) {
  145. explorer.Attach();
  146. this.attached.push(key);
  147. }
  148. else {
  149. explorer.Detach();
  150. }
  151. }
  152. }
  153. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  154. finally {
  155. try {
  156. if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
  157. }
  158. finally { if (e_1) throw e_1.error; }
  159. }
  160. try {
  161. for (var keyExplorers_1 = __values(keyExplorers), keyExplorers_1_1 = keyExplorers_1.next(); !keyExplorers_1_1.done; keyExplorers_1_1 = keyExplorers_1.next()) {
  162. var explorer = keyExplorers_1_1.value;
  163. if (explorer.attached) {
  164. explorer.stoppable = true;
  165. break;
  166. }
  167. }
  168. }
  169. catch (e_2_1) { e_2 = { error: e_2_1 }; }
  170. finally {
  171. try {
  172. if (keyExplorers_1_1 && !keyExplorers_1_1.done && (_b = keyExplorers_1.return)) _b.call(keyExplorers_1);
  173. }
  174. finally { if (e_2) throw e_2.error; }
  175. }
  176. };
  177. class_1.prototype.rerender = function (document, start) {
  178. var e_3, _a;
  179. if (start === void 0) { start = MathItem_js_1.STATE.RERENDER; }
  180. this.savedId = this.typesetRoot.getAttribute('sre-explorer-id');
  181. this.refocus = (window.document.activeElement === this.typesetRoot);
  182. try {
  183. for (var _b = __values(this.attached), _c = _b.next(); !_c.done; _c = _b.next()) {
  184. var key = _c.value;
  185. var explorer = this.explorers[key];
  186. if (explorer.active) {
  187. this.restart.push(key);
  188. explorer.Stop();
  189. }
  190. }
  191. }
  192. catch (e_3_1) { e_3 = { error: e_3_1 }; }
  193. finally {
  194. try {
  195. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  196. }
  197. finally { if (e_3) throw e_3.error; }
  198. }
  199. _super.prototype.rerender.call(this, document, start);
  200. };
  201. class_1.prototype.updateDocument = function (document) {
  202. var _this = this;
  203. _super.prototype.updateDocument.call(this, document);
  204. this.refocus && this.typesetRoot.focus();
  205. this.restart.forEach(function (x) { return _this.explorers[x].Start(); });
  206. this.restart = [];
  207. this.refocus = false;
  208. };
  209. return class_1;
  210. }(BaseMathItem));
  211. }
  212. exports.ExplorerMathItemMixin = ExplorerMathItemMixin;
  213. function ExplorerMathDocumentMixin(BaseDocument) {
  214. var _a;
  215. return _a = (function (_super) {
  216. __extends(class_2, _super);
  217. function class_2() {
  218. var args = [];
  219. for (var _i = 0; _i < arguments.length; _i++) {
  220. args[_i] = arguments[_i];
  221. }
  222. var _this = _super.apply(this, __spreadArray([], __read(args), false)) || this;
  223. var ProcessBits = _this.constructor.ProcessBits;
  224. if (!ProcessBits.has('explorer')) {
  225. ProcessBits.allocate('explorer');
  226. }
  227. var visitor = new SerializedMmlVisitor_js_1.SerializedMmlVisitor(_this.mmlFactory);
  228. var toMathML = (function (node) { return visitor.visitTree(node); });
  229. _this.options.MathItem = ExplorerMathItemMixin(_this.options.MathItem, toMathML);
  230. _this.explorerRegions = initExplorerRegions(_this);
  231. return _this;
  232. }
  233. class_2.prototype.explorable = function () {
  234. var e_4, _a;
  235. if (!this.processed.isSet('explorer')) {
  236. if (this.options.enableExplorer) {
  237. try {
  238. for (var _b = __values(this.math), _c = _b.next(); !_c.done; _c = _b.next()) {
  239. var math = _c.value;
  240. math.explorable(this);
  241. }
  242. }
  243. catch (e_4_1) { e_4 = { error: e_4_1 }; }
  244. finally {
  245. try {
  246. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  247. }
  248. finally { if (e_4) throw e_4.error; }
  249. }
  250. }
  251. this.processed.set('explorer');
  252. }
  253. return this;
  254. };
  255. class_2.prototype.state = function (state, restore) {
  256. if (restore === void 0) { restore = false; }
  257. _super.prototype.state.call(this, state, restore);
  258. if (state < MathItem_js_1.STATE.EXPLORER) {
  259. this.processed.clear('explorer');
  260. }
  261. return this;
  262. };
  263. return class_2;
  264. }(BaseDocument)),
  265. _a.OPTIONS = __assign(__assign({}, BaseDocument.OPTIONS), { enableExplorer: true, renderActions: (0, Options_js_1.expandable)(__assign(__assign({}, BaseDocument.OPTIONS.renderActions), { explorable: [MathItem_js_1.STATE.EXPLORER] })), sre: (0, Options_js_1.expandable)(__assign(__assign({}, BaseDocument.OPTIONS.sre), { speech: 'shallow' })), a11y: {
  266. align: 'top',
  267. backgroundColor: 'Blue',
  268. backgroundOpacity: 20,
  269. braille: false,
  270. flame: false,
  271. foregroundColor: 'Black',
  272. foregroundOpacity: 100,
  273. highlight: 'None',
  274. hover: false,
  275. infoPrefix: false,
  276. infoRole: false,
  277. infoType: false,
  278. keyMagnifier: false,
  279. magnification: 'None',
  280. magnify: '400%',
  281. mouseMagnifier: false,
  282. speech: true,
  283. subtitles: true,
  284. treeColoring: false,
  285. viewBraille: false
  286. } }),
  287. _a;
  288. }
  289. exports.ExplorerMathDocumentMixin = ExplorerMathDocumentMixin;
  290. function ExplorerHandler(handler, MmlJax) {
  291. if (MmlJax === void 0) { MmlJax = null; }
  292. if (!handler.documentClass.prototype.enrich && MmlJax) {
  293. handler = (0, semantic_enrich_js_1.EnrichHandler)(handler, MmlJax);
  294. }
  295. handler.documentClass = ExplorerMathDocumentMixin(handler.documentClass);
  296. return handler;
  297. }
  298. exports.ExplorerHandler = ExplorerHandler;
  299. function initExplorerRegions(document) {
  300. return {
  301. speechRegion: new Region_js_1.LiveRegion(document),
  302. brailleRegion: new Region_js_1.LiveRegion(document),
  303. magnifier: new Region_js_1.HoverRegion(document),
  304. tooltip1: new Region_js_1.ToolTip(document),
  305. tooltip2: new Region_js_1.ToolTip(document),
  306. tooltip3: new Region_js_1.ToolTip(document)
  307. };
  308. }
  309. var allExplorers = {
  310. speech: function (doc, node) {
  311. var _a;
  312. var rest = [];
  313. for (var _i = 2; _i < arguments.length; _i++) {
  314. rest[_i - 2] = arguments[_i];
  315. }
  316. var explorer = (_a = ke.SpeechExplorer).create.apply(_a, __spreadArray([doc, doc.explorerRegions.speechRegion, node], __read(rest), false));
  317. explorer.speechGenerator.setOptions({
  318. locale: doc.options.sre.locale, domain: doc.options.sre.domain,
  319. style: doc.options.sre.style, modality: 'speech'
  320. });
  321. var locale = explorer.speechGenerator.getOptions().locale;
  322. if (locale !== sre_js_1.default.engineSetup().locale) {
  323. doc.options.sre.locale = sre_js_1.default.engineSetup().locale;
  324. explorer.speechGenerator.setOptions({ locale: doc.options.sre.locale });
  325. }
  326. explorer.showRegion = 'subtitles';
  327. return explorer;
  328. },
  329. braille: function (doc, node) {
  330. var _a;
  331. var rest = [];
  332. for (var _i = 2; _i < arguments.length; _i++) {
  333. rest[_i - 2] = arguments[_i];
  334. }
  335. var explorer = (_a = ke.SpeechExplorer).create.apply(_a, __spreadArray([doc, doc.explorerRegions.brailleRegion, node], __read(rest), false));
  336. explorer.speechGenerator.setOptions({ locale: 'nemeth', domain: 'default',
  337. style: 'default', modality: 'braille' });
  338. explorer.showRegion = 'viewBraille';
  339. return explorer;
  340. },
  341. keyMagnifier: function (doc, node) {
  342. var _a;
  343. var rest = [];
  344. for (var _i = 2; _i < arguments.length; _i++) {
  345. rest[_i - 2] = arguments[_i];
  346. }
  347. return (_a = ke.Magnifier).create.apply(_a, __spreadArray([doc, doc.explorerRegions.magnifier, node], __read(rest), false));
  348. },
  349. mouseMagnifier: function (doc, node) {
  350. var _rest = [];
  351. for (var _i = 2; _i < arguments.length; _i++) {
  352. _rest[_i - 2] = arguments[_i];
  353. }
  354. return me.ContentHoverer.create(doc, doc.explorerRegions.magnifier, node, function (x) { return x.hasAttribute('data-semantic-type'); }, function (x) { return x; });
  355. },
  356. hover: function (doc, node) {
  357. var _rest = [];
  358. for (var _i = 2; _i < arguments.length; _i++) {
  359. _rest[_i - 2] = arguments[_i];
  360. }
  361. return me.FlameHoverer.create(doc, null, node);
  362. },
  363. infoType: function (doc, node) {
  364. var _rest = [];
  365. for (var _i = 2; _i < arguments.length; _i++) {
  366. _rest[_i - 2] = arguments[_i];
  367. }
  368. return me.ValueHoverer.create(doc, doc.explorerRegions.tooltip1, node, function (x) { return x.hasAttribute('data-semantic-type'); }, function (x) { return x.getAttribute('data-semantic-type'); });
  369. },
  370. infoRole: function (doc, node) {
  371. var _rest = [];
  372. for (var _i = 2; _i < arguments.length; _i++) {
  373. _rest[_i - 2] = arguments[_i];
  374. }
  375. return me.ValueHoverer.create(doc, doc.explorerRegions.tooltip2, node, function (x) { return x.hasAttribute('data-semantic-role'); }, function (x) { return x.getAttribute('data-semantic-role'); });
  376. },
  377. infoPrefix: function (doc, node) {
  378. var _rest = [];
  379. for (var _i = 2; _i < arguments.length; _i++) {
  380. _rest[_i - 2] = arguments[_i];
  381. }
  382. return me.ValueHoverer.create(doc, doc.explorerRegions.tooltip3, node, function (x) { return x.hasAttribute('data-semantic-prefix'); }, function (x) { return x.getAttribute('data-semantic-prefix'); });
  383. },
  384. flame: function (doc, node) {
  385. var _rest = [];
  386. for (var _i = 2; _i < arguments.length; _i++) {
  387. _rest[_i - 2] = arguments[_i];
  388. }
  389. return TreeExplorer_js_1.FlameColorer.create(doc, null, node);
  390. },
  391. treeColoring: function (doc, node) {
  392. var rest = [];
  393. for (var _i = 2; _i < arguments.length; _i++) {
  394. rest[_i - 2] = arguments[_i];
  395. }
  396. return TreeExplorer_js_1.TreeColorer.create.apply(TreeExplorer_js_1.TreeColorer, __spreadArray([doc, null, node], __read(rest), false));
  397. }
  398. };
  399. function initExplorers(document, node, mml) {
  400. var e_5, _a;
  401. var explorers = {};
  402. try {
  403. for (var _b = __values(Object.keys(allExplorers)), _c = _b.next(); !_c.done; _c = _b.next()) {
  404. var key = _c.value;
  405. explorers[key] = allExplorers[key](document, node, mml);
  406. }
  407. }
  408. catch (e_5_1) { e_5 = { error: e_5_1 }; }
  409. finally {
  410. try {
  411. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  412. }
  413. finally { if (e_5) throw e_5.error; }
  414. }
  415. return explorers;
  416. }
  417. function setA11yOptions(document, options) {
  418. var e_6, _a;
  419. var sreOptions = sre_js_1.default.engineSetup();
  420. for (var key in options) {
  421. if (document.options.a11y[key] !== undefined) {
  422. setA11yOption(document, key, options[key]);
  423. if (key === 'locale') {
  424. document.options.sre[key] = options[key];
  425. }
  426. continue;
  427. }
  428. if (sreOptions[key] !== undefined) {
  429. document.options.sre[key] = options[key];
  430. }
  431. }
  432. try {
  433. for (var _b = __values(document.math), _c = _b.next(); !_c.done; _c = _b.next()) {
  434. var item = _c.value;
  435. item.attachExplorers(document);
  436. }
  437. }
  438. catch (e_6_1) { e_6 = { error: e_6_1 }; }
  439. finally {
  440. try {
  441. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  442. }
  443. finally { if (e_6) throw e_6.error; }
  444. }
  445. }
  446. exports.setA11yOptions = setA11yOptions;
  447. function setA11yOption(document, option, value) {
  448. switch (option) {
  449. case 'magnification':
  450. switch (value) {
  451. case 'None':
  452. document.options.a11y.magnification = value;
  453. document.options.a11y.keyMagnifier = false;
  454. document.options.a11y.mouseMagnifier = false;
  455. break;
  456. case 'Keyboard':
  457. document.options.a11y.magnification = value;
  458. document.options.a11y.keyMagnifier = true;
  459. document.options.a11y.mouseMagnifier = false;
  460. break;
  461. case 'Mouse':
  462. document.options.a11y.magnification = value;
  463. document.options.a11y.keyMagnifier = false;
  464. document.options.a11y.mouseMagnifier = true;
  465. break;
  466. }
  467. break;
  468. case 'highlight':
  469. switch (value) {
  470. case 'None':
  471. document.options.a11y.highlight = value;
  472. document.options.a11y.hover = false;
  473. document.options.a11y.flame = false;
  474. break;
  475. case 'Hover':
  476. document.options.a11y.highlight = value;
  477. document.options.a11y.hover = true;
  478. document.options.a11y.flame = false;
  479. break;
  480. case 'Flame':
  481. document.options.a11y.highlight = value;
  482. document.options.a11y.hover = false;
  483. document.options.a11y.flame = true;
  484. break;
  485. }
  486. break;
  487. default:
  488. document.options.a11y[option] = value;
  489. }
  490. }
  491. exports.setA11yOption = setA11yOption;
  492. var csPrefsSetting = {};
  493. var csPrefsVariables = function (menu, prefs) {
  494. var e_7, _a;
  495. var srVariable = menu.pool.lookup('speechRules');
  496. var _loop_1 = function (pref) {
  497. if (csPrefsSetting[pref])
  498. return "continue";
  499. menu.factory.get('variable')(menu.factory, {
  500. name: 'csprf_' + pref,
  501. setter: function (value) {
  502. csPrefsSetting[pref] = value;
  503. srVariable.setValue('clearspeak-' +
  504. sre_js_1.default.clearspeakPreferences.addPreference(sre_js_1.default.clearspeakStyle(), pref, value));
  505. },
  506. getter: function () { return csPrefsSetting[pref] || 'Auto'; }
  507. }, menu.pool);
  508. };
  509. try {
  510. for (var prefs_1 = __values(prefs), prefs_1_1 = prefs_1.next(); !prefs_1_1.done; prefs_1_1 = prefs_1.next()) {
  511. var pref = prefs_1_1.value;
  512. _loop_1(pref);
  513. }
  514. }
  515. catch (e_7_1) { e_7 = { error: e_7_1 }; }
  516. finally {
  517. try {
  518. if (prefs_1_1 && !prefs_1_1.done && (_a = prefs_1.return)) _a.call(prefs_1);
  519. }
  520. finally { if (e_7) throw e_7.error; }
  521. }
  522. };
  523. var csSelectionBox = function (menu, locale) {
  524. var e_8, _a;
  525. var prefs = sre_js_1.default.clearspeakPreferences.getLocalePreferences();
  526. var props = prefs[locale];
  527. if (!props) {
  528. var csEntry = menu.findID('Accessibility', 'Speech', 'Clearspeak');
  529. if (csEntry) {
  530. csEntry.disable();
  531. }
  532. return null;
  533. }
  534. csPrefsVariables(menu, Object.keys(props));
  535. var items = [];
  536. var _loop_2 = function (prop) {
  537. items.push({
  538. 'title': prop,
  539. 'values': props[prop].map(function (x) { return x.replace(RegExp('^' + prop + '_'), ''); }),
  540. 'variable': 'csprf_' + prop
  541. });
  542. };
  543. try {
  544. for (var _b = __values(Object.getOwnPropertyNames(props)), _c = _b.next(); !_c.done; _c = _b.next()) {
  545. var prop = _c.value;
  546. _loop_2(prop);
  547. }
  548. }
  549. catch (e_8_1) { e_8 = { error: e_8_1 }; }
  550. finally {
  551. try {
  552. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  553. }
  554. finally { if (e_8) throw e_8.error; }
  555. }
  556. var sb = menu.factory.get('selectionBox')(menu.factory, {
  557. 'title': 'Clearspeak Preferences',
  558. 'signature': '',
  559. 'order': 'alphabetic',
  560. 'grid': 'square',
  561. 'selections': items
  562. }, menu);
  563. return { 'type': 'command',
  564. 'id': 'ClearspeakPreferences',
  565. 'content': 'Select Preferences',
  566. 'action': function () { return sb.post(0, 0); } };
  567. };
  568. var csMenu = function (menu, sub) {
  569. var locale = menu.pool.lookup('locale').getValue();
  570. var box = csSelectionBox(menu, locale);
  571. var items = [];
  572. try {
  573. items = sre_js_1.default.clearspeakPreferences.smartPreferences(menu.mathItem, locale);
  574. }
  575. catch (e) {
  576. console.log(e);
  577. }
  578. if (box) {
  579. items.splice(2, 0, box);
  580. }
  581. return menu.factory.get('subMenu')(menu.factory, {
  582. items: items,
  583. id: 'Clearspeak'
  584. }, sub);
  585. };
  586. MJContextMenu_js_1.MJContextMenu.DynamicSubmenus.set('Clearspeak', csMenu);
  587. var language = function (menu, sub) {
  588. var e_9, _a;
  589. var radios = [];
  590. try {
  591. for (var _b = __values(sre_js_1.default.locales.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
  592. var lang = _c.value;
  593. if (lang === 'nemeth')
  594. continue;
  595. radios.push({ type: 'radio', id: lang,
  596. content: sre_js_1.default.locales.get(lang) || lang, variable: 'locale' });
  597. }
  598. }
  599. catch (e_9_1) { e_9 = { error: e_9_1 }; }
  600. finally {
  601. try {
  602. if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
  603. }
  604. finally { if (e_9) throw e_9.error; }
  605. }
  606. radios.sort(function (x, y) { return x.content.localeCompare(y.content, 'en'); });
  607. return menu.factory.get('subMenu')(menu.factory, {
  608. items: radios, id: 'Language'
  609. }, sub);
  610. };
  611. MJContextMenu_js_1.MJContextMenu.DynamicSubmenus.set('A11yLanguage', language);
  612. //# sourceMappingURL=explorer.js.map