Debian Codegraph @

unpacked/extensions/a11y/explorer.js

raw
1 MathJax.Hub.Register.StartupHook("Sre Ready", function() {
2 var o, r, s = MathJax.Hub.config.menuSettings, l = {};
3 MathJax.Hub.Register.StartupHook("MathEvents Ready", function() {
4 o = MathJax.Extension.MathEvents.Event.False, r = MathJax.Extension.MathEvents.Event.KEY;
5 });
6 var h = MathJax.Extension.explorer = {
7 version: "1.6.0",
8 dependents: [],
9 defaults: {
10 walker: "table",
11 highlight: "none",
12 background: "blue",
13 foreground: "black",
14 speech: !0,
15 generation: "lazy",
16 subtitle: !1,
17 ruleset: "mathspeak-default"
18 },
19 eagerComplexity: 80,
20 prefix: "Assistive-",
21 hook: null,
22 locHook: null,
23 oldrules: null,
24 addMenuOption: function(e, t) {
25 s[h.prefix + e] = t;
26 },
27 addDefaults: function() {
28 for (var e, t = MathJax.Hub.CombineConfig("explorer", h.defaults), a = Object.keys(t), i = 0; e = a[i]; i++) void 0 === s[h.prefix + e] && h.addMenuOption(e, t[e]);
29 h.setSpeechOption(), u.Reset();
30 },
31 setOption: function(e, t) {
32 s[h.prefix + e] !== t && (h.addMenuOption(e, t), u.Reset());
33 },
34 getOption: function(e) {
35 return s[h.prefix + e];
36 },
37 speechOption: function(e) {
38 h.oldrules !== e.value && (h.setSpeechOption(), u.Regenerate());
39 },
40 setSpeechOption: function() {
41 var e = s[h.prefix + "ruleset"], t = e.split("-");
42 sre.System.getInstance().setupEngine({
43 locale: MathJax.Localization.locale,
44 domain: h.Domain(t[0]),
45 style: t[1]
46 }), h.oldrules = e;
47 },
48 Domain: function(e) {
49 switch (e) {
50 case "chromevox":
51 return "default";
52
53 case "clearspeak":
54 return "clearspeak";
55
56 case "mathspeak":
57 default:
58 return "mathspeak";
59 }
60 },
61 Enable: function(e, t) {
62 s.explorer = !0, t && (l.explorer = !0), MathJax.Extension.collapsible.Enable(!1, t),
63 MathJax.Extension.AssistiveMML && (MathJax.Extension.AssistiveMML.config.disabled = !0,
64 s.assistiveMML = !1, t && (l.assistiveMML = !1)), this.DisableMenus(!1), this.hook || (this.hook = MathJax.Hub.Register.MessageHook("New Math", [ "Register", this.Explorer ])),
65 this.locHook || (this.locHook = MathJax.Hub.Register.MessageHook("Locale Reset", [ "RemoveSpeech", this.Explorer ])),
66 e && MathJax.Hub.Queue([ "Reprocess", MathJax.Hub ]);
67 },
68 Disable: function(e, t) {
69 s.explorer = !1, t && (l.explorer = !1), this.DisableMenus(!0), this.hook && (MathJax.Hub.UnRegister.MessageHook(this.hook),
70 this.hook = null);
71 for (var a = this.dependents.length - 1; 0 <= a; a--) {
72 var i = this.dependents[a];
73 i.Disable && i.Disable(!1, t);
74 }
75 },
76 DisableMenus: function(e) {
77 if (MathJax.Menu) {
78 var t = MathJax.Menu.menu.FindId("Accessibility", "Explorer");
79 if (t) {
80 for (var a, i = (t = t.submenu).items, n = 2; a = i[n]; n++) a.disabled = e;
81 e || !t.FindId("SpeechOutput") || s[h.prefix + "speech"] || (t.FindId("Subtitles").disabled = !0);
82 }
83 }
84 },
85 Dependent: function(e) {
86 this.dependents.push(e);
87 }
88 }, n = MathJax.Object.Subclass({
89 div: null,
90 inner: null,
91 Init: function() {
92 this.div = n.Create("assertive"), this.inner = MathJax.HTML.addElement(this.div, "div");
93 },
94 Add: function() {
95 n.added || (document.body.appendChild(this.div), n.added = !0);
96 },
97 Show: function(e, t) {
98 this.div.classList.add("MJX_LiveRegion_Show");
99 var a = e.getBoundingClientRect(), i = a.bottom + 10 + window.pageYOffset, n = a.left + window.pageXOffset;
100 this.div.style.top = i + "px", this.div.style.left = n + "px";
101 var o = t.colorString();
102 this.inner.style.backgroundColor = o.background, this.inner.style.color = o.foreground;
103 },
104 Hide: function(e) {
105 this.div.classList.remove("MJX_LiveRegion_Show");
106 },
107 Clear: function() {
108 this.Update(""), this.inner.style.top = "", this.inner.style.backgroundColor = "";
109 },
110 Update: function(e) {
111 h.getOption("speech") && n.Update(this.inner, e);
112 }
113 }, {
114 ANNOUNCE: "Navigatable Math in page. Explore with enter or shift space and arrow keys. Expand or collapse elements hitting enter.",
115 announced: !1,
116 added: !1,
117 styles: {
118 ".MJX_LiveRegion": {
119 position: "absolute",
120 top: "0",
121 height: "1px",
122 width: "1px",
123 padding: "1px",
124 overflow: "hidden"
125 },
126 ".MJX_LiveRegion_Show": {
127 top: "0",
128 position: "absolute",
129 width: "auto",
130 height: "auto",
131 padding: "0px 0px",
132 opacity: 1,
133 "z-index": "202",
134 left: 0,
135 right: 0,
136 margin: "0 auto",
137 "background-color": "white",
138 "box-shadow": "0px 10px 20px #888",
139 border: "2px solid #CCCCCC"
140 }
141 },
142 Create: function(e) {
143 var t = MathJax.HTML.Element("div", {
144 className: "MJX_LiveRegion"
145 });
146 return t.setAttribute("aria-live", e), t;
147 },
148 Update: MathJax.Hub.Browser.isPC ? function(e, t) {
149 e.textContent = "", setTimeout(function() {
150 e.textContent = t;
151 }, 100);
152 } : function(e, t) {
153 e.textContent = "", e.textContent = t;
154 },
155 Announce: function() {
156 var e;
157 h.getOption("speech") && (n.announced = !0, MathJax.Ajax.Styles(n.styles), e = n.Create("polite"),
158 document.body.appendChild(e), n.Update(e, n.ANNOUNCE), setTimeout(function() {
159 document.body.removeChild(e);
160 }, 1e3));
161 }
162 });
163 MathJax.Extension.explorer.LiveRegion = n;
164 var e = MathJax.Ajax.fileURL(MathJax.Ajax.config.path.a11y), u = MathJax.Extension.explorer.Explorer = {
165 liveRegion: n(),
166 walker: null,
167 highlighter: null,
168 hoverer: null,
169 flamer: null,
170 speechDiv: null,
171 earconFile: e + "/invalid_keypress" + (-1 !== [ "Firefox", "Chrome", "Opera" ].indexOf(MathJax.Hub.Browser.name) ? ".ogg" : ".mp3"),
172 expanded: !1,
173 focusoutEvent: MathJax.Hub.Browser.isFirefox ? "blur" : "focusout",
174 focusinEvent: "focus",
175 ignoreFocusOut: !1,
176 jaxCache: {},
177 messageID: null,
178 Reset: function() {
179 u.FlameEnriched();
180 },
181 Register: function(e) {
182 var t, a;
183 !h.hook || (t = document.getElementById(e[1])) && t.id && ((a = MathJax.Hub.getJaxFor(t.id)) && a.enriched && (u.StateChange(t.id, a),
184 u.liveRegion.Add(), u.AddEvent(t)));
185 },
186 StateChange: function(e, t) {
187 u.GetHighlighter(.2);
188 var a = u.jaxCache[e];
189 a && a === t.root || (a && sre.Walker.resetState(e + "-Frame"), u.jaxCache[e] = t.root);
190 },
191 AddAria: function(e) {
192 e.setAttribute("role", "application"), e.setAttribute("aria-label", "Math");
193 },
194 AddHook: function(i) {
195 u.RemoveHook(), u.hook = MathJax.Hub.Register.MessageHook("End Math", function(e) {
196 var t = e[1].id + "-Frame", a = document.getElementById(t);
197 i && t === u.expanded && (u.ActivateWalker(a, i), a.focus(), u.expanded = !1);
198 });
199 },
200 RemoveHook: function() {
201 u.hook && (MathJax.Hub.UnRegister.MessageHook(u.hook), u.hook = null);
202 },
203 AddMessage: function() {
204 return MathJax.Message.Set("Generating Speech Output");
205 },
206 RemoveMessage: function(e) {
207 e && MathJax.Message.Clear(e);
208 },
209 AddEvent: function(e) {
210 var t, a = e.id + "-Frame", i = e.previousSibling;
211 i && (t = i.id !== a ? i.firstElementChild : i, u.AddAria(t), u.AddMouseEvents(t),
212 "MathJax_MathML" === t.className && (t = t.firstElementChild), t && (t.onkeydown = u.Keydown,
213 u.Flame(t), t.addEventListener(u.focusinEvent, function(e) {
214 h.hook && (n.announced || n.Announce());
215 }), t.addEventListener(u.focusoutEvent, function(e) {
216 h.hook && (u.ignoreFocusOut && (u.ignoreFocusOut = !1, "enter" === u.walker.moved) ? e.target.focus() : u.walker && u.DeactivateWalker());
217 }), h.getOption("speech") && u.AddSpeech(t)));
218 },
219 AddSpeech: function(e) {
220 var t = e.id, a = MathJax.Hub.getJaxFor(t).root.toMathML();
221 if (e.getAttribute("haslabel") || u.AddMathLabel(a, t), !e.getAttribute("hasspeech")) switch (MathJax.Hub.config.explorer.generation) {
222 case "eager":
223 u.AddSpeechEager(a, t);
224 break;
225
226 case "mixed":
227 e.querySelectorAll("[data-semantic-complexity]").length >= h.eagerComplexity && u.AddSpeechEager(a, t);
228 }
229 },
230 AddSpeechLazy: function(e) {
231 var t = new sre.TreeSpeechGenerator();
232 t.setRebuilt(u.walker.getRebuilt()), t.getSpeech(u.walker.rootNode, u.walker.getXml()),
233 e.setAttribute("hasspeech", "true");
234 },
235 AddSpeechEager: function(e, t) {
236 u.MakeSpeechTask(e, t, sre.TreeSpeechGenerator, function(e, t) {
237 e.setAttribute("hasspeech", "true");
238 }, 5);
239 },
240 AddMathLabel: function(e, t) {
241 u.MakeSpeechTask(e, t, sre.SummarySpeechGenerator, function(e, t) {
242 e.setAttribute("haslabel", "true"), e.setAttribute("aria-label", t);
243 }, 5);
244 },
245 MakeSpeechTask: function(i, n, o, r, e) {
246 var s = u.AddMessage();
247 setTimeout(function() {
248 var e = new o(), t = document.getElementById(n), a = new sre.DummyWalker(t, e, u.highlighter, i).speech();
249 a && r(t, a), u.RemoveMessage(s);
250 }, e);
251 },
252 Keydown: function(e) {
253 var t = e.keyCode;
254 if (t === r.ESCAPE) {
255 if (!u.walker) return;
256 return u.RemoveHook(), u.DeactivateWalker(), void o(e);
257 }
258 if (u.walker && u.walker.isActive()) {
259 t = t === r.RETURN ? r.DASH : t, void 0 !== u.walker.modifier && (u.walker.modifier = e.shiftKey);
260 var a = u.walker.move(t);
261 if (null === a) return;
262 if (a) {
263 if ("expand" === u.walker.moved) {
264 if (u.expanded = u.walker.node.id, MathJax.Hub.Browser.isEdge) return u.ignoreFocusOut = !0,
265 void u.DeactivateWalker();
266 if (MathJax.Hub.Browser.isFirefox || MathJax.Hub.Browser.isMSIE) return void u.DeactivateWalker();
267 }
268 u.liveRegion.Update(u.walker.speech()), u.Highlight();
269 } else u.PlayEarcon();
270 o(e);
271 } else {
272 var i = e.target;
273 if (t === r.SPACE && !e.shiftKey) return MathJax.Extension.MathEvents.Event.ContextMenu(e, i),
274 void o(e);
275 if (h.hook && (t === r.RETURN || t === r.SPACE && e.shiftKey)) {
276 var n = MathJax.Hub.getJaxFor(i);
277 return u.ActivateWalker(i, n), u.AddHook(n), void o(e);
278 }
279 }
280 },
281 GetHighlighter: function(e) {
282 u.highlighter = sre.HighlighterFactory.highlighter({
283 color: h.getOption("background"),
284 alpha: e
285 }, {
286 color: h.getOption("foreground"),
287 alpha: 1
288 }, {
289 renderer: MathJax.Hub.outputJax["jax/mml"][0].id,
290 browser: MathJax.Hub.Browser.name
291 });
292 },
293 AddMouseEvents: function(e) {
294 sre.HighlighterFactory.addEvents(e, {
295 mouseover: u.MouseOver,
296 mouseout: u.MouseOut
297 }, {
298 renderer: MathJax.Hub.outputJax["jax/mml"][0].id,
299 browser: MathJax.Hub.Browser.name
300 });
301 },
302 MouseOver: function(e) {
303 var t;
304 "none" !== h.getOption("highlight") && ("hover" === h.getOption("highlight") && (t = e.currentTarget,
305 u.GetHighlighter(.1), u.highlighter.highlight([ t ]), u.hoverer = !0), o(e));
306 },
307 MouseOut: function(e) {
308 return u.hoverer && (u.highlighter.unhighlight(), u.hoverer = !1), o(e);
309 },
310 Flame: function(e) {
311 if ("flame" === h.getOption("highlight")) return u.GetHighlighter(.05), u.highlighter.highlightAll(e),
312 void (u.flamer = !0);
313 },
314 UnFlame: function() {
315 u.flamer && (u.highlighter.unhighlightAll(), u.flamer = null);
316 },
317 FlameEnriched: function() {
318 u.UnFlame();
319 for (var e, t = 0, a = MathJax.Hub.getAllJax(); e = a[t]; t++) u.Flame(e.SourceElement().previousSibling);
320 },
321 Walkers: {
322 syntactic: sre.SyntaxWalker,
323 table: sre.TableWalker,
324 semantic: sre.SemanticWalker,
325 none: sre.DummyWalker
326 },
327 ActivateWalker: function(e, t) {
328 var a = h.getOption("speech"), i = h.getOption("walker") ? u.Walkers[MathJax.Hub.config.explorer.walker] : u.Walkers.none, n = a ? new sre.DirectSpeechGenerator() : new sre.DummySpeechGenerator(), o = sre.System.getInstance().engineSetup();
329 n.setOptions({
330 locale: o.locale,
331 domain: o.domain,
332 style: o.style,
333 modality: "speech"
334 }), u.GetHighlighter(.2), u.walker = new i(e, n, u.highlighter, t.root.toMathML()),
335 a && !e.getAttribute("hasspeech") && u.AddSpeechLazy(e), u.walker.activate(), a && (h.getOption("subtitle") && u.liveRegion.Show(e, u.highlighter),
336 u.liveRegion.Update(u.walker.speech())), u.Highlight(), u.ignoreFocusOut && setTimeout(function() {
337 u.ignoreFocusOut = !1;
338 }, 500);
339 },
340 DeactivateWalker: function() {
341 var e = sre.System.getInstance().engineSetup(), t = "clearspeak" === e.domain ? "default" : e.style;
342 h.setOption("ruleset", e.domain + "-" + t), u.liveRegion.Clear(), u.liveRegion.Hide(),
343 u.Unhighlight(), u.currentHighlight = null, u.walker.deactivate(), u.walker = null;
344 },
345 Highlight: function() {
346 u.Unhighlight(), u.highlighter.highlight(u.walker.getFocus().getNodes());
347 },
348 Unhighlight: function() {
349 u.highlighter.unhighlight();
350 },
351 PlayEarcon: function() {
352 new Audio(u.earconFile).play();
353 },
354 SpeechOutput: function() {
355 u.Reset();
356 [ "Subtitles" ].forEach(function(e) {
357 var t = MathJax.Menu.menu.FindId("Accessibility", "Explorer", e);
358 t && (t.disabled = !t.disabled);
359 }), u.Regenerate();
360 },
361 RemoveSpeech: function() {
362 h.setSpeechOption();
363 for (var e, t = 0, a = MathJax.Hub.getAllJax(); e = a[t]; t++) {
364 var i = document.getElementById(e.inputID + "-Frame");
365 i && (i.removeAttribute("hasspeech"), i.removeAttribute("haslabel"));
366 }
367 },
368 Regenerate: function() {
369 for (var e, t = 0, a = MathJax.Hub.getAllJax(); e = a[t]; t++) {
370 var i = document.getElementById(e.inputID + "-Frame");
371 i && (i.removeAttribute("hasspeech"), u.AddSpeech(i));
372 }
373 },
374 Startup: function() {
375 var e = MathJax.Extension.collapsible;
376 e && e.Dependent(h), h.addDefaults();
377 }
378 };
379 MathJax.Hub.Register.StartupHook("End Extensions", function() {
380 h[!1 === s.explorer ? "Disable" : "Enable"](), MathJax.Hub.Startup.signal.Post("Explorer Ready"),
381 MathJax.Hub.Register.StartupHook("MathMenu Ready", function() {
382 l = MathJax.Menu.cookie;
383 var e, t = MathJax.Menu.ITEM, a = MathJax.Menu.menu, i = {
384 action: u.Reset
385 }, n = {
386 action: h.speechOption
387 }, o = t.SUBMENU([ "Explorer", "Explorer" ], t.CHECKBOX([ "Active", "Active" ], "explorer", {
388 action: function(e) {
389 h[s.explorer ? "Enable" : "Disable"](!0, !0), MathJax.Menu.saveCookie();
390 }
391 }), t.RULE(), t.CHECKBOX([ "Walker", "Walker" ], "Assistive-walker"), t.SUBMENU([ "Highlight", "Highlight" ], t.RADIO([ "none", "None" ], "Assistive-highlight", i), t.RADIO([ "hover", "Hover" ], "Assistive-highlight", i), t.RADIO([ "flame", "Flame" ], "Assistive-highlight", i)), t.SUBMENU([ "Background", "Background" ], t.RADIO([ "blue", "Blue" ], "Assistive-background", i), t.RADIO([ "red", "Red" ], "Assistive-background", i), t.RADIO([ "green", "Green" ], "Assistive-background", i), t.RADIO([ "yellow", "Yellow" ], "Assistive-background", i), t.RADIO([ "cyan", "Cyan" ], "Assistive-background", i), t.RADIO([ "magenta", "Magenta" ], "Assistive-background", i), t.RADIO([ "white", "White" ], "Assistive-background", i), t.RADIO([ "black", "Black" ], "Assistive-background", i)), t.SUBMENU([ "Foreground", "Foreground" ], t.RADIO([ "black", "Black" ], "Assistive-foreground", i), t.RADIO([ "white", "White" ], "Assistive-foreground", i), t.RADIO([ "magenta", "Magenta" ], "Assistive-foreground", i), t.RADIO([ "cyan", "Cyan" ], "Assistive-foreground", i), t.RADIO([ "yellow", "Yellow" ], "Assistive-foreground", i), t.RADIO([ "green", "Green" ], "Assistive-foreground", i), t.RADIO([ "red", "Red" ], "Assistive-foreground", i), t.RADIO([ "blue", "Blue" ], "Assistive-foreground", i)), t.RULE(), t.CHECKBOX([ "SpeechOutput", "Speech Output" ], "Assistive-speech", {
392 action: u.SpeechOutput
393 }), t.CHECKBOX([ "Subtitles", "Subtitles" ], "Assistive-subtitle", {
394 disabled: !s["Assistive-speech"]
395 }), t.RULE(), t.SUBMENU([ "Mathspeak", "Mathspeak Rules" ], t.RADIO([ "mathspeak-default", "Verbose" ], "Assistive-ruleset", n), t.RADIO([ "mathspeak-brief", "Brief" ], "Assistive-ruleset", n), t.RADIO([ "mathspeak-sbrief", "Superbrief" ], "Assistive-ruleset", n)), t.RADIO([ "clearspeak-default", "Clearspeak Rules" ], "Assistive-ruleset", n), t.SUBMENU([ "Chromevox", "ChromeVox Rules" ], t.RADIO([ "chromevox-default", "Verbose" ], "Assistive-ruleset", n), t.RADIO([ "chromevox-alternative", "Alternative" ], "Assistive-ruleset", n))), r = (a.FindId("Accessibility") || {}).submenu;
396 r ? null !== (e = r.IndexOfId("Explorer")) ? r.items[e] = o : (e = r.IndexOfId("CollapsibleMath"),
397 r.items.splice(e + 1, 0, o)) : (e = a.IndexOfId("CollapsibleMath"), a.items.splice(e + 1, 0, o)),
398 s.explorer || h.DisableMenus(!0);
399 }, 20);
400 }, 20);
401 }), MathJax.Hub.Register.StartupHook("SVG Jax Ready", function() {
402 MathJax.Hub.Config({
403 SVG: {
404 addMMLclasses: !0
405 }
406 });
407 var t, e = MathJax.OutputJax.SVG;
408 parseFloat(e.version) < 2.7 && (t = e.getJaxFromMath, e.Augment({
409 getJaxFromMath: function(e) {
410 return e.parentNode.className.match(/MathJax_SVG_Display/) && (e = e.parentNode),
411 t.call(this, e);
412 }
413 }));
414 }), MathJax.Ajax.config.path.a11y || (MathJax.Ajax.config.path.a11y = MathJax.Hub.config.root + "/extensions/a11y"),
415 MathJax.Ajax.Require("[a11y]/collapsible.js"), MathJax.Hub.Register.StartupHook("Collapsible Ready", function() {
416 MathJax.Extension.explorer.Explorer.Startup(), MathJax.Ajax.loadComplete("[a11y]/explorer.js");
417 });