(()=>{"use strict";const e="7.31.0";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t(e)}function n(e,n){for(var r=0;r<n.length;r++){var i=n[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,(o=i.key,a=void 0,a=function(e,n){if("object"!==t(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var i=r.call(e,n||"default");if("object"!==t(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(e)}(o,"string"),"symbol"===t(a)?a:String(a)),i)}var o,a}function r(){return r="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=a(e)););return e}(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},r.apply(this,arguments)}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function o(e){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,i=a(e);if(n){var o=a(this).constructor;r=Reflect.construct(i,arguments,o)}else r=i.apply(this,arguments);return function(e,n){if(n&&("object"===t(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(this,r)}}function a(e){return a=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},a(e)}H5P.Blanks.prototype._oldResetTask=H5P.Blanks.prototype.resetTask,H5P.Blanks.prototype.resetTask=function(){this._oldResetTask(),this.trigger("reset")};var s=function(){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t)}(u,WirisPlugin.IntegrationModel);var t,s,l,c=o(u);function u(t,n,r){var i;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,u),void 0===t.serviceProviderProperties&&(t.serviceProviderProperties={},t.serviceProviderProperties.URI="https://www.wiris.net/demo/plugins/app",t.serviceProviderProperties.server="java"),t.version=e,t.scriptName="wirisplugin-generic.js",t.environment={},t.environment.editor="GenericHTML",(i=c.call(this,t)).blanks=n,i.container=r,i.restoreContainerSize=null,i.toolbar=null,i.toolbar=t.toolbar,void 0!==t.configurationService&&(i.configurationService=t.configurationService),i.overriddenModal=!1,i}return t=u,(s=[{key:"openNewFormulaEditor",value:function(){var e=this;if(r(a(u.prototype),"openNewFormulaEditor",this).call(this),!this.overriddenModal){var t=this.core.getModalDialog(),n=t.close;t.close=function(){n.call(t),setTimeout((function(){if(e.container.style.minHeight){var t="";e.restoreContainerSize&&(t=e.restoreContainerSize,e.restoreContainerSize=null),e.container.style.minHeight=t,e.blanks.trigger("resize")}}),100)},this.overriddenModal=!0}}},{key:"getLanguage",value:function(){return H5PIntegration.locale?H5PIntegration.locale:r(a(u.prototype),"getLanguage",this).call(this)}},{key:"selectRange",value:function(e){e.removeAllRanges();var t=document.createRange();return t.setStart(this.target,0),t.setEnd(this.target,0),e.addRange(t),e}},{key:"getSelection",value:function(){return this.selectRange(r(a(u.prototype),"getSelection",this).call(this))}},{key:"selectTarget",value:function(){this.selectRange(window.getSelection())}},{key:"callbackFunction",value:function(){var e=this;if(r(a(u.prototype),"callbackFunction",this).call(this),this.isIframe){var t=this.target.contentWindow.document.body.innerHTML||"";""!==t&&(this.target.contentWindow.document.body.innerHTML=WirisPlugin.Parser.initParse(t))}else{var n=this.target.innerHTML||"";""!==n&&(this.target.innerHTML=WirisPlugin.Parser.initParse(n))}var i=document.createElement("button");i.classList.add("wiris-h5p-formula-button"),i.src="/images/vendor/@wiris/mathtype-generic/icons/formula.png?6acd19101c144a4e919e2fd90123c061";var o=function(){e.blanks.isRoot()?setTimeout((function(){var t=e.container.style.minHeight;t&&(e.restoreContainerSize=t);var n=getComputedStyle(e.container);e.container.style.minHeight=parseInt(n.height)+290+"px",e.blanks.trigger("resize"),setTimeout(s.bind(e),10)}),100):s.call(e)},s=function(){var e=i.getBoundingClientRect(),t=this.core.modalDialog;t.setPosition(window.innerHeight-e.top-parseFloat(t.container.style.height)-40,window.innerWidth/2-parseFloat(t.container.style.width)/2)};i.addEventListener("click",function(){if(WirisPlugin.currentInstance.core.modalDialog&&WirisPlugin.currentInstance.core.modalDialog.close(),this.core.getCustomEditors().disable(),this.selectTarget(),this.openNewFormulaEditor(),null!==this.core.contentManager&&null===this.core.contentManager.editor?this.core.contentManager.addListener(WirisPlugin.Listeners.newListener("onLoad",(function(){o()}))):o(),WirisPlugin.currentInstance=this,this.core.modalDialog.deviceProperties.isMobile)return this.core.modalDialog.contentContainer.style.maxHeight=this.container.getBoundingClientRect().height-25+"px",void(this.core.modalDialog.deviceProperties.isIOS?this.core.modalDialog.addClass("wrs_modal_ios"):this.core.modalDialog.deviceProperties.isAndroid||this.core.modalDialog.addClass("wrs_modal_android"));this.core.modalDialog.deviceProperties.isIOS?this.core.modalDialog.contentContainer.style.maxHeight=this.container.getBoundingClientRect().height-25+"px":this.core.modalDialog.minimizeDiv.style.visibility="hidden"}.bind(this)),this.toolbar.appendChild(i)}}])&&n(t.prototype,s),l&&n(t,l),Object.defineProperty(t,"prototype",{writable:!1}),u}();function l(e,t){var n=this,r=!1;e.params.behaviour.autoCheck&&(r=!0),this.container=t,this.setContainer=function(e){n.container=e};var i=function(){l.forEach((function(e){var t=e.getCore();t.modalDialog&&t.modalDialog.properties.open&&t.modalDialog.close()}))};H5P.externalDispatcher.on("domHidden",(function(e){e.data.$dom[0].contains(n.container)&&i()}));var o=e.pause;e.pause=function(){o(),i()};for(var a=t.querySelector(".h5p-question-content"),l=[],c=a.querySelectorAll(".h5p-text-input"),u=[],d=0;d<c.length;d++)u.push({blanksInput:c[d]});return u.forEach((function(n){var i=n.blanksInput,o=document.createElement("div");n.wirisInput=o,o.contentEditable=!0,o.tabIndex=0,o.setAttribute("aria-label",i.getAttribute("aria-label")),o.classList.add("wiris-h5p-input"),i.parentNode.appendChild(o),i.style.display="none",o.innerHTML=i.value;var c=document.createElement("div");c.classList.add("wiris-h5p-toolbar"),r&&a.classList.add("blanks-autocheck"),i.parentNode.appendChild(c);var u={};u.target=o,u.toolbar=c;var d=new s(u,e,t);d.init(),d.listeners.fire("onTargetReady",{}),l.push(d),o.addEventListener("focus",(function(){r&&(i.value="",i.dispatchEvent(new Event("keyup")))})),o.addEventListener("blur",(function(){var e;i.value=(e=o.innerHTML,WirisPlugin.Parser.endParse(e).replace(/<math.*?<\/math>/g,(function(e){return"\\("+WirisPlugin.Latex.getLatexFromMathML(e)+"\\)"}))),r&&(i.dispatchEvent(new Event("blur")),i.getAttribute("disabled")&&(o.classList.add("disabled"),o.contentEditable=!1))})),o.addEventListener("keyup",(function(){r&&(i.value="",i.dispatchEvent(new Event("keyup")))})),WirisPlugin.currentInstance=d})),e.on("xAPI",(function(e){"http://adlnet.gov/expapi/verbs/answered"===e.data.statement.verb.id&&u.forEach((function(e){e.wirisInput.contentEditable=!1,e.wirisInput.classList.add("disabled")}))})),e.on("reset",(function(){u.forEach((function(e){e.wirisInput.innerHTML="",e.wirisInput.contentEditable=!0,e.wirisInput.classList.remove("disabled")}))})),e.trigger("resize"),this}var c=function(e){for(var t,n=e.indexOf("$$");-1!==n&&-1!==t;)-1!==(t=e.indexOf("$$",n+2))&&(n=(e=e.substring(0,n)+"\\("+e.substring(n+2,t)+"\\)"+e.substr(t+2)).indexOf("$$"));return e},u=H5P.newRunnable;H5P.newRunnable=function(e,t,n){var r=!1,i=!1;try{r=!(!e.library||"H5P.Blanks"!==e.library.split(" ")[0]),i=!!(H5PIntegration.isMathTypeEnabled&&e.params&&e.params.behaviour&&e.params.behaviour.formulaEditor);var o=!(!e.params||!e.params.questions||!e.params.questions.length);r&&i&&o&&(e.params.questions=e.params.questions.map(c))}catch(e){console.warning(e)}var a,s=u.apply(null,arguments);if(i&&r)if(n)a=new l(s,n[0]);else{var d=s.attach;s.attach=function(e){d.apply(s,arguments),a?a.setContainer(e[0]):a=new l(s,e[0])}}return s}})();