S2OJ/web/js/mathjax3/a11y/semantic-enrich.js

1 line
7.9 KiB
JavaScript
Raw Normal View History

2022-09-20 02:24:04 +00:00
!function(){"use strict";var t={433:function(t,e,r){var n,a=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var a in e=arguments[r])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},i.apply(this,arguments)},o=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},s=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,a,i=r.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(n=i.next()).done;)o.push(n.value)}catch(t){a={error:t}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(a)throw a.error}}return o},c=this&&this.__spreadArray||function(t,e,r){if(r||2===arguments.length)for(var n,a=0,i=e.length;a<i;a++)!n&&a in e||(n||(n=Array.prototype.slice.call(e,0,a)),n[a]=e[a]);return t.concat(n||Array.prototype.slice.call(e))},l=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.EnrichHandler=e.EnrichedMathDocumentMixin=e.EnrichedMathItemMixin=void 0;var h=r(184),u=r(769),p=r(758),f=r(77),d=l(r(712)),y="none";function M(t,e,r){return function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return a(n,t),n.prototype.serializeMml=function(t){if("outerHTML"in t)return t.outerHTML;if("undefined"!=typeof Element&&"undefined"!=typeof window&&t instanceof Element){var e=window.document.createElement("div");return e.appendChild(t),e.innerHTML}return t.toString()},n.prototype.enrich=function(t,n){if(void 0===n&&(n=!1),!(this.state()>=u.STATE.ENRICHED)){if(!this.isEscaped&&(t.options.enableEnrichment||n)){t.options.sre.speech!==y&&(y=t.options.sre.speech,h.mathjax.retryAfter(d.default.setupEngine(t.options.sre).then((function(){return d.default.sreReady()}))));var a=new t.options.MathItem("",e);try{var i=this.inputData.originalMml=r(this.root);a.math=this.serializeMml(d.default.toEnriched(i)),a.display=this.display,a.compile(t),this.root=a.root,this.inputData.enrichedMml=a.math}catch(e){t.options.enrichError(t,this,e)}}this.state(u.STATE.ENRICHED)}},n.prototype.attachSpeech=function(t){var e,r;if(!(this.state()>=u.STATE.ATTACHSPEECH)){var n=this.root.attributes.get("aria-label")||this.getSpeech(this.root);if(n){var a=t.adaptor,i=this.typesetRoot;a.setAttribute(i,"aria-label",n);try{for(var s=o(a.childNodes(i)),c=s.next();!c.done;c=s.next()){var l=c.value;a.setAttribute(l,"aria-hidden","true")}}catch(t){e={error:t}}finally{try{c&&!c.done&&(r=s.return)&&r.call(s)}finally{if(e)throw e.error}}}this.state(u.STATE.ATTACHSPEECH)}},n.prototype.getSpeech=function(t){var e,r,n=t.attributes;if(!n)return"";var a=n.getExplicit("data-semantic-speech");if(!n.getExplicit("data-semantic-parent")&&a)return a;try{for(var i=o(t.childNodes),s=i.next();!s.done;s=i.next()){var c=s.value,l=this.getSpeech(c);if(null!=l)return l}}catch(t){e={error:t}}finally{try{s&&!s.done&&(r=i.return)&&r.call(i)}finally{if(e)throw e.error}}return""},n}(t)}function m(t,e){var r;return r=function(t){function r(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];var a=t.apply(this,c([],s(r),!1))||this;e.setMmlFactory(a.mmlFactory);var i=a.constructor.ProcessBits;i.has("enriched")||(i.allocate("enriched"),i.allocate("attach-speech"));var o=new p.SerializedMmlVisitor(a.mmlFactory),l=function(t){return o.visitTree(t)};return a.o