From 055331e6c27488af3bfb8deff8541731cfde1cff Mon Sep 17 00:00:00 2001 From: Carla Lara Date: Mon, 15 Sep 2025 12:36:00 +0200 Subject: [PATCH] fix: CK5 incompatibility with textpartlanguage --- packages/ckeditor5/dist/browser/index.css.map | 2 +- packages/ckeditor5/dist/browser/index.js | 180 +++++++++++------- packages/ckeditor5/dist/browser/index.js.map | 2 +- packages/ckeditor5/dist/browser/index.umd.js | 180 +++++++++++------- .../ckeditor5/dist/browser/index.umd.js.map | 2 +- packages/ckeditor5/dist/index.js | 2 +- packages/ckeditor5/dist/index.js.map | 2 +- packages/ckeditor5/src/integration.js | 2 +- 8 files changed, 238 insertions(+), 134 deletions(-) diff --git a/packages/ckeditor5/dist/browser/index.css.map b/packages/ckeditor5/dist/browser/index.css.map index 30b9a4e43..0057d38dd 100644 --- a/packages/ckeditor5/dist/browser/index.css.map +++ b/packages/ckeditor5/dist/browser/index.css.map @@ -1 +1 @@ -{"version":3,"sources":["../../node_modules/@wiris/mathtype-html-integration-devkit/styles/styles.css"],"names":[],"mappings":"AAAA;EACE,eAAe;EACf,8BAA8B;EAC9B,MAAM;EACN,QAAQ;EACR,OAAO;EACP,SAAS;EACT,8BAA8B;EAC9B,eAAe;EACf,aAAa;EACb,oBAAoB;AACtB;;AAEA;EACE,kBAAkB;EAClB,aAAa;AACf;;AAEA;EACE,kBAAkB;EAClB,aAAa;AACf;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,4BAA4B;EAC5B,aAAa;AACf;;AAEA;EACE,8BAA8B;AAChC;;AAEA;EACE,4BAA4B;EAC5B,aAAa;AACf;;AAEA;EACE,4BAA4B;EAC5B,aAAa;AACf;;AAEA;EACE,WAAW;EACX,uBAAuB;EACvB,sBAAsB;EACtB,yBAAyB;EACzB,qBAAqB;EACrB,iBAAiB;EACjB,gBAAgB;AAClB;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,uBAAuB;EACvB,oBAAoB;EACpB,4BAA4B;AAC9B;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,uBAAuB;EACvB,YAAY;EACZ,oBAAoB;AACtB;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,oBAAoB;EACpB,uBAAuB;EACvB,YAAY;AACd;;AAEA;EACE,kBAAkB;EAClB,SAAS;EACT,UAAU;AACZ;;AAEA;EACE,kBAAkB;EAClB,SAAS;EACT,UAAU;AACZ;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,oBAAoB;EACpB,uBAAuB;EACvB,YAAY;AACd;;AAEA;EACE,kBAAkB;EAClB,SAAS;EACT,UAAU;AACZ;;AAEA;EACE,cAAc;EACd,yBAAyB;AAC3B;;AAEA;EACE,YAAY;EACZ,mBAAmB;EACnB,eAAe;AACjB;;AAEA;EACE,eAAe;EACf,aAAa;EACb,iBAAiB;AACnB;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;EACf,YAAY;EACZ,SAAS;EACT,kBAAkB;AACpB;;AAEA;EACE,kBAAkB;EAClB,aAAa;EACb,UAAU;AACZ;;AAEA;wEACwE;;AAExE;EACE,eAAe;EACf,SAAS;EACT,QAAQ;EACR,wCAAwC;AAC1C;;AAEA;EACE,wCAAwC;AAC1C;;AAEA;EACE,wCAAwC;AAC1C;;AAEA;;EAEE,WAAW;EACX,eAAe;EACf,YAAY;EACZ,gBAAgB;EAChB,mCAAmC;EACnC,uCAAuC;EACvC,qCAAqC;EACrC,WAAW;EACX,eAAe;EACf,sBAAsB;EACtB,aAAa;EACb,sBAAsB;AACxB;;AAEA;yCACyC;;AAEzC;EACE,aAAa;AACf;;AAEA;;GAEG;;AAEH;EACE,YAAY;AACd;;AAEA;;EAEE,yBAAyB;EACzB,eAAe;EACf,aAAa;AACf;;AAEA;;EAEE,eAAe;EACf,aAAa;AACf;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,aAAa;EACb,sBAAsB;EACtB,uBAAuB;AACzB;;AAEA;EACE,WAAW;EACX,aAAa;EACb,cAAc;EACd,eAAe;AACjB;;AAEA;EACE,WAAW;EACX,aAAa;EACb,cAAc;EACd,eAAe;AACjB;;AAEA;EACE,sBAAsB;EACtB,wBAAwB;EACxB,yBAAyB;EACzB,qBAAqB;EACrB,iBAAiB;AACnB;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,cAAc;EACd,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,iBAAiB;EACjB,sBAAsB;EACtB,yBAAyB;EACzB,qBAAqB;EACrB,iBAAiB;AACnB;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,cAAc;EACd,kBAAkB;EAClB,OAAO;EACP,MAAM;EACN,iBAAiB;AACnB;;AAEA;EACE,YAAY;EACZ,mBAAmB;AACrB;;AAEA;EACE,iBAAiB;EACjB,gBAAgB;EAChB,8BAA8B;EAC9B,YAAY;EACZ,eAAe;EACf,YAAY;EACZ,iBAAiB;AACnB;;AAEA;EACE,qBAAqB;EACrB,cAAc;EACd,eAAe;AACjB;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,gBAAgB;EAChB,gBAAgB;EAChB,eAAe;EACf,8BAA8B;EAC9B,sBAAsB;EACtB,YAAY;AACd;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,iBAAiB;EACjB,gBAAgB;EAChB,WAAW;EACX,mBAAmB;EACnB,eAAe;EACf,8BAA8B;EAC9B,YAAY;AACd;;AAEA;EACE,YAAY;EACZ,YAAY;EACZ,gBAAgB;EAChB,WAAW;EACX,eAAe;AACjB;;AAEA;EACE,eAAe;EACf,WAAW;AACb;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,mBAAmB;EACnB,sBAAsB;AACxB;;AAEA;EACE,WAAW;EACX,aAAa;EACb,sBAAsB;EACtB,YAAY;AACd;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,aAAa;EACb,WAAW;AACb;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,YAAY;EACZ,MAAM;EACN,OAAO;EACP,QAAQ;EACR,SAAS;EACT,oCAAoC;EACpC,UAAU;EACV,eAAe;AACjB;;AAEA;EACE,QAAQ;EACR,SAAS;EACT,gCAAgC;EAChC,kBAAkB;EAClB,iBAAiB;EACjB,gBAAgB;EAChB,UAAU;EACV,kBAAkB;EAClB,aAAa;EACb,uBAAuB;EACvB,eAAe;EACf,gBAAgB;EAChB,cAAc;EACd,UAAU;EACV,eAAe;EACf,cAAc;AAChB;;AAEA;EACE,kBAAkB;AACpB;;AAEA;EACE,SAAS;AACX;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,gBAAgB;EAChB,gBAAgB;EAChB,eAAe;EACf,8BAA8B;EAC9B,sBAAsB;EACtB,sBAAsB;EACtB,YAAY;AACd;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,iBAAiB;EACjB,gBAAgB;EAChB,WAAW;EACX,mBAAmB;EACnB,eAAe;EACf,8BAA8B;EAC9B,YAAY;AACd;;AAEA;EACE,gBAAgB;AAClB;;AAEA;EACE,mBAAmB;EACnB,4BAA4B;EAC5B,6BAA6B;AAC/B;;AAEA;EACE,cAAc;AAChB;;AAEA,kCAAkC;AAClC;EACE,gBAAgB;AAClB;;AAEA;EACE,gBAAgB;AAClB;;AAEA,sBAAsB;AACtB;EACE,iBAAiB;EACjB,cAAc;AAChB;;AAEA;EACE,eAAe;EACf,gBAAgB;AAClB;;AAEA;EACE,iBAAiB;EACjB,cAAc;AAChB;;AAEA;EACE,eAAe;EACf,gBAAgB;AAClB;;AAEA,mCAAmC;AACnC;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;EACf,kBAAkB;EAClB,UAAU;EACV,eAAe;EACf,kBAAkB;EAClB,wBAAwB;EACxB,OAAO;EACP,MAAM;EACN,WAAW;EACX,eAAe;EACf,YAAY;EACZ,gBAAgB;EAChB,cAAc;EACd,4BAA4B;EAC5B,8BAA8B;EAC9B,mBAAmB;EACnB,oCAAoC;EACpC,qBAAqB;EACrB,YAAY;AACd;;AAEA,kBAAkB;AAClB;EACE,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,kBAAkB;EAClB,YAAY;EACZ,aAAa;EACb,kBAAkB;AACpB;;AAEA,qBAAqB;AACrB;EACE,cAAc;EACd,eAAe;EACf,iBAAiB;EACjB,WAAW;EACX,YAAY;EACZ,SAAS;EACT,WAAW;EACX,oBAAoB;EACpB,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;AACpB;;AAEA,kBAAkB;AAClB;EACE,kBAAkB;EAClB,WAAW;EACX,UAAU;EACV,UAAU;EACV,WAAW;EACX,eAAe;EACf,cAAc;EACd,4BAA4B;AAC9B;;AAEA;EACE,kBAAkB;EAClB,UAAU;EACV,YAAY;EACZ,UAAU;EACV,UAAU;AACZ;;AAEA;EACE,oBAAoB;EACpB,kBAAkB;EAClB,gBAAgB;EAChB,eAAe;EACf,iBAAiB;EACjB,cAAc;AAChB;;AAEA;EACE,YAAY;EACZ,oBAAoB;EACpB,kBAAkB;EAClB,eAAe;EACf,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;AAChB;;AAEA;;EAEE,WAAW;EACX,qBAAqB;EACrB,eAAe;AACjB","file":"index.css","sourcesContent":[".wrs_modal_overlay {\n position: fixed;\n font-family: arial, sans-serif;\n top: 0;\n right: 0;\n left: 0;\n bottom: 0;\n background: rgba(0, 0, 0, 0.8);\n z-index: 999998;\n opacity: 0.65;\n pointer-events: auto;\n}\n\n.wrs_modal_overlay.wrs_modal_ios {\n visibility: hidden;\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_android {\n visibility: hidden;\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_ios.moodle {\n position: fixed;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_stack {\n background: rgba(0, 0, 0, 0);\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_maximized {\n background: rgba(0, 0, 0, 0.8);\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_minimized {\n background: rgba(0, 0, 0, 0);\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_closed {\n background: rgba(0, 0, 0, 0);\n display: none;\n}\n\n.wrs_modal_title {\n color: #fff;\n padding: 5px 0 5px 10px;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n text-align: left;\n}\n\n.wrs_modal_close_button {\n float: right;\n cursor: pointer;\n color: #fff;\n padding: 5px 10px 5px 0;\n margin: 10px 7px 0 0;\n background-repeat: no-repeat;\n}\n\n.wrs_modal_minimize_button {\n float: right;\n cursor: pointer;\n color: #fff;\n padding: 5px 10px 5px 0;\n top: inherit;\n margin: 10px 7px 0 0;\n}\n\n.wrs_modal_stack_button {\n float: right;\n cursor: pointer;\n color: #fff;\n margin: 10px 7px 0 0;\n padding: 5px 10px 5px 0;\n top: inherit;\n}\n\n.wrs_modal_stack_button.wrs_stack {\n visibility: hidden;\n margin: 0;\n padding: 0;\n}\n\n.wrs_modal_stack_button.wrs_minimized {\n visibility: hidden;\n margin: 0;\n padding: 0;\n}\n\n.wrs_modal_maximize_button {\n float: right;\n cursor: pointer;\n color: #fff;\n margin: 10px 7px 0 0;\n padding: 5px 10px 5px 0;\n top: inherit;\n}\n\n.wrs_modal_maximize_button.wrs_maximized {\n visibility: hidden;\n margin: 0;\n padding: 0;\n}\n\n.wrs_modal_title_bar {\n display: block;\n background-color: #778e9a;\n}\n\n.wrs_modal_dialogContainer {\n border: none;\n background: #fafafa;\n z-index: 999999;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop {\n font-size: 14px;\n display: flex;\n flex-flow: column;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_maximized {\n position: fixed;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_minimized {\n position: fixed;\n top: inherit;\n margin: 0;\n margin-right: 10px;\n}\n\n.wrs_modal_dialogContainer.wrs_closed {\n visibility: hidden;\n display: none;\n opacity: 0;\n}\n\n/* Class that exists but hasn't got css properties defined\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_minimized.wrs_drag {} */\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_stack {\n position: fixed;\n bottom: 0;\n right: 0;\n box-shadow: rgba(0, 0, 0, 0.5) 0 2px 8px;\n}\n\n.wrs_modal_dialogContainer.wrs_drag {\n box-shadow: rgba(0, 0, 0, 0.5) 0 2px 8px;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_drag {\n box-shadow: rgba(0, 0, 0, 0.5) 0 2px 8px;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_ios,\n.wrs_modal_dialogContainer.wrs_modal_android {\n margin: 0px;\n position: fixed;\n height: auto;\n overflow: hidden;\n top: calc(env(safe-area-inset-top));\n right: calc(env(safe-area-inset-right));\n left: calc(env(safe-area-inset-left));\n bottom: 0px;\n transform: none;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n}\n\n/* Class that exists but hasn't got css properties defined\n.wrs_content_container.wrs_maximized {} */\n\n.wrs_content_container.wrs_minimized {\n display: none;\n}\n\n/* .wrs_editor {\n flex-grow: 1;\n} */\n\n.wrs_content_container.wrs_modal_desktop > div:first-child {\n flex-grow: 1;\n}\n\n.wrs_modal_wrapper.wrs_modal_android,\n.wrs_modal_wrapper.wrs_modal_ios {\n margin: 0.5rem !important;\n flex-grow: 0.98;\n display: flex;\n}\n\n.wrs_content_container.wrs_modal_ios,\n.wrs_content_container.wrs_modal_android {\n flex-grow: 0.98;\n display: flex;\n}\n\n.wrs_content_container.wrs_modal_desktop {\n width: 100%;\n flex-grow: 1;\n display: flex;\n flex-direction: column;\n height: auto !important;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_badStock {\n width: 100%;\n height: 280px;\n margin: 0 auto;\n border-width: 0;\n}\n\n.wrs_modal_wrapper.wrs_modal_badStock {\n width: 100%;\n height: 280px;\n margin: 0 auto;\n border-width: 0;\n}\n\n.wrs_noselect {\n -moz-user-select: none;\n -khtml-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.wrs_bottom_right_resizer {\n width: 10px;\n height: 10px;\n color: #778e9a;\n position: absolute;\n right: 4px;\n bottom: 8px;\n cursor: se-resize;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.wrs_bottom_left_resizer {\n width: 15px;\n height: 15px;\n color: #778e9a;\n position: absolute;\n left: 0;\n top: 0;\n cursor: se-resize;\n}\n\n.wrs_modal_controls {\n height: 42px;\n line-height: normal;\n}\n\n.wrs_modal_links {\n margin: 10px auto;\n margin-bottom: 0;\n font-family: arial, sans-serif;\n padding: 6px;\n display: inline;\n float: right;\n text-align: right;\n}\n\n.wrs_modal_links > a {\n text-decoration: none;\n color: #778e9a;\n font-size: 16px;\n}\n\n.wrs_modal_button_cancel,\n.wrs_modal_button_cancel:hover,\n.wrs_modal_button_cancel:visited,\n.wrs_modal_button_cancel:active,\n.wrs_modal_button_cancel:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-left: 5px;\n margin-bottom: 0;\n cursor: pointer;\n font-family: arial, sans-serif;\n background-color: #ddd;\n height: 32px;\n}\n\n.wrs_modal_button_accept,\n.wrs_modal_button_accept:hover,\n.wrs_modal_button_accept:visited,\n.wrs_modal_button_accept:active,\n.wrs_modal_button_accept:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-right: 5px;\n margin-bottom: 0;\n color: #fff;\n background: #778e9a;\n cursor: pointer;\n font-family: arial, sans-serif;\n height: 32px;\n}\n\n.wrs_editor_vertical_bar {\n height: 20px;\n float: right;\n background: none;\n width: 20px;\n cursor: pointer;\n}\n\n.wrs_modal_buttons_container {\n display: inline;\n float: left;\n}\n\n.wrs_modal_buttons_container.wrs_modalDesktop {\n padding-left: 0;\n}\n\n.wrs_modal_buttons_container > button {\n line-height: normal;\n background-image: none;\n}\n\n.wrs_modal_wrapper {\n margin: 6px;\n display: flex;\n flex-direction: column;\n flex-grow: 1;\n}\n\n.wrs_modal_wrapper.wrs_modal_desktop.wrs_minimized {\n display: none;\n}\n\n.wrs_popupmessage_overlay_envolture {\n display: none;\n width: 100%;\n}\n\n.wrs_popupmessage_overlay {\n position: absolute;\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: rgba(0, 0, 0, 0.5);\n z-index: 4;\n cursor: pointer;\n}\n\n.wrs_popupmessage_panel {\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n position: absolute;\n background: white;\n max-width: 500px;\n width: 75%;\n border-radius: 2px;\n padding: 20px;\n font-family: sans-serif;\n font-size: 15px;\n text-align: left;\n color: #2e2e2e;\n z-index: 5;\n max-height: 75%;\n overflow: auto;\n}\n\n.wrs_popupmessage_button_area {\n margin: 10px 0 0 0;\n}\n\n.wrs_panelContainer * {\n border: 0;\n}\n\n.wrs_button_cancel,\n.wrs_button_cancel:hover,\n.wrs_button_cancel:visited,\n.wrs_button_cancel:active,\n.wrs_button_cancel:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-left: 5px;\n margin-bottom: 0;\n cursor: pointer;\n font-family: arial, sans-serif;\n background-color: #ddd;\n background-image: none;\n height: 32px;\n}\n\n.wrs_button_accept,\n.wrs_button_accept:hover,\n.wrs_button_accept:visited,\n.wrs_button_accept:active,\n.wrs_button_accept:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-right: 5px;\n margin-bottom: 0;\n color: #fff;\n background: #778e9a;\n cursor: pointer;\n font-family: arial, sans-serif;\n height: 32px;\n}\n\n.wrs_editor button {\n box-shadow: none;\n}\n\n.wrs_editor .wrs_header button {\n border-bottom: none;\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_stack.wrs_overlay_active {\n display: block;\n}\n\n/* Fix selection in drupal style */\n.wrs_toolbar tr:focus {\n background: none;\n}\n\n.wrs_toolbar tr:hover {\n background: none;\n}\n\n/* End of fix drupal */\n.wrs_modal_rtl .wrs_modal_button_cancel {\n margin-right: 5px;\n margin-left: 0;\n}\n\n.wrs_modal_rtl .wrs_modal_button_accept {\n margin-right: 0;\n margin-left: 5px;\n}\n\n.wrs_modal_rtl .wrs_button_cancel {\n margin-right: 5px;\n margin-left: 0;\n}\n\n.wrs_modal_rtl .wrs_button_accept {\n margin-right: 0;\n margin-left: 5px;\n}\n\n/* The Offline Modal (background) */\n.wrs_modal_offline {\n display: none;\n /* Hidden by default */\n position: fixed;\n /* Stay in place */\n z-index: 2;\n /* Sit on top */\n padding-top: 150px;\n /* Location of the box */\n left: 0;\n top: 0;\n width: 100%;\n /* Full width */\n height: 100%;\n /* Full height */\n overflow: auto;\n /* Enable scroll if needed */\n background-color: rgb(0, 0, 0);\n /* Fallback color */\n background-color: rgba(0, 0, 0, 0.4);\n /* Black w/ opacity */\n margin: auto;\n}\n\n/* Modal Content */\n.wrs_modal_content_offline {\n margin: auto;\n padding: 16px;\n background: #fff7ed;\n border-radius: 6px;\n width: 517px;\n height: 100px;\n position: relative;\n}\n\n/* The Close Button */\n.wrs_modal_offline_close {\n color: #c2410c;\n font-size: 24px;\n font-weight: bold;\n left: 95.7%;\n right: 2.08%;\n top: 7.6%;\n bottom: 75%;\n font-family: \"Inter\";\n font-style: normal;\n font-weight: 400;\n position: absolute;\n}\n\n/* The Warn Icon */\n.wrs_modal_offline_warn {\n position: absolute;\n left: 2.08%;\n right: 94%;\n top: 11.6%;\n bottom: 75%;\n font-size: 24px;\n color: #fb923c;\n background-repeat: no-repeat;\n}\n\n.wrs_modal_offline_text_container {\n position: absolute;\n left: 6.8%;\n right: 6.08%;\n top: 10.4%;\n bottom: 2%;\n}\n\n.wrs_modal_offline_text {\n font-family: \"Inter\";\n font-style: normal;\n font-weight: 400;\n font-size: 14px;\n line-height: 20px;\n color: #c2410c;\n}\n\n.wrs_modal_offline_text_warn {\n height: 25px;\n font-family: \"Inter\";\n font-style: normal;\n font-size: 14px;\n line-height: 20px;\n font-weight: bold;\n color: #c2410c;\n}\n\n.wrs_modal_offline_close:hover,\n.wrs_modal_offline_close:focus {\n color: #000;\n text-decoration: none;\n cursor: pointer;\n}\n"]} \ No newline at end of file +{"version":3,"sources":["../../../devkit/styles/styles.css"],"names":[],"mappings":"AAAA;EACE,eAAe;EACf,8BAA8B;EAC9B,MAAM;EACN,QAAQ;EACR,OAAO;EACP,SAAS;EACT,8BAA8B;EAC9B,eAAe;EACf,aAAa;EACb,oBAAoB;AACtB;;AAEA;EACE,kBAAkB;EAClB,aAAa;AACf;;AAEA;EACE,kBAAkB;EAClB,aAAa;AACf;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,4BAA4B;EAC5B,aAAa;AACf;;AAEA;EACE,8BAA8B;AAChC;;AAEA;EACE,4BAA4B;EAC5B,aAAa;AACf;;AAEA;EACE,4BAA4B;EAC5B,aAAa;AACf;;AAEA;EACE,WAAW;EACX,uBAAuB;EACvB,sBAAsB;EACtB,yBAAyB;EACzB,qBAAqB;EACrB,iBAAiB;EACjB,gBAAgB;AAClB;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,uBAAuB;EACvB,oBAAoB;EACpB,4BAA4B;AAC9B;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,uBAAuB;EACvB,YAAY;EACZ,oBAAoB;AACtB;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,oBAAoB;EACpB,uBAAuB;EACvB,YAAY;AACd;;AAEA;EACE,kBAAkB;EAClB,SAAS;EACT,UAAU;AACZ;;AAEA;EACE,kBAAkB;EAClB,SAAS;EACT,UAAU;AACZ;;AAEA;EACE,YAAY;EACZ,eAAe;EACf,WAAW;EACX,oBAAoB;EACpB,uBAAuB;EACvB,YAAY;AACd;;AAEA;EACE,kBAAkB;EAClB,SAAS;EACT,UAAU;AACZ;;AAEA;EACE,cAAc;EACd,yBAAyB;AAC3B;;AAEA;EACE,YAAY;EACZ,mBAAmB;EACnB,eAAe;AACjB;;AAEA;EACE,eAAe;EACf,aAAa;EACb,iBAAiB;AACnB;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;EACf,YAAY;EACZ,SAAS;EACT,kBAAkB;AACpB;;AAEA;EACE,kBAAkB;EAClB,aAAa;EACb,UAAU;AACZ;;AAEA;wEACwE;;AAExE;EACE,eAAe;EACf,SAAS;EACT,QAAQ;EACR,wCAAwC;AAC1C;;AAEA;EACE,wCAAwC;AAC1C;;AAEA;EACE,wCAAwC;AAC1C;;AAEA;;EAEE,WAAW;EACX,eAAe;EACf,YAAY;EACZ,gBAAgB;EAChB,mCAAmC;EACnC,uCAAuC;EACvC,qCAAqC;EACrC,WAAW;EACX,eAAe;EACf,sBAAsB;EACtB,aAAa;EACb,sBAAsB;AACxB;;AAEA;yCACyC;;AAEzC;EACE,aAAa;AACf;;AAEA;;GAEG;;AAEH;EACE,YAAY;AACd;;AAEA;;EAEE,yBAAyB;EACzB,eAAe;EACf,aAAa;AACf;;AAEA;;EAEE,eAAe;EACf,aAAa;AACf;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,aAAa;EACb,sBAAsB;EACtB,uBAAuB;AACzB;;AAEA;EACE,WAAW;EACX,aAAa;EACb,cAAc;EACd,eAAe;AACjB;;AAEA;EACE,WAAW;EACX,aAAa;EACb,cAAc;EACd,eAAe;AACjB;;AAEA;EACE,sBAAsB;EACtB,wBAAwB;EACxB,yBAAyB;EACzB,qBAAqB;EACrB,iBAAiB;AACnB;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,cAAc;EACd,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,iBAAiB;EACjB,sBAAsB;EACtB,yBAAyB;EACzB,qBAAqB;EACrB,iBAAiB;AACnB;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,cAAc;EACd,kBAAkB;EAClB,OAAO;EACP,MAAM;EACN,iBAAiB;AACnB;;AAEA;EACE,YAAY;EACZ,mBAAmB;AACrB;;AAEA;EACE,iBAAiB;EACjB,gBAAgB;EAChB,8BAA8B;EAC9B,YAAY;EACZ,eAAe;EACf,YAAY;EACZ,iBAAiB;AACnB;;AAEA;EACE,qBAAqB;EACrB,cAAc;EACd,eAAe;AACjB;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,gBAAgB;EAChB,gBAAgB;EAChB,eAAe;EACf,8BAA8B;EAC9B,sBAAsB;EACtB,YAAY;AACd;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,iBAAiB;EACjB,gBAAgB;EAChB,WAAW;EACX,mBAAmB;EACnB,eAAe;EACf,8BAA8B;EAC9B,YAAY;AACd;;AAEA;EACE,YAAY;EACZ,YAAY;EACZ,gBAAgB;EAChB,WAAW;EACX,eAAe;AACjB;;AAEA;EACE,eAAe;EACf,WAAW;AACb;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,mBAAmB;EACnB,sBAAsB;AACxB;;AAEA;EACE,WAAW;EACX,aAAa;EACb,sBAAsB;EACtB,YAAY;AACd;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,aAAa;EACb,WAAW;AACb;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,YAAY;EACZ,MAAM;EACN,OAAO;EACP,QAAQ;EACR,SAAS;EACT,oCAAoC;EACpC,UAAU;EACV,eAAe;AACjB;;AAEA;EACE,QAAQ;EACR,SAAS;EACT,gCAAgC;EAChC,kBAAkB;EAClB,iBAAiB;EACjB,gBAAgB;EAChB,UAAU;EACV,kBAAkB;EAClB,aAAa;EACb,uBAAuB;EACvB,eAAe;EACf,gBAAgB;EAChB,cAAc;EACd,UAAU;EACV,eAAe;EACf,cAAc;AAChB;;AAEA;EACE,kBAAkB;AACpB;;AAEA;EACE,SAAS;AACX;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,gBAAgB;EAChB,gBAAgB;EAChB,eAAe;EACf,8BAA8B;EAC9B,sBAAsB;EACtB,sBAAsB;EACtB,YAAY;AACd;;AAEA;;;;;EAKE,eAAe;EACf,eAAe;EACf,kBAAkB;EAClB,yBAAyB;EACzB,gBAAgB;EAChB,iBAAiB;EACjB,iBAAiB;EACjB,gBAAgB;EAChB,WAAW;EACX,mBAAmB;EACnB,eAAe;EACf,8BAA8B;EAC9B,YAAY;AACd;;AAEA;EACE,gBAAgB;AAClB;;AAEA;EACE,mBAAmB;EACnB,4BAA4B;EAC5B,6BAA6B;AAC/B;;AAEA;EACE,cAAc;AAChB;;AAEA,kCAAkC;AAClC;EACE,gBAAgB;AAClB;;AAEA;EACE,gBAAgB;AAClB;;AAEA,sBAAsB;AACtB;EACE,iBAAiB;EACjB,cAAc;AAChB;;AAEA;EACE,eAAe;EACf,gBAAgB;AAClB;;AAEA;EACE,iBAAiB;EACjB,cAAc;AAChB;;AAEA;EACE,eAAe;EACf,gBAAgB;AAClB;;AAEA,mCAAmC;AACnC;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;EACf,kBAAkB;EAClB,UAAU;EACV,eAAe;EACf,kBAAkB;EAClB,wBAAwB;EACxB,OAAO;EACP,MAAM;EACN,WAAW;EACX,eAAe;EACf,YAAY;EACZ,gBAAgB;EAChB,cAAc;EACd,4BAA4B;EAC5B,8BAA8B;EAC9B,mBAAmB;EACnB,oCAAoC;EACpC,qBAAqB;EACrB,YAAY;AACd;;AAEA,kBAAkB;AAClB;EACE,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,kBAAkB;EAClB,YAAY;EACZ,aAAa;EACb,kBAAkB;AACpB;;AAEA,qBAAqB;AACrB;EACE,cAAc;EACd,eAAe;EACf,iBAAiB;EACjB,WAAW;EACX,YAAY;EACZ,SAAS;EACT,WAAW;EACX,oBAAoB;EACpB,kBAAkB;EAClB,gBAAgB;EAChB,kBAAkB;AACpB;;AAEA,kBAAkB;AAClB;EACE,kBAAkB;EAClB,WAAW;EACX,UAAU;EACV,UAAU;EACV,WAAW;EACX,eAAe;EACf,cAAc;EACd,4BAA4B;AAC9B;;AAEA;EACE,kBAAkB;EAClB,UAAU;EACV,YAAY;EACZ,UAAU;EACV,UAAU;AACZ;;AAEA;EACE,oBAAoB;EACpB,kBAAkB;EAClB,gBAAgB;EAChB,eAAe;EACf,iBAAiB;EACjB,cAAc;AAChB;;AAEA;EACE,YAAY;EACZ,oBAAoB;EACpB,kBAAkB;EAClB,eAAe;EACf,iBAAiB;EACjB,iBAAiB;EACjB,cAAc;AAChB;;AAEA;;EAEE,WAAW;EACX,qBAAqB;EACrB,eAAe;AACjB","file":"index.css","sourcesContent":[".wrs_modal_overlay {\n position: fixed;\n font-family: arial, sans-serif;\n top: 0;\n right: 0;\n left: 0;\n bottom: 0;\n background: rgba(0, 0, 0, 0.8);\n z-index: 999998;\n opacity: 0.65;\n pointer-events: auto;\n}\n\n.wrs_modal_overlay.wrs_modal_ios {\n visibility: hidden;\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_android {\n visibility: hidden;\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_ios.moodle {\n position: fixed;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_stack {\n background: rgba(0, 0, 0, 0);\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_maximized {\n background: rgba(0, 0, 0, 0.8);\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_minimized {\n background: rgba(0, 0, 0, 0);\n display: none;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_closed {\n background: rgba(0, 0, 0, 0);\n display: none;\n}\n\n.wrs_modal_title {\n color: #fff;\n padding: 5px 0 5px 10px;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n text-align: left;\n}\n\n.wrs_modal_close_button {\n float: right;\n cursor: pointer;\n color: #fff;\n padding: 5px 10px 5px 0;\n margin: 10px 7px 0 0;\n background-repeat: no-repeat;\n}\n\n.wrs_modal_minimize_button {\n float: right;\n cursor: pointer;\n color: #fff;\n padding: 5px 10px 5px 0;\n top: inherit;\n margin: 10px 7px 0 0;\n}\n\n.wrs_modal_stack_button {\n float: right;\n cursor: pointer;\n color: #fff;\n margin: 10px 7px 0 0;\n padding: 5px 10px 5px 0;\n top: inherit;\n}\n\n.wrs_modal_stack_button.wrs_stack {\n visibility: hidden;\n margin: 0;\n padding: 0;\n}\n\n.wrs_modal_stack_button.wrs_minimized {\n visibility: hidden;\n margin: 0;\n padding: 0;\n}\n\n.wrs_modal_maximize_button {\n float: right;\n cursor: pointer;\n color: #fff;\n margin: 10px 7px 0 0;\n padding: 5px 10px 5px 0;\n top: inherit;\n}\n\n.wrs_modal_maximize_button.wrs_maximized {\n visibility: hidden;\n margin: 0;\n padding: 0;\n}\n\n.wrs_modal_title_bar {\n display: block;\n background-color: #778e9a;\n}\n\n.wrs_modal_dialogContainer {\n border: none;\n background: #fafafa;\n z-index: 999999;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop {\n font-size: 14px;\n display: flex;\n flex-flow: column;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_maximized {\n position: fixed;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_minimized {\n position: fixed;\n top: inherit;\n margin: 0;\n margin-right: 10px;\n}\n\n.wrs_modal_dialogContainer.wrs_closed {\n visibility: hidden;\n display: none;\n opacity: 0;\n}\n\n/* Class that exists but hasn't got css properties defined\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_minimized.wrs_drag {} */\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_stack {\n position: fixed;\n bottom: 0;\n right: 0;\n box-shadow: rgba(0, 0, 0, 0.5) 0 2px 8px;\n}\n\n.wrs_modal_dialogContainer.wrs_drag {\n box-shadow: rgba(0, 0, 0, 0.5) 0 2px 8px;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_desktop.wrs_drag {\n box-shadow: rgba(0, 0, 0, 0.5) 0 2px 8px;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_ios,\n.wrs_modal_dialogContainer.wrs_modal_android {\n margin: 0px;\n position: fixed;\n height: auto;\n overflow: hidden;\n top: calc(env(safe-area-inset-top));\n right: calc(env(safe-area-inset-right));\n left: calc(env(safe-area-inset-left));\n bottom: 0px;\n transform: none;\n box-sizing: border-box;\n display: flex;\n flex-direction: column;\n}\n\n/* Class that exists but hasn't got css properties defined\n.wrs_content_container.wrs_maximized {} */\n\n.wrs_content_container.wrs_minimized {\n display: none;\n}\n\n/* .wrs_editor {\n flex-grow: 1;\n} */\n\n.wrs_content_container.wrs_modal_desktop > div:first-child {\n flex-grow: 1;\n}\n\n.wrs_modal_wrapper.wrs_modal_android,\n.wrs_modal_wrapper.wrs_modal_ios {\n margin: 0.5rem !important;\n flex-grow: 0.98;\n display: flex;\n}\n\n.wrs_content_container.wrs_modal_ios,\n.wrs_content_container.wrs_modal_android {\n flex-grow: 0.98;\n display: flex;\n}\n\n.wrs_content_container.wrs_modal_desktop {\n width: 100%;\n flex-grow: 1;\n display: flex;\n flex-direction: column;\n height: auto !important;\n}\n\n.wrs_modal_dialogContainer.wrs_modal_badStock {\n width: 100%;\n height: 280px;\n margin: 0 auto;\n border-width: 0;\n}\n\n.wrs_modal_wrapper.wrs_modal_badStock {\n width: 100%;\n height: 280px;\n margin: 0 auto;\n border-width: 0;\n}\n\n.wrs_noselect {\n -moz-user-select: none;\n -khtml-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.wrs_bottom_right_resizer {\n width: 10px;\n height: 10px;\n color: #778e9a;\n position: absolute;\n right: 4px;\n bottom: 8px;\n cursor: se-resize;\n -moz-user-select: none;\n -webkit-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.wrs_bottom_left_resizer {\n width: 15px;\n height: 15px;\n color: #778e9a;\n position: absolute;\n left: 0;\n top: 0;\n cursor: se-resize;\n}\n\n.wrs_modal_controls {\n height: 42px;\n line-height: normal;\n}\n\n.wrs_modal_links {\n margin: 10px auto;\n margin-bottom: 0;\n font-family: arial, sans-serif;\n padding: 6px;\n display: inline;\n float: right;\n text-align: right;\n}\n\n.wrs_modal_links > a {\n text-decoration: none;\n color: #778e9a;\n font-size: 16px;\n}\n\n.wrs_modal_button_cancel,\n.wrs_modal_button_cancel:hover,\n.wrs_modal_button_cancel:visited,\n.wrs_modal_button_cancel:active,\n.wrs_modal_button_cancel:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-left: 5px;\n margin-bottom: 0;\n cursor: pointer;\n font-family: arial, sans-serif;\n background-color: #ddd;\n height: 32px;\n}\n\n.wrs_modal_button_accept,\n.wrs_modal_button_accept:hover,\n.wrs_modal_button_accept:visited,\n.wrs_modal_button_accept:active,\n.wrs_modal_button_accept:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-right: 5px;\n margin-bottom: 0;\n color: #fff;\n background: #778e9a;\n cursor: pointer;\n font-family: arial, sans-serif;\n height: 32px;\n}\n\n.wrs_editor_vertical_bar {\n height: 20px;\n float: right;\n background: none;\n width: 20px;\n cursor: pointer;\n}\n\n.wrs_modal_buttons_container {\n display: inline;\n float: left;\n}\n\n.wrs_modal_buttons_container.wrs_modalDesktop {\n padding-left: 0;\n}\n\n.wrs_modal_buttons_container > button {\n line-height: normal;\n background-image: none;\n}\n\n.wrs_modal_wrapper {\n margin: 6px;\n display: flex;\n flex-direction: column;\n flex-grow: 1;\n}\n\n.wrs_modal_wrapper.wrs_modal_desktop.wrs_minimized {\n display: none;\n}\n\n.wrs_popupmessage_overlay_envolture {\n display: none;\n width: 100%;\n}\n\n.wrs_popupmessage_overlay {\n position: absolute;\n width: 100%;\n height: 100%;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: rgba(0, 0, 0, 0.5);\n z-index: 4;\n cursor: pointer;\n}\n\n.wrs_popupmessage_panel {\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n position: absolute;\n background: white;\n max-width: 500px;\n width: 75%;\n border-radius: 2px;\n padding: 20px;\n font-family: sans-serif;\n font-size: 15px;\n text-align: left;\n color: #2e2e2e;\n z-index: 5;\n max-height: 75%;\n overflow: auto;\n}\n\n.wrs_popupmessage_button_area {\n margin: 10px 0 0 0;\n}\n\n.wrs_panelContainer * {\n border: 0;\n}\n\n.wrs_button_cancel,\n.wrs_button_cancel:hover,\n.wrs_button_cancel:visited,\n.wrs_button_cancel:active,\n.wrs_button_cancel:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-left: 5px;\n margin-bottom: 0;\n cursor: pointer;\n font-family: arial, sans-serif;\n background-color: #ddd;\n background-image: none;\n height: 32px;\n}\n\n.wrs_button_accept,\n.wrs_button_accept:hover,\n.wrs_button_accept:visited,\n.wrs_button_accept:active,\n.wrs_button_accept:focus {\n min-width: 80px;\n font-size: 14px;\n border-radius: 3px;\n border: 1px solid #778e9a;\n padding: 6px 8px;\n margin: 10px auto;\n margin-right: 5px;\n margin-bottom: 0;\n color: #fff;\n background: #778e9a;\n cursor: pointer;\n font-family: arial, sans-serif;\n height: 32px;\n}\n\n.wrs_editor button {\n box-shadow: none;\n}\n\n.wrs_editor .wrs_header button {\n border-bottom: none;\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n}\n\n.wrs_modal_overlay.wrs_modal_desktop.wrs_stack.wrs_overlay_active {\n display: block;\n}\n\n/* Fix selection in drupal style */\n.wrs_toolbar tr:focus {\n background: none;\n}\n\n.wrs_toolbar tr:hover {\n background: none;\n}\n\n/* End of fix drupal */\n.wrs_modal_rtl .wrs_modal_button_cancel {\n margin-right: 5px;\n margin-left: 0;\n}\n\n.wrs_modal_rtl .wrs_modal_button_accept {\n margin-right: 0;\n margin-left: 5px;\n}\n\n.wrs_modal_rtl .wrs_button_cancel {\n margin-right: 5px;\n margin-left: 0;\n}\n\n.wrs_modal_rtl .wrs_button_accept {\n margin-right: 0;\n margin-left: 5px;\n}\n\n/* The Offline Modal (background) */\n.wrs_modal_offline {\n display: none;\n /* Hidden by default */\n position: fixed;\n /* Stay in place */\n z-index: 2;\n /* Sit on top */\n padding-top: 150px;\n /* Location of the box */\n left: 0;\n top: 0;\n width: 100%;\n /* Full width */\n height: 100%;\n /* Full height */\n overflow: auto;\n /* Enable scroll if needed */\n background-color: rgb(0, 0, 0);\n /* Fallback color */\n background-color: rgba(0, 0, 0, 0.4);\n /* Black w/ opacity */\n margin: auto;\n}\n\n/* Modal Content */\n.wrs_modal_content_offline {\n margin: auto;\n padding: 16px;\n background: #fff7ed;\n border-radius: 6px;\n width: 517px;\n height: 100px;\n position: relative;\n}\n\n/* The Close Button */\n.wrs_modal_offline_close {\n color: #c2410c;\n font-size: 24px;\n font-weight: bold;\n left: 95.7%;\n right: 2.08%;\n top: 7.6%;\n bottom: 75%;\n font-family: \"Inter\";\n font-style: normal;\n font-weight: 400;\n position: absolute;\n}\n\n/* The Warn Icon */\n.wrs_modal_offline_warn {\n position: absolute;\n left: 2.08%;\n right: 94%;\n top: 11.6%;\n bottom: 75%;\n font-size: 24px;\n color: #fb923c;\n background-repeat: no-repeat;\n}\n\n.wrs_modal_offline_text_container {\n position: absolute;\n left: 6.8%;\n right: 6.08%;\n top: 10.4%;\n bottom: 2%;\n}\n\n.wrs_modal_offline_text {\n font-family: \"Inter\";\n font-style: normal;\n font-weight: 400;\n font-size: 14px;\n line-height: 20px;\n color: #c2410c;\n}\n\n.wrs_modal_offline_text_warn {\n height: 25px;\n font-family: \"Inter\";\n font-style: normal;\n font-size: 14px;\n line-height: 20px;\n font-weight: bold;\n color: #c2410c;\n}\n\n.wrs_modal_offline_close:hover,\n.wrs_modal_offline_close:focus {\n color: #000;\n text-decoration: none;\n cursor: pointer;\n}\n"]} \ No newline at end of file diff --git a/packages/ckeditor5/dist/browser/index.js b/packages/ckeditor5/dist/browser/index.js index 22fb726b8..942be4b8e 100644 --- a/packages/ckeditor5/dist/browser/index.js +++ b/packages/ckeditor5/dist/browser/index.js @@ -3,7 +3,7 @@ import { ButtonView } from 'ckeditor5'; import { ClickObserver, XmlDataProcessor, ViewUpcastWriter, HtmlDataProcessor } from 'ckeditor5'; import { Widget, viewToModelPositionOutsideModelElement, toWidget } from 'ckeditor5'; -/*! @license DOMPurify 3.2.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.6/LICENSE */ +/*! @license DOMPurify 3.3.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.0/LICENSE */ const { entries, @@ -32,12 +32,18 @@ if (!seal) { }; } if (!apply) { - apply = function apply(fun, thisValue, args) { - return fun.apply(thisValue, args); + apply = function apply(func, thisArg) { + for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + args[_key - 2] = arguments[_key]; + } + return func.apply(thisArg, args); }; } if (!construct) { - construct = function construct(Func, args) { + construct = function construct(Func) { + for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { + args[_key2 - 1] = arguments[_key2]; + } return new Func(...args); }; } @@ -66,8 +72,8 @@ function unapply(func) { if (thisArg instanceof RegExp) { thisArg.lastIndex = 0; } - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; + for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + args[_key3 - 1] = arguments[_key3]; } return apply(func, thisArg, args); }; @@ -78,12 +84,12 @@ function unapply(func) { * @param func - The constructor function to be wrapped and called. * @returns A new function that constructs an instance of the given constructor function with the provided arguments. */ -function unconstruct(func) { +function unconstruct(Func) { return function () { - for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; + for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { + args[_key4] = arguments[_key4]; } - return construct(func, args); + return construct(Func, args); }; } /** @@ -182,8 +188,8 @@ function lookupGetter(object, prop) { return fallbackValue; } -const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); -const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']); +const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); +const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']); const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']); // List of SVG elements that are disallowed by default. // We still need to know them so that we can do namespace @@ -196,8 +202,8 @@ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mgly const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']); const text = freeze(['#text']); -const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']); -const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']); +const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']); +const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']); const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']); const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']); @@ -295,7 +301,7 @@ const _createHooksMap = function _createHooksMap() { function createDOMPurify() { let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal(); const DOMPurify = root => createDOMPurify(root); - DOMPurify.version = '3.2.6'; + DOMPurify.version = '3.3.0'; DOMPurify.removed = []; if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) { // Not running in a browser, provide a factory function @@ -406,6 +412,21 @@ function createDOMPurify() { let FORBID_TAGS = null; /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */ let FORBID_ATTR = null; + /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */ + const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, { + tagCheck: { + writable: true, + configurable: false, + enumerable: true, + value: null + }, + attributeCheck: { + writable: true, + configurable: false, + enumerable: true, + value: null + } + })); /* Decide if ARIA attributes are okay */ let ALLOW_ARIA_ATTR = true; /* Decide if custom data attributes are okay */ @@ -598,16 +619,24 @@ function createDOMPurify() { } /* Merge configuration parameters */ if (cfg.ADD_TAGS) { - if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) { - ALLOWED_TAGS = clone(ALLOWED_TAGS); + if (typeof cfg.ADD_TAGS === 'function') { + EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS; + } else { + if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) { + ALLOWED_TAGS = clone(ALLOWED_TAGS); + } + addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc); } - addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc); } if (cfg.ADD_ATTR) { - if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) { - ALLOWED_ATTR = clone(ALLOWED_ATTR); + if (typeof cfg.ADD_ATTR === 'function') { + EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR; + } else { + if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) { + ALLOWED_ATTR = clone(ALLOWED_ATTR); + } + addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc); } - addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc); } if (cfg.ADD_URI_SAFE_ATTR) { addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc); @@ -915,7 +944,7 @@ function createDOMPurify() { return true; } /* Remove element if anything forbids its presence */ - if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) { + if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) { /* Check if we have a custom element to handle */ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) { if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) { @@ -987,12 +1016,12 @@ function createDOMPurify() { (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes) XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804) We don't need to check the value; it's always URI safe. */ - if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) { + if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) { if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck - _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || + _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) || // Alternative, second condition checks if it's an `is`-attribute, AND // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else { @@ -1071,7 +1100,12 @@ function createDOMPurify() { value = SANITIZE_NAMED_PROPS_PREFIX + value; } /* Work around a security issue with comments inside attributes */ - if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) { + if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) { + _removeAttribute(name, currentNode); + continue; + } + /* Make sure we cannot easily use animated hrefs, even if animations are allowed */ + if (lcName === 'attributename' && stringMatch(value, 'href')) { _removeAttribute(name, currentNode); continue; } @@ -3455,6 +3489,13 @@ var translations = { } } /** + * A map from event target to event handlers so we can remove the event + * listeners in removeElementEvents + * + * @type {Map} + * @static + */ static elementEventsMap = new Map(); + /** * Adds the a callback function, for a certain event target, to the following event types: * - dblclick * - mousedown @@ -3465,24 +3506,29 @@ var translations = { * @param {Function} mouseupHandler - function to run when on mouseup event. * @static */ static addElementEvents(eventTarget, doubleClickHandler, mousedownHandler, mouseupHandler) { + // Make sure not to leak event listeners if we've already added events to + // this element + Util.removeElementEvents(eventTarget); + let entry = {}; + Util.elementEventsMap.set(eventTarget, entry); if (doubleClickHandler) { - this.callbackDblclick = (event)=>{ + entry.callbackDblclick = (event)=>{ const realEvent = event || window.event; const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target; doubleClickHandler(element, realEvent); }; - Util.addEvent(eventTarget, "dblclick", this.callbackDblclick); + Util.addEvent(eventTarget, "dblclick", entry.callbackDblclick); } if (mousedownHandler) { - this.callbackMousedown = (event)=>{ + entry.callbackMousedown = (event)=>{ const realEvent = event || window.event; const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target; mousedownHandler(element, realEvent); }; - Util.addEvent(eventTarget, "mousedown", this.callbackMousedown); + Util.addEvent(eventTarget, "mousedown", entry.callbackMousedown); } if (mouseupHandler) { - this.callbackMouseup = (event)=>{ + entry.callbackMouseup = (event)=>{ const realEvent = event || window.event; const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target; mouseupHandler(element, realEvent); @@ -3491,8 +3537,8 @@ var translations = { // while the mouse is outside the editor text field. // This is a workaround: we trigger the event independently of where the mouse // is when we release its button. - Util.addEvent(document, "mouseup", this.callbackMouseup); - Util.addEvent(eventTarget, "mouseup", this.callbackMouseup); + Util.addEvent(document, "mouseup", entry.callbackMouseup); + Util.addEvent(eventTarget, "mouseup", entry.callbackMouseup); } } /** @@ -3503,10 +3549,15 @@ var translations = { * @param {EventTarget} eventTarget - event target. * @static */ static removeElementEvents(eventTarget) { - Util.removeEvent(eventTarget, "dblclick", this.callbackDblclick); - Util.removeEvent(eventTarget, "mousedown", this.callbackMousedown); - Util.removeEvent(document, "mouseup", this.callbackMouseup); - Util.removeEvent(eventTarget, "mouseup", this.callbackMouseup); + let entry = Util.elementEventsMap.get(eventTarget); + if (!entry) { + return; + } + Util.elementEventsMap.delete(eventTarget); + Util.removeEvent(eventTarget, "dblclick", entry.callbackDblclick); + Util.removeEvent(eventTarget, "mousedown", entry.callbackMousedown); + Util.removeEvent(document, "mouseup", entry.callbackMouseup); + Util.removeEvent(eventTarget, "mouseup", entry.callbackMouseup); } /** * Adds a class name to a HTMLElement. @@ -7230,11 +7281,11 @@ const { unprotect, protect } = focusProtection(); this.closeDiv.setAttribute("role", "button"); this.closeDiv.setAttribute("tabindex", 3); // Apply styles and events after the creation as createElement doesn't process them correctly - let generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`; - let hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`; - this.closeDiv.setAttribute("style", generalStyle); - this.closeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.closeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`; + const hoverStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`; + this.closeDiv.setAttribute("style", generalStyleClose); + this.closeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleClose); + this.closeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleClose); // To identifiy the element in automated testing this.closeDiv.setAttribute("data-testid", "mtcteditor-close-button"); attributes = {}; @@ -7244,11 +7295,11 @@ const { unprotect, protect } = focusProtection(); this.stackDiv = Util.createElement("a", attributes); this.stackDiv.setAttribute("role", "button"); this.stackDiv.setAttribute("tabindex", 2); - generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`; - hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`; - this.stackDiv.setAttribute("style", generalStyle); - this.stackDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.stackDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`; + const hoverStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`; + this.stackDiv.setAttribute("style", generalStyleStack); + this.stackDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleStack); + this.stackDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleStack); // To identifiy the element in automated testing this.stackDiv.setAttribute("data-testid", "mtcteditor-fullscreen-disable-button"); attributes = {}; @@ -7258,11 +7309,11 @@ const { unprotect, protect } = focusProtection(); this.maximizeDiv = Util.createElement("a", attributes); this.maximizeDiv.setAttribute("role", "button"); this.maximizeDiv.setAttribute("tabindex", 2); - generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`; - hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`; - this.maximizeDiv.setAttribute("style", generalStyle); - this.maximizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.maximizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`; + const hoverStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`; + this.maximizeDiv.setAttribute("style", generalStyleMaximize); + this.maximizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleMaximize); + this.maximizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleMaximize); // To identifiy the element in automated testing this.maximizeDiv.setAttribute("data-testid", "mtcteditor-fullscreen-enable-button"); attributes = {}; @@ -7272,11 +7323,11 @@ const { unprotect, protect } = focusProtection(); this.minimizeDiv = Util.createElement("a", attributes); this.minimizeDiv.setAttribute("role", "button"); this.minimizeDiv.setAttribute("tabindex", 1); - generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; - hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; - this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; + const hoverStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; + this.minimizeDiv.setAttribute("style", generalStyleMinimize); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleMinimize); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleMinimize); // To identify the element in automated testing this.minimizeDiv.setAttribute("data-testid", "mtcteditor-minimize-button"); attributes = {}; @@ -7828,8 +7879,8 @@ const { unprotect, protect } = focusProtection(); const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyle); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyle); this.restoreModalProperties(); if (typeof this.resizerBR !== "undefined" && typeof this.resizerTL !== "undefined") { this.setResizeButtonsVisibility(); @@ -7871,8 +7922,8 @@ const { unprotect, protect } = focusProtection(); const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxIcon)})`; const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxHoverIcon)})`; this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyle); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyle); } } /** @@ -7899,8 +7950,8 @@ const { unprotect, protect } = focusProtection(); const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyle); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyle); // Set size to 80% screen with a max size. this.setSize(parseInt(window.innerHeight * 0.8, 10), parseInt(window.innerWidth * 0.8, 10)); if (this.container.clientHeight > 700) { @@ -9765,7 +9816,8 @@ var warnIcon = "{ this.doubleClickHandler(element, event); // Avoid creating the double click listener more than once for each element. - event.stopImmediatePropagation(); + // This also allows CKEditor4 to add their own double click listener. + event.preventDefault(); }, (element, event)=>{ this.mousedownHandler(element, event); }, (element, event)=>{ @@ -11108,7 +11160,7 @@ delete Array.prototype.__class__; // @codingStandardsIgnoreEnd if (Object.prototype.hasOwnProperty.call(languageObject, "ui")) { return languageObject.ui; } - return languageObject; + return this.editorObject.locale.uiLanguage; } return languageObject; } diff --git a/packages/ckeditor5/dist/browser/index.js.map b/packages/ckeditor5/dist/browser/index.js.map index 396746eef..36c36b0d2 100644 --- a/packages/ckeditor5/dist/browser/index.js.map +++ b/packages/ckeditor5/dist/browser/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../../../../node_modules/dompurify/dist/purify.es.mjs","../../node_modules/@wiris/mathtype-html-integration-devkit/src/constants.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/mathml.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/configuration.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/textcache.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/listeners.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/serviceprovider.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/latex.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/stringmanager.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/util.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/image.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/accessibility.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/parser.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/editorlistener.js","../../node_modules/@wiris/mathtype-html-integration-devkit/telemeter-wasm/telemeter_wasm.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/telemeter.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/contentmanager.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/customeditors.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/jsvariables.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/event.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/popupmessage.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/focusprotection.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/modal.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/polyfills.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/core.src.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/integrationmodel.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/md5.js","../../src/integration.js","../../src/commands.js","../../src/plugin.js"],"sourcesContent":["/*! @license DOMPurify 3.2.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.6/LICENSE */\n\nconst {\n entries,\n setPrototypeOf,\n isFrozen,\n getPrototypeOf,\n getOwnPropertyDescriptor\n} = Object;\nlet {\n freeze,\n seal,\n create\n} = Object; // eslint-disable-line import/no-mutable-exports\nlet {\n apply,\n construct\n} = typeof Reflect !== 'undefined' && Reflect;\nif (!freeze) {\n freeze = function freeze(x) {\n return x;\n };\n}\nif (!seal) {\n seal = function seal(x) {\n return x;\n };\n}\nif (!apply) {\n apply = function apply(fun, thisValue, args) {\n return fun.apply(thisValue, args);\n };\n}\nif (!construct) {\n construct = function construct(Func, args) {\n return new Func(...args);\n };\n}\nconst arrayForEach = unapply(Array.prototype.forEach);\nconst arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);\nconst arrayPop = unapply(Array.prototype.pop);\nconst arrayPush = unapply(Array.prototype.push);\nconst arraySplice = unapply(Array.prototype.splice);\nconst stringToLowerCase = unapply(String.prototype.toLowerCase);\nconst stringToString = unapply(String.prototype.toString);\nconst stringMatch = unapply(String.prototype.match);\nconst stringReplace = unapply(String.prototype.replace);\nconst stringIndexOf = unapply(String.prototype.indexOf);\nconst stringTrim = unapply(String.prototype.trim);\nconst objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);\nconst regExpTest = unapply(RegExp.prototype.test);\nconst typeErrorCreate = unconstruct(TypeError);\n/**\n * Creates a new function that calls the given function with a specified thisArg and arguments.\n *\n * @param func - The function to be wrapped and called.\n * @returns A new function that calls the given function with a specified thisArg and arguments.\n */\nfunction unapply(func) {\n return function (thisArg) {\n if (thisArg instanceof RegExp) {\n thisArg.lastIndex = 0;\n }\n for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n args[_key - 1] = arguments[_key];\n }\n return apply(func, thisArg, args);\n };\n}\n/**\n * Creates a new function that constructs an instance of the given constructor function with the provided arguments.\n *\n * @param func - The constructor function to be wrapped and called.\n * @returns A new function that constructs an instance of the given constructor function with the provided arguments.\n */\nfunction unconstruct(func) {\n return function () {\n for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n args[_key2] = arguments[_key2];\n }\n return construct(func, args);\n };\n}\n/**\n * Add properties to a lookup table\n *\n * @param set - The set to which elements will be added.\n * @param array - The array containing elements to be added to the set.\n * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.\n * @returns The modified set with added elements.\n */\nfunction addToSet(set, array) {\n let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;\n if (setPrototypeOf) {\n // Make 'in' and truthy checks like Boolean(set.constructor)\n // independent of any properties defined on Object.prototype.\n // Prevent prototype setters from intercepting set as a this value.\n setPrototypeOf(set, null);\n }\n let l = array.length;\n while (l--) {\n let element = array[l];\n if (typeof element === 'string') {\n const lcElement = transformCaseFunc(element);\n if (lcElement !== element) {\n // Config presets (e.g. tags.js, attrs.js) are immutable.\n if (!isFrozen(array)) {\n array[l] = lcElement;\n }\n element = lcElement;\n }\n }\n set[element] = true;\n }\n return set;\n}\n/**\n * Clean up an array to harden against CSPP\n *\n * @param array - The array to be cleaned.\n * @returns The cleaned version of the array\n */\nfunction cleanArray(array) {\n for (let index = 0; index < array.length; index++) {\n const isPropertyExist = objectHasOwnProperty(array, index);\n if (!isPropertyExist) {\n array[index] = null;\n }\n }\n return array;\n}\n/**\n * Shallow clone an object\n *\n * @param object - The object to be cloned.\n * @returns A new object that copies the original.\n */\nfunction clone(object) {\n const newObject = create(null);\n for (const [property, value] of entries(object)) {\n const isPropertyExist = objectHasOwnProperty(object, property);\n if (isPropertyExist) {\n if (Array.isArray(value)) {\n newObject[property] = cleanArray(value);\n } else if (value && typeof value === 'object' && value.constructor === Object) {\n newObject[property] = clone(value);\n } else {\n newObject[property] = value;\n }\n }\n }\n return newObject;\n}\n/**\n * This method automatically checks if the prop is function or getter and behaves accordingly.\n *\n * @param object - The object to look up the getter function in its prototype chain.\n * @param prop - The property name for which to find the getter function.\n * @returns The getter function found in the prototype chain or a fallback function.\n */\nfunction lookupGetter(object, prop) {\n while (object !== null) {\n const desc = getOwnPropertyDescriptor(object, prop);\n if (desc) {\n if (desc.get) {\n return unapply(desc.get);\n }\n if (typeof desc.value === 'function') {\n return unapply(desc.value);\n }\n }\n object = getPrototypeOf(object);\n }\n function fallbackValue() {\n return null;\n }\n return fallbackValue;\n}\n\nconst html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);\nconst svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);\nconst svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);\n// List of SVG elements that are disallowed by default.\n// We still need to know them so that we can do namespace\n// checks properly in case one wants to add them to\n// allow-list.\nconst svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);\nconst mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);\n// Similarly to SVG, we want to know all MathML elements,\n// even those that we disallow by default.\nconst mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);\nconst text = freeze(['#text']);\n\nconst html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);\nconst svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);\nconst mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);\nconst xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);\n\n// eslint-disable-next-line unicorn/better-regex\nconst MUSTACHE_EXPR = seal(/\\{\\{[\\w\\W]*|[\\w\\W]*\\}\\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode\nconst ERB_EXPR = seal(/<%[\\w\\W]*|[\\w\\W]*%>/gm);\nconst TMPLIT_EXPR = seal(/\\$\\{[\\w\\W]*/gm); // eslint-disable-line unicorn/better-regex\nconst DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]+$/); // eslint-disable-line no-useless-escape\nconst ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\nconst IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\n);\nconst IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\nconst ATTR_WHITESPACE = seal(/[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\n);\nconst DOCTYPE_NAME = seal(/^html$/i);\nconst CUSTOM_ELEMENT = seal(/^[a-z][.\\w]*(-[.\\w]+)+$/i);\n\nvar EXPRESSIONS = /*#__PURE__*/Object.freeze({\n __proto__: null,\n ARIA_ATTR: ARIA_ATTR,\n ATTR_WHITESPACE: ATTR_WHITESPACE,\n CUSTOM_ELEMENT: CUSTOM_ELEMENT,\n DATA_ATTR: DATA_ATTR,\n DOCTYPE_NAME: DOCTYPE_NAME,\n ERB_EXPR: ERB_EXPR,\n IS_ALLOWED_URI: IS_ALLOWED_URI,\n IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,\n MUSTACHE_EXPR: MUSTACHE_EXPR,\n TMPLIT_EXPR: TMPLIT_EXPR\n});\n\n/* eslint-disable @typescript-eslint/indent */\n// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\nconst NODE_TYPE = {\n element: 1,\n attribute: 2,\n text: 3,\n cdataSection: 4,\n entityReference: 5,\n // Deprecated\n entityNode: 6,\n // Deprecated\n progressingInstruction: 7,\n comment: 8,\n document: 9,\n documentType: 10,\n documentFragment: 11,\n notation: 12 // Deprecated\n};\nconst getGlobal = function getGlobal() {\n return typeof window === 'undefined' ? null : window;\n};\n/**\n * Creates a no-op policy for internal use only.\n * Don't export this function outside this module!\n * @param trustedTypes The policy factory.\n * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).\n * @return The policy created (or null, if Trusted Types\n * are not supported or creating the policy failed).\n */\nconst _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {\n if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {\n return null;\n }\n // Allow the callers to control the unique policy name\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\n // Policy creation with duplicate names throws in Trusted Types.\n let suffix = null;\n const ATTR_NAME = 'data-tt-policy-suffix';\n if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {\n suffix = purifyHostElement.getAttribute(ATTR_NAME);\n }\n const policyName = 'dompurify' + (suffix ? '#' + suffix : '');\n try {\n return trustedTypes.createPolicy(policyName, {\n createHTML(html) {\n return html;\n },\n createScriptURL(scriptUrl) {\n return scriptUrl;\n }\n });\n } catch (_) {\n // Policy creation failed (most likely another DOMPurify script has\n // already run). Skip creating the policy, as this will only cause errors\n // if TT are enforced.\n console.warn('TrustedTypes policy ' + policyName + ' could not be created.');\n return null;\n }\n};\nconst _createHooksMap = function _createHooksMap() {\n return {\n afterSanitizeAttributes: [],\n afterSanitizeElements: [],\n afterSanitizeShadowDOM: [],\n beforeSanitizeAttributes: [],\n beforeSanitizeElements: [],\n beforeSanitizeShadowDOM: [],\n uponSanitizeAttribute: [],\n uponSanitizeElement: [],\n uponSanitizeShadowNode: []\n };\n};\nfunction createDOMPurify() {\n let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();\n const DOMPurify = root => createDOMPurify(root);\n DOMPurify.version = '3.2.6';\n DOMPurify.removed = [];\n if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {\n // Not running in a browser, provide a factory function\n // so that you can pass your own Window\n DOMPurify.isSupported = false;\n return DOMPurify;\n }\n let {\n document\n } = window;\n const originalDocument = document;\n const currentScript = originalDocument.currentScript;\n const {\n DocumentFragment,\n HTMLTemplateElement,\n Node,\n Element,\n NodeFilter,\n NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,\n HTMLFormElement,\n DOMParser,\n trustedTypes\n } = window;\n const ElementPrototype = Element.prototype;\n const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');\n const remove = lookupGetter(ElementPrototype, 'remove');\n const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');\n const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');\n const getParentNode = lookupGetter(ElementPrototype, 'parentNode');\n // As per issue #47, the web-components registry is inherited by a\n // new document created via createHTMLDocument. As per the spec\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\n // a new empty registry is used when creating a template contents owner\n // document, so we use that as our parent document to ensure nothing\n // is inherited.\n if (typeof HTMLTemplateElement === 'function') {\n const template = document.createElement('template');\n if (template.content && template.content.ownerDocument) {\n document = template.content.ownerDocument;\n }\n }\n let trustedTypesPolicy;\n let emptyHTML = '';\n const {\n implementation,\n createNodeIterator,\n createDocumentFragment,\n getElementsByTagName\n } = document;\n const {\n importNode\n } = originalDocument;\n let hooks = _createHooksMap();\n /**\n * Expose whether this browser supports running the full DOMPurify.\n */\n DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;\n const {\n MUSTACHE_EXPR,\n ERB_EXPR,\n TMPLIT_EXPR,\n DATA_ATTR,\n ARIA_ATTR,\n IS_SCRIPT_OR_DATA,\n ATTR_WHITESPACE,\n CUSTOM_ELEMENT\n } = EXPRESSIONS;\n let {\n IS_ALLOWED_URI: IS_ALLOWED_URI$1\n } = EXPRESSIONS;\n /**\n * We consider the elements and attributes below to be safe. Ideally\n * don't add any new ones but feel free to remove unwanted ones.\n */\n /* allowed element names */\n let ALLOWED_TAGS = null;\n const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);\n /* Allowed attribute names */\n let ALLOWED_ATTR = null;\n const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);\n /*\n * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.\n * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)\n * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)\n * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.\n */\n let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {\n tagNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n attributeNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n allowCustomizedBuiltInElements: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: false\n }\n }));\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\n let FORBID_TAGS = null;\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\n let FORBID_ATTR = null;\n /* Decide if ARIA attributes are okay */\n let ALLOW_ARIA_ATTR = true;\n /* Decide if custom data attributes are okay */\n let ALLOW_DATA_ATTR = true;\n /* Decide if unknown protocols are okay */\n let ALLOW_UNKNOWN_PROTOCOLS = false;\n /* Decide if self-closing tags in attributes are allowed.\n * Usually removed due to a mXSS issue in jQuery 3.0 */\n let ALLOW_SELF_CLOSE_IN_ATTR = true;\n /* Output should be safe for common template engines.\n * This means, DOMPurify removes data attributes, mustaches and ERB\n */\n let SAFE_FOR_TEMPLATES = false;\n /* Output should be safe even for XML used within HTML and alike.\n * This means, DOMPurify removes comments when containing risky content.\n */\n let SAFE_FOR_XML = true;\n /* Decide if document with ... should be returned */\n let WHOLE_DOCUMENT = false;\n /* Track whether config is already set on this instance of DOMPurify. */\n let SET_CONFIG = false;\n /* Decide if all elements (e.g. style, script) must be children of\n * document.body. By default, browsers might move them to document.head */\n let FORCE_BODY = false;\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported).\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\n */\n let RETURN_DOM = false;\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported) */\n let RETURN_DOM_FRAGMENT = false;\n /* Try to return a Trusted Type object instead of a string, return a string in\n * case Trusted Types are not supported */\n let RETURN_TRUSTED_TYPE = false;\n /* Output should be free from DOM clobbering attacks?\n * This sanitizes markups named with colliding, clobberable built-in DOM APIs.\n */\n let SANITIZE_DOM = true;\n /* Achieve full DOM Clobbering protection by isolating the namespace of named\n * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.\n *\n * HTML/DOM spec rules that enable DOM Clobbering:\n * - Named Access on Window (§7.3.3)\n * - DOM Tree Accessors (§3.1.5)\n * - Form Element Parent-Child Relations (§4.10.3)\n * - Iframe srcdoc / Nested WindowProxies (§4.8.5)\n * - HTMLCollection (§4.2.10.2)\n *\n * Namespace isolation is implemented by prefixing `id` and `name` attributes\n * with a constant string, i.e., `user-content-`\n */\n let SANITIZE_NAMED_PROPS = false;\n const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';\n /* Keep element content when removing element? */\n let KEEP_CONTENT = true;\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\n * of importing it into a new Document and returning a sanitized copy */\n let IN_PLACE = false;\n /* Allow usage of profiles like html, svg and mathMl */\n let USE_PROFILES = {};\n /* Tags to ignore content of when KEEP_CONTENT is true */\n let FORBID_CONTENTS = null;\n const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);\n /* Tags that are safe for data: URIs */\n let DATA_URI_TAGS = null;\n const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);\n /* Attributes safe for values like \"javascript:\" */\n let URI_SAFE_ATTRIBUTES = null;\n const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);\n const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';\n const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';\n /* Document namespace */\n let NAMESPACE = HTML_NAMESPACE;\n let IS_EMPTY_INPUT = false;\n /* Allowed XHTML+XML namespaces */\n let ALLOWED_NAMESPACES = null;\n const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);\n let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);\n let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);\n // Certain elements are allowed in both SVG and HTML\n // namespace. We need to specify them explicitly\n // so that they don't get erroneously deleted from\n // HTML namespace.\n const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);\n /* Parsing of strict XHTML documents */\n let PARSER_MEDIA_TYPE = null;\n const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];\n const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';\n let transformCaseFunc = null;\n /* Keep a reference to config to pass to hooks */\n let CONFIG = null;\n /* Ideally, do not touch anything below this line */\n /* ______________________________________________ */\n const formElement = document.createElement('form');\n const isRegexOrFunction = function isRegexOrFunction(testValue) {\n return testValue instanceof RegExp || testValue instanceof Function;\n };\n /**\n * _parseConfig\n *\n * @param cfg optional config literal\n */\n // eslint-disable-next-line complexity\n const _parseConfig = function _parseConfig() {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n if (CONFIG && CONFIG === cfg) {\n return;\n }\n /* Shield configuration object from tampering */\n if (!cfg || typeof cfg !== 'object') {\n cfg = {};\n }\n /* Shield configuration object from prototype pollution */\n cfg = clone(cfg);\n PARSER_MEDIA_TYPE =\n // eslint-disable-next-line unicorn/prefer-includes\n SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;\n // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.\n transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;\n /* Set configuration parameters */\n ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;\n ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;\n ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;\n URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;\n DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;\n FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;\n FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});\n FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});\n USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;\n ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true\n ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true\n ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false\n ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true\n SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false\n SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true\n WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false\n RETURN_DOM = cfg.RETURN_DOM || false; // Default false\n RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false\n RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false\n FORCE_BODY = cfg.FORCE_BODY || false; // Default false\n SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true\n SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false\n KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true\n IN_PLACE = cfg.IN_PLACE || false; // Default false\n IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;\n NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;\n MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;\n HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;\n CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {\n CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;\n }\n if (SAFE_FOR_TEMPLATES) {\n ALLOW_DATA_ATTR = false;\n }\n if (RETURN_DOM_FRAGMENT) {\n RETURN_DOM = true;\n }\n /* Parse profile info */\n if (USE_PROFILES) {\n ALLOWED_TAGS = addToSet({}, text);\n ALLOWED_ATTR = [];\n if (USE_PROFILES.html === true) {\n addToSet(ALLOWED_TAGS, html$1);\n addToSet(ALLOWED_ATTR, html);\n }\n if (USE_PROFILES.svg === true) {\n addToSet(ALLOWED_TAGS, svg$1);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.svgFilters === true) {\n addToSet(ALLOWED_TAGS, svgFilters);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.mathMl === true) {\n addToSet(ALLOWED_TAGS, mathMl$1);\n addToSet(ALLOWED_ATTR, mathMl);\n addToSet(ALLOWED_ATTR, xml);\n }\n }\n /* Merge configuration parameters */\n if (cfg.ADD_TAGS) {\n if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {\n ALLOWED_TAGS = clone(ALLOWED_TAGS);\n }\n addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);\n }\n if (cfg.ADD_ATTR) {\n if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {\n ALLOWED_ATTR = clone(ALLOWED_ATTR);\n }\n addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);\n }\n if (cfg.ADD_URI_SAFE_ATTR) {\n addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);\n }\n if (cfg.FORBID_CONTENTS) {\n if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {\n FORBID_CONTENTS = clone(FORBID_CONTENTS);\n }\n addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);\n }\n /* Add #text in case KEEP_CONTENT is set to true */\n if (KEEP_CONTENT) {\n ALLOWED_TAGS['#text'] = true;\n }\n /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */\n if (WHOLE_DOCUMENT) {\n addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);\n }\n /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */\n if (ALLOWED_TAGS.table) {\n addToSet(ALLOWED_TAGS, ['tbody']);\n delete FORBID_TAGS.tbody;\n }\n if (cfg.TRUSTED_TYPES_POLICY) {\n if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.');\n }\n if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.');\n }\n // Overwrite existing TrustedTypes policy.\n trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;\n // Sign local variables required by `sanitize`.\n emptyHTML = trustedTypesPolicy.createHTML('');\n } else {\n // Uninitialized policy, attempt to initialize the internal dompurify policy.\n if (trustedTypesPolicy === undefined) {\n trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);\n }\n // If creating the internal policy succeeded sign internal variables.\n if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {\n emptyHTML = trustedTypesPolicy.createHTML('');\n }\n }\n // Prevent further manipulation of configuration.\n // Not available in IE8, Safari 5, etc.\n if (freeze) {\n freeze(cfg);\n }\n CONFIG = cfg;\n };\n /* Keep track of all possible SVG and MathML tags\n * so that we can perform the namespace checks\n * correctly. */\n const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);\n const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);\n /**\n * @param element a DOM element whose namespace is being checked\n * @returns Return false if the element has a\n * namespace that a spec-compliant parser would never\n * return. Return true otherwise.\n */\n const _checkValidNamespace = function _checkValidNamespace(element) {\n let parent = getParentNode(element);\n // In JSDOM, if we're inside shadow DOM, then parentNode\n // can be null. We just simulate parent in this case.\n if (!parent || !parent.tagName) {\n parent = {\n namespaceURI: NAMESPACE,\n tagName: 'template'\n };\n }\n const tagName = stringToLowerCase(element.tagName);\n const parentTagName = stringToLowerCase(parent.tagName);\n if (!ALLOWED_NAMESPACES[element.namespaceURI]) {\n return false;\n }\n if (element.namespaceURI === SVG_NAMESPACE) {\n // The only way to switch from HTML namespace to SVG\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'svg';\n }\n // The only way to switch from MathML to SVG is via`\n // svg if parent is either or MathML\n // text integration points.\n if (parent.namespaceURI === MATHML_NAMESPACE) {\n return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);\n }\n // We only allow elements that are defined in SVG\n // spec. All others are disallowed in SVG namespace.\n return Boolean(ALL_SVG_TAGS[tagName]);\n }\n if (element.namespaceURI === MATHML_NAMESPACE) {\n // The only way to switch from HTML namespace to MathML\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'math';\n }\n // The only way to switch from SVG to MathML is via\n // and HTML integration points\n if (parent.namespaceURI === SVG_NAMESPACE) {\n return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];\n }\n // We only allow elements that are defined in MathML\n // spec. All others are disallowed in MathML namespace.\n return Boolean(ALL_MATHML_TAGS[tagName]);\n }\n if (element.namespaceURI === HTML_NAMESPACE) {\n // The only way to switch from SVG to HTML is via\n // HTML integration points, and from MathML to HTML\n // is via MathML text integration points\n if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n // We disallow tags that are specific for MathML\n // or SVG and should never appear in HTML namespace\n return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);\n }\n // For XHTML and XML documents that support custom namespaces\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {\n return true;\n }\n // The code should never reach this place (this means\n // that the element somehow got namespace that is not\n // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).\n // Return false just in case.\n return false;\n };\n /**\n * _forceRemove\n *\n * @param node a DOM node\n */\n const _forceRemove = function _forceRemove(node) {\n arrayPush(DOMPurify.removed, {\n element: node\n });\n try {\n // eslint-disable-next-line unicorn/prefer-dom-node-remove\n getParentNode(node).removeChild(node);\n } catch (_) {\n remove(node);\n }\n };\n /**\n * _removeAttribute\n *\n * @param name an Attribute name\n * @param element a DOM node\n */\n const _removeAttribute = function _removeAttribute(name, element) {\n try {\n arrayPush(DOMPurify.removed, {\n attribute: element.getAttributeNode(name),\n from: element\n });\n } catch (_) {\n arrayPush(DOMPurify.removed, {\n attribute: null,\n from: element\n });\n }\n element.removeAttribute(name);\n // We void attribute values for unremovable \"is\" attributes\n if (name === 'is') {\n if (RETURN_DOM || RETURN_DOM_FRAGMENT) {\n try {\n _forceRemove(element);\n } catch (_) {}\n } else {\n try {\n element.setAttribute(name, '');\n } catch (_) {}\n }\n }\n };\n /**\n * _initDocument\n *\n * @param dirty - a string of dirty markup\n * @return a DOM, filled with the dirty markup\n */\n const _initDocument = function _initDocument(dirty) {\n /* Create a HTML document */\n let doc = null;\n let leadingWhitespace = null;\n if (FORCE_BODY) {\n dirty = '' + dirty;\n } else {\n /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */\n const matches = stringMatch(dirty, /^[\\r\\n\\t ]+/);\n leadingWhitespace = matches && matches[0];\n }\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {\n // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)\n dirty = '' + dirty + '';\n }\n const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;\n /*\n * Use the DOMParser API by default, fallback later if needs be\n * DOMParser not work for svg when has multiple root element.\n */\n if (NAMESPACE === HTML_NAMESPACE) {\n try {\n doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);\n } catch (_) {}\n }\n /* Use createHTMLDocument in case DOMParser is not available */\n if (!doc || !doc.documentElement) {\n doc = implementation.createDocument(NAMESPACE, 'template', null);\n try {\n doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;\n } catch (_) {\n // Syntax error if dirtyPayload is invalid xml\n }\n }\n const body = doc.body || doc.documentElement;\n if (dirty && leadingWhitespace) {\n body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);\n }\n /* Work on whole document or just its body */\n if (NAMESPACE === HTML_NAMESPACE) {\n return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];\n }\n return WHOLE_DOCUMENT ? doc.documentElement : body;\n };\n /**\n * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.\n *\n * @param root The root element or node to start traversing on.\n * @return The created NodeIterator\n */\n const _createNodeIterator = function _createNodeIterator(root) {\n return createNodeIterator.call(root.ownerDocument || root, root,\n // eslint-disable-next-line no-bitwise\n NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);\n };\n /**\n * _isClobbered\n *\n * @param element element to check for clobbering attacks\n * @return true if clobbered, false if safe\n */\n const _isClobbered = function _isClobbered(element) {\n return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');\n };\n /**\n * Checks whether the given object is a DOM node.\n *\n * @param value object to check whether it's a DOM node\n * @return true is object is a DOM node\n */\n const _isNode = function _isNode(value) {\n return typeof Node === 'function' && value instanceof Node;\n };\n function _executeHooks(hooks, currentNode, data) {\n arrayForEach(hooks, hook => {\n hook.call(DOMPurify, currentNode, data, CONFIG);\n });\n }\n /**\n * _sanitizeElements\n *\n * @protect nodeName\n * @protect textContent\n * @protect removeChild\n * @param currentNode to check for permission to exist\n * @return true if node was killed, false if left alive\n */\n const _sanitizeElements = function _sanitizeElements(currentNode) {\n let content = null;\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeElements, currentNode, null);\n /* Check if element is clobbered or can clobber */\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Now let's check the element's type and name */\n const tagName = transformCaseFunc(currentNode.nodeName);\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeElement, currentNode, {\n tagName,\n allowedTags: ALLOWED_TAGS\n });\n /* Detect mXSS attempts abusing namespace confusion */\n if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\\w!]/g, currentNode.textContent)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any occurrence of processing instructions */\n if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any kind of possibly harmful comments */\n if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\\w]/g, currentNode.data)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove element if anything forbids its presence */\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n /* Check if we have a custom element to handle */\n if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {\n return false;\n }\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {\n return false;\n }\n }\n /* Keep content except for bad-listed elements */\n if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {\n const parentNode = getParentNode(currentNode) || currentNode.parentNode;\n const childNodes = getChildNodes(currentNode) || currentNode.childNodes;\n if (childNodes && parentNode) {\n const childCount = childNodes.length;\n for (let i = childCount - 1; i >= 0; --i) {\n const childClone = cloneNode(childNodes[i], true);\n childClone.__removalCount = (currentNode.__removalCount || 0) + 1;\n parentNode.insertBefore(childClone, getNextSibling(currentNode));\n }\n }\n }\n _forceRemove(currentNode);\n return true;\n }\n /* Check whether element has a valid namespace */\n if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Make sure that older browsers don't get fallback-tag mXSS */\n if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\\/no(script|embed|frames)/i, currentNode.innerHTML)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Sanitize element content to be template-safe */\n if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {\n /* Get the element's text content */\n content = currentNode.textContent;\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n content = stringReplace(content, expr, ' ');\n });\n if (currentNode.textContent !== content) {\n arrayPush(DOMPurify.removed, {\n element: currentNode.cloneNode()\n });\n currentNode.textContent = content;\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeElements, currentNode, null);\n return false;\n };\n /**\n * _isValidAttribute\n *\n * @param lcTag Lowercase tag name of containing element.\n * @param lcName Lowercase attribute name.\n * @param value Attribute value.\n * @return Returns true if `value` is valid, otherwise false.\n */\n // eslint-disable-next-line complexity\n const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {\n /* Make sure attribute cannot clobber */\n if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {\n return false;\n }\n /* Allow valid data-* attributes: At least one character after \"-\"\n (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)\n XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)\n We don't need to check the value; it's always URI safe. */\n if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {\n if (\n // First condition does a very basic check if a) it's basically a valid custom element tagname AND\n // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck\n _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||\n // Alternative, second condition checks if it's an `is`-attribute, AND\n // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {\n return false;\n }\n /* Check value is safe. First, is attr inert? If so, is safe */\n } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {\n return false;\n } else ;\n return true;\n };\n /**\n * _isBasicCustomElement\n * checks if at least one dash is included in tagName, and it's not the first char\n * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name\n *\n * @param tagName name of the tag of the node to sanitize\n * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.\n */\n const _isBasicCustomElement = function _isBasicCustomElement(tagName) {\n return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);\n };\n /**\n * _sanitizeAttributes\n *\n * @protect attributes\n * @protect nodeName\n * @protect removeAttribute\n * @protect setAttribute\n *\n * @param currentNode to sanitize\n */\n const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);\n const {\n attributes\n } = currentNode;\n /* Check if we have attributes; if not we might have a text node */\n if (!attributes || _isClobbered(currentNode)) {\n return;\n }\n const hookEvent = {\n attrName: '',\n attrValue: '',\n keepAttr: true,\n allowedAttributes: ALLOWED_ATTR,\n forceKeepAttr: undefined\n };\n let l = attributes.length;\n /* Go backwards over all attributes; safely remove bad ones */\n while (l--) {\n const attr = attributes[l];\n const {\n name,\n namespaceURI,\n value: attrValue\n } = attr;\n const lcName = transformCaseFunc(name);\n const initValue = attrValue;\n let value = name === 'value' ? initValue : stringTrim(initValue);\n /* Execute a hook if present */\n hookEvent.attrName = lcName;\n hookEvent.attrValue = value;\n hookEvent.keepAttr = true;\n hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set\n _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);\n value = hookEvent.attrValue;\n /* Full DOM Clobbering protection via namespace isolation,\n * Prefix id and name attributes with `user-content-`\n */\n if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {\n // Remove the attribute with this value\n _removeAttribute(name, currentNode);\n // Prefix the value and later re-create the attribute with the sanitized value\n value = SANITIZE_NAMED_PROPS_PREFIX + value;\n }\n /* Work around a security issue with comments inside attributes */\n if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\\/(style|title)/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (hookEvent.forceKeepAttr) {\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (!hookEvent.keepAttr) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Work around a security issue in jQuery 3.0 */\n if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\\/>/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Sanitize attribute content to be template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n value = stringReplace(value, expr, ' ');\n });\n }\n /* Is `value` valid for this attribute? */\n const lcTag = transformCaseFunc(currentNode.nodeName);\n if (!_isValidAttribute(lcTag, lcName, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Handle attributes that require Trusted Types */\n if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {\n if (namespaceURI) ; else {\n switch (trustedTypes.getAttributeType(lcTag, lcName)) {\n case 'TrustedHTML':\n {\n value = trustedTypesPolicy.createHTML(value);\n break;\n }\n case 'TrustedScriptURL':\n {\n value = trustedTypesPolicy.createScriptURL(value);\n break;\n }\n }\n }\n }\n /* Handle invalid data-* attribute set by try-catching it */\n if (value !== initValue) {\n try {\n if (namespaceURI) {\n currentNode.setAttributeNS(namespaceURI, name, value);\n } else {\n /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. \"x-schema\". */\n currentNode.setAttribute(name, value);\n }\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n } else {\n arrayPop(DOMPurify.removed);\n }\n } catch (_) {\n _removeAttribute(name, currentNode);\n }\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);\n };\n /**\n * _sanitizeShadowDOM\n *\n * @param fragment to iterate over recursively\n */\n const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {\n let shadowNode = null;\n const shadowIterator = _createNodeIterator(fragment);\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);\n while (shadowNode = shadowIterator.nextNode()) {\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);\n /* Sanitize tags and elements */\n _sanitizeElements(shadowNode);\n /* Check attributes next */\n _sanitizeAttributes(shadowNode);\n /* Deep shadow DOM detected */\n if (shadowNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(shadowNode.content);\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);\n };\n // eslint-disable-next-line complexity\n DOMPurify.sanitize = function (dirty) {\n let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let body = null;\n let importedNode = null;\n let currentNode = null;\n let returnNode = null;\n /* Make sure we have a string to sanitize.\n DO NOT return early, as this will return the wrong type if\n the user has requested a DOM object rather than a string */\n IS_EMPTY_INPUT = !dirty;\n if (IS_EMPTY_INPUT) {\n dirty = '';\n }\n /* Stringify, in case dirty is an object */\n if (typeof dirty !== 'string' && !_isNode(dirty)) {\n if (typeof dirty.toString === 'function') {\n dirty = dirty.toString();\n if (typeof dirty !== 'string') {\n throw typeErrorCreate('dirty is not a string, aborting');\n }\n } else {\n throw typeErrorCreate('toString is not a function');\n }\n }\n /* Return dirty HTML if DOMPurify cannot run */\n if (!DOMPurify.isSupported) {\n return dirty;\n }\n /* Assign config vars */\n if (!SET_CONFIG) {\n _parseConfig(cfg);\n }\n /* Clean up removed elements */\n DOMPurify.removed = [];\n /* Check if dirty is correctly typed for IN_PLACE */\n if (typeof dirty === 'string') {\n IN_PLACE = false;\n }\n if (IN_PLACE) {\n /* Do some early pre-sanitization to avoid unsafe root nodes */\n if (dirty.nodeName) {\n const tagName = transformCaseFunc(dirty.nodeName);\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');\n }\n }\n } else if (dirty instanceof Node) {\n /* If dirty is a DOM element, append to an empty document to avoid\n elements being stripped by the parser */\n body = _initDocument('');\n importedNode = body.ownerDocument.importNode(dirty, true);\n if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {\n /* Node is already a body, use as is */\n body = importedNode;\n } else if (importedNode.nodeName === 'HTML') {\n body = importedNode;\n } else {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n body.appendChild(importedNode);\n }\n } else {\n /* Exit directly if we have nothing to do */\n if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&\n // eslint-disable-next-line unicorn/prefer-includes\n dirty.indexOf('<') === -1) {\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;\n }\n /* Initialize the document to work on */\n body = _initDocument(dirty);\n /* Check we have a DOM node from the data */\n if (!body) {\n return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';\n }\n }\n /* Remove first element node (ours) if FORCE_BODY is set */\n if (body && FORCE_BODY) {\n _forceRemove(body.firstChild);\n }\n /* Get node iterator */\n const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);\n /* Now start iterating over the created document */\n while (currentNode = nodeIterator.nextNode()) {\n /* Sanitize tags and elements */\n _sanitizeElements(currentNode);\n /* Check attributes next */\n _sanitizeAttributes(currentNode);\n /* Shadow DOM detected, sanitize it */\n if (currentNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(currentNode.content);\n }\n }\n /* If we sanitized `dirty` in-place, return it. */\n if (IN_PLACE) {\n return dirty;\n }\n /* Return sanitized string or DOM */\n if (RETURN_DOM) {\n if (RETURN_DOM_FRAGMENT) {\n returnNode = createDocumentFragment.call(body.ownerDocument);\n while (body.firstChild) {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n returnNode.appendChild(body.firstChild);\n }\n } else {\n returnNode = body;\n }\n if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {\n /*\n AdoptNode() is not used because internal state is not reset\n (e.g. the past names map of a HTMLFormElement), this is safe\n in theory but we would rather not risk another attack vector.\n The state that is cloned by importNode() is explicitly defined\n by the specs.\n */\n returnNode = importNode.call(originalDocument, returnNode, true);\n }\n return returnNode;\n }\n let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;\n /* Serialize doctype if allowed */\n if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {\n serializedHTML = '\\n' + serializedHTML;\n }\n /* Sanitize final string template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n serializedHTML = stringReplace(serializedHTML, expr, ' ');\n });\n }\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;\n };\n DOMPurify.setConfig = function () {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n _parseConfig(cfg);\n SET_CONFIG = true;\n };\n DOMPurify.clearConfig = function () {\n CONFIG = null;\n SET_CONFIG = false;\n };\n DOMPurify.isValidAttribute = function (tag, attr, value) {\n /* Initialize shared config vars if necessary. */\n if (!CONFIG) {\n _parseConfig({});\n }\n const lcTag = transformCaseFunc(tag);\n const lcName = transformCaseFunc(attr);\n return _isValidAttribute(lcTag, lcName, value);\n };\n DOMPurify.addHook = function (entryPoint, hookFunction) {\n if (typeof hookFunction !== 'function') {\n return;\n }\n arrayPush(hooks[entryPoint], hookFunction);\n };\n DOMPurify.removeHook = function (entryPoint, hookFunction) {\n if (hookFunction !== undefined) {\n const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);\n return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];\n }\n return arrayPop(hooks[entryPoint]);\n };\n DOMPurify.removeHooks = function (entryPoint) {\n hooks[entryPoint] = [];\n };\n DOMPurify.removeAllHooks = function () {\n hooks = _createHooksMap();\n };\n return DOMPurify;\n}\nvar purify = createDOMPurify();\n\nexport { purify as default };\n//# sourceMappingURL=purify.es.mjs.map\n","/**\n * This class represents all the constants needed in a MathType integration among different classes.\n * If a constant should be used across different classes should be defined using attribute\n * accessors.\n */\nexport default class Constants {\n /**\n * Safe XML entities.\n * @type {Object}\n */\n static get safeXmlCharactersEntities() {\n return {\n tagOpener: \"«\",\n tagCloser: \"»\",\n doubleQuote: \"¨\",\n realDoubleQuote: \""\",\n };\n }\n\n /**\n * Blackboard invalid safe characters.\n * @type {Object}\n */\n static get safeBadBlackboardCharacters() {\n return {\n ltElement: \"«mo»<«/mo»\",\n gtElement: \"«mo»>«/mo»\",\n ampElement: \"«mo»&«/mo»\",\n };\n }\n\n /**\n * Blackboard valid safe characters.\n * @type{Object}\n */\n static get safeGoodBlackboardCharacters() {\n return {\n ltElement: \"«mo»§lt;«/mo»\",\n gtElement: \"«mo»§gt;«/mo»\",\n ampElement: \"«mo»§amp;«/mo»\",\n };\n }\n\n /**\n * Standard XML special characters.\n * @type {Object}\n */\n static get xmlCharacters() {\n return {\n id: \"xmlCharacters\",\n tagOpener: \"<\", // Hex: \\x3C.\n tagCloser: \">\", // Hex: \\x3E.\n doubleQuote: '\"', // Hex: \\x22.\n ampersand: \"&\", // Hex: \\x26.\n quote: \"'\", // Hex: \\x27.\n };\n }\n\n /**\n * Safe XML special characters. This characters are used instead the standard\n * the standard to parse the MathML if safeXML save mode is enable. Each XML\n * special character have a UTF-8 representation.\n * @type {Object}\n */\n static get safeXmlCharacters() {\n return {\n id: \"safeXmlCharacters\",\n tagOpener: \"«\", // Hex: \\xAB.\n tagCloser: \"»\", // Hex: \\xBB.\n doubleQuote: \"¨\", // Hex: \\xA8.\n ampersand: \"§\", // Hex: \\xA7.\n quote: \"`\", // Hex: \\x60.\n realDoubleQuote: \"¨\",\n };\n }\n}\n","import Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a class to manage MathML objects.\n */\nexport default class MathML {\n /**\n * Checks if the mathml at position i is inside an HTML attribute or not.\n * @param {string} content - a string containing MathML code.\n * @param {number} i - search index.\n * @return {boolean} true if is inside an HTML attribute. false otherwise.\n */\n static isMathmlInAttribute(content, i) {\n // Regex =\n // '^[\\'\"][\\\\s]*=[\\\\s]*[\\\\w-]+([\\\\s]*(\"[^\"]*\"|\\'[^\\']*\\')[\\\\s]*\n // =[\\\\s]*[\\\\w-]+[\\\\s]*)*[\\\\s]+gmi<';\n const mathAtt = \"['\\\"][\\\\s]*=[\\\\s]*[\\\\w-]+\"; // \"=att OR '=att\n const attContent = \"\\\"[^\\\"]*\\\"|'[^']*'\"; // \"blabla\" OR 'blabla'\n const att = `[\\\\s]*(${attContent})[\\\\s]*=[\\\\s]*[\\\\w-]+[\\\\s]*`; // \"blabla\"=att OR 'blabla'=att\n const atts = `('${att}')*`; // \"blabla\"=att1 \"blabla\"=att2\n const regex = `^${mathAtt}${atts}[\\\\s]+gmi<`; // \"=att \"blabla\"=att1 \"blabla\"=att2 gmi< .\n const expression = new RegExp(regex);\n\n const actualContent = content.substring(0, i);\n const reversed = actualContent.split(\"\").reverse().join(\"\");\n const exists = expression.test(reversed);\n\n return exists;\n }\n\n /**\n * Decodes an encoded MathML with standard XML tags.\n * We use these entities because IE doesn't support html entities\n * on its attributes sometimes. Yes, sometimes.\n * @param {string} input - string to be decoded.\n * @return {string} decoded string.\n */\n static safeXmlDecode(input) {\n let { tagOpener } = Constants.safeXmlCharactersEntities;\n let { tagCloser } = Constants.safeXmlCharactersEntities;\n let { doubleQuote } = Constants.safeXmlCharactersEntities;\n let { realDoubleQuote } = Constants.safeXmlCharactersEntities;\n // Decoding entities.\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n // Added to fix problem due to import from 1.9.x.\n input = input.split(realDoubleQuote).join(Constants.safeXmlCharacters.realDoubleQuote);\n\n // Blackboard.\n const { ltElement } = Constants.safeBadBlackboardCharacters;\n const { gtElement } = Constants.safeBadBlackboardCharacters;\n const { ampElement } = Constants.safeBadBlackboardCharacters;\n if (\"_wrs_blackboard\" in window && window._wrs_blackboard) {\n input = input.split(ltElement).join(Constants.safeGoodBlackboardCharacters.ltElement);\n input = input.split(gtElement).join(Constants.safeGoodBlackboardCharacters.gtElement);\n input = input.split(ampElement).join(Constants.safeGoodBlackboardCharacters.ampElement);\n }\n\n ({ tagOpener } = Constants.safeXmlCharacters);\n ({ tagCloser } = Constants.safeXmlCharacters);\n ({ doubleQuote } = Constants.safeXmlCharacters);\n ({ realDoubleQuote } = Constants.safeXmlCharacters);\n const { ampersand } = Constants.safeXmlCharacters;\n const { quote } = Constants.safeXmlCharacters;\n\n // Decoding characters.\n input = input.split(tagOpener).join(Constants.xmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.xmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.xmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.xmlCharacters.ampersand);\n input = input.split(quote).join(Constants.xmlCharacters.quote);\n\n // We are replacing $ by & when its part of an entity for retro-compatibility.\n // Now, the standard is replace § by &.\n let returnValue = \"\";\n let currentEntity = null;\n\n for (let i = 0; i < input.length; i += 1) {\n const character = input.charAt(i);\n if (currentEntity == null) {\n if (character === \"$\") {\n currentEntity = \"\";\n } else {\n returnValue += character;\n }\n } else if (character === \";\") {\n returnValue += `&${currentEntity}`;\n currentEntity = null;\n } else if (character.match(/([a-zA-Z0-9#._-] | '-')/)) {\n // Character is part of an entity.\n currentEntity += character;\n } else {\n returnValue += `$${currentEntity}`; // Is not an entity.\n currentEntity = null;\n i -= 1; // Parse again the current character.\n }\n }\n\n return returnValue;\n }\n\n /**\n * Encodes a MathML with standard XML tags to a MMathML encoded with safe XML tags.\n * We use these entities because IE doesn't support html entities on its attributes sometimes.\n * @param {string} input - input string to be encoded\n * @returns {string} encoded string.\n */\n static safeXmlEncode(input) {\n const { tagOpener } = Constants.xmlCharacters;\n const { tagCloser } = Constants.xmlCharacters;\n const { doubleQuote } = Constants.xmlCharacters;\n const { ampersand } = Constants.xmlCharacters;\n const { quote } = Constants.xmlCharacters;\n\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.safeXmlCharacters.ampersand);\n input = input.split(quote).join(Constants.safeXmlCharacters.quote);\n\n return input;\n }\n\n /**\n * Converts special symbols (> 128) to entities and replaces all textual\n * entities by its number entities.\n * @param {string} mathml - MathML string containing - or not - special symbols\n * @returns {string} MathML with all textual entities replaced.\n */\n static mathMLEntities(mathml) {\n let toReturn = \"\";\n\n for (let i = 0; i < mathml.length; i += 1) {\n const character = mathml.charAt(i);\n\n // Parsing > 128 characters.\n if (mathml.codePointAt(i) > 128) {\n toReturn += `&#${mathml.codePointAt(i)};`;\n // For UTF-32 characters we need to move the index one position.\n if (mathml.codePointAt(i) > 0xffff) {\n i += 1;\n }\n } else if (character === \"&\") {\n const end = mathml.indexOf(\";\", i + 1);\n if (end >= 0) {\n const container = document.createElement(\"span\");\n container.innerHTML = mathml.substring(i, end + 1);\n toReturn += `&#${Util.fixedCharCodeAt(container.textContent || container.innerText, 0)};`;\n i = end;\n } else {\n toReturn += character;\n }\n } else {\n toReturn += character;\n }\n }\n\n return toReturn;\n }\n\n /**\n * Add a custom editor name with the prefix wrs_ to a MathML class attribute.\n * @param {string} mathml - a MathML string created with a custom editor, like chemistry.\n * @param {string} customEditor - custom editor name.\n * @returns {string} MathML string with his class containing the editor toolbar string.\n */\n static addCustomEditorClassAttribute(mathml, customEditor) {\n let toReturn = \"\";\n\n const start = mathml.indexOf(\"\");\n if (mathml.indexOf(\"class\") === -1) {\n // Adding custom editor type.\n toReturn = `${mathml.substr(start, end)} class=\"wrs_${customEditor}\">`;\n toReturn += mathml.substr(end + 1, mathml.length);\n return toReturn;\n }\n }\n return mathml;\n }\n\n /**\n * Remove a custom editor name from the MathML class attribute.\n * @param {string} mathml - a MathML string.\n * @param {string} customEditor - custom editor name.\n * @returns {string} The input MathML without customEditor name in his class.\n */\n static removeCustomEditorClassAttribute(mathml, customEditor) {\n // Discard MathML without the specified class.\n if (mathml.indexOf(\"class\") === -1 || mathml.indexOf(`wrs_${customEditor}`) === -1) {\n return mathml;\n }\n\n // Trivial case: class attribute value equal to editor name. Then\n // class attribute is removed.\n // First try to remove it with a space before if there is one\n // Otherwise without the space\n if (mathml.indexOf(` class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(` class=\"wrs_${customEditor}\"`, \"\");\n }\n if (mathml.indexOf(`class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(`class=\"wrs_${customEditor}\"`, \"\");\n }\n\n // Non Trivial case: class attribute contains editor name.\n return mathml.replace(`wrs_${customEditor}`, \"\");\n }\n\n /**\n * Adds annotation tag in MathML element.\n * @param {String} mathml - valid MathML.\n * @param {String} content - value to put inside annotation tag.\n * @param {String} annotationEncoding - annotation encoding.\n * @returns {String} - 'mathml' with an annotation that contains\n * 'content' and encoding 'encoding'.\n */\n static addAnnotation(mathml, content, annotationEncoding) {\n // If contains annotation, also contains semantics tag.\n const containsAnnotation = mathml.indexOf(\"\");\n mathmlWithAnnotation = `${mathml.substring(0, closeSemanticsIndex)}${content}${mathml.substring(closeSemanticsIndex)}`;\n } else if (MathML.isEmpty(mathml)) {\n const endIndexInline = mathml.indexOf(\"/>\");\n const endIndexNonInline = mathml.indexOf(\">\");\n const endIndex = endIndexNonInline === endIndexInline ? endIndexInline : endIndexNonInline;\n mathmlWithAnnotation = `${mathml.substring(0, endIndex)}>${content}`;\n } else {\n const beginMathMLContent = mathml.indexOf(\">\") + 1;\n const endMathmlContent = mathml.lastIndexOf(\"\");\n const mathmlContent = mathml.substring(beginMathMLContent, endMathmlContent);\n mathmlWithAnnotation = `${mathml.substring(0, beginMathMLContent)}${mathmlContent}${content}`; // eslint-disable-line max-len\n }\n\n return mathmlWithAnnotation;\n }\n\n /**\n * Removes specific annotation tag in MathML element.\n * In case of remove the unique annotation, also is removed semantics tag.\n * @param {String} mathml - valid MathML.\n * @param {String} annotationEncoding - annotation encoding to remove.\n * @returns {String} - 'mathml' without the annotation encoding specified.\n */\n static removeAnnotation(mathml, annotationEncoding) {\n let mathmlWithoutAnnotation = mathml;\n const openAnnotationTag = ``;\n const closeAnnotationTag = \"\";\n const startAnnotationIndex = mathml.indexOf(openAnnotationTag);\n if (startAnnotationIndex !== -1) {\n let differentAnnotationFound = false;\n let differentAnnotationIndex = mathml.indexOf(\"\\s*?()?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsEndingTagRegex = /(<\\/mrow>)?\\s*/gm;\n\n return mathml.replace(semanticsStartingTagRegex, \"\").replace(semanticsEndingTagRegex, \"\");\n }\n\n /**\n * Removes semantics tag to element that contains mathml.\n * When using Hand to create formulas, it adds the mrow tag due to the semantics one, this one is also removed.\n * @param {string} element - Inner HTML text string.\n * @returns {string} - 'mathml' without semantics tag.\n */\n static removeSafeXMLSemantics(element) {\n // If `mrow` is found right before the `semantics` starting tag, it's removed as well\n const semanticsSafeStartingTagRegex = /«semantics»\\s*?(«mrow»)?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsSafeEndingTagRegex = /(«\\/mrow»)?\\s*«annotation[\\W\\w]*?«\\/semantics»/gm;\n\n return element.replace(semanticsSafeStartingTagRegex, \"\").replace(semanticsSafeEndingTagRegex, \"\");\n }\n\n /**\n * Transforms all xml mathml occurrences that contain semantics to the same\n * xml mathml occurrences without semantics.\n * @param {string} text - string that can contain xml mathml occurrences.\n * @param {Constants} [characters] - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * xmlCharacters by default.\n * @returns {string} - 'text' with all xml mathml occurrences without annotation tag.\n */\n static removeSemanticsOcurrences(text, characters = Constants.xmlCharacters) {\n const mathTagStart = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const mathTagEndline = `/${characters.tagCloser}`;\n const { tagCloser } = characters;\n const semanticsTagStart = `${characters.tagOpener}semantics${characters.tagCloser}`;\n const annotationTagStart = `${characters.tagOpener}annotation encoding=`;\n\n let output = \"\";\n let start = text.indexOf(mathTagStart);\n let end = 0;\n while (start !== -1) {\n output += text.substring(end, start);\n\n // MathML can be written as '' or ''.\n const mathTagEndIndex = text.indexOf(mathTagEnd, start);\n const mathTagEndlineIndex = text.indexOf(mathTagEndline, start);\n const firstTagCloser = text.indexOf(tagCloser, start);\n if (mathTagEndIndex !== -1) {\n end = mathTagEndIndex;\n } else if (mathTagEndlineIndex === firstTagCloser - 1) {\n end = mathTagEndlineIndex;\n }\n\n const semanticsIndex = text.indexOf(semanticsTagStart, start);\n if (semanticsIndex !== -1) {\n const mmlTagStart = text.substring(start, semanticsIndex);\n const annotationIndex = text.indexOf(annotationTagStart, start);\n if (annotationIndex !== -1) {\n const startIndex = semanticsIndex + semanticsTagStart.length;\n const mmlContent = text.substring(startIndex, annotationIndex);\n output += mmlTagStart + mmlContent + mathTagEnd;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n end += mathTagEnd.length;\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n }\n\n output += text.substring(end, text.length);\n return output;\n }\n\n /**\n * Returns true if a MathML contains a certain class.\n * @param {string} mathML - input MathML.\n * @param {string} className - className.\n * @returns {boolean} true if the input MathML contains the input class.\n * false otherwise.\n * @static\n */\n static containClass(mathML, className) {\n const classIndex = mathML.indexOf(\"class\");\n if (classIndex === -1) {\n return false;\n }\n const classTagEndIndex = mathML.indexOf(\">\", classIndex);\n const classTag = mathML.substring(classIndex, classTagEndIndex);\n if (classTag.indexOf(className) !== -1) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns true if mathml is empty. Otherwise, false.\n * @param {string} mathml - valid MathML with standard XML tags.\n * @returns {boolean} - true if mathml is empty. Otherwise, false.\n */\n static isEmpty(mathml) {\n // MathML can have the shape or ''.\n const closeTag = \">\";\n const closeTagInline = \"/>\";\n const firstCloseTagIndex = mathml.indexOf(closeTag);\n const firstCloseTagInlineIndex = mathml.indexOf(closeTagInline);\n let empty = false;\n // MathML is always empty in the second shape.\n if (firstCloseTagInlineIndex !== -1) {\n if (firstCloseTagInlineIndex === firstCloseTagIndex - 1) {\n empty = true;\n }\n }\n\n // MathML is always empty in the first shape when there aren't elements\n // between math tags.\n if (!empty) {\n const mathTagEndRegex = new RegExp(\"\");\n const mathTagEndArray = mathTagEndRegex.exec(mathml);\n if (mathTagEndArray) {\n empty = firstCloseTagIndex + 1 === mathTagEndArray.index;\n }\n }\n\n return empty;\n }\n\n /**\n * Encodes html entities inside properties.\n * @param {String} mathml - valid MathML with standard XML tags.\n * @returns {String} - 'mathml' with property entities encoded.\n */\n static encodeProperties(mathml) {\n // Search all the properties.\n const regex = /\\w+=\".*?\"/g;\n // Encode html entities.\n const replacer = (match) => {\n // It has the shape:\n // .\n const quoteIndex = match.indexOf('\"');\n const propertyValue = match.substring(quoteIndex + 1, match.length - 1);\n const propertyValueEncoded = Util.htmlEntities(propertyValue);\n const matchEncoded = `${match.substring(0, quoteIndex + 1)}${propertyValueEncoded}\"`;\n return matchEncoded;\n };\n\n const mathmlEncoded = mathml.replace(regex, replacer);\n return mathmlEncoded;\n }\n}\n","/**\n * This class represents the configuration class.\n * Usually used to retrieve configuration properties generated in the backend into the frontend.\n */\nexport default class Configuration {\n /**\n * Adds a properties object to {@link Configuration.properties}.\n * @param {Object} properties - properties to append to current properties.\n */\n static addConfiguration(properties) {\n Object.assign(Configuration.properties, properties);\n }\n\n /**\n * Static property.\n * The configuration properties object.\n * @private\n * @type {Object}\n */\n static get properties() {\n return Configuration._properties;\n }\n\n /**\n * Static property setter.\n * Set configuration properties.\n * @param {Object} value - The property value.\n * @ignore\n */\n static set properties(value) {\n Configuration._properties = value;\n }\n\n /**\n * Returns the value of a property key.\n * @param {String} key - Property key\n * @returns {String} Property value\n */\n static get(key) {\n if (!Object.prototype.hasOwnProperty.call(Configuration.properties, key)) {\n // Backwards compatibility.\n if (Object.prototype.hasOwnProperty.call(Configuration.properties, \"_wrs_conf_\")) {\n return Configuration.properties[`_wrs_conf_${key}`];\n }\n return false;\n }\n return Configuration.properties[key];\n }\n\n /**\n * Adds a new property to Configuration class.\n * @param {String} key - Property key.\n * @param {Object} value - Property value.\n */\n static set(key, value) {\n Configuration.properties[key] = value;\n }\n\n /**\n * Updates a property object value with new values.\n * @param {String} key - The property key to be updated.\n * @param {Object} propertyValue - Object containing the new values.\n */\n static update(key, propertyValue) {\n if (!Configuration.get(key)) {\n Configuration.set(key, propertyValue);\n } else {\n const updateProperty = Object.assign(Configuration.get(key), propertyValue);\n Configuration.set(key, updateProperty);\n }\n }\n}\n\n/**\n * Static properties object. Stores all configuration properties.\n * Needed to attribute accessors.\n * @private\n * @type {Object}\n */\nConfiguration._properties = {};\n","export default class TextCache {\n /**\n * @classdesc\n * This class represent a client-side text cache class. Contains pairs of\n * strings (key/value) which can be retrieved in any moment. Usually used\n * to store AJAX responses for text services like mathml2latex\n * (c.f {@link Latex} class) or mathml2accessible (c.f {@link Accessibility} class).\n * @constructs\n */\n constructor() {\n /**\n * Cache array property storing the cache entries.\n * @type {Array.}\n */\n this.cache = [];\n }\n\n /**\n * This method populates a key/value pair into the {@link this.cache} property.\n * @param {String} key - Cache key, usually the service string parameter.\n * @param {String} value - Cache value, usually the service response.\n */\n populate(key, value) {\n this.cache[key] = value;\n }\n\n /**\n * Returns the cache value associated to certain cache key.\n * @param {String} key - Cache key, usually the service string parameter.\n * @return {String} value - Cache value, if exists. False otherwise.\n */\n get(key) {\n if (Object.prototype.hasOwnProperty.call(this.cache, key)) {\n return this.cache[key];\n }\n return false;\n }\n}\n","/**\n * This object represents a custom listener.\n * @typedef {Object} Listener\n * @property {String} Listener.eventName - The listener name.\n * @property {Function} Listener.callback - The listener callback function.\n */\n\nexport default class Listeners {\n /**\n * @classdesc\n * This class represents a custom listeners manager.\n * @constructs\n */\n constructor() {\n /**\n * Array containing all custom listeners.\n * @type {Object[]}\n */\n this.listeners = [];\n }\n\n /**\n * Add a listener to Listener class.\n * @param {Object} listener - A listener object.\n */\n add(listener) {\n this.listeners.push(listener);\n }\n\n /**\n * Fires MathType event listeners\n * @param {String} eventName - event name\n * @param {Event} event - event object.\n * @return {boolean} false if event has been prevented. true otherwise.\n */\n fire(eventName, event) {\n for (let i = 0; i < this.listeners.length && !event.cancelled; i += 1) {\n if (this.listeners[i].eventName === eventName) {\n // Calling listener.\n this.listeners[i].callback(event);\n }\n }\n return event.defaultPrevented;\n }\n\n /**\n * Creates a new listener object.\n * @param {string} eventName - Event name.\n * @param {Object} callback - Callback function.\n * @returns {object} the listener object.\n */\n static newListener(eventName, callback) {\n const listener = {};\n listener.eventName = eventName;\n listener.callback = callback;\n return listener;\n }\n}\n","import Util from \"./util\";\nimport Listeners from \"./listeners\";\nimport Configuration from \"./configuration\";\n\n/**\n * @typedef {Object} ServiceProviderProperties\n * @property {String} URI - Service URI.\n * @property {String} server - Service server language.\n */\n\n/**\n * @classdesc\n * Class representing a serviceProvider. A serviceProvider is a class containing\n * an arbitrary number of services with the correspondent path.\n */\nexport default class ServiceProvider {\n /**\n * Returns Service Provider listeners.\n * @type {Listeners}\n */\n static get listeners() {\n return ServiceProvider._listeners;\n }\n\n /**\n * Adds a {@link Listener} instance to {@link ServiceProvider} class.\n * @param {Listener} listener - Instance of {@link Listener}.\n */\n static addListener(listener) {\n ServiceProvider.listeners.add(listener);\n }\n\n /**\n * Fires events in Service Provider.\n * @param {String} eventName - Event name.\n * @param {Event} event - Event object.\n */\n static fireEvent(eventName, event) {\n ServiceProvider.listeners.fire(eventName, event);\n }\n\n /**\n * Service parameters.\n * @type {ServiceProviderProperties}\n *\n */\n static get parameters() {\n return ServiceProvider._parameters;\n }\n\n /**\n * Service parameters.\n * @private\n * @type {ServiceProviderProperties}\n */\n static set parameters(parameters) {\n ServiceProvider._parameters = parameters;\n }\n\n /**\n * Static property.\n * Return service provider paths.\n * @private\n * @type {String}\n */\n static get servicePaths() {\n return ServiceProvider._servicePaths;\n }\n\n /**\n * Static property setter.\n * Set service paths.\n * @param {String} value - The property value.\n * @ignore\n */\n static set servicePaths(value) {\n ServiceProvider._servicePaths = value;\n }\n\n /**\n * Adds a new service to the ServiceProvider.\n * @param {String} service - Service name.\n * @param {String} path - Service path.\n * @static\n */\n static setServicePath(service, path) {\n ServiceProvider.servicePaths[service] = path;\n }\n\n /**\n * Returns the service path for a certain service.\n * @param {String} serviceName - Service name.\n * @returns {String} The service path.\n * @static\n */\n static getServicePath(serviceName) {\n return ServiceProvider.servicePaths[serviceName];\n }\n\n /**\n * Static property.\n * Service provider integration path.\n * @type {String}\n */\n static get integrationPath() {\n return ServiceProvider._integrationPath;\n }\n\n /**\n * Static property setter.\n * Set service provider integration path.\n * @param {String} value - The property value.\n * @ignore\n */\n static set integrationPath(value) {\n ServiceProvider._integrationPath = value;\n }\n\n /**\n * Returns the server URL in the form protocol://serverName:serverPort.\n * @return {String} The client side server path.\n */\n static getServerURL() {\n const url = window.location.href;\n const arr = url.split(\"/\");\n const result = `${arr[0]}//${arr[2]}`;\n return result;\n }\n\n /**\n * Inits {@link this} class. Uses {@link this.integrationPath} as\n * base path to generate all backend services paths.\n * @param {Object} parameters - Function parameters.\n * @param {String} parameters.integrationPath - Service path.\n */\n static init(parameters) {\n ServiceProvider.parameters = parameters;\n // Services path (tech dependant).\n let configurationURI = ServiceProvider.createServiceURI(\"configurationjs\");\n let createImageURI = ServiceProvider.createServiceURI(\"createimage\");\n let showImageURI = ServiceProvider.createServiceURI(\"showimage\");\n let getMathMLURI = ServiceProvider.createServiceURI(\"getmathml\");\n let serviceURI = ServiceProvider.createServiceURI(\"service\");\n\n // Some backend integrations (like Java o Ruby) have an absolute backend path,\n // for example: /app/service. For them we calculate the absolute URL path, i.e\n // protocol://domain:port/app/service\n if (ServiceProvider.parameters.URI.indexOf(\"/\") === 0) {\n const serverPath = ServiceProvider.getServerURL();\n configurationURI = serverPath + configurationURI;\n showImageURI = serverPath + showImageURI;\n createImageURI = serverPath + createImageURI;\n getMathMLURI = serverPath + getMathMLURI;\n serviceURI = serverPath + serviceURI;\n }\n\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n ServiceProvider.setServicePath(\"showimage\", showImageURI);\n ServiceProvider.setServicePath(\"createimage\", createImageURI);\n ServiceProvider.setServicePath(\"service\", serviceURI);\n ServiceProvider.setServicePath(\"getmathml\", getMathMLURI);\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n\n ServiceProvider.listeners.fire(\"onInit\", {});\n }\n\n /**\n * Gets the content from an URL.\n * @param {String} url - Target URL.\n * @param {Object} [postVariables] - Object containing post variables.\n * null if a GET query should be done.\n * @returns {String} Content of the target URL.\n * @private\n * @static\n */\n static getUrl(url, postVariables) {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n const httpRequest = Util.createHttpRequest();\n\n if (httpRequest) {\n if (typeof postVariables === \"undefined\" || typeof postVariables === \"undefined\") {\n httpRequest.open(\"GET\", url, false);\n } else if (url.substr(0, 1) === \"/\" || url.substr(0, 7) === \"http://\" || url.substr(0, 8) === \"https://\") {\n httpRequest.open(\"POST\", url, false);\n } else {\n httpRequest.open(\"POST\", currentPath + url, false);\n }\n\n let header = Configuration.get(\"customHeaders\");\n if (header) {\n if (typeof header === \"string\") {\n header = Util.convertStringToObject(header);\n }\n Object.entries(header).forEach(([key, val]) => httpRequest.setRequestHeader(key, val));\n }\n\n if (typeof postVariables !== \"undefined\" && postVariables) {\n httpRequest.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded; charset=UTF-8\");\n httpRequest.send(Util.httpBuildQuery(postVariables));\n } else {\n httpRequest.send(null);\n }\n\n return httpRequest.responseText;\n }\n return \"\";\n }\n\n /**\n * Returns the response text of a certain service.\n * @param {String} service - Service name.\n * @param {String} postVariables - Post variables.\n * @param {Boolean} get - True if the request is GET instead of POST. false otherwise.\n * @returns {String} Service response text.\n */\n static getService(service, postVariables, get) {\n let response;\n if (get === true) {\n const getVariables = postVariables ? `?${postVariables}` : \"\";\n const serviceUrl = `${ServiceProvider.getServicePath(service)}${getVariables}`;\n response = ServiceProvider.getUrl(serviceUrl);\n } else {\n const serviceUrl = ServiceProvider.getServicePath(service);\n response = ServiceProvider.getUrl(serviceUrl, postVariables);\n }\n return response;\n }\n\n /**\n * Returns the server language of a certain service. The possible values\n * are: php, aspx, java and ruby.\n * This method has backward compatibility purposes.\n * @param {String} service - The configuration service.\n * @returns {String} - The server technology associated with the configuration service.\n */\n static getServerLanguageFromService(service) {\n if (service.indexOf(\".php\") !== -1) {\n return \"php\";\n }\n if (service.indexOf(\".aspx\") !== -1) {\n return \"aspx\";\n }\n if (service.indexOf(\"wirispluginengine\") !== -1) {\n return \"ruby\";\n }\n return \"java\";\n }\n\n /**\n * Returns the URI associated with a certain service.\n * @param {String} service - The service name.\n * @return {String} The service path.\n */\n static createServiceURI(service) {\n const extension = ServiceProvider.serverExtension();\n return Util.concatenateUrl(ServiceProvider.parameters.URI, service) + extension;\n }\n\n static serverExtension() {\n if (ServiceProvider.parameters.server.indexOf(\"php\") !== -1) {\n return \".php\";\n }\n if (ServiceProvider.parameters.server.indexOf(\"aspx\") !== -1) {\n return \".aspx\";\n }\n return \"\";\n }\n}\n\n/**\n * @property {String} service - The service name.\n * @property {String} path - The service path.\n * @static\n */\nServiceProvider._servicePaths = {};\n\n/**\n * The integration path. Contains the path of the configuration service.\n * Used to define the path for all services.\n * @type {String}\n * @private\n */\nServiceProvider._integrationPath = \"\";\n\n/**\n * ServiceProvider static listeners.\n * @type {Listeners}\n * @private\n */\nServiceProvider._listeners = new Listeners();\n\n/**\n * Service provider parameters.\n * @type {ServiceProviderParameters}\n */\nServiceProvider._parameters = {};\n","import TextCache from \"./textcache\";\nimport MathML from \"./mathml\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a LaTeX parser. Manages the services which allows to convert\n * LaTeX into MathML and MathML into LaTeX.\n */\nexport default class Latex {\n /**\n * Static property.\n * Return latex cache.\n * @private\n * @type {Cache}\n */\n static get cache() {\n return Latex._cache;\n }\n\n /**\n * Static property setter.\n * Set latex cache.\n * @param {Cache} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Latex._cache = value;\n }\n\n /**\n * Converts MathML to LaTeX by calling mathml2latex service. For text services\n * we call a text service with the param mathml2latex.\n * @param {String} mathml - MathML String.\n * @return {String} LaTeX string generated by the MathML argument.\n */\n static getLatexFromMathML(mathml) {\n const mathmlWithoutSemantics = MathML.removeSemantics(mathml);\n /**\n * @type {TextCache}\n */\n const { cache } = Latex;\n\n const data = {\n service: \"mathml2latex\",\n mml: mathmlWithoutSemantics,\n };\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n // TODO: Error handling.\n let latex = \"\";\n\n if (jsonResponse.status === \"ok\") {\n latex = jsonResponse.result.text;\n const latexHtmlEntitiesEncoded = Util.htmlEntities(latex);\n // Inserting LaTeX semantics.\n const mathmlWithSemantics = MathML.addAnnotation(mathml, latexHtmlEntitiesEncoded, \"LaTeX\");\n cache.populate(latex, mathmlWithSemantics);\n }\n\n return latex;\n }\n\n /**\n * Converts LaTeX to MathML by calling latex2mathml service. For text services\n * we call a text service with the param latex2mathml.\n * @param {String} latex - String containing a LaTeX formula.\n * @param {Boolean} includeLatexOnSemantics\n * - If true LaTeX would me included into MathML semantics.\n * @return {String} MathML string generated by the LaTeX argument.\n */\n static getMathMLFromLatex(latex, includeLatexOnSemantics) {\n /**\n * @type {TextCache}\n */\n const latexCache = Latex.cache;\n\n if (Latex.cache.get(latex)) {\n return Latex.cache.get(latex);\n }\n const data = {\n service: \"latex2mathml\",\n latex,\n };\n\n if (includeLatexOnSemantics) {\n data.saveLatex = \"\";\n }\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n let output;\n if (jsonResponse.status === \"ok\") {\n let mathml = jsonResponse.result.text;\n mathml = mathml.split(\"\\r\").join(\"\").split(\"\\n\").join(\" \");\n\n // Populate LatexCache.\n if (mathml.indexOf(\"semantics\") === -1 && mathml.indexOf(\"annotation\") === -1) {\n const content = Util.htmlEntities(latex);\n mathml = MathML.addAnnotation(mathml, content, \"LaTeX\");\n output = mathml;\n } else {\n output = mathml;\n }\n if (!latexCache.get(latex)) {\n latexCache.populate(latex, mathml);\n }\n } else {\n output = `$$${latex}$$`;\n }\n return output;\n }\n\n /**\n * Converts all occurrences of MathML code to LaTeX.\n * The MathML code should containing to be converted.\n * @param {String} content - A string containing MathML valid code.\n * @param {Object} characters - An object containing special characters.\n * @return {String} A string containing all MathML annotated occurrences\n * replaced by the corresponding LaTeX code.\n */\n static parseMathmlToLatex(content, characters) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const openTarget = `${characters.tagOpener}annotation encoding=${characters.doubleQuote}LaTeX${characters.doubleQuote}${characters.tagCloser}`;\n const closeTarget = `${characters.tagOpener}/annotation${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n let mathml;\n let startAnnotation;\n let closeAnnotation;\n\n while (start !== -1) {\n output += content.substring(end, start);\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else {\n end += mathTagEnd.length;\n }\n\n mathml = content.substring(start, end);\n\n startAnnotation = mathml.indexOf(openTarget);\n if (startAnnotation !== -1) {\n startAnnotation += openTarget.length;\n closeAnnotation = mathml.indexOf(closeTarget);\n let latex = mathml.substring(startAnnotation, closeAnnotation);\n if (characters === Constants.safeXmlCharacters) {\n latex = MathML.safeXmlDecode(latex);\n }\n output += `$$${latex}$$`;\n // Populate latex into cache.\n\n Latex.cache.populate(latex, mathml);\n } else {\n output += mathml;\n }\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n\n /**\n * Extracts the latex of a determined position in a text.\n * @param {Node} textNode - textNode to extract the LaTeX\n * @param {Number} caretPosition - Starting position to find LaTeX.\n * @param {Object} latexTags - Optional parameter representing tags between latex is inserted.\n * It has the 'open' attribute for the open tag and the 'close' attribute for the close tag.\n * \"$$\" by default.\n * @return {Object} An object with 3 keys: 'latex', 'start' and 'end'. Null if latex is not found.\n * @static\n */\n static getLatexFromTextNode(textNode, caretPosition, latexTags) {\n // TODO: Set LaTeX Tags as Core variable. Fix the call to this function (third argument).\n // Tags used for LaTeX formulas.\n const defaultLatexTags = {\n open: \"$$\",\n close: \"$$\",\n };\n // latexTags is an optional parameter. If is not set, use default latexTags.\n if (typeof latexTags === \"undefined\" || latexTags == null) {\n latexTags = defaultLatexTags;\n }\n // Looking for the first textNode.\n let startNode = textNode;\n\n while (startNode.previousSibling && startNode.previousSibling.nodeType === 3) {\n // TEXT_NODE.\n startNode = startNode.previousSibling;\n }\n\n /**\n * Returns the next latex position and node from a specific node and position.\n * @param {Node} currentNode - Node where searching latex.\n * @param {Number} currentPosition - Current position inside the currentNode.\n * @param {Object} latexTagsToUse - Tags used at latex beginning and latex final.\n * \"$$\" by default.\n * @param {Boolean} tag - Tag containing the current search.\n * @returns {Object} Object containing the current node and the position.\n */\n function getNextLatexPosition(currentNode, currentPosition, tag) {\n let position = currentNode.nodeValue.indexOf(tag, currentPosition);\n\n while (position === -1) {\n currentNode = currentNode.nextSibling;\n\n if (!currentNode) {\n // TEXT_NODE.\n return null; // Not found.\n }\n\n position = currentNode.nodeValue ? currentNode.nodeValue.indexOf(latexTags.close) : -1;\n }\n\n return {\n node: currentNode,\n position,\n };\n }\n\n /**\n * Determines if a node is previous, or not, to a second one.\n * @param {Node} node - Start node.\n * @param {Number} position - Start node position.\n * @param {Node} endNode - End node.\n * @param {Number} endPosition - End node position.\n * @returns {Boolean} True if the starting node is previous thant the en node. false otherwise.\n */\n function isPrevious(node, position, endNode, endPosition) {\n if (node === endNode) {\n return position <= endPosition;\n }\n while (node && node !== endNode) {\n node = node.nextSibling;\n }\n\n return node === endNode;\n }\n\n let start;\n let end = {\n node: startNode,\n position: 0,\n };\n // Is supposed that open and close tags has the same length.\n const tagLength = latexTags.open.length;\n do {\n start = getNextLatexPosition(end.node, end.position, latexTags.open);\n\n if (start == null || isPrevious(textNode, caretPosition, start.node, start.position)) {\n return null;\n }\n\n end = getNextLatexPosition(start.node, start.position + tagLength, latexTags.close);\n\n if (end == null) {\n return null;\n }\n\n end.position += tagLength;\n } while (isPrevious(end.node, end.position, textNode, caretPosition));\n\n // Isolating latex.\n let latex;\n\n if (start.node === end.node) {\n latex = start.node.nodeValue.substring(start.position + tagLength, end.position - tagLength);\n } else {\n const index = start.position + tagLength;\n latex = start.node.nodeValue.substring(index, start.node.nodeValue.length);\n let currentNode = start.node;\n\n do {\n currentNode = currentNode.nextSibling;\n if (currentNode === end.node) {\n latex += end.node.nodeValue.substring(0, end.position - tagLength);\n } else {\n latex += currentNode.nodeValue ? currentNode.nodeValue : \"\";\n }\n } while (currentNode !== end.node);\n }\n\n return {\n latex,\n startNode: start.node,\n startPosition: start.position,\n endNode: end.node,\n endPosition: end.position,\n };\n }\n}\n\n/**\n * Text cache. Stores all processed LaTeX strings and it's correspondent MathML string.\n * @type {Cache}\n * @static\n */\nLatex._cache = new TextCache();\n","import translations from \"../lang/strings.json\";\n/**\n * This class represents a string manager. It's used to load localized strings.\n */\nexport default class StringManager {\n constructor() {\n throw new Error(\"Static class StringManager can not be instantiated.\");\n }\n\n /**\n * Returns the associated value of certain string key. If the associated value\n * doesn't exits returns the original key.\n * @param {string} key - string key\n * @param {string} lang - DEFAULT = null. Specify the language to translate the string\n * @returns {string} correspondent value. If doesn't exists original key.\n */\n static get(key, lang) {\n // Default language definition\n let { language } = this;\n\n // If parameter language, use it\n if (lang) {\n language = lang;\n }\n\n // Cut down on strings. e.g. en_US -> en\n if (language && language.length > 2) {\n language = language.slice(0, 2);\n }\n\n // Check if we support the language\n if (!this.strings.hasOwnProperty(language)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown language ${language} set in StringManager.`);\n language = \"en\";\n }\n\n // Check if the key is supported in the given language\n if (!this.strings[language].hasOwnProperty(key)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown key ${key} for language ${language} in StringManager.`);\n return key;\n }\n\n return this.strings[language][key];\n }\n}\n\n/**\n * Dictionary of dictionaries:\n * Key: language code\n * Value: Key: id of the string\n * Value: translation of the string\n */\nStringManager.strings = translations;\n\n/**\n * Language of the translations; English by default\n */\nStringManager.language = \"en\";\n","/* eslint-disable no-bitwise */\nimport DOMPurify from \"dompurify\";\nimport MathML from \"./mathml\";\nimport Configuration from \"./configuration\";\nimport Latex from \"./latex\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * This class represents an utility class.\n */\nexport default class Util {\n /**\n * Fires an event in a target.\n * @param {EventTarget} eventTarget - target where event should be fired.\n * @param {string} eventName event to fire.\n * @static\n */\n static fireEvent(eventTarget, eventName) {\n if (document.createEvent) {\n const eventObject = document.createEvent(\"HTMLEvents\");\n eventObject.initEvent(eventName, true, true);\n return !eventTarget.dispatchEvent(eventObject);\n }\n\n const eventObject = document.createEventObject();\n return eventTarget.fireEvent(`on${eventName}`, eventObject);\n }\n\n /**\n * Cross-browser addEventListener/attachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - callback function.\n * @static\n */\n static addEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.addEventListener) {\n eventTarget.addEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.attachEvent) {\n // Backwards compatibility.\n eventTarget.attachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * Cross-browser removeEventListener/detachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - function to remove from the event target.\n * @static\n */\n static removeEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.removeEventListener) {\n eventTarget.removeEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.detachEvent) {\n eventTarget.detachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * Adds the a callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @param {Function} doubleClickHandler - function to run when on dblclick event.\n * @param {Function} mousedownHandler - function to run when on mousedown event.\n * @param {Function} mouseupHandler - function to run when on mouseup event.\n * @static\n */\n static addElementEvents(eventTarget, doubleClickHandler, mousedownHandler, mouseupHandler) {\n if (doubleClickHandler) {\n this.callbackDblclick = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n doubleClickHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"dblclick\", this.callbackDblclick);\n }\n\n if (mousedownHandler) {\n this.callbackMousedown = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mousedownHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"mousedown\", this.callbackMousedown);\n }\n\n if (mouseupHandler) {\n this.callbackMouseup = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mouseupHandler(element, realEvent);\n };\n // Chrome doesn't trigger this event for eventTarget if we release the mouse button\n // while the mouse is outside the editor text field.\n // This is a workaround: we trigger the event independently of where the mouse\n // is when we release its button.\n Util.addEvent(document, \"mouseup\", this.callbackMouseup);\n Util.addEvent(eventTarget, \"mouseup\", this.callbackMouseup);\n }\n }\n\n /**\n * Remove all callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @static\n */\n static removeElementEvents(eventTarget) {\n Util.removeEvent(eventTarget, \"dblclick\", this.callbackDblclick);\n Util.removeEvent(eventTarget, \"mousedown\", this.callbackMousedown);\n Util.removeEvent(document, \"mouseup\", this.callbackMouseup);\n Util.removeEvent(eventTarget, \"mouseup\", this.callbackMouseup);\n }\n\n /**\n * Adds a class name to a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static addClass(element, className) {\n if (!Util.containsClass(element, className)) {\n element.className += ` ${className}`;\n }\n }\n\n /**\n * Checks if a HTMLElement contains a certain class.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the className.\n * @returns {boolean} true if the HTMLElement contains the class name. false otherwise.\n * @static\n */\n static containsClass(element, className) {\n if (element == null || !(\"className\" in element)) {\n return false;\n }\n\n const currentClasses = element.className.split(\" \");\n\n for (let i = currentClasses.length - 1; i >= 0; i -= 1) {\n if (currentClasses[i] === className) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Remove a certain class for a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static removeClass(element, className) {\n let newClassName = \"\";\n const classes = element.className.split(\" \");\n\n for (let i = 0; i < classes.length; i += 1) {\n if (classes[i] !== className) {\n newClassName += `${classes[i]} `;\n }\n }\n element.className = newClassName.trim();\n }\n\n /**\n * Converts old xml initial text attribute (with «») to the correct one(with §lt;§gt;). It's\n * used to parse old applets.\n * @param {string} text - string containing safeXml characters\n * @returns {string} a string with safeXml characters parsed.\n * @static\n */\n static convertOldXmlinitialtextAttribute(text) {\n // Used to fix a bug with Cas imported from Moodle 1.9 to Moodle 2.x.\n // This could be removed in future.\n const val = \"value=\";\n\n const xitpos = text.indexOf(\"xmlinitialtext\");\n const valpos = text.indexOf(val, xitpos);\n const quote = text.charAt(valpos + val.length);\n const startquote = valpos + val.length + 1;\n const endquote = text.indexOf(quote, startquote);\n\n const value = text.substring(startquote, endquote);\n\n let newvalue = value.split(\"«\").join(\"§lt;\");\n newvalue = newvalue.split(\"»\").join(\"§gt;\");\n newvalue = newvalue.split(\"&\").join(\"§\");\n newvalue = newvalue.split(\"¨\").join(\"§quot;\");\n\n text = text.split(value).join(newvalue);\n return text;\n }\n\n /**\n * Convert a string representation of key-value pairs to an object.\n * @param {string} keyValueString - String with key-value pairs in the format key1='value1', key2='value2'\n * @returns {Object} - Object containing the key-value pairs\n */\n static convertStringToObject(keyValueString) {\n if (!keyValueString || typeof keyValueString !== \"string\") {\n return {};\n }\n\n return keyValueString\n .split(\",\")\n .map((pair) => pair.trim().split(\"=\"))\n .reduce((resultObject, [key, value]) => {\n if (key && value) {\n resultObject[key] = value;\n }\n return resultObject;\n }, {});\n }\n\n /**\n * Cross-browser solution for creating new elements.\n * @param {string} tagName - tag name of the wished element.\n * @param {Object} attributes - an object where each key is a wished\n * attribute name and each value is its value.\n * @param {Object} [creator] - if supplied, this function will use\n * the \"createElement\" method from this param. Otherwise\n * document will be used as creator.\n * @returns {Element} The DOM element with the specified attributes assigned.\n * @static\n */\n static createElement(tagName, attributes, creator) {\n if (attributes === undefined) {\n attributes = {};\n }\n\n if (creator === undefined) {\n creator = document;\n }\n\n let element;\n\n /*\n * Internet Explorer fix:\n * If you create a new object dynamically, you can't set a non-standard attribute.\n * For example, you can't set the \"src\" attribute on an \"applet\" object.\n * Other browsers will throw an exception and will run the standard code.\n */\n try {\n let html = `<${tagName}`;\n\n Object.keys(attributes).forEach((attributeName) => {\n html += ` ${attributeName}=\"${Util.htmlEntities(attributes[attributeName])}\"`;\n });\n html += \">\";\n element = creator.createElement(html);\n } catch (e) {\n element = creator.createElement(tagName);\n Object.keys(attributes).forEach((attributeName) => {\n element.setAttribute(attributeName, attributes[attributeName]);\n });\n }\n return element;\n }\n\n /**\n * Creates new HTML from it's HTML code as string.\n * @param {string} objectCode - html code\n * @returns {Element} the HTML element.\n * @static\n */\n static createObject(objectCode, creator) {\n if (creator === undefined) {\n creator = document;\n }\n\n // Internet Explorer can't include \"param\" tag when is setting an innerHTML property.\n objectCode = objectCode\n .split(\"\").join(\"\").split(\"\").join(\"\");\n\n objectCode = objectCode\n .split(\"\").join(\"
\").split(\"\").join(\"
\");\n\n const container = Util.createElement(\"div\", {}, creator);\n container.innerHTML = objectCode;\n\n function recursiveParamsFix(object) {\n if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisParam\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const param = Util.createElement(\"param\", attributesParsed, creator);\n\n // IE fix.\n if (param.NAME) {\n param.name = param.NAME;\n param.value = param.VALUE;\n }\n\n param.removeAttribute(\"wirisObject\");\n object.parentNode.replaceChild(param, object);\n } else if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisApplet\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const applet = Util.createElement(\"applet\", attributesParsed, creator);\n applet.removeAttribute(\"wirisObject\");\n\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n\n if (object.childNodes[i].nodeName.toLowerCase() === \"param\") {\n applet.appendChild(object.childNodes[i]);\n i -= 1; // When we insert the object child into the applet, object loses one child.\n }\n }\n\n object.parentNode.replaceChild(applet, object);\n } else {\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n }\n }\n }\n\n recursiveParamsFix(container);\n return container.firstChild;\n }\n\n /**\n * Converts an Element to its HTML code.\n * @param {Element} element - entry element.\n * @return {string} the HTML code of the input element.\n * @static\n */\n static createObjectCode(element) {\n // In case that the image was not created, the object can be null or undefined.\n if (typeof element === \"undefined\" || element === null) {\n return null;\n }\n\n if (element.nodeType === 1) {\n // ELEMENT_NODE.\n let output = `<${element.tagName}`;\n\n for (let i = 0; i < element.attributes.length; i += 1) {\n if (element.attributes[i].specified) {\n output += ` ${element.attributes[i].name}=\"${Util.htmlEntities(element.attributes[i].value)}\"`;\n }\n }\n\n if (element.childNodes.length > 0) {\n output += \">\";\n\n for (let i = 0; i < element.childNodes.length; i += 1) {\n output += Util.createObject(element.childNodes[i]);\n }\n\n output += ``;\n } else if (element.nodeName === \"DIV\" || element.nodeName === \"SCRIPT\") {\n output += `>`;\n } else {\n output += \"/>\";\n }\n\n return output;\n }\n\n if (element.nodeType === 3) {\n // TEXT_NODE.\n return Util.htmlEntities(element.nodeValue);\n }\n\n return \"\";\n }\n\n /**\n * Concatenates two URL paths.\n * @param {string} path1 - first URL path\n * @param {string} path2 - second URL path\n * @returns {string} new URL.\n */\n static concatenateUrl(path1, path2) {\n let separator = \"\";\n if (path1.indexOf(\"/\") !== path1.length && path2.indexOf(\"/\") !== 0) {\n separator = \"/\";\n }\n return (path1 + separator + path2).replace(/([^:]\\/)\\/+/g, \"$1\");\n }\n\n /**\n * Parses a text and replaces all HTML special characters by their correspondent entities.\n * @param {string} input - text to be parsed.\n * @returns {string} the input text with all their special characters replaced by their entities.\n * @static\n */\n static htmlEntities(input) {\n return input.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\").split('\"').join(\""\");\n }\n\n /**\n * Sanitize HTML to prevent XSS injections.\n * @param {string} html - html to be sanitize.\n * @returns {string} html sanitized.\n * @static\n */\n static htmlSanitize(html) {\n const annotationRegex = /\\/;\n // Get all the annotation content including the tags.\n const annotation = html.match(annotationRegex);\n // Sanitize html code without removing our supported MathML tags and attributes.\n html = DOMPurify.sanitize(html, {\n ADD_TAGS: [\"semantics\", \"annotation\", \"mstack\", \"msline\", \"msrow\", \"none\"],\n ADD_ATTR: [\"linebreak\", \"charalign\", \"stackalign\"],\n });\n // Readd old annotation content.\n return html.replace(annotationRegex, annotation);\n }\n\n /**\n * Parses a text and replaces all the HTML entities by their characters.\n * @param {string} input - text to be parsed\n * @returns {string} the input text with all their entities replaced by characters.\n * @static\n */\n static htmlEntitiesDecode(input) {\n // Textarea element decodes when inner html is set.\n const textarea = document.createElement(\"textarea\");\n textarea.innerHTML = input;\n return textarea.value;\n }\n\n /**\n * Returns a cross-browser http request.\n * @return {object} httpRequest request object.\n * @returns {XMLHttpRequest|ActiveXObject} the proper request object.\n */\n static createHttpRequest() {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n if (currentPath.substr(0, 7) === \"file://\") {\n throw StringManager.get(\"exception_cross_site\");\n }\n\n if (typeof XMLHttpRequest !== \"undefined\") {\n return new XMLHttpRequest();\n }\n\n try {\n return new ActiveXObject(\"Msxml2.XMLHTTP\");\n } catch (e) {\n try {\n return new ActiveXObject(\"Microsoft.XMLHTTP\");\n } catch (oc) {\n return null;\n }\n }\n }\n\n /**\n * Converts a hash to a HTTP query.\n * @param {Object[]} properties - a key/value object.\n * @returns {string} a HTTP query containing all the key value pairs with\n * all the special characters replaced by their entities.\n * @static\n */\n static httpBuildQuery(properties) {\n let result = \"\";\n\n Object.keys(properties).forEach((i) => {\n if (properties[i] != null) {\n result += `${Util.urlEncode(i)}=${Util.urlEncode(properties[i])}&`;\n }\n });\n\n // Deleting last '&' empty character.\n if (result.substring(result.length - 1) === \"&\") {\n result = result.substring(0, result.length - 1);\n }\n\n return result;\n }\n\n /**\n * Convert a hash to string sorting keys to get a deterministic output\n * @param {Object[]} hash - a key/value object.\n * @returns {string} a string with the form key1=value1...keyn=valuen\n * @static\n */\n static propertiesToString(hash) {\n // 1. Sort keys. We sort the keys because we want a deterministic output.\n const keys = [];\n Object.keys(hash).forEach((key) => {\n if (Object.prototype.hasOwnProperty.call(hash, key)) {\n keys.push(key);\n }\n });\n\n const n = keys.length;\n for (let i = 0; i < n; i += 1) {\n for (let j = i + 1; j < n; j += 1) {\n const s1 = keys[i];\n const s2 = keys[j];\n if (Util.compareStrings(s1, s2) > 0) {\n // Swap.\n keys[i] = s2;\n keys[j] = s1;\n }\n }\n }\n\n // 2. Generate output.\n let output = \"\";\n for (let i = 0; i < n; i += 1) {\n const key = keys[i];\n output += key;\n output += \"=\";\n let value = hash[key];\n value = value.replace(\"\\\\\", \"\\\\\\\\\");\n value = value.replace(\"\\n\", \"\\\\n\");\n value = value.replace(\"\\r\", \"\\\\r\");\n value = value.replace(\"\\t\", \"\\\\t\");\n\n output += value;\n output += \"\\n\";\n }\n return output;\n }\n\n /**\n * Compare two strings using charCodeAt method\n * @param {string} a - first string to compare.\n * @param {string} b - second string to compare.\n * @returns {number} the difference between a and b\n * @static\n */\n static compareStrings(a, b) {\n let i;\n const an = a.length;\n const bn = b.length;\n const n = an > bn ? bn : an;\n for (i = 0; i < n; i += 1) {\n const c = Util.fixedCharCodeAt(a, i) - Util.fixedCharCodeAt(b, i);\n if (c !== 0) {\n return c;\n }\n }\n return a.length - b.length;\n }\n\n /**\n * Fix charCodeAt() JavaScript function to handle non-Basic-Multilingual-Plane characters.\n * @param {string} string - input string\n * @param {number} idx - an integer greater than or equal to 0\n * and less than the length of the string\n * @returns {number} an integer representing the UTF-16 code of the string at the given index.\n * @static\n */\n static fixedCharCodeAt(string, idx) {\n idx = idx || 0;\n const code = string.charCodeAt(idx);\n let hi;\n let low;\n\n /* High surrogate (could change last hex to 0xDB7F to treat high\n private surrogates as single characters) */\n\n if (code >= 0xd800 && code <= 0xdbff) {\n hi = code;\n low = string.charCodeAt(idx + 1);\n if (Number.isNaN(low)) {\n throw StringManager.get(\"exception_high_surrogate\");\n }\n return (hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;\n }\n\n if (code >= 0xdc00 && code <= 0xdfff) {\n // Low surrogate.\n /* We return false to allow loops to skip this iteration since should have\n already handled high surrogate above in the previous iteration. */\n return false;\n }\n return code;\n }\n\n /**\n * Returns an URL with it's query params converted into array.\n * @param {string} url - input URL.\n * @returns {Object[]} an array containing all URL query params.\n * @static\n */\n static urlToAssArray(url) {\n let i;\n i = url.indexOf(\"?\");\n if (i > 0) {\n const query = url.substring(i + 1);\n const ss = query.split(\"&\");\n const h = {};\n for (i = 0; i < ss.length; i += 1) {\n const s = ss[i];\n const kv = s.split(\"=\");\n if (kv.length > 1) {\n h[kv[0]] = decodeURIComponent(kv[1].replace(/\\+/g, \" \"));\n }\n }\n return h;\n }\n return {};\n }\n\n /**\n * Returns an encoded URL by replacing each instance of certain characters by\n * one, two, three or four escape sequences using encodeURIComponent method.\n * !'()* . will not be encoded.\n *\n * @param {string} clearString - URL string to be encoded\n * @returns {string} URL with it's special characters replaced.\n * @static\n */\n static urlEncode(clearString) {\n let output = \"\";\n // Method encodeURIComponent doesn't encode !'()*~ .\n output = encodeURIComponent(clearString);\n return output;\n }\n\n // TODO: To parser?\n /**\n * Converts the HTML of a image into the output code that WIRIS must return.\n * By default returns the MathML stored on data-mahml attribute (if imgCode is a formula)\n * or the Wiriscas attribute of a WIRIS applet.\n * @param {string} imgCode - the html code from a formula or a CAS image.\n * @param {boolean} convertToXml - true if the image should be converted to XML.\n * @param {boolean} convertToSafeXml - true if the image should be converted to safeXML.\n * @returns {string} the XML or safeXML of a WIRIS image.\n * @static\n */\n static getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml) {\n const imgObject = Util.createObject(imgCode);\n if (imgObject) {\n if (\n imgObject.className === Configuration.get(\"imageClassName\") ||\n imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"))\n ) {\n if (!convertToXml) {\n return imgCode;\n }\n\n const dataMathML = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n // To handle annotations, first we need the MathML in XML.\n let mathML = MathML.safeXmlDecode(dataMathML);\n\n if (!Configuration.get(\"saveHandTraces\")) {\n mathML = MathML.removeAnnotation(mathML, \"application/json\");\n }\n\n if (mathML == null) {\n mathML = imgObject.getAttribute(\"alt\");\n }\n\n if (convertToSafeXml) {\n const safeMathML = MathML.safeXmlEncode(mathML);\n return safeMathML;\n }\n\n return mathML;\n }\n }\n return imgCode;\n }\n\n /**\n * Gets the node length in characters.\n * @param {Node} node - HTML node.\n * @returns {number} node length.\n * @static\n */\n static getNodeLength(node) {\n const staticNodeLengths = {\n IMG: 1,\n BR: 1,\n };\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return node.nodeValue.length;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n let length = staticNodeLengths[node.nodeName.toUpperCase()];\n\n if (length === undefined) {\n length = 0;\n }\n\n for (let i = 0; i < node.childNodes.length; i += 1) {\n length += Util.getNodeLength(node.childNodes[i]);\n }\n return length;\n }\n return 0;\n }\n\n /**\n * Gets a selected node or text from an editable HTMLElement.\n * If the caret is on a text node, concatenates it with all the previous and next text nodes.\n * @param {HTMLElement} target - the editable HTMLElement.\n * @param {boolean} isIframe - specifies if the target is an iframe or not\n * @param {boolean} forceGetSelection - if true, ignores IE system to get\n * the current selection and uses window.getSelection()\n * @returns {object} an object with the 'node' key set if the item is an\n * element or the keys 'node' and 'caretPosition' if the element is text.\n * @static\n */\n static getSelectedItem(target, isIframe, forceGetSelection) {\n let windowTarget;\n\n if (isIframe) {\n windowTarget = target.contentWindow;\n windowTarget.focus();\n } else {\n windowTarget = window;\n target.focus();\n }\n\n if (document.selection && !forceGetSelection) {\n const range = windowTarget.document.selection.createRange();\n\n if (range.parentElement) {\n if (range.htmlText.length > 0) {\n if (range.text.length === 0) {\n return Util.getSelectedItem(target, isIframe, true);\n }\n\n return null;\n }\n\n windowTarget.document.execCommand(\"InsertImage\", false, \"#\");\n let temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() !== \"IMG\") {\n // IE9 fix: parentElement() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML('');\n temporalObject = windowTarget.document.getElementById(\"wrs_openEditorWindow_temporalObject\");\n }\n\n let node;\n let caretPosition;\n\n if (temporalObject.nextSibling && temporalObject.nextSibling.nodeType === 3) {\n // TEXT_NODE.\n node = temporalObject.nextSibling;\n caretPosition = 0;\n } else if (temporalObject.previousSibling && temporalObject.previousSibling.nodeType === 3) {\n node = temporalObject.previousSibling;\n caretPosition = node.nodeValue.length;\n } else {\n node = windowTarget.document.createTextNode(\"\");\n temporalObject.parentNode.insertBefore(node, temporalObject);\n caretPosition = 0;\n }\n\n temporalObject.parentNode.removeChild(temporalObject);\n\n return {\n node,\n caretPosition,\n };\n }\n\n if (range.length > 1) {\n return null;\n }\n\n return {\n node: range.item(0),\n };\n }\n\n if (windowTarget.getSelection) {\n let range;\n const selection = windowTarget.getSelection();\n\n try {\n range = selection.getRangeAt(0);\n } catch (e) {\n range = windowTarget.document.createRange();\n }\n\n const node = range.startContainer;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return {\n node,\n caretPosition: range.startOffset,\n };\n }\n\n if (node !== range.endContainer) {\n return null;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n const position = range.startOffset;\n\n if (node.childNodes[position]) {\n // In case that a formula is detected but not selected,\n // we create an empty span where we could insert the new formula.\n if (range.startOffset === range.endOffset) {\n if (\n position !== 0 &&\n node.childNodes[position - 1].localName === \"span\" &&\n node.childNodes[position].classList?.contains(\"Wirisformula\")\n ) {\n node.childNodes[position - 1].remove();\n return Util.getSelectedItem(target, isIframe, forceGetSelection);\n }\n if (node.childNodes[position].classList?.contains(\"Wirisformula\")) {\n if (\n (position > 0 && node.childNodes[position - 1].classList?.contains(\"Wirisformula\")) ||\n position === 0\n ) {\n const emptySpan = document.createElement(\"span\");\n node.insertBefore(emptySpan, node.childNodes[position]);\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n\n return null;\n }\n\n /**\n * Returns null if there isn't any item or if it is malformed.\n * Otherwise returns an object containing the node with the MathML image\n * and the cursor position inside the textarea.\n * @param {HTMLTextAreaElement} textarea - textarea element.\n * @returns {Object} An object containing the node, the index of the\n * beginning of the selected text, caret position and the start and end position of the\n * text node.\n * @static\n */\n static getSelectedItemOnTextarea(textarea) {\n const textNode = document.createTextNode(textarea.value);\n const textNodeValues = Latex.getLatexFromTextNode(textNode, textarea.selectionStart);\n if (textNodeValues === null) {\n return null;\n }\n\n return {\n node: textNode,\n caretPosition: textarea.selectionStart,\n startPosition: textNodeValues.startPosition,\n endPosition: textNodeValues.endPosition,\n };\n }\n\n /**\n * Looks for elements that match the given name in a HTML code string.\n * Important: this function is very concrete for WIRIS code.\n * It takes as preconditions lots of behaviors that are not the general case.\n * @param {string} code - HTML code.\n * @param {string} name - element name.\n * @param {boolean} autoClosed - true if the elements are autoClosed.\n * @return {Object[]} an object containing all HTML elements of code matching the name argument.\n * @static\n */\n static getElementsByNameFromString(code, name, autoClosed) {\n const elements = [];\n code = code.toLowerCase();\n name = name.toLowerCase();\n let start = code.indexOf(`<${name} `);\n\n while (start !== -1) {\n // Look for nodes.\n let endString;\n\n if (autoClosed) {\n endString = \">\";\n } else {\n endString = ``;\n }\n\n let end = code.indexOf(endString, start);\n\n if (end !== -1) {\n end += endString.length;\n elements.push({\n start,\n end,\n });\n } else {\n end = start + 1;\n }\n\n start = code.indexOf(`<${name} `, end);\n }\n\n return elements;\n }\n\n /**\n * Returns the numeric value of a base64 character.\n * @param {string} character - base64 character.\n * @returns {number} base64 character numeric value.\n * @static\n */\n static decode64(character) {\n const PLUS = \"+\".charCodeAt(0);\n const SLASH = \"/\".charCodeAt(0);\n const NUMBER = \"0\".charCodeAt(0);\n const LOWER = \"a\".charCodeAt(0);\n const UPPER = \"A\".charCodeAt(0);\n const PLUS_URL_SAFE = \"-\".charCodeAt(0);\n const SLASH_URL_SAFE = \"_\".charCodeAt(0);\n const code = character.charCodeAt(0);\n\n if (code === PLUS || code === PLUS_URL_SAFE) {\n return 62; // Char '+'.\n }\n if (code === SLASH || code === SLASH_URL_SAFE) {\n return 63; // Char '/'.\n }\n if (code < NUMBER) {\n return -1; // No match.\n }\n if (code < NUMBER + 10) {\n return code - NUMBER + 26 + 26;\n }\n if (code < UPPER + 26) {\n return code - UPPER;\n }\n if (code < LOWER + 26) {\n return code - LOWER + 26;\n }\n\n return null;\n }\n\n /**\n * Converts a base64 string to a array of bytes.\n * @param {string} b64String - base64 string.\n * @param {number} length - dimension of byte array (by default whole string).\n * @return {Object[]} the resultant byte array.\n * @static\n */\n static b64ToByteArray(b64String, length) {\n let tmp;\n\n if (b64String.length % 4 > 0) {\n throw new Error(\"Invalid string. Length must be a multiple of 4\"); // Tipped base64. Length is fixed.\n }\n\n const arr = [];\n\n let l;\n let placeHolders;\n if (!length) {\n // All b64String string.\n if (b64String.charAt(b64String.length - 2) === \"=\") {\n placeHolders = 2;\n } else if (b64String.charAt(b64String.length - 1) === \"=\") {\n placeHolders = 1;\n } else {\n placeHolders = 0;\n }\n l = placeHolders > 0 ? b64String.length - 4 : b64String.length;\n } else {\n l = length;\n }\n\n let i;\n for (i = 0; i < l; i += 4) {\n // Ignoring code checker standards (bitewise operators).\n // See https://tracker.moodle.org/browse/CONTRIB-5862 for further information.\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 18) |\n (Util.decode64(b64String.charAt(i + 1)) << 12) |\n (Util.decode64(b64String.charAt(i + 2)) << 6) |\n Util.decode64(b64String.charAt(i + 3));\n\n arr.push((tmp >> 16) & 0xff);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n\n if (placeHolders) {\n if (placeHolders === 2) {\n // Ignoring code checker standards (bitewise operators).\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp = (Util.decode64(b64String.charAt(i)) << 2) | (Util.decode64(b64String.charAt(i + 1)) >> 4);\n arr.push(tmp & 0xff);\n } else if (placeHolders === 1) {\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 10) |\n (Util.decode64(b64String.charAt(i + 1)) << 4) |\n (Util.decode64(b64String.charAt(i + 2)) >> 2);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n }\n return arr;\n }\n\n /**\n * Returns the first 32-bit signed integer from a byte array.\n * @param {Object[]} bytes - array of bytes.\n * @returns {number} the 32-bit signed integer.\n * @static\n */\n static readInt32(bytes) {\n if (bytes.length < 4) {\n return false;\n }\n const int32 = bytes.splice(0, 4);\n // @codingStandardsIgnoreStart¡\n return (int32[0] << 24) | (int32[1] << 16) | (int32[2] << 8) | (int32[3] << 0);\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read the first byte from a byte array.\n * @param {Object} bytes - input byte array.\n * @returns {number} first byte of the byte array.\n * @static\n */\n static readByte(bytes) {\n // @codingStandardsIgnoreStart\n return bytes.shift() << 0;\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read an arbitrary number of bytes, from a fixed position on a byte array.\n * @param {Object[]} bytes - byte array.\n * @param {number} pos - start position.\n * @param {number} len - number of bytes to read.\n * @returns {Object[]} the byte array.\n * @static\n */\n static readBytes(bytes, pos, len) {\n return bytes.splice(pos, len);\n }\n\n /**\n * Inserts or modifies formulas or CAS on a textarea.\n * @param {HTMLTextAreaElement} textarea - textarea target.\n * @param {string} text - text to add in the textarea. For example, to add the link to the image,\n * call this function as (textarea, Parser.createImageSrc(mathml));\n * @static\n */\n static updateTextArea(textarea, text) {\n if (textarea && text) {\n textarea.focus();\n\n if (textarea.selectionStart != null) {\n const { selectionEnd } = textarea;\n const selectionStart = textarea.value.substring(0, textarea.selectionStart);\n const selectionEndSub = textarea.value.substring(selectionEnd, textarea.value.length);\n textarea.value = selectionStart + text + selectionEndSub;\n textarea.selectionEnd = selectionEnd + text.length;\n } else {\n const selection = document.selection.createRange();\n selection.text = text;\n }\n }\n }\n\n /**\n * Modifies existing formula on a textarea.\n * @param {HTMLTextAreaElement} textarea - text area target.\n * @param {string} text - text to add in the textarea. For example, if you want to add the link\n * to the image,you can call this function as\n * Util.updateTextarea(textarea, Parser.createImageSrc(mathml));\n * @param {number} start - beginning index from textarea where it needs to be replaced by text.\n * @param {number} end - ending index from textarea where it needs to be replaced by text\n * @static\n */\n static updateExistingTextOnTextarea(textarea, text, start, end) {\n textarea.focus();\n const textareaStart = textarea.value.substring(0, start);\n textarea.value = textareaStart + text + textarea.value.substring(end, textarea.value.length);\n textarea.selectionEnd = start + text.length;\n }\n\n /**\n * Add a parameter with it's correspondent value to an URL (GET).\n * @param {string} path - URL path\n * @param {string} parameter - parameter\n * @param {string} value - value\n * @static\n */\n static addArgument(path, parameter, value) {\n let sep;\n if (path.indexOf(\"?\") > 0) {\n sep = \"&\";\n } else {\n sep = \"?\";\n }\n return `${path + sep + parameter}=${value}`;\n }\n}\n","import Configuration from \"./configuration\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents MathType Image class. Contains all the logic related\n * to MathType images manipulation.\n * All MathType images are generated using the appropriate MathType\n * integration service: showimage or createimage.\n *\n * There are two available image formats:\n * - svg (default)\n * - png\n *\n * There are two formats for the image src attribute:\n * - A data-uri scheme containing the URL-encoded SVG or a PNG's base64.\n * - A link to the showimage service.\n */\nexport default class Image {\n /**\n * Removes data attributes from an image.\n * @param {HTMLImageElement} img - Image where remove data attributes.\n */\n static removeImgDataAttributes(img) {\n const attributesToRemove = [];\n const { attributes } = img;\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key];\n if (attribute !== undefined && attribute.name !== undefined && attribute.name.indexOf(\"data-\") === 0) {\n // Is preferred keep an array and remove after the search\n // because when attribute is removed the array of attributes\n // is modified.\n attributesToRemove.push(attribute.name);\n }\n });\n\n attributesToRemove.forEach((attribute) => {\n img.removeAttribute(attribute);\n });\n }\n\n /**\n * @static\n * Clones all MathType image attributes from a HTMLImageElement to another.\n * @param {HTMLImageElement} originImg - The original image.\n * @param {HTMLImageElement} destImg - The destination image.\n */\n static clone(originImg, destImg) {\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (!originImg.hasAttribute(customEditorAttributeName)) {\n destImg.removeAttribute(customEditorAttributeName);\n }\n\n const mathmlAttributeName = Configuration.get(\"imageMathmlAttribute\");\n const imgAttributes = [\n mathmlAttributeName,\n customEditorAttributeName,\n \"alt\",\n \"height\",\n \"width\",\n \"style\",\n \"src\",\n \"role\",\n ];\n\n imgAttributes.forEach((iterator) => {\n const originAttribute = originImg.getAttribute(iterator);\n if (originAttribute) {\n destImg.setAttribute(iterator, originAttribute);\n }\n });\n }\n\n /**\n * Determines whether an img src contains an SVG.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src contains an SVG, false otherwise\n */\n static isSvg(img) {\n return img.src.startsWith(\"data:image/svg+xml;\");\n }\n\n /**\n * Determines whether an img src is encoded in base64 or not.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src is encoded in base64, false otherwise\n */\n static isBase64(img) {\n return img.src.startsWith(\"data:image/svg+xml;base64,\") || img.src.startsWith(\"data:image/png;base64,\");\n }\n\n /**\n * Calculates the metrics of a MathType image given the the service response and the image format.\n * @param {HTMLImageElement} img - The HTMLImageElement.\n * @param {String} uri - The URI generated by the image service: can be a data URI scheme or a URL.\n * @param {Boolean} jsonResponse - True the response of the image service is a\n * JSON object. False otherwise.\n */\n static setImgSize(img, uri, jsonResponse) {\n let ar;\n let base64String;\n let bytes;\n let svgString;\n if (jsonResponse) {\n // Cleaning data:image/png;base64.\n if (Image.isSvg(img)) {\n // SVG format.\n // If SVG is encoded in base64 we need to convert the base64 bytes into a SVG string.\n if (!Image.isBase64(img)) {\n ar = Image.getMetricsFromSvgString(uri);\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n svgString = \"\";\n bytes = Util.b64ToByteArray(base64String, base64String.length);\n for (let i = 0; i < bytes.length; i += 1) {\n svgString += String.fromCharCode(bytes[i]);\n }\n ar = Image.getMetricsFromSvgString(svgString);\n }\n // PNG format: we store all metrics information in the first 88 bytes.\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n bytes = Util.b64ToByteArray(base64String, 88);\n ar = Image.getMetricsFromBytes(bytes);\n }\n // Backwards compatibility: we store the metrics into createimage response.\n } else {\n ar = Util.urlToAssArray(uri);\n }\n let width = ar.cw;\n if (!width) {\n return;\n }\n let height = ar.ch;\n let baseline = ar.cb;\n const { dpi } = ar;\n if (dpi) {\n width = (width * 96) / dpi;\n height = (height * 96) / dpi;\n baseline = (baseline * 96) / dpi;\n }\n img.width = width;\n img.height = height;\n img.style.verticalAlign = `-${height - baseline}px`;\n }\n\n /**\n * Calculates the metrics of an image which has been resized. Is used to restore the original\n * metrics of a resized image.\n * @param {HTMLImageElement } img - The resized HTMLImageElement.\n */\n static fixAfterResize(img) {\n img.removeAttribute(\"style\");\n img.removeAttribute(\"width\");\n img.removeAttribute(\"height\");\n // In order to avoid resize with max-width css property.\n img.style.maxWidth = \"none\";\n\n const processImg = (img) => {\n if (img.src.indexOf(\"data:image\") !== -1) {\n if (img.src.indexOf(\"data:image/svg+xml\") !== -1) {\n // Image is in base64: decode it in order to calculate the size, and then bring it back to base64\n // This is a bit of an ugly hack used to recycle the logic of Image.setImgSize instead of rewriting it\n // (which would actually make more sense for readibility and efficiency).\n if (img.src.indexOf(\"data:image/svg+xml;base64,\") !== -1) {\n // 'data:image/svg+xml;base64,'.length === 26\n const base64String = img.getAttribute(\"src\").substring(26);\n const svgString = window.atob(base64String);\n const encodedSvgString = encodeURIComponent(svgString);\n img.setAttribute(\"src\", `data:image/svg+xml;charset=utf8,${encodedSvgString}`);\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n // Return src to base64!\n img.setAttribute(\"src\", `data:image/svg+xml;base64,${base64String}`);\n } else {\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n }\n } else {\n // 'data:image/png;base64,' === 22.\n const base64 = img.src.substring(22, img.src.length);\n Image.setImgSize(img, base64, true);\n }\n } else {\n Image.setImgSize(img, img.src);\n }\n };\n\n // If the image doesn't contain a blob, just process it normally\n if (img.src.indexOf(\"blob:\") === -1) {\n processImg(img);\n // if it does contain a blob, then read that, replace the src with the decoded content, and process it\n } else {\n const reader = new FileReader();\n reader.onload = function () {\n img.setAttribute(\"src\", reader.result);\n processImg(img);\n };\n fetch(img.src)\n .then((r) => r.blob())\n .then((blob) => {\n reader.readAsDataURL(blob);\n });\n }\n }\n\n /**\n * Returns the metrics (height, width and baseline) contained in a SVG image generated\n * by the MathType image service. This image contains as an extra custom attribute:\n * the baseline (wrs:baseline).\n * @param {String} svgString - The SVG image.\n * @return {Array} - The image metrics.\n */\n static getMetricsFromSvgString(svgString) {\n let first = svgString.indexOf('height=\"');\n let last = svgString.indexOf('\"', first + 8, svgString.length);\n const height = svgString.substring(first + 8, last);\n\n first = svgString.indexOf('width=\"');\n last = svgString.indexOf('\"', first + 7, svgString.length);\n const width = svgString.substring(first + 7, last);\n\n first = svgString.indexOf('wrs:baseline=\"');\n last = svgString.indexOf('\"', first + 14, svgString.length);\n const baseline = svgString.substring(first + 14, last);\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n if (typeof baseline !== \"undefined\") {\n arr.cb = baseline;\n }\n return arr;\n }\n return [];\n }\n\n /**\n * Returns the metrics (width, height, baseline and dpi) contained in a PNG byte array.\n * @param {Array.} bytes - png byte array.\n * @return {Array} The png metrics.\n */\n static getMetricsFromBytes(bytes) {\n Util.readBytes(bytes, 0, 8);\n let width;\n let height;\n let typ;\n let baseline;\n let dpi;\n while (bytes.length >= 4) {\n typ = Util.readInt32(bytes);\n if (typ === 0x49484452) {\n width = Util.readInt32(bytes);\n height = Util.readInt32(bytes);\n // Read 5 bytes.\n Util.readInt32(bytes);\n Util.readByte(bytes);\n } else if (typ === 0x62615345) {\n // Baseline: 'baSE'.\n baseline = Util.readInt32(bytes);\n } else if (typ === 0x70485973) {\n // Dpis: 'pHYs'.\n dpi = Util.readInt32(bytes);\n dpi = Math.round(dpi / 39.37);\n Util.readInt32(bytes);\n Util.readByte(bytes);\n }\n Util.readInt32(bytes);\n }\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n arr.dpi = dpi;\n if (baseline) {\n arr.cb = baseline;\n }\n\n return arr;\n }\n return [];\n }\n}\n","import TextCache from \"./textcache\";\nimport ServiceProvider from \"./serviceprovider\";\nimport MathML from \"./mathml\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * @classdesc\n * This class represents MathType accessible class. Converts MathML to accessible text and manages\n * the associated client-side cache.\n */\nexport default class Accessibility {\n /**\n * Static property.\n * Accessibility cache, each entry contains a MathML and its correspondent accessibility text.\n * @type {TextCache}\n */\n static get cache() {\n return Accessibility._cache;\n }\n\n /**\n * Static property setter.\n * Set accessibility cache.\n * @param {TextCahe} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Accessibility._cache = value;\n }\n\n /**\n * Converts MathML strings to its accessible text representation.\n * @param {String} mathML - MathML to be converted to accessible text.\n * @param {String} [language] - Language of the accessible text. 'en' by default.\n * @param {Array.} [data] - Parameters to send to mathml2accessible service.\n * @return {String} Accessibility text.\n */\n static mathMLToAccessible(mathML, language, data) {\n if (typeof language === \"undefined\") {\n language = \"en\";\n }\n // Check MathML class. If the class is chemistry,\n // we add chemistry to data to force accessibility service\n // to load chemistry grammar.\n if (MathML.containClass(mathML, \"wrs_chemistry\")) {\n data.mode = \"chemistry\";\n }\n // Ignore accesibility styles\n data.ignoreStyles = true;\n let accessibleText = \"\";\n\n if (Accessibility.cache.get(mathML)) {\n accessibleText = Accessibility.cache.get(mathML);\n } else {\n data.service = \"mathml2accessible\";\n data.lang = language;\n const accessibleJsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n if (accessibleJsonResponse.status !== \"error\") {\n accessibleText = accessibleJsonResponse.result.text;\n Accessibility.cache.populate(mathML, accessibleText);\n } else {\n accessibleText = StringManager.get(\"error_convert_accessibility\");\n }\n }\n\n return accessibleText;\n }\n}\n\n/**\n * Contains an instance of TextCache class to manage the JavaScript accessible cache.\n * Each entry of the cache object contains the MathML and it's correspondent accessibility text.\n * @private\n * @type {TextCache}\n */\nAccessibility._cache = new TextCache();\n","import Util from \"./util\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport Image from \"./image\";\nimport Accessibility from \"./accessibility\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Configuration from \"./configuration\";\nimport Constants from \"./constants\";\n// eslint-disable-next-line no-unused-vars\nimport md5 from \"./md5\";\n\n/**\n * @classdesc\n * This class represent a MahML parser. Converts MathML into formulas depending on the\n * image format (SVG, PNG, base64) and the save mode (XML, safeXML, Image) configured\n * in the backend.\n */\nexport default class Parser {\n /**\n * Converts a MathML string to an img element.\n * @param {Document} creator - Document object to call createElement method.\n * @param {string} mathml - MathML code\n * @param {Object[]} wirisProperties - object containing WIRIS custom properties\n * @param {language} language - custom language for accessibility.\n * @returns {HTMLImageElement} the formula image corresponding to initial MathML string.\n * @static\n */\n static mathmlToImgObject(creator, mathml, wirisProperties, language) {\n const imgObject = creator.createElement(\"img\");\n imgObject.align = \"middle\";\n imgObject.style.maxWidth = \"none\";\n let data = wirisProperties || {};\n\n // Take into account the backend config\n const wirisEditorProperties = Configuration.get(\"editorParameters\");\n data = { ...wirisEditorProperties, ...data };\n\n data.mml = mathml;\n data.lang = language;\n // Request metrics of the generated image.\n data.metrics = \"true\";\n data.centerbaseline = \"false\";\n\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n // Render js params: _wrs_int_wirisProperties contains some js render params.\n // Since MathML can support render params, js params should be send only to editor.\n\n imgObject.className = Configuration.get(\"imageClassName\");\n\n if (mathml.indexOf('class=\"') !== -1) {\n // We check here if the MathML has been created from a customEditor (such chemistry)\n // to add custom editor name attribute to img object (if necessary).\n let mathmlSubstring = mathml.substring(mathml.indexOf('class=\"') + 'class=\"'.length, mathml.length);\n mathmlSubstring = mathmlSubstring.substring(0, mathmlSubstring.indexOf('\"'));\n mathmlSubstring = mathmlSubstring.substring(4, mathmlSubstring.length);\n imgObject.setAttribute(Configuration.get(\"imageCustomEditorName\"), mathmlSubstring);\n }\n\n // Performance enabled.\n if (\n Configuration.get(\"wirisPluginPerformance\") &&\n (Configuration.get(\"saveMode\") === \"xml\" || Configuration.get(\"saveMode\") === \"safeXml\")\n ) {\n let result = JSON.parse(Parser.createShowImageSrc(data, language));\n if (result.status === \"warning\") {\n // POST call.\n // if the mathml is malformed, this function will throw an exception.\n try {\n result = JSON.parse(ServiceProvider.getService(\"showimage\", data));\n } catch (e) {\n return null;\n }\n }\n ({ result } = result);\n if (result.format === \"png\") {\n imgObject.src = `data:image/png;base64,${result.content}`;\n } else {\n imgObject.src = `data:image/svg+xml;charset=utf8,${Util.urlEncode(result.content)}`;\n }\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n Image.setImgSize(imgObject, result.content, true);\n\n if (Configuration.get(\"enableAccessibility\")) {\n if (typeof result.alt === \"undefined\") {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n } else {\n imgObject.alt = result.alt;\n }\n }\n } else {\n const result = Parser.createImageSrc(mathml, data);\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n imgObject.src = result;\n Image.setImgSize(\n imgObject,\n result,\n Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\",\n );\n if (Configuration.get(\"enableAccessibility\")) {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n }\n }\n\n if (typeof Parser.observer !== \"undefined\") {\n Parser.observer.observe(imgObject);\n }\n\n // Role math https://www.w3.org/TR/wai-aria/roles#math.\n imgObject.setAttribute(\"role\", \"math\");\n return imgObject;\n }\n\n /**\n * Returns the source to showimage service by calling createimage service. The\n * output of the createimage service is a URL path pointing to showimage service.\n * This method is called when performance is disabled.\n * @param {string} mathml - MathML code.\n * @param {Object[]} data - data object containing service parameters.\n * @returns {string} the showimage path.\n */\n static createImageSrc(mathml, data) {\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n let result = ServiceProvider.getService(\"createimage\", data);\n\n if (result.indexOf(\"@BASE@\") !== -1) {\n // Replacing '@BASE@' with the base URL of createimage.\n const baseParts = ServiceProvider.getServicePath(\"createimage\").split(\"/\");\n baseParts.pop();\n result = result.split(\"@BASE@\").join(baseParts.join(\"/\"));\n }\n\n return result;\n }\n\n /**\n * Parses initial HTML code. If the HTML contains data generated by WIRIS,\n * this data would be converted as following:\n *
\n   * MathML code: Image containing the corresponding MathML formulas.\n   * MathML code with LaTeX annotation : LaTeX string.\n   * 
\n * @param {string} code - HTML code containing MathML data.\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code with the original MathML converted into LaTeX and images.\n */\n static initParse(code, language) {\n /* Note: The code inside this function has been inverted.\n If you invert again the code then you cannot use correctly LaTeX\n in Moodle.\n */\n code = Parser.initParseSaveMode(code, language);\n return Parser.initParseEditMode(code);\n }\n\n /**\n * Parses initial HTML code depending on the save mode. Transforms all MathML\n * occurrences for it's correspondent image or LaTeX.\n * @param {string} code - HTML code to be parsed\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code parsed.\n */\n static initParseSaveMode(code, language) {\n if (Configuration.get(\"saveMode\")) {\n // Converting XML to tags.\n code = Latex.parseMathmlToLatex(code, Constants.safeXmlCharacters);\n code = Latex.parseMathmlToLatex(code, Constants.xmlCharacters);\n code = Parser.parseMathmlToImg(code, Constants.safeXmlCharacters, language);\n code = Parser.parseMathmlToImg(code, Constants.xmlCharacters, language);\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"image\") {\n code = Parser.codeImgTransform(code, \"base642showimage\");\n }\n }\n return code;\n }\n\n /**\n * Parses initial HTML code depending on the edit mode.\n * If 'latex' parseMode is enabled all MathML containing an annotation with encoding='LaTeX' will\n * be converted into a LaTeX string instead of an image.\n * @param {string} code - HTML code containing MathML.\n * @returns {string} parsed HTML code.\n */\n static initParseEditMode(code) {\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n const imgList = Util.getElementsByNameFromString(code, \"img\", true);\n const token = 'encoding=\"LaTeX\">';\n // While replacing images with latex, the indexes of the found images changes\n // respecting the original code, so this carry is needed.\n let carry = 0;\n\n for (let i = 0; i < imgList.length; i += 1) {\n const imgCode = code.substring(imgList[i].start + carry, imgList[i].end + carry);\n\n if (imgCode.indexOf(` class=\"${Configuration.get(\"imageClassName\")}\"`) !== -1) {\n let mathmlStartToken = ` ${Configuration.get(\"imageMathmlAttribute\")}=\"`;\n let mathmlStart = imgCode.indexOf(mathmlStartToken);\n\n if (mathmlStart === -1) {\n mathmlStartToken = ' alt=\"';\n mathmlStart = imgCode.indexOf(mathmlStartToken);\n }\n\n if (mathmlStart !== -1) {\n mathmlStart += mathmlStartToken.length;\n const mathmlEnd = imgCode.indexOf('\"', mathmlStart);\n const mathml = Util.htmlSanitize(MathML.safeXmlDecode(imgCode.substring(mathmlStart, mathmlEnd)));\n let latexStartPosition = mathml.indexOf(token);\n\n if (latexStartPosition !== -1) {\n latexStartPosition += token.length;\n const latexEndPosition = mathml.indexOf(\"
\", latexStartPosition);\n const latex = mathml.substring(latexStartPosition, latexEndPosition);\n\n const replaceText = `$$${Util.htmlEntitiesDecode(latex)}$$`;\n const start = code.substring(0, imgList[i].start + carry);\n const end = code.substring(imgList[i].end + carry);\n code = start + replaceText + end;\n carry += replaceText.length - (imgList[i].end - imgList[i].start);\n }\n }\n }\n }\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code. The end HTML code is HTML code with embedded images\n * or LaTeX formulas created with MathType.
\n * By default this method converts the formula images and LaTeX strings in MathML.
\n * If image mode is enabled the images will not be converted into MathML. For further information see {@link https://docs.wiris.com/mathtype/en/mathtype-integrations/mathtype-web-interface-features/full-mathml-mode---wirisplugins-js.html}.\n * @param {string} code - HTML to be parsed\n * @returns {string} the HTML code parsed.\n */\n static endParse(code) {\n // Transform LaTeX ocurrences to MathML elements.\n const codeEndParsedEditMode = Parser.endParseEditMode(code);\n // Transform img elements to MathML elements.\n const codeEndParseSaveMode = Parser.endParseSaveMode(codeEndParsedEditMode);\n return codeEndParseSaveMode;\n }\n\n /**\n * Parses end HTML code depending on the edit mode.\n * - LaTeX is an enabled parse mode, all LaTeX occurrences will be converted into MathML.\n * @param {string} code - HTML code to be parsed.\n * @returns {string} HTML code parsed.\n */\n static endParseEditMode(code) {\n // Converting LaTeX to images.\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n let output = \"\";\n let endPosition = 0;\n let startPosition = code.indexOf(\"$$\");\n while (startPosition !== -1) {\n output += code.substring(endPosition, startPosition);\n endPosition = code.indexOf(\"$$\", startPosition + 2);\n\n if (endPosition !== -1) {\n // Before, it was a condition here to execute the next codelines\n // 'latex.indexOf('<') == -1'.\n // We don't know why it was used, but seems to have a conflict with\n // latex formulas that contains '<'.\n const latex = code.substring(startPosition + 2, endPosition);\n const decodedLatex = Util.htmlEntitiesDecode(latex);\n let mathml = Util.htmlSanitize(Latex.getMathMLFromLatex(decodedLatex, true));\n if (!Configuration.get(\"saveHandTraces\")) {\n // Remove hand traces.\n mathml = MathML.removeAnnotation(mathml, \"application/json\");\n }\n output += mathml;\n endPosition += 2;\n } else {\n output += \"$$\";\n endPosition = startPosition + 2;\n }\n\n startPosition = code.indexOf(\"$$\", endPosition);\n }\n\n output += code.substring(endPosition, code.length);\n code = output;\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code depending on the save mode. Converts all\n * images into the element determined by the save mode:\n * - xml: Parses images formulas into MathML.\n * - safeXml: Parses images formulas into safeMAthML\n * - base64: Parses images into base64 images.\n * - image: Parse images into images (no parsing)\n * @param {string} code - HTML code to be parsed\n * @returns {string} HTML code parsed.\n */\n static endParseSaveMode(code) {\n const savemode = Configuration.get(\"saveMode\");\n const base64savemode = Configuration.get(\"base64savemode\");\n\n if (savemode) {\n if (savemode === \"safeXml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"xml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"base64\" && base64savemode === \"image\") {\n code = Parser.codeImgTransform(code, \"img264\");\n }\n }\n\n return code;\n }\n\n /**\n * Auxiliar function that builds the data object to send to the showimage endpoint\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object with the data to send to showimage.\n */\n static createShowImageSrcData(data, language) {\n const dataMd5 = {};\n const renderParams = [\n \"mml\",\n \"color\",\n \"centerbaseline\",\n \"zoom\",\n \"dpi\",\n \"fontSize\",\n \"fontFamily\",\n \"defaultStretchy\",\n \"backgroundColor\",\n \"format\",\n ];\n renderParams.forEach((param) => {\n if (typeof data[param] !== \"undefined\") {\n dataMd5[param] = data[param];\n }\n });\n // Data variables to get.\n const dataObject = {};\n Object.keys(data).forEach((key) => {\n // We don't need mathml in this request we try to get cached.\n // Only need the formula md5 calculated before.\n if (key !== \"mml\") {\n dataObject[key] = data[key];\n }\n });\n\n dataObject.formula = com.wiris.js.JsPluginTools.md5encode(Util.propertiesToString(dataMd5));\n dataObject.lang = typeof language === \"undefined\" ? \"en\" : language;\n dataObject.version = Configuration.get(\"version\");\n\n return dataObject;\n }\n\n /**\n * Returns the result to call showimage service with the formula md5 as parameter.\n * The result could be:\n * - {'status' : warning'} : The image associated to the MathML md5 is not in cache.\n * - {'status' : 'ok' ...} : The image associated to the MathML md5 is in cache.\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object containing showimage response.\n */\n static createShowImageSrc(data, language) {\n const dataObject = this.createShowImageSrcData(data, language);\n const result = ServiceProvider.getService(\"showimage\", Util.httpBuildQuery(dataObject), true);\n return result;\n }\n\n /**\n * Transform html img tags inside a html code to mathml, base64 img tags (i.e with base64 on src)\n * or showimage img tags (i.e with showimage.php on src)\n * @param {string} code - HTML code\n * @param {string} mode - base642showimage or img2mathml or img264 transform.\n * @returns {string} html - code transformed.\n */\n static codeImgTransform(code, mode) {\n let output = \"\";\n let endPosition = 0;\n const pattern = /\") {\n endPosition = i + 1;\n }\n\n i += 1;\n }\n\n if (endPosition < startPosition) {\n // The img tag is stripped.\n output += code.substring(startPosition, code.length);\n return output;\n }\n let imgCode = code.substring(startPosition, endPosition);\n const imgObject = Util.createObject(imgCode);\n let xmlCode = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n let convertToXml;\n let convertToSafeXml;\n\n if (mode === \"base642showimage\") {\n if (xmlCode == null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n imgCode = Parser.mathmlToImgObject(document, xmlCode, null, null);\n output += Util.createObjectCode(imgCode);\n } else if (mode === \"img2mathml\") {\n if (Configuration.get(\"saveMode\")) {\n if (Configuration.get(\"saveMode\") === \"safeXml\") {\n convertToXml = true;\n convertToSafeXml = true;\n } else if (Configuration.get(\"saveMode\") === \"xml\") {\n convertToXml = true;\n convertToSafeXml = false;\n }\n }\n output += Util.getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml);\n } else if (mode === \"img264\") {\n if (xmlCode === null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n\n const properties = {};\n properties.base64 = \"true\";\n imgCode = Parser.mathmlToImgObject(document, xmlCode, properties, null);\n // Metrics.\n Image.setImgSize(imgCode, imgCode.src, true);\n output += Util.createObjectCode(imgCode);\n }\n }\n output += code.substring(endPosition, code.length);\n return output;\n }\n\n /**\n * Converts all occurrences of MathML to the corresponding image.\n * @param {string} content - string with valid MathML code.\n * The MathML code doesn't contain semantics.\n * @param {Constants} characters - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * @param {string} language - a valid language code\n * in order to generate formula accessibility.\n * @returns {string} The input string with all the MathML\n * occurrences replaced by the corresponding image.\n */\n static parseMathmlToImg(content, characters, language) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n\n while (start !== -1) {\n output += content.substring(end, start);\n // Avoid WIRIS images to be parsed.\n const imageMathmlAtrribute = content.indexOf(Configuration.get(\"imageMathmlAttribute\"));\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else if (imageMathmlAtrribute !== -1) {\n // First close tag of img attribute\n // If a mathmlAttribute exists should be inside a img tag.\n end += content.indexOf(\"/>\", start);\n } else {\n end += mathTagEnd.length;\n }\n\n if (!MathML.isMathmlInAttribute(content, start) && imageMathmlAtrribute === -1) {\n let mathml = content.substring(start, end);\n mathml =\n characters.id === Constants.safeXmlCharacters.id\n ? MathML.safeXmlDecode(mathml)\n : MathML.mathMLEntities(mathml);\n output += Util.createObjectCode(Parser.mathmlToImgObject(document, mathml, null, language));\n } else {\n output += content.substring(start, end);\n }\n\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n}\n\n// Mutation observers to avoid wiris image formulas class be removed.\nif (typeof MutationObserver !== \"undefined\") {\n const mutationObserver = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n if (\n mutation.oldValue === Configuration.get(\"imageClassName\") &&\n mutation.attributeName === \"class\" &&\n mutation.target.className.indexOf(Configuration.get(\"imageClassName\")) === -1\n ) {\n mutation.target.className = Configuration.get(\"imageClassName\");\n }\n });\n });\n\n Parser.observer = Object.create(mutationObserver);\n Parser.observer.Config = { attributes: true, attributeOldValue: true };\n // We use own default config.\n Parser.observer.observe = function (target) {\n Object.getPrototypeOf(this).observe(target, this.Config);\n };\n}\n","/* eslint-disable class-methods-use-this */\n/* eslint-disable no-unused-vars */\n/* eslint-disable no-extra-semi */\n\n// The rules above are disabled because we are implementing\n// an external interface.\n\nexport default class EditorListener {\n /**\n * @classdesc\n * Determines if the content of the\n * MathType Editor has changes.\n * @implements {EditorListeners}\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the content of the editor has changed.\n * @type {Boolean}\n */\n this.isContentChanged = false;\n\n /**\n * Indicates if the listener should be waiting for changes in the editor.\n * @type {Boolean}\n */\n this.waitingForChanges = false;\n }\n\n /**\n * Sets {@link EditorListener.isContentChanged} property.\n * @param {Boolean} value - The new vlue.\n */\n setIsContentChanged(value) {\n this.isContentChanged = value;\n }\n\n /**\n * Returns true if the content of the editor has been changed, false otherwise.\n * @return {Boolean}\n */\n getIsContentChanged() {\n return this.isContentChanged;\n }\n\n /**\n * Determines if the EditorListener should wait for any changes.\n * @param {Boolean} value - True if the editor should wait for changes, false otherwise.\n */\n setWaitingForChanges(value) {\n this.waitingForChanges = value;\n }\n\n /**\n * EditorListener method to overwrite.\n * @type {JsEditor}\n * @ignore\n */\n caretPositionChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @type {JsEditor}\n * @ignore\n */\n clipboardChanged(_editor) {}\n\n /**\n * Determines if the content of an editor has been changed.\n * @param {JsEditor} editor - editor object.\n */\n contentChanged(_editor) {\n if (this.waitingForChanges === true && this.isContentChanged === false) {\n this.isContentChanged = true;\n }\n }\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} editor - The editor instance.\n */\n styleChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} - The editor instance.\n */\n transformationReceived(_editor) {}\n}\n","let wasm;\n\nconst cachedTextDecoder =\n typeof TextDecoder !== \"undefined\"\n ? new TextDecoder(\"utf-8\", { ignoreBOM: true, fatal: true })\n : {\n decode: () => {\n throw Error(\"TextDecoder not available\");\n },\n };\n\nif (typeof TextDecoder !== \"undefined\") {\n cachedTextDecoder.decode();\n}\n\nlet cachedUint8Memory0 = null;\n\nfunction getUint8Memory0() {\n if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {\n cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8Memory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));\n}\n\nconst heap = new Array(128).fill(undefined);\n\nheap.push(undefined, null, true, false);\n\nlet heap_next = heap.length;\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction getObject(idx) {\n return heap[idx];\n}\n\nfunction dropObject(idx) {\n if (idx < 132) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nconst cachedTextEncoder =\n typeof TextEncoder !== \"undefined\"\n ? new TextEncoder(\"utf-8\")\n : {\n encode: () => {\n throw Error(\"TextEncoder not available\");\n },\n };\n\nconst encodeString =\n typeof cachedTextEncoder.encodeInto === \"function\"\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n }\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length,\n };\n };\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8Memory0()\n .subarray(ptr, ptr + buf.length)\n .set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8Memory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7f) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0;\n const view = getUint8Memory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nlet cachedInt32Memory0 = null;\n\nfunction getInt32Memory0() {\n if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {\n cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);\n }\n return cachedInt32Memory0;\n}\n\nlet cachedFloat64Memory0 = null;\n\nfunction getFloat64Memory0() {\n if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {\n cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);\n }\n return cachedFloat64Memory0;\n}\n\nlet cachedBigInt64Memory0 = null;\n\nfunction getBigInt64Memory0() {\n if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) {\n cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer);\n }\n return cachedBigInt64Memory0;\n}\n\nfunction debugString(val) {\n // primitive types\n const type = typeof val;\n if (type == \"number\" || type == \"boolean\" || val == null) {\n return `${val}`;\n }\n if (type == \"string\") {\n return `\"${val}\"`;\n }\n if (type == \"symbol\") {\n const description = val.description;\n if (description == null) {\n return \"Symbol\";\n } else {\n return `Symbol(${description})`;\n }\n }\n if (type == \"function\") {\n const name = val.name;\n if (typeof name == \"string\" && name.length > 0) {\n return `Function(${name})`;\n } else {\n return \"Function\";\n }\n }\n // objects\n if (Array.isArray(val)) {\n const length = val.length;\n let debug = \"[\";\n if (length > 0) {\n debug += debugString(val[0]);\n }\n for (let i = 1; i < length; i++) {\n debug += \", \" + debugString(val[i]);\n }\n debug += \"]\";\n return debug;\n }\n // Test for built-in\n const builtInMatches = /\\[object ([^\\]]+)\\]/.exec(toString.call(val));\n let className;\n if (builtInMatches.length > 1) {\n className = builtInMatches[1];\n } else {\n // Failed to match the standard '[object ClassName]'\n return toString.call(val);\n }\n if (className == \"Object\") {\n // we're a user defined class or Object\n // JSON.stringify avoids problems with cycles, and is generally much\n // easier than looping through ownProperties of `val`.\n try {\n return \"Object(\" + JSON.stringify(val) + \")\";\n } catch (_) {\n return \"Object\";\n }\n }\n // errors\n if (val instanceof Error) {\n return `${val.name}: ${val.message}\\n${val.stack}`;\n }\n // TODO we could test for more things here, like `Set`s and `Map`s.\n return className;\n}\n\nfunction makeClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n try {\n return f(state.a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);\n state.a = 0;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_46(arg0, arg1, arg2) {\n wasm.__wbindgen_export_3(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction makeMutClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n const a = state.a;\n state.a = 0;\n try {\n return f(a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);\n } else {\n state.a = a;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_49(arg0, arg1) {\n wasm.__wbindgen_export_4(arg0, arg1);\n}\n\nfunction __wbg_adapter_52(arg0, arg1, arg2) {\n wasm.__wbindgen_export_5(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction handleError(f, args) {\n try {\n return f.apply(this, args);\n } catch (e) {\n wasm.__wbindgen_export_6(addHeapObject(e));\n }\n}\nfunction __wbg_adapter_103(arg0, arg1, arg2, arg3) {\n wasm.__wbindgen_export_7(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));\n}\n\n/**\n */\nexport function main_js() {\n wasm.main_js();\n}\n\nfunction getArrayU8FromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);\n}\n/**\n */\nexport const Level = Object.freeze({\n Err: 0,\n 0: \"Err\",\n Warn: 1,\n 1: \"Warn\",\n Info: 2,\n 2: \"Info\",\n Debug: 3,\n 3: \"Debug\",\n});\n/**\n */\nexport class Telemeter {\n __destroy_into_raw() {\n const ptr = this.__wbg_ptr;\n this.__wbg_ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_telemeter_free(ptr);\n }\n /**\n * @param {any} solution\n * @param {any} hosts\n * @param {any} config\n */\n constructor(solution, hosts, config) {\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n wasm.telemeter_new(retptr, addHeapObject(solution), addHeapObject(hosts), addHeapObject(config));\n var r0 = getInt32Memory0()[retptr / 4 + 0];\n var r1 = getInt32Memory0()[retptr / 4 + 1];\n var r2 = getInt32Memory0()[retptr / 4 + 2];\n if (r2) {\n throw takeObject(r1);\n }\n this.__wbg_ptr = r0 >>> 0;\n return this;\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n }\n }\n /**\n * @param {string} sender_id\n * @returns {Promise}\n */\n identify(sender_id) {\n const ptr0 = passStringToWasm0(sender_id, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_identify(this.__wbg_ptr, ptr0, len0);\n return takeObject(ret);\n }\n /**\n * @param {string} event_type\n * @param {any} event_payload\n * @returns {Promise}\n */\n track(event_type, event_payload) {\n const ptr0 = passStringToWasm0(event_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_track(this.__wbg_ptr, ptr0, len0, addHeapObject(event_payload));\n return takeObject(ret);\n }\n /**\n * @param {any} level\n * @param {string} message\n * @param {any} payload\n * @returns {Promise}\n */\n log(level, message, payload) {\n const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_log(this.__wbg_ptr, addHeapObject(level), ptr0, len0, addHeapObject(payload));\n return takeObject(ret);\n }\n /**\n * @returns {Promise}\n */\n finish() {\n const ptr = this.__destroy_into_raw();\n const ret = wasm.telemeter_finish(ptr);\n return takeObject(ret);\n }\n /**\n * @param {boolean | undefined} [new_debug_status]\n */\n debug(new_debug_status) {\n wasm.telemeter_debug(this.__wbg_ptr, isLikeNone(new_debug_status) ? 0xffffff : new_debug_status ? 1 : 0);\n }\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === \"function\" && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === \"function\") {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n if (module.headers.get(\"Content-Type\") != \"application/wasm\") {\n console.warn(\n \"`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",\n e,\n );\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n}\n\nfunction __wbg_get_imports() {\n const imports = {};\n imports.wbg = {};\n imports.wbg.__wbindgen_string_new = function (arg0, arg1) {\n const ret = getStringFromWasm0(arg0, arg1);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_c728d68b8b34487e = function () {\n const ret = new Object();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_status_7841bb47be2a8f16 = function (arg0) {\n const ret = getObject(arg0).status;\n return ret;\n };\n imports.wbg.__wbg_headers_ea7ef583d1564b08 = function (arg0) {\n const ret = getObject(arg0).headers;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new0_ad75dd38f92424e2 = function () {\n const ret = new Date();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getTime_ed6ee333b702f8fc = function (arg0) {\n const ret = getObject(arg0).getTime();\n return ret;\n };\n imports.wbg.__wbindgen_object_drop_ref = function (arg0) {\n takeObject(arg0);\n };\n imports.wbg.__wbindgen_is_object = function (arg0) {\n const val = getObject(arg0);\n const ret = typeof val === \"object\" && val !== null;\n return ret;\n };\n imports.wbg.__wbg_crypto_58f13aa23ffcb166 = function (arg0) {\n const ret = getObject(arg0).crypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_process_5b786e71d465a513 = function (arg0) {\n const ret = getObject(arg0).process;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_versions_c2ab80650590b6a2 = function (arg0) {\n const ret = getObject(arg0).versions;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_node_523d7bd03ef69fba = function (arg0) {\n const ret = getObject(arg0).node;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_string = function (arg0) {\n const ret = typeof getObject(arg0) === \"string\";\n return ret;\n };\n imports.wbg.__wbg_msCrypto_abcb1295e768d1f2 = function (arg0) {\n const ret = getObject(arg0).msCrypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_require_2784e593a4674877 = function () {\n return handleError(function () {\n const ret = module.require;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_newwithlength_13b5319ab422dcf6 = function (arg0) {\n const ret = new Uint8Array(arg0 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_4a9aa5157afeb382 = function (arg0, arg1) {\n const ret = getObject(arg0)[arg1 >>> 0];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_next_1989a20442400aaa = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).next();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_done_bc26bf4ada718266 = function (arg0) {\n const ret = getObject(arg0).done;\n return ret;\n };\n imports.wbg.__wbg_value_0570714ff7d75f35 = function (arg0) {\n const ret = getObject(arg0).value;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_iterator_7ee1a391d310f8e4 = function () {\n const ret = Symbol.iterator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_2aff440840bb6202 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.get(getObject(arg0), getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_next_15da6a3df9290720 = function (arg0) {\n const ret = getObject(arg0).next;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_function = function (arg0) {\n const ret = typeof getObject(arg0) === \"function\";\n return ret;\n };\n imports.wbg.__wbg_call_669127b9d730c650 = function () {\n return handleError(function (arg0, arg1) {\n const ret = getObject(arg0).call(getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_object_clone_ref = function (arg0) {\n const ret = getObject(arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_self_3fad056edded10bd = function () {\n return handleError(function () {\n const ret = self.self;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_window_a4f46c98a61d4089 = function () {\n return handleError(function () {\n const ret = window.window;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_globalThis_17eff828815f7d84 = function () {\n return handleError(function () {\n const ret = globalThis.globalThis;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_global_46f939f6541643c5 = function () {\n return handleError(function () {\n const ret = global.global;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_is_undefined = function (arg0) {\n const ret = getObject(arg0) === undefined;\n return ret;\n };\n imports.wbg.__wbg_newnoargs_ccdcae30fd002262 = function (arg0, arg1) {\n const ret = new Function(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_isArray_38525be7442aa21e = function (arg0) {\n const ret = Array.isArray(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_call_53fc3abd42e24ec8 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_isSafeInteger_c38b0a16d0c7cef7 = function (arg0) {\n const ret = Number.isSafeInteger(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_new_feb65b865d980ae2 = function (arg0, arg1) {\n try {\n var state0 = { a: arg0, b: arg1 };\n var cb0 = (arg0, arg1) => {\n const a = state0.a;\n state0.a = 0;\n try {\n return __wbg_adapter_103(a, state0.b, arg0, arg1);\n } finally {\n state0.a = a;\n }\n };\n const ret = new Promise(cb0);\n return addHeapObject(ret);\n } finally {\n state0.a = state0.b = 0;\n }\n };\n imports.wbg.__wbindgen_memory = function () {\n const ret = wasm.memory;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_buffer_344d9b41efe96da7 = function (arg0) {\n const ret = getObject(arg0).buffer;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_d8a000788389a31e = function (arg0) {\n const ret = new Uint8Array(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_set_dcfd613a3420f908 = function (arg0, arg1, arg2) {\n getObject(arg0).set(getObject(arg1), arg2 >>> 0);\n };\n imports.wbg.__wbg_length_a5587d6cd79ab197 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbindgen_string_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"string\" ? obj : undefined;\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_stringify_4039297315a25b00 = function () {\n return handleError(function (arg0) {\n const ret = JSON.stringify(getObject(arg0));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_set_40f7786a25a9cc7e = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_has_cdf8b85f6e903c80 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.has(getObject(arg0), getObject(arg1));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_fetch_701fcd2bde06379a = function (arg0, arg1) {\n const ret = getObject(arg0).fetch(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_fetch_b5d6bebed1e6c2d2 = function (arg0) {\n const ret = fetch(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_newwithbyteoffsetandlength_2dc04d99088b15e3 = function (arg0, arg1, arg2) {\n const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_e4960143e41697a4 = function () {\n return handleError(function () {\n const ret = new AbortController();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_signal_1ed842bebd6ae322 = function (arg0) {\n const ret = getObject(arg0).signal;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_abort_8355f201f30300bb = function (arg0) {\n getObject(arg0).abort();\n };\n imports.wbg.__wbindgen_error_new = function (arg0, arg1) {\n const ret = new Error(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_loose_eq = function (arg0, arg1) {\n const ret = getObject(arg0) == getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_boolean_get = function (arg0) {\n const v = getObject(arg0);\n const ret = typeof v === \"boolean\" ? (v ? 1 : 0) : 2;\n return ret;\n };\n imports.wbg.__wbindgen_number_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"number\" ? obj : undefined;\n getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbg_instanceof_Uint8Array_19e6f142a5e7e1e1 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Uint8Array;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_instanceof_ArrayBuffer_c7cc317e5c29cc0d = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof ArrayBuffer;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_entries_6d727b73ee02b7ce = function (arg0) {\n const ret = Object.entries(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_String_917f38a1211cf44b = function (arg0, arg1) {\n const ret = String(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_warn_ade8d3b7ecee11ff = function (arg0, arg1) {\n console.warn(getObject(arg0), getObject(arg1));\n };\n imports.wbg.__wbg_readyState_13e55da5ad6d64e2 = function (arg0) {\n const ret = getObject(arg0).readyState;\n return ret;\n };\n imports.wbg.__wbg_warn_4affe1093892a4ef = function (arg0) {\n console.warn(getObject(arg0));\n };\n imports.wbg.__wbg_close_f4135085ec3fc8f0 = function () {\n return handleError(function (arg0) {\n getObject(arg0).close();\n }, arguments);\n };\n imports.wbg.__wbg_new_b9b318679315404f = function () {\n return handleError(function (arg0, arg1) {\n const ret = new WebSocket(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setbinaryType_dcb62e0f2b346301 = function (arg0, arg1) {\n getObject(arg0).binaryType = takeObject(arg1);\n };\n imports.wbg.__wbg_log_7811587c4c6d2844 = function (arg0) {\n console.log(getObject(arg0));\n };\n imports.wbg.__wbg_error_f0a6627f4b23c19d = function (arg0) {\n console.error(getObject(arg0));\n };\n imports.wbg.__wbg_info_3ca7870690403fee = function (arg0) {\n console.info(getObject(arg0));\n };\n imports.wbg.__wbg_document_183cf1eecfdbffee = function (arg0) {\n const ret = getObject(arg0).document;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n };\n imports.wbg.__wbg_visibilityState_9721703a5ef75faf = function (arg0) {\n const ret = getObject(arg0).visibilityState;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getwithrefkey_3b3c46ba20582127 = function (arg0, arg1) {\n const ret = getObject(arg0)[getObject(arg1)];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_length_cace2e0b3ddc0502 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbg_addEventListener_0f2891b0794e07fa = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).addEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbg_removeEventListener_104d11302bb212d1 = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).removeEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbindgen_is_bigint = function (arg0) {\n const ret = typeof getObject(arg0) === \"bigint\";\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_i64 = function (arg0) {\n const ret = arg0;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_in = function (arg0, arg1) {\n const ret = getObject(arg0) in getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_u64 = function (arg0) {\n const ret = BigInt.asUintN(64, arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_eq = function (arg0, arg1) {\n const ret = getObject(arg0) === getObject(arg1);\n return ret;\n };\n imports.wbg.__wbg_localStorage_e11f72e996a4f5d9 = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).localStorage;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_getItem_c81cd3ae30cd579a = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n const ret = getObject(arg1).getItem(getStringFromWasm0(arg2, arg3));\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n }, arguments);\n };\n imports.wbg.__wbg_navigator_7078da62d92ff5ad = function (arg0) {\n const ret = getObject(arg0).navigator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_mediaDevices_e00b1f64d2b9939f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).mediaDevices;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_enumerateDevices_619d52f5eef34c2f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).enumerateDevices();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setItem_fe04f524052a3839 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbindgen_cb_drop = function (arg0) {\n const obj = takeObject(arg0).original;\n if (obj.cnt-- == 1) {\n obj.a = 0;\n return true;\n }\n const ret = false;\n return ret;\n };\n imports.wbg.__wbg_deviceId_58f7da2228a26c02 = function (arg0, arg1) {\n const ret = getObject(arg1).deviceId;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_instanceof_Response_944e2745b5db71f5 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Response;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_randomFillSync_a0d98aa11c81fe89 = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).randomFillSync(takeObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbg_subarray_6ca5cfa7fbb9abbe = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getRandomValues_504510b5564925af = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).getRandomValues(getObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbindgen_bigint_get_as_i64 = function (arg0, arg1) {\n const v = getObject(arg1);\n const ret = typeof v === \"bigint\" ? v : undefined;\n getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbindgen_debug_string = function (arg0, arg1) {\n const ret = debugString(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbindgen_throw = function (arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n };\n imports.wbg.__wbg_then_89e1c559530b85cf = function (arg0, arg1) {\n const ret = getObject(arg0).then(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_e5949c35d772a669 = function (arg0) {\n queueMicrotask(getObject(arg0));\n };\n imports.wbg.__wbg_then_1bbc9edafd859b06 = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_2be8b97a81fe4d00 = function (arg0) {\n const ret = getObject(arg0).queueMicrotask;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_resolve_a3252b2860f0a09e = function (arg0) {\n const ret = Promise.resolve(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_url_1f609e63ff1a7983 = function (arg0, arg1) {\n const ret = getObject(arg1).url;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_send_2860805104507701 = function () {\n return handleError(function (arg0, arg1, arg2) {\n getObject(arg0).send(getArrayU8FromWasm0(arg1, arg2));\n }, arguments);\n };\n imports.wbg.__wbg_instanceof_Window_cde2416cf5126a72 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Window;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_new_19676474aa414d62 = function () {\n return handleError(function () {\n const ret = new Headers();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_append_feec4143bbf21904 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbg_newwithstrandinit_29038da14d09e330 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_closure_wrapper1532 = function (arg0, arg1, arg2) {\n const ret = makeClosure(arg0, arg1, 76, __wbg_adapter_46);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1602 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_49);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1834 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_52);\n return addHeapObject(ret);\n };\n\n return imports;\n}\n\nfunction __wbg_init_memory(imports, maybe_memory) {}\n\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n __wbg_init.__wbindgen_wasm_module = module;\n cachedBigInt64Memory0 = null;\n cachedFloat64Memory0 = null;\n cachedInt32Memory0 = null;\n cachedUint8Memory0 = null;\n\n wasm.__wbindgen_start();\n return wasm;\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n const imports = __wbg_get_imports();\n\n __wbg_init_memory(imports);\n\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n\n const instance = new WebAssembly.Instance(module, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(input) {\n if (wasm !== undefined) return wasm;\n\n if (typeof input === \"undefined\") {\n input = new URL(\"telemeter_wasm_bg.wasm\", import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (\n typeof input === \"string\" ||\n (typeof Request === \"function\" && input instanceof Request) ||\n (typeof URL === \"function\" && input instanceof URL)\n ) {\n input = fetch(input);\n }\n\n __wbg_init_memory(imports);\n\n const { instance, module } = await __wbg_load(await input, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync };\nexport default __wbg_init;\n","/* eslint-disable-next-line */\nimport init, { Telemeter as TelemeterWASM } from \"../telemeter-wasm\";\n\n/**\n * @classdesc\n * This class implements the @wiris/telemeter-wasm. A utility that helps our Solutions to send the data\n * to Telemetry in a more comfortable and homogeneous way.\n */\nexport default class Telemeter {\n /**\n * Inits Telemeter class.\n * The parameters structures are defiended on {@link [Telemeter API](https://github.com/wiris/telemeter/blob/main/docs/USAGE.md#telemeter-api)}\n * @param {Object} telemeterAttributes.solution - The product that send data to Telemetry.\n * @param {Object} telemeterAttributes.hosts - Data about the environment where solution is integrated.\n * @param {Object} telemeterAttributes.config - Configuration parameters.\n */\n static init(telemeterAttributes) {\n if (!this.telemeter && !this.waitingForInit) {\n this.waitingForInit = true;\n init(telemeterAttributes.url)\n .then(() => {\n this.telemeter = new TelemeterWASM(\n telemeterAttributes.solution,\n telemeterAttributes.hosts,\n telemeterAttributes.config,\n );\n })\n .catch((error) => {\n console.log(error);\n })\n .finally(() => (this.waitingForInit = false));\n }\n }\n\n /**\n * Closes the Telemetry Session. After calling this method no data will be added to the Telemetry Session.\n */\n static async finish() {\n if (!this.telemeter) return;\n\n try {\n const local_telemeter = this.telemeter;\n this.telemeter = undefined;\n await local_telemeter.finish();\n } catch (e) {\n console.error(e);\n }\n }\n}\n","import Configuration from \"./configuration\";\nimport Core from \"./core.src\";\nimport EditorListener from \"./editorlistener\";\nimport Listeners from \"./listeners\";\nimport MathML from \"./mathml\";\nimport Util from \"./util\";\nimport Telemeter from \"./telemeter\";\n\nexport default class ContentManager {\n /**\n * @classdesc\n * This class represents a modal dialog, managing the following:\n * - The insertion of content into the current instance of the {@link ModalDialog} class.\n * - The actions to be done once the modal object has been submitted\n * (submitAction} method).\n * - The update of the content when the {@link ModalDialog} class is also updated,\n * for example when ModalDialog is re-opened.\n * - The communication between the {@link ModalDialog} class and itself, if the content\n * has been changed (hasChanges} method).\n * @constructs\n * @param {Object} contentManagerAttributes - Object containing all attributes needed to\n * create a new instance.\n */\n constructor(contentManagerAttributes) {\n /**\n * An object containing MathType editor parameters. See\n * http://docs.wiris.com/en/mathtype/mathtype_web/sdk-api/parameters for further information.\n * @type {Object}\n */\n this.editorAttributes = {};\n if (\"editorAttributes\" in contentManagerAttributes) {\n this.editorAttributes = contentManagerAttributes.editorAttributes;\n } else {\n throw new Error(\"ContentManager constructor error: editorAttributes property missed.\");\n }\n\n /**\n * CustomEditors instance. Contains the custom editors.\n * @type {CustomEditors}\n */\n this.customEditors = null;\n if (\"customEditors\" in contentManagerAttributes) {\n this.customEditors = contentManagerAttributes.customEditors;\n }\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @type {Object}\n * @property {String} editor - Editor name. Usually the HTML editor.\n * @property {String} mode - Save mode. Xml by default.\n * @property {String} version - Plugin version.\n */\n this.environment = {};\n if (\"environment\" in contentManagerAttributes) {\n this.environment = contentManagerAttributes.environment;\n } else {\n throw new Error(\"ContentManager constructor error: environment property missed\");\n }\n\n /**\n * ContentManager language.\n * @type {String}\n */\n this.language = \"\";\n if (\"language\" in contentManagerAttributes) {\n this.language = contentManagerAttributes.language;\n } else {\n throw new Error(\"ContentManager constructor error: language property missed\");\n }\n\n /**\n * {@link EditorListener} instance. Manages the changes inside the editor.\n * @type {EditorListener}\n */\n this.editorListener = new EditorListener();\n\n /**\n * MathType editor instance.\n * @type {JsEditor}\n */\n this.editor = null;\n\n /**\n * Navigator user agent.\n * @type {String}\n */\n this.ua = navigator.userAgent.toLowerCase();\n\n /**\n * Mobile device properties object\n * @type {DeviceProperties}\n */\n this.deviceProperties = {};\n this.deviceProperties.isAndroid = this.ua.indexOf(\"android\") > -1;\n this.deviceProperties.isIOS = ContentManager.isIOS();\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.toolbar = null;\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.dbclick = null;\n\n /**\n * Instance of the {@link ModalDialog} class associated with the current\n * {@link ContentManager} instance.\n * @type {ModalDialog}\n */\n this.modalDialogInstance = null;\n\n /**\n * ContentManager listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n /**\n * MathML associated to the ContentManager instance.\n * @type {String}\n */\n this.mathML = null;\n\n /**\n * Indicates if the edited element is a new one or not.\n * @type {Boolean}\n */\n this.isNewElement = true;\n\n /**\n * {@link IntegrationModel} instance. Needed to call wrapper methods.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n }\n\n /**\n * Adds a new listener to the current {@link ContentManager} instance.\n * @param {Object} listener - The listener to be added.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Sets an instance of {@link IntegrationModel} class to the current {@link ContentManager}\n * instance.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} instance.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link ModalDialog} instance into the current {@link ContentManager} instance.\n * @param {ModalDialog} modalDialogInstance - The {@link ModalDialog} instance\n */\n setModalDialogInstance(modalDialogInstance) {\n this.modalDialogInstance = modalDialogInstance;\n }\n\n /**\n * Inserts the content into the current {@link ModalDialog} instance updating\n * the title and inserting the JavaScript editor.\n */\n insert() {\n // Before insert the editor we update the modal object title to avoid weird render display.\n this.updateTitle(this.modalDialogInstance);\n this.insertEditor(this.modalDialogInstance);\n }\n\n /**\n * Inserts MathType editor into the {@link ModalDialog.contentContainer}. It waits until\n * editor's JavaScript is loaded.\n */\n insertEditor() {\n if (ContentManager.isEditorLoaded()) {\n this.editor = window.com.wiris.jsEditor.JsEditor.newInstance(this.editorAttributes);\n this.editor.insertInto(this.modalDialogInstance.contentContainer);\n this.editor.focus();\n\n // `editor.action(\"rtl\");` toggles the RTL mode based on the current state, it doesn't just switch to RTL.\n if (this.modalDialogInstance.rtl && !this.editor.getEditorModel().isRTL()) {\n this.editor.action(\"rtl\");\n }\n // Setting div in rtl in case of it's activated.\n if (this.editor.getEditorModel().isRTL()) {\n this.editor.element.style.direction = \"rtl\";\n }\n\n // Editor listener: this object manages the changes logic of editor.\n this.editor.getEditorModel().addEditorListener(this.editorListener);\n\n // iOS events.\n if (this.modalDialogInstance.deviceProperties.isIOS) {\n setTimeout(function () {\n // Make sure the modalDialogInstance is available when the timeout is over\n // to avoid throw errors and stop execution.\n if (this.hasOwnProperty(\"modalDialogInstance\")) this.modalDialogInstance.hideKeyboard(); // eslint-disable-line no-prototype-builtins\n }, 400);\n\n const formulaDisplayDiv = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n Util.addEvent(formulaDisplayDiv, \"focus\", this.modalDialogInstance.handleOpenedIosSoftkeyboard);\n Util.addEvent(formulaDisplayDiv, \"blur\", this.modalDialogInstance.handleClosedIosSoftkeyboard);\n }\n // Fire onLoad event. Necessary to set the MathML into the editor\n // after is loaded.\n this.listeners.fire(\"onLoad\", {});\n } else {\n setTimeout(ContentManager.prototype.insertEditor.bind(this), 100);\n }\n }\n\n /**\n * Initializes the current class by loading MathType script.\n */\n init() {\n if (!ContentManager.isEditorLoaded()) {\n this.addEditorAsExternalDependency();\n }\n }\n\n /**\n * Adds script element to the DOM to include editor externally.\n */\n addEditorAsExternalDependency() {\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n let editorUrl = Configuration.get(\"editorUrl\");\n\n // We create an object url for parse url string and work more efficiently.\n const anchorElement = document.createElement(\"a\");\n\n ContentManager.setHrefToAnchorElement(anchorElement, editorUrl);\n ContentManager.setProtocolToAnchorElement(anchorElement);\n\n editorUrl = ContentManager.getURLFromAnchorElement(anchorElement);\n\n // Load editor URL. We add stats as GET params.\n const stats = this.getEditorStats();\n script.src = `${editorUrl}?lang=${this.language}&stats-editor=${stats.editor}&stats-mode=${stats.mode}&stats-version=${stats.version}`;\n\n document.getElementsByTagName(\"head\")[0].appendChild(script);\n }\n\n /**\n * Sets the specified url to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set 'url'.\n * @param {String} url - URL to set.\n */\n static setHrefToAnchorElement(anchorElement, url) {\n anchorElement.href = url;\n }\n\n /**\n * Sets the current protocol to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set its protocol.\n */\n static setProtocolToAnchorElement(anchorElement) {\n // Change to https if necessary.\n if (window.location.href.indexOf(\"https://\") === 0) {\n // It check if browser is https and configuration is http.\n // If this is so, we will replace protocol.\n if (anchorElement.protocol === \"http:\") {\n anchorElement.protocol = \"https:\";\n }\n }\n }\n\n /**\n * Returns the url of the anchor element adding the current port\n * if it is needed.\n * @param {HTMLAnchorElement} anchorElement - Element where extract the url.\n * @returns {String}\n */\n static getURLFromAnchorElement(anchorElement) {\n // Check protocol and remove port if it's standard.\n const removePort = anchorElement.port === \"80\" || anchorElement.port === \"443\" || anchorElement.port === \"\";\n return `${anchorElement.protocol}//${anchorElement.hostname}${removePort ? \"\" : `:${anchorElement.port}`}${anchorElement.pathname.startsWith(\"/\") ? anchorElement.pathname : `/${anchorElement.pathname}`}`; // eslint-disable-line max-len\n }\n\n /**\n * Returns object with editor stats.\n *\n * @typedef {Object} EditorStatsObject\n * @property {string} editor - Editor name.\n * @property {string} mode - Current configuration for formula save mode.\n * @property {string} version - Current plugins version.\n * @returns {EditorStatsObject}\n */\n getEditorStats() {\n // Editor stats. Use environment property to set it.\n const stats = {};\n if (\"editor\" in this.environment) {\n stats.editor = this.environment.editor;\n } else {\n stats.editor = \"unknown\";\n }\n\n if (\"mode\" in this.environment) {\n stats.mode = this.environment.mode;\n } else {\n stats.mode = Configuration.get(\"saveMode\");\n }\n\n if (\"version\" in this.environment) {\n stats.version = this.environment.version;\n } else {\n stats.version = Configuration.get(\"version\");\n }\n\n return stats;\n }\n\n /**\n * Returns true if device is iOS. Otherwise, false.\n * @returns {Boolean}\n */\n static isIOS() {\n return (\n [\"iPad Simulator\", \"iPhone Simulator\", \"iPod Simulator\", \"iPad\", \"iPhone\", \"iPod\"].includes(navigator.platform) ||\n // iPad on iOS 13 detection\n (navigator.userAgent.includes(\"Mac\") && \"ontouchend\" in document)\n );\n }\n\n /**\n * Returns true if device is Mobile. Otherwise, false.\n * @returns {Boolean}\n */\n static isMobile() {\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n /**\n * Returns true if editor is loaded. Otherwise, false.\n * @returns {Boolean}\n */\n static isEditorLoaded() {\n // To know if editor JavaScript is loaded we need to wait until\n // window.com.wiris.jsEditor.JsEditor.newInstance is ready.\n return (\n window.com &&\n window.com.wiris &&\n window.com.wiris.jsEditor &&\n window.com.wiris.jsEditor.JsEditor &&\n window.com.wiris.jsEditor.JsEditor.newInstance\n );\n }\n\n /**\n * Sets the {@link ContentManager.editor} initial content.\n */\n setInitialContent() {\n if (!this.isNewElement) {\n this.setMathML(this.mathML);\n }\n }\n\n /**\n * Sets a MathML into {@link ContentManager.editor} instance.\n * @param {String} mathml - MathML string.\n * @param {Boolean} focusDisabled - If true editor don't get focus after the MathML is set.\n * False by default.\n */\n setMathML(mathml, focusDisabled) {\n // By default focus is enabled.\n if (typeof focusDisabled === \"undefined\") {\n focusDisabled = false;\n }\n // Using setMathML method is not a change produced by the user but for the API\n // so we set to false the contentChange property of editorListener.\n this.editor.setMathMLWithCallback(mathml, () => {\n this.editorListener.setWaitingForChanges(true);\n });\n\n // We need to wait a little until the callback finish.\n setTimeout(() => {\n this.editorListener.setIsContentChanged(false);\n }, 500);\n\n // In some scenarios - like closing modal object - editor mustn't be focused.\n if (!focusDisabled) {\n this.onFocus();\n }\n }\n\n /**\n * Sets the focus to the current instance of {@link ContentManager.editor}. Triggered by\n * {@link ModalDialog.focus}.\n */\n onFocus() {\n if (typeof this.editor !== \"undefined\" && this.editor != null) {\n this.editor.focus();\n\n // On WordPress integration, the focus gets lost right after setting it.\n // To fix this, we enforce another focus some milliseconds after this behaviour.\n setTimeout(() => {\n this.editor.focus();\n }, 100);\n }\n }\n\n /**\n * Updates the edition area by calling {@link IntegrationModel.updateFormula}.\n * Triggered by {@link ModalDialog.submitAction}.\n */\n submitAction() {\n if (!this.editor.isFormulaEmpty()) {\n let mathML = this.editor.getMathMLWithSemantics();\n // Add class for custom editors.\n if (this.customEditors.getActiveEditor() !== null) {\n const { toolbar } = this.customEditors.getActiveEditor();\n mathML = MathML.addCustomEditorClassAttribute(mathML, toolbar);\n } else {\n // We need - if exists - the editor name from MathML\n // class attribute.\n Object.keys(this.customEditors.editors).forEach((key) => {\n mathML = MathML.removeCustomEditorClassAttribute(mathML, key);\n });\n }\n const mathmlEntitiesEncoded = MathML.mathMLEntities(mathML);\n this.integrationModel.updateFormula(mathmlEntitiesEncoded);\n } else {\n this.integrationModel.updateFormula(null);\n }\n\n this.customEditors.disable();\n this.integrationModel.notifyWindowClosed();\n\n // Set disabled focus to prevent lost focus.\n this.setEmptyMathML();\n this.customEditors.disable();\n }\n\n /**\n * Sets an empty MathML as {@link ContentManager.editor} content.\n * This will open the MT/CT editor with the hand mode.\n * It adds dir rtl in case of it's activated.\n */\n setEmptyMathML() {\n const isMobile = this.deviceProperties.isAndroid || this.deviceProperties.isIOS;\n const isRTL = this.editor.getEditorModel().isRTL();\n\n if (isMobile || this.integrationModel.forcedHandMode) {\n // For mobile devices or forced hand mode, set an empty annotation MATHML to maintain the editor in Hand mode.\n const mathML = `[]`;\n this.setMathML(mathML, true);\n } else {\n // For non-mobile devices or not forced hand mode, set the empty MathML without an annotation.\n const mathML = ``;\n this.setMathML(mathML, true);\n }\n }\n\n /**\n * Open event. Triggered by {@link ModalDialog.open}. Does the following:\n * - Updates the {@link ContentManager.editor} content\n * (with an empty MathML or an existing formula),\n * - Updates the {@link ContentManager.editor} toolbar.\n * - Recovers the the focus.\n */\n onOpen() {\n if (this.isNewElement) {\n this.setEmptyMathML();\n } else {\n this.setMathML(this.mathML);\n }\n const toolbar = this.updateToolbar();\n this.onFocus();\n\n if (this.deviceProperties.isIOS) {\n const zoom = document.documentElement.clientWidth / window.innerWidth;\n\n if (zoom !== 1) {\n // Open editor in Keyboard mode if user use iOS, Safari and page is zoomed.\n this.setKeyboardMode();\n }\n }\n\n const trigger = this.dbclick ? \"formula\" : \"button\";\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"OPENED_MTCT_EDITOR\", {\n toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking OPENED_MTCT_EDITOR\", error);\n }\n\n Core.globalListeners.fire(\"onModalOpen\", {});\n\n if (this.integrationModel.forcedHandMode) {\n this.hideHandModeButton();\n\n // In case we have a keyboard written formula, we still want it to be opened with handMode.\n if (this.mathML && !this.mathML.includes('') && !this.isNewElement) {\n this.openHandOnKeyboardMathML(this.mathML, this.editor);\n }\n }\n }\n\n /**\n * Change Editor in keyboard mode when is loaded\n */\n setKeyboardMode() {\n const wrsEditor = document.getElementsByClassName(\"wrs_handOpen wrs_disablePalette\")[0];\n if (wrsEditor) {\n wrsEditor.classList.remove(\"wrs_handOpen\");\n wrsEditor.classList.remove(\"wrs_disablePalette\");\n } else {\n setTimeout(ContentManager.prototype.setKeyboardMode.bind(this), 100);\n }\n }\n\n /**\n * Hides the hand <-> keyboard mode switch.\n *\n * This method relies completely on the classes used on different HTML elements within the editor itself, meaning\n * any change on those classes will make this code stop working properly.\n *\n * On top of that, some of those classes are changed on runtime (for example, the one that makes some buttons change).\n * This forces us to use some delayed code (this is, a timeout) to make sure everything exists when we need it.\n * @param {*} forced (boolean) Forces the user to stay in Hand mode by hiding the keyboard mode button.\n */\n hideHandModeButton(forced = true) {\n if (this.handSwitchHidden) {\n return; // hand <-> keyboard button already hidden.\n }\n\n // \"Open hand mode\" button takes a little bit to be available.\n // This selector gets the hand <-> keyboard mode switch\n const handModeButtonSelector =\n \"div.wrs_editor.wrs_flexEditor.wrs_withHand.wrs_animated .wrs_handWrapper input[type=button]\";\n\n // If in \"forced mode\", we hide the \"keyboard button\" so the user can't can't change between hand and keyboard modes.\n // We use an observer to ensure that the button it hidden as soon as it appears.\n if (forced) {\n const mutationInstance = new MutationObserver((mutations) => {\n const handModeButton = document.querySelector(handModeButtonSelector);\n if (handModeButton) {\n handModeButton.hidden = true;\n this.handSwitchHidden = true;\n mutationInstance.disconnect();\n }\n });\n mutationInstance.observe(document.body, {\n attributes: true,\n childList: true,\n characterData: true,\n subtree: true,\n });\n }\n }\n\n /**\n * It will open any formula written in Keyboard mode with the hand mode with the default hand trace.\n *\n * @param {String} mathml The original KeyBoard MathML\n * @param {Object} editor The editor object.\n */\n async openHandOnKeyboardMathML(mathml, editor) {\n // First, as an editor requirement, we need to update the editor object with the current MathML formula.\n // Once the MathML formula is updated to the one we want to open with handMode, we will be able to proceed.\n await new Promise((resolve) => {\n editor.setMathMLWithCallback(mathml, resolve);\n });\n\n // We wait until the hand editor object exists.\n await this.waitForHand(editor);\n\n // Logic to get the hand traces and open the formula in hand mode.\n // This logic comes from the editor.\n const handEditor = editor.hand;\n editor.handTemporalMathML = editor.getMathML();\n const handCoordinates = editor.editorModel.getHandStrokes();\n handEditor.setStrokes(handCoordinates);\n handEditor.fitStrokes(true);\n editor.openHand();\n }\n\n /**\n * Waits until the hand editor object exists.\n * @param {Obect} editor The editor object.\n */\n async waitForHand(editor) {\n while (!editor.hand) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Sets the correct toolbar depending if exist other custom toolbars\n * at the same time (e.g: Chemistry).\n */\n updateToolbar() {\n this.updateTitle(this.modalDialogInstance);\n const customEditor = this.customEditors.getActiveEditor();\n\n let toolbar;\n if (customEditor) {\n toolbar = customEditor.toolbar ? customEditor.toolbar : _wrs_int_wirisProperties.toolbar;\n\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n }\n } else {\n toolbar = this.getToolbar();\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n this.customEditors.disable();\n }\n }\n\n return toolbar;\n }\n\n /**\n * Updates the current {@link ModalDialog.title}. If a {@link CustomEditors} is enabled\n * sets the custom editor title. Otherwise sets the default title.\n */\n updateTitle() {\n const customEditor = this.customEditors.getActiveEditor();\n if (customEditor) {\n this.modalDialogInstance.setTitle(customEditor.title);\n } else {\n this.modalDialogInstance.setTitle(\"MathType\");\n }\n }\n\n /**\n * Returns the editor toolbar, depending on the configuration local or server side.\n * @returns {String} - Toolbar identifier.\n */\n getToolbar() {\n let toolbar = \"general\";\n if (\"toolbar\" in this.editorAttributes) {\n ({ toolbar } = this.editorAttributes);\n }\n // TODO: Change global integration variable for integration custom toolbar.\n if (toolbar === \"general\") {\n // eslint-disable-next-line camelcase\n toolbar =\n typeof _wrs_int_wirisProperties === \"undefined\" || typeof _wrs_int_wirisProperties.toolbar === \"undefined\"\n ? \"general\"\n : _wrs_int_wirisProperties.toolbar;\n }\n\n return toolbar;\n }\n\n /**\n * Sets the current {@link ContentManager.editor} instance toolbar.\n * @param {String} toolbar - The toolbar name.\n */\n setToolbar(toolbar) {\n this.toolbar = toolbar;\n this.editor.setParams({ toolbar: this.toolbar });\n }\n\n /**\n * Sets the custom headers added on editor requests.\n * @returns {Object} headers - key value headers.\n */\n setCustomHeaders(headers) {\n let headersObj = {};\n\n // We control that we only get String or Object as the input.\n if (typeof headers === \"object\") {\n headersObj = headers;\n } else if (typeof headers === \"string\") {\n headersObj = Util.convertStringToObject(headers);\n }\n\n this.editor.setParams({ customHeaders: headersObj });\n return headersObj;\n }\n\n /**\n * Returns true if the content of the editor has been changed. The logic of the changes\n * is delegated to {@link EditorListener} class.\n * @returns {Boolean} True if the editor content has been changed. False otherwise.\n */\n hasChanges() {\n return !this.editor.isFormulaEmpty() && this.editorListener.getIsContentChanged();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined && keyboardEvent.repeat === false) {\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n // Code to detect Esc event.\n // There should be only one element with class name 'wrs_pressed' at the same time.\n let list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor3RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor2RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_select wrs_pressed\");\n if (list.length === 0) {\n this.modalDialogInstance.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.modalDialogInstance.submitButton) {\n // Focus is on OK button.\n this.editor.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.querySelector('[title=\"Manual\"]') === document.activeElement) {\n // Focus is on minimize button (_).\n this.modalDialogInstance.closeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.minimizeDiv) {\n // Focus on cancel button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n this.modalDialogInstance.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.modalDialogInstance.cancelButton) {\n // Focus is on X button.\n this.modalDialogInstance.minimizeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.closeDiv) {\n // Focus on help button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n const element = document.querySelector('[title=\"Manual\"]');\n element.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n } else {\n // There should be only one element with class name 'wrs_formulaDisplay'.\n const element = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n if (element.getAttribute(\"class\") === \"wrs_formulaDisplay wrs_focused\") {\n // Focus is on formuladisplay.\n this.modalDialogInstance.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n }\n }\n}\n","/**\n * A custom editor is MathType editor with a different\n * @typedef {Object} CustomEditor\n * @property {String} CustomEditor.name - Custom editor name.\n * @property {String} CustomEditor.toolbar - Custom editor toolbar.\n * @property {String} CustomEditor.icon - Custom editor icon.\n * @property {String} CustomEditor.confVariable - Configuration property to manage\n * the availability of the custom editor.\n * @property {String} CustomEditor.title - Custom editor modal dialog title.\n * @property {String} CustomEditor.tooltip - Custom editor icon tooltip.\n */\n\nexport default class CustomEditors {\n /**\n * @classdesc\n * This class represents the MathType custom editors manager.\n * A custom editor is MathType editor with a custom toolbar.\n * This class associates a {@link CustomEditor} to:\n * - It's own formulas\n * - A custom toolbar\n * - An icon to open it from a HTML editor.\n * - A tooltip for the icon.\n * - A global variable to enable or disable it globally.\n * @constructs\n */\n constructor() {\n /**\n * The custom editors.\n * @type {Array.}\n */\n\n this.editors = [];\n /**\n * The active editor name.\n * @type {String}\n */\n this.activeEditor = \"default\";\n }\n\n /**\n * Adds a {@link CustomEditor} to editors array.\n * @param {String} editorName - The editor name.\n * @param {CustomEditor} editorParams - The custom editor parameters.\n */\n addEditor(editorName, editorParams) {\n const customEditor = {};\n customEditor.name = editorParams.name;\n customEditor.toolbar = editorParams.toolbar;\n customEditor.icon = editorParams.icon;\n customEditor.confVariable = editorParams.confVariable;\n customEditor.title = editorParams.title;\n customEditor.tooltip = editorParams.tooltip;\n this.editors[editorName] = customEditor;\n }\n\n /**\n * Enables a {@link CustomEditor}.\n * @param {String} customEditorName - The custom editor name.\n */\n enable(customEditorName) {\n this.activeEditor = customEditorName;\n }\n\n /**\n * Disables a {@link CustomEditor}.\n */\n disable() {\n this.activeEditor = \"default\";\n }\n\n /**\n * Returns the active editor.\n * @return {CustomEditor} - A {@link CustomEditor} if a custom editor is enabled. Null otherwise.\n */\n getActiveEditor() {\n if (this.activeEditor !== \"default\") {\n return this.editors[this.activeEditor];\n }\n return null;\n }\n}\n","/**\n * Represents the configuration properties generated from the frontend (JavaScript variables).\n * @type {Object}\n * @property {string} imageClassName - Default MathType formula image class.\n * @property {string} imageClassName - Default MathType CAS image class.\n * @ignore\n */\nconst jsProperties = {\n imageCustomEditorName: \"data-custom-editor\",\n imageClassName: \"Wirisformula\",\n CASClassName: \"Wiriscas\",\n};\nexport default jsProperties;\n","export default class Event {\n /**\n * @classdesc\n * This class represents a custom event. Events should be fired by the {@link Listener} class.\n *\n * ```js\n * let customEvent = new Event();\n * customEvent.properties = {};\n *\n * let listeners = new Listeners();\n * listeners.newListener(eventName, callback);\n *\n * listeners.fire(eventName, customEvent) *\n * ```\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the event should be cancelled.\n * @type {Boolean}\n */\n\n this.cancelled = false;\n /**\n * Indicates if the event should be prevented.\n * @type {Boolean}\n */\n this.defaultPrevented = false;\n }\n\n /**\n * Cancels the event.\n */\n cancel() {\n this.cancelled = true;\n }\n\n /**\n * Prevents the default action.\n */\n preventDefault() {\n this.defaultPrevented = true;\n }\n}\n","import IntegrationModel from \"./integrationmodel\";\n\n/**\n\n */\nexport default class PopUpMessage {\n /**\n * @classdesc\n * This class represents a dialog message overlaying a DOM element in order to\n * accept / cancel discard changes. The dialog can be closed i.e the overlay disappears\n * o canceled. In this last case a callback function should be called.\n * @constructs\n * @param {Object} popupMessageAttributes - Object containing popup properties.\n * @param {HTMLElement} popupMessageAttributes.overlayElement - Element to overlay.\n * @param {Object} popupMessageAttributes.callbacks - Contains callback\n * methods for close and cancel actions.\n * @param {Object} popupMessageAttributes.strings - Contains all the strings needed.\n */\n constructor(popupMessageAttributes) {\n /**\n * Element to be overlaid when the popup appears.\n */\n this.overlayElement = popupMessageAttributes.overlayElement;\n\n this.callbacks = popupMessageAttributes.callbacks;\n\n /**\n * HTMLElement element to wrap all HTML elements inside the popupMessage.\n */\n this.overlayWrapper = this.overlayElement.appendChild(document.createElement(\"div\"));\n this.overlayWrapper.setAttribute(\"class\", \"wrs_popupmessage_overlay_envolture\");\n\n /**\n * HTMLElement to display the popup message, close button and cancel button.\n */\n this.message = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n this.message.id = \"wrs_popupmessage\";\n this.message.setAttribute(\"class\", \"wrs_popupmessage_panel\");\n this.message.setAttribute(\"role\", \"dialog\");\n this.message.setAttribute(\"aria-describedby\", \"description_txt\");\n const paragraph = document.createElement(\"p\");\n const text = document.createTextNode(popupMessageAttributes.strings.message);\n paragraph.appendChild(text);\n paragraph.id = \"description_txt\";\n this.message.appendChild(paragraph);\n\n /**\n * HTML element overlaying the overlayElement.\n */\n const overlay = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n overlay.setAttribute(\"class\", \"wrs_popupmessage_overlay\");\n // We create a overlay that close popup message on click in there\n overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n /**\n * HTML element containing cancel and close buttons.\n */\n this.buttonArea = this.message.appendChild(document.createElement(\"div\"));\n this.buttonArea.setAttribute(\"class\", \"wrs_popupmessage_button_area\");\n this.buttonArea.id = \"wrs_popup_button_area\";\n\n // Close button arguments.\n const buttonSubmitArguments = {\n class: \"wrs_button_accept\",\n innerHTML: popupMessageAttributes.strings.submitString,\n id: \"wrs_popup_accept_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-close-button\",\n };\n\n /**\n * Close button arguments.\n */\n this.closeButton = this.createButton(buttonSubmitArguments, this.closeAction.bind(this));\n this.buttonArea.appendChild(this.closeButton);\n\n // Cancel button arguments.\n const buttonCancelArguments = {\n class: \"wrs_button_cancel\",\n innerHTML: popupMessageAttributes.strings.cancelString,\n id: \"wrs_popup_cancel_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-cancel-button\",\n };\n\n /**\n * Cancel button.\n */\n this.cancelButton = this.createButton(buttonCancelArguments, this.cancelAction.bind(this));\n this.buttonArea.appendChild(this.cancelButton);\n }\n\n /**\n * This method create a button with arguments and return button dom object\n * @param {Object} parameters - An object containing id, class and innerHTML button text.\n * @param {String} parameters.id - Button id.\n * @param {String} parameters.class - Button class name.\n * @param {String} parameters.innerHTML - Button innerHTML text.\n * @param {Object} callback- Callback method to call on click event.\n * @returns {HTMLElement} HTML button.\n */\n // eslint-disable-next-line class-methods-use-this\n createButton(parameters, callback) {\n let element = {};\n element = document.createElement(\"button\");\n element.setAttribute(\"id\", parameters.id);\n element.setAttribute(\"class\", parameters.class);\n element.innerHTML = parameters.innerHTML;\n element.addEventListener(\"click\", callback);\n if (parameters[\"data-testid\"]) {\n element.setAttribute(\"data-testid\", parameters[\"data-testid\"]);\n }\n\n return element;\n }\n\n /**\n * Shows the popupmessage containing a message, and two buttons\n * to cancel the action or close the modal dialog.\n */\n show() {\n if (this.overlayWrapper.style.display !== \"block\") {\n // Clear focus with blur for prevent press any key.\n document.activeElement.blur();\n this.overlayWrapper.style.display = \"block\";\n this.closeButton.focus();\n } else {\n this.overlayWrapper.style.display = \"none\";\n // _wrs_modalWindow.focus(); This throws an error of not existing _wrs_modalWindow\n }\n }\n\n /**\n * This method cancels the popupMessage: the dialog disappears revealing the overlaid element.\n * A callback method is called (if defined). For example a method to focus the overlaid element.\n */\n cancelAction() {\n this.overlayWrapper.style.display = \"none\";\n if (typeof this.callbacks.cancelCallback !== \"undefined\") {\n this.callbacks.cancelCallback();\n // Set temporal image to null to prevent loading\n // an existent formula when starting one from scratch. Make focus come back too.\n // IntegrationModel.setActionsOnCancelButtons();\n }\n }\n\n /**\n * This method closes the popupMessage: the dialog disappears and the close callback is called.\n * For example to close the overlaid element.\n */\n closeAction() {\n this.cancelAction();\n if (typeof this.callbacks.closeCallback !== \"undefined\") {\n this.callbacks.closeCallback();\n }\n IntegrationModel.setActionsOnCancelButtons();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Code to detect Esc event.\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n this.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.closeButton) {\n this.cancelButton.focus();\n } else {\n this.closeButton.focus();\n }\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n}\n","/**\n * This module provides protection against external focus management scripts\n * that might interfere with the MathType editor modal.\n */\n\n/**\n * focusProtection function creates and returns methods to prevent external scripts from\n * interfering with the focus of the MathType modal dialog.\n *\n * @returns {Object} An object with protect and unprotect methods.\n */\nconst focusProtection = () => {\n /**\n * Initialize focus protection on the given modal element.\n *\n * @param {HTMLElement} modalElement - The modal element to protect\n * @param {HTMLElement} overlayElement - The overlay element of the modal (not used in current implementation)\n * @param {HTMLElement} editorElement - The editor element inside the modal\n */\n const protect = (modalElement, overlayElement, editorElement) => {\n if (!modalElement || !overlayElement || !editorElement) {\n console.warn(\"FocusProtection: Missing required elements\");\n return;\n }\n\n // Apply the focus protection\n overrideFocusBehavior(modalElement, editorElement);\n };\n\n /**\n * Apply focus protection by overriding focus-related methods\n *\n * @param {HTMLElement} modalElement - The modal element\n * @param {HTMLElement} editorElement - The editor element to keep focused\n * @private\n */\n const overrideFocusBehavior = (modalElement, editorElement) => {\n // Store original focus methods to be able to restore them\n const originalElementFocus = HTMLElement.prototype.focus;\n const originalElementBlur = HTMLElement.prototype.blur;\n\n // Override the focus method for all elements\n HTMLElement.prototype.focus = function (...args) {\n // If the modal is open and this is not part of the modal, prevent focus\n if (modalElement.style.display !== \"none\" && !modalElement.contains(this) && this !== document.body) {\n // If some external script is trying to focus another element, prevent it\n // and restore focus to the editor\n if (editorElement) {\n // Use the original focus method to avoid infinite recursion\n originalElementFocus.apply(editorElement, args);\n }\n return;\n }\n\n // Otherwise, allow the focus to happen\n originalElementFocus.apply(this, args);\n };\n\n // Store the methods to remove them when the modal is closed\n modalElement.originalElementFocus = originalElementFocus;\n modalElement.originalElementBlur = originalElementBlur;\n };\n\n /**\n * Remove focus protection from the modal\n *\n * @param {HTMLElement} modalElement - The modal element to unprotect\n */\n const unprotect = (modalElement) => {\n if (!modalElement) {\n return;\n }\n\n // Restore original focus methods\n if (modalElement.originalElementFocus) {\n HTMLElement.prototype.focus = modalElement.originalElementFocus;\n delete modalElement.originalElementFocus;\n }\n\n if (modalElement.originalElementBlur) {\n HTMLElement.prototype.blur = modalElement.originalElementBlur;\n delete modalElement.originalElementBlur;\n }\n };\n\n return {\n protect,\n unprotect,\n };\n};\n\nexport default focusProtection;\n","// eslint-disable-next-line max-classes-per-file\nimport PopUpMessage from \"./popupmessage\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport Listeners from \"./listeners\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Telemeter from \"./telemeter\";\nimport IntegrationModel from \"./integrationmodel\";\nimport Core from \"./core.src\";\nimport focusProtection from \"./focusprotection\";\nimport closeIcon from \"../styles/icons/general/close_icon.svg\"; //eslint-disable-line\nimport closeHoverIcon from \"../styles/icons/hover/close_icon_h.svg\"; //eslint-disable-line\nimport fullsIcon from \"../styles/icons/general/fulls_icon.svg\"; //eslint-disable-line\nimport fullsHoverIcon from \"../styles/icons/hover/fulls_icon_h.svg\"; //eslint-disable-line\nimport minIcon from \"../styles/icons/general/min_icon.svg\"; //eslint-disable-line\nimport minHoverIcon from \"../styles/icons/hover/min_icon_h.svg\"; //eslint-disable-line\nimport minsIcon from \"../styles/icons/general/mins_icon.svg\"; //eslint-disable-line\nimport minsHoverIcon from \"../styles/icons/hover/mins_icon_h.svg\"; //eslint-disable-line\nimport maxIcon from \"../styles/icons/general/max_icon.svg\"; //eslint-disable-line\nimport maxHoverIcon from \"../styles/icons/hover/max_icon_h.svg\"; //eslint-disable-line\nconst { unprotect, protect } = focusProtection();\n\n/**\n * @typedef {Object} DeviceProperties\n * @property {String} DeviceProperties.orientation - Indicates of the orientation of the device.\n * @property {Boolean} DeviceProperties.isAndroid - True if the device is Android. False otherwise.\n * @property {Boolean} DeviceProperties.isIOS - True if the device is iOS. False otherwise.\n * @property {Boolean} DeviceProperties.isMobile - True if the device is a mobile one.\n * False otherwise.\n * @property {Boolean} DeviceProperties.isDesktop - True if the device is a desktop one.\n * False otherwise.\n */\n\nexport default class ModalDialog {\n /**\n * @classdesc\n * This class represents a modal dialog. The modal dialog admits\n * a {@link ContentManager} instance to manage the content of the dialog.\n * @constructs\n * @param {Object} modalDialogAttributes - An object containing all modal dialog attributes.\n */\n constructor(modalDialogAttributes) {\n this.attributes = modalDialogAttributes;\n\n // Metrics.\n const ua = navigator.userAgent.toLowerCase();\n const isAndroid = ua.indexOf(\"android\") > -1;\n const isIOS = ContentManager.isIOS();\n this.iosSoftkeyboardOpened = false;\n this.iosMeasureUnit = ua.indexOf(\"crios\") === -1 ? \"%\" : \"vh\";\n this.iosDivHeight = `auto`;\n\n const deviceWidth = window.outerWidth;\n const deviceHeight = window.outerHeight;\n\n const landscape = deviceWidth > deviceHeight;\n const portrait = deviceWidth < deviceHeight;\n\n // TODO: Detect isMobile without using editor metrics.\n const isLandscape = landscape && this.attributes.height > deviceHeight;\n const isPortrait = portrait && this.attributes.width > deviceWidth;\n const isMobile = ContentManager.isMobile();\n\n // Obtain number of current instance.\n this.instanceId = document.getElementsByClassName(\"wrs_modal_dialogContainer\").length;\n\n // Device object properties.\n\n /**\n * @type {DeviceProperties}\n */\n this.deviceProperties = {\n orientation: landscape ? \"landscape\" : \"portrait\",\n isAndroid,\n isIOS,\n isMobile,\n isDesktop: !isMobile && !isIOS && !isAndroid,\n };\n\n this.properties = {\n created: false,\n state: \"\",\n previousState: \"\",\n position: { bottom: 0, right: 10 },\n size: { height: 338, width: 580 },\n };\n\n /**\n * Object to keep website's style before change it on lock scroll for mobile devices.\n * @type {Object}\n * @property {String} bodyStylePosition - Previous body style position.\n * @property {String} bodyStyleOverflow - Previous body style overflow.\n * @property {String} htmlStyleOverflow - Previous body style overflow.\n * @property {String} windowScrollX - Previous window's scroll Y.\n * @property {String} windowScrollY - Previous window's scroll X.\n */\n this.websiteBeforeLockParameters = null;\n\n let attributes = {};\n attributes.class = \"wrs_modal_overlay\";\n attributes.id = this.getElementId(attributes.class);\n this.overlay = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title_bar\";\n attributes.id = this.getElementId(attributes.class);\n this.titleBar = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title\";\n attributes.id = this.getElementId(attributes.class);\n this.title = Util.createElement(\"div\", attributes);\n this.title.innerHTML = \"offline\";\n\n attributes = {};\n attributes.class = \"wrs_modal_close_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"close\");\n attributes.style = {};\n this.closeDiv = Util.createElement(\"a\", attributes);\n this.closeDiv.setAttribute(\"role\", \"button\");\n this.closeDiv.setAttribute(\"tabindex\", 3);\n // Apply styles and events after the creation as createElement doesn't process them correctly\n let generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`;\n let hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`;\n this.closeDiv.setAttribute(\"style\", generalStyle);\n this.closeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.closeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identifiy the element in automated testing\n this.closeDiv.setAttribute(\"data-testid\", \"mtcteditor-close-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_stack_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"exit_fullscreen\");\n this.stackDiv = Util.createElement(\"a\", attributes);\n this.stackDiv.setAttribute(\"role\", \"button\");\n this.stackDiv.setAttribute(\"tabindex\", 2);\n generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`;\n hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`;\n this.stackDiv.setAttribute(\"style\", generalStyle);\n this.stackDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.stackDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identifiy the element in automated testing\n this.stackDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-disable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_maximize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"fullscreen\");\n this.maximizeDiv = Util.createElement(\"a\", attributes);\n this.maximizeDiv.setAttribute(\"role\", \"button\");\n this.maximizeDiv.setAttribute(\"tabindex\", 2);\n generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`;\n hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`;\n this.maximizeDiv.setAttribute(\"style\", generalStyle);\n this.maximizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.maximizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identifiy the element in automated testing\n this.maximizeDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-enable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_minimize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"minimize\");\n this.minimizeDiv = Util.createElement(\"a\", attributes);\n this.minimizeDiv.setAttribute(\"role\", \"button\");\n this.minimizeDiv.setAttribute(\"tabindex\", 1);\n generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identify the element in automated testing\n this.minimizeDiv.setAttribute(\"data-testid\", \"mtcteditor-minimize-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_dialogContainer\";\n attributes.id = this.getElementId(attributes.class);\n attributes.role = \"dialog\";\n this.container = Util.createElement(\"div\", attributes);\n this.container.setAttribute(\"aria-labeledby\", \"wrs_modal_title[0]\");\n\n attributes = {};\n attributes.class = \"wrs_modal_wrapper\";\n attributes.id = this.getElementId(attributes.class);\n this.wrapper = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_content_container\";\n attributes.id = this.getElementId(attributes.class);\n this.contentContainer = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_controls\";\n attributes.id = this.getElementId(attributes.class);\n this.controls = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_buttons_container\";\n attributes.id = this.getElementId(attributes.class);\n this.buttonContainer = Util.createElement(\"div\", attributes);\n\n // Buttons: all button must be created using createSubmitButton method.\n this.submitButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_accept\"),\n class: \"wrs_modal_button_accept\",\n innerHTML: StringManager.get(\"accept\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-insert-button\",\n },\n this.submitAction.bind(this),\n );\n\n this.cancelButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_cancel\"),\n class: \"wrs_modal_button_cancel\",\n innerHTML: StringManager.get(\"cancel\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cancel-button\",\n },\n this.cancelAction.bind(this),\n );\n\n this.contentManager = null;\n\n // Overlay popup.\n const popupStrings = {\n cancelString: StringManager.get(\"cancel\"),\n submitString: StringManager.get(\"close\"),\n message: StringManager.get(\"close_modal_warning\"),\n };\n\n const callbacks = {\n closeCallback: () => {\n this.close(\"mtc_close\");\n },\n cancelCallback: () => {\n this.focus();\n },\n };\n\n const popupupProperties = {\n overlayElement: this.container,\n callbacks,\n strings: popupStrings,\n };\n\n this.popup = new PopUpMessage(popupupProperties);\n\n /**\n * Indicates if directionality of the modal dialog is RTL. false by default.\n * @type {Boolean}\n */\n this.rtl = false;\n if (\"rtl\" in this.attributes) {\n this.rtl = this.attributes.rtl;\n }\n\n // Event handlers need modal instance context.\n this.handleOpenedIosSoftkeyboard = this.handleOpenedIosSoftkeyboard.bind(this);\n this.handleClosedIosSoftkeyboard = this.handleClosedIosSoftkeyboard.bind(this);\n }\n\n /**\n * This method sets an ContentManager instance to ModalDialog. ContentManager\n * manages the logic of ModalDialog content: submit, update, close and changes.\n * @param {ContentManager} contentManager - ContentManager instance.\n */\n setContentManager(contentManager) {\n this.contentManager = contentManager;\n }\n\n /**\n * Returns the modal contentElement object.\n * @returns {ContentManager} the instance of the ContentManager class.\n */\n getContentManager() {\n return this.contentManager;\n }\n\n /**\n * This method is called when the modal object has been submitted. Calls\n * contentElement submitAction method - if exists - and closes the modal\n * object. No logic about the content should be placed here,\n * contentElement.submitAction is the responsible of the content logic.\n */\n async submitAction() {\n if (typeof this.contentManager.submitAction !== \"undefined\") {\n this.contentManager.submitAction();\n }\n\n await this.close(\"mtc_insert\");\n }\n\n /**\n * Performs the cancel action.\n * If there are no changes in the content, it closes the modal.\n * Otherwise, it shows a pop-up message to confirm the cancel action.\n * @returns {Promise} - A promise that resolves when the modal is closed.\n */\n async cancelAction() {\n if (typeof this.contentManager.hasChanges === \"undefined\" || !this.contentManager.hasChanges()) {\n IntegrationModel.setActionsOnCancelButtons();\n await this.close(\"mtc_close\");\n } else {\n this.showPopUpMessage();\n }\n }\n\n /**\n * Returns a button element.\n * @param {Object} properties - Input button properties.\n * @param {String} properties.class - Input button class.\n * @param {String} properties.innerHTML - Input button innerHTML.\n * @param {Object} callback - Callback function associated to click event.\n * @returns {HTMLButtonElement} The button element.\n *\n */\n // eslint-disable-next-line class-methods-use-this\n createSubmitButton(properties, callback) {\n class SubmitButton {\n constructor() {\n this.element = document.createElement(\"button\");\n this.element.id = properties.id;\n this.element.className = properties.class;\n this.element.innerHTML = properties.innerHTML;\n this.element.dataset.testid = properties[\"data-testid\"];\n Util.addEvent(this.element, \"click\", callback);\n }\n\n getElement() {\n return this.element;\n }\n }\n return new SubmitButton(properties, callback).getElement();\n }\n\n /**\n * Creates the modal window object inserting a contentElement object.\n */\n create() {\n /* Modal Window Structure\n _____________________________________________________________________________________\n |wrs_modal_dialog_Container |\n | _________________________________________________________________________________ |\n | |title_bar minimize_button stack_button close_button | |\n | |_______________________________________________________________________________| |\n | |wrapper | |\n | | _____________________________________________________________________________ | |\n | | |content | | |\n | | | | | |\n | | | | | |\n | | |___________________________________________________________________________| | |\n | | _____________________________________________________________________________ | |\n | | |controls | | |\n | | | ___________________________________ | | |\n | | | |buttonContainer | | | |\n | | | | _______________________________ | | | |\n | | | | |button_accept | button_cancel| | | | |\n | | | |_|_____________ |______________|_| | | |\n | | |___________________________________________________________________________| | |\n | |_______________________________________________________________________________| |\n |___________________________________________________________________________________| */\n\n this.titleBar.appendChild(this.closeDiv);\n this.titleBar.appendChild(this.stackDiv);\n this.titleBar.appendChild(this.maximizeDiv);\n this.titleBar.appendChild(this.minimizeDiv);\n this.titleBar.appendChild(this.title);\n\n if (this.deviceProperties.isDesktop) {\n this.container.appendChild(this.titleBar);\n }\n\n this.wrapper.appendChild(this.contentContainer);\n this.wrapper.appendChild(this.controls);\n\n this.controls.appendChild(this.buttonContainer);\n\n this.buttonContainer.appendChild(this.submitButton);\n this.buttonContainer.appendChild(this.cancelButton);\n\n this.container.appendChild(this.wrapper);\n\n // Check if browser has scrollBar before modal has modified.\n this.recalculateScrollBar();\n\n document.body.appendChild(this.container);\n document.body.appendChild(this.overlay);\n\n if (this.deviceProperties.isDesktop) {\n // Desktop.\n this.createModalWindowDesktop();\n this.createResizeButtons();\n\n this.addListeners();\n // Maximize window only when the configuration is set and the device is not iOS or Android.\n if (Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n } else if (this.deviceProperties.isAndroid) {\n this.createModalWindowAndroid();\n } else if (this.deviceProperties.isIOS) {\n this.createModalWindowIos();\n }\n\n if (this.contentManager != null) {\n this.contentManager.insert(this);\n }\n\n this.properties.open = true;\n this.properties.created = true;\n\n // Checks language directionality.\n if (this.isRTL()) {\n this.container.style.right = `${window.innerWidth - this.scrollbarWidth - this.container.offsetWidth}px`;\n this.container.className += \" wrs_modal_rtl\";\n }\n }\n\n /**\n * Creates a button in the modal object to resize it.\n */\n createResizeButtons() {\n // This is a definition of Resize Button Bottom-Right.\n this.resizerBR = document.createElement(\"div\");\n this.resizerBR.className = \"wrs_bottom_right_resizer\";\n this.resizerBR.innerHTML = \"◢\";\n // To identifiy the element in automated testing\n this.resizerBR.dataset.testid = \"mtcteditor-resize-button-right\";\n // This is a definition of Resize Button Top-Left.\n this.resizerTL = document.createElement(\"div\");\n this.resizerTL.className = \"wrs_bottom_left_resizer\";\n // To identifiy the element in automated testing\n this.resizerTL.dataset.testid = \"mtcteditor-resize-button-left\";\n // Append resize buttons to modal.\n this.container.appendChild(this.resizerBR);\n this.titleBar.appendChild(this.resizerTL);\n // Add events to resize on click and drag.\n Util.addEvent(this.resizerBR, \"mousedown\", this.activateResizeStateBR.bind(this));\n Util.addEvent(this.resizerTL, \"mousedown\", this.activateResizeStateTL.bind(this));\n }\n\n /**\n * Initialize variables for Bottom-Right resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateBR(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, false);\n }\n\n /**\n * Initialize variables for Top-Left resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateTL(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, true);\n }\n\n /**\n * Common method to initialize variables at resize.\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n initializeResizeProperties(mouseEvent, leftOption) {\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n this.resizeDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Save Initial state of modal to compare on drag and obtain the difference.\n this.initialWidth = parseInt(this.container.style.width, 10);\n this.initialHeight = parseInt(this.container.style.height, 10);\n if (!leftOption) {\n this.initialRight = parseInt(this.container.style.right, 10);\n this.initialBottom = parseInt(this.container.style.bottom, 10);\n } else {\n this.leftScale = true;\n }\n if (!this.initialRight) {\n this.initialRight = 0;\n }\n if (!this.initialBottom) {\n this.initialBottom = 0;\n }\n // Disable mouse events on editor when we start to drag modal.\n document.body.style[\"user-select\"] = \"none\";\n }\n\n /**\n * This method opens the modal window, restoring the previous state, position and metrics,\n * if exists. By default the modal object opens in stack mode.\n */\n open() {\n // Removing close class.\n this.removeClass(\"wrs_closed\");\n // Hiding keyboard for mobile devices.\n const { isIOS } = this.deviceProperties;\n const { isAndroid } = this.deviceProperties;\n const { isMobile } = this.deviceProperties;\n if (isIOS || isAndroid || isMobile) {\n // Restore scale to 1.\n this.restoreWebsiteScale();\n this.lockWebsiteScroll();\n // Due to editor wait we need to wait until editor focus.\n setTimeout(() => {\n this.hideKeyboard();\n }, 400);\n }\n\n // New modal window. He need to create the whole object.\n if (!this.properties.created) {\n this.create();\n } else {\n // Previous state closed. Open method can be called even the previous state is open,\n // for example updating the content of the modal object.\n if (!this.properties.open) {\n this.properties.open = true;\n\n // Restoring the previous open state: if the modal object has been closed\n // re-open it should preserve the state and the metrics.\n if (!this.deviceProperties.isAndroid && !this.deviceProperties.isIOS) {\n this.restoreState();\n }\n }\n\n // Maximize window only when the configuration is set and the device is not iOs or Android.\n if (this.deviceProperties.isDesktop && Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n\n // In iOS we need to recalculate the size of the modal object because\n // iOS keyboard is a float div which can overlay the modal object.\n if (this.deviceProperties.isIOS) {\n this.iosSoftkeyboardOpened = false;\n }\n }\n\n if (!ContentManager.isEditorLoaded()) {\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.displayEditor();\n });\n this.contentManager.addListener(listener);\n } else {\n this.displayEditor();\n }\n }\n\n /**\n * Prepares and displays the editor in the modal.\n *\n * This method is responsible for displaying the MathType editor inside the modal container.\n *\n * For Moodle environments, it applies focus protection to prevent external scripts\n * from hijacking focus away from the editor while it's open. This is particularly\n * important in Moodle which may have its own focus management scripts.\n * @returns {void}\n */\n displayEditor() {\n if (this.contentManager.integrationModel.isMoodle) {\n protect(this.container, this.overlay, this.contentContainer);\n }\n\n // Initialize and open the editor using the contentManager.\n this.contentManager.onOpen(this);\n }\n\n /**\n * Closes the modal.\n * Removes specific CSS classes, saves modal properties, unlocks website scroll,\n * sets the 'open' property to false, and triggers the 'onModalClose' event.\n * If a close trigger is defined, it tracks the telemetry event 'CLOSED_MTCT_EDITOR' with the trigger.\n * @returns {Promise} A promise that resolves when the modal is closed.\n */\n async close(trigger) {\n // Remove focus protection before closing\n unprotect(this.container);\n\n this.removeClass(\"wrs_maximized\");\n this.removeClass(\"wrs_minimized\");\n this.removeClass(\"wrs_stack\");\n this.addClass(\"wrs_closed\");\n this.saveModalProperties();\n this.unlockWebsiteScroll();\n this.properties.open = false;\n\n if (trigger) {\n try {\n await Telemeter.telemeter.track(\"CLOSED_MTCT_EDITOR\", {\n toolbar: this.contentManager.toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking CLOSED_MTCT_EDITOR\", error);\n }\n }\n\n Core.globalListeners.fire(\"onModalClose\", {});\n }\n\n /**\n * Closes modal window and destroys the object.\n */\n destroy() {\n // Remove focus protection before destroying\n unprotect(this.container);\n\n // Close modal window.\n this.close();\n // Remove listeners and destroy the object.\n this.removeListeners();\n this.overlay.remove();\n this.container.remove();\n // Reset properties to allow open again.\n this.properties.created = false;\n }\n\n /**\n * Sets the website scale to one.\n */\n // eslint-disable-next-line class-methods-use-this\n restoreWebsiteScale() {\n let viewportmeta = document.querySelector(\"meta[name=viewport]\");\n // Let the equal symbols in order to search and make meta's final content.\n const contentAttrsToUpdate = [\"initial-scale=\", \"minimum-scale=\", \"maximum-scale=\"];\n const contentAttrsValuesToUpdate = [\"1.0\", \"1.0\", \"1.0\"];\n const setMetaAttrFunc = (viewportelement, contentAttrs) => {\n const contentAttr = viewportelement.getAttribute(\"content\");\n // If it exists, we need to maintain old values and put our values.\n if (contentAttr) {\n const attrArray = contentAttr.split(\",\");\n let finalContentMeta = \"\";\n const oldAttrs = [];\n for (let i = 0; i < attrArray.length; i += 1) {\n let isAttrToUpdate = false;\n let j = 0;\n while (!isAttrToUpdate && j < contentAttrs.length) {\n if (attrArray[i].indexOf(contentAttrs[j])) {\n isAttrToUpdate = true;\n }\n j += 1;\n }\n\n if (!isAttrToUpdate) {\n oldAttrs.push(attrArray[i]);\n }\n }\n\n for (let i = 0; i < contentAttrs.length; i += 1) {\n const attr = contentAttrs[i] + contentAttrsValuesToUpdate[i];\n finalContentMeta += i === 0 ? attr : `,${attr}`;\n }\n\n for (let i = 0; i < oldAttrs.length; i += 1) {\n finalContentMeta += `,${oldAttrs[i]}`;\n }\n viewportelement.setAttribute(\"content\", finalContentMeta);\n // It needs to set to empty because setAttribute refresh only when attribute is different.\n viewportelement.setAttribute(\"content\", \"\");\n viewportelement.setAttribute(\"content\", contentAttr);\n } else {\n viewportelement.setAttribute(\"content\", \"initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0\");\n viewportelement.removeAttribute(\"content\");\n }\n };\n\n if (!viewportmeta) {\n viewportmeta = document.createElement(\"meta\");\n document.getElementsByTagName(\"head\")[0].appendChild(viewportmeta);\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n viewportmeta.remove();\n } else {\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n }\n }\n\n /**\n * Locks website scroll for mobile devices.\n */\n lockWebsiteScroll() {\n this.websiteBeforeLockParameters = {\n bodyStylePosition: document.body.style.position ? document.body.style.position : \"\",\n bodyStyleOverflow: document.body.style.overflow ? document.body.style.overflow : \"\",\n htmlStyleOverflow: document.documentElement.style.overflow ? document.documentElement.style.overflow : \"\",\n windowScrollX: window.scrollX,\n windowScrollY: window.scrollY,\n };\n }\n\n /**\n * Unlocks website scroll for mobile devices.\n */\n unlockWebsiteScroll() {\n if (this.websiteBeforeLockParameters) {\n document.body.style.position = this.websiteBeforeLockParameters.bodyStylePosition;\n document.body.style.overflow = this.websiteBeforeLockParameters.bodyStyleOverflow;\n document.documentElement.style.overflow = this.websiteBeforeLockParameters.htmlStyleOverflow;\n const { windowScrollX } = this.websiteBeforeLockParameters;\n const { windowScrollY } = this.websiteBeforeLockParameters;\n window.scrollTo(windowScrollX, windowScrollY);\n this.websiteBeforeLockParameters = null;\n }\n }\n\n /**\n * Util function to known if browser is IE11.\n * @returns {Boolean} true if the browser is IE11. false otherwise.\n */\n // eslint-disable-next-line class-methods-use-this\n isIE11() {\n if (\n navigator.userAgent.search(\"Msie/\") >= 0 ||\n navigator.userAgent.search(\"Trident/\") >= 0 ||\n navigator.userAgent.search(\"Edge/\") >= 0\n ) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns if the current language type is RTL.\n * @return {Boolean} true if current language is RTL. false otherwise.\n */\n isRTL() {\n if (this.attributes.language === \"ar\" || this.attributes.language === \"he\") {\n return true;\n }\n return this.rtl;\n }\n\n /**\n * Adds a class to all modal ModalDialog DOM elements.\n * @param {String} className - Class name.\n */\n addClass(className) {\n Util.addClass(this.overlay, className);\n Util.addClass(this.titleBar, className);\n Util.addClass(this.overlay, className);\n Util.addClass(this.container, className);\n Util.addClass(this.contentContainer, className);\n Util.addClass(this.stackDiv, className);\n Util.addClass(this.minimizeDiv, className);\n Util.addClass(this.maximizeDiv, className);\n Util.addClass(this.wrapper, className);\n }\n\n /**\n * Remove a class from all modal DOM elements.\n * @param {String} className - Class name.\n */\n removeClass(className) {\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.titleBar, className);\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.container, className);\n Util.removeClass(this.contentContainer, className);\n Util.removeClass(this.stackDiv, className);\n Util.removeClass(this.minimizeDiv, className);\n Util.removeClass(this.maximizeDiv, className);\n Util.removeClass(this.wrapper, className);\n }\n\n /**\n * Create modal dialog for desktop.\n */\n createModalWindowDesktop() {\n this.addClass(\"wrs_modal_desktop\");\n this.stack();\n }\n\n /**\n * Create modal dialog for non android devices.\n */\n createModalWindowAndroid() {\n this.addClass(\"wrs_modal_android\");\n window.addEventListener(\"resize\", this.orientationChangeAndroidSoftkeyboard.bind(this));\n }\n\n /**\n * Create modal dialog for iOS devices.\n */\n createModalWindowIos() {\n this.addClass(\"wrs_modal_ios\");\n // Refresh the size when the orientation is changed.\n window.addEventListener(\"resize\", this.orientationChangeIosSoftkeyboard.bind(this));\n }\n\n /**\n * Restore previous state, position and size of previous stacked modal dialog.\n */\n restoreState() {\n if (this.properties.state === \"maximized\") {\n // Reset states for prevent return to stack state.\n this.maximize();\n } else if (this.properties.state === \"minimized\") {\n // Reset states for prevent return to stack state.\n this.properties.state = this.properties.previousState;\n this.properties.previousState = \"\";\n this.minimize();\n } else {\n this.stack();\n }\n }\n\n /**\n * Stacks the modal object.\n */\n stack() {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"stack\";\n this.removeClass(\"wrs_maximized\");\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n this.addClass(\"wrs_stack\");\n\n // Change maximize/minimize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n\n this.restoreModalProperties();\n\n if (typeof this.resizerBR !== \"undefined\" && typeof this.resizerTL !== \"undefined\") {\n this.setResizeButtonsVisibility();\n }\n\n // Need recalculate position of actual modal because window can was changed in fullscreenmode.\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n this.focus();\n }\n\n /**\n * Minimizes the modal object.\n */\n minimize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n this.title.style.cursor = \"pointer\";\n if (this.properties.state === \"minimized\" && this.properties.previousState === \"stack\") {\n this.stack();\n } else if (this.properties.state === \"minimized\" && this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n // Setting css to prevent important tag into css style.\n this.container.style.height = \"30px\";\n this.container.style.width = \"250px\";\n this.container.style.bottom = \"0px\";\n this.container.style.right = \"10px\";\n\n this.removeListeners();\n this.properties.previousState = this.properties.state;\n this.properties.state = \"minimized\";\n this.setResizeButtonsVisibility();\n this.minimizeDiv.title = StringManager.get(\"maximize\");\n\n if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.removeClass(\"wrs_stack\");\n } else {\n this.removeClass(\"wrs_maximized\");\n }\n this.addClass(\"wrs_minimized\");\n\n // Change minimize icon to maximize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n }\n }\n\n /**\n * Maximizes the modal object.\n */\n maximize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n if (this.properties.state !== \"maximized\") {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"maximized\";\n }\n // Don't permit resize on maximize mode.\n this.setResizeButtonsVisibility();\n\n if (Util.containsClass(this.overlay, \"wrs_minimized\")) {\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n } else if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.container.style.left = null;\n this.container.style.top = null;\n this.removeClass(\"wrs_stack\");\n }\n\n this.addClass(\"wrs_maximized\");\n\n // Change maximize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n\n // Set size to 80% screen with a max size.\n this.setSize(parseInt(window.innerHeight * 0.8, 10), parseInt(window.innerWidth * 0.8, 10));\n if (this.container.clientHeight > 700) {\n this.container.style.height = \"700px\";\n }\n if (this.container.clientWidth > 1200) {\n this.container.style.width = \"1200px\";\n }\n\n // Setting modal position in center on screen.\n const { innerHeight } = window;\n const { innerWidth } = window;\n const { offsetHeight } = this.container;\n const { offsetWidth } = this.container;\n const bottom = innerHeight / 2 - offsetHeight / 2;\n const right = innerWidth / 2 - offsetWidth / 2;\n\n this.setPosition(bottom, right);\n this.recalculateScale();\n this.recalculatePosition();\n this.recalculateSize();\n this.focus();\n }\n\n /**\n * Expand again the modal object from a minimized state.\n */\n reExpand() {\n if (this.properties.state === \"minimized\") {\n if (this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n this.stack();\n }\n this.title.style.cursor = \"\";\n }\n }\n\n /**\n * Sets modal size.\n * @param {Number} height - Height of the ModalDialog\n * @param {Number} width - Width of the ModalDialog.\n */\n setSize(height, width) {\n this.container.style.height = `${height}px`;\n this.container.style.width = `${width}px`;\n this.recalculateSize();\n }\n\n /**\n * Sets modal position using bottom and right style attributes.\n * @param {number} bottom - bottom attribute.\n * @param {number} right - right attribute.\n */\n setPosition(bottom, right) {\n this.container.style.bottom = `${bottom}px`;\n this.container.style.right = `${right}px`;\n }\n\n /**\n * Saves position and size parameters of and open ModalDialog. This attributes\n * are needed to restore it on re-open.\n */\n saveModalProperties() {\n // Saving values of modal only when modal is in stack state.\n if (this.properties.state === \"stack\") {\n this.properties.position.bottom = parseInt(this.container.style.bottom, 10);\n this.properties.position.right = parseInt(this.container.style.right, 10);\n this.properties.size.width = parseInt(this.container.style.width, 10);\n this.properties.size.height = parseInt(this.container.style.height, 10);\n }\n }\n\n /**\n * Restore ModalDialog position and size parameters.\n */\n restoreModalProperties() {\n if (this.properties.state === \"stack\") {\n // Restoring Bottom and Right values from last modal.\n this.setPosition(this.properties.position.bottom, this.properties.position.right);\n // Restoring Height and Left values from last modal.\n this.setSize(this.properties.size.height, this.properties.size.width);\n }\n }\n\n /**\n * Sets the modal dialog initial size.\n */\n recalculateSize() {\n this.contentContainer.style.height = `${parseInt(this.wrapper.offsetHeight - 50, 10)}px`;\n }\n\n /**\n * Enable or disable visibility of resize buttons in modal window depend on state.\n */\n setResizeButtonsVisibility() {\n if (this.properties.state === \"stack\") {\n this.resizerTL.style.visibility = \"visible\";\n this.resizerBR.style.visibility = \"visible\";\n } else {\n this.resizerTL.style.visibility = \"hidden\";\n this.resizerBR.style.visibility = \"hidden\";\n }\n }\n\n /**\n * Makes an object draggable adding mouse and touch events.\n */\n addListeners() {\n // Button events (maximize, minimize, stack and close).\n this.maximizeDiv.addEventListener(\"click\", this.maximize.bind(this), true);\n this.stackDiv.addEventListener(\"click\", this.stack.bind(this), true);\n this.minimizeDiv.addEventListener(\"click\", this.minimize.bind(this), true);\n this.closeDiv.addEventListener(\"click\", this.cancelAction.bind(this));\n this.maximizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n }\n },\n true,\n );\n this.stackDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.minimizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.closeDiv.addEventListener(\"keypress\", (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n });\n this.title.addEventListener(\"click\", this.reExpand.bind(this));\n\n // Overlay events (close).\n this.overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n // Mouse events.\n Util.addEvent(window, \"mousedown\", this.startDrag.bind(this));\n Util.addEvent(window, \"mouseup\", this.stopDrag.bind(this));\n Util.addEvent(window, \"mousemove\", this.drag.bind(this));\n Util.addEvent(window, \"resize\", this.onWindowResize.bind(this));\n // Key events.\n Util.addEvent(window, \"keydown\", this.onKeyDown.bind(this));\n }\n\n /**\n * Removes draggable events from an object.\n */\n removeListeners() {\n // Mouse events.\n Util.removeEvent(window, \"mousedown\", this.startDrag);\n Util.removeEvent(window, \"mouseup\", this.stopDrag);\n Util.removeEvent(window, \"mousemove\", this.drag);\n Util.removeEvent(window, \"resize\", this.onWindowResize);\n // Key events.\n Util.removeEvent(window, \"keydown\", this.onKeyDown);\n }\n\n /**\n * Returns mouse or touch coordinates (on touch events ev.ClientX doesn't exists)\n * @param {MouseEvent} mouseEvent - Mouse event.\n * @return {Object} With the X and Y coordinates.\n */\n // eslint-disable-next-line class-methods-use-this\n eventClient(mouseEvent) {\n if (typeof mouseEvent.clientX === \"undefined\" && mouseEvent.changedTouches) {\n const client = {\n X: mouseEvent.changedTouches[0].clientX,\n Y: mouseEvent.changedTouches[0].clientY,\n };\n return client;\n }\n const client = {\n X: mouseEvent.clientX,\n Y: mouseEvent.clientY,\n };\n return client;\n }\n\n /**\n * Start drag function: set the object dragDataObject with the draggable\n * object offsets coordinates.\n * when drag starts (on touchstart or mousedown events).\n * @param {MouseEvent} mouseEvent - Touchstart or mousedown event.\n */\n startDrag(mouseEvent) {\n if (this.properties.state === \"minimized\") {\n return;\n }\n if (mouseEvent.target === this.title) {\n if (typeof this.dragDataObject === \"undefined\" || this.dragDataObject === null) {\n // Save first click mouse point on screen.\n this.dragDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Reset last drag position when start drag.\n this.lastDrag = {\n x: \"0px\",\n y: \"0px\",\n };\n // Init right and bottom values for window modal if it isn't exist.\n if (this.container.style.right === \"\") {\n this.container.style.right = \"0px\";\n }\n if (this.container.style.bottom === \"\") {\n this.container.style.bottom = \"0px\";\n }\n\n // Needed for IE11 for apply disabled mouse events on editor because\n // internet explorer needs a dynamic object to apply this property.\n if (this.isIE11()) {\n // this.iframe.style['position'] = 'relative';\n }\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n // Obtain screen limits for prevent overflow.\n this.limitWindow = this.getLimitWindow();\n }\n }\n }\n\n /**\n * Updates dragDataObject with the draggable object coordinates when\n * the draggable object is being moved.\n * @param {MouseEvent} mouseEvent - The mouse event.\n */\n drag(mouseEvent) {\n if (this.dragDataObject) {\n mouseEvent.preventDefault();\n // Calculate max and min between actual mouse position and limit of screeen.\n // It restric the movement of modal into window.\n let limitY = Math.min(this.eventClient(mouseEvent).Y, this.limitWindow.minPointer.y);\n limitY = Math.max(this.limitWindow.maxPointer.y, limitY);\n let limitX = Math.min(this.eventClient(mouseEvent).X, this.limitWindow.minPointer.x);\n limitX = Math.max(this.limitWindow.maxPointer.x, limitX);\n // Subtract limit with first position to obtain relative pixels increment\n // to the anchor point.\n const dragX = `${limitX - this.dragDataObject.x}px`;\n const dragY = `${limitY - this.dragDataObject.y}px`;\n // Save last valid position of modal before window overflow.\n this.lastDrag = {\n x: dragX,\n y: dragY,\n };\n // This move modal with hardware acceleration.\n this.container.style.transform = `translate3d(${dragX},${dragY},0)`;\n }\n if (this.resizeDataObject) {\n const { innerWidth } = window;\n const { innerHeight } = window;\n let limitX = Math.min(this.eventClient(mouseEvent).X, innerWidth - this.scrollbarWidth - 7);\n let limitY = Math.min(this.eventClient(mouseEvent).Y, innerHeight - 7);\n if (limitX < 0) {\n limitX = 0;\n }\n\n if (limitY < 0) {\n limitY = 0;\n }\n\n let scaleMultiplier;\n if (this.leftScale) {\n scaleMultiplier = -1;\n } else {\n scaleMultiplier = 1;\n }\n\n this.container.style.width = `${this.initialWidth + scaleMultiplier * (limitX - this.resizeDataObject.x)}px`;\n this.container.style.height = `${this.initialHeight + scaleMultiplier * (limitY - this.resizeDataObject.y)}px`;\n if (!this.leftScale) {\n if (this.resizeDataObject.x - limitX - this.initialWidth < -580) {\n this.container.style.right = `${this.initialRight - (limitX - this.resizeDataObject.x)}px`;\n } else {\n this.container.style.right = `${this.initialRight + this.initialWidth - 580}px`;\n this.container.style.width = \"580px\";\n }\n if (this.resizeDataObject.y - limitY < this.initialHeight - 338) {\n this.container.style.bottom = `${this.initialBottom - (limitY - this.resizeDataObject.y)}px`;\n } else {\n this.container.style.bottom = `${this.initialBottom + this.initialHeight - 338}px`;\n this.container.style.height = \"338px\";\n }\n }\n this.recalculateScale();\n this.recalculatePosition();\n }\n }\n\n /**\n * Returns the boundaries of actual window to limit modal movement.\n * @return {Object} Object containing mouseX and mouseY coordinates of actual mouse on screen.\n */\n getLimitWindow() {\n // Obtain dimensions of window page.\n const maxWidth = window.innerWidth;\n const maxHeight = window.innerHeight;\n\n // Calculate relative position of mouse point into window.\n const { offsetHeight } = this.container;\n const contStyleBottom = parseInt(this.container.style.bottom, 10);\n const contStyleRight = parseInt(this.container.style.right, 10);\n\n const { pageXOffset } = window;\n const dragY = this.dragDataObject.y;\n const dragX = this.dragDataObject.x;\n\n const offSetToolbarY = offsetHeight + contStyleBottom - (maxHeight - (dragY - pageXOffset));\n const offSetToolbarX = maxWidth - this.scrollbarWidth - (dragX - pageXOffset) - contStyleRight;\n\n // Calculate limits with sizes of window, modal and mouse position.\n const minPointerY = maxHeight - this.container.offsetHeight + offSetToolbarY;\n const maxPointerY = this.title.offsetHeight - (this.title.offsetHeight - offSetToolbarY);\n const minPointerX = maxWidth - offSetToolbarX - this.scrollbarWidth;\n const maxPointerX = this.container.offsetWidth - offSetToolbarX;\n const minPointer = { x: minPointerX, y: minPointerY };\n const maxPointer = { x: maxPointerX, y: maxPointerY };\n return { minPointer, maxPointer };\n }\n\n /**\n * Returns the scrollbar width size of browser\n * @returns {Number} The scrollbar width.\n */\n // eslint-disable-next-line class-methods-use-this\n getScrollBarWidth() {\n // Create a paragraph with full width of page.\n const inner = document.createElement(\"p\");\n inner.style.width = \"100%\";\n inner.style.height = \"200px\";\n\n // Create a hidden div to compare sizes.\n const outer = document.createElement(\"div\");\n outer.style.position = \"absolute\";\n outer.style.top = \"0px\";\n outer.style.left = \"0px\";\n outer.style.visibility = \"hidden\";\n outer.style.width = \"200px\";\n outer.style.height = \"150px\";\n outer.style.overflow = \"hidden\";\n outer.appendChild(inner);\n\n document.body.appendChild(outer);\n const widthOuter = inner.offsetWidth;\n\n // Change type overflow of paragraph for measure scrollbar.\n outer.style.overflow = \"scroll\";\n let widthInner = inner.offsetWidth;\n\n // If measure is the same, we compare with internal div.\n if (widthOuter === widthInner) {\n widthInner = outer.clientWidth;\n }\n document.body.removeChild(outer);\n\n return widthOuter - widthInner;\n }\n\n /**\n * Set the dragDataObject to null.\n */\n stopDrag() {\n // Due to we have multiple events that call this function, we need only to execute\n // the next modifiers one time,\n // when the user stops to drag and dragDataObject is not null (the object to drag is attached).\n if (this.dragDataObject || this.resizeDataObject) {\n // If modal doesn't change, it's not necessary to set position with interpolation.\n this.container.style.transform = \"\";\n if (this.dragDataObject) {\n this.container.style.right = `${parseInt(this.container.style.right, 10) - parseInt(this.lastDrag.x, 10)}px`;\n this.container.style.bottom = `${parseInt(this.container.style.bottom, 10) - parseInt(this.lastDrag.y, 10)}px`;\n }\n // We make focus on editor after drag modal windows to prevent lose focus.\n this.focus();\n // Restore mouse events on iframe.\n // this.iframe.style['pointer-events'] = 'auto';\n document.body.style[\"user-select\"] = \"\";\n // Restore static state of iframe if we use Internet Explorer.\n if (this.isIE11()) {\n // this.iframe.style['position'] = null;\n }\n // Active text select event.\n Util.removeClass(document.body, \"wrs_noselect\");\n Util.removeClass(this.overlay, \"wrs_overlay_active\");\n }\n this.dragDataObject = null;\n this.resizeDataObject = null;\n this.initialWidth = null;\n this.leftScale = null;\n }\n\n /**\n * Recalculates scale for modal when resize browser window.\n */\n onWindowResize() {\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n }\n\n /**\n * Triggers keyboard events:\n * - Tab key tab to go to submit button.\n * - Esc key to close the modal dialog.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Popupmessage is not oppened.\n if (this.popup.overlayWrapper.style.display !== \"block\") {\n // Code to detect Esc event\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n if (this.properties.open) {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.cancelButton) {\n this.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.submitButton) {\n this.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n }\n } else {\n // Popupmessage oppened.\n this.popup.onKeyDown(keyboardEvent);\n }\n }\n }\n\n /**\n * Recalculating position for modal dialog when the browser is resized.\n */\n recalculatePosition() {\n this.container.style.right = `${Math.min(parseInt(this.container.style.right, 10), window.innerWidth - this.scrollbarWidth - this.container.offsetWidth)}px`;\n if (parseInt(this.container.style.right, 10) < 0) {\n this.container.style.right = \"0px\";\n }\n this.container.style.bottom = `${Math.min(parseInt(this.container.style.bottom, 10), window.innerHeight - this.container.offsetHeight)}px`;\n if (parseInt(this.container.style.bottom, 10) < 0) {\n this.container.style.bottom = \"0px\";\n }\n }\n\n /**\n * Recalculating scale for modal when the browser is resized.\n */\n recalculateScale() {\n let sizeModified = false;\n\n if (parseInt(this.container.style.width, 10) > 580) {\n this.container.style.width = `${Math.min(parseInt(this.container.style.width, 10), window.innerWidth - this.scrollbarWidth)}px`;\n sizeModified = true;\n } else {\n this.container.style.width = \"580px\";\n sizeModified = true;\n }\n\n if (parseInt(this.container.style.height, 10) > 338) {\n this.container.style.height = `${Math.min(parseInt(this.container.style.height, 10), window.innerHeight)}px`;\n sizeModified = true;\n } else {\n this.container.style.height = \"338px\";\n sizeModified = true;\n }\n\n if (sizeModified) {\n this.recalculateSize();\n }\n }\n\n /**\n * Recalculating width of browser scroll bar.\n */\n recalculateScrollBar() {\n this.hasScrollBar = window.innerWidth > document.documentElement.clientWidth;\n if (this.hasScrollBar) {\n this.scrollbarWidth = this.getScrollBarWidth();\n } else {\n this.scrollbarWidth = 0;\n }\n }\n\n /**\n * Hide soft keyboards on iOS devices.\n */\n // eslint-disable-next-line class-methods-use-this\n hideKeyboard() {\n // iOS keyboard can't be detected or hide directly from JavaScript.\n // So, this method simulates that user focus a text input and blur\n // the selection.\n const inputField = document.createElement(\"input\");\n this.container.appendChild(inputField);\n inputField.focus();\n inputField.blur();\n // Is removed to not see it.\n inputField.remove();\n }\n\n /**\n * Focus to contentManager object.\n */\n focus() {\n if (this.contentManager != null && typeof this.contentManager.onFocus !== \"undefined\") {\n this.contentManager.onFocus();\n }\n }\n\n /**\n * Returns true when the device is on portrait mode.\n */\n // eslint-disable-next-line class-methods-use-this\n portraitMode() {\n return window.innerHeight > window.innerWidth;\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is opened.\n */\n handleOpenedIosSoftkeyboard() {\n if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `auto`) {\n if (this.portraitMode()) {\n this.setContainerHeight(`60${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`35${this.iosMeasureUnit}`);\n }\n }\n this.iosSoftkeyboardOpened = true;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is closed.\n */\n handleClosedIosSoftkeyboard() {\n this.iosSoftkeyboardOpened = false;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Change container sizes when orientation is changed on iOS.\n */\n orientationChangeIosSoftkeyboard() {\n if (this.iosSoftkeyboardOpened) {\n if (this.portraitMode()) {\n this.setContainerHeight(`65${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`45${this.iosMeasureUnit}`);\n }\n } else {\n this.wrapper.style.flexGrow = \"1\";\n }\n }\n\n /**\n * Change container sizes when orientation is changed on Android.\n */\n orientationChangeAndroidSoftkeyboard() {\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Set iframe container height.\n * @param {Number} height - New height.\n */\n setContainerHeight(height) {\n this.iosDivHeight = height;\n this.wrapper.style.height = height;\n }\n\n /**\n * Check content of editor before close action.\n */\n showPopUpMessage() {\n if (this.properties.state === \"minimized\") {\n this.stack();\n }\n this.popup.show();\n }\n\n /**\n * Sets the title of the modal dialog.\n * @param {String} title - Modal dialog title.\n */\n setTitle(title) {\n this.title.innerHTML = title;\n }\n\n /**\n * Returns the id of an element, adding the instance number to\n * the element class name:\n * className --> className[idNumber]\n * @param {String} className - The element class name.\n * @returns {String} A string appending the instance id to the className.\n */\n getElementId(className) {\n return `${className}[${this.instanceId}]`;\n }\n}\n","/* eslint-disable */\nvar polyfills;\nexport default polyfills;\n\n// Polyfills.\n/*! http://mths.be/codepointat v0.1.0 by @mathias */\nif (!String.prototype.codePointAt) {\n (function () {\n \"use strict\"; // needed to support `apply`/`call` with `undefined`/`null`\n var codePointAt = function (position) {\n if (this == null) {\n throw TypeError();\n }\n var string = String(this);\n var size = string.length;\n // `ToInteger`\n var index = position ? Number(position) : 0;\n if (index != index) {\n // better `isNaN`\n index = 0;\n }\n // Account for out-of-bounds indices:\n if (index < 0 || index >= size) {\n return undefined;\n }\n // Get the first code unit\n var first = string.charCodeAt(index);\n var second;\n if (\n // check if it’s the start of a surrogate pair\n first >= 0xd800 &&\n first <= 0xdbff && // high surrogate\n size > index + 1 // there is a next code unit\n ) {\n second = string.charCodeAt(index + 1);\n if (second >= 0xdc00 && second <= 0xdfff) {\n // low surrogate\n // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000;\n }\n }\n return first;\n };\n if (Object.defineProperty) {\n Object.defineProperty(String.prototype, \"codePointAt\", {\n value: codePointAt,\n configurable: true,\n writable: true,\n });\n } else {\n String.prototype.codePointAt = codePointAt;\n }\n })();\n}\n\n// Object.assign polyfill.\nif (typeof Object.assign != \"function\") {\n // Must be writable: true, enumerable: false, configurable: true\n Object.defineProperty(Object, \"assign\", {\n value: function assign(target, varArgs) {\n // .length of function is 2\n \"use strict\";\n if (target == null) {\n // TypeError if undefined or null\n throw new TypeError(\"Cannot convert undefined or null to object\");\n }\n\n var to = Object(target);\n\n for (var index = 1; index < arguments.length; index++) {\n var nextSource = arguments[index];\n\n if (nextSource != null) {\n // Skip over if undefined or null\n for (var nextKey in nextSource) {\n // Avoid bugs when hasOwnProperty is shadowed\n if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {\n to[nextKey] = nextSource[nextKey];\n }\n }\n }\n }\n return to;\n },\n writable: true,\n configurable: true,\n });\n}\n\n// https://tc39.github.io/ecma262/#sec-array.prototype.includes\nif (!Array.prototype.includes) {\n Object.defineProperty(Array.prototype, \"includes\", {\n value: function (searchElement, fromIndex) {\n if (this == null) {\n throw new TypeError('\"this\" s null or is not defined');\n }\n\n // 1. Let O be ? ToObject(this value).\n var o = Object(this);\n\n // 2. Let len be ? ToLength(? Get(O, \"length\")).\n var len = o.length >>> 0;\n\n // 3. if len is 0, return false.\n if (len === 0) {\n return false;\n }\n\n // 4. Let n be ? ToInteger(fromIndex).\n // (if fromIndex is undefinedo, this step generates the value 0.)\n var n = fromIndex | 0;\n\n // 5. if n ≥ 0, then\n // a. Let k be n.\n // 6. Else n < 0,\n // a. Let k be len + n.\n // b. if k < 0, let k be 0.\n var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);\n\n function sameValueZero(x, y) {\n return x === y || (typeof x === \"number\" && typeof y === \"number\" && isNaN(x) && isNaN(y));\n }\n\n // 7. Repeat while k < len\n while (k < len) {\n // a. let element k be the result of ? Get(O, ! ToString(k)).\n // b. if SameValueZero(searchElement, elementK) is true, return true.\n if (sameValueZero(o[k], searchElement)) {\n return true;\n }\n // c. Increase k by 1.\n k++;\n }\n\n // 8. Return false\n return false;\n },\n });\n}\n\nif (!String.prototype.includes) {\n String.prototype.includes = function (search, start) {\n \"use strict\";\n\n if (search instanceof RegExp) {\n throw TypeError(\"first argument must not be a RegExp\");\n }\n if (start === undefined) {\n start = 0;\n }\n return this.indexOf(search, start) !== -1;\n };\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, \"startsWith\", {\n value: function (search, rawPos) {\n var pos = rawPos > 0 ? rawPos | 0 : 0;\n return this.substring(pos, pos + search.length) === search;\n },\n });\n}\n","import Parser from \"./parser\";\nimport Util from \"./util\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport CustomEditors from \"./customeditors\";\nimport Configuration from \"./configuration\";\nimport jsProperties from \"./jsvariables\";\nimport Event from \"./event\";\nimport Listeners from \"./listeners\";\nimport Image from \"./image\";\nimport ServiceProvider from \"./serviceprovider\";\nimport ModalDialog from \"./modal\";\nimport Telemeter from \"./telemeter\";\nimport \"./polyfills\";\nimport \"../styles/styles.css\";\n\n/**\n * @typedef {Object} CoreProperties\n * @property {ServiceProviderProperties} serviceProviderProperties\n * - The ServiceProvider class properties. *\n */\nexport default class Core {\n /**\n * @classdesc\n * This class represents MathType integration Core, managing the following:\n * - Integration initialization.\n * - Event managing.\n * - Insertion of formulas into the edit area.\n * ```js\n * let core = new Core();\n * core.addListener(listener);\n * core.language = 'en';\n *\n * // Initializing Core class.\n * core.init(configurationService);\n * ```\n * @constructs\n * Core constructor.\n * @param {CoreProperties}\n */\n constructor(coreProperties) {\n /**\n * Language. Needed for accessibility and locales. 'en' by default.\n * @type {String}\n */\n this.language = \"en\";\n\n /**\n * Edit mode, 'images' by default. Admits the following values:\n * - images\n * - latex\n * @type {String}\n */\n this.editMode = \"images\";\n\n /**\n * Modal dialog instance.\n * @type {ModalDialog}\n */\n this.modalDialog = null;\n\n /**\n * The instance of {@link CustomEditors}. By default\n * the only custom editor is the Chemistry editor.\n * @type {CustomEditors}\n */\n this.customEditors = new CustomEditors();\n\n /**\n * Chemistry editor.\n * @type {CustomEditor}\n */\n const chemEditorParams = {\n name: \"Chemistry\",\n toolbar: \"chemistry\",\n icon: \"chem.png\",\n confVariable: \"chemEnabled\",\n title: \"ChemType\",\n tooltip: \"Insert a chemistry formula - ChemType\", // TODO: Localize tooltip.\n };\n\n this.customEditors.addEditor(\"chemistry\", chemEditorParams);\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @typedef IntegrationEnvironment\n * @property {String} IntegrationEnvironment.editor - Editor name. For example the HTML editor.\n * @property {String} IntegrationEnvironment.mode - Integration save mode.\n * @property {String} IntegrationEnvironment.version - Integration version.\n *\n */\n\n /**\n * The environment properties object.\n * @type {IntegrationEnvironment}\n */\n this.environment = {};\n\n /**\n * @typedef EditionProperties\n * @property {Boolean} editionProperties.isNewElement - True if the formula is a new one.\n * False otherwise.\n * @property {HTMLImageElement} editionProperties.temporalImage- The image element.\n * Null if the formula is new.\n * @property {Range} editionProperties.latexRange - Tha range that contains the LaTeX formula.\n * @property {Range} editionProperties.range - The range that contains the image element.\n * @property {String} editionProperties.editMode - The edition mode. 'images' by default.\n */\n\n /**\n * The properties of the current edition process.\n * @type {EditionProperties}\n */\n this.editionProperties = {};\n\n this.editionProperties.isNewElement = true;\n this.editionProperties.temporalImage = null;\n this.editionProperties.latexRange = null;\n this.editionProperties.range = null;\n this.editionProperties.editionStartTime = null;\n\n /**\n * The {@link IntegrationModel} instance.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n\n /**\n * The {@link ContentManager} instance.\n * @type {ContentManager}\n */\n this.contentManager = null;\n\n /**\n * The current browser.\n * @type {String}\n */\n this.browser = (() => {\n const ua = navigator.userAgent;\n let browser = \"none\";\n if (ua.search(\"Edge/\") >= 0) {\n browser = \"EDGE\";\n } else if (ua.search(\"Chrome/\") >= 0) {\n browser = \"CHROME\";\n } else if (ua.search(\"Trident/\") >= 0) {\n browser = \"IE\";\n } else if (ua.search(\"Firefox/\") >= 0) {\n browser = \"FIREFOX\";\n } else if (ua.search(\"Safari/\") >= 0) {\n browser = \"SAFARI\";\n }\n return browser;\n })();\n\n /**\n * Plugin listeners.\n * @type {Array.}\n */\n this.listeners = new Listeners();\n\n /**\n * Service provider properties.\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = {};\n if (\"serviceProviderProperties\" in coreProperties) {\n this.serviceProviderProperties = coreProperties.serviceProviderProperties;\n } else {\n throw new Error(\"serviceProviderProperties property missing.\");\n }\n }\n\n /**\n * Static property.\n * Core listeners.\n * @private\n * @type {Listeners}\n */\n static get globalListeners() {\n return Core._globalListeners;\n }\n\n /**\n * Static property setter.\n * Set core listeners.\n * @param {Listeners} value - The property value.\n * @ignore\n */\n static set globalListeners(value) {\n Core._globalListeners = value;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * True when Core.init was called. Otherwise, false.\n * @private\n * @type {Boolean}\n */\n static get initialized() {\n return Core._initialized;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * @param {Boolean} value - True to say that Core.init was called. Otherwise, false.\n * @ignore\n */\n static set initialized(value) {\n Core._initialized = value;\n }\n\n /**\n * Sets the {@link Core.integrationModel} property.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} property.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link Core.environment} property.\n * @param {IntegrationEnvironment} integrationEnvironment -\n * The {@link IntegrationEnvironment} object.\n */\n setEnvironment(integrationEnvironment) {\n if (\"editor\" in integrationEnvironment) {\n this.environment.editor = integrationEnvironment.editor;\n }\n if (\"mode\" in integrationEnvironment) {\n this.environment.mode = integrationEnvironment.mode;\n }\n if (\"version\" in integrationEnvironment) {\n this.environment.version = integrationEnvironment.version;\n }\n }\n\n /**\n * Sets the custom headers added on editor requests if contentManager isn't undefined.\n * @returns {Object} headers - key value headers.\n */\n setHeaders(headers) {\n const headerObject = this?.contentManager?.setCustomHeaders(headers) || headers;\n Configuration.set(\"customHeaders\", headerObject);\n }\n\n /**\n * Returns the current {@link ModalDialog} instance.\n * @returns {ModalDialog} The current {@link ModalDialog} instance.\n */\n getModalDialog() {\n return this.modalDialog;\n }\n\n /**\n * Inits the {@link Core} class, doing the following:\n * - Calls asynchronously configuration service, retrieving the backend configuration in a JSON.\n * - Updates {@link Configuration} class with the previous configuration properties.\n * - Updates the {@link ServiceProvider} class using the configuration service path as reference.\n * - Loads language strings.\n * - Fires onLoad event.\n * @param {Object} serviceParameters - Service parameters.\n */\n init() {\n if (!Core.initialized) {\n const serviceProviderListener = Listeners.newListener(\"onInit\", () => {\n const jsConfiguration = ServiceProvider.getService(\"configurationjs\", \"\", \"get\");\n const jsonConfiguration = JSON.parse(jsConfiguration);\n Configuration.addConfiguration(jsonConfiguration);\n // Adding JavaScript (not backend) configuration variables.\n Configuration.addConfiguration(jsProperties);\n // Fire 'onLoad' event:\n // All integration must listen this event in order to know if the plugin\n // has been properly loaded.\n StringManager.language = this.language;\n this.listeners.fire(\"onLoad\", {});\n });\n\n ServiceProvider.addListener(serviceProviderListener);\n ServiceProvider.init(this.serviceProviderProperties);\n\n Core.initialized = true;\n } else {\n // Case when there are more than two editor instances.\n // After the first editor all the other editors don't need to load any file or service.\n this.listeners.fire(\"onLoad\", {});\n }\n }\n\n /**\n * Adds a {@link Listener} to the current instance of the {@link Core} class.\n * @param {Listener} listener - The listener object.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Adds the global {@link Listener} instance to {@link Core} class.\n * @param {Listener} listener - The event listener to be added.\n * @static\n */\n static addGlobalListener(listener) {\n Core.globalListeners.add(listener);\n }\n\n beforeUpdateFormula(mathml, wirisProperties) {\n /**\n * This event is fired before updating the formula.\n * @type {Object}\n * @property {String} mathml - MathML to be transformed.\n * @property {String} editMode - Edit mode.\n * @property {Object} wirisProperties - Extra attributes for the formula.\n * @property {String} language - Formula language.\n */\n const beforeUpdateEvent = new Event();\n\n beforeUpdateEvent.mathml = mathml;\n\n // Cloning wirisProperties object\n // We don't want wirisProperties object modified.\n beforeUpdateEvent.wirisProperties = {};\n\n if (wirisProperties != null) {\n Object.keys(wirisProperties).forEach((attr) => {\n beforeUpdateEvent.wirisProperties[attr] = wirisProperties[attr];\n });\n }\n\n // Read only.\n beforeUpdateEvent.language = this.language;\n beforeUpdateEvent.editMode = this.editMode;\n\n if (this.listeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n return {\n mathml: beforeUpdateEvent.mathml,\n wirisProperties: beforeUpdateEvent.wirisProperties,\n };\n }\n\n /**\n * Converts a MathML into it's correspondent image and inserts the image is\n * inserted in a HTMLElement target by creating\n * a new image or updating an existing one.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the insertion.\n * @param {Window} windowTarget - The window element where the editable content is.\n * @param {String} mathml - The MathML.\n * @param {Array.} wirisProperties - The extra attributes for the formula.\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n /**\n * It is the object with the information of the node or latex to insert.\n * @typedef ReturnObject\n * @property {Node} [node] - The DOM node to insert.\n * @property {String} [latex] - The latex to insert.\n */\n const returnObject = {};\n\n if (!mathml) {\n this.insertElementOnSelection(null, focusElement, windowTarget);\n } else if (this.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n // this.integrationModel.getNonLatexNode is an integration wrapper\n // to have special behaviours for nonLatex.\n // Not all the integrations have special behaviours for nonLatex.\n if (!!this.integrationModel.fillNonLatexNode && !returnObject.latex) {\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.latex = returnObject.latex;\n this.integrationModel.fillNonLatexNode(afterUpdateEvent, windowTarget, mathml);\n } else {\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n }\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n } else {\n returnObject.node = Parser.mathmlToImgObject(windowTarget.document, mathml, wirisProperties, this.language);\n\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n }\n\n return returnObject;\n }\n\n afterUpdateFormula(focusElement, windowTarget, node, latex) {\n /**\n * This event is fired after update the formula.\n * @type {Event}\n * @param {String} editMode - edit mode.\n * @param {Object} windowTarget - target window.\n * @param {Object} focusElement - target element to be focused after update.\n * @param {String} latex - LaTeX generated by the formula (editMode=latex).\n * @param {Object} node - node generated after update the formula (text if LaTeX img otherwise).\n */\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.node = node;\n afterUpdateEvent.latex = latex;\n\n if (this.listeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n return {};\n }\n\n /**\n * Sets the caret after a given Node and set the focus to the owner document.\n * @param {Node} node - The Node element.\n */\n placeCaretAfterNode(node) {\n if (node === null) return;\n\n this.integrationModel.getSelection();\n const nodeDocument = node.ownerDocument;\n if (typeof nodeDocument.getSelection !== \"undefined\" && !!node.parentElement) {\n const range = nodeDocument.createRange();\n range.setStartAfter(node);\n range.collapse(true);\n const selection = nodeDocument.getSelection();\n selection.removeAllRanges();\n selection.addRange(range);\n nodeDocument.body.focus();\n }\n }\n\n /**\n * Replaces a Selection object with an HTMLElement.\n * @param {HTMLElement} element - The HTMLElement to replace the selection.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the replace.\n * @param {Window} windowTarget - The window target.\n */\n insertElementOnSelection(element, focusElement, windowTarget) {\n let mathmlOrigin = null;\n if (this.editionProperties.isNewElement) {\n if (element) {\n if (focusElement.type === \"textarea\") {\n Util.updateTextArea(focusElement, element.textContent);\n } else if (document.selection && document.getSelection === 0) {\n let range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n\n if (!(\"parentElement\" in range)) {\n windowTarget.document.execCommand(\"delete\", false);\n range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n }\n\n if (\"parentElement\" in range) {\n const temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() === \"IMG\") {\n temporalObject.parentNode.replaceChild(element, temporalObject);\n } else {\n // IE9 fix: parentNode() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML(Util.createObjectCode(element));\n }\n }\n } else {\n let range = null;\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n if (this.editionProperties.range) {\n ({ range } = this.editionProperties);\n this.editionProperties.range = null;\n } else {\n const editorSelection = this.integrationModel.getSelection();\n range = editorSelection.getRangeAt(0);\n }\n\n // Delete if something was surrounded.\n range.deleteContents();\n\n let node = range.startContainer;\n const position = range.startOffset;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n node = node.splitText(position);\n node.parentNode.insertBefore(element, node);\n } else if (node.nodeType === 1) {\n // ELEMENT_NODE.\n node.insertBefore(element, node.childNodes[position]);\n }\n\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n focusElement.focus();\n } else {\n const editorSelection = this.integrationModel.getSelection();\n editorSelection.removeAllRanges();\n\n if (this.editionProperties.range) {\n const { range } = this.editionProperties;\n this.editionProperties.range = null;\n editorSelection.addRange(range);\n }\n }\n } else if (this.editionProperties.latexRange) {\n if (document.selection && document.getSelection === 0) {\n this.editionProperties.isNewElement = true;\n this.editionProperties.latexRange.select();\n this.insertElementOnSelection(element, focusElement, windowTarget);\n } else {\n this.editionProperties.latexRange.deleteContents();\n this.editionProperties.latexRange.insertNode(element);\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n let item;\n // Wrapper for some integrations that can have special behaviours to show latex.\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n item = this.integrationModel.getSelectedItem(focusElement, false);\n } else {\n item = Util.getSelectedItemOnTextarea(focusElement);\n }\n Util.updateExistingTextOnTextarea(focusElement, element.textContent, item.startPosition, item.endPosition);\n } else {\n mathmlOrigin = this.editionProperties.temporalImage?.dataset.mathml;\n if (element && element.nodeName.toLowerCase() === \"img\") {\n // Editor empty, formula has been erased on edit.\n // There are editors (e.g: CKEditor) that put attributes in images.\n // We don't allow that behaviour in our images.\n Image.removeImgDataAttributes(this.editionProperties.temporalImage);\n // Clone is needed to maintain event references to temporalImage.\n Image.clone(element, this.editionProperties.temporalImage);\n } else {\n this.editionProperties.temporalImage.remove();\n }\n this.placeCaretAfterNode(this.editionProperties.temporalImage);\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const mathml = element?.dataset?.mathml;\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove the desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n }\n\n /**\n * Opens a modal dialog containing MathType editor..\n * @param {HTMLElement} target - The target HTMLElement where formulas should be inserted.\n * @param {Boolean} isIframe - True if the target HTMLElement is an iframe. False otherwise.\n */\n openModalDialog(target, isIframe) {\n // Count the time since the editor is open\n this.editionProperties.editionStartTime = Date.now();\n\n // Textarea elements don't have normal document ranges. It only accepts latex edit.\n this.editMode = \"images\";\n\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n try {\n if (isIframe) {\n // Is needed focus the target first.\n target.contentWindow.focus();\n const selection = target.contentWindow.getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n } else {\n // Is needed focus the target first.\n target.focus();\n const selection = getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n }\n } catch (e) {\n this.editionProperties.range = null;\n }\n\n if (isIframe === undefined) {\n isIframe = true;\n }\n\n this.editionProperties.latexRange = null;\n\n if (target) {\n let selectedItem;\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n selectedItem = this.integrationModel.getSelectedItem(target, isIframe);\n } else {\n selectedItem = Util.getSelectedItem(target, isIframe);\n }\n\n // Check LaTeX if and only if the node is a text node (nodeType==3).\n if (selectedItem) {\n // Case when image was selected and button pressed.\n if (!selectedItem.caretPosition && Util.containsClass(selectedItem.node, Configuration.get(\"imageClassName\"))) {\n this.editionProperties.temporalImage = selectedItem.node;\n this.editionProperties.isNewElement = false;\n } else if (selectedItem.node.nodeType === 3) {\n // If it's a text node means that editor is working with LaTeX.\n if (this.integrationModel.getMathmlFromTextNode) {\n // If integration has this function it isn't set range due to we don't\n // know if it will be put into a textarea as a text or image.\n const mathml = this.integrationModel.getMathmlFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (mathml) {\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n }\n } else {\n const latexResult = Latex.getLatexFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (latexResult) {\n const mathml = Latex.getMathMLFromLatex(latexResult.latex);\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n const windowTarget = isIframe ? target.contentWindow : window;\n\n if (target.tagName.toLowerCase() !== \"textarea\") {\n if (document.selection) {\n let leftOffset = 0;\n let previousNode = latexResult.startNode.previousSibling;\n\n while (previousNode) {\n leftOffset += Util.getNodeLength(previousNode);\n previousNode = previousNode.previousSibling;\n }\n\n this.editionProperties.latexRange = windowTarget.document.selection.createRange();\n this.editionProperties.latexRange.moveToElementText(latexResult.startNode.parentNode);\n this.editionProperties.latexRange.move(\"character\", leftOffset + latexResult.startPosition);\n this.editionProperties.latexRange.moveEnd(\"character\", latexResult.latex.length + 4); // Plus 4 for the '$$' characters.\n } else {\n this.editionProperties.latexRange = windowTarget.document.createRange();\n this.editionProperties.latexRange.setStart(latexResult.startNode, latexResult.startPosition);\n this.editionProperties.latexRange.setEnd(latexResult.endNode, latexResult.endPosition);\n }\n }\n }\n }\n }\n } else if (target.tagName.toLowerCase() === \"textarea\") {\n // By default editMode is 'images', but when target is a textarea it needs to be 'latex'.\n this.editMode = \"latex\";\n }\n }\n\n // Setting an object with the editor parameters.\n // Editor parameters can be customized in several ways:\n // 1 - editorAttributes: Contains the default editor attributes,\n // usually the metrics in a comma separated string. Always exists.\n // 2 - editorParameters: Object containing custom editor parameters.\n // These parameters are defined in the backend. So they affects all integration instances.\n\n // The backend send the default editor attributes in a coma separated\n // with the following structure: key1=value1,key2=value2...\n const defaultEditorAttributesArray = Configuration.get(\"editorAttributes\").split(\", \");\n const defaultEditorAttributes = {};\n for (let i = 0, len = defaultEditorAttributesArray.length; i < len; i += 1) {\n const tempAttribute = defaultEditorAttributesArray[i].split(\"=\");\n const key = tempAttribute[0];\n const value = tempAttribute[1];\n defaultEditorAttributes[key] = value;\n }\n // Custom editor parameters.\n const editorAttributes = {\n language: this.language, // Default language value\n };\n // Editor parameters in backend, usually configuration.ini.\n const serverEditorParameters = Configuration.get(\"editorParameters\");\n // Editor parameters through JavaScript configuration.\n const clientEditorParameters = this.integrationModel.editorParameters;\n Object.assign(editorAttributes, defaultEditorAttributes, serverEditorParameters);\n Object.assign(editorAttributes, defaultEditorAttributes, clientEditorParameters);\n\n // Now, update backwards: if user has set a custom language, pass that back to core properties\n this.language = editorAttributes.language;\n StringManager.language = this.language;\n\n editorAttributes.rtl = this.integrationModel.rtl;\n\n const customHeaders = Configuration.get(\"customHeaders\");\n // This is not being used in the code, we are keeping it just in case it's needed.\n // We check if it is a string since we have a setter that will make the customHeaders an object. And we do the conversion for the case when we get the headers from the backend.\n editorAttributes.customHeaders =\n typeof customHeaders === \"string\" ? Util.convertStringToObject(customHeaders) : customHeaders;\n\n const contentManagerAttributes = {};\n contentManagerAttributes.editorAttributes = editorAttributes;\n contentManagerAttributes.language = this.language;\n contentManagerAttributes.customEditors = this.customEditors;\n contentManagerAttributes.environment = this.environment;\n\n if (this.modalDialog == null) {\n this.modalDialog = new ModalDialog(editorAttributes);\n this.contentManager = new ContentManager(contentManagerAttributes);\n // When an instance of ContentManager is created we need to wait until\n // the ContentManager is ready by listening 'onLoad' event.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n });\n this.contentManager.addListener(listener);\n this.contentManager.init();\n this.modalDialog.setContentManager(this.contentManager);\n this.contentManager.setModalDialogInstance(this.modalDialog);\n } else {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n }\n this.contentManager.setIntegrationModel(this.integrationModel);\n this.modalDialog.open();\n }\n\n /**\n * Returns the {@link CustomEditors} instance.\n * @return {CustomEditors} The current {@link CustomEditors} instance.\n */\n getCustomEditors() {\n return this.customEditors;\n }\n}\n\n/**\n * Core static listeners.\n * @type {Listeners}\n * @private\n */\nCore._globalListeners = new Listeners();\n\n/**\n * Resources state. Says if they were loaded or not.\n * @type {Boolean}\n * @private\n */\nCore._initialized = false;\n","// eslint-disable-next-line no-unused-vars, import/named\nimport Core from \"./core.src\";\nimport Image from \"./image\";\nimport Listeners from \"./listeners\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Telemeter from \"./telemeter\";\nimport warnIcon from \"../styles/icons/general/warn_icon.svg\"; //eslint-disable-line\n\n/**\n * @typedef {Object} IntegrationModelProperties\n * @property {string} configurationService - Configuration service path.\n * This parameter is needed to determine all services paths.\n * @property {HTMLElement} integrationModelProperties.target - HTML target.\n * @property {string} integrationModelProperties.scriptName - Integration script name.\n * Usually the name of the integration script.\n * @property {Object} integrationModelProperties.environment - integration environment properties.\n * @property {Object} [integrationModelProperties.callbackMethodArguments] - object containing\n * callback method arguments.\n * @property {string} [integrationModelProperties.version] - integration version number.\n * @property {Object} [integrationModelProperties.editorObject] - object containing\n * the integration editor instance.\n * @property {boolean} [integrationModelProperties.rtl] - true if the editor is in RTL mode.\n * false otherwise.\n * @property {ServiceProviderProperties} [integrationModelProperties.serviceProviderProperties]\n * - The service parameters.\n * @property {Object} [integrationModelProperties.integrationParameters]\n * - Overwritten integration parameters.\n */\n\nexport default class IntegrationModel {\n /**\n * @classdesc\n * This class represents an integration model, allowing the integration script to\n * communicate with Core class. Each integration must extend this class.\n * @constructs\n * @param {IntegrationModelProperties} integrationModelProperties\n */\n constructor(integrationModelProperties) {\n /**\n * Language. Needed for accessibility and locales. English by default.\n */\n this.language = \"en\";\n\n /**\n * Service parameters\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = integrationModelProperties.serviceProviderProperties ?? {};\n\n /**\n * Configuration service path. The integration service is needed by Core class to\n * load all the backend configuration into the frontend and also to create the paths\n * of all services (all services lives in the same route). Mandatory property.\n */\n this.configurationService = \"\";\n if (\"configurationService\" in integrationModelProperties) {\n this.serviceProviderProperties.URI = integrationModelProperties.configurationService;\n console.warn(\"Deprecated property configurationService. Use serviceParameters on instead.\", [\n integrationModelProperties.configurationService,\n ]);\n }\n\n /**\n * Plugin version. Needed to stats and caching.\n * @type {string}\n */\n this.version = \"version\" in integrationModelProperties ? integrationModelProperties.version : \"\";\n\n /**\n * DOM target in which the plugin works. Needed to associate events, insert formulas, etc.\n * Mandatory property.\n */\n this.target = null;\n if (\"target\" in integrationModelProperties) {\n this.target = integrationModelProperties.target;\n } else {\n throw new Error(\"IntegrationModel constructor error: target property missed.\");\n }\n\n /**\n * Integration script name. Needed to know the plugin path.\n */\n if (\"scriptName\" in integrationModelProperties) {\n this.scriptName = integrationModelProperties.scriptName;\n }\n\n /**\n * Object containing the arguments needed by the callback function.\n */\n this.callbackMethodArguments = integrationModelProperties.callbackMethodArguments ?? {};\n\n /**\n * Contains information about the integration environment:\n * like the name of the editor, the version, etc.\n */\n this.environment = integrationModelProperties.environment ?? {};\n\n /**\n * Indicates if the DOM target is - or not - and iframe.\n */\n this.isIframe = false;\n if (this.target != null) {\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Instance of the integration editor object. Usually the entry point to access the API\n * of a HTML editor.\n */\n this.editorObject = integrationModelProperties.editorObject ?? null;\n\n /**\n * Specifies if the direction of the text is RTL. false by default.\n */\n this.rtl = integrationModelProperties.rtl ?? false;\n\n /**\n * Specifies if the integration model exposes the locale strings. false by default.\n */\n this.managesLanguage = integrationModelProperties.managesLanguage ?? false;\n\n /**\n * Specify if editor will open in hand mode only\n */\n this.forcedHandMode = integrationModelProperties?.integrationParameters?.forcedHandMode ?? false;\n\n /**\n * Indicates if an image is selected. Needed to resize the image to the original size in case\n * the image is resized.\n * @type {boolean}\n */\n this.temporalImageResizing = false;\n\n /**\n * The Core class instance associated to the integration model.\n * @type {Core}\n */\n this.core = null;\n\n /**\n * Integration model listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n // Parameters overwrite.\n if (\"integrationParameters\" in integrationModelProperties) {\n IntegrationModel.integrationParameters.forEach((parameter) => {\n if (parameter in integrationModelProperties.integrationParameters) {\n // Don't add empty parameters.\n const value = integrationModelProperties.integrationParameters[parameter];\n if (Object.keys(value).length !== 0) {\n this[parameter] = value;\n }\n }\n });\n }\n }\n\n /**\n * Init function. Usually called from the integration side once the core.js file is loaded.\n */\n init() {\n // Check if language is an object and select the property necessary\n this.language = this.getLanguage();\n\n // We need to wait until Core class is loaded ('onLoad' event) before\n // call the callback method.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.callbackFunction(this.callbackMethodArguments);\n });\n\n // Backwards compatibility.\n if (this.serviceProviderProperties.URI.indexOf(\"configuration\") !== -1) {\n const uri = this.serviceProviderProperties.URI;\n const server = ServiceProvider.getServerLanguageFromService(uri);\n this.serviceProviderProperties.server = server;\n const configurationIndex = this.serviceProviderProperties.URI.indexOf(\"configuration\");\n const subsTring = this.serviceProviderProperties.URI.substring(0, configurationIndex);\n this.serviceProviderProperties.URI = subsTring;\n }\n\n let serviceParametersURI = this.serviceProviderProperties.URI;\n serviceParametersURI =\n serviceParametersURI.indexOf(\"/\") === 0 || serviceParametersURI.indexOf(\"http\") === 0\n ? serviceParametersURI\n : Util.concatenateUrl(this.getPath(), serviceParametersURI);\n\n this.serviceProviderProperties.URI = serviceParametersURI;\n\n const coreProperties = {};\n coreProperties.serviceProviderProperties = this.serviceProviderProperties;\n\n this.setCore(new Core(coreProperties));\n this.core.addListener(listener);\n this.core.language = this.language;\n\n // Initializing Core class.\n this.core.init();\n // TODO: Move to Core constructor.\n this.core.setEnvironment(this.environment);\n\n // No internet connection modal.\n let attributes = {};\n attributes.class = attributes.id = \"wrs_modal_offline\";\n this.offlineModal = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_content_offline\";\n this.offlineModalContent = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_close\";\n this.offlineModalClose = Util.createElement(\"span\", attributes);\n this.offlineModalClose.innerHTML = \"×\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_warn\";\n this.offlineModalWarn = Util.createElement(\"span\", attributes);\n const generalStyle = `background-image: url(data:image/svg+xml;base64,${window.btoa(warnIcon)})`;\n this.offlineModalWarn.setAttribute(\"style\", generalStyle);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_container\";\n this.offlineModalMessage = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_warn\";\n this.offlineModalMessage1 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage1.innerHTML = \"You are not online!\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text\";\n this.offlineModalMessage2 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage2.innerHTML = `Thank you for using MathType. We have detected you are disconnected from the network. We remind you that you'll need to be connected to use MathType.

Please refresh the page if this message continues appearing.`;\n\n // Append offline modal elements\n this.offlineModalContent.appendChild(this.offlineModalClose);\n this.offlineModalMessage.appendChild(this.offlineModalMessage1);\n this.offlineModalMessage.appendChild(this.offlineModalMessage2);\n this.offlineModalContent.appendChild(this.offlineModalMessage);\n this.offlineModalContent.appendChild(this.offlineModalWarn);\n this.offlineModal.appendChild(this.offlineModalContent);\n document.body.appendChild(this.offlineModal);\n\n const modal = document.getElementById(\"wrs_modal_offline\");\n this.offlineModalClose.addEventListener(\"click\", () => {\n modal.style.display = \"none\";\n });\n\n // Store editor name for telemetry purposes.\n let editorName = this.environment.editor;\n editorName = editorName.slice(0, -1); // Remove version number from editors\n if (editorName.includes(\"TinyMCE\")) editorName = \"TinyMCE\"; // Remove version from Tinymce editor.\n if (editorName.includes(\"Generic\")) editorName = \"Generic\"; // Remove version from Generic editor.\n let solutionTelemeter = editorName;\n\n // If moodle, add information to hosts and solution.\n const isMoodle = !!(typeof M === \"object\" && M !== null);\n let lms;\n\n if (isMoodle) {\n solutionTelemeter = \"Moodle\";\n lms = {\n nam: \"moodle\",\n fam: \"lms\",\n ver: this.environment.moodleVersion,\n category: this.environment.moodleCourseCategory,\n course: this.environment.moodleCourseName,\n };\n if (!editorName.includes(\"TinyMCE\")) {\n editorName = \"Atto\";\n }\n }\n\n // Get the OS and its version.\n const OSData = this.getOS();\n\n // Get the broswer and its version.\n const broswerData = this.getBrowser();\n\n // Create list of hosts to send to telemetry.\n let hosts = [\n {\n nam: broswerData.detectedBrowser,\n fam: \"browser\",\n ver: broswerData.versionBrowser,\n },\n {\n nam: editorName.toLowerCase(),\n fam: \"html-editor\",\n ver: this.environment.editorVersion,\n },\n {\n nam: OSData.detectedOS,\n fam: \"os\",\n ver: OSData.versionOS,\n },\n {\n nam: window.location.hostname,\n fam: \"domain\",\n },\n lms,\n ];\n\n // Filter hosts to remove empty objects and empty keys.\n hosts = hosts.filter((element) => {\n if (element) Object.keys(element).forEach((key) => (element[key] === \"unknown\" ? delete element[key] : {}));\n return element !== undefined;\n });\n\n // Initialize telemeter\n Telemeter.init({\n solution: {\n name: `MathType for ${solutionTelemeter}`,\n version: this.version,\n },\n hosts,\n config: {\n test: false, // True to use the staging Telemetry endpoint instead of the production one.\n debug: false, // True to show more information about Telemeter's execution and use dev-tools.\n dry_run: false, // True to skip sending data to the Telemetry endpoint (for example for unit tests).\n api_key: \"eda2ce9b-0e8a-46f2-acdd-c228a615314e\", // to auth against Telemetry. Data team is the responsible of providing it.\n },\n url: undefined,\n });\n }\n\n /**\n * Returns the Browser name and its version.\n * @return {array} - detectedBrowser = Operating System name.\n * versionBrowser = Operating System version.\n */\n getBrowser() {\n // default value for OS just in case nothing is detected\n let detectedBrowser = \"unknown\";\n let versionBrowser = \"unknown\";\n\n const userAgent = window.navigator.userAgent;\n\n if (/Brave/.test(userAgent)) {\n detectedBrowser = \"brave\";\n if (userAgent.indexOf(\"Brave/\")) {\n const start = userAgent.indexOf(\"Brave\") + 6;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (userAgent.indexOf(\"Edg/\") !== -1) {\n detectedBrowser = \"edge_chromium\";\n const start = userAgent.indexOf(\"Edg/\") + 4;\n versionBrowser = userAgent\n .substring(start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Edg/.test(userAgent)) {\n detectedBrowser = \"edge\";\n let start = userAgent.indexOf(\"Edg\") + 3;\n start += userAgent.substring(start).indexOf(\"/\");\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Firefox/.test(userAgent) || /FxiOS/.test(userAgent)) {\n detectedBrowser = \"firefox\";\n let start = userAgent.indexOf(\"Firefox\");\n start = start === -1 ? userAgent.indexOf(\"FxiOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/OPR/.test(userAgent)) {\n detectedBrowser = \"opera\";\n const start = userAgent.indexOf(\"OPR/\") + 4;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Chrome/.test(userAgent) || /CriOS/.test(userAgent)) {\n detectedBrowser = \"chrome\";\n let start = userAgent.indexOf(\"Chrome\");\n start = start === -1 ? userAgent.indexOf(\"CriOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/Safari/.test(userAgent)) {\n detectedBrowser = \"safari\";\n let start = userAgent.indexOf(\"Version/\");\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n }\n\n return { detectedBrowser, versionBrowser };\n }\n\n /**\n * Returns the operating system and its version.\n * @return {array} - detectedOS = Operating System name.\n * versionOS = Operating System version.\n */\n getOS() {\n // default value for OS just in case nothing is detected\n let detectedOS = \"unknown\";\n let versionOS = \"unknown\";\n\n // Retrieve properties to easily detect the OS\n const userAgent = window.navigator.userAgent;\n const platform = window.navigator.platform;\n const macosPlatforms = [\"Macintosh\", \"MacIntel\", \"MacPPC\", \"Mac68K\"];\n const windowsPlatforms = [\"Win32\", \"Win64\", \"Windows\", \"WinCE\"];\n const iosPlatforms = [\"iPhone\", \"iPad\", \"iPod\"];\n\n // Find OS and their respective versions\n if (macosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"macos\";\n if (userAgent.indexOf(\"OS X\") !== -1) {\n const start = userAgent.indexOf(\"OS X\") + 5;\n const end = userAgent.substring(start).indexOf(\" \");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (iosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"ios\";\n if (userAgent.indexOf(\"OS \") !== -1) {\n const start = userAgent.indexOf(\"OS \") + 3;\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (windowsPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"windows\";\n const start = userAgent.indexOf(\"Windows\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Android/.test(userAgent)) {\n detectedOS = \"android\";\n const start = userAgent.indexOf(\"Android\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/CrOS/.test(userAgent)) {\n detectedOS = \"chromeos\";\n let start = userAgent.indexOf(\"CrOS \") + 5;\n start += userAgent.substring(start).indexOf(\" \");\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (detectedOS === \"unknown\" && /Linux/.test(platform)) {\n detectedOS = \"linux\";\n }\n\n return { detectedOS, versionOS };\n }\n\n /**\n * Returns the absolute path of the integration script.\n * @return {string} - Absolute path for the integration script.\n */\n getPath() {\n if (typeof this.scriptName === \"undefined\") {\n throw new Error(\"scriptName property needed for getPath.\");\n }\n const col = document.getElementsByTagName(\"script\");\n let path = \"\";\n for (let i = 0; i < col.length; i += 1) {\n const j = col[i].src.lastIndexOf(this.scriptName);\n if (j >= 0) {\n path = col[i].src.substr(0, j - 1);\n }\n }\n return path;\n }\n\n /**\n * Returns integration model plugin version\n * @param {string} - Plugin version\n */\n getVersion() {\n return this.version;\n }\n\n /**\n * Sets the language property.\n * @param {string} language - language code.\n */\n setLanguage(language) {\n this.language = language;\n }\n\n /**\n * Sets a Core instance.\n * @param {Core} core - instance of Core class.\n */\n setCore(core) {\n this.core = core;\n core.setIntegrationModel(this);\n }\n\n /**\n * Returns the Core instance.\n * @returns {Core} instance of Core class.\n */\n getCore() {\n return this.core;\n }\n\n /**\n * Sets the object target and updates the iframe property.\n * @param {HTMLElement} target - target object.\n */\n setTarget(target) {\n this.target = target;\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Sets the editor object.\n * @param {Object} editorObject - The editor object.\n */\n setEditorObject(editorObject) {\n this.editorObject = editorObject;\n }\n\n /**\n * Opens formula editor to editing a new formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openNewFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.dbclick = false;\n this.core.editionProperties.isNewElement = true;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Opens formula editor to editing an existing formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openExistingFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.isNewElement = false;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Wrapper to Core.updateFormula method.\n * Transform a MathML into a image formula.\n * Then the image formula is inserted in the specified target, creating a new image (new formula)\n * or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n */\n updateFormula(mathml) {\n if (this.editorParameters) {\n mathml = com.wiris.editor.util.EditorUtils.addAnnotation(\n mathml,\n \"application/vnd.wiris.mtweb-params+json\",\n JSON.stringify(this.editorParameters),\n );\n }\n let focusElement;\n let windowTarget;\n const wirisProperties = null;\n\n if (this.isIframe) {\n focusElement = this.target.contentWindow;\n windowTarget = this.target.contentWindow;\n } else {\n focusElement = this.target;\n windowTarget = window;\n }\n\n let obj = this.core.beforeUpdateFormula(mathml, wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n obj = this.insertFormula(focusElement, windowTarget, obj.mathml, obj.wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n return this.core.afterUpdateFormula(obj.focusElement, obj.windowTarget, obj.node, obj.latex);\n }\n\n /**\n * Wrapper to Core.insertFormula method.\n * Inserts the formula in the specified target, creating\n * a new image (new formula) or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n const obj = this.core.insertFormula(focusElement, windowTarget, mathml, wirisProperties);\n\n // Delete temporal image when inserted\n this.core.editionProperties.temporalImage = null;\n\n return obj;\n }\n\n /**\n * Returns the target selection.\n * @returns {Selection} target selection.\n */\n getSelection() {\n if (this.isIframe) {\n this.target.contentWindow.focus();\n return this.target.contentWindow.getSelection();\n }\n this.target.focus();\n return window.getSelection();\n }\n\n /**\n * Add events to formulas in the DOM target. The events added are the following:\n * - doubleClickHandler: handles Double-click event on formulas by opening an editor\n * to edit them.\n * - mouseDownHandler: handles mouse down event on formulas by saving the size of the formula\n * in case the the formula is resized.\n * - mouseUpHandler: handles mouse up event on formulas by restoring the saved formula size\n * in case the formula is resized.\n */\n addEvents() {\n const eventTarget = this.isIframe ? this.target.contentWindow.document : this.target;\n Util.addElementEvents(\n eventTarget,\n (element, event) => {\n this.doubleClickHandler(element, event);\n // Avoid creating the double click listener more than once for each element.\n event.stopImmediatePropagation();\n },\n (element, event) => {\n this.mousedownHandler(element, event);\n },\n (element, event) => {\n this.mouseupHandler(element, event);\n },\n );\n }\n\n /**\n * Remove events to formulas in the DOM target.\n */\n removeEvents() {\n const eventTarget =\n this.isIframe && this.target.contentWindow?.document ? this.target.contentWindow.document : this.target;\n\n if (!eventTarget) {\n return;\n }\n\n Util.removeElementEvents(eventTarget);\n }\n\n /**\n * Remove events, modals and set this.editorObject to null in order to prevent memory leaks.\n */\n destroy() {\n this.removeEvents();\n // Destroy modal dialog if exists.\n if (this.core.modalDialog) {\n this.core.modalDialog.destroy();\n }\n\n // Remove offline modal dialog if exists.\n if (this.offlineModal) {\n this.offlineModal.remove();\n }\n\n this.editorObject = null;\n }\n\n /**\n * Handles a Double-click on the target element. Opens an editor\n * to re-edit the double-clicked formula.\n * @param {HTMLElement} element - DOM object target.\n */\n doubleClickHandler(element) {\n this.core.editionProperties.dbclick = true;\n if (element.nodeName.toLowerCase() === \"img\") {\n this.core.getCustomEditors().disable();\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (element.hasAttribute(customEditorAttributeName)) {\n const customEditor = element.getAttribute(customEditorAttributeName);\n this.core.getCustomEditors().enable(customEditor);\n }\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.core.editionProperties.temporalImage = element;\n this.core.editionProperties.isNewElement = true;\n this.openExistingFormulaEditor();\n }\n }\n }\n\n /**\n * Handles a mouse up event on the target element. Restores the image size to avoid\n * resizing formulas.\n */\n mouseupHandler() {\n if (this.temporalImageResizing) {\n setTimeout(() => {\n Image.fixAfterResize(this.temporalImageResizing);\n }, 10);\n }\n }\n\n /**\n * Handles a mouse down event on the target element. Saves the formula size to avoid\n * resizing formulas.\n * @param {HTMLElement} element - target element.\n */\n mousedownHandler(element) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.temporalImageResizing = element;\n }\n }\n }\n\n /**\n * Returns the integration language. By default the browser agent. This method\n * should be overwritten to obtain the integration language, for example using the\n * plugin API of an HTML editor.\n * @returns {string} integration language.\n */\n getLanguage() {\n return this.getBrowserLanguage();\n }\n\n /**\n * Returns the browser language.\n * @returns {string} the browser language.\n */\n // eslint-disable-next-line class-methods-use-this\n getBrowserLanguage() {\n let language = \"en\";\n if (navigator.userLanguage) {\n language = navigator.userLanguage.substring(0, 2);\n } else if (navigator.language) {\n language = navigator.language.substring(0, 2);\n } else {\n language = \"en\";\n }\n return language;\n }\n\n /**\n * This function is called once the {@link Core} is loaded. IntegrationModel class\n * will fire this method when {@link Core} 'onLoad' event is fired.\n * This method should content all the logic to init\n * the integration.\n */\n callbackFunction() {\n // It's needed to wait until the integration target is ready. The event is fired\n // from the integration side.\n const listener = Listeners.newListener(\"onTargetReady\", () => {\n this.addEvents(this.target);\n });\n this.listeners.add(listener);\n }\n\n /**\n * Function called when the content submits an action.\n */\n // eslint-disable-next-line class-methods-use-this\n notifyWindowClosed() {\n // Nothing.\n }\n\n /**\n * Wrapper.\n * Extracts mathml of a determined text node. This function is used as a wrapper inside core.js\n * in order to get mathml from a text node that can contain normal LaTeX or other chosen text.\n * @param {string} textNode - text node to extract the MathML.\n * @param {int} caretPosition - caret position inside the text node.\n * @returns {string} MathML inside the text node.\n */\n\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getMathmlFromTextNode(textNode, caretPosition) {}\n\n /**\n * Wrapper\n * It fills wrs event object of nonLatex with the desired data.\n * @param {Object} event - event object.\n * @param {Object} window dom window object.\n * @param {string} mathml valid mathml.\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n fillNonLatexNode(event, window, mathml) {}\n\n /**\n Wrapper.\n * Returns selected item from the target.\n * @param {HTMLElement} target - target element\n * @param {boolean} iframe\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getSelectedItem(target, isIframe) {}\n\n // Set temporal image to null and make focus come back.\n static setActionsOnCancelButtons() {\n // Make focus come back on the previous place it was when click cancel button\n const currentInstance = WirisPlugin.currentInstance;\n const editorSelection = currentInstance.getSelection();\n editorSelection.removeAllRanges();\n\n if (currentInstance.core.editionProperties.range) {\n const { range } = currentInstance.core.editionProperties;\n currentInstance.core.editionProperties.range = null;\n editorSelection.addRange(range);\n if (range.startOffset !== range.endOffset) {\n currentInstance.core.placeCaretAfterNode(currentInstance.core.editionProperties.temporalImage);\n }\n }\n\n // eslint-disable-next-line no-undef\n if (WirisPlugin.currentInstance) {\n WirisPlugin.currentInstance.core.editionProperties.temporalImage = null; // eslint-disable-line\n }\n }\n}\n\n// To know if the integration that extends this class implements\n// wrapper methods, they are set as undefined.\nIntegrationModel.prototype.getMathmlFromTextNode = undefined;\nIntegrationModel.prototype.fillNonLatexNode = undefined;\nIntegrationModel.prototype.getSelectedItem = undefined;\n\n/**\n * An object containing a list with the overwritable class constructor properties.\n * @type {Object}\n */\nIntegrationModel.integrationParameters = [\"serviceProviderProperties\", \"editorParameters\"];\n","/* eslint-disable */\nvar md5;\nexport default md5;\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n delete Array.prototype.__class__;\n})();\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n})();\ndelete Array.prototype.__class__;\n// @codingStandardsIgnoreEnd\n","import IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Telemeter from \"@wiris/mathtype-html-integration-devkit/src/telemeter.js\";\n\n/**\n * This class represents the MathType integration for CKEditor5.\n * @extends {IntegrationModel}\n */\nexport default class CKEditor5Integration extends IntegrationModel {\n constructor(ckeditorIntegrationModelProperties) {\n const editor = ckeditorIntegrationModelProperties.editorObject;\n\n if (typeof editor.config !== \"undefined\" && typeof editor.config.get(\"mathTypeParameters\") !== \"undefined\") {\n ckeditorIntegrationModelProperties.integrationParameters = editor.config.get(\"mathTypeParameters\");\n }\n /**\n * CKEditor5 Integration.\n *\n * @param {integrationModelProperties} integrationModelAttributes\n */\n super(ckeditorIntegrationModelProperties);\n\n /**\n * Folder name used for the integration inside CKEditor plugins folder.\n */\n this.integrationFolderName = \"ckeditor_wiris\";\n }\n\n /**\n * @inheritdoc\n * @returns {string} - The CKEditor instance language.\n * @override\n */\n getLanguage() {\n // Returns the CKEDitor instance language taking into account that the language can be an object.\n // Try to get editorParameters.language, fail silently otherwise\n try {\n return this.editorParameters.language;\n } catch (e) {}\n const languageObject = this.editorObject.config.get(\"language\");\n if (languageObject != null) {\n if (typeof languageObject === \"object\") {\n if (Object.prototype.hasOwnProperty.call(languageObject, \"ui\")) {\n return languageObject.ui;\n }\n return languageObject;\n }\n return languageObject;\n }\n return super.getLanguage();\n }\n\n /**\n * Adds callbacks to the following CKEditor listeners:\n * - 'focus' - updates the current instance.\n * - 'contentDom' - adds 'doubleclick' callback.\n * - 'doubleclick' - sets to null data.dialog property to avoid modifications for MathType formulas.\n * - 'setData' - parses the data converting MathML into images.\n * - 'afterSetData' - adds an observer to MathType formulas to avoid modifications.\n * - 'getData' - parses the data converting images into selected save mode (MathML by default).\n * - 'mode' - recalculates the active element.\n */\n addEditorListeners() {\n const editor = this.editorObject;\n\n if (typeof editor.config.wirislistenersdisabled === \"undefined\" || !editor.config.wirislistenersdisabled) {\n this.checkElement();\n }\n }\n\n /**\n * Checks the current container and assign events in case that it doesn't have them.\n * CKEditor replaces several times the element element during its execution,\n * so we must assign the events again to editor element.\n */\n checkElement() {\n const editor = this.editorObject;\n const newElement = editor.sourceElement;\n\n // If the element wasn't treated, add the events.\n if (!newElement.wirisActive) {\n this.setTarget(newElement);\n this.addEvents();\n // Set the element as treated\n newElement.wirisActive = true;\n }\n }\n\n /**\n * @inheritdoc\n * @param {HTMLElement} element - HTMLElement target.\n * @param {MouseEvent} event - event which trigger the handler.\n */\n doubleClickHandler(element, event) {\n this.core.editionProperties.dbclick = true;\n if (this.editorObject.isReadOnly === false) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n // Some plugins (image2, image) open a dialog on Double-click. On formulas\n // doubleclick event ends here.\n if (typeof event.stopPropagation !== \"undefined\") {\n // old I.E compatibility.\n event.stopPropagation();\n } else {\n event.returnValue = false;\n }\n this.core.getCustomEditors().disable();\n const customEditorAttr = element.getAttribute(Configuration.get(\"imageCustomEditorName\"));\n if (customEditorAttr) {\n this.core.getCustomEditors().enable(customEditorAttr);\n }\n this.core.editionProperties.temporalImage = element;\n this.openExistingFormulaEditor();\n }\n }\n }\n }\n\n /** @inheritdoc */\n static getCorePath() {\n return null; // TODO\n }\n\n /** @inheritdoc */\n callbackFunction() {\n super.callbackFunction();\n this.addEditorListeners();\n }\n\n openNewFormulaEditor() {\n // Store the editor selection as it will be lost upon opening the modal\n this.core.editionProperties.selection = this.editorObject.editing.view.document.selection;\n\n // Focus on the selected editor when multiple editor instances are present\n WirisPlugin.currentInstance = this;\n\n return super.openNewFormulaEditor();\n }\n\n /**\n * Replaces old formula with new MathML or inserts it in caret position if new\n * @param {String} mathml MathML to update old one or insert\n * @returns {module:engine/model/element~Element} The model element corresponding to the inserted image\n */\n insertMathml(mathml) {\n // This returns the value returned by the callback function (writer => {...})\n return this.editorObject.model.change((writer) => {\n const core = this.getCore();\n const selection = this.editorObject.model.document.selection;\n\n const modelElementNew = writer.createElement(\"mathml\", {\n formula: mathml,\n ...Object.fromEntries(selection.getAttributes()), // To keep the format, such as style and font\n });\n\n // Obtain the DOM object corresponding to the formula\n if (core.editionProperties.isNewElement) {\n // Don't bother inserting anything at all if the MathML is empty.\n if (!mathml) return;\n\n const viewSelection =\n this.core.editionProperties.selection || this.editorObject.editing.view.document.selection;\n const modelPosition = this.editorObject.editing.mapper.toModelPosition(viewSelection.getLastPosition());\n\n this.editorObject.model.insertObject(modelElementNew, modelPosition);\n\n // Remove selection\n if (!viewSelection.isCollapsed) {\n for (const range of viewSelection.getRanges()) {\n writer.remove(this.editorObject.editing.mapper.toModelRange(range));\n }\n }\n\n // Set carret after the formula\n const position = this.editorObject.model.createPositionAfter(modelElementNew);\n writer.setSelection(position);\n } else {\n const img = core.editionProperties.temporalImage;\n const viewElement = this.editorObject.editing.view.domConverter.domToView(img).parent;\n const modelElementOld = this.editorObject.editing.mapper.toModelElement(viewElement);\n\n // Insert the new and remove the old one\n const position = this.editorObject.model.createPositionBefore(modelElementOld);\n\n // If the given MathML is empty, don't insert a new formula.\n if (mathml) {\n this.editorObject.model.insertObject(modelElementNew, position);\n }\n writer.remove(modelElementOld);\n }\n\n // eslint-disable-next-line consistent-return\n return modelElementNew;\n });\n }\n\n /**\n * Finds the text node corresponding to given DOM text element.\n * @param {element} viewElement Element to find corresponding text node of.\n * @returns {module:engine/model/text~Text|undefined} Text node corresponding to the given element or undefined if it doesn't exist.\n */\n findText(viewElement) {\n // eslint-disable-line consistent-return\n // mapper always converts text nodes to *new* model elements so we need to convert the text's parents and then come back down\n let pivot = viewElement;\n let element;\n while (!element) {\n element = this.editorObject.editing.mapper.toModelElement(\n this.editorObject.editing.view.domConverter.domToView(pivot),\n );\n pivot = pivot.parentElement;\n }\n\n // Navigate through all the subtree under `pivot` in order to find the correct text node\n const range = this.editorObject.model.createRangeIn(element);\n const descendants = Array.from(range.getItems());\n for (const node of descendants) {\n let viewElementData = viewElement.data;\n if (viewElement.nodeType === 3) {\n // Remove invisible white spaces\n viewElementData = viewElementData.replaceAll(String.fromCharCode(8288), \"\");\n }\n if (node.is(\"textProxy\") && node.data === viewElementData.replace(String.fromCharCode(160), \" \")) {\n return node.textNode;\n }\n }\n }\n\n /** @inheritdoc */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n // eslint-disable-line no-unused-vars\n const returnObject = {};\n\n let mathmlOrigin;\n if (!mathml) {\n this.insertMathml(\"\");\n } else if (this.core.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n\n this.editorObject.model.change((writer) => {\n const { latexRange } = this.core.editionProperties;\n\n const startNode = this.findText(latexRange.startContainer);\n const endNode = this.findText(latexRange.endContainer);\n\n let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);\n let endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);\n\n let range = writer.createRange(startPosition, endPosition);\n\n // When Latex is next to image/formula.\n if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {\n // Get the position of the latex to be replaced.\n const latexEdited = `$$${Latex.getLatexFromMathML(\n MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml),\n )}$$`;\n let data = latexRange.startContainer.data;\n\n // Remove invisible characters.\n data = data.replaceAll(String.fromCharCode(8288), \"\");\n\n // Get to the start of the latex we are editing.\n const offset = data.indexOf(latexEdited);\n const dataOffset = data.substring(offset);\n const second$ = dataOffset.substring(2).indexOf(\"$$\") + 4;\n const substring = dataOffset.substr(0, second$);\n data = data.replace(substring, \"\");\n\n if (!data) {\n startPosition = writer.createPositionBefore(startNode);\n range = startNode;\n } else {\n startPosition = startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + offset);\n endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + second$ + offset);\n range = writer.createRange(startPosition, endPosition);\n }\n }\n\n writer.remove(range);\n writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);\n });\n } else {\n mathmlOrigin = this.core.editionProperties.temporalImage?.dataset.mathml;\n try {\n returnObject.node = this.editorObject.editing.view.domConverter.viewToDom(\n this.editorObject.editing.mapper.toViewElement(this.insertMathml(mathml)),\n windowTarget.document,\n );\n } catch (e) {\n const x = e.toString();\n if (x.includes(\"CKEditorError: Cannot read property 'parent' of undefined\")) {\n this.core.modalDialog.cancelAction();\n }\n }\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.core.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n\n /* Due to PLUGINS-1329, we add the onChange event to the CK4 insertFormula.\n We probably should add it here as well, but we should look further into how */\n // this.editorObject.fire('change');\n\n // Remove temporal image of inserted formula\n this.core.editionProperties.temporalImage = null;\n\n return returnObject;\n }\n\n /**\n * Function called when the content submits an action.\n */\n notifyWindowClosed() {\n this.editorObject.editing.view.focus();\n }\n}\n","/* eslint-disable max-classes-per-file */\nimport { Command } from \"ckeditor5/src/core.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\n/**\n * Command for opening the MathType editor\n */\nexport class MathTypeCommand extends Command {\n execute(options = {}) {\n // Check we get a valid integration\n // eslint-disable-next-line no-prototype-builtins\n if (!options.hasOwnProperty(\"integration\") || !(options.integration instanceof CKEditor5Integration)) {\n throw 'Must pass a valid CKEditor5Integration instance as attribute \"integration\" of options';\n }\n\n // Save the integration instance as a property of the command.\n this.integration = options.integration;\n\n // Set custom editor or disable it\n this.setEditor();\n\n // Open the editor\n this.openEditor();\n }\n\n /**\n * Sets the appropriate custom editor, if any, or disables them.\n */\n setEditor() {\n // It's possible that a custom editor was last used.\n // We need to disable it to avoid wrong behaviors.\n this.integration.core.getCustomEditors().disable();\n }\n\n /**\n * Checks whether we are editing an existing formula or a new one and opens the editor.\n */\n openEditor() {\n this.integration.core.editionProperties.dbclick = false;\n const image = this._getSelectedImage();\n if (\n typeof image !== \"undefined\" &&\n image !== null &&\n image.classList.contains(WirisPlugin.Configuration.get(\"imageClassName\"))\n ) {\n this.integration.core.editionProperties.temporalImage = image;\n this.integration.openExistingFormulaEditor();\n } else {\n this.integration.openNewFormulaEditor();\n }\n }\n\n /**\n * Gets the currently selected formula image\n * @returns {Element} selected image, if any, undefined otherwise\n */\n _getSelectedImage() {\n const { selection } = this.editor.editing.view.document;\n\n // If we can not extract the formula, fall back to default behavior.\n if (selection.isCollapsed || selection.rangeCount !== 1) {\n return;\n }\n\n // Look for the wrapping the formula and then for the inside\n\n const range = selection.getFirstRange();\n\n let image;\n\n for (const span of range) {\n if (span.item.name !== \"span\") {\n return;\n }\n image = span.item.getChild(0);\n break;\n }\n\n if (!image) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n return this.editor.editing.view.domConverter.mapViewToDom(image);\n }\n}\n\n/**\n * Command for opening the ChemType editor\n */\nexport class ChemTypeCommand extends MathTypeCommand {\n setEditor() {\n this.integration.core.getCustomEditors().enable(\"chemistry\");\n }\n}\n","// CKEditor imports\nimport { Plugin } from \"ckeditor5/src/core.js\";\nimport { ButtonView } from \"ckeditor5/src/ui.js\";\nimport { ClickObserver, HtmlDataProcessor, XmlDataProcessor, ViewUpcastWriter } from \"ckeditor5/src/engine.js\";\nimport { Widget, toWidget, viewToModelPositionOutsideModelElement } from \"ckeditor5/src/widget.js\";\n\n// MathType API imports\nimport IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Core from \"@wiris/mathtype-html-integration-devkit/src/core.src.js\";\nimport Parser from \"@wiris/mathtype-html-integration-devkit/src/parser.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Image from \"@wiris/mathtype-html-integration-devkit/src/image.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Listeners from \"@wiris/mathtype-html-integration-devkit/src/listeners.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport StringManager from \"@wiris/mathtype-html-integration-devkit/src/stringmanager.js\";\nimport \"@wiris/mathtype-html-integration-devkit/src/md5.js\";\n\n// Local imports\nimport { MathTypeCommand, ChemTypeCommand } from \"./commands.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\nimport mathIcon from \"../theme/icons/ckeditor5-formula.svg\";\nimport chemIcon from \"../theme/icons/ckeditor5-chem.svg\";\n\nimport packageInfo from \"../package.json\";\n\nexport let currentInstance = null; // eslint-disable-line import/no-mutable-exports\n\nexport default class MathType extends Plugin {\n static get requires() {\n return [Widget];\n }\n\n static get pluginName() {\n return \"MathType\";\n }\n\n init() {\n // Create the MathType API Integration object\n const integration = this._addIntegration();\n currentInstance = integration;\n\n // Add the MathType and ChemType commands to the editor\n this._addCommands();\n\n // Add the buttons for MathType and ChemType\n this._addViews(integration);\n\n // Registers the element in the schema\n this._addSchema();\n\n // Add the downcast and upcast converters\n this._addConverters(integration);\n\n // Expose the WirisPlugin variable to the window\n this._exposeWiris();\n }\n\n /**\n * Inherited from Plugin class: Executed when CKEditor5 is destroyed\n */\n destroy() {\n // eslint-disable-line class-methods-use-this\n currentInstance?.destroy();\n }\n\n /**\n * Create the MathType API Integration object\n * @returns {CKEditor5Integration} the integration object\n */\n _addIntegration() {\n const { editor } = this;\n\n /**\n * Integration model constructor attributes.\n * @type {integrationModelProperties}\n */\n const integrationProperties = {};\n integrationProperties.environment = {};\n integrationProperties.environment.editor = \"CKEditor5\";\n integrationProperties.environment.editorVersion = \"5.x\";\n integrationProperties.version = packageInfo.version;\n integrationProperties.editorObject = editor;\n integrationProperties.serviceProviderProperties = {};\n integrationProperties.serviceProviderProperties.URI = \"https://www.wiris.net/demo/plugins/app\";\n integrationProperties.serviceProviderProperties.server = \"java\";\n integrationProperties.target = editor.sourceElement;\n integrationProperties.scriptName = \"bundle.js\";\n integrationProperties.managesLanguage = true;\n // etc\n\n // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.\n // To avoid a wrong behavior, this integration only starts if the workspace container exists.\n let integration;\n if (integrationProperties.target) {\n // Instance of the integration associated to this editor instance\n integration = new CKEditor5Integration(integrationProperties);\n integration.init();\n integration.listeners.fire(\"onTargetReady\", {});\n\n integration.checkElement();\n\n this.listenTo(\n editor.editing.view.document,\n \"click\",\n (evt, data) => {\n // Is Double-click\n if (data.domEvent.detail === 2) {\n integration.doubleClickHandler(data.domTarget, data.domEvent);\n evt.stop();\n }\n },\n { priority: \"highest\" },\n );\n }\n\n return integration;\n }\n\n /**\n * Add the MathType and ChemType commands to the editor\n */\n _addCommands() {\n const { editor } = this;\n\n // Add command to open the formula editor\n editor.commands.add(\"MathType\", new MathTypeCommand(editor));\n\n // Add command to open the chemistry formula editor\n editor.commands.add(\"ChemType\", new ChemTypeCommand(editor));\n }\n\n /**\n * Add the buttons for MathType and ChemType\n * @param {CKEditor5Integration} integration the integration object\n */\n _addViews(integration) {\n const { editor } = this;\n\n // Check if MathType editor is enabled\n if (Configuration.get(\"editorEnabled\")) {\n // Add button for the formula editor\n editor.ui.componentFactory.add(\"MathType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"MathType\"), \"isEnabled\");\n view.set({\n label: StringManager.get(\"insert_math\", integration.getLanguage()),\n icon: mathIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"MathType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Check if ChemType editor is enabled\n if (Configuration.get(\"chemEnabled\")) {\n // Add button for the chemistry formula editor\n editor.ui.componentFactory.add(\"ChemType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"ChemType\"), \"isEnabled\");\n\n view.set({\n label: StringManager.get(\"insert_chem\", integration.getLanguage()),\n icon: chemIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"ChemType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Observer for the Double-click event\n editor.editing.view.addObserver(ClickObserver);\n }\n\n /**\n * Registers the element in the schema\n */\n _addSchema() {\n const { schema } = this.editor.model;\n\n schema.register(\"mathml\", {\n inheritAllFrom: \"$inlineObject\",\n allowAttributes: [\"formula\", \"htmlContent\"],\n });\n }\n\n /**\n * Add the downcast and upcast converters\n */\n _addConverters(integration) {\n const { editor } = this;\n\n // Editing view -> Model\n editor.conversion.for(\"upcast\").elementToElement({\n view: {\n name: \"span\",\n classes: \"ck-math-widget\",\n },\n model: (viewElement, { writer: modelWriter }) => {\n const formula = MathML.safeXmlDecode(viewElement.getChild(0).getAttribute(\"data-mathml\"));\n return modelWriter.createElement(\"mathml\", {\n formula,\n });\n },\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\"element:math\", (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // When element was already consumed then skip it.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // If we encounter any with a LaTeX annotation inside,\n // convert it into a \"$$...$$\" string.\n const isLatex = mathIsLatex(viewItem); // eslint-disable-line no-use-before-define\n\n // Get the formula of the (which is all its children).\n const processor = new XmlDataProcessor(editor.editing.view.document);\n\n // Only god knows why the following line makes viewItem lose all of its children,\n // so we obtain isLatex before doing this because we need viewItem's children for that.\n const upcastWriter = new ViewUpcastWriter(editor.editing.view.document);\n const viewDocumentFragment = upcastWriter.createDocumentFragment(viewItem.getChildren());\n\n // and obtain the attributes of too!\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n\n // We process the document fragment\n let formula = processor.toData(viewDocumentFragment) || \"\";\n\n // And obtain the complete formula\n formula = Util.htmlSanitize(`${formula}`);\n\n // Replaces the < & > characters to its HTMLEntity to avoid render issues.\n formula = formula.replaceAll('\"<\"', '\"<\"').replaceAll('\">\"', '\">\"').replaceAll(\"><<\", \"><<\");\n\n /* Model node that contains what's going to actually be inserted. This can be either:\n - A element with a formula attribute set to the given formula, or\n - If the original had a LaTeX annotation, then the annotation surrounded by \"$$...$$\" */\n const modelNode = isLatex\n ? writer.createText(Parser.initParse(formula, integration.getLanguage()))\n : writer.createElement(\"mathml\", { formula });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\n \"element:img\",\n (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // Only upcast when is wiris formula\n if (viewItem.getClassNames().next().value !== \"Wirisformula\") {\n return;\n }\n\n // The following code ensures that the element's name, attributes, and classes are consumed.\n // This means that they are marked as handled so that other parts of the system or plugins don't process them again.\n\n // Check if we can consume the element name.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // Consume the name, attributes, and classes so nothing else processes it.\n consumable.consume(viewItem, { name: true });\n for (const attrName of viewItem.getAttributes()) {\n consumable.consume(viewItem, { attributes: [attrName] });\n }\n\n for (const className of viewItem.getClassNames()) {\n consumable.consume(viewItem, { classes: [className] });\n }\n\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n const htmlContent = Util.htmlSanitize(``);\n\n const modelNode = writer.createElement(\"mathml\", { htmlContent });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n },\n // Ensures MathType processes the Wiris formulas before other plugins, preventing conflicts.\n { priority: \"high\" },\n );\n\n /**\n * Whether the given view element has a LaTeX annotation element.\n * @param {*} math\n * @returns {bool}\n */\n function mathIsLatex(math) {\n const semantics = math.getChild(0);\n if (!semantics || semantics.name !== \"semantics\") return false;\n for (const child of semantics.getChildren()) {\n if (child.name === \"annotation\" && child.getAttribute(\"encoding\") === \"LaTeX\") {\n return true;\n }\n }\n return false;\n }\n\n function createViewWidget(modelItem, { writer: viewWriter }) {\n const widgetElement = viewWriter.createContainerElement(\"span\", {\n class: \"ck-math-widget\",\n });\n\n const mathUIElement = createViewImage(modelItem, { writer: viewWriter }); // eslint-disable-line no-use-before-define\n\n if (mathUIElement) {\n viewWriter.insert(viewWriter.createPositionAt(widgetElement, 0), mathUIElement);\n }\n\n return toWidget(widgetElement, viewWriter);\n }\n\n function createViewImage(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n const formula = modelItem.getAttribute(\"formula\");\n const htmlContent = modelItem.getAttribute(\"htmlContent\");\n\n if (!formula && !htmlContent) {\n return null;\n }\n\n let imgElement = null;\n\n if (htmlContent) {\n imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);\n } else if (formula) {\n const mathString = formula.replaceAll('ref=\"<\"', 'ref=\"<\"');\n\n const imgHtml = Parser.initParse(mathString, integration.getLanguage());\n imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);\n\n // Add HTML element () to model\n viewWriter.setAttribute(\"htmlContent\", imgHtml, modelItem);\n }\n\n /* Although we use the HtmlDataProcessor to obtain the attributes,\n * we must create a new EmptyElement which is independent of the\n * DataProcessor being used by this editor instance\n */\n if (imgElement) {\n return viewWriter.createEmptyElement(\"img\", imgElement.getAttributes(), {\n renderUnsafeAttributes: [\"src\"],\n });\n }\n\n return null;\n }\n\n // Model -> Editing view\n editor.conversion.for(\"editingDowncast\").elementToElement({\n model: \"mathml\",\n view: createViewWidget,\n });\n\n // Model -> Data view\n editor.conversion.for(\"dataDowncast\").elementToElement({\n model: \"mathml\",\n view: createDataString, // eslint-disable-line no-use-before-define\n });\n\n /**\n * Makes a copy of the given view node.\n * @param {module:engine/view/node~Node} sourceNode Node to copy.\n * @returns {module:engine/view/node~Node} Copy of the node.\n */\n function clone(viewWriter, sourceNode) {\n if (sourceNode.is(\"text\")) {\n return viewWriter.createText(sourceNode.data);\n }\n if (sourceNode.is(\"element\")) {\n if (sourceNode.is(\"emptyElement\")) {\n return viewWriter.createEmptyElement(sourceNode.name, sourceNode.getAttributes());\n }\n const element = viewWriter.createContainerElement(sourceNode.name, sourceNode.getAttributes());\n for (const child of sourceNode.getChildren()) {\n viewWriter.insert(viewWriter.createPositionAt(element, \"end\"), clone(viewWriter, child));\n }\n return element;\n }\n\n throw new Exception(\"Given node has unsupported type.\"); // eslint-disable-line no-undef\n }\n\n function createDataString(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n // Load img element\n const mathString =\n modelItem.getAttribute(\"htmlContent\") || Parser.endParseSaveMode(modelItem.getAttribute(\"formula\"));\n\n const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);\n\n return clone(viewWriter, sourceMathElement);\n }\n\n // This stops the view selection getting into the s and messing up caret movement\n editor.editing.mapper.on(\n \"viewToModelPosition\",\n viewToModelPositionOutsideModelElement(editor.model, (viewElement) => viewElement.hasClass(\"ck-math-widget\")),\n );\n\n // Keep a reference to the original get and set function.\n const { get, set } = editor.data;\n\n /**\n * Hack to transform $$latex$$ into in editor.getData()'s output.\n */\n editor.data.on(\n \"get\",\n (e) => {\n const output = e.return;\n const parsedResult = Parser.endParse(output);\n\n // Cleans all the semantics tag for safexml\n // including the handwritten data points\n e.return = MathML.removeSafeXMLSemantics(parsedResult);\n },\n { priority: \"low\" },\n );\n\n /**\n * Hack to transform with LaTeX into $$LaTeX$$ and formula images in editor.setData().\n */\n editor.data.on(\n \"set\",\n (e, args) => {\n // Retrieve the data to be set on the CKEditor.\n let modifiedData = args[0];\n // Regex to find all mathml formulas.\n const regexp = /(]*>)|()/gm;\n const formulas = [];\n let formula;\n\n // Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.\n while ((formula = regexp.exec(modifiedData)) !== null) {\n formulas.push(formula[0]);\n }\n\n // Loop to find LaTeX and formula images and replace the MathML for the both.\n formulas.forEach((formula) => {\n if (formula.includes('encoding=\"LaTeX\"')) {\n // LaTeX found.\n const latex = `$$$${Latex.getLatexFromMathML(formula)}$$$`; // We add $$$ instead of $$ because the replace function ignores one $.\n modifiedData = modifiedData.replace(formula, latex);\n } else if (formula.includes(\" 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {\n args[_key - 2] = arguments[_key];\n }\n return func.apply(thisArg, args);\n };\n}\nif (!construct) {\n construct = function construct(Func) {\n for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {\n args[_key2 - 1] = arguments[_key2];\n }\n return new Func(...args);\n };\n}\nconst arrayForEach = unapply(Array.prototype.forEach);\nconst arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);\nconst arrayPop = unapply(Array.prototype.pop);\nconst arrayPush = unapply(Array.prototype.push);\nconst arraySplice = unapply(Array.prototype.splice);\nconst stringToLowerCase = unapply(String.prototype.toLowerCase);\nconst stringToString = unapply(String.prototype.toString);\nconst stringMatch = unapply(String.prototype.match);\nconst stringReplace = unapply(String.prototype.replace);\nconst stringIndexOf = unapply(String.prototype.indexOf);\nconst stringTrim = unapply(String.prototype.trim);\nconst objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);\nconst regExpTest = unapply(RegExp.prototype.test);\nconst typeErrorCreate = unconstruct(TypeError);\n/**\n * Creates a new function that calls the given function with a specified thisArg and arguments.\n *\n * @param func - The function to be wrapped and called.\n * @returns A new function that calls the given function with a specified thisArg and arguments.\n */\nfunction unapply(func) {\n return function (thisArg) {\n if (thisArg instanceof RegExp) {\n thisArg.lastIndex = 0;\n }\n for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {\n args[_key3 - 1] = arguments[_key3];\n }\n return apply(func, thisArg, args);\n };\n}\n/**\n * Creates a new function that constructs an instance of the given constructor function with the provided arguments.\n *\n * @param func - The constructor function to be wrapped and called.\n * @returns A new function that constructs an instance of the given constructor function with the provided arguments.\n */\nfunction unconstruct(Func) {\n return function () {\n for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {\n args[_key4] = arguments[_key4];\n }\n return construct(Func, args);\n };\n}\n/**\n * Add properties to a lookup table\n *\n * @param set - The set to which elements will be added.\n * @param array - The array containing elements to be added to the set.\n * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.\n * @returns The modified set with added elements.\n */\nfunction addToSet(set, array) {\n let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;\n if (setPrototypeOf) {\n // Make 'in' and truthy checks like Boolean(set.constructor)\n // independent of any properties defined on Object.prototype.\n // Prevent prototype setters from intercepting set as a this value.\n setPrototypeOf(set, null);\n }\n let l = array.length;\n while (l--) {\n let element = array[l];\n if (typeof element === 'string') {\n const lcElement = transformCaseFunc(element);\n if (lcElement !== element) {\n // Config presets (e.g. tags.js, attrs.js) are immutable.\n if (!isFrozen(array)) {\n array[l] = lcElement;\n }\n element = lcElement;\n }\n }\n set[element] = true;\n }\n return set;\n}\n/**\n * Clean up an array to harden against CSPP\n *\n * @param array - The array to be cleaned.\n * @returns The cleaned version of the array\n */\nfunction cleanArray(array) {\n for (let index = 0; index < array.length; index++) {\n const isPropertyExist = objectHasOwnProperty(array, index);\n if (!isPropertyExist) {\n array[index] = null;\n }\n }\n return array;\n}\n/**\n * Shallow clone an object\n *\n * @param object - The object to be cloned.\n * @returns A new object that copies the original.\n */\nfunction clone(object) {\n const newObject = create(null);\n for (const [property, value] of entries(object)) {\n const isPropertyExist = objectHasOwnProperty(object, property);\n if (isPropertyExist) {\n if (Array.isArray(value)) {\n newObject[property] = cleanArray(value);\n } else if (value && typeof value === 'object' && value.constructor === Object) {\n newObject[property] = clone(value);\n } else {\n newObject[property] = value;\n }\n }\n }\n return newObject;\n}\n/**\n * This method automatically checks if the prop is function or getter and behaves accordingly.\n *\n * @param object - The object to look up the getter function in its prototype chain.\n * @param prop - The property name for which to find the getter function.\n * @returns The getter function found in the prototype chain or a fallback function.\n */\nfunction lookupGetter(object, prop) {\n while (object !== null) {\n const desc = getOwnPropertyDescriptor(object, prop);\n if (desc) {\n if (desc.get) {\n return unapply(desc.get);\n }\n if (typeof desc.value === 'function') {\n return unapply(desc.value);\n }\n }\n object = getPrototypeOf(object);\n }\n function fallbackValue() {\n return null;\n }\n return fallbackValue;\n}\n\nconst html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);\nconst svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);\nconst svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);\n// List of SVG elements that are disallowed by default.\n// We still need to know them so that we can do namespace\n// checks properly in case one wants to add them to\n// allow-list.\nconst svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);\nconst mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);\n// Similarly to SVG, we want to know all MathML elements,\n// even those that we disallow by default.\nconst mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);\nconst text = freeze(['#text']);\n\nconst html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);\nconst svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);\nconst mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);\nconst xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);\n\n// eslint-disable-next-line unicorn/better-regex\nconst MUSTACHE_EXPR = seal(/\\{\\{[\\w\\W]*|[\\w\\W]*\\}\\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode\nconst ERB_EXPR = seal(/<%[\\w\\W]*|[\\w\\W]*%>/gm);\nconst TMPLIT_EXPR = seal(/\\$\\{[\\w\\W]*/gm); // eslint-disable-line unicorn/better-regex\nconst DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]+$/); // eslint-disable-line no-useless-escape\nconst ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\nconst IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\n);\nconst IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\nconst ATTR_WHITESPACE = seal(/[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\n);\nconst DOCTYPE_NAME = seal(/^html$/i);\nconst CUSTOM_ELEMENT = seal(/^[a-z][.\\w]*(-[.\\w]+)+$/i);\n\nvar EXPRESSIONS = /*#__PURE__*/Object.freeze({\n __proto__: null,\n ARIA_ATTR: ARIA_ATTR,\n ATTR_WHITESPACE: ATTR_WHITESPACE,\n CUSTOM_ELEMENT: CUSTOM_ELEMENT,\n DATA_ATTR: DATA_ATTR,\n DOCTYPE_NAME: DOCTYPE_NAME,\n ERB_EXPR: ERB_EXPR,\n IS_ALLOWED_URI: IS_ALLOWED_URI,\n IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,\n MUSTACHE_EXPR: MUSTACHE_EXPR,\n TMPLIT_EXPR: TMPLIT_EXPR\n});\n\n/* eslint-disable @typescript-eslint/indent */\n// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\nconst NODE_TYPE = {\n element: 1,\n attribute: 2,\n text: 3,\n cdataSection: 4,\n entityReference: 5,\n // Deprecated\n entityNode: 6,\n // Deprecated\n progressingInstruction: 7,\n comment: 8,\n document: 9,\n documentType: 10,\n documentFragment: 11,\n notation: 12 // Deprecated\n};\nconst getGlobal = function getGlobal() {\n return typeof window === 'undefined' ? null : window;\n};\n/**\n * Creates a no-op policy for internal use only.\n * Don't export this function outside this module!\n * @param trustedTypes The policy factory.\n * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).\n * @return The policy created (or null, if Trusted Types\n * are not supported or creating the policy failed).\n */\nconst _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {\n if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {\n return null;\n }\n // Allow the callers to control the unique policy name\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\n // Policy creation with duplicate names throws in Trusted Types.\n let suffix = null;\n const ATTR_NAME = 'data-tt-policy-suffix';\n if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {\n suffix = purifyHostElement.getAttribute(ATTR_NAME);\n }\n const policyName = 'dompurify' + (suffix ? '#' + suffix : '');\n try {\n return trustedTypes.createPolicy(policyName, {\n createHTML(html) {\n return html;\n },\n createScriptURL(scriptUrl) {\n return scriptUrl;\n }\n });\n } catch (_) {\n // Policy creation failed (most likely another DOMPurify script has\n // already run). Skip creating the policy, as this will only cause errors\n // if TT are enforced.\n console.warn('TrustedTypes policy ' + policyName + ' could not be created.');\n return null;\n }\n};\nconst _createHooksMap = function _createHooksMap() {\n return {\n afterSanitizeAttributes: [],\n afterSanitizeElements: [],\n afterSanitizeShadowDOM: [],\n beforeSanitizeAttributes: [],\n beforeSanitizeElements: [],\n beforeSanitizeShadowDOM: [],\n uponSanitizeAttribute: [],\n uponSanitizeElement: [],\n uponSanitizeShadowNode: []\n };\n};\nfunction createDOMPurify() {\n let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();\n const DOMPurify = root => createDOMPurify(root);\n DOMPurify.version = '3.3.0';\n DOMPurify.removed = [];\n if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {\n // Not running in a browser, provide a factory function\n // so that you can pass your own Window\n DOMPurify.isSupported = false;\n return DOMPurify;\n }\n let {\n document\n } = window;\n const originalDocument = document;\n const currentScript = originalDocument.currentScript;\n const {\n DocumentFragment,\n HTMLTemplateElement,\n Node,\n Element,\n NodeFilter,\n NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,\n HTMLFormElement,\n DOMParser,\n trustedTypes\n } = window;\n const ElementPrototype = Element.prototype;\n const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');\n const remove = lookupGetter(ElementPrototype, 'remove');\n const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');\n const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');\n const getParentNode = lookupGetter(ElementPrototype, 'parentNode');\n // As per issue #47, the web-components registry is inherited by a\n // new document created via createHTMLDocument. As per the spec\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\n // a new empty registry is used when creating a template contents owner\n // document, so we use that as our parent document to ensure nothing\n // is inherited.\n if (typeof HTMLTemplateElement === 'function') {\n const template = document.createElement('template');\n if (template.content && template.content.ownerDocument) {\n document = template.content.ownerDocument;\n }\n }\n let trustedTypesPolicy;\n let emptyHTML = '';\n const {\n implementation,\n createNodeIterator,\n createDocumentFragment,\n getElementsByTagName\n } = document;\n const {\n importNode\n } = originalDocument;\n let hooks = _createHooksMap();\n /**\n * Expose whether this browser supports running the full DOMPurify.\n */\n DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;\n const {\n MUSTACHE_EXPR,\n ERB_EXPR,\n TMPLIT_EXPR,\n DATA_ATTR,\n ARIA_ATTR,\n IS_SCRIPT_OR_DATA,\n ATTR_WHITESPACE,\n CUSTOM_ELEMENT\n } = EXPRESSIONS;\n let {\n IS_ALLOWED_URI: IS_ALLOWED_URI$1\n } = EXPRESSIONS;\n /**\n * We consider the elements and attributes below to be safe. Ideally\n * don't add any new ones but feel free to remove unwanted ones.\n */\n /* allowed element names */\n let ALLOWED_TAGS = null;\n const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);\n /* Allowed attribute names */\n let ALLOWED_ATTR = null;\n const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);\n /*\n * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.\n * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)\n * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)\n * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.\n */\n let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {\n tagNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n attributeNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n allowCustomizedBuiltInElements: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: false\n }\n }));\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\n let FORBID_TAGS = null;\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\n let FORBID_ATTR = null;\n /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */\n const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {\n tagCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n attributeCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n }\n }));\n /* Decide if ARIA attributes are okay */\n let ALLOW_ARIA_ATTR = true;\n /* Decide if custom data attributes are okay */\n let ALLOW_DATA_ATTR = true;\n /* Decide if unknown protocols are okay */\n let ALLOW_UNKNOWN_PROTOCOLS = false;\n /* Decide if self-closing tags in attributes are allowed.\n * Usually removed due to a mXSS issue in jQuery 3.0 */\n let ALLOW_SELF_CLOSE_IN_ATTR = true;\n /* Output should be safe for common template engines.\n * This means, DOMPurify removes data attributes, mustaches and ERB\n */\n let SAFE_FOR_TEMPLATES = false;\n /* Output should be safe even for XML used within HTML and alike.\n * This means, DOMPurify removes comments when containing risky content.\n */\n let SAFE_FOR_XML = true;\n /* Decide if document with ... should be returned */\n let WHOLE_DOCUMENT = false;\n /* Track whether config is already set on this instance of DOMPurify. */\n let SET_CONFIG = false;\n /* Decide if all elements (e.g. style, script) must be children of\n * document.body. By default, browsers might move them to document.head */\n let FORCE_BODY = false;\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported).\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\n */\n let RETURN_DOM = false;\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported) */\n let RETURN_DOM_FRAGMENT = false;\n /* Try to return a Trusted Type object instead of a string, return a string in\n * case Trusted Types are not supported */\n let RETURN_TRUSTED_TYPE = false;\n /* Output should be free from DOM clobbering attacks?\n * This sanitizes markups named with colliding, clobberable built-in DOM APIs.\n */\n let SANITIZE_DOM = true;\n /* Achieve full DOM Clobbering protection by isolating the namespace of named\n * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.\n *\n * HTML/DOM spec rules that enable DOM Clobbering:\n * - Named Access on Window (§7.3.3)\n * - DOM Tree Accessors (§3.1.5)\n * - Form Element Parent-Child Relations (§4.10.3)\n * - Iframe srcdoc / Nested WindowProxies (§4.8.5)\n * - HTMLCollection (§4.2.10.2)\n *\n * Namespace isolation is implemented by prefixing `id` and `name` attributes\n * with a constant string, i.e., `user-content-`\n */\n let SANITIZE_NAMED_PROPS = false;\n const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';\n /* Keep element content when removing element? */\n let KEEP_CONTENT = true;\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\n * of importing it into a new Document and returning a sanitized copy */\n let IN_PLACE = false;\n /* Allow usage of profiles like html, svg and mathMl */\n let USE_PROFILES = {};\n /* Tags to ignore content of when KEEP_CONTENT is true */\n let FORBID_CONTENTS = null;\n const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);\n /* Tags that are safe for data: URIs */\n let DATA_URI_TAGS = null;\n const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);\n /* Attributes safe for values like \"javascript:\" */\n let URI_SAFE_ATTRIBUTES = null;\n const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);\n const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';\n const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';\n /* Document namespace */\n let NAMESPACE = HTML_NAMESPACE;\n let IS_EMPTY_INPUT = false;\n /* Allowed XHTML+XML namespaces */\n let ALLOWED_NAMESPACES = null;\n const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);\n let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);\n let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);\n // Certain elements are allowed in both SVG and HTML\n // namespace. We need to specify them explicitly\n // so that they don't get erroneously deleted from\n // HTML namespace.\n const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);\n /* Parsing of strict XHTML documents */\n let PARSER_MEDIA_TYPE = null;\n const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];\n const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';\n let transformCaseFunc = null;\n /* Keep a reference to config to pass to hooks */\n let CONFIG = null;\n /* Ideally, do not touch anything below this line */\n /* ______________________________________________ */\n const formElement = document.createElement('form');\n const isRegexOrFunction = function isRegexOrFunction(testValue) {\n return testValue instanceof RegExp || testValue instanceof Function;\n };\n /**\n * _parseConfig\n *\n * @param cfg optional config literal\n */\n // eslint-disable-next-line complexity\n const _parseConfig = function _parseConfig() {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n if (CONFIG && CONFIG === cfg) {\n return;\n }\n /* Shield configuration object from tampering */\n if (!cfg || typeof cfg !== 'object') {\n cfg = {};\n }\n /* Shield configuration object from prototype pollution */\n cfg = clone(cfg);\n PARSER_MEDIA_TYPE =\n // eslint-disable-next-line unicorn/prefer-includes\n SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;\n // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.\n transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;\n /* Set configuration parameters */\n ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;\n ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;\n ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;\n URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;\n DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;\n FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;\n FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});\n FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});\n USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;\n ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true\n ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true\n ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false\n ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true\n SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false\n SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true\n WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false\n RETURN_DOM = cfg.RETURN_DOM || false; // Default false\n RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false\n RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false\n FORCE_BODY = cfg.FORCE_BODY || false; // Default false\n SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true\n SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false\n KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true\n IN_PLACE = cfg.IN_PLACE || false; // Default false\n IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;\n NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;\n MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;\n HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;\n CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {\n CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;\n }\n if (SAFE_FOR_TEMPLATES) {\n ALLOW_DATA_ATTR = false;\n }\n if (RETURN_DOM_FRAGMENT) {\n RETURN_DOM = true;\n }\n /* Parse profile info */\n if (USE_PROFILES) {\n ALLOWED_TAGS = addToSet({}, text);\n ALLOWED_ATTR = [];\n if (USE_PROFILES.html === true) {\n addToSet(ALLOWED_TAGS, html$1);\n addToSet(ALLOWED_ATTR, html);\n }\n if (USE_PROFILES.svg === true) {\n addToSet(ALLOWED_TAGS, svg$1);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.svgFilters === true) {\n addToSet(ALLOWED_TAGS, svgFilters);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.mathMl === true) {\n addToSet(ALLOWED_TAGS, mathMl$1);\n addToSet(ALLOWED_ATTR, mathMl);\n addToSet(ALLOWED_ATTR, xml);\n }\n }\n /* Merge configuration parameters */\n if (cfg.ADD_TAGS) {\n if (typeof cfg.ADD_TAGS === 'function') {\n EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;\n } else {\n if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {\n ALLOWED_TAGS = clone(ALLOWED_TAGS);\n }\n addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);\n }\n }\n if (cfg.ADD_ATTR) {\n if (typeof cfg.ADD_ATTR === 'function') {\n EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;\n } else {\n if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {\n ALLOWED_ATTR = clone(ALLOWED_ATTR);\n }\n addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);\n }\n }\n if (cfg.ADD_URI_SAFE_ATTR) {\n addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);\n }\n if (cfg.FORBID_CONTENTS) {\n if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {\n FORBID_CONTENTS = clone(FORBID_CONTENTS);\n }\n addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);\n }\n /* Add #text in case KEEP_CONTENT is set to true */\n if (KEEP_CONTENT) {\n ALLOWED_TAGS['#text'] = true;\n }\n /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */\n if (WHOLE_DOCUMENT) {\n addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);\n }\n /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */\n if (ALLOWED_TAGS.table) {\n addToSet(ALLOWED_TAGS, ['tbody']);\n delete FORBID_TAGS.tbody;\n }\n if (cfg.TRUSTED_TYPES_POLICY) {\n if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.');\n }\n if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.');\n }\n // Overwrite existing TrustedTypes policy.\n trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;\n // Sign local variables required by `sanitize`.\n emptyHTML = trustedTypesPolicy.createHTML('');\n } else {\n // Uninitialized policy, attempt to initialize the internal dompurify policy.\n if (trustedTypesPolicy === undefined) {\n trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);\n }\n // If creating the internal policy succeeded sign internal variables.\n if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {\n emptyHTML = trustedTypesPolicy.createHTML('');\n }\n }\n // Prevent further manipulation of configuration.\n // Not available in IE8, Safari 5, etc.\n if (freeze) {\n freeze(cfg);\n }\n CONFIG = cfg;\n };\n /* Keep track of all possible SVG and MathML tags\n * so that we can perform the namespace checks\n * correctly. */\n const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);\n const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);\n /**\n * @param element a DOM element whose namespace is being checked\n * @returns Return false if the element has a\n * namespace that a spec-compliant parser would never\n * return. Return true otherwise.\n */\n const _checkValidNamespace = function _checkValidNamespace(element) {\n let parent = getParentNode(element);\n // In JSDOM, if we're inside shadow DOM, then parentNode\n // can be null. We just simulate parent in this case.\n if (!parent || !parent.tagName) {\n parent = {\n namespaceURI: NAMESPACE,\n tagName: 'template'\n };\n }\n const tagName = stringToLowerCase(element.tagName);\n const parentTagName = stringToLowerCase(parent.tagName);\n if (!ALLOWED_NAMESPACES[element.namespaceURI]) {\n return false;\n }\n if (element.namespaceURI === SVG_NAMESPACE) {\n // The only way to switch from HTML namespace to SVG\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'svg';\n }\n // The only way to switch from MathML to SVG is via`\n // svg if parent is either or MathML\n // text integration points.\n if (parent.namespaceURI === MATHML_NAMESPACE) {\n return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);\n }\n // We only allow elements that are defined in SVG\n // spec. All others are disallowed in SVG namespace.\n return Boolean(ALL_SVG_TAGS[tagName]);\n }\n if (element.namespaceURI === MATHML_NAMESPACE) {\n // The only way to switch from HTML namespace to MathML\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'math';\n }\n // The only way to switch from SVG to MathML is via\n // and HTML integration points\n if (parent.namespaceURI === SVG_NAMESPACE) {\n return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];\n }\n // We only allow elements that are defined in MathML\n // spec. All others are disallowed in MathML namespace.\n return Boolean(ALL_MATHML_TAGS[tagName]);\n }\n if (element.namespaceURI === HTML_NAMESPACE) {\n // The only way to switch from SVG to HTML is via\n // HTML integration points, and from MathML to HTML\n // is via MathML text integration points\n if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n // We disallow tags that are specific for MathML\n // or SVG and should never appear in HTML namespace\n return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);\n }\n // For XHTML and XML documents that support custom namespaces\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {\n return true;\n }\n // The code should never reach this place (this means\n // that the element somehow got namespace that is not\n // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).\n // Return false just in case.\n return false;\n };\n /**\n * _forceRemove\n *\n * @param node a DOM node\n */\n const _forceRemove = function _forceRemove(node) {\n arrayPush(DOMPurify.removed, {\n element: node\n });\n try {\n // eslint-disable-next-line unicorn/prefer-dom-node-remove\n getParentNode(node).removeChild(node);\n } catch (_) {\n remove(node);\n }\n };\n /**\n * _removeAttribute\n *\n * @param name an Attribute name\n * @param element a DOM node\n */\n const _removeAttribute = function _removeAttribute(name, element) {\n try {\n arrayPush(DOMPurify.removed, {\n attribute: element.getAttributeNode(name),\n from: element\n });\n } catch (_) {\n arrayPush(DOMPurify.removed, {\n attribute: null,\n from: element\n });\n }\n element.removeAttribute(name);\n // We void attribute values for unremovable \"is\" attributes\n if (name === 'is') {\n if (RETURN_DOM || RETURN_DOM_FRAGMENT) {\n try {\n _forceRemove(element);\n } catch (_) {}\n } else {\n try {\n element.setAttribute(name, '');\n } catch (_) {}\n }\n }\n };\n /**\n * _initDocument\n *\n * @param dirty - a string of dirty markup\n * @return a DOM, filled with the dirty markup\n */\n const _initDocument = function _initDocument(dirty) {\n /* Create a HTML document */\n let doc = null;\n let leadingWhitespace = null;\n if (FORCE_BODY) {\n dirty = '' + dirty;\n } else {\n /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */\n const matches = stringMatch(dirty, /^[\\r\\n\\t ]+/);\n leadingWhitespace = matches && matches[0];\n }\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {\n // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)\n dirty = '' + dirty + '';\n }\n const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;\n /*\n * Use the DOMParser API by default, fallback later if needs be\n * DOMParser not work for svg when has multiple root element.\n */\n if (NAMESPACE === HTML_NAMESPACE) {\n try {\n doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);\n } catch (_) {}\n }\n /* Use createHTMLDocument in case DOMParser is not available */\n if (!doc || !doc.documentElement) {\n doc = implementation.createDocument(NAMESPACE, 'template', null);\n try {\n doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;\n } catch (_) {\n // Syntax error if dirtyPayload is invalid xml\n }\n }\n const body = doc.body || doc.documentElement;\n if (dirty && leadingWhitespace) {\n body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);\n }\n /* Work on whole document or just its body */\n if (NAMESPACE === HTML_NAMESPACE) {\n return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];\n }\n return WHOLE_DOCUMENT ? doc.documentElement : body;\n };\n /**\n * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.\n *\n * @param root The root element or node to start traversing on.\n * @return The created NodeIterator\n */\n const _createNodeIterator = function _createNodeIterator(root) {\n return createNodeIterator.call(root.ownerDocument || root, root,\n // eslint-disable-next-line no-bitwise\n NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);\n };\n /**\n * _isClobbered\n *\n * @param element element to check for clobbering attacks\n * @return true if clobbered, false if safe\n */\n const _isClobbered = function _isClobbered(element) {\n return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');\n };\n /**\n * Checks whether the given object is a DOM node.\n *\n * @param value object to check whether it's a DOM node\n * @return true is object is a DOM node\n */\n const _isNode = function _isNode(value) {\n return typeof Node === 'function' && value instanceof Node;\n };\n function _executeHooks(hooks, currentNode, data) {\n arrayForEach(hooks, hook => {\n hook.call(DOMPurify, currentNode, data, CONFIG);\n });\n }\n /**\n * _sanitizeElements\n *\n * @protect nodeName\n * @protect textContent\n * @protect removeChild\n * @param currentNode to check for permission to exist\n * @return true if node was killed, false if left alive\n */\n const _sanitizeElements = function _sanitizeElements(currentNode) {\n let content = null;\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeElements, currentNode, null);\n /* Check if element is clobbered or can clobber */\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Now let's check the element's type and name */\n const tagName = transformCaseFunc(currentNode.nodeName);\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeElement, currentNode, {\n tagName,\n allowedTags: ALLOWED_TAGS\n });\n /* Detect mXSS attempts abusing namespace confusion */\n if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\\w!]/g, currentNode.textContent)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any occurrence of processing instructions */\n if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any kind of possibly harmful comments */\n if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\\w]/g, currentNode.data)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove element if anything forbids its presence */\n if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {\n /* Check if we have a custom element to handle */\n if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {\n return false;\n }\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {\n return false;\n }\n }\n /* Keep content except for bad-listed elements */\n if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {\n const parentNode = getParentNode(currentNode) || currentNode.parentNode;\n const childNodes = getChildNodes(currentNode) || currentNode.childNodes;\n if (childNodes && parentNode) {\n const childCount = childNodes.length;\n for (let i = childCount - 1; i >= 0; --i) {\n const childClone = cloneNode(childNodes[i], true);\n childClone.__removalCount = (currentNode.__removalCount || 0) + 1;\n parentNode.insertBefore(childClone, getNextSibling(currentNode));\n }\n }\n }\n _forceRemove(currentNode);\n return true;\n }\n /* Check whether element has a valid namespace */\n if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Make sure that older browsers don't get fallback-tag mXSS */\n if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\\/no(script|embed|frames)/i, currentNode.innerHTML)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Sanitize element content to be template-safe */\n if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {\n /* Get the element's text content */\n content = currentNode.textContent;\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n content = stringReplace(content, expr, ' ');\n });\n if (currentNode.textContent !== content) {\n arrayPush(DOMPurify.removed, {\n element: currentNode.cloneNode()\n });\n currentNode.textContent = content;\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeElements, currentNode, null);\n return false;\n };\n /**\n * _isValidAttribute\n *\n * @param lcTag Lowercase tag name of containing element.\n * @param lcName Lowercase attribute name.\n * @param value Attribute value.\n * @return Returns true if `value` is valid, otherwise false.\n */\n // eslint-disable-next-line complexity\n const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {\n /* Make sure attribute cannot clobber */\n if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {\n return false;\n }\n /* Allow valid data-* attributes: At least one character after \"-\"\n (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)\n XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)\n We don't need to check the value; it's always URI safe. */\n if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {\n if (\n // First condition does a very basic check if a) it's basically a valid custom element tagname AND\n // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck\n _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||\n // Alternative, second condition checks if it's an `is`-attribute, AND\n // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {\n return false;\n }\n /* Check value is safe. First, is attr inert? If so, is safe */\n } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {\n return false;\n } else ;\n return true;\n };\n /**\n * _isBasicCustomElement\n * checks if at least one dash is included in tagName, and it's not the first char\n * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name\n *\n * @param tagName name of the tag of the node to sanitize\n * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.\n */\n const _isBasicCustomElement = function _isBasicCustomElement(tagName) {\n return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);\n };\n /**\n * _sanitizeAttributes\n *\n * @protect attributes\n * @protect nodeName\n * @protect removeAttribute\n * @protect setAttribute\n *\n * @param currentNode to sanitize\n */\n const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);\n const {\n attributes\n } = currentNode;\n /* Check if we have attributes; if not we might have a text node */\n if (!attributes || _isClobbered(currentNode)) {\n return;\n }\n const hookEvent = {\n attrName: '',\n attrValue: '',\n keepAttr: true,\n allowedAttributes: ALLOWED_ATTR,\n forceKeepAttr: undefined\n };\n let l = attributes.length;\n /* Go backwards over all attributes; safely remove bad ones */\n while (l--) {\n const attr = attributes[l];\n const {\n name,\n namespaceURI,\n value: attrValue\n } = attr;\n const lcName = transformCaseFunc(name);\n const initValue = attrValue;\n let value = name === 'value' ? initValue : stringTrim(initValue);\n /* Execute a hook if present */\n hookEvent.attrName = lcName;\n hookEvent.attrValue = value;\n hookEvent.keepAttr = true;\n hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set\n _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);\n value = hookEvent.attrValue;\n /* Full DOM Clobbering protection via namespace isolation,\n * Prefix id and name attributes with `user-content-`\n */\n if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {\n // Remove the attribute with this value\n _removeAttribute(name, currentNode);\n // Prefix the value and later re-create the attribute with the sanitized value\n value = SANITIZE_NAMED_PROPS_PREFIX + value;\n }\n /* Work around a security issue with comments inside attributes */\n if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\\/(style|title|textarea)/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Make sure we cannot easily use animated hrefs, even if animations are allowed */\n if (lcName === 'attributename' && stringMatch(value, 'href')) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (hookEvent.forceKeepAttr) {\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (!hookEvent.keepAttr) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Work around a security issue in jQuery 3.0 */\n if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\\/>/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Sanitize attribute content to be template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n value = stringReplace(value, expr, ' ');\n });\n }\n /* Is `value` valid for this attribute? */\n const lcTag = transformCaseFunc(currentNode.nodeName);\n if (!_isValidAttribute(lcTag, lcName, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Handle attributes that require Trusted Types */\n if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {\n if (namespaceURI) ; else {\n switch (trustedTypes.getAttributeType(lcTag, lcName)) {\n case 'TrustedHTML':\n {\n value = trustedTypesPolicy.createHTML(value);\n break;\n }\n case 'TrustedScriptURL':\n {\n value = trustedTypesPolicy.createScriptURL(value);\n break;\n }\n }\n }\n }\n /* Handle invalid data-* attribute set by try-catching it */\n if (value !== initValue) {\n try {\n if (namespaceURI) {\n currentNode.setAttributeNS(namespaceURI, name, value);\n } else {\n /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. \"x-schema\". */\n currentNode.setAttribute(name, value);\n }\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n } else {\n arrayPop(DOMPurify.removed);\n }\n } catch (_) {\n _removeAttribute(name, currentNode);\n }\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);\n };\n /**\n * _sanitizeShadowDOM\n *\n * @param fragment to iterate over recursively\n */\n const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {\n let shadowNode = null;\n const shadowIterator = _createNodeIterator(fragment);\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);\n while (shadowNode = shadowIterator.nextNode()) {\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);\n /* Sanitize tags and elements */\n _sanitizeElements(shadowNode);\n /* Check attributes next */\n _sanitizeAttributes(shadowNode);\n /* Deep shadow DOM detected */\n if (shadowNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(shadowNode.content);\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);\n };\n // eslint-disable-next-line complexity\n DOMPurify.sanitize = function (dirty) {\n let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let body = null;\n let importedNode = null;\n let currentNode = null;\n let returnNode = null;\n /* Make sure we have a string to sanitize.\n DO NOT return early, as this will return the wrong type if\n the user has requested a DOM object rather than a string */\n IS_EMPTY_INPUT = !dirty;\n if (IS_EMPTY_INPUT) {\n dirty = '';\n }\n /* Stringify, in case dirty is an object */\n if (typeof dirty !== 'string' && !_isNode(dirty)) {\n if (typeof dirty.toString === 'function') {\n dirty = dirty.toString();\n if (typeof dirty !== 'string') {\n throw typeErrorCreate('dirty is not a string, aborting');\n }\n } else {\n throw typeErrorCreate('toString is not a function');\n }\n }\n /* Return dirty HTML if DOMPurify cannot run */\n if (!DOMPurify.isSupported) {\n return dirty;\n }\n /* Assign config vars */\n if (!SET_CONFIG) {\n _parseConfig(cfg);\n }\n /* Clean up removed elements */\n DOMPurify.removed = [];\n /* Check if dirty is correctly typed for IN_PLACE */\n if (typeof dirty === 'string') {\n IN_PLACE = false;\n }\n if (IN_PLACE) {\n /* Do some early pre-sanitization to avoid unsafe root nodes */\n if (dirty.nodeName) {\n const tagName = transformCaseFunc(dirty.nodeName);\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');\n }\n }\n } else if (dirty instanceof Node) {\n /* If dirty is a DOM element, append to an empty document to avoid\n elements being stripped by the parser */\n body = _initDocument('');\n importedNode = body.ownerDocument.importNode(dirty, true);\n if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {\n /* Node is already a body, use as is */\n body = importedNode;\n } else if (importedNode.nodeName === 'HTML') {\n body = importedNode;\n } else {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n body.appendChild(importedNode);\n }\n } else {\n /* Exit directly if we have nothing to do */\n if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&\n // eslint-disable-next-line unicorn/prefer-includes\n dirty.indexOf('<') === -1) {\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;\n }\n /* Initialize the document to work on */\n body = _initDocument(dirty);\n /* Check we have a DOM node from the data */\n if (!body) {\n return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';\n }\n }\n /* Remove first element node (ours) if FORCE_BODY is set */\n if (body && FORCE_BODY) {\n _forceRemove(body.firstChild);\n }\n /* Get node iterator */\n const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);\n /* Now start iterating over the created document */\n while (currentNode = nodeIterator.nextNode()) {\n /* Sanitize tags and elements */\n _sanitizeElements(currentNode);\n /* Check attributes next */\n _sanitizeAttributes(currentNode);\n /* Shadow DOM detected, sanitize it */\n if (currentNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(currentNode.content);\n }\n }\n /* If we sanitized `dirty` in-place, return it. */\n if (IN_PLACE) {\n return dirty;\n }\n /* Return sanitized string or DOM */\n if (RETURN_DOM) {\n if (RETURN_DOM_FRAGMENT) {\n returnNode = createDocumentFragment.call(body.ownerDocument);\n while (body.firstChild) {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n returnNode.appendChild(body.firstChild);\n }\n } else {\n returnNode = body;\n }\n if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {\n /*\n AdoptNode() is not used because internal state is not reset\n (e.g. the past names map of a HTMLFormElement), this is safe\n in theory but we would rather not risk another attack vector.\n The state that is cloned by importNode() is explicitly defined\n by the specs.\n */\n returnNode = importNode.call(originalDocument, returnNode, true);\n }\n return returnNode;\n }\n let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;\n /* Serialize doctype if allowed */\n if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {\n serializedHTML = '\\n' + serializedHTML;\n }\n /* Sanitize final string template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n serializedHTML = stringReplace(serializedHTML, expr, ' ');\n });\n }\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;\n };\n DOMPurify.setConfig = function () {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n _parseConfig(cfg);\n SET_CONFIG = true;\n };\n DOMPurify.clearConfig = function () {\n CONFIG = null;\n SET_CONFIG = false;\n };\n DOMPurify.isValidAttribute = function (tag, attr, value) {\n /* Initialize shared config vars if necessary. */\n if (!CONFIG) {\n _parseConfig({});\n }\n const lcTag = transformCaseFunc(tag);\n const lcName = transformCaseFunc(attr);\n return _isValidAttribute(lcTag, lcName, value);\n };\n DOMPurify.addHook = function (entryPoint, hookFunction) {\n if (typeof hookFunction !== 'function') {\n return;\n }\n arrayPush(hooks[entryPoint], hookFunction);\n };\n DOMPurify.removeHook = function (entryPoint, hookFunction) {\n if (hookFunction !== undefined) {\n const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);\n return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];\n }\n return arrayPop(hooks[entryPoint]);\n };\n DOMPurify.removeHooks = function (entryPoint) {\n hooks[entryPoint] = [];\n };\n DOMPurify.removeAllHooks = function () {\n hooks = _createHooksMap();\n };\n return DOMPurify;\n}\nvar purify = createDOMPurify();\n\nexport { purify as default };\n//# sourceMappingURL=purify.es.mjs.map\n","/**\n * This class represents all the constants needed in a MathType integration among different classes.\n * If a constant should be used across different classes should be defined using attribute\n * accessors.\n */\nexport default class Constants {\n /**\n * Safe XML entities.\n * @type {Object}\n */\n static get safeXmlCharactersEntities() {\n return {\n tagOpener: \"«\",\n tagCloser: \"»\",\n doubleQuote: \"¨\",\n realDoubleQuote: \""\",\n };\n }\n\n /**\n * Blackboard invalid safe characters.\n * @type {Object}\n */\n static get safeBadBlackboardCharacters() {\n return {\n ltElement: \"«mo»<«/mo»\",\n gtElement: \"«mo»>«/mo»\",\n ampElement: \"«mo»&«/mo»\",\n };\n }\n\n /**\n * Blackboard valid safe characters.\n * @type{Object}\n */\n static get safeGoodBlackboardCharacters() {\n return {\n ltElement: \"«mo»§lt;«/mo»\",\n gtElement: \"«mo»§gt;«/mo»\",\n ampElement: \"«mo»§amp;«/mo»\",\n };\n }\n\n /**\n * Standard XML special characters.\n * @type {Object}\n */\n static get xmlCharacters() {\n return {\n id: \"xmlCharacters\",\n tagOpener: \"<\", // Hex: \\x3C.\n tagCloser: \">\", // Hex: \\x3E.\n doubleQuote: '\"', // Hex: \\x22.\n ampersand: \"&\", // Hex: \\x26.\n quote: \"'\", // Hex: \\x27.\n };\n }\n\n /**\n * Safe XML special characters. This characters are used instead the standard\n * the standard to parse the MathML if safeXML save mode is enable. Each XML\n * special character have a UTF-8 representation.\n * @type {Object}\n */\n static get safeXmlCharacters() {\n return {\n id: \"safeXmlCharacters\",\n tagOpener: \"«\", // Hex: \\xAB.\n tagCloser: \"»\", // Hex: \\xBB.\n doubleQuote: \"¨\", // Hex: \\xA8.\n ampersand: \"§\", // Hex: \\xA7.\n quote: \"`\", // Hex: \\x60.\n realDoubleQuote: \"¨\",\n };\n }\n}\n","import Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a class to manage MathML objects.\n */\nexport default class MathML {\n /**\n * Checks if the mathml at position i is inside an HTML attribute or not.\n * @param {string} content - a string containing MathML code.\n * @param {number} i - search index.\n * @return {boolean} true if is inside an HTML attribute. false otherwise.\n */\n static isMathmlInAttribute(content, i) {\n // Regex =\n // '^[\\'\"][\\\\s]*=[\\\\s]*[\\\\w-]+([\\\\s]*(\"[^\"]*\"|\\'[^\\']*\\')[\\\\s]*\n // =[\\\\s]*[\\\\w-]+[\\\\s]*)*[\\\\s]+gmi<';\n const mathAtt = \"['\\\"][\\\\s]*=[\\\\s]*[\\\\w-]+\"; // \"=att OR '=att\n const attContent = \"\\\"[^\\\"]*\\\"|'[^']*'\"; // \"blabla\" OR 'blabla'\n const att = `[\\\\s]*(${attContent})[\\\\s]*=[\\\\s]*[\\\\w-]+[\\\\s]*`; // \"blabla\"=att OR 'blabla'=att\n const atts = `('${att}')*`; // \"blabla\"=att1 \"blabla\"=att2\n const regex = `^${mathAtt}${atts}[\\\\s]+gmi<`; // \"=att \"blabla\"=att1 \"blabla\"=att2 gmi< .\n const expression = new RegExp(regex);\n\n const actualContent = content.substring(0, i);\n const reversed = actualContent.split(\"\").reverse().join(\"\");\n const exists = expression.test(reversed);\n\n return exists;\n }\n\n /**\n * Decodes an encoded MathML with standard XML tags.\n * We use these entities because IE doesn't support html entities\n * on its attributes sometimes. Yes, sometimes.\n * @param {string} input - string to be decoded.\n * @return {string} decoded string.\n */\n static safeXmlDecode(input) {\n let { tagOpener } = Constants.safeXmlCharactersEntities;\n let { tagCloser } = Constants.safeXmlCharactersEntities;\n let { doubleQuote } = Constants.safeXmlCharactersEntities;\n let { realDoubleQuote } = Constants.safeXmlCharactersEntities;\n // Decoding entities.\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n // Added to fix problem due to import from 1.9.x.\n input = input.split(realDoubleQuote).join(Constants.safeXmlCharacters.realDoubleQuote);\n\n // Blackboard.\n const { ltElement } = Constants.safeBadBlackboardCharacters;\n const { gtElement } = Constants.safeBadBlackboardCharacters;\n const { ampElement } = Constants.safeBadBlackboardCharacters;\n if (\"_wrs_blackboard\" in window && window._wrs_blackboard) {\n input = input.split(ltElement).join(Constants.safeGoodBlackboardCharacters.ltElement);\n input = input.split(gtElement).join(Constants.safeGoodBlackboardCharacters.gtElement);\n input = input.split(ampElement).join(Constants.safeGoodBlackboardCharacters.ampElement);\n }\n\n ({ tagOpener } = Constants.safeXmlCharacters);\n ({ tagCloser } = Constants.safeXmlCharacters);\n ({ doubleQuote } = Constants.safeXmlCharacters);\n ({ realDoubleQuote } = Constants.safeXmlCharacters);\n const { ampersand } = Constants.safeXmlCharacters;\n const { quote } = Constants.safeXmlCharacters;\n\n // Decoding characters.\n input = input.split(tagOpener).join(Constants.xmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.xmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.xmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.xmlCharacters.ampersand);\n input = input.split(quote).join(Constants.xmlCharacters.quote);\n\n // We are replacing $ by & when its part of an entity for retro-compatibility.\n // Now, the standard is replace § by &.\n let returnValue = \"\";\n let currentEntity = null;\n\n for (let i = 0; i < input.length; i += 1) {\n const character = input.charAt(i);\n if (currentEntity == null) {\n if (character === \"$\") {\n currentEntity = \"\";\n } else {\n returnValue += character;\n }\n } else if (character === \";\") {\n returnValue += `&${currentEntity}`;\n currentEntity = null;\n } else if (character.match(/([a-zA-Z0-9#._-] | '-')/)) {\n // Character is part of an entity.\n currentEntity += character;\n } else {\n returnValue += `$${currentEntity}`; // Is not an entity.\n currentEntity = null;\n i -= 1; // Parse again the current character.\n }\n }\n\n return returnValue;\n }\n\n /**\n * Encodes a MathML with standard XML tags to a MMathML encoded with safe XML tags.\n * We use these entities because IE doesn't support html entities on its attributes sometimes.\n * @param {string} input - input string to be encoded\n * @returns {string} encoded string.\n */\n static safeXmlEncode(input) {\n const { tagOpener } = Constants.xmlCharacters;\n const { tagCloser } = Constants.xmlCharacters;\n const { doubleQuote } = Constants.xmlCharacters;\n const { ampersand } = Constants.xmlCharacters;\n const { quote } = Constants.xmlCharacters;\n\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.safeXmlCharacters.ampersand);\n input = input.split(quote).join(Constants.safeXmlCharacters.quote);\n\n return input;\n }\n\n /**\n * Converts special symbols (> 128) to entities and replaces all textual\n * entities by its number entities.\n * @param {string} mathml - MathML string containing - or not - special symbols\n * @returns {string} MathML with all textual entities replaced.\n */\n static mathMLEntities(mathml) {\n let toReturn = \"\";\n\n for (let i = 0; i < mathml.length; i += 1) {\n const character = mathml.charAt(i);\n\n // Parsing > 128 characters.\n if (mathml.codePointAt(i) > 128) {\n toReturn += `&#${mathml.codePointAt(i)};`;\n // For UTF-32 characters we need to move the index one position.\n if (mathml.codePointAt(i) > 0xffff) {\n i += 1;\n }\n } else if (character === \"&\") {\n const end = mathml.indexOf(\";\", i + 1);\n if (end >= 0) {\n const container = document.createElement(\"span\");\n container.innerHTML = mathml.substring(i, end + 1);\n toReturn += `&#${Util.fixedCharCodeAt(container.textContent || container.innerText, 0)};`;\n i = end;\n } else {\n toReturn += character;\n }\n } else {\n toReturn += character;\n }\n }\n\n return toReturn;\n }\n\n /**\n * Add a custom editor name with the prefix wrs_ to a MathML class attribute.\n * @param {string} mathml - a MathML string created with a custom editor, like chemistry.\n * @param {string} customEditor - custom editor name.\n * @returns {string} MathML string with his class containing the editor toolbar string.\n */\n static addCustomEditorClassAttribute(mathml, customEditor) {\n let toReturn = \"\";\n\n const start = mathml.indexOf(\"\");\n if (mathml.indexOf(\"class\") === -1) {\n // Adding custom editor type.\n toReturn = `${mathml.substr(start, end)} class=\"wrs_${customEditor}\">`;\n toReturn += mathml.substr(end + 1, mathml.length);\n return toReturn;\n }\n }\n return mathml;\n }\n\n /**\n * Remove a custom editor name from the MathML class attribute.\n * @param {string} mathml - a MathML string.\n * @param {string} customEditor - custom editor name.\n * @returns {string} The input MathML without customEditor name in his class.\n */\n static removeCustomEditorClassAttribute(mathml, customEditor) {\n // Discard MathML without the specified class.\n if (mathml.indexOf(\"class\") === -1 || mathml.indexOf(`wrs_${customEditor}`) === -1) {\n return mathml;\n }\n\n // Trivial case: class attribute value equal to editor name. Then\n // class attribute is removed.\n // First try to remove it with a space before if there is one\n // Otherwise without the space\n if (mathml.indexOf(` class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(` class=\"wrs_${customEditor}\"`, \"\");\n }\n if (mathml.indexOf(`class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(`class=\"wrs_${customEditor}\"`, \"\");\n }\n\n // Non Trivial case: class attribute contains editor name.\n return mathml.replace(`wrs_${customEditor}`, \"\");\n }\n\n /**\n * Adds annotation tag in MathML element.\n * @param {String} mathml - valid MathML.\n * @param {String} content - value to put inside annotation tag.\n * @param {String} annotationEncoding - annotation encoding.\n * @returns {String} - 'mathml' with an annotation that contains\n * 'content' and encoding 'encoding'.\n */\n static addAnnotation(mathml, content, annotationEncoding) {\n // If contains annotation, also contains semantics tag.\n const containsAnnotation = mathml.indexOf(\"\");\n mathmlWithAnnotation = `${mathml.substring(0, closeSemanticsIndex)}${content}${mathml.substring(closeSemanticsIndex)}`;\n } else if (MathML.isEmpty(mathml)) {\n const endIndexInline = mathml.indexOf(\"/>\");\n const endIndexNonInline = mathml.indexOf(\">\");\n const endIndex = endIndexNonInline === endIndexInline ? endIndexInline : endIndexNonInline;\n mathmlWithAnnotation = `${mathml.substring(0, endIndex)}>${content}`;\n } else {\n const beginMathMLContent = mathml.indexOf(\">\") + 1;\n const endMathmlContent = mathml.lastIndexOf(\"\");\n const mathmlContent = mathml.substring(beginMathMLContent, endMathmlContent);\n mathmlWithAnnotation = `${mathml.substring(0, beginMathMLContent)}${mathmlContent}${content}`; // eslint-disable-line max-len\n }\n\n return mathmlWithAnnotation;\n }\n\n /**\n * Removes specific annotation tag in MathML element.\n * In case of remove the unique annotation, also is removed semantics tag.\n * @param {String} mathml - valid MathML.\n * @param {String} annotationEncoding - annotation encoding to remove.\n * @returns {String} - 'mathml' without the annotation encoding specified.\n */\n static removeAnnotation(mathml, annotationEncoding) {\n let mathmlWithoutAnnotation = mathml;\n const openAnnotationTag = ``;\n const closeAnnotationTag = \"\";\n const startAnnotationIndex = mathml.indexOf(openAnnotationTag);\n if (startAnnotationIndex !== -1) {\n let differentAnnotationFound = false;\n let differentAnnotationIndex = mathml.indexOf(\"\\s*?()?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsEndingTagRegex = /(<\\/mrow>)?\\s*/gm;\n\n return mathml.replace(semanticsStartingTagRegex, \"\").replace(semanticsEndingTagRegex, \"\");\n }\n\n /**\n * Removes semantics tag to element that contains mathml.\n * When using Hand to create formulas, it adds the mrow tag due to the semantics one, this one is also removed.\n * @param {string} element - Inner HTML text string.\n * @returns {string} - 'mathml' without semantics tag.\n */\n static removeSafeXMLSemantics(element) {\n // If `mrow` is found right before the `semantics` starting tag, it's removed as well\n const semanticsSafeStartingTagRegex = /«semantics»\\s*?(«mrow»)?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsSafeEndingTagRegex = /(«\\/mrow»)?\\s*«annotation[\\W\\w]*?«\\/semantics»/gm;\n\n return element.replace(semanticsSafeStartingTagRegex, \"\").replace(semanticsSafeEndingTagRegex, \"\");\n }\n\n /**\n * Transforms all xml mathml occurrences that contain semantics to the same\n * xml mathml occurrences without semantics.\n * @param {string} text - string that can contain xml mathml occurrences.\n * @param {Constants} [characters] - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * xmlCharacters by default.\n * @returns {string} - 'text' with all xml mathml occurrences without annotation tag.\n */\n static removeSemanticsOcurrences(text, characters = Constants.xmlCharacters) {\n const mathTagStart = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const mathTagEndline = `/${characters.tagCloser}`;\n const { tagCloser } = characters;\n const semanticsTagStart = `${characters.tagOpener}semantics${characters.tagCloser}`;\n const annotationTagStart = `${characters.tagOpener}annotation encoding=`;\n\n let output = \"\";\n let start = text.indexOf(mathTagStart);\n let end = 0;\n while (start !== -1) {\n output += text.substring(end, start);\n\n // MathML can be written as '' or ''.\n const mathTagEndIndex = text.indexOf(mathTagEnd, start);\n const mathTagEndlineIndex = text.indexOf(mathTagEndline, start);\n const firstTagCloser = text.indexOf(tagCloser, start);\n if (mathTagEndIndex !== -1) {\n end = mathTagEndIndex;\n } else if (mathTagEndlineIndex === firstTagCloser - 1) {\n end = mathTagEndlineIndex;\n }\n\n const semanticsIndex = text.indexOf(semanticsTagStart, start);\n if (semanticsIndex !== -1) {\n const mmlTagStart = text.substring(start, semanticsIndex);\n const annotationIndex = text.indexOf(annotationTagStart, start);\n if (annotationIndex !== -1) {\n const startIndex = semanticsIndex + semanticsTagStart.length;\n const mmlContent = text.substring(startIndex, annotationIndex);\n output += mmlTagStart + mmlContent + mathTagEnd;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n end += mathTagEnd.length;\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n }\n\n output += text.substring(end, text.length);\n return output;\n }\n\n /**\n * Returns true if a MathML contains a certain class.\n * @param {string} mathML - input MathML.\n * @param {string} className - className.\n * @returns {boolean} true if the input MathML contains the input class.\n * false otherwise.\n * @static\n */\n static containClass(mathML, className) {\n const classIndex = mathML.indexOf(\"class\");\n if (classIndex === -1) {\n return false;\n }\n const classTagEndIndex = mathML.indexOf(\">\", classIndex);\n const classTag = mathML.substring(classIndex, classTagEndIndex);\n if (classTag.indexOf(className) !== -1) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns true if mathml is empty. Otherwise, false.\n * @param {string} mathml - valid MathML with standard XML tags.\n * @returns {boolean} - true if mathml is empty. Otherwise, false.\n */\n static isEmpty(mathml) {\n // MathML can have the shape or ''.\n const closeTag = \">\";\n const closeTagInline = \"/>\";\n const firstCloseTagIndex = mathml.indexOf(closeTag);\n const firstCloseTagInlineIndex = mathml.indexOf(closeTagInline);\n let empty = false;\n // MathML is always empty in the second shape.\n if (firstCloseTagInlineIndex !== -1) {\n if (firstCloseTagInlineIndex === firstCloseTagIndex - 1) {\n empty = true;\n }\n }\n\n // MathML is always empty in the first shape when there aren't elements\n // between math tags.\n if (!empty) {\n const mathTagEndRegex = new RegExp(\"\");\n const mathTagEndArray = mathTagEndRegex.exec(mathml);\n if (mathTagEndArray) {\n empty = firstCloseTagIndex + 1 === mathTagEndArray.index;\n }\n }\n\n return empty;\n }\n\n /**\n * Encodes html entities inside properties.\n * @param {String} mathml - valid MathML with standard XML tags.\n * @returns {String} - 'mathml' with property entities encoded.\n */\n static encodeProperties(mathml) {\n // Search all the properties.\n const regex = /\\w+=\".*?\"/g;\n // Encode html entities.\n const replacer = (match) => {\n // It has the shape:\n // .\n const quoteIndex = match.indexOf('\"');\n const propertyValue = match.substring(quoteIndex + 1, match.length - 1);\n const propertyValueEncoded = Util.htmlEntities(propertyValue);\n const matchEncoded = `${match.substring(0, quoteIndex + 1)}${propertyValueEncoded}\"`;\n return matchEncoded;\n };\n\n const mathmlEncoded = mathml.replace(regex, replacer);\n return mathmlEncoded;\n }\n}\n","/**\n * This class represents the configuration class.\n * Usually used to retrieve configuration properties generated in the backend into the frontend.\n */\nexport default class Configuration {\n /**\n * Adds a properties object to {@link Configuration.properties}.\n * @param {Object} properties - properties to append to current properties.\n */\n static addConfiguration(properties) {\n Object.assign(Configuration.properties, properties);\n }\n\n /**\n * Static property.\n * The configuration properties object.\n * @private\n * @type {Object}\n */\n static get properties() {\n return Configuration._properties;\n }\n\n /**\n * Static property setter.\n * Set configuration properties.\n * @param {Object} value - The property value.\n * @ignore\n */\n static set properties(value) {\n Configuration._properties = value;\n }\n\n /**\n * Returns the value of a property key.\n * @param {String} key - Property key\n * @returns {String} Property value\n */\n static get(key) {\n if (!Object.prototype.hasOwnProperty.call(Configuration.properties, key)) {\n // Backwards compatibility.\n if (Object.prototype.hasOwnProperty.call(Configuration.properties, \"_wrs_conf_\")) {\n return Configuration.properties[`_wrs_conf_${key}`];\n }\n return false;\n }\n return Configuration.properties[key];\n }\n\n /**\n * Adds a new property to Configuration class.\n * @param {String} key - Property key.\n * @param {Object} value - Property value.\n */\n static set(key, value) {\n Configuration.properties[key] = value;\n }\n\n /**\n * Updates a property object value with new values.\n * @param {String} key - The property key to be updated.\n * @param {Object} propertyValue - Object containing the new values.\n */\n static update(key, propertyValue) {\n if (!Configuration.get(key)) {\n Configuration.set(key, propertyValue);\n } else {\n const updateProperty = Object.assign(Configuration.get(key), propertyValue);\n Configuration.set(key, updateProperty);\n }\n }\n}\n\n/**\n * Static properties object. Stores all configuration properties.\n * Needed to attribute accessors.\n * @private\n * @type {Object}\n */\nConfiguration._properties = {};\n","export default class TextCache {\n /**\n * @classdesc\n * This class represent a client-side text cache class. Contains pairs of\n * strings (key/value) which can be retrieved in any moment. Usually used\n * to store AJAX responses for text services like mathml2latex\n * (c.f {@link Latex} class) or mathml2accessible (c.f {@link Accessibility} class).\n * @constructs\n */\n constructor() {\n /**\n * Cache array property storing the cache entries.\n * @type {Array.}\n */\n this.cache = [];\n }\n\n /**\n * This method populates a key/value pair into the {@link this.cache} property.\n * @param {String} key - Cache key, usually the service string parameter.\n * @param {String} value - Cache value, usually the service response.\n */\n populate(key, value) {\n this.cache[key] = value;\n }\n\n /**\n * Returns the cache value associated to certain cache key.\n * @param {String} key - Cache key, usually the service string parameter.\n * @return {String} value - Cache value, if exists. False otherwise.\n */\n get(key) {\n if (Object.prototype.hasOwnProperty.call(this.cache, key)) {\n return this.cache[key];\n }\n return false;\n }\n}\n","/**\n * This object represents a custom listener.\n * @typedef {Object} Listener\n * @property {String} Listener.eventName - The listener name.\n * @property {Function} Listener.callback - The listener callback function.\n */\n\nexport default class Listeners {\n /**\n * @classdesc\n * This class represents a custom listeners manager.\n * @constructs\n */\n constructor() {\n /**\n * Array containing all custom listeners.\n * @type {Object[]}\n */\n this.listeners = [];\n }\n\n /**\n * Add a listener to Listener class.\n * @param {Object} listener - A listener object.\n */\n add(listener) {\n this.listeners.push(listener);\n }\n\n /**\n * Fires MathType event listeners\n * @param {String} eventName - event name\n * @param {Event} event - event object.\n * @return {boolean} false if event has been prevented. true otherwise.\n */\n fire(eventName, event) {\n for (let i = 0; i < this.listeners.length && !event.cancelled; i += 1) {\n if (this.listeners[i].eventName === eventName) {\n // Calling listener.\n this.listeners[i].callback(event);\n }\n }\n return event.defaultPrevented;\n }\n\n /**\n * Creates a new listener object.\n * @param {string} eventName - Event name.\n * @param {Object} callback - Callback function.\n * @returns {object} the listener object.\n */\n static newListener(eventName, callback) {\n const listener = {};\n listener.eventName = eventName;\n listener.callback = callback;\n return listener;\n }\n}\n","import Util from \"./util\";\nimport Listeners from \"./listeners\";\nimport Configuration from \"./configuration\";\n\n/**\n * @typedef {Object} ServiceProviderProperties\n * @property {String} URI - Service URI.\n * @property {String} server - Service server language.\n */\n\n/**\n * @classdesc\n * Class representing a serviceProvider. A serviceProvider is a class containing\n * an arbitrary number of services with the correspondent path.\n */\nexport default class ServiceProvider {\n /**\n * Returns Service Provider listeners.\n * @type {Listeners}\n */\n static get listeners() {\n return ServiceProvider._listeners;\n }\n\n /**\n * Adds a {@link Listener} instance to {@link ServiceProvider} class.\n * @param {Listener} listener - Instance of {@link Listener}.\n */\n static addListener(listener) {\n ServiceProvider.listeners.add(listener);\n }\n\n /**\n * Fires events in Service Provider.\n * @param {String} eventName - Event name.\n * @param {Event} event - Event object.\n */\n static fireEvent(eventName, event) {\n ServiceProvider.listeners.fire(eventName, event);\n }\n\n /**\n * Service parameters.\n * @type {ServiceProviderProperties}\n *\n */\n static get parameters() {\n return ServiceProvider._parameters;\n }\n\n /**\n * Service parameters.\n * @private\n * @type {ServiceProviderProperties}\n */\n static set parameters(parameters) {\n ServiceProvider._parameters = parameters;\n }\n\n /**\n * Static property.\n * Return service provider paths.\n * @private\n * @type {String}\n */\n static get servicePaths() {\n return ServiceProvider._servicePaths;\n }\n\n /**\n * Static property setter.\n * Set service paths.\n * @param {String} value - The property value.\n * @ignore\n */\n static set servicePaths(value) {\n ServiceProvider._servicePaths = value;\n }\n\n /**\n * Adds a new service to the ServiceProvider.\n * @param {String} service - Service name.\n * @param {String} path - Service path.\n * @static\n */\n static setServicePath(service, path) {\n ServiceProvider.servicePaths[service] = path;\n }\n\n /**\n * Returns the service path for a certain service.\n * @param {String} serviceName - Service name.\n * @returns {String} The service path.\n * @static\n */\n static getServicePath(serviceName) {\n return ServiceProvider.servicePaths[serviceName];\n }\n\n /**\n * Static property.\n * Service provider integration path.\n * @type {String}\n */\n static get integrationPath() {\n return ServiceProvider._integrationPath;\n }\n\n /**\n * Static property setter.\n * Set service provider integration path.\n * @param {String} value - The property value.\n * @ignore\n */\n static set integrationPath(value) {\n ServiceProvider._integrationPath = value;\n }\n\n /**\n * Returns the server URL in the form protocol://serverName:serverPort.\n * @return {String} The client side server path.\n */\n static getServerURL() {\n const url = window.location.href;\n const arr = url.split(\"/\");\n const result = `${arr[0]}//${arr[2]}`;\n return result;\n }\n\n /**\n * Inits {@link this} class. Uses {@link this.integrationPath} as\n * base path to generate all backend services paths.\n * @param {Object} parameters - Function parameters.\n * @param {String} parameters.integrationPath - Service path.\n */\n static init(parameters) {\n ServiceProvider.parameters = parameters;\n // Services path (tech dependant).\n let configurationURI = ServiceProvider.createServiceURI(\"configurationjs\");\n let createImageURI = ServiceProvider.createServiceURI(\"createimage\");\n let showImageURI = ServiceProvider.createServiceURI(\"showimage\");\n let getMathMLURI = ServiceProvider.createServiceURI(\"getmathml\");\n let serviceURI = ServiceProvider.createServiceURI(\"service\");\n\n // Some backend integrations (like Java o Ruby) have an absolute backend path,\n // for example: /app/service. For them we calculate the absolute URL path, i.e\n // protocol://domain:port/app/service\n if (ServiceProvider.parameters.URI.indexOf(\"/\") === 0) {\n const serverPath = ServiceProvider.getServerURL();\n configurationURI = serverPath + configurationURI;\n showImageURI = serverPath + showImageURI;\n createImageURI = serverPath + createImageURI;\n getMathMLURI = serverPath + getMathMLURI;\n serviceURI = serverPath + serviceURI;\n }\n\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n ServiceProvider.setServicePath(\"showimage\", showImageURI);\n ServiceProvider.setServicePath(\"createimage\", createImageURI);\n ServiceProvider.setServicePath(\"service\", serviceURI);\n ServiceProvider.setServicePath(\"getmathml\", getMathMLURI);\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n\n ServiceProvider.listeners.fire(\"onInit\", {});\n }\n\n /**\n * Gets the content from an URL.\n * @param {String} url - Target URL.\n * @param {Object} [postVariables] - Object containing post variables.\n * null if a GET query should be done.\n * @returns {String} Content of the target URL.\n * @private\n * @static\n */\n static getUrl(url, postVariables) {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n const httpRequest = Util.createHttpRequest();\n\n if (httpRequest) {\n if (typeof postVariables === \"undefined\" || typeof postVariables === \"undefined\") {\n httpRequest.open(\"GET\", url, false);\n } else if (url.substr(0, 1) === \"/\" || url.substr(0, 7) === \"http://\" || url.substr(0, 8) === \"https://\") {\n httpRequest.open(\"POST\", url, false);\n } else {\n httpRequest.open(\"POST\", currentPath + url, false);\n }\n\n let header = Configuration.get(\"customHeaders\");\n if (header) {\n if (typeof header === \"string\") {\n header = Util.convertStringToObject(header);\n }\n Object.entries(header).forEach(([key, val]) => httpRequest.setRequestHeader(key, val));\n }\n\n if (typeof postVariables !== \"undefined\" && postVariables) {\n httpRequest.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded; charset=UTF-8\");\n httpRequest.send(Util.httpBuildQuery(postVariables));\n } else {\n httpRequest.send(null);\n }\n\n return httpRequest.responseText;\n }\n return \"\";\n }\n\n /**\n * Returns the response text of a certain service.\n * @param {String} service - Service name.\n * @param {String} postVariables - Post variables.\n * @param {Boolean} get - True if the request is GET instead of POST. false otherwise.\n * @returns {String} Service response text.\n */\n static getService(service, postVariables, get) {\n let response;\n if (get === true) {\n const getVariables = postVariables ? `?${postVariables}` : \"\";\n const serviceUrl = `${ServiceProvider.getServicePath(service)}${getVariables}`;\n response = ServiceProvider.getUrl(serviceUrl);\n } else {\n const serviceUrl = ServiceProvider.getServicePath(service);\n response = ServiceProvider.getUrl(serviceUrl, postVariables);\n }\n return response;\n }\n\n /**\n * Returns the server language of a certain service. The possible values\n * are: php, aspx, java and ruby.\n * This method has backward compatibility purposes.\n * @param {String} service - The configuration service.\n * @returns {String} - The server technology associated with the configuration service.\n */\n static getServerLanguageFromService(service) {\n if (service.indexOf(\".php\") !== -1) {\n return \"php\";\n }\n if (service.indexOf(\".aspx\") !== -1) {\n return \"aspx\";\n }\n if (service.indexOf(\"wirispluginengine\") !== -1) {\n return \"ruby\";\n }\n return \"java\";\n }\n\n /**\n * Returns the URI associated with a certain service.\n * @param {String} service - The service name.\n * @return {String} The service path.\n */\n static createServiceURI(service) {\n const extension = ServiceProvider.serverExtension();\n return Util.concatenateUrl(ServiceProvider.parameters.URI, service) + extension;\n }\n\n static serverExtension() {\n if (ServiceProvider.parameters.server.indexOf(\"php\") !== -1) {\n return \".php\";\n }\n if (ServiceProvider.parameters.server.indexOf(\"aspx\") !== -1) {\n return \".aspx\";\n }\n return \"\";\n }\n}\n\n/**\n * @property {String} service - The service name.\n * @property {String} path - The service path.\n * @static\n */\nServiceProvider._servicePaths = {};\n\n/**\n * The integration path. Contains the path of the configuration service.\n * Used to define the path for all services.\n * @type {String}\n * @private\n */\nServiceProvider._integrationPath = \"\";\n\n/**\n * ServiceProvider static listeners.\n * @type {Listeners}\n * @private\n */\nServiceProvider._listeners = new Listeners();\n\n/**\n * Service provider parameters.\n * @type {ServiceProviderParameters}\n */\nServiceProvider._parameters = {};\n","import TextCache from \"./textcache\";\nimport MathML from \"./mathml\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a LaTeX parser. Manages the services which allows to convert\n * LaTeX into MathML and MathML into LaTeX.\n */\nexport default class Latex {\n /**\n * Static property.\n * Return latex cache.\n * @private\n * @type {Cache}\n */\n static get cache() {\n return Latex._cache;\n }\n\n /**\n * Static property setter.\n * Set latex cache.\n * @param {Cache} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Latex._cache = value;\n }\n\n /**\n * Converts MathML to LaTeX by calling mathml2latex service. For text services\n * we call a text service with the param mathml2latex.\n * @param {String} mathml - MathML String.\n * @return {String} LaTeX string generated by the MathML argument.\n */\n static getLatexFromMathML(mathml) {\n const mathmlWithoutSemantics = MathML.removeSemantics(mathml);\n /**\n * @type {TextCache}\n */\n const { cache } = Latex;\n\n const data = {\n service: \"mathml2latex\",\n mml: mathmlWithoutSemantics,\n };\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n // TODO: Error handling.\n let latex = \"\";\n\n if (jsonResponse.status === \"ok\") {\n latex = jsonResponse.result.text;\n const latexHtmlEntitiesEncoded = Util.htmlEntities(latex);\n // Inserting LaTeX semantics.\n const mathmlWithSemantics = MathML.addAnnotation(mathml, latexHtmlEntitiesEncoded, \"LaTeX\");\n cache.populate(latex, mathmlWithSemantics);\n }\n\n return latex;\n }\n\n /**\n * Converts LaTeX to MathML by calling latex2mathml service. For text services\n * we call a text service with the param latex2mathml.\n * @param {String} latex - String containing a LaTeX formula.\n * @param {Boolean} includeLatexOnSemantics\n * - If true LaTeX would me included into MathML semantics.\n * @return {String} MathML string generated by the LaTeX argument.\n */\n static getMathMLFromLatex(latex, includeLatexOnSemantics) {\n /**\n * @type {TextCache}\n */\n const latexCache = Latex.cache;\n\n if (Latex.cache.get(latex)) {\n return Latex.cache.get(latex);\n }\n const data = {\n service: \"latex2mathml\",\n latex,\n };\n\n if (includeLatexOnSemantics) {\n data.saveLatex = \"\";\n }\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n let output;\n if (jsonResponse.status === \"ok\") {\n let mathml = jsonResponse.result.text;\n mathml = mathml.split(\"\\r\").join(\"\").split(\"\\n\").join(\" \");\n\n // Populate LatexCache.\n if (mathml.indexOf(\"semantics\") === -1 && mathml.indexOf(\"annotation\") === -1) {\n const content = Util.htmlEntities(latex);\n mathml = MathML.addAnnotation(mathml, content, \"LaTeX\");\n output = mathml;\n } else {\n output = mathml;\n }\n if (!latexCache.get(latex)) {\n latexCache.populate(latex, mathml);\n }\n } else {\n output = `$$${latex}$$`;\n }\n return output;\n }\n\n /**\n * Converts all occurrences of MathML code to LaTeX.\n * The MathML code should containing to be converted.\n * @param {String} content - A string containing MathML valid code.\n * @param {Object} characters - An object containing special characters.\n * @return {String} A string containing all MathML annotated occurrences\n * replaced by the corresponding LaTeX code.\n */\n static parseMathmlToLatex(content, characters) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const openTarget = `${characters.tagOpener}annotation encoding=${characters.doubleQuote}LaTeX${characters.doubleQuote}${characters.tagCloser}`;\n const closeTarget = `${characters.tagOpener}/annotation${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n let mathml;\n let startAnnotation;\n let closeAnnotation;\n\n while (start !== -1) {\n output += content.substring(end, start);\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else {\n end += mathTagEnd.length;\n }\n\n mathml = content.substring(start, end);\n\n startAnnotation = mathml.indexOf(openTarget);\n if (startAnnotation !== -1) {\n startAnnotation += openTarget.length;\n closeAnnotation = mathml.indexOf(closeTarget);\n let latex = mathml.substring(startAnnotation, closeAnnotation);\n if (characters === Constants.safeXmlCharacters) {\n latex = MathML.safeXmlDecode(latex);\n }\n output += `$$${latex}$$`;\n // Populate latex into cache.\n\n Latex.cache.populate(latex, mathml);\n } else {\n output += mathml;\n }\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n\n /**\n * Extracts the latex of a determined position in a text.\n * @param {Node} textNode - textNode to extract the LaTeX\n * @param {Number} caretPosition - Starting position to find LaTeX.\n * @param {Object} latexTags - Optional parameter representing tags between latex is inserted.\n * It has the 'open' attribute for the open tag and the 'close' attribute for the close tag.\n * \"$$\" by default.\n * @return {Object} An object with 3 keys: 'latex', 'start' and 'end'. Null if latex is not found.\n * @static\n */\n static getLatexFromTextNode(textNode, caretPosition, latexTags) {\n // TODO: Set LaTeX Tags as Core variable. Fix the call to this function (third argument).\n // Tags used for LaTeX formulas.\n const defaultLatexTags = {\n open: \"$$\",\n close: \"$$\",\n };\n // latexTags is an optional parameter. If is not set, use default latexTags.\n if (typeof latexTags === \"undefined\" || latexTags == null) {\n latexTags = defaultLatexTags;\n }\n // Looking for the first textNode.\n let startNode = textNode;\n\n while (startNode.previousSibling && startNode.previousSibling.nodeType === 3) {\n // TEXT_NODE.\n startNode = startNode.previousSibling;\n }\n\n /**\n * Returns the next latex position and node from a specific node and position.\n * @param {Node} currentNode - Node where searching latex.\n * @param {Number} currentPosition - Current position inside the currentNode.\n * @param {Object} latexTagsToUse - Tags used at latex beginning and latex final.\n * \"$$\" by default.\n * @param {Boolean} tag - Tag containing the current search.\n * @returns {Object} Object containing the current node and the position.\n */\n function getNextLatexPosition(currentNode, currentPosition, tag) {\n let position = currentNode.nodeValue.indexOf(tag, currentPosition);\n\n while (position === -1) {\n currentNode = currentNode.nextSibling;\n\n if (!currentNode) {\n // TEXT_NODE.\n return null; // Not found.\n }\n\n position = currentNode.nodeValue ? currentNode.nodeValue.indexOf(latexTags.close) : -1;\n }\n\n return {\n node: currentNode,\n position,\n };\n }\n\n /**\n * Determines if a node is previous, or not, to a second one.\n * @param {Node} node - Start node.\n * @param {Number} position - Start node position.\n * @param {Node} endNode - End node.\n * @param {Number} endPosition - End node position.\n * @returns {Boolean} True if the starting node is previous thant the en node. false otherwise.\n */\n function isPrevious(node, position, endNode, endPosition) {\n if (node === endNode) {\n return position <= endPosition;\n }\n while (node && node !== endNode) {\n node = node.nextSibling;\n }\n\n return node === endNode;\n }\n\n let start;\n let end = {\n node: startNode,\n position: 0,\n };\n // Is supposed that open and close tags has the same length.\n const tagLength = latexTags.open.length;\n do {\n start = getNextLatexPosition(end.node, end.position, latexTags.open);\n\n if (start == null || isPrevious(textNode, caretPosition, start.node, start.position)) {\n return null;\n }\n\n end = getNextLatexPosition(start.node, start.position + tagLength, latexTags.close);\n\n if (end == null) {\n return null;\n }\n\n end.position += tagLength;\n } while (isPrevious(end.node, end.position, textNode, caretPosition));\n\n // Isolating latex.\n let latex;\n\n if (start.node === end.node) {\n latex = start.node.nodeValue.substring(start.position + tagLength, end.position - tagLength);\n } else {\n const index = start.position + tagLength;\n latex = start.node.nodeValue.substring(index, start.node.nodeValue.length);\n let currentNode = start.node;\n\n do {\n currentNode = currentNode.nextSibling;\n if (currentNode === end.node) {\n latex += end.node.nodeValue.substring(0, end.position - tagLength);\n } else {\n latex += currentNode.nodeValue ? currentNode.nodeValue : \"\";\n }\n } while (currentNode !== end.node);\n }\n\n return {\n latex,\n startNode: start.node,\n startPosition: start.position,\n endNode: end.node,\n endPosition: end.position,\n };\n }\n}\n\n/**\n * Text cache. Stores all processed LaTeX strings and it's correspondent MathML string.\n * @type {Cache}\n * @static\n */\nLatex._cache = new TextCache();\n","import translations from \"../lang/strings.json\";\n/**\n * This class represents a string manager. It's used to load localized strings.\n */\nexport default class StringManager {\n constructor() {\n throw new Error(\"Static class StringManager can not be instantiated.\");\n }\n\n /**\n * Returns the associated value of certain string key. If the associated value\n * doesn't exits returns the original key.\n * @param {string} key - string key\n * @param {string} lang - DEFAULT = null. Specify the language to translate the string\n * @returns {string} correspondent value. If doesn't exists original key.\n */\n static get(key, lang) {\n // Default language definition\n let { language } = this;\n\n // If parameter language, use it\n if (lang) {\n language = lang;\n }\n\n // Cut down on strings. e.g. en_US -> en\n if (language && language.length > 2) {\n language = language.slice(0, 2);\n }\n\n // Check if we support the language\n if (!this.strings.hasOwnProperty(language)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown language ${language} set in StringManager.`);\n language = \"en\";\n }\n\n // Check if the key is supported in the given language\n if (!this.strings[language].hasOwnProperty(key)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown key ${key} for language ${language} in StringManager.`);\n return key;\n }\n\n return this.strings[language][key];\n }\n}\n\n/**\n * Dictionary of dictionaries:\n * Key: language code\n * Value: Key: id of the string\n * Value: translation of the string\n */\nStringManager.strings = translations;\n\n/**\n * Language of the translations; English by default\n */\nStringManager.language = \"en\";\n","/* eslint-disable no-bitwise */\nimport DOMPurify from \"dompurify\";\nimport MathML from \"./mathml\";\nimport Configuration from \"./configuration\";\nimport Latex from \"./latex\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * This class represents an utility class.\n */\nexport default class Util {\n /**\n * Fires an event in a target.\n * @param {EventTarget} eventTarget - target where event should be fired.\n * @param {string} eventName event to fire.\n * @static\n */\n static fireEvent(eventTarget, eventName) {\n if (document.createEvent) {\n const eventObject = document.createEvent(\"HTMLEvents\");\n eventObject.initEvent(eventName, true, true);\n return !eventTarget.dispatchEvent(eventObject);\n }\n\n const eventObject = document.createEventObject();\n return eventTarget.fireEvent(`on${eventName}`, eventObject);\n }\n\n /**\n * Cross-browser addEventListener/attachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - callback function.\n * @static\n */\n static addEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.addEventListener) {\n eventTarget.addEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.attachEvent) {\n // Backwards compatibility.\n eventTarget.attachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * Cross-browser removeEventListener/detachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - function to remove from the event target.\n * @static\n */\n static removeEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.removeEventListener) {\n eventTarget.removeEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.detachEvent) {\n eventTarget.detachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * A map from event target to event handlers so we can remove the event\n * listeners in removeElementEvents\n *\n * @type {Map}\n * @static\n */\n static elementEventsMap = new Map();\n\n /**\n * Adds the a callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @param {Function} doubleClickHandler - function to run when on dblclick event.\n * @param {Function} mousedownHandler - function to run when on mousedown event.\n * @param {Function} mouseupHandler - function to run when on mouseup event.\n * @static\n */\n static addElementEvents(eventTarget, doubleClickHandler, mousedownHandler, mouseupHandler) {\n // Make sure not to leak event listeners if we've already added events to\n // this element\n Util.removeElementEvents(eventTarget);\n\n let entry = {};\n Util.elementEventsMap.set(eventTarget, entry);\n\n if (doubleClickHandler) {\n entry.callbackDblclick = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n doubleClickHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"dblclick\", entry.callbackDblclick);\n }\n\n if (mousedownHandler) {\n entry.callbackMousedown = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mousedownHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"mousedown\", entry.callbackMousedown);\n }\n\n if (mouseupHandler) {\n entry.callbackMouseup = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mouseupHandler(element, realEvent);\n };\n // Chrome doesn't trigger this event for eventTarget if we release the mouse button\n // while the mouse is outside the editor text field.\n // This is a workaround: we trigger the event independently of where the mouse\n // is when we release its button.\n Util.addEvent(document, \"mouseup\", entry.callbackMouseup);\n Util.addEvent(eventTarget, \"mouseup\", entry.callbackMouseup);\n }\n }\n\n /**\n * Remove all callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @static\n */\n static removeElementEvents(eventTarget) {\n let entry = Util.elementEventsMap.get(eventTarget);\n if (!entry) {\n return;\n }\n\n Util.elementEventsMap.delete(eventTarget);\n\n Util.removeEvent(eventTarget, \"dblclick\", entry.callbackDblclick);\n Util.removeEvent(eventTarget, \"mousedown\", entry.callbackMousedown);\n Util.removeEvent(document, \"mouseup\", entry.callbackMouseup);\n Util.removeEvent(eventTarget, \"mouseup\", entry.callbackMouseup);\n }\n\n /**\n * Adds a class name to a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static addClass(element, className) {\n if (!Util.containsClass(element, className)) {\n element.className += ` ${className}`;\n }\n }\n\n /**\n * Checks if a HTMLElement contains a certain class.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the className.\n * @returns {boolean} true if the HTMLElement contains the class name. false otherwise.\n * @static\n */\n static containsClass(element, className) {\n if (element == null || !(\"className\" in element)) {\n return false;\n }\n\n const currentClasses = element.className.split(\" \");\n\n for (let i = currentClasses.length - 1; i >= 0; i -= 1) {\n if (currentClasses[i] === className) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Remove a certain class for a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static removeClass(element, className) {\n let newClassName = \"\";\n const classes = element.className.split(\" \");\n\n for (let i = 0; i < classes.length; i += 1) {\n if (classes[i] !== className) {\n newClassName += `${classes[i]} `;\n }\n }\n element.className = newClassName.trim();\n }\n\n /**\n * Converts old xml initial text attribute (with «») to the correct one(with §lt;§gt;). It's\n * used to parse old applets.\n * @param {string} text - string containing safeXml characters\n * @returns {string} a string with safeXml characters parsed.\n * @static\n */\n static convertOldXmlinitialtextAttribute(text) {\n // Used to fix a bug with Cas imported from Moodle 1.9 to Moodle 2.x.\n // This could be removed in future.\n const val = \"value=\";\n\n const xitpos = text.indexOf(\"xmlinitialtext\");\n const valpos = text.indexOf(val, xitpos);\n const quote = text.charAt(valpos + val.length);\n const startquote = valpos + val.length + 1;\n const endquote = text.indexOf(quote, startquote);\n\n const value = text.substring(startquote, endquote);\n\n let newvalue = value.split(\"«\").join(\"§lt;\");\n newvalue = newvalue.split(\"»\").join(\"§gt;\");\n newvalue = newvalue.split(\"&\").join(\"§\");\n newvalue = newvalue.split(\"¨\").join(\"§quot;\");\n\n text = text.split(value).join(newvalue);\n return text;\n }\n\n /**\n * Convert a string representation of key-value pairs to an object.\n * @param {string} keyValueString - String with key-value pairs in the format key1='value1', key2='value2'\n * @returns {Object} - Object containing the key-value pairs\n */\n static convertStringToObject(keyValueString) {\n if (!keyValueString || typeof keyValueString !== \"string\") {\n return {};\n }\n\n return keyValueString\n .split(\",\")\n .map((pair) => pair.trim().split(\"=\"))\n .reduce((resultObject, [key, value]) => {\n if (key && value) {\n resultObject[key] = value;\n }\n return resultObject;\n }, {});\n }\n\n /**\n * Cross-browser solution for creating new elements.\n * @param {string} tagName - tag name of the wished element.\n * @param {Object} attributes - an object where each key is a wished\n * attribute name and each value is its value.\n * @param {Object} [creator] - if supplied, this function will use\n * the \"createElement\" method from this param. Otherwise\n * document will be used as creator.\n * @returns {Element} The DOM element with the specified attributes assigned.\n * @static\n */\n static createElement(tagName, attributes, creator) {\n if (attributes === undefined) {\n attributes = {};\n }\n\n if (creator === undefined) {\n creator = document;\n }\n\n let element;\n\n /*\n * Internet Explorer fix:\n * If you create a new object dynamically, you can't set a non-standard attribute.\n * For example, you can't set the \"src\" attribute on an \"applet\" object.\n * Other browsers will throw an exception and will run the standard code.\n */\n try {\n let html = `<${tagName}`;\n\n Object.keys(attributes).forEach((attributeName) => {\n html += ` ${attributeName}=\"${Util.htmlEntities(attributes[attributeName])}\"`;\n });\n html += \">\";\n element = creator.createElement(html);\n } catch (e) {\n element = creator.createElement(tagName);\n Object.keys(attributes).forEach((attributeName) => {\n element.setAttribute(attributeName, attributes[attributeName]);\n });\n }\n return element;\n }\n\n /**\n * Creates new HTML from it's HTML code as string.\n * @param {string} objectCode - html code\n * @returns {Element} the HTML element.\n * @static\n */\n static createObject(objectCode, creator) {\n if (creator === undefined) {\n creator = document;\n }\n\n // Internet Explorer can't include \"param\" tag when is setting an innerHTML property.\n objectCode = objectCode\n .split(\"\").join(\"\").split(\"\").join(\"\");\n\n objectCode = objectCode\n .split(\"\").join(\"
\").split(\"\").join(\"
\");\n\n const container = Util.createElement(\"div\", {}, creator);\n container.innerHTML = objectCode;\n\n function recursiveParamsFix(object) {\n if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisParam\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const param = Util.createElement(\"param\", attributesParsed, creator);\n\n // IE fix.\n if (param.NAME) {\n param.name = param.NAME;\n param.value = param.VALUE;\n }\n\n param.removeAttribute(\"wirisObject\");\n object.parentNode.replaceChild(param, object);\n } else if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisApplet\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const applet = Util.createElement(\"applet\", attributesParsed, creator);\n applet.removeAttribute(\"wirisObject\");\n\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n\n if (object.childNodes[i].nodeName.toLowerCase() === \"param\") {\n applet.appendChild(object.childNodes[i]);\n i -= 1; // When we insert the object child into the applet, object loses one child.\n }\n }\n\n object.parentNode.replaceChild(applet, object);\n } else {\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n }\n }\n }\n\n recursiveParamsFix(container);\n return container.firstChild;\n }\n\n /**\n * Converts an Element to its HTML code.\n * @param {Element} element - entry element.\n * @return {string} the HTML code of the input element.\n * @static\n */\n static createObjectCode(element) {\n // In case that the image was not created, the object can be null or undefined.\n if (typeof element === \"undefined\" || element === null) {\n return null;\n }\n\n if (element.nodeType === 1) {\n // ELEMENT_NODE.\n let output = `<${element.tagName}`;\n\n for (let i = 0; i < element.attributes.length; i += 1) {\n if (element.attributes[i].specified) {\n output += ` ${element.attributes[i].name}=\"${Util.htmlEntities(element.attributes[i].value)}\"`;\n }\n }\n\n if (element.childNodes.length > 0) {\n output += \">\";\n\n for (let i = 0; i < element.childNodes.length; i += 1) {\n output += Util.createObject(element.childNodes[i]);\n }\n\n output += ``;\n } else if (element.nodeName === \"DIV\" || element.nodeName === \"SCRIPT\") {\n output += `>`;\n } else {\n output += \"/>\";\n }\n\n return output;\n }\n\n if (element.nodeType === 3) {\n // TEXT_NODE.\n return Util.htmlEntities(element.nodeValue);\n }\n\n return \"\";\n }\n\n /**\n * Concatenates two URL paths.\n * @param {string} path1 - first URL path\n * @param {string} path2 - second URL path\n * @returns {string} new URL.\n */\n static concatenateUrl(path1, path2) {\n let separator = \"\";\n if (path1.indexOf(\"/\") !== path1.length && path2.indexOf(\"/\") !== 0) {\n separator = \"/\";\n }\n return (path1 + separator + path2).replace(/([^:]\\/)\\/+/g, \"$1\");\n }\n\n /**\n * Parses a text and replaces all HTML special characters by their correspondent entities.\n * @param {string} input - text to be parsed.\n * @returns {string} the input text with all their special characters replaced by their entities.\n * @static\n */\n static htmlEntities(input) {\n return input.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\").split('\"').join(\""\");\n }\n\n /**\n * Sanitize HTML to prevent XSS injections.\n * @param {string} html - html to be sanitize.\n * @returns {string} html sanitized.\n * @static\n */\n static htmlSanitize(html) {\n const annotationRegex = /\\/;\n // Get all the annotation content including the tags.\n const annotation = html.match(annotationRegex);\n // Sanitize html code without removing our supported MathML tags and attributes.\n html = DOMPurify.sanitize(html, {\n ADD_TAGS: [\"semantics\", \"annotation\", \"mstack\", \"msline\", \"msrow\", \"none\"],\n ADD_ATTR: [\"linebreak\", \"charalign\", \"stackalign\"],\n });\n // Readd old annotation content.\n return html.replace(annotationRegex, annotation);\n }\n\n /**\n * Parses a text and replaces all the HTML entities by their characters.\n * @param {string} input - text to be parsed\n * @returns {string} the input text with all their entities replaced by characters.\n * @static\n */\n static htmlEntitiesDecode(input) {\n // Textarea element decodes when inner html is set.\n const textarea = document.createElement(\"textarea\");\n textarea.innerHTML = input;\n return textarea.value;\n }\n\n /**\n * Returns a cross-browser http request.\n * @return {object} httpRequest request object.\n * @returns {XMLHttpRequest|ActiveXObject} the proper request object.\n */\n static createHttpRequest() {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n if (currentPath.substr(0, 7) === \"file://\") {\n throw StringManager.get(\"exception_cross_site\");\n }\n\n if (typeof XMLHttpRequest !== \"undefined\") {\n return new XMLHttpRequest();\n }\n\n try {\n return new ActiveXObject(\"Msxml2.XMLHTTP\");\n } catch (e) {\n try {\n return new ActiveXObject(\"Microsoft.XMLHTTP\");\n } catch (oc) {\n return null;\n }\n }\n }\n\n /**\n * Converts a hash to a HTTP query.\n * @param {Object[]} properties - a key/value object.\n * @returns {string} a HTTP query containing all the key value pairs with\n * all the special characters replaced by their entities.\n * @static\n */\n static httpBuildQuery(properties) {\n let result = \"\";\n\n Object.keys(properties).forEach((i) => {\n if (properties[i] != null) {\n result += `${Util.urlEncode(i)}=${Util.urlEncode(properties[i])}&`;\n }\n });\n\n // Deleting last '&' empty character.\n if (result.substring(result.length - 1) === \"&\") {\n result = result.substring(0, result.length - 1);\n }\n\n return result;\n }\n\n /**\n * Convert a hash to string sorting keys to get a deterministic output\n * @param {Object[]} hash - a key/value object.\n * @returns {string} a string with the form key1=value1...keyn=valuen\n * @static\n */\n static propertiesToString(hash) {\n // 1. Sort keys. We sort the keys because we want a deterministic output.\n const keys = [];\n Object.keys(hash).forEach((key) => {\n if (Object.prototype.hasOwnProperty.call(hash, key)) {\n keys.push(key);\n }\n });\n\n const n = keys.length;\n for (let i = 0; i < n; i += 1) {\n for (let j = i + 1; j < n; j += 1) {\n const s1 = keys[i];\n const s2 = keys[j];\n if (Util.compareStrings(s1, s2) > 0) {\n // Swap.\n keys[i] = s2;\n keys[j] = s1;\n }\n }\n }\n\n // 2. Generate output.\n let output = \"\";\n for (let i = 0; i < n; i += 1) {\n const key = keys[i];\n output += key;\n output += \"=\";\n let value = hash[key];\n value = value.replace(\"\\\\\", \"\\\\\\\\\");\n value = value.replace(\"\\n\", \"\\\\n\");\n value = value.replace(\"\\r\", \"\\\\r\");\n value = value.replace(\"\\t\", \"\\\\t\");\n\n output += value;\n output += \"\\n\";\n }\n return output;\n }\n\n /**\n * Compare two strings using charCodeAt method\n * @param {string} a - first string to compare.\n * @param {string} b - second string to compare.\n * @returns {number} the difference between a and b\n * @static\n */\n static compareStrings(a, b) {\n let i;\n const an = a.length;\n const bn = b.length;\n const n = an > bn ? bn : an;\n for (i = 0; i < n; i += 1) {\n const c = Util.fixedCharCodeAt(a, i) - Util.fixedCharCodeAt(b, i);\n if (c !== 0) {\n return c;\n }\n }\n return a.length - b.length;\n }\n\n /**\n * Fix charCodeAt() JavaScript function to handle non-Basic-Multilingual-Plane characters.\n * @param {string} string - input string\n * @param {number} idx - an integer greater than or equal to 0\n * and less than the length of the string\n * @returns {number} an integer representing the UTF-16 code of the string at the given index.\n * @static\n */\n static fixedCharCodeAt(string, idx) {\n idx = idx || 0;\n const code = string.charCodeAt(idx);\n let hi;\n let low;\n\n /* High surrogate (could change last hex to 0xDB7F to treat high\n private surrogates as single characters) */\n\n if (code >= 0xd800 && code <= 0xdbff) {\n hi = code;\n low = string.charCodeAt(idx + 1);\n if (Number.isNaN(low)) {\n throw StringManager.get(\"exception_high_surrogate\");\n }\n return (hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;\n }\n\n if (code >= 0xdc00 && code <= 0xdfff) {\n // Low surrogate.\n /* We return false to allow loops to skip this iteration since should have\n already handled high surrogate above in the previous iteration. */\n return false;\n }\n return code;\n }\n\n /**\n * Returns an URL with it's query params converted into array.\n * @param {string} url - input URL.\n * @returns {Object[]} an array containing all URL query params.\n * @static\n */\n static urlToAssArray(url) {\n let i;\n i = url.indexOf(\"?\");\n if (i > 0) {\n const query = url.substring(i + 1);\n const ss = query.split(\"&\");\n const h = {};\n for (i = 0; i < ss.length; i += 1) {\n const s = ss[i];\n const kv = s.split(\"=\");\n if (kv.length > 1) {\n h[kv[0]] = decodeURIComponent(kv[1].replace(/\\+/g, \" \"));\n }\n }\n return h;\n }\n return {};\n }\n\n /**\n * Returns an encoded URL by replacing each instance of certain characters by\n * one, two, three or four escape sequences using encodeURIComponent method.\n * !'()* . will not be encoded.\n *\n * @param {string} clearString - URL string to be encoded\n * @returns {string} URL with it's special characters replaced.\n * @static\n */\n static urlEncode(clearString) {\n let output = \"\";\n // Method encodeURIComponent doesn't encode !'()*~ .\n output = encodeURIComponent(clearString);\n return output;\n }\n\n // TODO: To parser?\n /**\n * Converts the HTML of a image into the output code that WIRIS must return.\n * By default returns the MathML stored on data-mahml attribute (if imgCode is a formula)\n * or the Wiriscas attribute of a WIRIS applet.\n * @param {string} imgCode - the html code from a formula or a CAS image.\n * @param {boolean} convertToXml - true if the image should be converted to XML.\n * @param {boolean} convertToSafeXml - true if the image should be converted to safeXML.\n * @returns {string} the XML or safeXML of a WIRIS image.\n * @static\n */\n static getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml) {\n const imgObject = Util.createObject(imgCode);\n if (imgObject) {\n if (\n imgObject.className === Configuration.get(\"imageClassName\") ||\n imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"))\n ) {\n if (!convertToXml) {\n return imgCode;\n }\n\n const dataMathML = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n // To handle annotations, first we need the MathML in XML.\n let mathML = MathML.safeXmlDecode(dataMathML);\n\n if (!Configuration.get(\"saveHandTraces\")) {\n mathML = MathML.removeAnnotation(mathML, \"application/json\");\n }\n\n if (mathML == null) {\n mathML = imgObject.getAttribute(\"alt\");\n }\n\n if (convertToSafeXml) {\n const safeMathML = MathML.safeXmlEncode(mathML);\n return safeMathML;\n }\n\n return mathML;\n }\n }\n return imgCode;\n }\n\n /**\n * Gets the node length in characters.\n * @param {Node} node - HTML node.\n * @returns {number} node length.\n * @static\n */\n static getNodeLength(node) {\n const staticNodeLengths = {\n IMG: 1,\n BR: 1,\n };\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return node.nodeValue.length;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n let length = staticNodeLengths[node.nodeName.toUpperCase()];\n\n if (length === undefined) {\n length = 0;\n }\n\n for (let i = 0; i < node.childNodes.length; i += 1) {\n length += Util.getNodeLength(node.childNodes[i]);\n }\n return length;\n }\n return 0;\n }\n\n /**\n * Gets a selected node or text from an editable HTMLElement.\n * If the caret is on a text node, concatenates it with all the previous and next text nodes.\n * @param {HTMLElement} target - the editable HTMLElement.\n * @param {boolean} isIframe - specifies if the target is an iframe or not\n * @param {boolean} forceGetSelection - if true, ignores IE system to get\n * the current selection and uses window.getSelection()\n * @returns {object} an object with the 'node' key set if the item is an\n * element or the keys 'node' and 'caretPosition' if the element is text.\n * @static\n */\n static getSelectedItem(target, isIframe, forceGetSelection) {\n let windowTarget;\n\n if (isIframe) {\n windowTarget = target.contentWindow;\n windowTarget.focus();\n } else {\n windowTarget = window;\n target.focus();\n }\n\n if (document.selection && !forceGetSelection) {\n const range = windowTarget.document.selection.createRange();\n\n if (range.parentElement) {\n if (range.htmlText.length > 0) {\n if (range.text.length === 0) {\n return Util.getSelectedItem(target, isIframe, true);\n }\n\n return null;\n }\n\n windowTarget.document.execCommand(\"InsertImage\", false, \"#\");\n let temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() !== \"IMG\") {\n // IE9 fix: parentElement() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML('');\n temporalObject = windowTarget.document.getElementById(\"wrs_openEditorWindow_temporalObject\");\n }\n\n let node;\n let caretPosition;\n\n if (temporalObject.nextSibling && temporalObject.nextSibling.nodeType === 3) {\n // TEXT_NODE.\n node = temporalObject.nextSibling;\n caretPosition = 0;\n } else if (temporalObject.previousSibling && temporalObject.previousSibling.nodeType === 3) {\n node = temporalObject.previousSibling;\n caretPosition = node.nodeValue.length;\n } else {\n node = windowTarget.document.createTextNode(\"\");\n temporalObject.parentNode.insertBefore(node, temporalObject);\n caretPosition = 0;\n }\n\n temporalObject.parentNode.removeChild(temporalObject);\n\n return {\n node,\n caretPosition,\n };\n }\n\n if (range.length > 1) {\n return null;\n }\n\n return {\n node: range.item(0),\n };\n }\n\n if (windowTarget.getSelection) {\n let range;\n const selection = windowTarget.getSelection();\n\n try {\n range = selection.getRangeAt(0);\n } catch (e) {\n range = windowTarget.document.createRange();\n }\n\n const node = range.startContainer;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return {\n node,\n caretPosition: range.startOffset,\n };\n }\n\n if (node !== range.endContainer) {\n return null;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n const position = range.startOffset;\n\n if (node.childNodes[position]) {\n // In case that a formula is detected but not selected,\n // we create an empty span where we could insert the new formula.\n if (range.startOffset === range.endOffset) {\n if (\n position !== 0 &&\n node.childNodes[position - 1].localName === \"span\" &&\n node.childNodes[position].classList?.contains(\"Wirisformula\")\n ) {\n node.childNodes[position - 1].remove();\n return Util.getSelectedItem(target, isIframe, forceGetSelection);\n }\n if (node.childNodes[position].classList?.contains(\"Wirisformula\")) {\n if (\n (position > 0 && node.childNodes[position - 1].classList?.contains(\"Wirisformula\")) ||\n position === 0\n ) {\n const emptySpan = document.createElement(\"span\");\n node.insertBefore(emptySpan, node.childNodes[position]);\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n\n return null;\n }\n\n /**\n * Returns null if there isn't any item or if it is malformed.\n * Otherwise returns an object containing the node with the MathML image\n * and the cursor position inside the textarea.\n * @param {HTMLTextAreaElement} textarea - textarea element.\n * @returns {Object} An object containing the node, the index of the\n * beginning of the selected text, caret position and the start and end position of the\n * text node.\n * @static\n */\n static getSelectedItemOnTextarea(textarea) {\n const textNode = document.createTextNode(textarea.value);\n const textNodeValues = Latex.getLatexFromTextNode(textNode, textarea.selectionStart);\n if (textNodeValues === null) {\n return null;\n }\n\n return {\n node: textNode,\n caretPosition: textarea.selectionStart,\n startPosition: textNodeValues.startPosition,\n endPosition: textNodeValues.endPosition,\n };\n }\n\n /**\n * Looks for elements that match the given name in a HTML code string.\n * Important: this function is very concrete for WIRIS code.\n * It takes as preconditions lots of behaviors that are not the general case.\n * @param {string} code - HTML code.\n * @param {string} name - element name.\n * @param {boolean} autoClosed - true if the elements are autoClosed.\n * @return {Object[]} an object containing all HTML elements of code matching the name argument.\n * @static\n */\n static getElementsByNameFromString(code, name, autoClosed) {\n const elements = [];\n code = code.toLowerCase();\n name = name.toLowerCase();\n let start = code.indexOf(`<${name} `);\n\n while (start !== -1) {\n // Look for nodes.\n let endString;\n\n if (autoClosed) {\n endString = \">\";\n } else {\n endString = ``;\n }\n\n let end = code.indexOf(endString, start);\n\n if (end !== -1) {\n end += endString.length;\n elements.push({\n start,\n end,\n });\n } else {\n end = start + 1;\n }\n\n start = code.indexOf(`<${name} `, end);\n }\n\n return elements;\n }\n\n /**\n * Returns the numeric value of a base64 character.\n * @param {string} character - base64 character.\n * @returns {number} base64 character numeric value.\n * @static\n */\n static decode64(character) {\n const PLUS = \"+\".charCodeAt(0);\n const SLASH = \"/\".charCodeAt(0);\n const NUMBER = \"0\".charCodeAt(0);\n const LOWER = \"a\".charCodeAt(0);\n const UPPER = \"A\".charCodeAt(0);\n const PLUS_URL_SAFE = \"-\".charCodeAt(0);\n const SLASH_URL_SAFE = \"_\".charCodeAt(0);\n const code = character.charCodeAt(0);\n\n if (code === PLUS || code === PLUS_URL_SAFE) {\n return 62; // Char '+'.\n }\n if (code === SLASH || code === SLASH_URL_SAFE) {\n return 63; // Char '/'.\n }\n if (code < NUMBER) {\n return -1; // No match.\n }\n if (code < NUMBER + 10) {\n return code - NUMBER + 26 + 26;\n }\n if (code < UPPER + 26) {\n return code - UPPER;\n }\n if (code < LOWER + 26) {\n return code - LOWER + 26;\n }\n\n return null;\n }\n\n /**\n * Converts a base64 string to a array of bytes.\n * @param {string} b64String - base64 string.\n * @param {number} length - dimension of byte array (by default whole string).\n * @return {Object[]} the resultant byte array.\n * @static\n */\n static b64ToByteArray(b64String, length) {\n let tmp;\n\n if (b64String.length % 4 > 0) {\n throw new Error(\"Invalid string. Length must be a multiple of 4\"); // Tipped base64. Length is fixed.\n }\n\n const arr = [];\n\n let l;\n let placeHolders;\n if (!length) {\n // All b64String string.\n if (b64String.charAt(b64String.length - 2) === \"=\") {\n placeHolders = 2;\n } else if (b64String.charAt(b64String.length - 1) === \"=\") {\n placeHolders = 1;\n } else {\n placeHolders = 0;\n }\n l = placeHolders > 0 ? b64String.length - 4 : b64String.length;\n } else {\n l = length;\n }\n\n let i;\n for (i = 0; i < l; i += 4) {\n // Ignoring code checker standards (bitewise operators).\n // See https://tracker.moodle.org/browse/CONTRIB-5862 for further information.\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 18) |\n (Util.decode64(b64String.charAt(i + 1)) << 12) |\n (Util.decode64(b64String.charAt(i + 2)) << 6) |\n Util.decode64(b64String.charAt(i + 3));\n\n arr.push((tmp >> 16) & 0xff);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n\n if (placeHolders) {\n if (placeHolders === 2) {\n // Ignoring code checker standards (bitewise operators).\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp = (Util.decode64(b64String.charAt(i)) << 2) | (Util.decode64(b64String.charAt(i + 1)) >> 4);\n arr.push(tmp & 0xff);\n } else if (placeHolders === 1) {\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 10) |\n (Util.decode64(b64String.charAt(i + 1)) << 4) |\n (Util.decode64(b64String.charAt(i + 2)) >> 2);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n }\n return arr;\n }\n\n /**\n * Returns the first 32-bit signed integer from a byte array.\n * @param {Object[]} bytes - array of bytes.\n * @returns {number} the 32-bit signed integer.\n * @static\n */\n static readInt32(bytes) {\n if (bytes.length < 4) {\n return false;\n }\n const int32 = bytes.splice(0, 4);\n // @codingStandardsIgnoreStart¡\n return (int32[0] << 24) | (int32[1] << 16) | (int32[2] << 8) | (int32[3] << 0);\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read the first byte from a byte array.\n * @param {Object} bytes - input byte array.\n * @returns {number} first byte of the byte array.\n * @static\n */\n static readByte(bytes) {\n // @codingStandardsIgnoreStart\n return bytes.shift() << 0;\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read an arbitrary number of bytes, from a fixed position on a byte array.\n * @param {Object[]} bytes - byte array.\n * @param {number} pos - start position.\n * @param {number} len - number of bytes to read.\n * @returns {Object[]} the byte array.\n * @static\n */\n static readBytes(bytes, pos, len) {\n return bytes.splice(pos, len);\n }\n\n /**\n * Inserts or modifies formulas or CAS on a textarea.\n * @param {HTMLTextAreaElement} textarea - textarea target.\n * @param {string} text - text to add in the textarea. For example, to add the link to the image,\n * call this function as (textarea, Parser.createImageSrc(mathml));\n * @static\n */\n static updateTextArea(textarea, text) {\n if (textarea && text) {\n textarea.focus();\n\n if (textarea.selectionStart != null) {\n const { selectionEnd } = textarea;\n const selectionStart = textarea.value.substring(0, textarea.selectionStart);\n const selectionEndSub = textarea.value.substring(selectionEnd, textarea.value.length);\n textarea.value = selectionStart + text + selectionEndSub;\n textarea.selectionEnd = selectionEnd + text.length;\n } else {\n const selection = document.selection.createRange();\n selection.text = text;\n }\n }\n }\n\n /**\n * Modifies existing formula on a textarea.\n * @param {HTMLTextAreaElement} textarea - text area target.\n * @param {string} text - text to add in the textarea. For example, if you want to add the link\n * to the image,you can call this function as\n * Util.updateTextarea(textarea, Parser.createImageSrc(mathml));\n * @param {number} start - beginning index from textarea where it needs to be replaced by text.\n * @param {number} end - ending index from textarea where it needs to be replaced by text\n * @static\n */\n static updateExistingTextOnTextarea(textarea, text, start, end) {\n textarea.focus();\n const textareaStart = textarea.value.substring(0, start);\n textarea.value = textareaStart + text + textarea.value.substring(end, textarea.value.length);\n textarea.selectionEnd = start + text.length;\n }\n\n /**\n * Add a parameter with it's correspondent value to an URL (GET).\n * @param {string} path - URL path\n * @param {string} parameter - parameter\n * @param {string} value - value\n * @static\n */\n static addArgument(path, parameter, value) {\n let sep;\n if (path.indexOf(\"?\") > 0) {\n sep = \"&\";\n } else {\n sep = \"?\";\n }\n return `${path + sep + parameter}=${value}`;\n }\n}\n","import Configuration from \"./configuration\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents MathType Image class. Contains all the logic related\n * to MathType images manipulation.\n * All MathType images are generated using the appropriate MathType\n * integration service: showimage or createimage.\n *\n * There are two available image formats:\n * - svg (default)\n * - png\n *\n * There are two formats for the image src attribute:\n * - A data-uri scheme containing the URL-encoded SVG or a PNG's base64.\n * - A link to the showimage service.\n */\nexport default class Image {\n /**\n * Removes data attributes from an image.\n * @param {HTMLImageElement} img - Image where remove data attributes.\n */\n static removeImgDataAttributes(img) {\n const attributesToRemove = [];\n const { attributes } = img;\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key];\n if (attribute !== undefined && attribute.name !== undefined && attribute.name.indexOf(\"data-\") === 0) {\n // Is preferred keep an array and remove after the search\n // because when attribute is removed the array of attributes\n // is modified.\n attributesToRemove.push(attribute.name);\n }\n });\n\n attributesToRemove.forEach((attribute) => {\n img.removeAttribute(attribute);\n });\n }\n\n /**\n * @static\n * Clones all MathType image attributes from a HTMLImageElement to another.\n * @param {HTMLImageElement} originImg - The original image.\n * @param {HTMLImageElement} destImg - The destination image.\n */\n static clone(originImg, destImg) {\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (!originImg.hasAttribute(customEditorAttributeName)) {\n destImg.removeAttribute(customEditorAttributeName);\n }\n\n const mathmlAttributeName = Configuration.get(\"imageMathmlAttribute\");\n const imgAttributes = [\n mathmlAttributeName,\n customEditorAttributeName,\n \"alt\",\n \"height\",\n \"width\",\n \"style\",\n \"src\",\n \"role\",\n ];\n\n imgAttributes.forEach((iterator) => {\n const originAttribute = originImg.getAttribute(iterator);\n if (originAttribute) {\n destImg.setAttribute(iterator, originAttribute);\n }\n });\n }\n\n /**\n * Determines whether an img src contains an SVG.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src contains an SVG, false otherwise\n */\n static isSvg(img) {\n return img.src.startsWith(\"data:image/svg+xml;\");\n }\n\n /**\n * Determines whether an img src is encoded in base64 or not.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src is encoded in base64, false otherwise\n */\n static isBase64(img) {\n return img.src.startsWith(\"data:image/svg+xml;base64,\") || img.src.startsWith(\"data:image/png;base64,\");\n }\n\n /**\n * Calculates the metrics of a MathType image given the the service response and the image format.\n * @param {HTMLImageElement} img - The HTMLImageElement.\n * @param {String} uri - The URI generated by the image service: can be a data URI scheme or a URL.\n * @param {Boolean} jsonResponse - True the response of the image service is a\n * JSON object. False otherwise.\n */\n static setImgSize(img, uri, jsonResponse) {\n let ar;\n let base64String;\n let bytes;\n let svgString;\n if (jsonResponse) {\n // Cleaning data:image/png;base64.\n if (Image.isSvg(img)) {\n // SVG format.\n // If SVG is encoded in base64 we need to convert the base64 bytes into a SVG string.\n if (!Image.isBase64(img)) {\n ar = Image.getMetricsFromSvgString(uri);\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n svgString = \"\";\n bytes = Util.b64ToByteArray(base64String, base64String.length);\n for (let i = 0; i < bytes.length; i += 1) {\n svgString += String.fromCharCode(bytes[i]);\n }\n ar = Image.getMetricsFromSvgString(svgString);\n }\n // PNG format: we store all metrics information in the first 88 bytes.\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n bytes = Util.b64ToByteArray(base64String, 88);\n ar = Image.getMetricsFromBytes(bytes);\n }\n // Backwards compatibility: we store the metrics into createimage response.\n } else {\n ar = Util.urlToAssArray(uri);\n }\n let width = ar.cw;\n if (!width) {\n return;\n }\n let height = ar.ch;\n let baseline = ar.cb;\n const { dpi } = ar;\n if (dpi) {\n width = (width * 96) / dpi;\n height = (height * 96) / dpi;\n baseline = (baseline * 96) / dpi;\n }\n img.width = width;\n img.height = height;\n img.style.verticalAlign = `-${height - baseline}px`;\n }\n\n /**\n * Calculates the metrics of an image which has been resized. Is used to restore the original\n * metrics of a resized image.\n * @param {HTMLImageElement } img - The resized HTMLImageElement.\n */\n static fixAfterResize(img) {\n img.removeAttribute(\"style\");\n img.removeAttribute(\"width\");\n img.removeAttribute(\"height\");\n // In order to avoid resize with max-width css property.\n img.style.maxWidth = \"none\";\n\n const processImg = (img) => {\n if (img.src.indexOf(\"data:image\") !== -1) {\n if (img.src.indexOf(\"data:image/svg+xml\") !== -1) {\n // Image is in base64: decode it in order to calculate the size, and then bring it back to base64\n // This is a bit of an ugly hack used to recycle the logic of Image.setImgSize instead of rewriting it\n // (which would actually make more sense for readibility and efficiency).\n if (img.src.indexOf(\"data:image/svg+xml;base64,\") !== -1) {\n // 'data:image/svg+xml;base64,'.length === 26\n const base64String = img.getAttribute(\"src\").substring(26);\n const svgString = window.atob(base64String);\n const encodedSvgString = encodeURIComponent(svgString);\n img.setAttribute(\"src\", `data:image/svg+xml;charset=utf8,${encodedSvgString}`);\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n // Return src to base64!\n img.setAttribute(\"src\", `data:image/svg+xml;base64,${base64String}`);\n } else {\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n }\n } else {\n // 'data:image/png;base64,' === 22.\n const base64 = img.src.substring(22, img.src.length);\n Image.setImgSize(img, base64, true);\n }\n } else {\n Image.setImgSize(img, img.src);\n }\n };\n\n // If the image doesn't contain a blob, just process it normally\n if (img.src.indexOf(\"blob:\") === -1) {\n processImg(img);\n // if it does contain a blob, then read that, replace the src with the decoded content, and process it\n } else {\n const reader = new FileReader();\n reader.onload = function () {\n img.setAttribute(\"src\", reader.result);\n processImg(img);\n };\n fetch(img.src)\n .then((r) => r.blob())\n .then((blob) => {\n reader.readAsDataURL(blob);\n });\n }\n }\n\n /**\n * Returns the metrics (height, width and baseline) contained in a SVG image generated\n * by the MathType image service. This image contains as an extra custom attribute:\n * the baseline (wrs:baseline).\n * @param {String} svgString - The SVG image.\n * @return {Array} - The image metrics.\n */\n static getMetricsFromSvgString(svgString) {\n let first = svgString.indexOf('height=\"');\n let last = svgString.indexOf('\"', first + 8, svgString.length);\n const height = svgString.substring(first + 8, last);\n\n first = svgString.indexOf('width=\"');\n last = svgString.indexOf('\"', first + 7, svgString.length);\n const width = svgString.substring(first + 7, last);\n\n first = svgString.indexOf('wrs:baseline=\"');\n last = svgString.indexOf('\"', first + 14, svgString.length);\n const baseline = svgString.substring(first + 14, last);\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n if (typeof baseline !== \"undefined\") {\n arr.cb = baseline;\n }\n return arr;\n }\n return [];\n }\n\n /**\n * Returns the metrics (width, height, baseline and dpi) contained in a PNG byte array.\n * @param {Array.} bytes - png byte array.\n * @return {Array} The png metrics.\n */\n static getMetricsFromBytes(bytes) {\n Util.readBytes(bytes, 0, 8);\n let width;\n let height;\n let typ;\n let baseline;\n let dpi;\n while (bytes.length >= 4) {\n typ = Util.readInt32(bytes);\n if (typ === 0x49484452) {\n width = Util.readInt32(bytes);\n height = Util.readInt32(bytes);\n // Read 5 bytes.\n Util.readInt32(bytes);\n Util.readByte(bytes);\n } else if (typ === 0x62615345) {\n // Baseline: 'baSE'.\n baseline = Util.readInt32(bytes);\n } else if (typ === 0x70485973) {\n // Dpis: 'pHYs'.\n dpi = Util.readInt32(bytes);\n dpi = Math.round(dpi / 39.37);\n Util.readInt32(bytes);\n Util.readByte(bytes);\n }\n Util.readInt32(bytes);\n }\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n arr.dpi = dpi;\n if (baseline) {\n arr.cb = baseline;\n }\n\n return arr;\n }\n return [];\n }\n}\n","import TextCache from \"./textcache\";\nimport ServiceProvider from \"./serviceprovider\";\nimport MathML from \"./mathml\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * @classdesc\n * This class represents MathType accessible class. Converts MathML to accessible text and manages\n * the associated client-side cache.\n */\nexport default class Accessibility {\n /**\n * Static property.\n * Accessibility cache, each entry contains a MathML and its correspondent accessibility text.\n * @type {TextCache}\n */\n static get cache() {\n return Accessibility._cache;\n }\n\n /**\n * Static property setter.\n * Set accessibility cache.\n * @param {TextCahe} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Accessibility._cache = value;\n }\n\n /**\n * Converts MathML strings to its accessible text representation.\n * @param {String} mathML - MathML to be converted to accessible text.\n * @param {String} [language] - Language of the accessible text. 'en' by default.\n * @param {Array.} [data] - Parameters to send to mathml2accessible service.\n * @return {String} Accessibility text.\n */\n static mathMLToAccessible(mathML, language, data) {\n if (typeof language === \"undefined\") {\n language = \"en\";\n }\n // Check MathML class. If the class is chemistry,\n // we add chemistry to data to force accessibility service\n // to load chemistry grammar.\n if (MathML.containClass(mathML, \"wrs_chemistry\")) {\n data.mode = \"chemistry\";\n }\n // Ignore accesibility styles\n data.ignoreStyles = true;\n let accessibleText = \"\";\n\n if (Accessibility.cache.get(mathML)) {\n accessibleText = Accessibility.cache.get(mathML);\n } else {\n data.service = \"mathml2accessible\";\n data.lang = language;\n const accessibleJsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n if (accessibleJsonResponse.status !== \"error\") {\n accessibleText = accessibleJsonResponse.result.text;\n Accessibility.cache.populate(mathML, accessibleText);\n } else {\n accessibleText = StringManager.get(\"error_convert_accessibility\");\n }\n }\n\n return accessibleText;\n }\n}\n\n/**\n * Contains an instance of TextCache class to manage the JavaScript accessible cache.\n * Each entry of the cache object contains the MathML and it's correspondent accessibility text.\n * @private\n * @type {TextCache}\n */\nAccessibility._cache = new TextCache();\n","import Util from \"./util\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport Image from \"./image\";\nimport Accessibility from \"./accessibility\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Configuration from \"./configuration\";\nimport Constants from \"./constants\";\n// eslint-disable-next-line no-unused-vars\nimport md5 from \"./md5\";\n\n/**\n * @classdesc\n * This class represent a MahML parser. Converts MathML into formulas depending on the\n * image format (SVG, PNG, base64) and the save mode (XML, safeXML, Image) configured\n * in the backend.\n */\nexport default class Parser {\n /**\n * Converts a MathML string to an img element.\n * @param {Document} creator - Document object to call createElement method.\n * @param {string} mathml - MathML code\n * @param {Object[]} wirisProperties - object containing WIRIS custom properties\n * @param {language} language - custom language for accessibility.\n * @returns {HTMLImageElement} the formula image corresponding to initial MathML string.\n * @static\n */\n static mathmlToImgObject(creator, mathml, wirisProperties, language) {\n const imgObject = creator.createElement(\"img\");\n imgObject.align = \"middle\";\n imgObject.style.maxWidth = \"none\";\n let data = wirisProperties || {};\n\n // Take into account the backend config\n const wirisEditorProperties = Configuration.get(\"editorParameters\");\n data = { ...wirisEditorProperties, ...data };\n\n data.mml = mathml;\n data.lang = language;\n // Request metrics of the generated image.\n data.metrics = \"true\";\n data.centerbaseline = \"false\";\n\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n // Render js params: _wrs_int_wirisProperties contains some js render params.\n // Since MathML can support render params, js params should be send only to editor.\n\n imgObject.className = Configuration.get(\"imageClassName\");\n\n if (mathml.indexOf('class=\"') !== -1) {\n // We check here if the MathML has been created from a customEditor (such chemistry)\n // to add custom editor name attribute to img object (if necessary).\n let mathmlSubstring = mathml.substring(mathml.indexOf('class=\"') + 'class=\"'.length, mathml.length);\n mathmlSubstring = mathmlSubstring.substring(0, mathmlSubstring.indexOf('\"'));\n mathmlSubstring = mathmlSubstring.substring(4, mathmlSubstring.length);\n imgObject.setAttribute(Configuration.get(\"imageCustomEditorName\"), mathmlSubstring);\n }\n\n // Performance enabled.\n if (\n Configuration.get(\"wirisPluginPerformance\") &&\n (Configuration.get(\"saveMode\") === \"xml\" || Configuration.get(\"saveMode\") === \"safeXml\")\n ) {\n let result = JSON.parse(Parser.createShowImageSrc(data, language));\n if (result.status === \"warning\") {\n // POST call.\n // if the mathml is malformed, this function will throw an exception.\n try {\n result = JSON.parse(ServiceProvider.getService(\"showimage\", data));\n } catch (e) {\n return null;\n }\n }\n ({ result } = result);\n if (result.format === \"png\") {\n imgObject.src = `data:image/png;base64,${result.content}`;\n } else {\n imgObject.src = `data:image/svg+xml;charset=utf8,${Util.urlEncode(result.content)}`;\n }\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n Image.setImgSize(imgObject, result.content, true);\n\n if (Configuration.get(\"enableAccessibility\")) {\n if (typeof result.alt === \"undefined\") {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n } else {\n imgObject.alt = result.alt;\n }\n }\n } else {\n const result = Parser.createImageSrc(mathml, data);\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n imgObject.src = result;\n Image.setImgSize(\n imgObject,\n result,\n Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\",\n );\n if (Configuration.get(\"enableAccessibility\")) {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n }\n }\n\n if (typeof Parser.observer !== \"undefined\") {\n Parser.observer.observe(imgObject);\n }\n\n // Role math https://www.w3.org/TR/wai-aria/roles#math.\n imgObject.setAttribute(\"role\", \"math\");\n return imgObject;\n }\n\n /**\n * Returns the source to showimage service by calling createimage service. The\n * output of the createimage service is a URL path pointing to showimage service.\n * This method is called when performance is disabled.\n * @param {string} mathml - MathML code.\n * @param {Object[]} data - data object containing service parameters.\n * @returns {string} the showimage path.\n */\n static createImageSrc(mathml, data) {\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n let result = ServiceProvider.getService(\"createimage\", data);\n\n if (result.indexOf(\"@BASE@\") !== -1) {\n // Replacing '@BASE@' with the base URL of createimage.\n const baseParts = ServiceProvider.getServicePath(\"createimage\").split(\"/\");\n baseParts.pop();\n result = result.split(\"@BASE@\").join(baseParts.join(\"/\"));\n }\n\n return result;\n }\n\n /**\n * Parses initial HTML code. If the HTML contains data generated by WIRIS,\n * this data would be converted as following:\n *
\n   * MathML code: Image containing the corresponding MathML formulas.\n   * MathML code with LaTeX annotation : LaTeX string.\n   * 
\n * @param {string} code - HTML code containing MathML data.\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code with the original MathML converted into LaTeX and images.\n */\n static initParse(code, language) {\n /* Note: The code inside this function has been inverted.\n If you invert again the code then you cannot use correctly LaTeX\n in Moodle.\n */\n code = Parser.initParseSaveMode(code, language);\n return Parser.initParseEditMode(code);\n }\n\n /**\n * Parses initial HTML code depending on the save mode. Transforms all MathML\n * occurrences for it's correspondent image or LaTeX.\n * @param {string} code - HTML code to be parsed\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code parsed.\n */\n static initParseSaveMode(code, language) {\n if (Configuration.get(\"saveMode\")) {\n // Converting XML to tags.\n code = Latex.parseMathmlToLatex(code, Constants.safeXmlCharacters);\n code = Latex.parseMathmlToLatex(code, Constants.xmlCharacters);\n code = Parser.parseMathmlToImg(code, Constants.safeXmlCharacters, language);\n code = Parser.parseMathmlToImg(code, Constants.xmlCharacters, language);\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"image\") {\n code = Parser.codeImgTransform(code, \"base642showimage\");\n }\n }\n return code;\n }\n\n /**\n * Parses initial HTML code depending on the edit mode.\n * If 'latex' parseMode is enabled all MathML containing an annotation with encoding='LaTeX' will\n * be converted into a LaTeX string instead of an image.\n * @param {string} code - HTML code containing MathML.\n * @returns {string} parsed HTML code.\n */\n static initParseEditMode(code) {\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n const imgList = Util.getElementsByNameFromString(code, \"img\", true);\n const token = 'encoding=\"LaTeX\">';\n // While replacing images with latex, the indexes of the found images changes\n // respecting the original code, so this carry is needed.\n let carry = 0;\n\n for (let i = 0; i < imgList.length; i += 1) {\n const imgCode = code.substring(imgList[i].start + carry, imgList[i].end + carry);\n\n if (imgCode.indexOf(` class=\"${Configuration.get(\"imageClassName\")}\"`) !== -1) {\n let mathmlStartToken = ` ${Configuration.get(\"imageMathmlAttribute\")}=\"`;\n let mathmlStart = imgCode.indexOf(mathmlStartToken);\n\n if (mathmlStart === -1) {\n mathmlStartToken = ' alt=\"';\n mathmlStart = imgCode.indexOf(mathmlStartToken);\n }\n\n if (mathmlStart !== -1) {\n mathmlStart += mathmlStartToken.length;\n const mathmlEnd = imgCode.indexOf('\"', mathmlStart);\n const mathml = Util.htmlSanitize(MathML.safeXmlDecode(imgCode.substring(mathmlStart, mathmlEnd)));\n let latexStartPosition = mathml.indexOf(token);\n\n if (latexStartPosition !== -1) {\n latexStartPosition += token.length;\n const latexEndPosition = mathml.indexOf(\"\", latexStartPosition);\n const latex = mathml.substring(latexStartPosition, latexEndPosition);\n\n const replaceText = `$$${Util.htmlEntitiesDecode(latex)}$$`;\n const start = code.substring(0, imgList[i].start + carry);\n const end = code.substring(imgList[i].end + carry);\n code = start + replaceText + end;\n carry += replaceText.length - (imgList[i].end - imgList[i].start);\n }\n }\n }\n }\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code. The end HTML code is HTML code with embedded images\n * or LaTeX formulas created with MathType.
\n * By default this method converts the formula images and LaTeX strings in MathML.
\n * If image mode is enabled the images will not be converted into MathML. For further information see {@link https://docs.wiris.com/mathtype/en/mathtype-integrations/mathtype-web-interface-features/full-mathml-mode---wirisplugins-js.html}.\n * @param {string} code - HTML to be parsed\n * @returns {string} the HTML code parsed.\n */\n static endParse(code) {\n // Transform LaTeX ocurrences to MathML elements.\n const codeEndParsedEditMode = Parser.endParseEditMode(code);\n // Transform img elements to MathML elements.\n const codeEndParseSaveMode = Parser.endParseSaveMode(codeEndParsedEditMode);\n return codeEndParseSaveMode;\n }\n\n /**\n * Parses end HTML code depending on the edit mode.\n * - LaTeX is an enabled parse mode, all LaTeX occurrences will be converted into MathML.\n * @param {string} code - HTML code to be parsed.\n * @returns {string} HTML code parsed.\n */\n static endParseEditMode(code) {\n // Converting LaTeX to images.\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n let output = \"\";\n let endPosition = 0;\n let startPosition = code.indexOf(\"$$\");\n while (startPosition !== -1) {\n output += code.substring(endPosition, startPosition);\n endPosition = code.indexOf(\"$$\", startPosition + 2);\n\n if (endPosition !== -1) {\n // Before, it was a condition here to execute the next codelines\n // 'latex.indexOf('<') == -1'.\n // We don't know why it was used, but seems to have a conflict with\n // latex formulas that contains '<'.\n const latex = code.substring(startPosition + 2, endPosition);\n const decodedLatex = Util.htmlEntitiesDecode(latex);\n let mathml = Util.htmlSanitize(Latex.getMathMLFromLatex(decodedLatex, true));\n if (!Configuration.get(\"saveHandTraces\")) {\n // Remove hand traces.\n mathml = MathML.removeAnnotation(mathml, \"application/json\");\n }\n output += mathml;\n endPosition += 2;\n } else {\n output += \"$$\";\n endPosition = startPosition + 2;\n }\n\n startPosition = code.indexOf(\"$$\", endPosition);\n }\n\n output += code.substring(endPosition, code.length);\n code = output;\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code depending on the save mode. Converts all\n * images into the element determined by the save mode:\n * - xml: Parses images formulas into MathML.\n * - safeXml: Parses images formulas into safeMAthML\n * - base64: Parses images into base64 images.\n * - image: Parse images into images (no parsing)\n * @param {string} code - HTML code to be parsed\n * @returns {string} HTML code parsed.\n */\n static endParseSaveMode(code) {\n const savemode = Configuration.get(\"saveMode\");\n const base64savemode = Configuration.get(\"base64savemode\");\n\n if (savemode) {\n if (savemode === \"safeXml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"xml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"base64\" && base64savemode === \"image\") {\n code = Parser.codeImgTransform(code, \"img264\");\n }\n }\n\n return code;\n }\n\n /**\n * Auxiliar function that builds the data object to send to the showimage endpoint\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object with the data to send to showimage.\n */\n static createShowImageSrcData(data, language) {\n const dataMd5 = {};\n const renderParams = [\n \"mml\",\n \"color\",\n \"centerbaseline\",\n \"zoom\",\n \"dpi\",\n \"fontSize\",\n \"fontFamily\",\n \"defaultStretchy\",\n \"backgroundColor\",\n \"format\",\n ];\n renderParams.forEach((param) => {\n if (typeof data[param] !== \"undefined\") {\n dataMd5[param] = data[param];\n }\n });\n // Data variables to get.\n const dataObject = {};\n Object.keys(data).forEach((key) => {\n // We don't need mathml in this request we try to get cached.\n // Only need the formula md5 calculated before.\n if (key !== \"mml\") {\n dataObject[key] = data[key];\n }\n });\n\n dataObject.formula = com.wiris.js.JsPluginTools.md5encode(Util.propertiesToString(dataMd5));\n dataObject.lang = typeof language === \"undefined\" ? \"en\" : language;\n dataObject.version = Configuration.get(\"version\");\n\n return dataObject;\n }\n\n /**\n * Returns the result to call showimage service with the formula md5 as parameter.\n * The result could be:\n * - {'status' : warning'} : The image associated to the MathML md5 is not in cache.\n * - {'status' : 'ok' ...} : The image associated to the MathML md5 is in cache.\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object containing showimage response.\n */\n static createShowImageSrc(data, language) {\n const dataObject = this.createShowImageSrcData(data, language);\n const result = ServiceProvider.getService(\"showimage\", Util.httpBuildQuery(dataObject), true);\n return result;\n }\n\n /**\n * Transform html img tags inside a html code to mathml, base64 img tags (i.e with base64 on src)\n * or showimage img tags (i.e with showimage.php on src)\n * @param {string} code - HTML code\n * @param {string} mode - base642showimage or img2mathml or img264 transform.\n * @returns {string} html - code transformed.\n */\n static codeImgTransform(code, mode) {\n let output = \"\";\n let endPosition = 0;\n const pattern = /\") {\n endPosition = i + 1;\n }\n\n i += 1;\n }\n\n if (endPosition < startPosition) {\n // The img tag is stripped.\n output += code.substring(startPosition, code.length);\n return output;\n }\n let imgCode = code.substring(startPosition, endPosition);\n const imgObject = Util.createObject(imgCode);\n let xmlCode = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n let convertToXml;\n let convertToSafeXml;\n\n if (mode === \"base642showimage\") {\n if (xmlCode == null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n imgCode = Parser.mathmlToImgObject(document, xmlCode, null, null);\n output += Util.createObjectCode(imgCode);\n } else if (mode === \"img2mathml\") {\n if (Configuration.get(\"saveMode\")) {\n if (Configuration.get(\"saveMode\") === \"safeXml\") {\n convertToXml = true;\n convertToSafeXml = true;\n } else if (Configuration.get(\"saveMode\") === \"xml\") {\n convertToXml = true;\n convertToSafeXml = false;\n }\n }\n output += Util.getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml);\n } else if (mode === \"img264\") {\n if (xmlCode === null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n\n const properties = {};\n properties.base64 = \"true\";\n imgCode = Parser.mathmlToImgObject(document, xmlCode, properties, null);\n // Metrics.\n Image.setImgSize(imgCode, imgCode.src, true);\n output += Util.createObjectCode(imgCode);\n }\n }\n output += code.substring(endPosition, code.length);\n return output;\n }\n\n /**\n * Converts all occurrences of MathML to the corresponding image.\n * @param {string} content - string with valid MathML code.\n * The MathML code doesn't contain semantics.\n * @param {Constants} characters - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * @param {string} language - a valid language code\n * in order to generate formula accessibility.\n * @returns {string} The input string with all the MathML\n * occurrences replaced by the corresponding image.\n */\n static parseMathmlToImg(content, characters, language) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n\n while (start !== -1) {\n output += content.substring(end, start);\n // Avoid WIRIS images to be parsed.\n const imageMathmlAtrribute = content.indexOf(Configuration.get(\"imageMathmlAttribute\"));\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else if (imageMathmlAtrribute !== -1) {\n // First close tag of img attribute\n // If a mathmlAttribute exists should be inside a img tag.\n end += content.indexOf(\"/>\", start);\n } else {\n end += mathTagEnd.length;\n }\n\n if (!MathML.isMathmlInAttribute(content, start) && imageMathmlAtrribute === -1) {\n let mathml = content.substring(start, end);\n mathml =\n characters.id === Constants.safeXmlCharacters.id\n ? MathML.safeXmlDecode(mathml)\n : MathML.mathMLEntities(mathml);\n output += Util.createObjectCode(Parser.mathmlToImgObject(document, mathml, null, language));\n } else {\n output += content.substring(start, end);\n }\n\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n}\n\n// Mutation observers to avoid wiris image formulas class be removed.\nif (typeof MutationObserver !== \"undefined\") {\n const mutationObserver = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n if (\n mutation.oldValue === Configuration.get(\"imageClassName\") &&\n mutation.attributeName === \"class\" &&\n mutation.target.className.indexOf(Configuration.get(\"imageClassName\")) === -1\n ) {\n mutation.target.className = Configuration.get(\"imageClassName\");\n }\n });\n });\n\n Parser.observer = Object.create(mutationObserver);\n Parser.observer.Config = { attributes: true, attributeOldValue: true };\n // We use own default config.\n Parser.observer.observe = function (target) {\n Object.getPrototypeOf(this).observe(target, this.Config);\n };\n}\n","/* eslint-disable class-methods-use-this */\n/* eslint-disable no-unused-vars */\n/* eslint-disable no-extra-semi */\n\n// The rules above are disabled because we are implementing\n// an external interface.\n\nexport default class EditorListener {\n /**\n * @classdesc\n * Determines if the content of the\n * MathType Editor has changes.\n * @implements {EditorListeners}\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the content of the editor has changed.\n * @type {Boolean}\n */\n this.isContentChanged = false;\n\n /**\n * Indicates if the listener should be waiting for changes in the editor.\n * @type {Boolean}\n */\n this.waitingForChanges = false;\n }\n\n /**\n * Sets {@link EditorListener.isContentChanged} property.\n * @param {Boolean} value - The new vlue.\n */\n setIsContentChanged(value) {\n this.isContentChanged = value;\n }\n\n /**\n * Returns true if the content of the editor has been changed, false otherwise.\n * @return {Boolean}\n */\n getIsContentChanged() {\n return this.isContentChanged;\n }\n\n /**\n * Determines if the EditorListener should wait for any changes.\n * @param {Boolean} value - True if the editor should wait for changes, false otherwise.\n */\n setWaitingForChanges(value) {\n this.waitingForChanges = value;\n }\n\n /**\n * EditorListener method to overwrite.\n * @type {JsEditor}\n * @ignore\n */\n caretPositionChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @type {JsEditor}\n * @ignore\n */\n clipboardChanged(_editor) {}\n\n /**\n * Determines if the content of an editor has been changed.\n * @param {JsEditor} editor - editor object.\n */\n contentChanged(_editor) {\n if (this.waitingForChanges === true && this.isContentChanged === false) {\n this.isContentChanged = true;\n }\n }\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} editor - The editor instance.\n */\n styleChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} - The editor instance.\n */\n transformationReceived(_editor) {}\n}\n","let wasm;\n\nconst cachedTextDecoder =\n typeof TextDecoder !== \"undefined\"\n ? new TextDecoder(\"utf-8\", { ignoreBOM: true, fatal: true })\n : {\n decode: () => {\n throw Error(\"TextDecoder not available\");\n },\n };\n\nif (typeof TextDecoder !== \"undefined\") {\n cachedTextDecoder.decode();\n}\n\nlet cachedUint8Memory0 = null;\n\nfunction getUint8Memory0() {\n if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {\n cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8Memory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));\n}\n\nconst heap = new Array(128).fill(undefined);\n\nheap.push(undefined, null, true, false);\n\nlet heap_next = heap.length;\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction getObject(idx) {\n return heap[idx];\n}\n\nfunction dropObject(idx) {\n if (idx < 132) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nconst cachedTextEncoder =\n typeof TextEncoder !== \"undefined\"\n ? new TextEncoder(\"utf-8\")\n : {\n encode: () => {\n throw Error(\"TextEncoder not available\");\n },\n };\n\nconst encodeString =\n typeof cachedTextEncoder.encodeInto === \"function\"\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n }\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length,\n };\n };\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8Memory0()\n .subarray(ptr, ptr + buf.length)\n .set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8Memory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7f) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0;\n const view = getUint8Memory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nlet cachedInt32Memory0 = null;\n\nfunction getInt32Memory0() {\n if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {\n cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);\n }\n return cachedInt32Memory0;\n}\n\nlet cachedFloat64Memory0 = null;\n\nfunction getFloat64Memory0() {\n if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {\n cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);\n }\n return cachedFloat64Memory0;\n}\n\nlet cachedBigInt64Memory0 = null;\n\nfunction getBigInt64Memory0() {\n if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) {\n cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer);\n }\n return cachedBigInt64Memory0;\n}\n\nfunction debugString(val) {\n // primitive types\n const type = typeof val;\n if (type == \"number\" || type == \"boolean\" || val == null) {\n return `${val}`;\n }\n if (type == \"string\") {\n return `\"${val}\"`;\n }\n if (type == \"symbol\") {\n const description = val.description;\n if (description == null) {\n return \"Symbol\";\n } else {\n return `Symbol(${description})`;\n }\n }\n if (type == \"function\") {\n const name = val.name;\n if (typeof name == \"string\" && name.length > 0) {\n return `Function(${name})`;\n } else {\n return \"Function\";\n }\n }\n // objects\n if (Array.isArray(val)) {\n const length = val.length;\n let debug = \"[\";\n if (length > 0) {\n debug += debugString(val[0]);\n }\n for (let i = 1; i < length; i++) {\n debug += \", \" + debugString(val[i]);\n }\n debug += \"]\";\n return debug;\n }\n // Test for built-in\n const builtInMatches = /\\[object ([^\\]]+)\\]/.exec(toString.call(val));\n let className;\n if (builtInMatches.length > 1) {\n className = builtInMatches[1];\n } else {\n // Failed to match the standard '[object ClassName]'\n return toString.call(val);\n }\n if (className == \"Object\") {\n // we're a user defined class or Object\n // JSON.stringify avoids problems with cycles, and is generally much\n // easier than looping through ownProperties of `val`.\n try {\n return \"Object(\" + JSON.stringify(val) + \")\";\n } catch (_) {\n return \"Object\";\n }\n }\n // errors\n if (val instanceof Error) {\n return `${val.name}: ${val.message}\\n${val.stack}`;\n }\n // TODO we could test for more things here, like `Set`s and `Map`s.\n return className;\n}\n\nfunction makeClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n try {\n return f(state.a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);\n state.a = 0;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_46(arg0, arg1, arg2) {\n wasm.__wbindgen_export_3(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction makeMutClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n const a = state.a;\n state.a = 0;\n try {\n return f(a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);\n } else {\n state.a = a;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_49(arg0, arg1) {\n wasm.__wbindgen_export_4(arg0, arg1);\n}\n\nfunction __wbg_adapter_52(arg0, arg1, arg2) {\n wasm.__wbindgen_export_5(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction handleError(f, args) {\n try {\n return f.apply(this, args);\n } catch (e) {\n wasm.__wbindgen_export_6(addHeapObject(e));\n }\n}\nfunction __wbg_adapter_103(arg0, arg1, arg2, arg3) {\n wasm.__wbindgen_export_7(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));\n}\n\n/**\n */\nexport function main_js() {\n wasm.main_js();\n}\n\nfunction getArrayU8FromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);\n}\n/**\n */\nexport const Level = Object.freeze({\n Err: 0,\n 0: \"Err\",\n Warn: 1,\n 1: \"Warn\",\n Info: 2,\n 2: \"Info\",\n Debug: 3,\n 3: \"Debug\",\n});\n/**\n */\nexport class Telemeter {\n __destroy_into_raw() {\n const ptr = this.__wbg_ptr;\n this.__wbg_ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_telemeter_free(ptr);\n }\n /**\n * @param {any} solution\n * @param {any} hosts\n * @param {any} config\n */\n constructor(solution, hosts, config) {\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n wasm.telemeter_new(retptr, addHeapObject(solution), addHeapObject(hosts), addHeapObject(config));\n var r0 = getInt32Memory0()[retptr / 4 + 0];\n var r1 = getInt32Memory0()[retptr / 4 + 1];\n var r2 = getInt32Memory0()[retptr / 4 + 2];\n if (r2) {\n throw takeObject(r1);\n }\n this.__wbg_ptr = r0 >>> 0;\n return this;\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n }\n }\n /**\n * @param {string} sender_id\n * @returns {Promise}\n */\n identify(sender_id) {\n const ptr0 = passStringToWasm0(sender_id, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_identify(this.__wbg_ptr, ptr0, len0);\n return takeObject(ret);\n }\n /**\n * @param {string} event_type\n * @param {any} event_payload\n * @returns {Promise}\n */\n track(event_type, event_payload) {\n const ptr0 = passStringToWasm0(event_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_track(this.__wbg_ptr, ptr0, len0, addHeapObject(event_payload));\n return takeObject(ret);\n }\n /**\n * @param {any} level\n * @param {string} message\n * @param {any} payload\n * @returns {Promise}\n */\n log(level, message, payload) {\n const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_log(this.__wbg_ptr, addHeapObject(level), ptr0, len0, addHeapObject(payload));\n return takeObject(ret);\n }\n /**\n * @returns {Promise}\n */\n finish() {\n const ptr = this.__destroy_into_raw();\n const ret = wasm.telemeter_finish(ptr);\n return takeObject(ret);\n }\n /**\n * @param {boolean | undefined} [new_debug_status]\n */\n debug(new_debug_status) {\n wasm.telemeter_debug(this.__wbg_ptr, isLikeNone(new_debug_status) ? 0xffffff : new_debug_status ? 1 : 0);\n }\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === \"function\" && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === \"function\") {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n if (module.headers.get(\"Content-Type\") != \"application/wasm\") {\n console.warn(\n \"`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",\n e,\n );\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n}\n\nfunction __wbg_get_imports() {\n const imports = {};\n imports.wbg = {};\n imports.wbg.__wbindgen_string_new = function (arg0, arg1) {\n const ret = getStringFromWasm0(arg0, arg1);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_c728d68b8b34487e = function () {\n const ret = new Object();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_status_7841bb47be2a8f16 = function (arg0) {\n const ret = getObject(arg0).status;\n return ret;\n };\n imports.wbg.__wbg_headers_ea7ef583d1564b08 = function (arg0) {\n const ret = getObject(arg0).headers;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new0_ad75dd38f92424e2 = function () {\n const ret = new Date();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getTime_ed6ee333b702f8fc = function (arg0) {\n const ret = getObject(arg0).getTime();\n return ret;\n };\n imports.wbg.__wbindgen_object_drop_ref = function (arg0) {\n takeObject(arg0);\n };\n imports.wbg.__wbindgen_is_object = function (arg0) {\n const val = getObject(arg0);\n const ret = typeof val === \"object\" && val !== null;\n return ret;\n };\n imports.wbg.__wbg_crypto_58f13aa23ffcb166 = function (arg0) {\n const ret = getObject(arg0).crypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_process_5b786e71d465a513 = function (arg0) {\n const ret = getObject(arg0).process;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_versions_c2ab80650590b6a2 = function (arg0) {\n const ret = getObject(arg0).versions;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_node_523d7bd03ef69fba = function (arg0) {\n const ret = getObject(arg0).node;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_string = function (arg0) {\n const ret = typeof getObject(arg0) === \"string\";\n return ret;\n };\n imports.wbg.__wbg_msCrypto_abcb1295e768d1f2 = function (arg0) {\n const ret = getObject(arg0).msCrypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_require_2784e593a4674877 = function () {\n return handleError(function () {\n const ret = module.require;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_newwithlength_13b5319ab422dcf6 = function (arg0) {\n const ret = new Uint8Array(arg0 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_4a9aa5157afeb382 = function (arg0, arg1) {\n const ret = getObject(arg0)[arg1 >>> 0];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_next_1989a20442400aaa = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).next();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_done_bc26bf4ada718266 = function (arg0) {\n const ret = getObject(arg0).done;\n return ret;\n };\n imports.wbg.__wbg_value_0570714ff7d75f35 = function (arg0) {\n const ret = getObject(arg0).value;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_iterator_7ee1a391d310f8e4 = function () {\n const ret = Symbol.iterator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_2aff440840bb6202 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.get(getObject(arg0), getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_next_15da6a3df9290720 = function (arg0) {\n const ret = getObject(arg0).next;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_function = function (arg0) {\n const ret = typeof getObject(arg0) === \"function\";\n return ret;\n };\n imports.wbg.__wbg_call_669127b9d730c650 = function () {\n return handleError(function (arg0, arg1) {\n const ret = getObject(arg0).call(getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_object_clone_ref = function (arg0) {\n const ret = getObject(arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_self_3fad056edded10bd = function () {\n return handleError(function () {\n const ret = self.self;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_window_a4f46c98a61d4089 = function () {\n return handleError(function () {\n const ret = window.window;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_globalThis_17eff828815f7d84 = function () {\n return handleError(function () {\n const ret = globalThis.globalThis;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_global_46f939f6541643c5 = function () {\n return handleError(function () {\n const ret = global.global;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_is_undefined = function (arg0) {\n const ret = getObject(arg0) === undefined;\n return ret;\n };\n imports.wbg.__wbg_newnoargs_ccdcae30fd002262 = function (arg0, arg1) {\n const ret = new Function(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_isArray_38525be7442aa21e = function (arg0) {\n const ret = Array.isArray(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_call_53fc3abd42e24ec8 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_isSafeInteger_c38b0a16d0c7cef7 = function (arg0) {\n const ret = Number.isSafeInteger(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_new_feb65b865d980ae2 = function (arg0, arg1) {\n try {\n var state0 = { a: arg0, b: arg1 };\n var cb0 = (arg0, arg1) => {\n const a = state0.a;\n state0.a = 0;\n try {\n return __wbg_adapter_103(a, state0.b, arg0, arg1);\n } finally {\n state0.a = a;\n }\n };\n const ret = new Promise(cb0);\n return addHeapObject(ret);\n } finally {\n state0.a = state0.b = 0;\n }\n };\n imports.wbg.__wbindgen_memory = function () {\n const ret = wasm.memory;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_buffer_344d9b41efe96da7 = function (arg0) {\n const ret = getObject(arg0).buffer;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_d8a000788389a31e = function (arg0) {\n const ret = new Uint8Array(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_set_dcfd613a3420f908 = function (arg0, arg1, arg2) {\n getObject(arg0).set(getObject(arg1), arg2 >>> 0);\n };\n imports.wbg.__wbg_length_a5587d6cd79ab197 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbindgen_string_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"string\" ? obj : undefined;\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_stringify_4039297315a25b00 = function () {\n return handleError(function (arg0) {\n const ret = JSON.stringify(getObject(arg0));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_set_40f7786a25a9cc7e = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_has_cdf8b85f6e903c80 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.has(getObject(arg0), getObject(arg1));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_fetch_701fcd2bde06379a = function (arg0, arg1) {\n const ret = getObject(arg0).fetch(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_fetch_b5d6bebed1e6c2d2 = function (arg0) {\n const ret = fetch(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_newwithbyteoffsetandlength_2dc04d99088b15e3 = function (arg0, arg1, arg2) {\n const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_e4960143e41697a4 = function () {\n return handleError(function () {\n const ret = new AbortController();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_signal_1ed842bebd6ae322 = function (arg0) {\n const ret = getObject(arg0).signal;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_abort_8355f201f30300bb = function (arg0) {\n getObject(arg0).abort();\n };\n imports.wbg.__wbindgen_error_new = function (arg0, arg1) {\n const ret = new Error(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_loose_eq = function (arg0, arg1) {\n const ret = getObject(arg0) == getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_boolean_get = function (arg0) {\n const v = getObject(arg0);\n const ret = typeof v === \"boolean\" ? (v ? 1 : 0) : 2;\n return ret;\n };\n imports.wbg.__wbindgen_number_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"number\" ? obj : undefined;\n getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbg_instanceof_Uint8Array_19e6f142a5e7e1e1 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Uint8Array;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_instanceof_ArrayBuffer_c7cc317e5c29cc0d = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof ArrayBuffer;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_entries_6d727b73ee02b7ce = function (arg0) {\n const ret = Object.entries(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_String_917f38a1211cf44b = function (arg0, arg1) {\n const ret = String(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_warn_ade8d3b7ecee11ff = function (arg0, arg1) {\n console.warn(getObject(arg0), getObject(arg1));\n };\n imports.wbg.__wbg_readyState_13e55da5ad6d64e2 = function (arg0) {\n const ret = getObject(arg0).readyState;\n return ret;\n };\n imports.wbg.__wbg_warn_4affe1093892a4ef = function (arg0) {\n console.warn(getObject(arg0));\n };\n imports.wbg.__wbg_close_f4135085ec3fc8f0 = function () {\n return handleError(function (arg0) {\n getObject(arg0).close();\n }, arguments);\n };\n imports.wbg.__wbg_new_b9b318679315404f = function () {\n return handleError(function (arg0, arg1) {\n const ret = new WebSocket(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setbinaryType_dcb62e0f2b346301 = function (arg0, arg1) {\n getObject(arg0).binaryType = takeObject(arg1);\n };\n imports.wbg.__wbg_log_7811587c4c6d2844 = function (arg0) {\n console.log(getObject(arg0));\n };\n imports.wbg.__wbg_error_f0a6627f4b23c19d = function (arg0) {\n console.error(getObject(arg0));\n };\n imports.wbg.__wbg_info_3ca7870690403fee = function (arg0) {\n console.info(getObject(arg0));\n };\n imports.wbg.__wbg_document_183cf1eecfdbffee = function (arg0) {\n const ret = getObject(arg0).document;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n };\n imports.wbg.__wbg_visibilityState_9721703a5ef75faf = function (arg0) {\n const ret = getObject(arg0).visibilityState;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getwithrefkey_3b3c46ba20582127 = function (arg0, arg1) {\n const ret = getObject(arg0)[getObject(arg1)];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_length_cace2e0b3ddc0502 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbg_addEventListener_0f2891b0794e07fa = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).addEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbg_removeEventListener_104d11302bb212d1 = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).removeEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbindgen_is_bigint = function (arg0) {\n const ret = typeof getObject(arg0) === \"bigint\";\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_i64 = function (arg0) {\n const ret = arg0;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_in = function (arg0, arg1) {\n const ret = getObject(arg0) in getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_u64 = function (arg0) {\n const ret = BigInt.asUintN(64, arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_eq = function (arg0, arg1) {\n const ret = getObject(arg0) === getObject(arg1);\n return ret;\n };\n imports.wbg.__wbg_localStorage_e11f72e996a4f5d9 = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).localStorage;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_getItem_c81cd3ae30cd579a = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n const ret = getObject(arg1).getItem(getStringFromWasm0(arg2, arg3));\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n }, arguments);\n };\n imports.wbg.__wbg_navigator_7078da62d92ff5ad = function (arg0) {\n const ret = getObject(arg0).navigator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_mediaDevices_e00b1f64d2b9939f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).mediaDevices;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_enumerateDevices_619d52f5eef34c2f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).enumerateDevices();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setItem_fe04f524052a3839 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbindgen_cb_drop = function (arg0) {\n const obj = takeObject(arg0).original;\n if (obj.cnt-- == 1) {\n obj.a = 0;\n return true;\n }\n const ret = false;\n return ret;\n };\n imports.wbg.__wbg_deviceId_58f7da2228a26c02 = function (arg0, arg1) {\n const ret = getObject(arg1).deviceId;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_instanceof_Response_944e2745b5db71f5 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Response;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_randomFillSync_a0d98aa11c81fe89 = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).randomFillSync(takeObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbg_subarray_6ca5cfa7fbb9abbe = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getRandomValues_504510b5564925af = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).getRandomValues(getObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbindgen_bigint_get_as_i64 = function (arg0, arg1) {\n const v = getObject(arg1);\n const ret = typeof v === \"bigint\" ? v : undefined;\n getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbindgen_debug_string = function (arg0, arg1) {\n const ret = debugString(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbindgen_throw = function (arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n };\n imports.wbg.__wbg_then_89e1c559530b85cf = function (arg0, arg1) {\n const ret = getObject(arg0).then(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_e5949c35d772a669 = function (arg0) {\n queueMicrotask(getObject(arg0));\n };\n imports.wbg.__wbg_then_1bbc9edafd859b06 = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_2be8b97a81fe4d00 = function (arg0) {\n const ret = getObject(arg0).queueMicrotask;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_resolve_a3252b2860f0a09e = function (arg0) {\n const ret = Promise.resolve(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_url_1f609e63ff1a7983 = function (arg0, arg1) {\n const ret = getObject(arg1).url;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_send_2860805104507701 = function () {\n return handleError(function (arg0, arg1, arg2) {\n getObject(arg0).send(getArrayU8FromWasm0(arg1, arg2));\n }, arguments);\n };\n imports.wbg.__wbg_instanceof_Window_cde2416cf5126a72 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Window;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_new_19676474aa414d62 = function () {\n return handleError(function () {\n const ret = new Headers();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_append_feec4143bbf21904 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbg_newwithstrandinit_29038da14d09e330 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_closure_wrapper1532 = function (arg0, arg1, arg2) {\n const ret = makeClosure(arg0, arg1, 76, __wbg_adapter_46);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1602 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_49);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1834 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_52);\n return addHeapObject(ret);\n };\n\n return imports;\n}\n\nfunction __wbg_init_memory(imports, maybe_memory) {}\n\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n __wbg_init.__wbindgen_wasm_module = module;\n cachedBigInt64Memory0 = null;\n cachedFloat64Memory0 = null;\n cachedInt32Memory0 = null;\n cachedUint8Memory0 = null;\n\n wasm.__wbindgen_start();\n return wasm;\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n const imports = __wbg_get_imports();\n\n __wbg_init_memory(imports);\n\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n\n const instance = new WebAssembly.Instance(module, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(input) {\n if (wasm !== undefined) return wasm;\n\n if (typeof input === \"undefined\") {\n input = new URL(\"telemeter_wasm_bg.wasm\", import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (\n typeof input === \"string\" ||\n (typeof Request === \"function\" && input instanceof Request) ||\n (typeof URL === \"function\" && input instanceof URL)\n ) {\n input = fetch(input);\n }\n\n __wbg_init_memory(imports);\n\n const { instance, module } = await __wbg_load(await input, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync };\nexport default __wbg_init;\n","/* eslint-disable-next-line */\nimport init, { Telemeter as TelemeterWASM } from \"../telemeter-wasm\";\n\n/**\n * @classdesc\n * This class implements the @wiris/telemeter-wasm. A utility that helps our Solutions to send the data\n * to Telemetry in a more comfortable and homogeneous way.\n */\nexport default class Telemeter {\n /**\n * Inits Telemeter class.\n * The parameters structures are defiended on {@link [Telemeter API](https://github.com/wiris/telemeter/blob/main/docs/USAGE.md#telemeter-api)}\n * @param {Object} telemeterAttributes.solution - The product that send data to Telemetry.\n * @param {Object} telemeterAttributes.hosts - Data about the environment where solution is integrated.\n * @param {Object} telemeterAttributes.config - Configuration parameters.\n */\n static init(telemeterAttributes) {\n if (!this.telemeter && !this.waitingForInit) {\n this.waitingForInit = true;\n init(telemeterAttributes.url)\n .then(() => {\n this.telemeter = new TelemeterWASM(\n telemeterAttributes.solution,\n telemeterAttributes.hosts,\n telemeterAttributes.config,\n );\n })\n .catch((error) => {\n console.log(error);\n })\n .finally(() => (this.waitingForInit = false));\n }\n }\n\n /**\n * Closes the Telemetry Session. After calling this method no data will be added to the Telemetry Session.\n */\n static async finish() {\n if (!this.telemeter) return;\n\n try {\n const local_telemeter = this.telemeter;\n this.telemeter = undefined;\n await local_telemeter.finish();\n } catch (e) {\n console.error(e);\n }\n }\n}\n","import Configuration from \"./configuration\";\nimport Core from \"./core.src\";\nimport EditorListener from \"./editorlistener\";\nimport Listeners from \"./listeners\";\nimport MathML from \"./mathml\";\nimport Util from \"./util\";\nimport Telemeter from \"./telemeter\";\n\nexport default class ContentManager {\n /**\n * @classdesc\n * This class represents a modal dialog, managing the following:\n * - The insertion of content into the current instance of the {@link ModalDialog} class.\n * - The actions to be done once the modal object has been submitted\n * (submitAction} method).\n * - The update of the content when the {@link ModalDialog} class is also updated,\n * for example when ModalDialog is re-opened.\n * - The communication between the {@link ModalDialog} class and itself, if the content\n * has been changed (hasChanges} method).\n * @constructs\n * @param {Object} contentManagerAttributes - Object containing all attributes needed to\n * create a new instance.\n */\n constructor(contentManagerAttributes) {\n /**\n * An object containing MathType editor parameters. See\n * http://docs.wiris.com/en/mathtype/mathtype_web/sdk-api/parameters for further information.\n * @type {Object}\n */\n this.editorAttributes = {};\n if (\"editorAttributes\" in contentManagerAttributes) {\n this.editorAttributes = contentManagerAttributes.editorAttributes;\n } else {\n throw new Error(\"ContentManager constructor error: editorAttributes property missed.\");\n }\n\n /**\n * CustomEditors instance. Contains the custom editors.\n * @type {CustomEditors}\n */\n this.customEditors = null;\n if (\"customEditors\" in contentManagerAttributes) {\n this.customEditors = contentManagerAttributes.customEditors;\n }\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @type {Object}\n * @property {String} editor - Editor name. Usually the HTML editor.\n * @property {String} mode - Save mode. Xml by default.\n * @property {String} version - Plugin version.\n */\n this.environment = {};\n if (\"environment\" in contentManagerAttributes) {\n this.environment = contentManagerAttributes.environment;\n } else {\n throw new Error(\"ContentManager constructor error: environment property missed\");\n }\n\n /**\n * ContentManager language.\n * @type {String}\n */\n this.language = \"\";\n if (\"language\" in contentManagerAttributes) {\n this.language = contentManagerAttributes.language;\n } else {\n throw new Error(\"ContentManager constructor error: language property missed\");\n }\n\n /**\n * {@link EditorListener} instance. Manages the changes inside the editor.\n * @type {EditorListener}\n */\n this.editorListener = new EditorListener();\n\n /**\n * MathType editor instance.\n * @type {JsEditor}\n */\n this.editor = null;\n\n /**\n * Navigator user agent.\n * @type {String}\n */\n this.ua = navigator.userAgent.toLowerCase();\n\n /**\n * Mobile device properties object\n * @type {DeviceProperties}\n */\n this.deviceProperties = {};\n this.deviceProperties.isAndroid = this.ua.indexOf(\"android\") > -1;\n this.deviceProperties.isIOS = ContentManager.isIOS();\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.toolbar = null;\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.dbclick = null;\n\n /**\n * Instance of the {@link ModalDialog} class associated with the current\n * {@link ContentManager} instance.\n * @type {ModalDialog}\n */\n this.modalDialogInstance = null;\n\n /**\n * ContentManager listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n /**\n * MathML associated to the ContentManager instance.\n * @type {String}\n */\n this.mathML = null;\n\n /**\n * Indicates if the edited element is a new one or not.\n * @type {Boolean}\n */\n this.isNewElement = true;\n\n /**\n * {@link IntegrationModel} instance. Needed to call wrapper methods.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n }\n\n /**\n * Adds a new listener to the current {@link ContentManager} instance.\n * @param {Object} listener - The listener to be added.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Sets an instance of {@link IntegrationModel} class to the current {@link ContentManager}\n * instance.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} instance.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link ModalDialog} instance into the current {@link ContentManager} instance.\n * @param {ModalDialog} modalDialogInstance - The {@link ModalDialog} instance\n */\n setModalDialogInstance(modalDialogInstance) {\n this.modalDialogInstance = modalDialogInstance;\n }\n\n /**\n * Inserts the content into the current {@link ModalDialog} instance updating\n * the title and inserting the JavaScript editor.\n */\n insert() {\n // Before insert the editor we update the modal object title to avoid weird render display.\n this.updateTitle(this.modalDialogInstance);\n this.insertEditor(this.modalDialogInstance);\n }\n\n /**\n * Inserts MathType editor into the {@link ModalDialog.contentContainer}. It waits until\n * editor's JavaScript is loaded.\n */\n insertEditor() {\n if (ContentManager.isEditorLoaded()) {\n this.editor = window.com.wiris.jsEditor.JsEditor.newInstance(this.editorAttributes);\n this.editor.insertInto(this.modalDialogInstance.contentContainer);\n this.editor.focus();\n\n // `editor.action(\"rtl\");` toggles the RTL mode based on the current state, it doesn't just switch to RTL.\n if (this.modalDialogInstance.rtl && !this.editor.getEditorModel().isRTL()) {\n this.editor.action(\"rtl\");\n }\n // Setting div in rtl in case of it's activated.\n if (this.editor.getEditorModel().isRTL()) {\n this.editor.element.style.direction = \"rtl\";\n }\n\n // Editor listener: this object manages the changes logic of editor.\n this.editor.getEditorModel().addEditorListener(this.editorListener);\n\n // iOS events.\n if (this.modalDialogInstance.deviceProperties.isIOS) {\n setTimeout(function () {\n // Make sure the modalDialogInstance is available when the timeout is over\n // to avoid throw errors and stop execution.\n if (this.hasOwnProperty(\"modalDialogInstance\")) this.modalDialogInstance.hideKeyboard(); // eslint-disable-line no-prototype-builtins\n }, 400);\n\n const formulaDisplayDiv = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n Util.addEvent(formulaDisplayDiv, \"focus\", this.modalDialogInstance.handleOpenedIosSoftkeyboard);\n Util.addEvent(formulaDisplayDiv, \"blur\", this.modalDialogInstance.handleClosedIosSoftkeyboard);\n }\n // Fire onLoad event. Necessary to set the MathML into the editor\n // after is loaded.\n this.listeners.fire(\"onLoad\", {});\n } else {\n setTimeout(ContentManager.prototype.insertEditor.bind(this), 100);\n }\n }\n\n /**\n * Initializes the current class by loading MathType script.\n */\n init() {\n if (!ContentManager.isEditorLoaded()) {\n this.addEditorAsExternalDependency();\n }\n }\n\n /**\n * Adds script element to the DOM to include editor externally.\n */\n addEditorAsExternalDependency() {\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n let editorUrl = Configuration.get(\"editorUrl\");\n\n // We create an object url for parse url string and work more efficiently.\n const anchorElement = document.createElement(\"a\");\n\n ContentManager.setHrefToAnchorElement(anchorElement, editorUrl);\n ContentManager.setProtocolToAnchorElement(anchorElement);\n\n editorUrl = ContentManager.getURLFromAnchorElement(anchorElement);\n\n // Load editor URL. We add stats as GET params.\n const stats = this.getEditorStats();\n script.src = `${editorUrl}?lang=${this.language}&stats-editor=${stats.editor}&stats-mode=${stats.mode}&stats-version=${stats.version}`;\n\n document.getElementsByTagName(\"head\")[0].appendChild(script);\n }\n\n /**\n * Sets the specified url to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set 'url'.\n * @param {String} url - URL to set.\n */\n static setHrefToAnchorElement(anchorElement, url) {\n anchorElement.href = url;\n }\n\n /**\n * Sets the current protocol to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set its protocol.\n */\n static setProtocolToAnchorElement(anchorElement) {\n // Change to https if necessary.\n if (window.location.href.indexOf(\"https://\") === 0) {\n // It check if browser is https and configuration is http.\n // If this is so, we will replace protocol.\n if (anchorElement.protocol === \"http:\") {\n anchorElement.protocol = \"https:\";\n }\n }\n }\n\n /**\n * Returns the url of the anchor element adding the current port\n * if it is needed.\n * @param {HTMLAnchorElement} anchorElement - Element where extract the url.\n * @returns {String}\n */\n static getURLFromAnchorElement(anchorElement) {\n // Check protocol and remove port if it's standard.\n const removePort = anchorElement.port === \"80\" || anchorElement.port === \"443\" || anchorElement.port === \"\";\n return `${anchorElement.protocol}//${anchorElement.hostname}${removePort ? \"\" : `:${anchorElement.port}`}${anchorElement.pathname.startsWith(\"/\") ? anchorElement.pathname : `/${anchorElement.pathname}`}`; // eslint-disable-line max-len\n }\n\n /**\n * Returns object with editor stats.\n *\n * @typedef {Object} EditorStatsObject\n * @property {string} editor - Editor name.\n * @property {string} mode - Current configuration for formula save mode.\n * @property {string} version - Current plugins version.\n * @returns {EditorStatsObject}\n */\n getEditorStats() {\n // Editor stats. Use environment property to set it.\n const stats = {};\n if (\"editor\" in this.environment) {\n stats.editor = this.environment.editor;\n } else {\n stats.editor = \"unknown\";\n }\n\n if (\"mode\" in this.environment) {\n stats.mode = this.environment.mode;\n } else {\n stats.mode = Configuration.get(\"saveMode\");\n }\n\n if (\"version\" in this.environment) {\n stats.version = this.environment.version;\n } else {\n stats.version = Configuration.get(\"version\");\n }\n\n return stats;\n }\n\n /**\n * Returns true if device is iOS. Otherwise, false.\n * @returns {Boolean}\n */\n static isIOS() {\n return (\n [\"iPad Simulator\", \"iPhone Simulator\", \"iPod Simulator\", \"iPad\", \"iPhone\", \"iPod\"].includes(navigator.platform) ||\n // iPad on iOS 13 detection\n (navigator.userAgent.includes(\"Mac\") && \"ontouchend\" in document)\n );\n }\n\n /**\n * Returns true if device is Mobile. Otherwise, false.\n * @returns {Boolean}\n */\n static isMobile() {\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n /**\n * Returns true if editor is loaded. Otherwise, false.\n * @returns {Boolean}\n */\n static isEditorLoaded() {\n // To know if editor JavaScript is loaded we need to wait until\n // window.com.wiris.jsEditor.JsEditor.newInstance is ready.\n return (\n window.com &&\n window.com.wiris &&\n window.com.wiris.jsEditor &&\n window.com.wiris.jsEditor.JsEditor &&\n window.com.wiris.jsEditor.JsEditor.newInstance\n );\n }\n\n /**\n * Sets the {@link ContentManager.editor} initial content.\n */\n setInitialContent() {\n if (!this.isNewElement) {\n this.setMathML(this.mathML);\n }\n }\n\n /**\n * Sets a MathML into {@link ContentManager.editor} instance.\n * @param {String} mathml - MathML string.\n * @param {Boolean} focusDisabled - If true editor don't get focus after the MathML is set.\n * False by default.\n */\n setMathML(mathml, focusDisabled) {\n // By default focus is enabled.\n if (typeof focusDisabled === \"undefined\") {\n focusDisabled = false;\n }\n // Using setMathML method is not a change produced by the user but for the API\n // so we set to false the contentChange property of editorListener.\n this.editor.setMathMLWithCallback(mathml, () => {\n this.editorListener.setWaitingForChanges(true);\n });\n\n // We need to wait a little until the callback finish.\n setTimeout(() => {\n this.editorListener.setIsContentChanged(false);\n }, 500);\n\n // In some scenarios - like closing modal object - editor mustn't be focused.\n if (!focusDisabled) {\n this.onFocus();\n }\n }\n\n /**\n * Sets the focus to the current instance of {@link ContentManager.editor}. Triggered by\n * {@link ModalDialog.focus}.\n */\n onFocus() {\n if (typeof this.editor !== \"undefined\" && this.editor != null) {\n this.editor.focus();\n\n // On WordPress integration, the focus gets lost right after setting it.\n // To fix this, we enforce another focus some milliseconds after this behaviour.\n setTimeout(() => {\n this.editor.focus();\n }, 100);\n }\n }\n\n /**\n * Updates the edition area by calling {@link IntegrationModel.updateFormula}.\n * Triggered by {@link ModalDialog.submitAction}.\n */\n submitAction() {\n if (!this.editor.isFormulaEmpty()) {\n let mathML = this.editor.getMathMLWithSemantics();\n // Add class for custom editors.\n if (this.customEditors.getActiveEditor() !== null) {\n const { toolbar } = this.customEditors.getActiveEditor();\n mathML = MathML.addCustomEditorClassAttribute(mathML, toolbar);\n } else {\n // We need - if exists - the editor name from MathML\n // class attribute.\n Object.keys(this.customEditors.editors).forEach((key) => {\n mathML = MathML.removeCustomEditorClassAttribute(mathML, key);\n });\n }\n const mathmlEntitiesEncoded = MathML.mathMLEntities(mathML);\n this.integrationModel.updateFormula(mathmlEntitiesEncoded);\n } else {\n this.integrationModel.updateFormula(null);\n }\n\n this.customEditors.disable();\n this.integrationModel.notifyWindowClosed();\n\n // Set disabled focus to prevent lost focus.\n this.setEmptyMathML();\n this.customEditors.disable();\n }\n\n /**\n * Sets an empty MathML as {@link ContentManager.editor} content.\n * This will open the MT/CT editor with the hand mode.\n * It adds dir rtl in case of it's activated.\n */\n setEmptyMathML() {\n const isMobile = this.deviceProperties.isAndroid || this.deviceProperties.isIOS;\n const isRTL = this.editor.getEditorModel().isRTL();\n\n if (isMobile || this.integrationModel.forcedHandMode) {\n // For mobile devices or forced hand mode, set an empty annotation MATHML to maintain the editor in Hand mode.\n const mathML = `[]`;\n this.setMathML(mathML, true);\n } else {\n // For non-mobile devices or not forced hand mode, set the empty MathML without an annotation.\n const mathML = ``;\n this.setMathML(mathML, true);\n }\n }\n\n /**\n * Open event. Triggered by {@link ModalDialog.open}. Does the following:\n * - Updates the {@link ContentManager.editor} content\n * (with an empty MathML or an existing formula),\n * - Updates the {@link ContentManager.editor} toolbar.\n * - Recovers the the focus.\n */\n onOpen() {\n if (this.isNewElement) {\n this.setEmptyMathML();\n } else {\n this.setMathML(this.mathML);\n }\n const toolbar = this.updateToolbar();\n this.onFocus();\n\n if (this.deviceProperties.isIOS) {\n const zoom = document.documentElement.clientWidth / window.innerWidth;\n\n if (zoom !== 1) {\n // Open editor in Keyboard mode if user use iOS, Safari and page is zoomed.\n this.setKeyboardMode();\n }\n }\n\n const trigger = this.dbclick ? \"formula\" : \"button\";\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"OPENED_MTCT_EDITOR\", {\n toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking OPENED_MTCT_EDITOR\", error);\n }\n\n Core.globalListeners.fire(\"onModalOpen\", {});\n\n if (this.integrationModel.forcedHandMode) {\n this.hideHandModeButton();\n\n // In case we have a keyboard written formula, we still want it to be opened with handMode.\n if (this.mathML && !this.mathML.includes('') && !this.isNewElement) {\n this.openHandOnKeyboardMathML(this.mathML, this.editor);\n }\n }\n }\n\n /**\n * Change Editor in keyboard mode when is loaded\n */\n setKeyboardMode() {\n const wrsEditor = document.getElementsByClassName(\"wrs_handOpen wrs_disablePalette\")[0];\n if (wrsEditor) {\n wrsEditor.classList.remove(\"wrs_handOpen\");\n wrsEditor.classList.remove(\"wrs_disablePalette\");\n } else {\n setTimeout(ContentManager.prototype.setKeyboardMode.bind(this), 100);\n }\n }\n\n /**\n * Hides the hand <-> keyboard mode switch.\n *\n * This method relies completely on the classes used on different HTML elements within the editor itself, meaning\n * any change on those classes will make this code stop working properly.\n *\n * On top of that, some of those classes are changed on runtime (for example, the one that makes some buttons change).\n * This forces us to use some delayed code (this is, a timeout) to make sure everything exists when we need it.\n * @param {*} forced (boolean) Forces the user to stay in Hand mode by hiding the keyboard mode button.\n */\n hideHandModeButton(forced = true) {\n if (this.handSwitchHidden) {\n return; // hand <-> keyboard button already hidden.\n }\n\n // \"Open hand mode\" button takes a little bit to be available.\n // This selector gets the hand <-> keyboard mode switch\n const handModeButtonSelector =\n \"div.wrs_editor.wrs_flexEditor.wrs_withHand.wrs_animated .wrs_handWrapper input[type=button]\";\n\n // If in \"forced mode\", we hide the \"keyboard button\" so the user can't can't change between hand and keyboard modes.\n // We use an observer to ensure that the button it hidden as soon as it appears.\n if (forced) {\n const mutationInstance = new MutationObserver((mutations) => {\n const handModeButton = document.querySelector(handModeButtonSelector);\n if (handModeButton) {\n handModeButton.hidden = true;\n this.handSwitchHidden = true;\n mutationInstance.disconnect();\n }\n });\n mutationInstance.observe(document.body, {\n attributes: true,\n childList: true,\n characterData: true,\n subtree: true,\n });\n }\n }\n\n /**\n * It will open any formula written in Keyboard mode with the hand mode with the default hand trace.\n *\n * @param {String} mathml The original KeyBoard MathML\n * @param {Object} editor The editor object.\n */\n async openHandOnKeyboardMathML(mathml, editor) {\n // First, as an editor requirement, we need to update the editor object with the current MathML formula.\n // Once the MathML formula is updated to the one we want to open with handMode, we will be able to proceed.\n await new Promise((resolve) => {\n editor.setMathMLWithCallback(mathml, resolve);\n });\n\n // We wait until the hand editor object exists.\n await this.waitForHand(editor);\n\n // Logic to get the hand traces and open the formula in hand mode.\n // This logic comes from the editor.\n const handEditor = editor.hand;\n editor.handTemporalMathML = editor.getMathML();\n const handCoordinates = editor.editorModel.getHandStrokes();\n handEditor.setStrokes(handCoordinates);\n handEditor.fitStrokes(true);\n editor.openHand();\n }\n\n /**\n * Waits until the hand editor object exists.\n * @param {Obect} editor The editor object.\n */\n async waitForHand(editor) {\n while (!editor.hand) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Sets the correct toolbar depending if exist other custom toolbars\n * at the same time (e.g: Chemistry).\n */\n updateToolbar() {\n this.updateTitle(this.modalDialogInstance);\n const customEditor = this.customEditors.getActiveEditor();\n\n let toolbar;\n if (customEditor) {\n toolbar = customEditor.toolbar ? customEditor.toolbar : _wrs_int_wirisProperties.toolbar;\n\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n }\n } else {\n toolbar = this.getToolbar();\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n this.customEditors.disable();\n }\n }\n\n return toolbar;\n }\n\n /**\n * Updates the current {@link ModalDialog.title}. If a {@link CustomEditors} is enabled\n * sets the custom editor title. Otherwise sets the default title.\n */\n updateTitle() {\n const customEditor = this.customEditors.getActiveEditor();\n if (customEditor) {\n this.modalDialogInstance.setTitle(customEditor.title);\n } else {\n this.modalDialogInstance.setTitle(\"MathType\");\n }\n }\n\n /**\n * Returns the editor toolbar, depending on the configuration local or server side.\n * @returns {String} - Toolbar identifier.\n */\n getToolbar() {\n let toolbar = \"general\";\n if (\"toolbar\" in this.editorAttributes) {\n ({ toolbar } = this.editorAttributes);\n }\n // TODO: Change global integration variable for integration custom toolbar.\n if (toolbar === \"general\") {\n // eslint-disable-next-line camelcase\n toolbar =\n typeof _wrs_int_wirisProperties === \"undefined\" || typeof _wrs_int_wirisProperties.toolbar === \"undefined\"\n ? \"general\"\n : _wrs_int_wirisProperties.toolbar;\n }\n\n return toolbar;\n }\n\n /**\n * Sets the current {@link ContentManager.editor} instance toolbar.\n * @param {String} toolbar - The toolbar name.\n */\n setToolbar(toolbar) {\n this.toolbar = toolbar;\n this.editor.setParams({ toolbar: this.toolbar });\n }\n\n /**\n * Sets the custom headers added on editor requests.\n * @returns {Object} headers - key value headers.\n */\n setCustomHeaders(headers) {\n let headersObj = {};\n\n // We control that we only get String or Object as the input.\n if (typeof headers === \"object\") {\n headersObj = headers;\n } else if (typeof headers === \"string\") {\n headersObj = Util.convertStringToObject(headers);\n }\n\n this.editor.setParams({ customHeaders: headersObj });\n return headersObj;\n }\n\n /**\n * Returns true if the content of the editor has been changed. The logic of the changes\n * is delegated to {@link EditorListener} class.\n * @returns {Boolean} True if the editor content has been changed. False otherwise.\n */\n hasChanges() {\n return !this.editor.isFormulaEmpty() && this.editorListener.getIsContentChanged();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined && keyboardEvent.repeat === false) {\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n // Code to detect Esc event.\n // There should be only one element with class name 'wrs_pressed' at the same time.\n let list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor3RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor2RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_select wrs_pressed\");\n if (list.length === 0) {\n this.modalDialogInstance.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.modalDialogInstance.submitButton) {\n // Focus is on OK button.\n this.editor.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.querySelector('[title=\"Manual\"]') === document.activeElement) {\n // Focus is on minimize button (_).\n this.modalDialogInstance.closeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.minimizeDiv) {\n // Focus on cancel button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n this.modalDialogInstance.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.modalDialogInstance.cancelButton) {\n // Focus is on X button.\n this.modalDialogInstance.minimizeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.closeDiv) {\n // Focus on help button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n const element = document.querySelector('[title=\"Manual\"]');\n element.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n } else {\n // There should be only one element with class name 'wrs_formulaDisplay'.\n const element = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n if (element.getAttribute(\"class\") === \"wrs_formulaDisplay wrs_focused\") {\n // Focus is on formuladisplay.\n this.modalDialogInstance.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n }\n }\n}\n","/**\n * A custom editor is MathType editor with a different\n * @typedef {Object} CustomEditor\n * @property {String} CustomEditor.name - Custom editor name.\n * @property {String} CustomEditor.toolbar - Custom editor toolbar.\n * @property {String} CustomEditor.icon - Custom editor icon.\n * @property {String} CustomEditor.confVariable - Configuration property to manage\n * the availability of the custom editor.\n * @property {String} CustomEditor.title - Custom editor modal dialog title.\n * @property {String} CustomEditor.tooltip - Custom editor icon tooltip.\n */\n\nexport default class CustomEditors {\n /**\n * @classdesc\n * This class represents the MathType custom editors manager.\n * A custom editor is MathType editor with a custom toolbar.\n * This class associates a {@link CustomEditor} to:\n * - It's own formulas\n * - A custom toolbar\n * - An icon to open it from a HTML editor.\n * - A tooltip for the icon.\n * - A global variable to enable or disable it globally.\n * @constructs\n */\n constructor() {\n /**\n * The custom editors.\n * @type {Array.}\n */\n\n this.editors = [];\n /**\n * The active editor name.\n * @type {String}\n */\n this.activeEditor = \"default\";\n }\n\n /**\n * Adds a {@link CustomEditor} to editors array.\n * @param {String} editorName - The editor name.\n * @param {CustomEditor} editorParams - The custom editor parameters.\n */\n addEditor(editorName, editorParams) {\n const customEditor = {};\n customEditor.name = editorParams.name;\n customEditor.toolbar = editorParams.toolbar;\n customEditor.icon = editorParams.icon;\n customEditor.confVariable = editorParams.confVariable;\n customEditor.title = editorParams.title;\n customEditor.tooltip = editorParams.tooltip;\n this.editors[editorName] = customEditor;\n }\n\n /**\n * Enables a {@link CustomEditor}.\n * @param {String} customEditorName - The custom editor name.\n */\n enable(customEditorName) {\n this.activeEditor = customEditorName;\n }\n\n /**\n * Disables a {@link CustomEditor}.\n */\n disable() {\n this.activeEditor = \"default\";\n }\n\n /**\n * Returns the active editor.\n * @return {CustomEditor} - A {@link CustomEditor} if a custom editor is enabled. Null otherwise.\n */\n getActiveEditor() {\n if (this.activeEditor !== \"default\") {\n return this.editors[this.activeEditor];\n }\n return null;\n }\n}\n","/**\n * Represents the configuration properties generated from the frontend (JavaScript variables).\n * @type {Object}\n * @property {string} imageClassName - Default MathType formula image class.\n * @property {string} imageClassName - Default MathType CAS image class.\n * @ignore\n */\nconst jsProperties = {\n imageCustomEditorName: \"data-custom-editor\",\n imageClassName: \"Wirisformula\",\n CASClassName: \"Wiriscas\",\n};\nexport default jsProperties;\n","export default class Event {\n /**\n * @classdesc\n * This class represents a custom event. Events should be fired by the {@link Listener} class.\n *\n * ```js\n * let customEvent = new Event();\n * customEvent.properties = {};\n *\n * let listeners = new Listeners();\n * listeners.newListener(eventName, callback);\n *\n * listeners.fire(eventName, customEvent) *\n * ```\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the event should be cancelled.\n * @type {Boolean}\n */\n\n this.cancelled = false;\n /**\n * Indicates if the event should be prevented.\n * @type {Boolean}\n */\n this.defaultPrevented = false;\n }\n\n /**\n * Cancels the event.\n */\n cancel() {\n this.cancelled = true;\n }\n\n /**\n * Prevents the default action.\n */\n preventDefault() {\n this.defaultPrevented = true;\n }\n}\n","import IntegrationModel from \"./integrationmodel\";\n\n/**\n\n */\nexport default class PopUpMessage {\n /**\n * @classdesc\n * This class represents a dialog message overlaying a DOM element in order to\n * accept / cancel discard changes. The dialog can be closed i.e the overlay disappears\n * o canceled. In this last case a callback function should be called.\n * @constructs\n * @param {Object} popupMessageAttributes - Object containing popup properties.\n * @param {HTMLElement} popupMessageAttributes.overlayElement - Element to overlay.\n * @param {Object} popupMessageAttributes.callbacks - Contains callback\n * methods for close and cancel actions.\n * @param {Object} popupMessageAttributes.strings - Contains all the strings needed.\n */\n constructor(popupMessageAttributes) {\n /**\n * Element to be overlaid when the popup appears.\n */\n this.overlayElement = popupMessageAttributes.overlayElement;\n\n this.callbacks = popupMessageAttributes.callbacks;\n\n /**\n * HTMLElement element to wrap all HTML elements inside the popupMessage.\n */\n this.overlayWrapper = this.overlayElement.appendChild(document.createElement(\"div\"));\n this.overlayWrapper.setAttribute(\"class\", \"wrs_popupmessage_overlay_envolture\");\n\n /**\n * HTMLElement to display the popup message, close button and cancel button.\n */\n this.message = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n this.message.id = \"wrs_popupmessage\";\n this.message.setAttribute(\"class\", \"wrs_popupmessage_panel\");\n this.message.setAttribute(\"role\", \"dialog\");\n this.message.setAttribute(\"aria-describedby\", \"description_txt\");\n const paragraph = document.createElement(\"p\");\n const text = document.createTextNode(popupMessageAttributes.strings.message);\n paragraph.appendChild(text);\n paragraph.id = \"description_txt\";\n this.message.appendChild(paragraph);\n\n /**\n * HTML element overlaying the overlayElement.\n */\n const overlay = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n overlay.setAttribute(\"class\", \"wrs_popupmessage_overlay\");\n // We create a overlay that close popup message on click in there\n overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n /**\n * HTML element containing cancel and close buttons.\n */\n this.buttonArea = this.message.appendChild(document.createElement(\"div\"));\n this.buttonArea.setAttribute(\"class\", \"wrs_popupmessage_button_area\");\n this.buttonArea.id = \"wrs_popup_button_area\";\n\n // Close button arguments.\n const buttonSubmitArguments = {\n class: \"wrs_button_accept\",\n innerHTML: popupMessageAttributes.strings.submitString,\n id: \"wrs_popup_accept_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-close-button\",\n };\n\n /**\n * Close button arguments.\n */\n this.closeButton = this.createButton(buttonSubmitArguments, this.closeAction.bind(this));\n this.buttonArea.appendChild(this.closeButton);\n\n // Cancel button arguments.\n const buttonCancelArguments = {\n class: \"wrs_button_cancel\",\n innerHTML: popupMessageAttributes.strings.cancelString,\n id: \"wrs_popup_cancel_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-cancel-button\",\n };\n\n /**\n * Cancel button.\n */\n this.cancelButton = this.createButton(buttonCancelArguments, this.cancelAction.bind(this));\n this.buttonArea.appendChild(this.cancelButton);\n }\n\n /**\n * This method create a button with arguments and return button dom object\n * @param {Object} parameters - An object containing id, class and innerHTML button text.\n * @param {String} parameters.id - Button id.\n * @param {String} parameters.class - Button class name.\n * @param {String} parameters.innerHTML - Button innerHTML text.\n * @param {Object} callback- Callback method to call on click event.\n * @returns {HTMLElement} HTML button.\n */\n // eslint-disable-next-line class-methods-use-this\n createButton(parameters, callback) {\n let element = {};\n element = document.createElement(\"button\");\n element.setAttribute(\"id\", parameters.id);\n element.setAttribute(\"class\", parameters.class);\n element.innerHTML = parameters.innerHTML;\n element.addEventListener(\"click\", callback);\n if (parameters[\"data-testid\"]) {\n element.setAttribute(\"data-testid\", parameters[\"data-testid\"]);\n }\n\n return element;\n }\n\n /**\n * Shows the popupmessage containing a message, and two buttons\n * to cancel the action or close the modal dialog.\n */\n show() {\n if (this.overlayWrapper.style.display !== \"block\") {\n // Clear focus with blur for prevent press any key.\n document.activeElement.blur();\n this.overlayWrapper.style.display = \"block\";\n this.closeButton.focus();\n } else {\n this.overlayWrapper.style.display = \"none\";\n // _wrs_modalWindow.focus(); This throws an error of not existing _wrs_modalWindow\n }\n }\n\n /**\n * This method cancels the popupMessage: the dialog disappears revealing the overlaid element.\n * A callback method is called (if defined). For example a method to focus the overlaid element.\n */\n cancelAction() {\n this.overlayWrapper.style.display = \"none\";\n if (typeof this.callbacks.cancelCallback !== \"undefined\") {\n this.callbacks.cancelCallback();\n // Set temporal image to null to prevent loading\n // an existent formula when starting one from scratch. Make focus come back too.\n // IntegrationModel.setActionsOnCancelButtons();\n }\n }\n\n /**\n * This method closes the popupMessage: the dialog disappears and the close callback is called.\n * For example to close the overlaid element.\n */\n closeAction() {\n this.cancelAction();\n if (typeof this.callbacks.closeCallback !== \"undefined\") {\n this.callbacks.closeCallback();\n }\n IntegrationModel.setActionsOnCancelButtons();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Code to detect Esc event.\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n this.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.closeButton) {\n this.cancelButton.focus();\n } else {\n this.closeButton.focus();\n }\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n}\n","/**\n * This module provides protection against external focus management scripts\n * that might interfere with the MathType editor modal.\n */\n\n/**\n * focusProtection function creates and returns methods to prevent external scripts from\n * interfering with the focus of the MathType modal dialog.\n *\n * @returns {Object} An object with protect and unprotect methods.\n */\nconst focusProtection = () => {\n /**\n * Initialize focus protection on the given modal element.\n *\n * @param {HTMLElement} modalElement - The modal element to protect\n * @param {HTMLElement} overlayElement - The overlay element of the modal (not used in current implementation)\n * @param {HTMLElement} editorElement - The editor element inside the modal\n */\n const protect = (modalElement, overlayElement, editorElement) => {\n if (!modalElement || !overlayElement || !editorElement) {\n console.warn(\"FocusProtection: Missing required elements\");\n return;\n }\n\n // Apply the focus protection\n overrideFocusBehavior(modalElement, editorElement);\n };\n\n /**\n * Apply focus protection by overriding focus-related methods\n *\n * @param {HTMLElement} modalElement - The modal element\n * @param {HTMLElement} editorElement - The editor element to keep focused\n * @private\n */\n const overrideFocusBehavior = (modalElement, editorElement) => {\n // Store original focus methods to be able to restore them\n const originalElementFocus = HTMLElement.prototype.focus;\n const originalElementBlur = HTMLElement.prototype.blur;\n\n // Override the focus method for all elements\n HTMLElement.prototype.focus = function (...args) {\n // If the modal is open and this is not part of the modal, prevent focus\n if (modalElement.style.display !== \"none\" && !modalElement.contains(this) && this !== document.body) {\n // If some external script is trying to focus another element, prevent it\n // and restore focus to the editor\n if (editorElement) {\n // Use the original focus method to avoid infinite recursion\n originalElementFocus.apply(editorElement, args);\n }\n return;\n }\n\n // Otherwise, allow the focus to happen\n originalElementFocus.apply(this, args);\n };\n\n // Store the methods to remove them when the modal is closed\n modalElement.originalElementFocus = originalElementFocus;\n modalElement.originalElementBlur = originalElementBlur;\n };\n\n /**\n * Remove focus protection from the modal\n *\n * @param {HTMLElement} modalElement - The modal element to unprotect\n */\n const unprotect = (modalElement) => {\n if (!modalElement) {\n return;\n }\n\n // Restore original focus methods\n if (modalElement.originalElementFocus) {\n HTMLElement.prototype.focus = modalElement.originalElementFocus;\n delete modalElement.originalElementFocus;\n }\n\n if (modalElement.originalElementBlur) {\n HTMLElement.prototype.blur = modalElement.originalElementBlur;\n delete modalElement.originalElementBlur;\n }\n };\n\n return {\n protect,\n unprotect,\n };\n};\n\nexport default focusProtection;\n","// eslint-disable-next-line max-classes-per-file\nimport PopUpMessage from \"./popupmessage\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport Listeners from \"./listeners\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Telemeter from \"./telemeter\";\nimport IntegrationModel from \"./integrationmodel\";\nimport Core from \"./core.src\";\nimport focusProtection from \"./focusprotection\";\nimport closeIcon from \"../styles/icons/general/close_icon.svg\"; //eslint-disable-line\nimport closeHoverIcon from \"../styles/icons/hover/close_icon_h.svg\"; //eslint-disable-line\nimport fullsIcon from \"../styles/icons/general/fulls_icon.svg\"; //eslint-disable-line\nimport fullsHoverIcon from \"../styles/icons/hover/fulls_icon_h.svg\"; //eslint-disable-line\nimport minIcon from \"../styles/icons/general/min_icon.svg\"; //eslint-disable-line\nimport minHoverIcon from \"../styles/icons/hover/min_icon_h.svg\"; //eslint-disable-line\nimport minsIcon from \"../styles/icons/general/mins_icon.svg\"; //eslint-disable-line\nimport minsHoverIcon from \"../styles/icons/hover/mins_icon_h.svg\"; //eslint-disable-line\nimport maxIcon from \"../styles/icons/general/max_icon.svg\"; //eslint-disable-line\nimport maxHoverIcon from \"../styles/icons/hover/max_icon_h.svg\"; //eslint-disable-line\nconst { unprotect, protect } = focusProtection();\n\n/**\n * @typedef {Object} DeviceProperties\n * @property {String} DeviceProperties.orientation - Indicates of the orientation of the device.\n * @property {Boolean} DeviceProperties.isAndroid - True if the device is Android. False otherwise.\n * @property {Boolean} DeviceProperties.isIOS - True if the device is iOS. False otherwise.\n * @property {Boolean} DeviceProperties.isMobile - True if the device is a mobile one.\n * False otherwise.\n * @property {Boolean} DeviceProperties.isDesktop - True if the device is a desktop one.\n * False otherwise.\n */\n\nexport default class ModalDialog {\n /**\n * @classdesc\n * This class represents a modal dialog. The modal dialog admits\n * a {@link ContentManager} instance to manage the content of the dialog.\n * @constructs\n * @param {Object} modalDialogAttributes - An object containing all modal dialog attributes.\n */\n constructor(modalDialogAttributes) {\n this.attributes = modalDialogAttributes;\n\n // Metrics.\n const ua = navigator.userAgent.toLowerCase();\n const isAndroid = ua.indexOf(\"android\") > -1;\n const isIOS = ContentManager.isIOS();\n this.iosSoftkeyboardOpened = false;\n this.iosMeasureUnit = ua.indexOf(\"crios\") === -1 ? \"%\" : \"vh\";\n this.iosDivHeight = `auto`;\n\n const deviceWidth = window.outerWidth;\n const deviceHeight = window.outerHeight;\n\n const landscape = deviceWidth > deviceHeight;\n const portrait = deviceWidth < deviceHeight;\n\n // TODO: Detect isMobile without using editor metrics.\n const isLandscape = landscape && this.attributes.height > deviceHeight;\n const isPortrait = portrait && this.attributes.width > deviceWidth;\n const isMobile = ContentManager.isMobile();\n\n // Obtain number of current instance.\n this.instanceId = document.getElementsByClassName(\"wrs_modal_dialogContainer\").length;\n\n // Device object properties.\n\n /**\n * @type {DeviceProperties}\n */\n this.deviceProperties = {\n orientation: landscape ? \"landscape\" : \"portrait\",\n isAndroid,\n isIOS,\n isMobile,\n isDesktop: !isMobile && !isIOS && !isAndroid,\n };\n\n this.properties = {\n created: false,\n state: \"\",\n previousState: \"\",\n position: { bottom: 0, right: 10 },\n size: { height: 338, width: 580 },\n };\n\n /**\n * Object to keep website's style before change it on lock scroll for mobile devices.\n * @type {Object}\n * @property {String} bodyStylePosition - Previous body style position.\n * @property {String} bodyStyleOverflow - Previous body style overflow.\n * @property {String} htmlStyleOverflow - Previous body style overflow.\n * @property {String} windowScrollX - Previous window's scroll Y.\n * @property {String} windowScrollY - Previous window's scroll X.\n */\n this.websiteBeforeLockParameters = null;\n\n let attributes = {};\n attributes.class = \"wrs_modal_overlay\";\n attributes.id = this.getElementId(attributes.class);\n this.overlay = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title_bar\";\n attributes.id = this.getElementId(attributes.class);\n this.titleBar = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title\";\n attributes.id = this.getElementId(attributes.class);\n this.title = Util.createElement(\"div\", attributes);\n this.title.innerHTML = \"offline\";\n\n attributes = {};\n attributes.class = \"wrs_modal_close_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"close\");\n attributes.style = {};\n this.closeDiv = Util.createElement(\"a\", attributes);\n this.closeDiv.setAttribute(\"role\", \"button\");\n this.closeDiv.setAttribute(\"tabindex\", 3);\n // Apply styles and events after the creation as createElement doesn't process them correctly\n const generalStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`;\n const hoverStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`;\n this.closeDiv.setAttribute(\"style\", generalStyleClose);\n this.closeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleClose));\n this.closeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleClose));\n // To identifiy the element in automated testing\n this.closeDiv.setAttribute(\"data-testid\", \"mtcteditor-close-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_stack_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"exit_fullscreen\");\n this.stackDiv = Util.createElement(\"a\", attributes);\n this.stackDiv.setAttribute(\"role\", \"button\");\n this.stackDiv.setAttribute(\"tabindex\", 2);\n const generalStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`;\n const hoverStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`;\n this.stackDiv.setAttribute(\"style\", generalStyleStack);\n this.stackDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleStack));\n this.stackDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleStack));\n // To identifiy the element in automated testing\n this.stackDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-disable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_maximize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"fullscreen\");\n this.maximizeDiv = Util.createElement(\"a\", attributes);\n this.maximizeDiv.setAttribute(\"role\", \"button\");\n this.maximizeDiv.setAttribute(\"tabindex\", 2);\n const generalStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`;\n const hoverStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`;\n this.maximizeDiv.setAttribute(\"style\", generalStyleMaximize);\n this.maximizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleMaximize));\n this.maximizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleMaximize));\n // To identifiy the element in automated testing\n this.maximizeDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-enable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_minimize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"minimize\");\n this.minimizeDiv = Util.createElement(\"a\", attributes);\n this.minimizeDiv.setAttribute(\"role\", \"button\");\n this.minimizeDiv.setAttribute(\"tabindex\", 1);\n const generalStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyleMinimize);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleMinimize));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleMinimize));\n // To identify the element in automated testing\n this.minimizeDiv.setAttribute(\"data-testid\", \"mtcteditor-minimize-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_dialogContainer\";\n attributes.id = this.getElementId(attributes.class);\n attributes.role = \"dialog\";\n this.container = Util.createElement(\"div\", attributes);\n this.container.setAttribute(\"aria-labeledby\", \"wrs_modal_title[0]\");\n\n attributes = {};\n attributes.class = \"wrs_modal_wrapper\";\n attributes.id = this.getElementId(attributes.class);\n this.wrapper = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_content_container\";\n attributes.id = this.getElementId(attributes.class);\n this.contentContainer = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_controls\";\n attributes.id = this.getElementId(attributes.class);\n this.controls = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_buttons_container\";\n attributes.id = this.getElementId(attributes.class);\n this.buttonContainer = Util.createElement(\"div\", attributes);\n\n // Buttons: all button must be created using createSubmitButton method.\n this.submitButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_accept\"),\n class: \"wrs_modal_button_accept\",\n innerHTML: StringManager.get(\"accept\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-insert-button\",\n },\n this.submitAction.bind(this),\n );\n\n this.cancelButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_cancel\"),\n class: \"wrs_modal_button_cancel\",\n innerHTML: StringManager.get(\"cancel\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cancel-button\",\n },\n this.cancelAction.bind(this),\n );\n\n this.contentManager = null;\n\n // Overlay popup.\n const popupStrings = {\n cancelString: StringManager.get(\"cancel\"),\n submitString: StringManager.get(\"close\"),\n message: StringManager.get(\"close_modal_warning\"),\n };\n\n const callbacks = {\n closeCallback: () => {\n this.close(\"mtc_close\");\n },\n cancelCallback: () => {\n this.focus();\n },\n };\n\n const popupupProperties = {\n overlayElement: this.container,\n callbacks,\n strings: popupStrings,\n };\n\n this.popup = new PopUpMessage(popupupProperties);\n\n /**\n * Indicates if directionality of the modal dialog is RTL. false by default.\n * @type {Boolean}\n */\n this.rtl = false;\n if (\"rtl\" in this.attributes) {\n this.rtl = this.attributes.rtl;\n }\n\n // Event handlers need modal instance context.\n this.handleOpenedIosSoftkeyboard = this.handleOpenedIosSoftkeyboard.bind(this);\n this.handleClosedIosSoftkeyboard = this.handleClosedIosSoftkeyboard.bind(this);\n }\n\n /**\n * This method sets an ContentManager instance to ModalDialog. ContentManager\n * manages the logic of ModalDialog content: submit, update, close and changes.\n * @param {ContentManager} contentManager - ContentManager instance.\n */\n setContentManager(contentManager) {\n this.contentManager = contentManager;\n }\n\n /**\n * Returns the modal contentElement object.\n * @returns {ContentManager} the instance of the ContentManager class.\n */\n getContentManager() {\n return this.contentManager;\n }\n\n /**\n * This method is called when the modal object has been submitted. Calls\n * contentElement submitAction method - if exists - and closes the modal\n * object. No logic about the content should be placed here,\n * contentElement.submitAction is the responsible of the content logic.\n */\n async submitAction() {\n if (typeof this.contentManager.submitAction !== \"undefined\") {\n this.contentManager.submitAction();\n }\n\n await this.close(\"mtc_insert\");\n }\n\n /**\n * Performs the cancel action.\n * If there are no changes in the content, it closes the modal.\n * Otherwise, it shows a pop-up message to confirm the cancel action.\n * @returns {Promise} - A promise that resolves when the modal is closed.\n */\n async cancelAction() {\n if (typeof this.contentManager.hasChanges === \"undefined\" || !this.contentManager.hasChanges()) {\n IntegrationModel.setActionsOnCancelButtons();\n await this.close(\"mtc_close\");\n } else {\n this.showPopUpMessage();\n }\n }\n\n /**\n * Returns a button element.\n * @param {Object} properties - Input button properties.\n * @param {String} properties.class - Input button class.\n * @param {String} properties.innerHTML - Input button innerHTML.\n * @param {Object} callback - Callback function associated to click event.\n * @returns {HTMLButtonElement} The button element.\n *\n */\n // eslint-disable-next-line class-methods-use-this\n createSubmitButton(properties, callback) {\n class SubmitButton {\n constructor() {\n this.element = document.createElement(\"button\");\n this.element.id = properties.id;\n this.element.className = properties.class;\n this.element.innerHTML = properties.innerHTML;\n this.element.dataset.testid = properties[\"data-testid\"];\n Util.addEvent(this.element, \"click\", callback);\n }\n\n getElement() {\n return this.element;\n }\n }\n return new SubmitButton(properties, callback).getElement();\n }\n\n /**\n * Creates the modal window object inserting a contentElement object.\n */\n create() {\n /* Modal Window Structure\n _____________________________________________________________________________________\n |wrs_modal_dialog_Container |\n | _________________________________________________________________________________ |\n | |title_bar minimize_button stack_button close_button | |\n | |_______________________________________________________________________________| |\n | |wrapper | |\n | | _____________________________________________________________________________ | |\n | | |content | | |\n | | | | | |\n | | | | | |\n | | |___________________________________________________________________________| | |\n | | _____________________________________________________________________________ | |\n | | |controls | | |\n | | | ___________________________________ | | |\n | | | |buttonContainer | | | |\n | | | | _______________________________ | | | |\n | | | | |button_accept | button_cancel| | | | |\n | | | |_|_____________ |______________|_| | | |\n | | |___________________________________________________________________________| | |\n | |_______________________________________________________________________________| |\n |___________________________________________________________________________________| */\n\n this.titleBar.appendChild(this.closeDiv);\n this.titleBar.appendChild(this.stackDiv);\n this.titleBar.appendChild(this.maximizeDiv);\n this.titleBar.appendChild(this.minimizeDiv);\n this.titleBar.appendChild(this.title);\n\n if (this.deviceProperties.isDesktop) {\n this.container.appendChild(this.titleBar);\n }\n\n this.wrapper.appendChild(this.contentContainer);\n this.wrapper.appendChild(this.controls);\n\n this.controls.appendChild(this.buttonContainer);\n\n this.buttonContainer.appendChild(this.submitButton);\n this.buttonContainer.appendChild(this.cancelButton);\n\n this.container.appendChild(this.wrapper);\n\n // Check if browser has scrollBar before modal has modified.\n this.recalculateScrollBar();\n\n document.body.appendChild(this.container);\n document.body.appendChild(this.overlay);\n\n if (this.deviceProperties.isDesktop) {\n // Desktop.\n this.createModalWindowDesktop();\n this.createResizeButtons();\n\n this.addListeners();\n // Maximize window only when the configuration is set and the device is not iOS or Android.\n if (Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n } else if (this.deviceProperties.isAndroid) {\n this.createModalWindowAndroid();\n } else if (this.deviceProperties.isIOS) {\n this.createModalWindowIos();\n }\n\n if (this.contentManager != null) {\n this.contentManager.insert(this);\n }\n\n this.properties.open = true;\n this.properties.created = true;\n\n // Checks language directionality.\n if (this.isRTL()) {\n this.container.style.right = `${window.innerWidth - this.scrollbarWidth - this.container.offsetWidth}px`;\n this.container.className += \" wrs_modal_rtl\";\n }\n }\n\n /**\n * Creates a button in the modal object to resize it.\n */\n createResizeButtons() {\n // This is a definition of Resize Button Bottom-Right.\n this.resizerBR = document.createElement(\"div\");\n this.resizerBR.className = \"wrs_bottom_right_resizer\";\n this.resizerBR.innerHTML = \"◢\";\n // To identifiy the element in automated testing\n this.resizerBR.dataset.testid = \"mtcteditor-resize-button-right\";\n // This is a definition of Resize Button Top-Left.\n this.resizerTL = document.createElement(\"div\");\n this.resizerTL.className = \"wrs_bottom_left_resizer\";\n // To identifiy the element in automated testing\n this.resizerTL.dataset.testid = \"mtcteditor-resize-button-left\";\n // Append resize buttons to modal.\n this.container.appendChild(this.resizerBR);\n this.titleBar.appendChild(this.resizerTL);\n // Add events to resize on click and drag.\n Util.addEvent(this.resizerBR, \"mousedown\", this.activateResizeStateBR.bind(this));\n Util.addEvent(this.resizerTL, \"mousedown\", this.activateResizeStateTL.bind(this));\n }\n\n /**\n * Initialize variables for Bottom-Right resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateBR(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, false);\n }\n\n /**\n * Initialize variables for Top-Left resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateTL(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, true);\n }\n\n /**\n * Common method to initialize variables at resize.\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n initializeResizeProperties(mouseEvent, leftOption) {\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n this.resizeDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Save Initial state of modal to compare on drag and obtain the difference.\n this.initialWidth = parseInt(this.container.style.width, 10);\n this.initialHeight = parseInt(this.container.style.height, 10);\n if (!leftOption) {\n this.initialRight = parseInt(this.container.style.right, 10);\n this.initialBottom = parseInt(this.container.style.bottom, 10);\n } else {\n this.leftScale = true;\n }\n if (!this.initialRight) {\n this.initialRight = 0;\n }\n if (!this.initialBottom) {\n this.initialBottom = 0;\n }\n // Disable mouse events on editor when we start to drag modal.\n document.body.style[\"user-select\"] = \"none\";\n }\n\n /**\n * This method opens the modal window, restoring the previous state, position and metrics,\n * if exists. By default the modal object opens in stack mode.\n */\n open() {\n // Removing close class.\n this.removeClass(\"wrs_closed\");\n // Hiding keyboard for mobile devices.\n const { isIOS } = this.deviceProperties;\n const { isAndroid } = this.deviceProperties;\n const { isMobile } = this.deviceProperties;\n if (isIOS || isAndroid || isMobile) {\n // Restore scale to 1.\n this.restoreWebsiteScale();\n this.lockWebsiteScroll();\n // Due to editor wait we need to wait until editor focus.\n setTimeout(() => {\n this.hideKeyboard();\n }, 400);\n }\n\n // New modal window. He need to create the whole object.\n if (!this.properties.created) {\n this.create();\n } else {\n // Previous state closed. Open method can be called even the previous state is open,\n // for example updating the content of the modal object.\n if (!this.properties.open) {\n this.properties.open = true;\n\n // Restoring the previous open state: if the modal object has been closed\n // re-open it should preserve the state and the metrics.\n if (!this.deviceProperties.isAndroid && !this.deviceProperties.isIOS) {\n this.restoreState();\n }\n }\n\n // Maximize window only when the configuration is set and the device is not iOs or Android.\n if (this.deviceProperties.isDesktop && Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n\n // In iOS we need to recalculate the size of the modal object because\n // iOS keyboard is a float div which can overlay the modal object.\n if (this.deviceProperties.isIOS) {\n this.iosSoftkeyboardOpened = false;\n }\n }\n\n if (!ContentManager.isEditorLoaded()) {\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.displayEditor();\n });\n this.contentManager.addListener(listener);\n } else {\n this.displayEditor();\n }\n }\n\n /**\n * Prepares and displays the editor in the modal.\n *\n * This method is responsible for displaying the MathType editor inside the modal container.\n *\n * For Moodle environments, it applies focus protection to prevent external scripts\n * from hijacking focus away from the editor while it's open. This is particularly\n * important in Moodle which may have its own focus management scripts.\n * @returns {void}\n */\n displayEditor() {\n if (this.contentManager.integrationModel.isMoodle) {\n protect(this.container, this.overlay, this.contentContainer);\n }\n\n // Initialize and open the editor using the contentManager.\n this.contentManager.onOpen(this);\n }\n\n /**\n * Closes the modal.\n * Removes specific CSS classes, saves modal properties, unlocks website scroll,\n * sets the 'open' property to false, and triggers the 'onModalClose' event.\n * If a close trigger is defined, it tracks the telemetry event 'CLOSED_MTCT_EDITOR' with the trigger.\n * @returns {Promise} A promise that resolves when the modal is closed.\n */\n async close(trigger) {\n // Remove focus protection before closing\n unprotect(this.container);\n\n this.removeClass(\"wrs_maximized\");\n this.removeClass(\"wrs_minimized\");\n this.removeClass(\"wrs_stack\");\n this.addClass(\"wrs_closed\");\n this.saveModalProperties();\n this.unlockWebsiteScroll();\n this.properties.open = false;\n\n if (trigger) {\n try {\n await Telemeter.telemeter.track(\"CLOSED_MTCT_EDITOR\", {\n toolbar: this.contentManager.toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking CLOSED_MTCT_EDITOR\", error);\n }\n }\n\n Core.globalListeners.fire(\"onModalClose\", {});\n }\n\n /**\n * Closes modal window and destroys the object.\n */\n destroy() {\n // Remove focus protection before destroying\n unprotect(this.container);\n\n // Close modal window.\n this.close();\n // Remove listeners and destroy the object.\n this.removeListeners();\n this.overlay.remove();\n this.container.remove();\n // Reset properties to allow open again.\n this.properties.created = false;\n }\n\n /**\n * Sets the website scale to one.\n */\n // eslint-disable-next-line class-methods-use-this\n restoreWebsiteScale() {\n let viewportmeta = document.querySelector(\"meta[name=viewport]\");\n // Let the equal symbols in order to search and make meta's final content.\n const contentAttrsToUpdate = [\"initial-scale=\", \"minimum-scale=\", \"maximum-scale=\"];\n const contentAttrsValuesToUpdate = [\"1.0\", \"1.0\", \"1.0\"];\n const setMetaAttrFunc = (viewportelement, contentAttrs) => {\n const contentAttr = viewportelement.getAttribute(\"content\");\n // If it exists, we need to maintain old values and put our values.\n if (contentAttr) {\n const attrArray = contentAttr.split(\",\");\n let finalContentMeta = \"\";\n const oldAttrs = [];\n for (let i = 0; i < attrArray.length; i += 1) {\n let isAttrToUpdate = false;\n let j = 0;\n while (!isAttrToUpdate && j < contentAttrs.length) {\n if (attrArray[i].indexOf(contentAttrs[j])) {\n isAttrToUpdate = true;\n }\n j += 1;\n }\n\n if (!isAttrToUpdate) {\n oldAttrs.push(attrArray[i]);\n }\n }\n\n for (let i = 0; i < contentAttrs.length; i += 1) {\n const attr = contentAttrs[i] + contentAttrsValuesToUpdate[i];\n finalContentMeta += i === 0 ? attr : `,${attr}`;\n }\n\n for (let i = 0; i < oldAttrs.length; i += 1) {\n finalContentMeta += `,${oldAttrs[i]}`;\n }\n viewportelement.setAttribute(\"content\", finalContentMeta);\n // It needs to set to empty because setAttribute refresh only when attribute is different.\n viewportelement.setAttribute(\"content\", \"\");\n viewportelement.setAttribute(\"content\", contentAttr);\n } else {\n viewportelement.setAttribute(\"content\", \"initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0\");\n viewportelement.removeAttribute(\"content\");\n }\n };\n\n if (!viewportmeta) {\n viewportmeta = document.createElement(\"meta\");\n document.getElementsByTagName(\"head\")[0].appendChild(viewportmeta);\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n viewportmeta.remove();\n } else {\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n }\n }\n\n /**\n * Locks website scroll for mobile devices.\n */\n lockWebsiteScroll() {\n this.websiteBeforeLockParameters = {\n bodyStylePosition: document.body.style.position ? document.body.style.position : \"\",\n bodyStyleOverflow: document.body.style.overflow ? document.body.style.overflow : \"\",\n htmlStyleOverflow: document.documentElement.style.overflow ? document.documentElement.style.overflow : \"\",\n windowScrollX: window.scrollX,\n windowScrollY: window.scrollY,\n };\n }\n\n /**\n * Unlocks website scroll for mobile devices.\n */\n unlockWebsiteScroll() {\n if (this.websiteBeforeLockParameters) {\n document.body.style.position = this.websiteBeforeLockParameters.bodyStylePosition;\n document.body.style.overflow = this.websiteBeforeLockParameters.bodyStyleOverflow;\n document.documentElement.style.overflow = this.websiteBeforeLockParameters.htmlStyleOverflow;\n const { windowScrollX } = this.websiteBeforeLockParameters;\n const { windowScrollY } = this.websiteBeforeLockParameters;\n window.scrollTo(windowScrollX, windowScrollY);\n this.websiteBeforeLockParameters = null;\n }\n }\n\n /**\n * Util function to known if browser is IE11.\n * @returns {Boolean} true if the browser is IE11. false otherwise.\n */\n // eslint-disable-next-line class-methods-use-this\n isIE11() {\n if (\n navigator.userAgent.search(\"Msie/\") >= 0 ||\n navigator.userAgent.search(\"Trident/\") >= 0 ||\n navigator.userAgent.search(\"Edge/\") >= 0\n ) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns if the current language type is RTL.\n * @return {Boolean} true if current language is RTL. false otherwise.\n */\n isRTL() {\n if (this.attributes.language === \"ar\" || this.attributes.language === \"he\") {\n return true;\n }\n return this.rtl;\n }\n\n /**\n * Adds a class to all modal ModalDialog DOM elements.\n * @param {String} className - Class name.\n */\n addClass(className) {\n Util.addClass(this.overlay, className);\n Util.addClass(this.titleBar, className);\n Util.addClass(this.overlay, className);\n Util.addClass(this.container, className);\n Util.addClass(this.contentContainer, className);\n Util.addClass(this.stackDiv, className);\n Util.addClass(this.minimizeDiv, className);\n Util.addClass(this.maximizeDiv, className);\n Util.addClass(this.wrapper, className);\n }\n\n /**\n * Remove a class from all modal DOM elements.\n * @param {String} className - Class name.\n */\n removeClass(className) {\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.titleBar, className);\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.container, className);\n Util.removeClass(this.contentContainer, className);\n Util.removeClass(this.stackDiv, className);\n Util.removeClass(this.minimizeDiv, className);\n Util.removeClass(this.maximizeDiv, className);\n Util.removeClass(this.wrapper, className);\n }\n\n /**\n * Create modal dialog for desktop.\n */\n createModalWindowDesktop() {\n this.addClass(\"wrs_modal_desktop\");\n this.stack();\n }\n\n /**\n * Create modal dialog for non android devices.\n */\n createModalWindowAndroid() {\n this.addClass(\"wrs_modal_android\");\n window.addEventListener(\"resize\", this.orientationChangeAndroidSoftkeyboard.bind(this));\n }\n\n /**\n * Create modal dialog for iOS devices.\n */\n createModalWindowIos() {\n this.addClass(\"wrs_modal_ios\");\n // Refresh the size when the orientation is changed.\n window.addEventListener(\"resize\", this.orientationChangeIosSoftkeyboard.bind(this));\n }\n\n /**\n * Restore previous state, position and size of previous stacked modal dialog.\n */\n restoreState() {\n if (this.properties.state === \"maximized\") {\n // Reset states for prevent return to stack state.\n this.maximize();\n } else if (this.properties.state === \"minimized\") {\n // Reset states for prevent return to stack state.\n this.properties.state = this.properties.previousState;\n this.properties.previousState = \"\";\n this.minimize();\n } else {\n this.stack();\n }\n }\n\n /**\n * Stacks the modal object.\n */\n stack() {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"stack\";\n this.removeClass(\"wrs_maximized\");\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n this.addClass(\"wrs_stack\");\n\n // Change maximize/minimize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyle));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyle));\n\n this.restoreModalProperties();\n\n if (typeof this.resizerBR !== \"undefined\" && typeof this.resizerTL !== \"undefined\") {\n this.setResizeButtonsVisibility();\n }\n\n // Need recalculate position of actual modal because window can was changed in fullscreenmode.\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n this.focus();\n }\n\n /**\n * Minimizes the modal object.\n */\n minimize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n this.title.style.cursor = \"pointer\";\n if (this.properties.state === \"minimized\" && this.properties.previousState === \"stack\") {\n this.stack();\n } else if (this.properties.state === \"minimized\" && this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n // Setting css to prevent important tag into css style.\n this.container.style.height = \"30px\";\n this.container.style.width = \"250px\";\n this.container.style.bottom = \"0px\";\n this.container.style.right = \"10px\";\n\n this.removeListeners();\n this.properties.previousState = this.properties.state;\n this.properties.state = \"minimized\";\n this.setResizeButtonsVisibility();\n this.minimizeDiv.title = StringManager.get(\"maximize\");\n\n if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.removeClass(\"wrs_stack\");\n } else {\n this.removeClass(\"wrs_maximized\");\n }\n this.addClass(\"wrs_minimized\");\n\n // Change minimize icon to maximize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyle));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyle));\n }\n }\n\n /**\n * Maximizes the modal object.\n */\n maximize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n if (this.properties.state !== \"maximized\") {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"maximized\";\n }\n // Don't permit resize on maximize mode.\n this.setResizeButtonsVisibility();\n\n if (Util.containsClass(this.overlay, \"wrs_minimized\")) {\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n } else if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.container.style.left = null;\n this.container.style.top = null;\n this.removeClass(\"wrs_stack\");\n }\n\n this.addClass(\"wrs_maximized\");\n\n // Change maximize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyle));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyle));\n\n // Set size to 80% screen with a max size.\n this.setSize(parseInt(window.innerHeight * 0.8, 10), parseInt(window.innerWidth * 0.8, 10));\n if (this.container.clientHeight > 700) {\n this.container.style.height = \"700px\";\n }\n if (this.container.clientWidth > 1200) {\n this.container.style.width = \"1200px\";\n }\n\n // Setting modal position in center on screen.\n const { innerHeight } = window;\n const { innerWidth } = window;\n const { offsetHeight } = this.container;\n const { offsetWidth } = this.container;\n const bottom = innerHeight / 2 - offsetHeight / 2;\n const right = innerWidth / 2 - offsetWidth / 2;\n\n this.setPosition(bottom, right);\n this.recalculateScale();\n this.recalculatePosition();\n this.recalculateSize();\n this.focus();\n }\n\n /**\n * Expand again the modal object from a minimized state.\n */\n reExpand() {\n if (this.properties.state === \"minimized\") {\n if (this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n this.stack();\n }\n this.title.style.cursor = \"\";\n }\n }\n\n /**\n * Sets modal size.\n * @param {Number} height - Height of the ModalDialog\n * @param {Number} width - Width of the ModalDialog.\n */\n setSize(height, width) {\n this.container.style.height = `${height}px`;\n this.container.style.width = `${width}px`;\n this.recalculateSize();\n }\n\n /**\n * Sets modal position using bottom and right style attributes.\n * @param {number} bottom - bottom attribute.\n * @param {number} right - right attribute.\n */\n setPosition(bottom, right) {\n this.container.style.bottom = `${bottom}px`;\n this.container.style.right = `${right}px`;\n }\n\n /**\n * Saves position and size parameters of and open ModalDialog. This attributes\n * are needed to restore it on re-open.\n */\n saveModalProperties() {\n // Saving values of modal only when modal is in stack state.\n if (this.properties.state === \"stack\") {\n this.properties.position.bottom = parseInt(this.container.style.bottom, 10);\n this.properties.position.right = parseInt(this.container.style.right, 10);\n this.properties.size.width = parseInt(this.container.style.width, 10);\n this.properties.size.height = parseInt(this.container.style.height, 10);\n }\n }\n\n /**\n * Restore ModalDialog position and size parameters.\n */\n restoreModalProperties() {\n if (this.properties.state === \"stack\") {\n // Restoring Bottom and Right values from last modal.\n this.setPosition(this.properties.position.bottom, this.properties.position.right);\n // Restoring Height and Left values from last modal.\n this.setSize(this.properties.size.height, this.properties.size.width);\n }\n }\n\n /**\n * Sets the modal dialog initial size.\n */\n recalculateSize() {\n this.contentContainer.style.height = `${parseInt(this.wrapper.offsetHeight - 50, 10)}px`;\n }\n\n /**\n * Enable or disable visibility of resize buttons in modal window depend on state.\n */\n setResizeButtonsVisibility() {\n if (this.properties.state === \"stack\") {\n this.resizerTL.style.visibility = \"visible\";\n this.resizerBR.style.visibility = \"visible\";\n } else {\n this.resizerTL.style.visibility = \"hidden\";\n this.resizerBR.style.visibility = \"hidden\";\n }\n }\n\n /**\n * Makes an object draggable adding mouse and touch events.\n */\n addListeners() {\n // Button events (maximize, minimize, stack and close).\n this.maximizeDiv.addEventListener(\"click\", this.maximize.bind(this), true);\n this.stackDiv.addEventListener(\"click\", this.stack.bind(this), true);\n this.minimizeDiv.addEventListener(\"click\", this.minimize.bind(this), true);\n this.closeDiv.addEventListener(\"click\", this.cancelAction.bind(this));\n this.maximizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n }\n },\n true,\n );\n this.stackDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.minimizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.closeDiv.addEventListener(\"keypress\", (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n });\n this.title.addEventListener(\"click\", this.reExpand.bind(this));\n\n // Overlay events (close).\n this.overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n // Mouse events.\n Util.addEvent(window, \"mousedown\", this.startDrag.bind(this));\n Util.addEvent(window, \"mouseup\", this.stopDrag.bind(this));\n Util.addEvent(window, \"mousemove\", this.drag.bind(this));\n Util.addEvent(window, \"resize\", this.onWindowResize.bind(this));\n // Key events.\n Util.addEvent(window, \"keydown\", this.onKeyDown.bind(this));\n }\n\n /**\n * Removes draggable events from an object.\n */\n removeListeners() {\n // Mouse events.\n Util.removeEvent(window, \"mousedown\", this.startDrag);\n Util.removeEvent(window, \"mouseup\", this.stopDrag);\n Util.removeEvent(window, \"mousemove\", this.drag);\n Util.removeEvent(window, \"resize\", this.onWindowResize);\n // Key events.\n Util.removeEvent(window, \"keydown\", this.onKeyDown);\n }\n\n /**\n * Returns mouse or touch coordinates (on touch events ev.ClientX doesn't exists)\n * @param {MouseEvent} mouseEvent - Mouse event.\n * @return {Object} With the X and Y coordinates.\n */\n // eslint-disable-next-line class-methods-use-this\n eventClient(mouseEvent) {\n if (typeof mouseEvent.clientX === \"undefined\" && mouseEvent.changedTouches) {\n const client = {\n X: mouseEvent.changedTouches[0].clientX,\n Y: mouseEvent.changedTouches[0].clientY,\n };\n return client;\n }\n const client = {\n X: mouseEvent.clientX,\n Y: mouseEvent.clientY,\n };\n return client;\n }\n\n /**\n * Start drag function: set the object dragDataObject with the draggable\n * object offsets coordinates.\n * when drag starts (on touchstart or mousedown events).\n * @param {MouseEvent} mouseEvent - Touchstart or mousedown event.\n */\n startDrag(mouseEvent) {\n if (this.properties.state === \"minimized\") {\n return;\n }\n if (mouseEvent.target === this.title) {\n if (typeof this.dragDataObject === \"undefined\" || this.dragDataObject === null) {\n // Save first click mouse point on screen.\n this.dragDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Reset last drag position when start drag.\n this.lastDrag = {\n x: \"0px\",\n y: \"0px\",\n };\n // Init right and bottom values for window modal if it isn't exist.\n if (this.container.style.right === \"\") {\n this.container.style.right = \"0px\";\n }\n if (this.container.style.bottom === \"\") {\n this.container.style.bottom = \"0px\";\n }\n\n // Needed for IE11 for apply disabled mouse events on editor because\n // internet explorer needs a dynamic object to apply this property.\n if (this.isIE11()) {\n // this.iframe.style['position'] = 'relative';\n }\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n // Obtain screen limits for prevent overflow.\n this.limitWindow = this.getLimitWindow();\n }\n }\n }\n\n /**\n * Updates dragDataObject with the draggable object coordinates when\n * the draggable object is being moved.\n * @param {MouseEvent} mouseEvent - The mouse event.\n */\n drag(mouseEvent) {\n if (this.dragDataObject) {\n mouseEvent.preventDefault();\n // Calculate max and min between actual mouse position and limit of screeen.\n // It restric the movement of modal into window.\n let limitY = Math.min(this.eventClient(mouseEvent).Y, this.limitWindow.minPointer.y);\n limitY = Math.max(this.limitWindow.maxPointer.y, limitY);\n let limitX = Math.min(this.eventClient(mouseEvent).X, this.limitWindow.minPointer.x);\n limitX = Math.max(this.limitWindow.maxPointer.x, limitX);\n // Subtract limit with first position to obtain relative pixels increment\n // to the anchor point.\n const dragX = `${limitX - this.dragDataObject.x}px`;\n const dragY = `${limitY - this.dragDataObject.y}px`;\n // Save last valid position of modal before window overflow.\n this.lastDrag = {\n x: dragX,\n y: dragY,\n };\n // This move modal with hardware acceleration.\n this.container.style.transform = `translate3d(${dragX},${dragY},0)`;\n }\n if (this.resizeDataObject) {\n const { innerWidth } = window;\n const { innerHeight } = window;\n let limitX = Math.min(this.eventClient(mouseEvent).X, innerWidth - this.scrollbarWidth - 7);\n let limitY = Math.min(this.eventClient(mouseEvent).Y, innerHeight - 7);\n if (limitX < 0) {\n limitX = 0;\n }\n\n if (limitY < 0) {\n limitY = 0;\n }\n\n let scaleMultiplier;\n if (this.leftScale) {\n scaleMultiplier = -1;\n } else {\n scaleMultiplier = 1;\n }\n\n this.container.style.width = `${this.initialWidth + scaleMultiplier * (limitX - this.resizeDataObject.x)}px`;\n this.container.style.height = `${this.initialHeight + scaleMultiplier * (limitY - this.resizeDataObject.y)}px`;\n if (!this.leftScale) {\n if (this.resizeDataObject.x - limitX - this.initialWidth < -580) {\n this.container.style.right = `${this.initialRight - (limitX - this.resizeDataObject.x)}px`;\n } else {\n this.container.style.right = `${this.initialRight + this.initialWidth - 580}px`;\n this.container.style.width = \"580px\";\n }\n if (this.resizeDataObject.y - limitY < this.initialHeight - 338) {\n this.container.style.bottom = `${this.initialBottom - (limitY - this.resizeDataObject.y)}px`;\n } else {\n this.container.style.bottom = `${this.initialBottom + this.initialHeight - 338}px`;\n this.container.style.height = \"338px\";\n }\n }\n this.recalculateScale();\n this.recalculatePosition();\n }\n }\n\n /**\n * Returns the boundaries of actual window to limit modal movement.\n * @return {Object} Object containing mouseX and mouseY coordinates of actual mouse on screen.\n */\n getLimitWindow() {\n // Obtain dimensions of window page.\n const maxWidth = window.innerWidth;\n const maxHeight = window.innerHeight;\n\n // Calculate relative position of mouse point into window.\n const { offsetHeight } = this.container;\n const contStyleBottom = parseInt(this.container.style.bottom, 10);\n const contStyleRight = parseInt(this.container.style.right, 10);\n\n const { pageXOffset } = window;\n const dragY = this.dragDataObject.y;\n const dragX = this.dragDataObject.x;\n\n const offSetToolbarY = offsetHeight + contStyleBottom - (maxHeight - (dragY - pageXOffset));\n const offSetToolbarX = maxWidth - this.scrollbarWidth - (dragX - pageXOffset) - contStyleRight;\n\n // Calculate limits with sizes of window, modal and mouse position.\n const minPointerY = maxHeight - this.container.offsetHeight + offSetToolbarY;\n const maxPointerY = this.title.offsetHeight - (this.title.offsetHeight - offSetToolbarY);\n const minPointerX = maxWidth - offSetToolbarX - this.scrollbarWidth;\n const maxPointerX = this.container.offsetWidth - offSetToolbarX;\n const minPointer = { x: minPointerX, y: minPointerY };\n const maxPointer = { x: maxPointerX, y: maxPointerY };\n return { minPointer, maxPointer };\n }\n\n /**\n * Returns the scrollbar width size of browser\n * @returns {Number} The scrollbar width.\n */\n // eslint-disable-next-line class-methods-use-this\n getScrollBarWidth() {\n // Create a paragraph with full width of page.\n const inner = document.createElement(\"p\");\n inner.style.width = \"100%\";\n inner.style.height = \"200px\";\n\n // Create a hidden div to compare sizes.\n const outer = document.createElement(\"div\");\n outer.style.position = \"absolute\";\n outer.style.top = \"0px\";\n outer.style.left = \"0px\";\n outer.style.visibility = \"hidden\";\n outer.style.width = \"200px\";\n outer.style.height = \"150px\";\n outer.style.overflow = \"hidden\";\n outer.appendChild(inner);\n\n document.body.appendChild(outer);\n const widthOuter = inner.offsetWidth;\n\n // Change type overflow of paragraph for measure scrollbar.\n outer.style.overflow = \"scroll\";\n let widthInner = inner.offsetWidth;\n\n // If measure is the same, we compare with internal div.\n if (widthOuter === widthInner) {\n widthInner = outer.clientWidth;\n }\n document.body.removeChild(outer);\n\n return widthOuter - widthInner;\n }\n\n /**\n * Set the dragDataObject to null.\n */\n stopDrag() {\n // Due to we have multiple events that call this function, we need only to execute\n // the next modifiers one time,\n // when the user stops to drag and dragDataObject is not null (the object to drag is attached).\n if (this.dragDataObject || this.resizeDataObject) {\n // If modal doesn't change, it's not necessary to set position with interpolation.\n this.container.style.transform = \"\";\n if (this.dragDataObject) {\n this.container.style.right = `${parseInt(this.container.style.right, 10) - parseInt(this.lastDrag.x, 10)}px`;\n this.container.style.bottom = `${parseInt(this.container.style.bottom, 10) - parseInt(this.lastDrag.y, 10)}px`;\n }\n // We make focus on editor after drag modal windows to prevent lose focus.\n this.focus();\n // Restore mouse events on iframe.\n // this.iframe.style['pointer-events'] = 'auto';\n document.body.style[\"user-select\"] = \"\";\n // Restore static state of iframe if we use Internet Explorer.\n if (this.isIE11()) {\n // this.iframe.style['position'] = null;\n }\n // Active text select event.\n Util.removeClass(document.body, \"wrs_noselect\");\n Util.removeClass(this.overlay, \"wrs_overlay_active\");\n }\n this.dragDataObject = null;\n this.resizeDataObject = null;\n this.initialWidth = null;\n this.leftScale = null;\n }\n\n /**\n * Recalculates scale for modal when resize browser window.\n */\n onWindowResize() {\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n }\n\n /**\n * Triggers keyboard events:\n * - Tab key tab to go to submit button.\n * - Esc key to close the modal dialog.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Popupmessage is not oppened.\n if (this.popup.overlayWrapper.style.display !== \"block\") {\n // Code to detect Esc event\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n if (this.properties.open) {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.cancelButton) {\n this.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.submitButton) {\n this.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n }\n } else {\n // Popupmessage oppened.\n this.popup.onKeyDown(keyboardEvent);\n }\n }\n }\n\n /**\n * Recalculating position for modal dialog when the browser is resized.\n */\n recalculatePosition() {\n this.container.style.right = `${Math.min(parseInt(this.container.style.right, 10), window.innerWidth - this.scrollbarWidth - this.container.offsetWidth)}px`;\n if (parseInt(this.container.style.right, 10) < 0) {\n this.container.style.right = \"0px\";\n }\n this.container.style.bottom = `${Math.min(parseInt(this.container.style.bottom, 10), window.innerHeight - this.container.offsetHeight)}px`;\n if (parseInt(this.container.style.bottom, 10) < 0) {\n this.container.style.bottom = \"0px\";\n }\n }\n\n /**\n * Recalculating scale for modal when the browser is resized.\n */\n recalculateScale() {\n let sizeModified = false;\n\n if (parseInt(this.container.style.width, 10) > 580) {\n this.container.style.width = `${Math.min(parseInt(this.container.style.width, 10), window.innerWidth - this.scrollbarWidth)}px`;\n sizeModified = true;\n } else {\n this.container.style.width = \"580px\";\n sizeModified = true;\n }\n\n if (parseInt(this.container.style.height, 10) > 338) {\n this.container.style.height = `${Math.min(parseInt(this.container.style.height, 10), window.innerHeight)}px`;\n sizeModified = true;\n } else {\n this.container.style.height = \"338px\";\n sizeModified = true;\n }\n\n if (sizeModified) {\n this.recalculateSize();\n }\n }\n\n /**\n * Recalculating width of browser scroll bar.\n */\n recalculateScrollBar() {\n this.hasScrollBar = window.innerWidth > document.documentElement.clientWidth;\n if (this.hasScrollBar) {\n this.scrollbarWidth = this.getScrollBarWidth();\n } else {\n this.scrollbarWidth = 0;\n }\n }\n\n /**\n * Hide soft keyboards on iOS devices.\n */\n // eslint-disable-next-line class-methods-use-this\n hideKeyboard() {\n // iOS keyboard can't be detected or hide directly from JavaScript.\n // So, this method simulates that user focus a text input and blur\n // the selection.\n const inputField = document.createElement(\"input\");\n this.container.appendChild(inputField);\n inputField.focus();\n inputField.blur();\n // Is removed to not see it.\n inputField.remove();\n }\n\n /**\n * Focus to contentManager object.\n */\n focus() {\n if (this.contentManager != null && typeof this.contentManager.onFocus !== \"undefined\") {\n this.contentManager.onFocus();\n }\n }\n\n /**\n * Returns true when the device is on portrait mode.\n */\n // eslint-disable-next-line class-methods-use-this\n portraitMode() {\n return window.innerHeight > window.innerWidth;\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is opened.\n */\n handleOpenedIosSoftkeyboard() {\n if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `auto`) {\n if (this.portraitMode()) {\n this.setContainerHeight(`60${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`35${this.iosMeasureUnit}`);\n }\n }\n this.iosSoftkeyboardOpened = true;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is closed.\n */\n handleClosedIosSoftkeyboard() {\n this.iosSoftkeyboardOpened = false;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Change container sizes when orientation is changed on iOS.\n */\n orientationChangeIosSoftkeyboard() {\n if (this.iosSoftkeyboardOpened) {\n if (this.portraitMode()) {\n this.setContainerHeight(`65${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`45${this.iosMeasureUnit}`);\n }\n } else {\n this.wrapper.style.flexGrow = \"1\";\n }\n }\n\n /**\n * Change container sizes when orientation is changed on Android.\n */\n orientationChangeAndroidSoftkeyboard() {\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Set iframe container height.\n * @param {Number} height - New height.\n */\n setContainerHeight(height) {\n this.iosDivHeight = height;\n this.wrapper.style.height = height;\n }\n\n /**\n * Check content of editor before close action.\n */\n showPopUpMessage() {\n if (this.properties.state === \"minimized\") {\n this.stack();\n }\n this.popup.show();\n }\n\n /**\n * Sets the title of the modal dialog.\n * @param {String} title - Modal dialog title.\n */\n setTitle(title) {\n this.title.innerHTML = title;\n }\n\n /**\n * Returns the id of an element, adding the instance number to\n * the element class name:\n * className --> className[idNumber]\n * @param {String} className - The element class name.\n * @returns {String} A string appending the instance id to the className.\n */\n getElementId(className) {\n return `${className}[${this.instanceId}]`;\n }\n}\n","/* eslint-disable */\nvar polyfills;\nexport default polyfills;\n\n// Polyfills.\n/*! http://mths.be/codepointat v0.1.0 by @mathias */\nif (!String.prototype.codePointAt) {\n (function () {\n \"use strict\"; // needed to support `apply`/`call` with `undefined`/`null`\n var codePointAt = function (position) {\n if (this == null) {\n throw TypeError();\n }\n var string = String(this);\n var size = string.length;\n // `ToInteger`\n var index = position ? Number(position) : 0;\n if (index != index) {\n // better `isNaN`\n index = 0;\n }\n // Account for out-of-bounds indices:\n if (index < 0 || index >= size) {\n return undefined;\n }\n // Get the first code unit\n var first = string.charCodeAt(index);\n var second;\n if (\n // check if it’s the start of a surrogate pair\n first >= 0xd800 &&\n first <= 0xdbff && // high surrogate\n size > index + 1 // there is a next code unit\n ) {\n second = string.charCodeAt(index + 1);\n if (second >= 0xdc00 && second <= 0xdfff) {\n // low surrogate\n // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000;\n }\n }\n return first;\n };\n if (Object.defineProperty) {\n Object.defineProperty(String.prototype, \"codePointAt\", {\n value: codePointAt,\n configurable: true,\n writable: true,\n });\n } else {\n String.prototype.codePointAt = codePointAt;\n }\n })();\n}\n\n// Object.assign polyfill.\nif (typeof Object.assign != \"function\") {\n // Must be writable: true, enumerable: false, configurable: true\n Object.defineProperty(Object, \"assign\", {\n value: function assign(target, varArgs) {\n // .length of function is 2\n \"use strict\";\n if (target == null) {\n // TypeError if undefined or null\n throw new TypeError(\"Cannot convert undefined or null to object\");\n }\n\n var to = Object(target);\n\n for (var index = 1; index < arguments.length; index++) {\n var nextSource = arguments[index];\n\n if (nextSource != null) {\n // Skip over if undefined or null\n for (var nextKey in nextSource) {\n // Avoid bugs when hasOwnProperty is shadowed\n if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {\n to[nextKey] = nextSource[nextKey];\n }\n }\n }\n }\n return to;\n },\n writable: true,\n configurable: true,\n });\n}\n\n// https://tc39.github.io/ecma262/#sec-array.prototype.includes\nif (!Array.prototype.includes) {\n Object.defineProperty(Array.prototype, \"includes\", {\n value: function (searchElement, fromIndex) {\n if (this == null) {\n throw new TypeError('\"this\" s null or is not defined');\n }\n\n // 1. Let O be ? ToObject(this value).\n var o = Object(this);\n\n // 2. Let len be ? ToLength(? Get(O, \"length\")).\n var len = o.length >>> 0;\n\n // 3. if len is 0, return false.\n if (len === 0) {\n return false;\n }\n\n // 4. Let n be ? ToInteger(fromIndex).\n // (if fromIndex is undefinedo, this step generates the value 0.)\n var n = fromIndex | 0;\n\n // 5. if n ≥ 0, then\n // a. Let k be n.\n // 6. Else n < 0,\n // a. Let k be len + n.\n // b. if k < 0, let k be 0.\n var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);\n\n function sameValueZero(x, y) {\n return x === y || (typeof x === \"number\" && typeof y === \"number\" && isNaN(x) && isNaN(y));\n }\n\n // 7. Repeat while k < len\n while (k < len) {\n // a. let element k be the result of ? Get(O, ! ToString(k)).\n // b. if SameValueZero(searchElement, elementK) is true, return true.\n if (sameValueZero(o[k], searchElement)) {\n return true;\n }\n // c. Increase k by 1.\n k++;\n }\n\n // 8. Return false\n return false;\n },\n });\n}\n\nif (!String.prototype.includes) {\n String.prototype.includes = function (search, start) {\n \"use strict\";\n\n if (search instanceof RegExp) {\n throw TypeError(\"first argument must not be a RegExp\");\n }\n if (start === undefined) {\n start = 0;\n }\n return this.indexOf(search, start) !== -1;\n };\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, \"startsWith\", {\n value: function (search, rawPos) {\n var pos = rawPos > 0 ? rawPos | 0 : 0;\n return this.substring(pos, pos + search.length) === search;\n },\n });\n}\n","import Parser from \"./parser\";\nimport Util from \"./util\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport CustomEditors from \"./customeditors\";\nimport Configuration from \"./configuration\";\nimport jsProperties from \"./jsvariables\";\nimport Event from \"./event\";\nimport Listeners from \"./listeners\";\nimport Image from \"./image\";\nimport ServiceProvider from \"./serviceprovider\";\nimport ModalDialog from \"./modal\";\nimport Telemeter from \"./telemeter\";\nimport \"./polyfills\";\nimport \"../styles/styles.css\";\n\n/**\n * @typedef {Object} CoreProperties\n * @property {ServiceProviderProperties} serviceProviderProperties\n * - The ServiceProvider class properties. *\n */\nexport default class Core {\n /**\n * @classdesc\n * This class represents MathType integration Core, managing the following:\n * - Integration initialization.\n * - Event managing.\n * - Insertion of formulas into the edit area.\n * ```js\n * let core = new Core();\n * core.addListener(listener);\n * core.language = 'en';\n *\n * // Initializing Core class.\n * core.init(configurationService);\n * ```\n * @constructs\n * Core constructor.\n * @param {CoreProperties}\n */\n constructor(coreProperties) {\n /**\n * Language. Needed for accessibility and locales. 'en' by default.\n * @type {String}\n */\n this.language = \"en\";\n\n /**\n * Edit mode, 'images' by default. Admits the following values:\n * - images\n * - latex\n * @type {String}\n */\n this.editMode = \"images\";\n\n /**\n * Modal dialog instance.\n * @type {ModalDialog}\n */\n this.modalDialog = null;\n\n /**\n * The instance of {@link CustomEditors}. By default\n * the only custom editor is the Chemistry editor.\n * @type {CustomEditors}\n */\n this.customEditors = new CustomEditors();\n\n /**\n * Chemistry editor.\n * @type {CustomEditor}\n */\n const chemEditorParams = {\n name: \"Chemistry\",\n toolbar: \"chemistry\",\n icon: \"chem.png\",\n confVariable: \"chemEnabled\",\n title: \"ChemType\",\n tooltip: \"Insert a chemistry formula - ChemType\", // TODO: Localize tooltip.\n };\n\n this.customEditors.addEditor(\"chemistry\", chemEditorParams);\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @typedef IntegrationEnvironment\n * @property {String} IntegrationEnvironment.editor - Editor name. For example the HTML editor.\n * @property {String} IntegrationEnvironment.mode - Integration save mode.\n * @property {String} IntegrationEnvironment.version - Integration version.\n *\n */\n\n /**\n * The environment properties object.\n * @type {IntegrationEnvironment}\n */\n this.environment = {};\n\n /**\n * @typedef EditionProperties\n * @property {Boolean} editionProperties.isNewElement - True if the formula is a new one.\n * False otherwise.\n * @property {HTMLImageElement} editionProperties.temporalImage- The image element.\n * Null if the formula is new.\n * @property {Range} editionProperties.latexRange - Tha range that contains the LaTeX formula.\n * @property {Range} editionProperties.range - The range that contains the image element.\n * @property {String} editionProperties.editMode - The edition mode. 'images' by default.\n */\n\n /**\n * The properties of the current edition process.\n * @type {EditionProperties}\n */\n this.editionProperties = {};\n\n this.editionProperties.isNewElement = true;\n this.editionProperties.temporalImage = null;\n this.editionProperties.latexRange = null;\n this.editionProperties.range = null;\n this.editionProperties.editionStartTime = null;\n\n /**\n * The {@link IntegrationModel} instance.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n\n /**\n * The {@link ContentManager} instance.\n * @type {ContentManager}\n */\n this.contentManager = null;\n\n /**\n * The current browser.\n * @type {String}\n */\n this.browser = (() => {\n const ua = navigator.userAgent;\n let browser = \"none\";\n if (ua.search(\"Edge/\") >= 0) {\n browser = \"EDGE\";\n } else if (ua.search(\"Chrome/\") >= 0) {\n browser = \"CHROME\";\n } else if (ua.search(\"Trident/\") >= 0) {\n browser = \"IE\";\n } else if (ua.search(\"Firefox/\") >= 0) {\n browser = \"FIREFOX\";\n } else if (ua.search(\"Safari/\") >= 0) {\n browser = \"SAFARI\";\n }\n return browser;\n })();\n\n /**\n * Plugin listeners.\n * @type {Array.}\n */\n this.listeners = new Listeners();\n\n /**\n * Service provider properties.\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = {};\n if (\"serviceProviderProperties\" in coreProperties) {\n this.serviceProviderProperties = coreProperties.serviceProviderProperties;\n } else {\n throw new Error(\"serviceProviderProperties property missing.\");\n }\n }\n\n /**\n * Static property.\n * Core listeners.\n * @private\n * @type {Listeners}\n */\n static get globalListeners() {\n return Core._globalListeners;\n }\n\n /**\n * Static property setter.\n * Set core listeners.\n * @param {Listeners} value - The property value.\n * @ignore\n */\n static set globalListeners(value) {\n Core._globalListeners = value;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * True when Core.init was called. Otherwise, false.\n * @private\n * @type {Boolean}\n */\n static get initialized() {\n return Core._initialized;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * @param {Boolean} value - True to say that Core.init was called. Otherwise, false.\n * @ignore\n */\n static set initialized(value) {\n Core._initialized = value;\n }\n\n /**\n * Sets the {@link Core.integrationModel} property.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} property.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link Core.environment} property.\n * @param {IntegrationEnvironment} integrationEnvironment -\n * The {@link IntegrationEnvironment} object.\n */\n setEnvironment(integrationEnvironment) {\n if (\"editor\" in integrationEnvironment) {\n this.environment.editor = integrationEnvironment.editor;\n }\n if (\"mode\" in integrationEnvironment) {\n this.environment.mode = integrationEnvironment.mode;\n }\n if (\"version\" in integrationEnvironment) {\n this.environment.version = integrationEnvironment.version;\n }\n }\n\n /**\n * Sets the custom headers added on editor requests if contentManager isn't undefined.\n * @returns {Object} headers - key value headers.\n */\n setHeaders(headers) {\n const headerObject = this?.contentManager?.setCustomHeaders(headers) || headers;\n Configuration.set(\"customHeaders\", headerObject);\n }\n\n /**\n * Returns the current {@link ModalDialog} instance.\n * @returns {ModalDialog} The current {@link ModalDialog} instance.\n */\n getModalDialog() {\n return this.modalDialog;\n }\n\n /**\n * Inits the {@link Core} class, doing the following:\n * - Calls asynchronously configuration service, retrieving the backend configuration in a JSON.\n * - Updates {@link Configuration} class with the previous configuration properties.\n * - Updates the {@link ServiceProvider} class using the configuration service path as reference.\n * - Loads language strings.\n * - Fires onLoad event.\n * @param {Object} serviceParameters - Service parameters.\n */\n init() {\n if (!Core.initialized) {\n const serviceProviderListener = Listeners.newListener(\"onInit\", () => {\n const jsConfiguration = ServiceProvider.getService(\"configurationjs\", \"\", \"get\");\n const jsonConfiguration = JSON.parse(jsConfiguration);\n Configuration.addConfiguration(jsonConfiguration);\n // Adding JavaScript (not backend) configuration variables.\n Configuration.addConfiguration(jsProperties);\n // Fire 'onLoad' event:\n // All integration must listen this event in order to know if the plugin\n // has been properly loaded.\n StringManager.language = this.language;\n this.listeners.fire(\"onLoad\", {});\n });\n\n ServiceProvider.addListener(serviceProviderListener);\n ServiceProvider.init(this.serviceProviderProperties);\n\n Core.initialized = true;\n } else {\n // Case when there are more than two editor instances.\n // After the first editor all the other editors don't need to load any file or service.\n this.listeners.fire(\"onLoad\", {});\n }\n }\n\n /**\n * Adds a {@link Listener} to the current instance of the {@link Core} class.\n * @param {Listener} listener - The listener object.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Adds the global {@link Listener} instance to {@link Core} class.\n * @param {Listener} listener - The event listener to be added.\n * @static\n */\n static addGlobalListener(listener) {\n Core.globalListeners.add(listener);\n }\n\n beforeUpdateFormula(mathml, wirisProperties) {\n /**\n * This event is fired before updating the formula.\n * @type {Object}\n * @property {String} mathml - MathML to be transformed.\n * @property {String} editMode - Edit mode.\n * @property {Object} wirisProperties - Extra attributes for the formula.\n * @property {String} language - Formula language.\n */\n const beforeUpdateEvent = new Event();\n\n beforeUpdateEvent.mathml = mathml;\n\n // Cloning wirisProperties object\n // We don't want wirisProperties object modified.\n beforeUpdateEvent.wirisProperties = {};\n\n if (wirisProperties != null) {\n Object.keys(wirisProperties).forEach((attr) => {\n beforeUpdateEvent.wirisProperties[attr] = wirisProperties[attr];\n });\n }\n\n // Read only.\n beforeUpdateEvent.language = this.language;\n beforeUpdateEvent.editMode = this.editMode;\n\n if (this.listeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n return {\n mathml: beforeUpdateEvent.mathml,\n wirisProperties: beforeUpdateEvent.wirisProperties,\n };\n }\n\n /**\n * Converts a MathML into it's correspondent image and inserts the image is\n * inserted in a HTMLElement target by creating\n * a new image or updating an existing one.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the insertion.\n * @param {Window} windowTarget - The window element where the editable content is.\n * @param {String} mathml - The MathML.\n * @param {Array.} wirisProperties - The extra attributes for the formula.\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n /**\n * It is the object with the information of the node or latex to insert.\n * @typedef ReturnObject\n * @property {Node} [node] - The DOM node to insert.\n * @property {String} [latex] - The latex to insert.\n */\n const returnObject = {};\n\n if (!mathml) {\n this.insertElementOnSelection(null, focusElement, windowTarget);\n } else if (this.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n // this.integrationModel.getNonLatexNode is an integration wrapper\n // to have special behaviours for nonLatex.\n // Not all the integrations have special behaviours for nonLatex.\n if (!!this.integrationModel.fillNonLatexNode && !returnObject.latex) {\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.latex = returnObject.latex;\n this.integrationModel.fillNonLatexNode(afterUpdateEvent, windowTarget, mathml);\n } else {\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n }\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n } else {\n returnObject.node = Parser.mathmlToImgObject(windowTarget.document, mathml, wirisProperties, this.language);\n\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n }\n\n return returnObject;\n }\n\n afterUpdateFormula(focusElement, windowTarget, node, latex) {\n /**\n * This event is fired after update the formula.\n * @type {Event}\n * @param {String} editMode - edit mode.\n * @param {Object} windowTarget - target window.\n * @param {Object} focusElement - target element to be focused after update.\n * @param {String} latex - LaTeX generated by the formula (editMode=latex).\n * @param {Object} node - node generated after update the formula (text if LaTeX img otherwise).\n */\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.node = node;\n afterUpdateEvent.latex = latex;\n\n if (this.listeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n return {};\n }\n\n /**\n * Sets the caret after a given Node and set the focus to the owner document.\n * @param {Node} node - The Node element.\n */\n placeCaretAfterNode(node) {\n if (node === null) return;\n\n this.integrationModel.getSelection();\n const nodeDocument = node.ownerDocument;\n if (typeof nodeDocument.getSelection !== \"undefined\" && !!node.parentElement) {\n const range = nodeDocument.createRange();\n range.setStartAfter(node);\n range.collapse(true);\n const selection = nodeDocument.getSelection();\n selection.removeAllRanges();\n selection.addRange(range);\n nodeDocument.body.focus();\n }\n }\n\n /**\n * Replaces a Selection object with an HTMLElement.\n * @param {HTMLElement} element - The HTMLElement to replace the selection.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the replace.\n * @param {Window} windowTarget - The window target.\n */\n insertElementOnSelection(element, focusElement, windowTarget) {\n let mathmlOrigin = null;\n if (this.editionProperties.isNewElement) {\n if (element) {\n if (focusElement.type === \"textarea\") {\n Util.updateTextArea(focusElement, element.textContent);\n } else if (document.selection && document.getSelection === 0) {\n let range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n\n if (!(\"parentElement\" in range)) {\n windowTarget.document.execCommand(\"delete\", false);\n range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n }\n\n if (\"parentElement\" in range) {\n const temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() === \"IMG\") {\n temporalObject.parentNode.replaceChild(element, temporalObject);\n } else {\n // IE9 fix: parentNode() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML(Util.createObjectCode(element));\n }\n }\n } else {\n let range = null;\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n if (this.editionProperties.range) {\n ({ range } = this.editionProperties);\n this.editionProperties.range = null;\n } else {\n const editorSelection = this.integrationModel.getSelection();\n range = editorSelection.getRangeAt(0);\n }\n\n // Delete if something was surrounded.\n range.deleteContents();\n\n let node = range.startContainer;\n const position = range.startOffset;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n node = node.splitText(position);\n node.parentNode.insertBefore(element, node);\n } else if (node.nodeType === 1) {\n // ELEMENT_NODE.\n node.insertBefore(element, node.childNodes[position]);\n }\n\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n focusElement.focus();\n } else {\n const editorSelection = this.integrationModel.getSelection();\n editorSelection.removeAllRanges();\n\n if (this.editionProperties.range) {\n const { range } = this.editionProperties;\n this.editionProperties.range = null;\n editorSelection.addRange(range);\n }\n }\n } else if (this.editionProperties.latexRange) {\n if (document.selection && document.getSelection === 0) {\n this.editionProperties.isNewElement = true;\n this.editionProperties.latexRange.select();\n this.insertElementOnSelection(element, focusElement, windowTarget);\n } else {\n this.editionProperties.latexRange.deleteContents();\n this.editionProperties.latexRange.insertNode(element);\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n let item;\n // Wrapper for some integrations that can have special behaviours to show latex.\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n item = this.integrationModel.getSelectedItem(focusElement, false);\n } else {\n item = Util.getSelectedItemOnTextarea(focusElement);\n }\n Util.updateExistingTextOnTextarea(focusElement, element.textContent, item.startPosition, item.endPosition);\n } else {\n mathmlOrigin = this.editionProperties.temporalImage?.dataset.mathml;\n if (element && element.nodeName.toLowerCase() === \"img\") {\n // Editor empty, formula has been erased on edit.\n // There are editors (e.g: CKEditor) that put attributes in images.\n // We don't allow that behaviour in our images.\n Image.removeImgDataAttributes(this.editionProperties.temporalImage);\n // Clone is needed to maintain event references to temporalImage.\n Image.clone(element, this.editionProperties.temporalImage);\n } else {\n this.editionProperties.temporalImage.remove();\n }\n this.placeCaretAfterNode(this.editionProperties.temporalImage);\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const mathml = element?.dataset?.mathml;\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove the desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n }\n\n /**\n * Opens a modal dialog containing MathType editor..\n * @param {HTMLElement} target - The target HTMLElement where formulas should be inserted.\n * @param {Boolean} isIframe - True if the target HTMLElement is an iframe. False otherwise.\n */\n openModalDialog(target, isIframe) {\n // Count the time since the editor is open\n this.editionProperties.editionStartTime = Date.now();\n\n // Textarea elements don't have normal document ranges. It only accepts latex edit.\n this.editMode = \"images\";\n\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n try {\n if (isIframe) {\n // Is needed focus the target first.\n target.contentWindow.focus();\n const selection = target.contentWindow.getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n } else {\n // Is needed focus the target first.\n target.focus();\n const selection = getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n }\n } catch (e) {\n this.editionProperties.range = null;\n }\n\n if (isIframe === undefined) {\n isIframe = true;\n }\n\n this.editionProperties.latexRange = null;\n\n if (target) {\n let selectedItem;\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n selectedItem = this.integrationModel.getSelectedItem(target, isIframe);\n } else {\n selectedItem = Util.getSelectedItem(target, isIframe);\n }\n\n // Check LaTeX if and only if the node is a text node (nodeType==3).\n if (selectedItem) {\n // Case when image was selected and button pressed.\n if (!selectedItem.caretPosition && Util.containsClass(selectedItem.node, Configuration.get(\"imageClassName\"))) {\n this.editionProperties.temporalImage = selectedItem.node;\n this.editionProperties.isNewElement = false;\n } else if (selectedItem.node.nodeType === 3) {\n // If it's a text node means that editor is working with LaTeX.\n if (this.integrationModel.getMathmlFromTextNode) {\n // If integration has this function it isn't set range due to we don't\n // know if it will be put into a textarea as a text or image.\n const mathml = this.integrationModel.getMathmlFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (mathml) {\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n }\n } else {\n const latexResult = Latex.getLatexFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (latexResult) {\n const mathml = Latex.getMathMLFromLatex(latexResult.latex);\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n const windowTarget = isIframe ? target.contentWindow : window;\n\n if (target.tagName.toLowerCase() !== \"textarea\") {\n if (document.selection) {\n let leftOffset = 0;\n let previousNode = latexResult.startNode.previousSibling;\n\n while (previousNode) {\n leftOffset += Util.getNodeLength(previousNode);\n previousNode = previousNode.previousSibling;\n }\n\n this.editionProperties.latexRange = windowTarget.document.selection.createRange();\n this.editionProperties.latexRange.moveToElementText(latexResult.startNode.parentNode);\n this.editionProperties.latexRange.move(\"character\", leftOffset + latexResult.startPosition);\n this.editionProperties.latexRange.moveEnd(\"character\", latexResult.latex.length + 4); // Plus 4 for the '$$' characters.\n } else {\n this.editionProperties.latexRange = windowTarget.document.createRange();\n this.editionProperties.latexRange.setStart(latexResult.startNode, latexResult.startPosition);\n this.editionProperties.latexRange.setEnd(latexResult.endNode, latexResult.endPosition);\n }\n }\n }\n }\n }\n } else if (target.tagName.toLowerCase() === \"textarea\") {\n // By default editMode is 'images', but when target is a textarea it needs to be 'latex'.\n this.editMode = \"latex\";\n }\n }\n\n // Setting an object with the editor parameters.\n // Editor parameters can be customized in several ways:\n // 1 - editorAttributes: Contains the default editor attributes,\n // usually the metrics in a comma separated string. Always exists.\n // 2 - editorParameters: Object containing custom editor parameters.\n // These parameters are defined in the backend. So they affects all integration instances.\n\n // The backend send the default editor attributes in a coma separated\n // with the following structure: key1=value1,key2=value2...\n const defaultEditorAttributesArray = Configuration.get(\"editorAttributes\").split(\", \");\n const defaultEditorAttributes = {};\n for (let i = 0, len = defaultEditorAttributesArray.length; i < len; i += 1) {\n const tempAttribute = defaultEditorAttributesArray[i].split(\"=\");\n const key = tempAttribute[0];\n const value = tempAttribute[1];\n defaultEditorAttributes[key] = value;\n }\n // Custom editor parameters.\n const editorAttributes = {\n language: this.language, // Default language value\n };\n // Editor parameters in backend, usually configuration.ini.\n const serverEditorParameters = Configuration.get(\"editorParameters\");\n // Editor parameters through JavaScript configuration.\n const clientEditorParameters = this.integrationModel.editorParameters;\n Object.assign(editorAttributes, defaultEditorAttributes, serverEditorParameters);\n Object.assign(editorAttributes, defaultEditorAttributes, clientEditorParameters);\n\n // Now, update backwards: if user has set a custom language, pass that back to core properties\n this.language = editorAttributes.language;\n StringManager.language = this.language;\n\n editorAttributes.rtl = this.integrationModel.rtl;\n\n const customHeaders = Configuration.get(\"customHeaders\");\n // This is not being used in the code, we are keeping it just in case it's needed.\n // We check if it is a string since we have a setter that will make the customHeaders an object. And we do the conversion for the case when we get the headers from the backend.\n editorAttributes.customHeaders =\n typeof customHeaders === \"string\" ? Util.convertStringToObject(customHeaders) : customHeaders;\n\n const contentManagerAttributes = {};\n contentManagerAttributes.editorAttributes = editorAttributes;\n contentManagerAttributes.language = this.language;\n contentManagerAttributes.customEditors = this.customEditors;\n contentManagerAttributes.environment = this.environment;\n\n if (this.modalDialog == null) {\n this.modalDialog = new ModalDialog(editorAttributes);\n this.contentManager = new ContentManager(contentManagerAttributes);\n // When an instance of ContentManager is created we need to wait until\n // the ContentManager is ready by listening 'onLoad' event.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n });\n this.contentManager.addListener(listener);\n this.contentManager.init();\n this.modalDialog.setContentManager(this.contentManager);\n this.contentManager.setModalDialogInstance(this.modalDialog);\n } else {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n }\n this.contentManager.setIntegrationModel(this.integrationModel);\n this.modalDialog.open();\n }\n\n /**\n * Returns the {@link CustomEditors} instance.\n * @return {CustomEditors} The current {@link CustomEditors} instance.\n */\n getCustomEditors() {\n return this.customEditors;\n }\n}\n\n/**\n * Core static listeners.\n * @type {Listeners}\n * @private\n */\nCore._globalListeners = new Listeners();\n\n/**\n * Resources state. Says if they were loaded or not.\n * @type {Boolean}\n * @private\n */\nCore._initialized = false;\n","// eslint-disable-next-line no-unused-vars, import/named\nimport Core from \"./core.src\";\nimport Image from \"./image\";\nimport Listeners from \"./listeners\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Telemeter from \"./telemeter\";\nimport warnIcon from \"../styles/icons/general/warn_icon.svg\"; //eslint-disable-line\n\n/**\n * @typedef {Object} IntegrationModelProperties\n * @property {string} configurationService - Configuration service path.\n * This parameter is needed to determine all services paths.\n * @property {HTMLElement} integrationModelProperties.target - HTML target.\n * @property {string} integrationModelProperties.scriptName - Integration script name.\n * Usually the name of the integration script.\n * @property {Object} integrationModelProperties.environment - integration environment properties.\n * @property {Object} [integrationModelProperties.callbackMethodArguments] - object containing\n * callback method arguments.\n * @property {string} [integrationModelProperties.version] - integration version number.\n * @property {Object} [integrationModelProperties.editorObject] - object containing\n * the integration editor instance.\n * @property {boolean} [integrationModelProperties.rtl] - true if the editor is in RTL mode.\n * false otherwise.\n * @property {ServiceProviderProperties} [integrationModelProperties.serviceProviderProperties]\n * - The service parameters.\n * @property {Object} [integrationModelProperties.integrationParameters]\n * - Overwritten integration parameters.\n */\n\nexport default class IntegrationModel {\n /**\n * @classdesc\n * This class represents an integration model, allowing the integration script to\n * communicate with Core class. Each integration must extend this class.\n * @constructs\n * @param {IntegrationModelProperties} integrationModelProperties\n */\n constructor(integrationModelProperties) {\n /**\n * Language. Needed for accessibility and locales. English by default.\n */\n this.language = \"en\";\n\n /**\n * Service parameters\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = integrationModelProperties.serviceProviderProperties ?? {};\n\n /**\n * Configuration service path. The integration service is needed by Core class to\n * load all the backend configuration into the frontend and also to create the paths\n * of all services (all services lives in the same route). Mandatory property.\n */\n this.configurationService = \"\";\n if (\"configurationService\" in integrationModelProperties) {\n this.serviceProviderProperties.URI = integrationModelProperties.configurationService;\n console.warn(\"Deprecated property configurationService. Use serviceParameters on instead.\", [\n integrationModelProperties.configurationService,\n ]);\n }\n\n /**\n * Plugin version. Needed to stats and caching.\n * @type {string}\n */\n this.version = \"version\" in integrationModelProperties ? integrationModelProperties.version : \"\";\n\n /**\n * DOM target in which the plugin works. Needed to associate events, insert formulas, etc.\n * Mandatory property.\n */\n this.target = null;\n if (\"target\" in integrationModelProperties) {\n this.target = integrationModelProperties.target;\n } else {\n throw new Error(\"IntegrationModel constructor error: target property missed.\");\n }\n\n /**\n * Integration script name. Needed to know the plugin path.\n */\n if (\"scriptName\" in integrationModelProperties) {\n this.scriptName = integrationModelProperties.scriptName;\n }\n\n /**\n * Object containing the arguments needed by the callback function.\n */\n this.callbackMethodArguments = integrationModelProperties.callbackMethodArguments ?? {};\n\n /**\n * Contains information about the integration environment:\n * like the name of the editor, the version, etc.\n */\n this.environment = integrationModelProperties.environment ?? {};\n\n /**\n * Indicates if the DOM target is - or not - and iframe.\n */\n this.isIframe = false;\n if (this.target != null) {\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Instance of the integration editor object. Usually the entry point to access the API\n * of a HTML editor.\n */\n this.editorObject = integrationModelProperties.editorObject ?? null;\n\n /**\n * Specifies if the direction of the text is RTL. false by default.\n */\n this.rtl = integrationModelProperties.rtl ?? false;\n\n /**\n * Specifies if the integration model exposes the locale strings. false by default.\n */\n this.managesLanguage = integrationModelProperties.managesLanguage ?? false;\n\n /**\n * Specify if editor will open in hand mode only\n */\n this.forcedHandMode = integrationModelProperties?.integrationParameters?.forcedHandMode ?? false;\n\n /**\n * Indicates if an image is selected. Needed to resize the image to the original size in case\n * the image is resized.\n * @type {boolean}\n */\n this.temporalImageResizing = false;\n\n /**\n * The Core class instance associated to the integration model.\n * @type {Core}\n */\n this.core = null;\n\n /**\n * Integration model listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n // Parameters overwrite.\n if (\"integrationParameters\" in integrationModelProperties) {\n IntegrationModel.integrationParameters.forEach((parameter) => {\n if (parameter in integrationModelProperties.integrationParameters) {\n // Don't add empty parameters.\n const value = integrationModelProperties.integrationParameters[parameter];\n if (Object.keys(value).length !== 0) {\n this[parameter] = value;\n }\n }\n });\n }\n }\n\n /**\n * Init function. Usually called from the integration side once the core.js file is loaded.\n */\n init() {\n // Check if language is an object and select the property necessary\n this.language = this.getLanguage();\n\n // We need to wait until Core class is loaded ('onLoad' event) before\n // call the callback method.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.callbackFunction(this.callbackMethodArguments);\n });\n\n // Backwards compatibility.\n if (this.serviceProviderProperties.URI.indexOf(\"configuration\") !== -1) {\n const uri = this.serviceProviderProperties.URI;\n const server = ServiceProvider.getServerLanguageFromService(uri);\n this.serviceProviderProperties.server = server;\n const configurationIndex = this.serviceProviderProperties.URI.indexOf(\"configuration\");\n const subsTring = this.serviceProviderProperties.URI.substring(0, configurationIndex);\n this.serviceProviderProperties.URI = subsTring;\n }\n\n let serviceParametersURI = this.serviceProviderProperties.URI;\n serviceParametersURI =\n serviceParametersURI.indexOf(\"/\") === 0 || serviceParametersURI.indexOf(\"http\") === 0\n ? serviceParametersURI\n : Util.concatenateUrl(this.getPath(), serviceParametersURI);\n\n this.serviceProviderProperties.URI = serviceParametersURI;\n\n const coreProperties = {};\n coreProperties.serviceProviderProperties = this.serviceProviderProperties;\n\n this.setCore(new Core(coreProperties));\n this.core.addListener(listener);\n this.core.language = this.language;\n\n // Initializing Core class.\n this.core.init();\n // TODO: Move to Core constructor.\n this.core.setEnvironment(this.environment);\n\n // No internet connection modal.\n let attributes = {};\n attributes.class = attributes.id = \"wrs_modal_offline\";\n this.offlineModal = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_content_offline\";\n this.offlineModalContent = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_close\";\n this.offlineModalClose = Util.createElement(\"span\", attributes);\n this.offlineModalClose.innerHTML = \"×\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_warn\";\n this.offlineModalWarn = Util.createElement(\"span\", attributes);\n const generalStyle = `background-image: url(data:image/svg+xml;base64,${window.btoa(warnIcon)})`;\n this.offlineModalWarn.setAttribute(\"style\", generalStyle);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_container\";\n this.offlineModalMessage = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_warn\";\n this.offlineModalMessage1 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage1.innerHTML = \"You are not online!\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text\";\n this.offlineModalMessage2 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage2.innerHTML = `Thank you for using MathType. We have detected you are disconnected from the network. We remind you that you'll need to be connected to use MathType.

Please refresh the page if this message continues appearing.`;\n\n // Append offline modal elements\n this.offlineModalContent.appendChild(this.offlineModalClose);\n this.offlineModalMessage.appendChild(this.offlineModalMessage1);\n this.offlineModalMessage.appendChild(this.offlineModalMessage2);\n this.offlineModalContent.appendChild(this.offlineModalMessage);\n this.offlineModalContent.appendChild(this.offlineModalWarn);\n this.offlineModal.appendChild(this.offlineModalContent);\n document.body.appendChild(this.offlineModal);\n\n const modal = document.getElementById(\"wrs_modal_offline\");\n this.offlineModalClose.addEventListener(\"click\", () => {\n modal.style.display = \"none\";\n });\n\n // Store editor name for telemetry purposes.\n let editorName = this.environment.editor;\n editorName = editorName.slice(0, -1); // Remove version number from editors\n if (editorName.includes(\"TinyMCE\")) editorName = \"TinyMCE\"; // Remove version from Tinymce editor.\n if (editorName.includes(\"Generic\")) editorName = \"Generic\"; // Remove version from Generic editor.\n let solutionTelemeter = editorName;\n\n // If moodle, add information to hosts and solution.\n const isMoodle = !!(typeof M === \"object\" && M !== null);\n let lms;\n\n if (isMoodle) {\n solutionTelemeter = \"Moodle\";\n lms = {\n nam: \"moodle\",\n fam: \"lms\",\n ver: this.environment.moodleVersion,\n category: this.environment.moodleCourseCategory,\n course: this.environment.moodleCourseName,\n };\n if (!editorName.includes(\"TinyMCE\")) {\n editorName = \"Atto\";\n }\n }\n\n // Get the OS and its version.\n const OSData = this.getOS();\n\n // Get the broswer and its version.\n const broswerData = this.getBrowser();\n\n // Create list of hosts to send to telemetry.\n let hosts = [\n {\n nam: broswerData.detectedBrowser,\n fam: \"browser\",\n ver: broswerData.versionBrowser,\n },\n {\n nam: editorName.toLowerCase(),\n fam: \"html-editor\",\n ver: this.environment.editorVersion,\n },\n {\n nam: OSData.detectedOS,\n fam: \"os\",\n ver: OSData.versionOS,\n },\n {\n nam: window.location.hostname,\n fam: \"domain\",\n },\n lms,\n ];\n\n // Filter hosts to remove empty objects and empty keys.\n hosts = hosts.filter((element) => {\n if (element) Object.keys(element).forEach((key) => (element[key] === \"unknown\" ? delete element[key] : {}));\n return element !== undefined;\n });\n\n // Initialize telemeter\n Telemeter.init({\n solution: {\n name: `MathType for ${solutionTelemeter}`,\n version: this.version,\n },\n hosts,\n config: {\n test: false, // True to use the staging Telemetry endpoint instead of the production one.\n debug: false, // True to show more information about Telemeter's execution and use dev-tools.\n dry_run: false, // True to skip sending data to the Telemetry endpoint (for example for unit tests).\n api_key: \"eda2ce9b-0e8a-46f2-acdd-c228a615314e\", // to auth against Telemetry. Data team is the responsible of providing it.\n },\n url: undefined,\n });\n }\n\n /**\n * Returns the Browser name and its version.\n * @return {array} - detectedBrowser = Operating System name.\n * versionBrowser = Operating System version.\n */\n getBrowser() {\n // default value for OS just in case nothing is detected\n let detectedBrowser = \"unknown\";\n let versionBrowser = \"unknown\";\n\n const userAgent = window.navigator.userAgent;\n\n if (/Brave/.test(userAgent)) {\n detectedBrowser = \"brave\";\n if (userAgent.indexOf(\"Brave/\")) {\n const start = userAgent.indexOf(\"Brave\") + 6;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (userAgent.indexOf(\"Edg/\") !== -1) {\n detectedBrowser = \"edge_chromium\";\n const start = userAgent.indexOf(\"Edg/\") + 4;\n versionBrowser = userAgent\n .substring(start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Edg/.test(userAgent)) {\n detectedBrowser = \"edge\";\n let start = userAgent.indexOf(\"Edg\") + 3;\n start += userAgent.substring(start).indexOf(\"/\");\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Firefox/.test(userAgent) || /FxiOS/.test(userAgent)) {\n detectedBrowser = \"firefox\";\n let start = userAgent.indexOf(\"Firefox\");\n start = start === -1 ? userAgent.indexOf(\"FxiOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/OPR/.test(userAgent)) {\n detectedBrowser = \"opera\";\n const start = userAgent.indexOf(\"OPR/\") + 4;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Chrome/.test(userAgent) || /CriOS/.test(userAgent)) {\n detectedBrowser = \"chrome\";\n let start = userAgent.indexOf(\"Chrome\");\n start = start === -1 ? userAgent.indexOf(\"CriOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/Safari/.test(userAgent)) {\n detectedBrowser = \"safari\";\n let start = userAgent.indexOf(\"Version/\");\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n }\n\n return { detectedBrowser, versionBrowser };\n }\n\n /**\n * Returns the operating system and its version.\n * @return {array} - detectedOS = Operating System name.\n * versionOS = Operating System version.\n */\n getOS() {\n // default value for OS just in case nothing is detected\n let detectedOS = \"unknown\";\n let versionOS = \"unknown\";\n\n // Retrieve properties to easily detect the OS\n const userAgent = window.navigator.userAgent;\n const platform = window.navigator.platform;\n const macosPlatforms = [\"Macintosh\", \"MacIntel\", \"MacPPC\", \"Mac68K\"];\n const windowsPlatforms = [\"Win32\", \"Win64\", \"Windows\", \"WinCE\"];\n const iosPlatforms = [\"iPhone\", \"iPad\", \"iPod\"];\n\n // Find OS and their respective versions\n if (macosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"macos\";\n if (userAgent.indexOf(\"OS X\") !== -1) {\n const start = userAgent.indexOf(\"OS X\") + 5;\n const end = userAgent.substring(start).indexOf(\" \");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (iosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"ios\";\n if (userAgent.indexOf(\"OS \") !== -1) {\n const start = userAgent.indexOf(\"OS \") + 3;\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (windowsPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"windows\";\n const start = userAgent.indexOf(\"Windows\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Android/.test(userAgent)) {\n detectedOS = \"android\";\n const start = userAgent.indexOf(\"Android\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/CrOS/.test(userAgent)) {\n detectedOS = \"chromeos\";\n let start = userAgent.indexOf(\"CrOS \") + 5;\n start += userAgent.substring(start).indexOf(\" \");\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (detectedOS === \"unknown\" && /Linux/.test(platform)) {\n detectedOS = \"linux\";\n }\n\n return { detectedOS, versionOS };\n }\n\n /**\n * Returns the absolute path of the integration script.\n * @return {string} - Absolute path for the integration script.\n */\n getPath() {\n if (typeof this.scriptName === \"undefined\") {\n throw new Error(\"scriptName property needed for getPath.\");\n }\n const col = document.getElementsByTagName(\"script\");\n let path = \"\";\n for (let i = 0; i < col.length; i += 1) {\n const j = col[i].src.lastIndexOf(this.scriptName);\n if (j >= 0) {\n path = col[i].src.substr(0, j - 1);\n }\n }\n return path;\n }\n\n /**\n * Returns integration model plugin version\n * @param {string} - Plugin version\n */\n getVersion() {\n return this.version;\n }\n\n /**\n * Sets the language property.\n * @param {string} language - language code.\n */\n setLanguage(language) {\n this.language = language;\n }\n\n /**\n * Sets a Core instance.\n * @param {Core} core - instance of Core class.\n */\n setCore(core) {\n this.core = core;\n core.setIntegrationModel(this);\n }\n\n /**\n * Returns the Core instance.\n * @returns {Core} instance of Core class.\n */\n getCore() {\n return this.core;\n }\n\n /**\n * Sets the object target and updates the iframe property.\n * @param {HTMLElement} target - target object.\n */\n setTarget(target) {\n this.target = target;\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Sets the editor object.\n * @param {Object} editorObject - The editor object.\n */\n setEditorObject(editorObject) {\n this.editorObject = editorObject;\n }\n\n /**\n * Opens formula editor to editing a new formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openNewFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.dbclick = false;\n this.core.editionProperties.isNewElement = true;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Opens formula editor to editing an existing formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openExistingFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.isNewElement = false;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Wrapper to Core.updateFormula method.\n * Transform a MathML into a image formula.\n * Then the image formula is inserted in the specified target, creating a new image (new formula)\n * or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n */\n updateFormula(mathml) {\n if (this.editorParameters) {\n mathml = com.wiris.editor.util.EditorUtils.addAnnotation(\n mathml,\n \"application/vnd.wiris.mtweb-params+json\",\n JSON.stringify(this.editorParameters),\n );\n }\n let focusElement;\n let windowTarget;\n const wirisProperties = null;\n\n if (this.isIframe) {\n focusElement = this.target.contentWindow;\n windowTarget = this.target.contentWindow;\n } else {\n focusElement = this.target;\n windowTarget = window;\n }\n\n let obj = this.core.beforeUpdateFormula(mathml, wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n obj = this.insertFormula(focusElement, windowTarget, obj.mathml, obj.wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n return this.core.afterUpdateFormula(obj.focusElement, obj.windowTarget, obj.node, obj.latex);\n }\n\n /**\n * Wrapper to Core.insertFormula method.\n * Inserts the formula in the specified target, creating\n * a new image (new formula) or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n const obj = this.core.insertFormula(focusElement, windowTarget, mathml, wirisProperties);\n\n // Delete temporal image when inserted\n this.core.editionProperties.temporalImage = null;\n\n return obj;\n }\n\n /**\n * Returns the target selection.\n * @returns {Selection} target selection.\n */\n getSelection() {\n if (this.isIframe) {\n this.target.contentWindow.focus();\n return this.target.contentWindow.getSelection();\n }\n this.target.focus();\n return window.getSelection();\n }\n\n /**\n * Add events to formulas in the DOM target. The events added are the following:\n * - doubleClickHandler: handles Double-click event on formulas by opening an editor\n * to edit them.\n * - mouseDownHandler: handles mouse down event on formulas by saving the size of the formula\n * in case the the formula is resized.\n * - mouseUpHandler: handles mouse up event on formulas by restoring the saved formula size\n * in case the formula is resized.\n */\n addEvents() {\n const eventTarget = this.isIframe ? this.target.contentWindow.document : this.target;\n Util.addElementEvents(\n eventTarget,\n (element, event) => {\n this.doubleClickHandler(element, event);\n // Avoid creating the double click listener more than once for each element.\n // This also allows CKEditor4 to add their own double click listener.\n event.preventDefault();\n },\n (element, event) => {\n this.mousedownHandler(element, event);\n },\n (element, event) => {\n this.mouseupHandler(element, event);\n },\n );\n }\n\n /**\n * Remove events to formulas in the DOM target.\n */\n removeEvents() {\n const eventTarget =\n this.isIframe && this.target.contentWindow?.document ? this.target.contentWindow.document : this.target;\n\n if (!eventTarget) {\n return;\n }\n\n Util.removeElementEvents(eventTarget);\n }\n\n /**\n * Remove events, modals and set this.editorObject to null in order to prevent memory leaks.\n */\n destroy() {\n this.removeEvents();\n // Destroy modal dialog if exists.\n if (this.core.modalDialog) {\n this.core.modalDialog.destroy();\n }\n\n // Remove offline modal dialog if exists.\n if (this.offlineModal) {\n this.offlineModal.remove();\n }\n\n this.editorObject = null;\n }\n\n /**\n * Handles a Double-click on the target element. Opens an editor\n * to re-edit the double-clicked formula.\n * @param {HTMLElement} element - DOM object target.\n */\n doubleClickHandler(element) {\n this.core.editionProperties.dbclick = true;\n if (element.nodeName.toLowerCase() === \"img\") {\n this.core.getCustomEditors().disable();\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (element.hasAttribute(customEditorAttributeName)) {\n const customEditor = element.getAttribute(customEditorAttributeName);\n this.core.getCustomEditors().enable(customEditor);\n }\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.core.editionProperties.temporalImage = element;\n this.core.editionProperties.isNewElement = true;\n this.openExistingFormulaEditor();\n }\n }\n }\n\n /**\n * Handles a mouse up event on the target element. Restores the image size to avoid\n * resizing formulas.\n */\n mouseupHandler() {\n if (this.temporalImageResizing) {\n setTimeout(() => {\n Image.fixAfterResize(this.temporalImageResizing);\n }, 10);\n }\n }\n\n /**\n * Handles a mouse down event on the target element. Saves the formula size to avoid\n * resizing formulas.\n * @param {HTMLElement} element - target element.\n */\n mousedownHandler(element) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.temporalImageResizing = element;\n }\n }\n }\n\n /**\n * Returns the integration language. By default the browser agent. This method\n * should be overwritten to obtain the integration language, for example using the\n * plugin API of an HTML editor.\n * @returns {string} integration language.\n */\n getLanguage() {\n return this.getBrowserLanguage();\n }\n\n /**\n * Returns the browser language.\n * @returns {string} the browser language.\n */\n // eslint-disable-next-line class-methods-use-this\n getBrowserLanguage() {\n let language = \"en\";\n if (navigator.userLanguage) {\n language = navigator.userLanguage.substring(0, 2);\n } else if (navigator.language) {\n language = navigator.language.substring(0, 2);\n } else {\n language = \"en\";\n }\n return language;\n }\n\n /**\n * This function is called once the {@link Core} is loaded. IntegrationModel class\n * will fire this method when {@link Core} 'onLoad' event is fired.\n * This method should content all the logic to init\n * the integration.\n */\n callbackFunction() {\n // It's needed to wait until the integration target is ready. The event is fired\n // from the integration side.\n const listener = Listeners.newListener(\"onTargetReady\", () => {\n this.addEvents(this.target);\n });\n this.listeners.add(listener);\n }\n\n /**\n * Function called when the content submits an action.\n */\n // eslint-disable-next-line class-methods-use-this\n notifyWindowClosed() {\n // Nothing.\n }\n\n /**\n * Wrapper.\n * Extracts mathml of a determined text node. This function is used as a wrapper inside core.js\n * in order to get mathml from a text node that can contain normal LaTeX or other chosen text.\n * @param {string} textNode - text node to extract the MathML.\n * @param {int} caretPosition - caret position inside the text node.\n * @returns {string} MathML inside the text node.\n */\n\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getMathmlFromTextNode(textNode, caretPosition) {}\n\n /**\n * Wrapper\n * It fills wrs event object of nonLatex with the desired data.\n * @param {Object} event - event object.\n * @param {Object} window dom window object.\n * @param {string} mathml valid mathml.\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n fillNonLatexNode(event, window, mathml) {}\n\n /**\n Wrapper.\n * Returns selected item from the target.\n * @param {HTMLElement} target - target element\n * @param {boolean} iframe\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getSelectedItem(target, isIframe) {}\n\n // Set temporal image to null and make focus come back.\n static setActionsOnCancelButtons() {\n // Make focus come back on the previous place it was when click cancel button\n const currentInstance = WirisPlugin.currentInstance;\n const editorSelection = currentInstance.getSelection();\n editorSelection.removeAllRanges();\n\n if (currentInstance.core.editionProperties.range) {\n const { range } = currentInstance.core.editionProperties;\n currentInstance.core.editionProperties.range = null;\n editorSelection.addRange(range);\n if (range.startOffset !== range.endOffset) {\n currentInstance.core.placeCaretAfterNode(currentInstance.core.editionProperties.temporalImage);\n }\n }\n\n // eslint-disable-next-line no-undef\n if (WirisPlugin.currentInstance) {\n WirisPlugin.currentInstance.core.editionProperties.temporalImage = null; // eslint-disable-line\n }\n }\n}\n\n// To know if the integration that extends this class implements\n// wrapper methods, they are set as undefined.\nIntegrationModel.prototype.getMathmlFromTextNode = undefined;\nIntegrationModel.prototype.fillNonLatexNode = undefined;\nIntegrationModel.prototype.getSelectedItem = undefined;\n\n/**\n * An object containing a list with the overwritable class constructor properties.\n * @type {Object}\n */\nIntegrationModel.integrationParameters = [\"serviceProviderProperties\", \"editorParameters\"];\n","/* eslint-disable */\nvar md5;\nexport default md5;\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n delete Array.prototype.__class__;\n})();\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n})();\ndelete Array.prototype.__class__;\n// @codingStandardsIgnoreEnd\n","import IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Telemeter from \"@wiris/mathtype-html-integration-devkit/src/telemeter.js\";\n\n/**\n * This class represents the MathType integration for CKEditor5.\n * @extends {IntegrationModel}\n */\nexport default class CKEditor5Integration extends IntegrationModel {\n constructor(ckeditorIntegrationModelProperties) {\n const editor = ckeditorIntegrationModelProperties.editorObject;\n\n if (typeof editor.config !== \"undefined\" && typeof editor.config.get(\"mathTypeParameters\") !== \"undefined\") {\n ckeditorIntegrationModelProperties.integrationParameters = editor.config.get(\"mathTypeParameters\");\n }\n /**\n * CKEditor5 Integration.\n *\n * @param {integrationModelProperties} integrationModelAttributes\n */\n super(ckeditorIntegrationModelProperties);\n\n /**\n * Folder name used for the integration inside CKEditor plugins folder.\n */\n this.integrationFolderName = \"ckeditor_wiris\";\n }\n\n /**\n * @inheritdoc\n * @returns {string} - The CKEditor instance language.\n * @override\n */\n getLanguage() {\n // Returns the CKEDitor instance language taking into account that the language can be an object.\n // Try to get editorParameters.language, fail silently otherwise\n try {\n return this.editorParameters.language;\n } catch (e) {}\n const languageObject = this.editorObject.config.get(\"language\");\n if (languageObject != null) {\n if (typeof languageObject === \"object\") {\n if (Object.prototype.hasOwnProperty.call(languageObject, \"ui\")) {\n return languageObject.ui;\n }\n return this.editorObject.locale.uiLanguage;\n }\n return languageObject;\n }\n return super.getLanguage();\n }\n\n /**\n * Adds callbacks to the following CKEditor listeners:\n * - 'focus' - updates the current instance.\n * - 'contentDom' - adds 'doubleclick' callback.\n * - 'doubleclick' - sets to null data.dialog property to avoid modifications for MathType formulas.\n * - 'setData' - parses the data converting MathML into images.\n * - 'afterSetData' - adds an observer to MathType formulas to avoid modifications.\n * - 'getData' - parses the data converting images into selected save mode (MathML by default).\n * - 'mode' - recalculates the active element.\n */\n addEditorListeners() {\n const editor = this.editorObject;\n\n if (typeof editor.config.wirislistenersdisabled === \"undefined\" || !editor.config.wirislistenersdisabled) {\n this.checkElement();\n }\n }\n\n /**\n * Checks the current container and assign events in case that it doesn't have them.\n * CKEditor replaces several times the element element during its execution,\n * so we must assign the events again to editor element.\n */\n checkElement() {\n const editor = this.editorObject;\n const newElement = editor.sourceElement;\n\n // If the element wasn't treated, add the events.\n if (!newElement.wirisActive) {\n this.setTarget(newElement);\n this.addEvents();\n // Set the element as treated\n newElement.wirisActive = true;\n }\n }\n\n /**\n * @inheritdoc\n * @param {HTMLElement} element - HTMLElement target.\n * @param {MouseEvent} event - event which trigger the handler.\n */\n doubleClickHandler(element, event) {\n this.core.editionProperties.dbclick = true;\n if (this.editorObject.isReadOnly === false) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n // Some plugins (image2, image) open a dialog on Double-click. On formulas\n // doubleclick event ends here.\n if (typeof event.stopPropagation !== \"undefined\") {\n // old I.E compatibility.\n event.stopPropagation();\n } else {\n event.returnValue = false;\n }\n this.core.getCustomEditors().disable();\n const customEditorAttr = element.getAttribute(Configuration.get(\"imageCustomEditorName\"));\n if (customEditorAttr) {\n this.core.getCustomEditors().enable(customEditorAttr);\n }\n this.core.editionProperties.temporalImage = element;\n this.openExistingFormulaEditor();\n }\n }\n }\n }\n\n /** @inheritdoc */\n static getCorePath() {\n return null; // TODO\n }\n\n /** @inheritdoc */\n callbackFunction() {\n super.callbackFunction();\n this.addEditorListeners();\n }\n\n openNewFormulaEditor() {\n // Store the editor selection as it will be lost upon opening the modal\n this.core.editionProperties.selection = this.editorObject.editing.view.document.selection;\n\n // Focus on the selected editor when multiple editor instances are present\n WirisPlugin.currentInstance = this;\n\n return super.openNewFormulaEditor();\n }\n\n /**\n * Replaces old formula with new MathML or inserts it in caret position if new\n * @param {String} mathml MathML to update old one or insert\n * @returns {module:engine/model/element~Element} The model element corresponding to the inserted image\n */\n insertMathml(mathml) {\n // This returns the value returned by the callback function (writer => {...})\n return this.editorObject.model.change((writer) => {\n const core = this.getCore();\n const selection = this.editorObject.model.document.selection;\n\n const modelElementNew = writer.createElement(\"mathml\", {\n formula: mathml,\n ...Object.fromEntries(selection.getAttributes()), // To keep the format, such as style and font\n });\n\n // Obtain the DOM object corresponding to the formula\n if (core.editionProperties.isNewElement) {\n // Don't bother inserting anything at all if the MathML is empty.\n if (!mathml) return;\n\n const viewSelection =\n this.core.editionProperties.selection || this.editorObject.editing.view.document.selection;\n const modelPosition = this.editorObject.editing.mapper.toModelPosition(viewSelection.getLastPosition());\n\n this.editorObject.model.insertObject(modelElementNew, modelPosition);\n\n // Remove selection\n if (!viewSelection.isCollapsed) {\n for (const range of viewSelection.getRanges()) {\n writer.remove(this.editorObject.editing.mapper.toModelRange(range));\n }\n }\n\n // Set carret after the formula\n const position = this.editorObject.model.createPositionAfter(modelElementNew);\n writer.setSelection(position);\n } else {\n const img = core.editionProperties.temporalImage;\n const viewElement = this.editorObject.editing.view.domConverter.domToView(img).parent;\n const modelElementOld = this.editorObject.editing.mapper.toModelElement(viewElement);\n\n // Insert the new and remove the old one\n const position = this.editorObject.model.createPositionBefore(modelElementOld);\n\n // If the given MathML is empty, don't insert a new formula.\n if (mathml) {\n this.editorObject.model.insertObject(modelElementNew, position);\n }\n writer.remove(modelElementOld);\n }\n\n // eslint-disable-next-line consistent-return\n return modelElementNew;\n });\n }\n\n /**\n * Finds the text node corresponding to given DOM text element.\n * @param {element} viewElement Element to find corresponding text node of.\n * @returns {module:engine/model/text~Text|undefined} Text node corresponding to the given element or undefined if it doesn't exist.\n */\n findText(viewElement) {\n // eslint-disable-line consistent-return\n // mapper always converts text nodes to *new* model elements so we need to convert the text's parents and then come back down\n let pivot = viewElement;\n let element;\n while (!element) {\n element = this.editorObject.editing.mapper.toModelElement(\n this.editorObject.editing.view.domConverter.domToView(pivot),\n );\n pivot = pivot.parentElement;\n }\n\n // Navigate through all the subtree under `pivot` in order to find the correct text node\n const range = this.editorObject.model.createRangeIn(element);\n const descendants = Array.from(range.getItems());\n for (const node of descendants) {\n let viewElementData = viewElement.data;\n if (viewElement.nodeType === 3) {\n // Remove invisible white spaces\n viewElementData = viewElementData.replaceAll(String.fromCharCode(8288), \"\");\n }\n if (node.is(\"textProxy\") && node.data === viewElementData.replace(String.fromCharCode(160), \" \")) {\n return node.textNode;\n }\n }\n }\n\n /** @inheritdoc */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n // eslint-disable-line no-unused-vars\n const returnObject = {};\n\n let mathmlOrigin;\n if (!mathml) {\n this.insertMathml(\"\");\n } else if (this.core.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n\n this.editorObject.model.change((writer) => {\n const { latexRange } = this.core.editionProperties;\n\n const startNode = this.findText(latexRange.startContainer);\n const endNode = this.findText(latexRange.endContainer);\n\n let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);\n let endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);\n\n let range = writer.createRange(startPosition, endPosition);\n\n // When Latex is next to image/formula.\n if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {\n // Get the position of the latex to be replaced.\n const latexEdited = `$$${Latex.getLatexFromMathML(\n MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml),\n )}$$`;\n let data = latexRange.startContainer.data;\n\n // Remove invisible characters.\n data = data.replaceAll(String.fromCharCode(8288), \"\");\n\n // Get to the start of the latex we are editing.\n const offset = data.indexOf(latexEdited);\n const dataOffset = data.substring(offset);\n const second$ = dataOffset.substring(2).indexOf(\"$$\") + 4;\n const substring = dataOffset.substr(0, second$);\n data = data.replace(substring, \"\");\n\n if (!data) {\n startPosition = writer.createPositionBefore(startNode);\n range = startNode;\n } else {\n startPosition = startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + offset);\n endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + second$ + offset);\n range = writer.createRange(startPosition, endPosition);\n }\n }\n\n writer.remove(range);\n writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);\n });\n } else {\n mathmlOrigin = this.core.editionProperties.temporalImage?.dataset.mathml;\n try {\n returnObject.node = this.editorObject.editing.view.domConverter.viewToDom(\n this.editorObject.editing.mapper.toViewElement(this.insertMathml(mathml)),\n windowTarget.document,\n );\n } catch (e) {\n const x = e.toString();\n if (x.includes(\"CKEditorError: Cannot read property 'parent' of undefined\")) {\n this.core.modalDialog.cancelAction();\n }\n }\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.core.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n\n /* Due to PLUGINS-1329, we add the onChange event to the CK4 insertFormula.\n We probably should add it here as well, but we should look further into how */\n // this.editorObject.fire('change');\n\n // Remove temporal image of inserted formula\n this.core.editionProperties.temporalImage = null;\n\n return returnObject;\n }\n\n /**\n * Function called when the content submits an action.\n */\n notifyWindowClosed() {\n this.editorObject.editing.view.focus();\n }\n}\n","/* eslint-disable max-classes-per-file */\nimport { Command } from \"ckeditor5/src/core.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\n/**\n * Command for opening the MathType editor\n */\nexport class MathTypeCommand extends Command {\n execute(options = {}) {\n // Check we get a valid integration\n // eslint-disable-next-line no-prototype-builtins\n if (!options.hasOwnProperty(\"integration\") || !(options.integration instanceof CKEditor5Integration)) {\n throw 'Must pass a valid CKEditor5Integration instance as attribute \"integration\" of options';\n }\n\n // Save the integration instance as a property of the command.\n this.integration = options.integration;\n\n // Set custom editor or disable it\n this.setEditor();\n\n // Open the editor\n this.openEditor();\n }\n\n /**\n * Sets the appropriate custom editor, if any, or disables them.\n */\n setEditor() {\n // It's possible that a custom editor was last used.\n // We need to disable it to avoid wrong behaviors.\n this.integration.core.getCustomEditors().disable();\n }\n\n /**\n * Checks whether we are editing an existing formula or a new one and opens the editor.\n */\n openEditor() {\n this.integration.core.editionProperties.dbclick = false;\n const image = this._getSelectedImage();\n if (\n typeof image !== \"undefined\" &&\n image !== null &&\n image.classList.contains(WirisPlugin.Configuration.get(\"imageClassName\"))\n ) {\n this.integration.core.editionProperties.temporalImage = image;\n this.integration.openExistingFormulaEditor();\n } else {\n this.integration.openNewFormulaEditor();\n }\n }\n\n /**\n * Gets the currently selected formula image\n * @returns {Element} selected image, if any, undefined otherwise\n */\n _getSelectedImage() {\n const { selection } = this.editor.editing.view.document;\n\n // If we can not extract the formula, fall back to default behavior.\n if (selection.isCollapsed || selection.rangeCount !== 1) {\n return;\n }\n\n // Look for the wrapping the formula and then for the inside\n\n const range = selection.getFirstRange();\n\n let image;\n\n for (const span of range) {\n if (span.item.name !== \"span\") {\n return;\n }\n image = span.item.getChild(0);\n break;\n }\n\n if (!image) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n return this.editor.editing.view.domConverter.mapViewToDom(image);\n }\n}\n\n/**\n * Command for opening the ChemType editor\n */\nexport class ChemTypeCommand extends MathTypeCommand {\n setEditor() {\n this.integration.core.getCustomEditors().enable(\"chemistry\");\n }\n}\n","// CKEditor imports\nimport { Plugin } from \"ckeditor5/src/core.js\";\nimport { ButtonView } from \"ckeditor5/src/ui.js\";\nimport { ClickObserver, HtmlDataProcessor, XmlDataProcessor, ViewUpcastWriter } from \"ckeditor5/src/engine.js\";\nimport { Widget, toWidget, viewToModelPositionOutsideModelElement } from \"ckeditor5/src/widget.js\";\n\n// MathType API imports\nimport IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Core from \"@wiris/mathtype-html-integration-devkit/src/core.src.js\";\nimport Parser from \"@wiris/mathtype-html-integration-devkit/src/parser.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Image from \"@wiris/mathtype-html-integration-devkit/src/image.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Listeners from \"@wiris/mathtype-html-integration-devkit/src/listeners.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport StringManager from \"@wiris/mathtype-html-integration-devkit/src/stringmanager.js\";\nimport \"@wiris/mathtype-html-integration-devkit/src/md5.js\";\n\n// Local imports\nimport { MathTypeCommand, ChemTypeCommand } from \"./commands.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\nimport mathIcon from \"../theme/icons/ckeditor5-formula.svg\";\nimport chemIcon from \"../theme/icons/ckeditor5-chem.svg\";\n\nimport packageInfo from \"../package.json\";\n\nexport let currentInstance = null; // eslint-disable-line import/no-mutable-exports\n\nexport default class MathType extends Plugin {\n static get requires() {\n return [Widget];\n }\n\n static get pluginName() {\n return \"MathType\";\n }\n\n init() {\n // Create the MathType API Integration object\n const integration = this._addIntegration();\n currentInstance = integration;\n\n // Add the MathType and ChemType commands to the editor\n this._addCommands();\n\n // Add the buttons for MathType and ChemType\n this._addViews(integration);\n\n // Registers the element in the schema\n this._addSchema();\n\n // Add the downcast and upcast converters\n this._addConverters(integration);\n\n // Expose the WirisPlugin variable to the window\n this._exposeWiris();\n }\n\n /**\n * Inherited from Plugin class: Executed when CKEditor5 is destroyed\n */\n destroy() {\n // eslint-disable-line class-methods-use-this\n currentInstance?.destroy();\n }\n\n /**\n * Create the MathType API Integration object\n * @returns {CKEditor5Integration} the integration object\n */\n _addIntegration() {\n const { editor } = this;\n\n /**\n * Integration model constructor attributes.\n * @type {integrationModelProperties}\n */\n const integrationProperties = {};\n integrationProperties.environment = {};\n integrationProperties.environment.editor = \"CKEditor5\";\n integrationProperties.environment.editorVersion = \"5.x\";\n integrationProperties.version = packageInfo.version;\n integrationProperties.editorObject = editor;\n integrationProperties.serviceProviderProperties = {};\n integrationProperties.serviceProviderProperties.URI = \"https://www.wiris.net/demo/plugins/app\";\n integrationProperties.serviceProviderProperties.server = \"java\";\n integrationProperties.target = editor.sourceElement;\n integrationProperties.scriptName = \"bundle.js\";\n integrationProperties.managesLanguage = true;\n // etc\n\n // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.\n // To avoid a wrong behavior, this integration only starts if the workspace container exists.\n let integration;\n if (integrationProperties.target) {\n // Instance of the integration associated to this editor instance\n integration = new CKEditor5Integration(integrationProperties);\n integration.init();\n integration.listeners.fire(\"onTargetReady\", {});\n\n integration.checkElement();\n\n this.listenTo(\n editor.editing.view.document,\n \"click\",\n (evt, data) => {\n // Is Double-click\n if (data.domEvent.detail === 2) {\n integration.doubleClickHandler(data.domTarget, data.domEvent);\n evt.stop();\n }\n },\n { priority: \"highest\" },\n );\n }\n\n return integration;\n }\n\n /**\n * Add the MathType and ChemType commands to the editor\n */\n _addCommands() {\n const { editor } = this;\n\n // Add command to open the formula editor\n editor.commands.add(\"MathType\", new MathTypeCommand(editor));\n\n // Add command to open the chemistry formula editor\n editor.commands.add(\"ChemType\", new ChemTypeCommand(editor));\n }\n\n /**\n * Add the buttons for MathType and ChemType\n * @param {CKEditor5Integration} integration the integration object\n */\n _addViews(integration) {\n const { editor } = this;\n\n // Check if MathType editor is enabled\n if (Configuration.get(\"editorEnabled\")) {\n // Add button for the formula editor\n editor.ui.componentFactory.add(\"MathType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"MathType\"), \"isEnabled\");\n view.set({\n label: StringManager.get(\"insert_math\", integration.getLanguage()),\n icon: mathIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"MathType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Check if ChemType editor is enabled\n if (Configuration.get(\"chemEnabled\")) {\n // Add button for the chemistry formula editor\n editor.ui.componentFactory.add(\"ChemType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"ChemType\"), \"isEnabled\");\n\n view.set({\n label: StringManager.get(\"insert_chem\", integration.getLanguage()),\n icon: chemIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"ChemType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Observer for the Double-click event\n editor.editing.view.addObserver(ClickObserver);\n }\n\n /**\n * Registers the element in the schema\n */\n _addSchema() {\n const { schema } = this.editor.model;\n\n schema.register(\"mathml\", {\n inheritAllFrom: \"$inlineObject\",\n allowAttributes: [\"formula\", \"htmlContent\"],\n });\n }\n\n /**\n * Add the downcast and upcast converters\n */\n _addConverters(integration) {\n const { editor } = this;\n\n // Editing view -> Model\n editor.conversion.for(\"upcast\").elementToElement({\n view: {\n name: \"span\",\n classes: \"ck-math-widget\",\n },\n model: (viewElement, { writer: modelWriter }) => {\n const formula = MathML.safeXmlDecode(viewElement.getChild(0).getAttribute(\"data-mathml\"));\n return modelWriter.createElement(\"mathml\", {\n formula,\n });\n },\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\"element:math\", (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // When element was already consumed then skip it.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // If we encounter any with a LaTeX annotation inside,\n // convert it into a \"$$...$$\" string.\n const isLatex = mathIsLatex(viewItem); // eslint-disable-line no-use-before-define\n\n // Get the formula of the (which is all its children).\n const processor = new XmlDataProcessor(editor.editing.view.document);\n\n // Only god knows why the following line makes viewItem lose all of its children,\n // so we obtain isLatex before doing this because we need viewItem's children for that.\n const upcastWriter = new ViewUpcastWriter(editor.editing.view.document);\n const viewDocumentFragment = upcastWriter.createDocumentFragment(viewItem.getChildren());\n\n // and obtain the attributes of too!\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n\n // We process the document fragment\n let formula = processor.toData(viewDocumentFragment) || \"\";\n\n // And obtain the complete formula\n formula = Util.htmlSanitize(`${formula}`);\n\n // Replaces the < & > characters to its HTMLEntity to avoid render issues.\n formula = formula.replaceAll('\"<\"', '\"<\"').replaceAll('\">\"', '\">\"').replaceAll(\"><<\", \"><<\");\n\n /* Model node that contains what's going to actually be inserted. This can be either:\n - A element with a formula attribute set to the given formula, or\n - If the original had a LaTeX annotation, then the annotation surrounded by \"$$...$$\" */\n const modelNode = isLatex\n ? writer.createText(Parser.initParse(formula, integration.getLanguage()))\n : writer.createElement(\"mathml\", { formula });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\n \"element:img\",\n (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // Only upcast when is wiris formula\n if (viewItem.getClassNames().next().value !== \"Wirisformula\") {\n return;\n }\n\n // The following code ensures that the element's name, attributes, and classes are consumed.\n // This means that they are marked as handled so that other parts of the system or plugins don't process them again.\n\n // Check if we can consume the element name.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // Consume the name, attributes, and classes so nothing else processes it.\n consumable.consume(viewItem, { name: true });\n for (const attrName of viewItem.getAttributes()) {\n consumable.consume(viewItem, { attributes: [attrName] });\n }\n\n for (const className of viewItem.getClassNames()) {\n consumable.consume(viewItem, { classes: [className] });\n }\n\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n const htmlContent = Util.htmlSanitize(``);\n\n const modelNode = writer.createElement(\"mathml\", { htmlContent });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n },\n // Ensures MathType processes the Wiris formulas before other plugins, preventing conflicts.\n { priority: \"high\" },\n );\n\n /**\n * Whether the given view element has a LaTeX annotation element.\n * @param {*} math\n * @returns {bool}\n */\n function mathIsLatex(math) {\n const semantics = math.getChild(0);\n if (!semantics || semantics.name !== \"semantics\") return false;\n for (const child of semantics.getChildren()) {\n if (child.name === \"annotation\" && child.getAttribute(\"encoding\") === \"LaTeX\") {\n return true;\n }\n }\n return false;\n }\n\n function createViewWidget(modelItem, { writer: viewWriter }) {\n const widgetElement = viewWriter.createContainerElement(\"span\", {\n class: \"ck-math-widget\",\n });\n\n const mathUIElement = createViewImage(modelItem, { writer: viewWriter }); // eslint-disable-line no-use-before-define\n\n if (mathUIElement) {\n viewWriter.insert(viewWriter.createPositionAt(widgetElement, 0), mathUIElement);\n }\n\n return toWidget(widgetElement, viewWriter);\n }\n\n function createViewImage(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n const formula = modelItem.getAttribute(\"formula\");\n const htmlContent = modelItem.getAttribute(\"htmlContent\");\n\n if (!formula && !htmlContent) {\n return null;\n }\n\n let imgElement = null;\n\n if (htmlContent) {\n imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);\n } else if (formula) {\n const mathString = formula.replaceAll('ref=\"<\"', 'ref=\"<\"');\n\n const imgHtml = Parser.initParse(mathString, integration.getLanguage());\n imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);\n\n // Add HTML element () to model\n viewWriter.setAttribute(\"htmlContent\", imgHtml, modelItem);\n }\n\n /* Although we use the HtmlDataProcessor to obtain the attributes,\n * we must create a new EmptyElement which is independent of the\n * DataProcessor being used by this editor instance\n */\n if (imgElement) {\n return viewWriter.createEmptyElement(\"img\", imgElement.getAttributes(), {\n renderUnsafeAttributes: [\"src\"],\n });\n }\n\n return null;\n }\n\n // Model -> Editing view\n editor.conversion.for(\"editingDowncast\").elementToElement({\n model: \"mathml\",\n view: createViewWidget,\n });\n\n // Model -> Data view\n editor.conversion.for(\"dataDowncast\").elementToElement({\n model: \"mathml\",\n view: createDataString, // eslint-disable-line no-use-before-define\n });\n\n /**\n * Makes a copy of the given view node.\n * @param {module:engine/view/node~Node} sourceNode Node to copy.\n * @returns {module:engine/view/node~Node} Copy of the node.\n */\n function clone(viewWriter, sourceNode) {\n if (sourceNode.is(\"text\")) {\n return viewWriter.createText(sourceNode.data);\n }\n if (sourceNode.is(\"element\")) {\n if (sourceNode.is(\"emptyElement\")) {\n return viewWriter.createEmptyElement(sourceNode.name, sourceNode.getAttributes());\n }\n const element = viewWriter.createContainerElement(sourceNode.name, sourceNode.getAttributes());\n for (const child of sourceNode.getChildren()) {\n viewWriter.insert(viewWriter.createPositionAt(element, \"end\"), clone(viewWriter, child));\n }\n return element;\n }\n\n throw new Exception(\"Given node has unsupported type.\"); // eslint-disable-line no-undef\n }\n\n function createDataString(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n // Load img element\n const mathString =\n modelItem.getAttribute(\"htmlContent\") || Parser.endParseSaveMode(modelItem.getAttribute(\"formula\"));\n\n const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);\n\n return clone(viewWriter, sourceMathElement);\n }\n\n // This stops the view selection getting into the s and messing up caret movement\n editor.editing.mapper.on(\n \"viewToModelPosition\",\n viewToModelPositionOutsideModelElement(editor.model, (viewElement) => viewElement.hasClass(\"ck-math-widget\")),\n );\n\n // Keep a reference to the original get and set function.\n const { get, set } = editor.data;\n\n /**\n * Hack to transform $$latex$$ into in editor.getData()'s output.\n */\n editor.data.on(\n \"get\",\n (e) => {\n const output = e.return;\n const parsedResult = Parser.endParse(output);\n\n // Cleans all the semantics tag for safexml\n // including the handwritten data points\n e.return = MathML.removeSafeXMLSemantics(parsedResult);\n },\n { priority: \"low\" },\n );\n\n /**\n * Hack to transform with LaTeX into $$LaTeX$$ and formula images in editor.setData().\n */\n editor.data.on(\n \"set\",\n (e, args) => {\n // Retrieve the data to be set on the CKEditor.\n let modifiedData = args[0];\n // Regex to find all mathml formulas.\n const regexp = /(]*>)|()/gm;\n const formulas = [];\n let formula;\n\n // Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.\n while ((formula = regexp.exec(modifiedData)) !== null) {\n formulas.push(formula[0]);\n }\n\n // Loop to find LaTeX and formula images and replace the MathML for the both.\n formulas.forEach((formula) => {\n if (formula.includes('encoding=\"LaTeX\"')) {\n // LaTeX found.\n const latex = `$$$${Latex.getLatexFromMathML(formula)}$$$`; // We add $$$ instead of $$ because the replace function ignores one $.\n modifiedData = modifiedData.replace(formula, latex);\n } else if (formula.includes(\" 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + args[_key - 2] = arguments[_key]; + } + return func.apply(thisArg, args); }; } if (!construct) { - construct = function construct(Func, args) { + construct = function construct(Func) { + for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { + args[_key2 - 1] = arguments[_key2]; + } return new Func(...args); }; } @@ -68,8 +74,8 @@ if (thisArg instanceof RegExp) { thisArg.lastIndex = 0; } - for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; + for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + args[_key3 - 1] = arguments[_key3]; } return apply(func, thisArg, args); }; @@ -80,12 +86,12 @@ * @param func - The constructor function to be wrapped and called. * @returns A new function that constructs an instance of the given constructor function with the provided arguments. */ - function unconstruct(func) { + function unconstruct(Func) { return function () { - for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { - args[_key2] = arguments[_key2]; + for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { + args[_key4] = arguments[_key4]; } - return construct(func, args); + return construct(Func, args); }; } /** @@ -184,8 +190,8 @@ return fallbackValue; } - const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); - const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']); + const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']); + const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']); const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']); // List of SVG elements that are disallowed by default. // We still need to know them so that we can do namespace @@ -198,8 +204,8 @@ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']); const text = freeze(['#text']); - const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']); - const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']); + const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']); + const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']); const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']); const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']); @@ -297,7 +303,7 @@ function createDOMPurify() { let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal(); const DOMPurify = root => createDOMPurify(root); - DOMPurify.version = '3.2.6'; + DOMPurify.version = '3.3.0'; DOMPurify.removed = []; if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) { // Not running in a browser, provide a factory function @@ -408,6 +414,21 @@ let FORBID_TAGS = null; /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */ let FORBID_ATTR = null; + /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */ + const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, { + tagCheck: { + writable: true, + configurable: false, + enumerable: true, + value: null + }, + attributeCheck: { + writable: true, + configurable: false, + enumerable: true, + value: null + } + })); /* Decide if ARIA attributes are okay */ let ALLOW_ARIA_ATTR = true; /* Decide if custom data attributes are okay */ @@ -600,16 +621,24 @@ } /* Merge configuration parameters */ if (cfg.ADD_TAGS) { - if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) { - ALLOWED_TAGS = clone(ALLOWED_TAGS); + if (typeof cfg.ADD_TAGS === 'function') { + EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS; + } else { + if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) { + ALLOWED_TAGS = clone(ALLOWED_TAGS); + } + addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc); } - addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc); } if (cfg.ADD_ATTR) { - if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) { - ALLOWED_ATTR = clone(ALLOWED_ATTR); + if (typeof cfg.ADD_ATTR === 'function') { + EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR; + } else { + if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) { + ALLOWED_ATTR = clone(ALLOWED_ATTR); + } + addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc); } - addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc); } if (cfg.ADD_URI_SAFE_ATTR) { addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc); @@ -917,7 +946,7 @@ return true; } /* Remove element if anything forbids its presence */ - if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) { + if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) { /* Check if we have a custom element to handle */ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) { if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) { @@ -989,12 +1018,12 @@ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes) XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804) We don't need to check the value; it's always URI safe. */ - if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) { + if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) { if ( // First condition does a very basic check if a) it's basically a valid custom element tagname AND // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck - _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) || + _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) || // Alternative, second condition checks if it's an `is`-attribute, AND // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else { @@ -1073,7 +1102,12 @@ value = SANITIZE_NAMED_PROPS_PREFIX + value; } /* Work around a security issue with comments inside attributes */ - if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) { + if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title|textarea)/i, value)) { + _removeAttribute(name, currentNode); + continue; + } + /* Make sure we cannot easily use animated hrefs, even if animations are allowed */ + if (lcName === 'attributename' && stringMatch(value, 'href')) { _removeAttribute(name, currentNode); continue; } @@ -3457,6 +3491,13 @@ } } /** + * A map from event target to event handlers so we can remove the event + * listeners in removeElementEvents + * + * @type {Map} + * @static + */ static elementEventsMap = new Map(); + /** * Adds the a callback function, for a certain event target, to the following event types: * - dblclick * - mousedown @@ -3467,24 +3508,29 @@ * @param {Function} mouseupHandler - function to run when on mouseup event. * @static */ static addElementEvents(eventTarget, doubleClickHandler, mousedownHandler, mouseupHandler) { + // Make sure not to leak event listeners if we've already added events to + // this element + Util.removeElementEvents(eventTarget); + let entry = {}; + Util.elementEventsMap.set(eventTarget, entry); if (doubleClickHandler) { - this.callbackDblclick = (event)=>{ + entry.callbackDblclick = (event)=>{ const realEvent = event || window.event; const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target; doubleClickHandler(element, realEvent); }; - Util.addEvent(eventTarget, "dblclick", this.callbackDblclick); + Util.addEvent(eventTarget, "dblclick", entry.callbackDblclick); } if (mousedownHandler) { - this.callbackMousedown = (event)=>{ + entry.callbackMousedown = (event)=>{ const realEvent = event || window.event; const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target; mousedownHandler(element, realEvent); }; - Util.addEvent(eventTarget, "mousedown", this.callbackMousedown); + Util.addEvent(eventTarget, "mousedown", entry.callbackMousedown); } if (mouseupHandler) { - this.callbackMouseup = (event)=>{ + entry.callbackMouseup = (event)=>{ const realEvent = event || window.event; const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target; mouseupHandler(element, realEvent); @@ -3493,8 +3539,8 @@ // while the mouse is outside the editor text field. // This is a workaround: we trigger the event independently of where the mouse // is when we release its button. - Util.addEvent(document, "mouseup", this.callbackMouseup); - Util.addEvent(eventTarget, "mouseup", this.callbackMouseup); + Util.addEvent(document, "mouseup", entry.callbackMouseup); + Util.addEvent(eventTarget, "mouseup", entry.callbackMouseup); } } /** @@ -3505,10 +3551,15 @@ * @param {EventTarget} eventTarget - event target. * @static */ static removeElementEvents(eventTarget) { - Util.removeEvent(eventTarget, "dblclick", this.callbackDblclick); - Util.removeEvent(eventTarget, "mousedown", this.callbackMousedown); - Util.removeEvent(document, "mouseup", this.callbackMouseup); - Util.removeEvent(eventTarget, "mouseup", this.callbackMouseup); + let entry = Util.elementEventsMap.get(eventTarget); + if (!entry) { + return; + } + Util.elementEventsMap.delete(eventTarget); + Util.removeEvent(eventTarget, "dblclick", entry.callbackDblclick); + Util.removeEvent(eventTarget, "mousedown", entry.callbackMousedown); + Util.removeEvent(document, "mouseup", entry.callbackMouseup); + Util.removeEvent(eventTarget, "mouseup", entry.callbackMouseup); } /** * Adds a class name to a HTMLElement. @@ -7232,11 +7283,11 @@ this.closeDiv.setAttribute("role", "button"); this.closeDiv.setAttribute("tabindex", 3); // Apply styles and events after the creation as createElement doesn't process them correctly - let generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`; - let hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`; - this.closeDiv.setAttribute("style", generalStyle); - this.closeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.closeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`; + const hoverStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`; + this.closeDiv.setAttribute("style", generalStyleClose); + this.closeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleClose); + this.closeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleClose); // To identifiy the element in automated testing this.closeDiv.setAttribute("data-testid", "mtcteditor-close-button"); attributes = {}; @@ -7246,11 +7297,11 @@ this.stackDiv = Util.createElement("a", attributes); this.stackDiv.setAttribute("role", "button"); this.stackDiv.setAttribute("tabindex", 2); - generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`; - hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`; - this.stackDiv.setAttribute("style", generalStyle); - this.stackDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.stackDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`; + const hoverStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`; + this.stackDiv.setAttribute("style", generalStyleStack); + this.stackDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleStack); + this.stackDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleStack); // To identifiy the element in automated testing this.stackDiv.setAttribute("data-testid", "mtcteditor-fullscreen-disable-button"); attributes = {}; @@ -7260,11 +7311,11 @@ this.maximizeDiv = Util.createElement("a", attributes); this.maximizeDiv.setAttribute("role", "button"); this.maximizeDiv.setAttribute("tabindex", 2); - generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`; - hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`; - this.maximizeDiv.setAttribute("style", generalStyle); - this.maximizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.maximizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`; + const hoverStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`; + this.maximizeDiv.setAttribute("style", generalStyleMaximize); + this.maximizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleMaximize); + this.maximizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleMaximize); // To identifiy the element in automated testing this.maximizeDiv.setAttribute("data-testid", "mtcteditor-fullscreen-enable-button"); attributes = {}; @@ -7274,11 +7325,11 @@ this.minimizeDiv = Util.createElement("a", attributes); this.minimizeDiv.setAttribute("role", "button"); this.minimizeDiv.setAttribute("tabindex", 1); - generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; - hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; - this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + const generalStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; + const hoverStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; + this.minimizeDiv.setAttribute("style", generalStyleMinimize); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyleMinimize); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyleMinimize); // To identify the element in automated testing this.minimizeDiv.setAttribute("data-testid", "mtcteditor-minimize-button"); attributes = {}; @@ -7830,8 +7881,8 @@ const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyle); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyle); this.restoreModalProperties(); if (typeof this.resizerBR !== "undefined" && typeof this.resizerTL !== "undefined") { this.setResizeButtonsVisibility(); @@ -7873,8 +7924,8 @@ const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxIcon)})`; const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxHoverIcon)})`; this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyle); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyle); } } /** @@ -7901,8 +7952,8 @@ const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`; const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`; this.minimizeDiv.setAttribute("style", generalStyle); - this.minimizeDiv.setAttribute("onmouseover", `this.style = "${hoverStyle}";`); - this.minimizeDiv.setAttribute("onmouseout", `this.style = "${generalStyle}";`); + this.minimizeDiv.addEventListener("mouseover", (e)=>e.target.style = hoverStyle); + this.minimizeDiv.addEventListener("mouseout", (e)=>e.target.style = generalStyle); // Set size to 80% screen with a max size. this.setSize(parseInt(window.innerHeight * 0.8, 10), parseInt(window.innerWidth * 0.8, 10)); if (this.container.clientHeight > 700) { @@ -9767,7 +9818,8 @@ Util.addElementEvents(eventTarget, (element, event)=>{ this.doubleClickHandler(element, event); // Avoid creating the double click listener more than once for each element. - event.stopImmediatePropagation(); + // This also allows CKEditor4 to add their own double click listener. + event.preventDefault(); }, (element, event)=>{ this.mousedownHandler(element, event); }, (element, event)=>{ @@ -11110,7 +11162,7 @@ if (Object.prototype.hasOwnProperty.call(languageObject, "ui")) { return languageObject.ui; } - return languageObject; + return this.editorObject.locale.uiLanguage; } return languageObject; } diff --git a/packages/ckeditor5/dist/browser/index.umd.js.map b/packages/ckeditor5/dist/browser/index.umd.js.map index ddcafb1f3..39d6a768b 100644 --- a/packages/ckeditor5/dist/browser/index.umd.js.map +++ b/packages/ckeditor5/dist/browser/index.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"index.umd.js","sources":["../../../../node_modules/dompurify/dist/purify.es.mjs","../../node_modules/@wiris/mathtype-html-integration-devkit/src/constants.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/mathml.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/configuration.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/textcache.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/listeners.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/serviceprovider.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/latex.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/stringmanager.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/util.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/image.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/accessibility.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/parser.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/editorlistener.js","../../node_modules/@wiris/mathtype-html-integration-devkit/telemeter-wasm/telemeter_wasm.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/telemeter.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/contentmanager.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/customeditors.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/jsvariables.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/event.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/popupmessage.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/focusprotection.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/modal.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/polyfills.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/core.src.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/integrationmodel.js","../../node_modules/@wiris/mathtype-html-integration-devkit/src/md5.js","../../src/integration.js","../../src/commands.js","../../src/plugin.js"],"sourcesContent":["/*! @license DOMPurify 3.2.6 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.6/LICENSE */\n\nconst {\n entries,\n setPrototypeOf,\n isFrozen,\n getPrototypeOf,\n getOwnPropertyDescriptor\n} = Object;\nlet {\n freeze,\n seal,\n create\n} = Object; // eslint-disable-line import/no-mutable-exports\nlet {\n apply,\n construct\n} = typeof Reflect !== 'undefined' && Reflect;\nif (!freeze) {\n freeze = function freeze(x) {\n return x;\n };\n}\nif (!seal) {\n seal = function seal(x) {\n return x;\n };\n}\nif (!apply) {\n apply = function apply(fun, thisValue, args) {\n return fun.apply(thisValue, args);\n };\n}\nif (!construct) {\n construct = function construct(Func, args) {\n return new Func(...args);\n };\n}\nconst arrayForEach = unapply(Array.prototype.forEach);\nconst arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);\nconst arrayPop = unapply(Array.prototype.pop);\nconst arrayPush = unapply(Array.prototype.push);\nconst arraySplice = unapply(Array.prototype.splice);\nconst stringToLowerCase = unapply(String.prototype.toLowerCase);\nconst stringToString = unapply(String.prototype.toString);\nconst stringMatch = unapply(String.prototype.match);\nconst stringReplace = unapply(String.prototype.replace);\nconst stringIndexOf = unapply(String.prototype.indexOf);\nconst stringTrim = unapply(String.prototype.trim);\nconst objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);\nconst regExpTest = unapply(RegExp.prototype.test);\nconst typeErrorCreate = unconstruct(TypeError);\n/**\n * Creates a new function that calls the given function with a specified thisArg and arguments.\n *\n * @param func - The function to be wrapped and called.\n * @returns A new function that calls the given function with a specified thisArg and arguments.\n */\nfunction unapply(func) {\n return function (thisArg) {\n if (thisArg instanceof RegExp) {\n thisArg.lastIndex = 0;\n }\n for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n args[_key - 1] = arguments[_key];\n }\n return apply(func, thisArg, args);\n };\n}\n/**\n * Creates a new function that constructs an instance of the given constructor function with the provided arguments.\n *\n * @param func - The constructor function to be wrapped and called.\n * @returns A new function that constructs an instance of the given constructor function with the provided arguments.\n */\nfunction unconstruct(func) {\n return function () {\n for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {\n args[_key2] = arguments[_key2];\n }\n return construct(func, args);\n };\n}\n/**\n * Add properties to a lookup table\n *\n * @param set - The set to which elements will be added.\n * @param array - The array containing elements to be added to the set.\n * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.\n * @returns The modified set with added elements.\n */\nfunction addToSet(set, array) {\n let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;\n if (setPrototypeOf) {\n // Make 'in' and truthy checks like Boolean(set.constructor)\n // independent of any properties defined on Object.prototype.\n // Prevent prototype setters from intercepting set as a this value.\n setPrototypeOf(set, null);\n }\n let l = array.length;\n while (l--) {\n let element = array[l];\n if (typeof element === 'string') {\n const lcElement = transformCaseFunc(element);\n if (lcElement !== element) {\n // Config presets (e.g. tags.js, attrs.js) are immutable.\n if (!isFrozen(array)) {\n array[l] = lcElement;\n }\n element = lcElement;\n }\n }\n set[element] = true;\n }\n return set;\n}\n/**\n * Clean up an array to harden against CSPP\n *\n * @param array - The array to be cleaned.\n * @returns The cleaned version of the array\n */\nfunction cleanArray(array) {\n for (let index = 0; index < array.length; index++) {\n const isPropertyExist = objectHasOwnProperty(array, index);\n if (!isPropertyExist) {\n array[index] = null;\n }\n }\n return array;\n}\n/**\n * Shallow clone an object\n *\n * @param object - The object to be cloned.\n * @returns A new object that copies the original.\n */\nfunction clone(object) {\n const newObject = create(null);\n for (const [property, value] of entries(object)) {\n const isPropertyExist = objectHasOwnProperty(object, property);\n if (isPropertyExist) {\n if (Array.isArray(value)) {\n newObject[property] = cleanArray(value);\n } else if (value && typeof value === 'object' && value.constructor === Object) {\n newObject[property] = clone(value);\n } else {\n newObject[property] = value;\n }\n }\n }\n return newObject;\n}\n/**\n * This method automatically checks if the prop is function or getter and behaves accordingly.\n *\n * @param object - The object to look up the getter function in its prototype chain.\n * @param prop - The property name for which to find the getter function.\n * @returns The getter function found in the prototype chain or a fallback function.\n */\nfunction lookupGetter(object, prop) {\n while (object !== null) {\n const desc = getOwnPropertyDescriptor(object, prop);\n if (desc) {\n if (desc.get) {\n return unapply(desc.get);\n }\n if (typeof desc.value === 'function') {\n return unapply(desc.value);\n }\n }\n object = getPrototypeOf(object);\n }\n function fallbackValue() {\n return null;\n }\n return fallbackValue;\n}\n\nconst html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'section', 'select', 'shadow', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);\nconst svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);\nconst svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);\n// List of SVG elements that are disallowed by default.\n// We still need to know them so that we can do namespace\n// checks properly in case one wants to add them to\n// allow-list.\nconst svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);\nconst mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);\n// Similarly to SVG, we want to know all MathML elements,\n// even those that we disallow by default.\nconst mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);\nconst text = freeze(['#text']);\n\nconst html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);\nconst svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);\nconst mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);\nconst xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);\n\n// eslint-disable-next-line unicorn/better-regex\nconst MUSTACHE_EXPR = seal(/\\{\\{[\\w\\W]*|[\\w\\W]*\\}\\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode\nconst ERB_EXPR = seal(/<%[\\w\\W]*|[\\w\\W]*%>/gm);\nconst TMPLIT_EXPR = seal(/\\$\\{[\\w\\W]*/gm); // eslint-disable-line unicorn/better-regex\nconst DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]+$/); // eslint-disable-line no-useless-escape\nconst ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\nconst IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\n);\nconst IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\nconst ATTR_WHITESPACE = seal(/[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\n);\nconst DOCTYPE_NAME = seal(/^html$/i);\nconst CUSTOM_ELEMENT = seal(/^[a-z][.\\w]*(-[.\\w]+)+$/i);\n\nvar EXPRESSIONS = /*#__PURE__*/Object.freeze({\n __proto__: null,\n ARIA_ATTR: ARIA_ATTR,\n ATTR_WHITESPACE: ATTR_WHITESPACE,\n CUSTOM_ELEMENT: CUSTOM_ELEMENT,\n DATA_ATTR: DATA_ATTR,\n DOCTYPE_NAME: DOCTYPE_NAME,\n ERB_EXPR: ERB_EXPR,\n IS_ALLOWED_URI: IS_ALLOWED_URI,\n IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,\n MUSTACHE_EXPR: MUSTACHE_EXPR,\n TMPLIT_EXPR: TMPLIT_EXPR\n});\n\n/* eslint-disable @typescript-eslint/indent */\n// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\nconst NODE_TYPE = {\n element: 1,\n attribute: 2,\n text: 3,\n cdataSection: 4,\n entityReference: 5,\n // Deprecated\n entityNode: 6,\n // Deprecated\n progressingInstruction: 7,\n comment: 8,\n document: 9,\n documentType: 10,\n documentFragment: 11,\n notation: 12 // Deprecated\n};\nconst getGlobal = function getGlobal() {\n return typeof window === 'undefined' ? null : window;\n};\n/**\n * Creates a no-op policy for internal use only.\n * Don't export this function outside this module!\n * @param trustedTypes The policy factory.\n * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).\n * @return The policy created (or null, if Trusted Types\n * are not supported or creating the policy failed).\n */\nconst _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {\n if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {\n return null;\n }\n // Allow the callers to control the unique policy name\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\n // Policy creation with duplicate names throws in Trusted Types.\n let suffix = null;\n const ATTR_NAME = 'data-tt-policy-suffix';\n if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {\n suffix = purifyHostElement.getAttribute(ATTR_NAME);\n }\n const policyName = 'dompurify' + (suffix ? '#' + suffix : '');\n try {\n return trustedTypes.createPolicy(policyName, {\n createHTML(html) {\n return html;\n },\n createScriptURL(scriptUrl) {\n return scriptUrl;\n }\n });\n } catch (_) {\n // Policy creation failed (most likely another DOMPurify script has\n // already run). Skip creating the policy, as this will only cause errors\n // if TT are enforced.\n console.warn('TrustedTypes policy ' + policyName + ' could not be created.');\n return null;\n }\n};\nconst _createHooksMap = function _createHooksMap() {\n return {\n afterSanitizeAttributes: [],\n afterSanitizeElements: [],\n afterSanitizeShadowDOM: [],\n beforeSanitizeAttributes: [],\n beforeSanitizeElements: [],\n beforeSanitizeShadowDOM: [],\n uponSanitizeAttribute: [],\n uponSanitizeElement: [],\n uponSanitizeShadowNode: []\n };\n};\nfunction createDOMPurify() {\n let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();\n const DOMPurify = root => createDOMPurify(root);\n DOMPurify.version = '3.2.6';\n DOMPurify.removed = [];\n if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {\n // Not running in a browser, provide a factory function\n // so that you can pass your own Window\n DOMPurify.isSupported = false;\n return DOMPurify;\n }\n let {\n document\n } = window;\n const originalDocument = document;\n const currentScript = originalDocument.currentScript;\n const {\n DocumentFragment,\n HTMLTemplateElement,\n Node,\n Element,\n NodeFilter,\n NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,\n HTMLFormElement,\n DOMParser,\n trustedTypes\n } = window;\n const ElementPrototype = Element.prototype;\n const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');\n const remove = lookupGetter(ElementPrototype, 'remove');\n const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');\n const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');\n const getParentNode = lookupGetter(ElementPrototype, 'parentNode');\n // As per issue #47, the web-components registry is inherited by a\n // new document created via createHTMLDocument. As per the spec\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\n // a new empty registry is used when creating a template contents owner\n // document, so we use that as our parent document to ensure nothing\n // is inherited.\n if (typeof HTMLTemplateElement === 'function') {\n const template = document.createElement('template');\n if (template.content && template.content.ownerDocument) {\n document = template.content.ownerDocument;\n }\n }\n let trustedTypesPolicy;\n let emptyHTML = '';\n const {\n implementation,\n createNodeIterator,\n createDocumentFragment,\n getElementsByTagName\n } = document;\n const {\n importNode\n } = originalDocument;\n let hooks = _createHooksMap();\n /**\n * Expose whether this browser supports running the full DOMPurify.\n */\n DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;\n const {\n MUSTACHE_EXPR,\n ERB_EXPR,\n TMPLIT_EXPR,\n DATA_ATTR,\n ARIA_ATTR,\n IS_SCRIPT_OR_DATA,\n ATTR_WHITESPACE,\n CUSTOM_ELEMENT\n } = EXPRESSIONS;\n let {\n IS_ALLOWED_URI: IS_ALLOWED_URI$1\n } = EXPRESSIONS;\n /**\n * We consider the elements and attributes below to be safe. Ideally\n * don't add any new ones but feel free to remove unwanted ones.\n */\n /* allowed element names */\n let ALLOWED_TAGS = null;\n const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);\n /* Allowed attribute names */\n let ALLOWED_ATTR = null;\n const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);\n /*\n * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.\n * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)\n * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)\n * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.\n */\n let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {\n tagNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n attributeNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n allowCustomizedBuiltInElements: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: false\n }\n }));\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\n let FORBID_TAGS = null;\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\n let FORBID_ATTR = null;\n /* Decide if ARIA attributes are okay */\n let ALLOW_ARIA_ATTR = true;\n /* Decide if custom data attributes are okay */\n let ALLOW_DATA_ATTR = true;\n /* Decide if unknown protocols are okay */\n let ALLOW_UNKNOWN_PROTOCOLS = false;\n /* Decide if self-closing tags in attributes are allowed.\n * Usually removed due to a mXSS issue in jQuery 3.0 */\n let ALLOW_SELF_CLOSE_IN_ATTR = true;\n /* Output should be safe for common template engines.\n * This means, DOMPurify removes data attributes, mustaches and ERB\n */\n let SAFE_FOR_TEMPLATES = false;\n /* Output should be safe even for XML used within HTML and alike.\n * This means, DOMPurify removes comments when containing risky content.\n */\n let SAFE_FOR_XML = true;\n /* Decide if document with ... should be returned */\n let WHOLE_DOCUMENT = false;\n /* Track whether config is already set on this instance of DOMPurify. */\n let SET_CONFIG = false;\n /* Decide if all elements (e.g. style, script) must be children of\n * document.body. By default, browsers might move them to document.head */\n let FORCE_BODY = false;\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported).\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\n */\n let RETURN_DOM = false;\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported) */\n let RETURN_DOM_FRAGMENT = false;\n /* Try to return a Trusted Type object instead of a string, return a string in\n * case Trusted Types are not supported */\n let RETURN_TRUSTED_TYPE = false;\n /* Output should be free from DOM clobbering attacks?\n * This sanitizes markups named with colliding, clobberable built-in DOM APIs.\n */\n let SANITIZE_DOM = true;\n /* Achieve full DOM Clobbering protection by isolating the namespace of named\n * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.\n *\n * HTML/DOM spec rules that enable DOM Clobbering:\n * - Named Access on Window (§7.3.3)\n * - DOM Tree Accessors (§3.1.5)\n * - Form Element Parent-Child Relations (§4.10.3)\n * - Iframe srcdoc / Nested WindowProxies (§4.8.5)\n * - HTMLCollection (§4.2.10.2)\n *\n * Namespace isolation is implemented by prefixing `id` and `name` attributes\n * with a constant string, i.e., `user-content-`\n */\n let SANITIZE_NAMED_PROPS = false;\n const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';\n /* Keep element content when removing element? */\n let KEEP_CONTENT = true;\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\n * of importing it into a new Document and returning a sanitized copy */\n let IN_PLACE = false;\n /* Allow usage of profiles like html, svg and mathMl */\n let USE_PROFILES = {};\n /* Tags to ignore content of when KEEP_CONTENT is true */\n let FORBID_CONTENTS = null;\n const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);\n /* Tags that are safe for data: URIs */\n let DATA_URI_TAGS = null;\n const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);\n /* Attributes safe for values like \"javascript:\" */\n let URI_SAFE_ATTRIBUTES = null;\n const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);\n const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';\n const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';\n /* Document namespace */\n let NAMESPACE = HTML_NAMESPACE;\n let IS_EMPTY_INPUT = false;\n /* Allowed XHTML+XML namespaces */\n let ALLOWED_NAMESPACES = null;\n const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);\n let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);\n let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);\n // Certain elements are allowed in both SVG and HTML\n // namespace. We need to specify them explicitly\n // so that they don't get erroneously deleted from\n // HTML namespace.\n const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);\n /* Parsing of strict XHTML documents */\n let PARSER_MEDIA_TYPE = null;\n const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];\n const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';\n let transformCaseFunc = null;\n /* Keep a reference to config to pass to hooks */\n let CONFIG = null;\n /* Ideally, do not touch anything below this line */\n /* ______________________________________________ */\n const formElement = document.createElement('form');\n const isRegexOrFunction = function isRegexOrFunction(testValue) {\n return testValue instanceof RegExp || testValue instanceof Function;\n };\n /**\n * _parseConfig\n *\n * @param cfg optional config literal\n */\n // eslint-disable-next-line complexity\n const _parseConfig = function _parseConfig() {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n if (CONFIG && CONFIG === cfg) {\n return;\n }\n /* Shield configuration object from tampering */\n if (!cfg || typeof cfg !== 'object') {\n cfg = {};\n }\n /* Shield configuration object from prototype pollution */\n cfg = clone(cfg);\n PARSER_MEDIA_TYPE =\n // eslint-disable-next-line unicorn/prefer-includes\n SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;\n // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.\n transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;\n /* Set configuration parameters */\n ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;\n ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;\n ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;\n URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;\n DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;\n FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;\n FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});\n FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});\n USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;\n ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true\n ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true\n ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false\n ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true\n SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false\n SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true\n WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false\n RETURN_DOM = cfg.RETURN_DOM || false; // Default false\n RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false\n RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false\n FORCE_BODY = cfg.FORCE_BODY || false; // Default false\n SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true\n SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false\n KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true\n IN_PLACE = cfg.IN_PLACE || false; // Default false\n IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;\n NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;\n MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;\n HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;\n CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {\n CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;\n }\n if (SAFE_FOR_TEMPLATES) {\n ALLOW_DATA_ATTR = false;\n }\n if (RETURN_DOM_FRAGMENT) {\n RETURN_DOM = true;\n }\n /* Parse profile info */\n if (USE_PROFILES) {\n ALLOWED_TAGS = addToSet({}, text);\n ALLOWED_ATTR = [];\n if (USE_PROFILES.html === true) {\n addToSet(ALLOWED_TAGS, html$1);\n addToSet(ALLOWED_ATTR, html);\n }\n if (USE_PROFILES.svg === true) {\n addToSet(ALLOWED_TAGS, svg$1);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.svgFilters === true) {\n addToSet(ALLOWED_TAGS, svgFilters);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.mathMl === true) {\n addToSet(ALLOWED_TAGS, mathMl$1);\n addToSet(ALLOWED_ATTR, mathMl);\n addToSet(ALLOWED_ATTR, xml);\n }\n }\n /* Merge configuration parameters */\n if (cfg.ADD_TAGS) {\n if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {\n ALLOWED_TAGS = clone(ALLOWED_TAGS);\n }\n addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);\n }\n if (cfg.ADD_ATTR) {\n if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {\n ALLOWED_ATTR = clone(ALLOWED_ATTR);\n }\n addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);\n }\n if (cfg.ADD_URI_SAFE_ATTR) {\n addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);\n }\n if (cfg.FORBID_CONTENTS) {\n if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {\n FORBID_CONTENTS = clone(FORBID_CONTENTS);\n }\n addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);\n }\n /* Add #text in case KEEP_CONTENT is set to true */\n if (KEEP_CONTENT) {\n ALLOWED_TAGS['#text'] = true;\n }\n /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */\n if (WHOLE_DOCUMENT) {\n addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);\n }\n /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */\n if (ALLOWED_TAGS.table) {\n addToSet(ALLOWED_TAGS, ['tbody']);\n delete FORBID_TAGS.tbody;\n }\n if (cfg.TRUSTED_TYPES_POLICY) {\n if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.');\n }\n if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.');\n }\n // Overwrite existing TrustedTypes policy.\n trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;\n // Sign local variables required by `sanitize`.\n emptyHTML = trustedTypesPolicy.createHTML('');\n } else {\n // Uninitialized policy, attempt to initialize the internal dompurify policy.\n if (trustedTypesPolicy === undefined) {\n trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);\n }\n // If creating the internal policy succeeded sign internal variables.\n if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {\n emptyHTML = trustedTypesPolicy.createHTML('');\n }\n }\n // Prevent further manipulation of configuration.\n // Not available in IE8, Safari 5, etc.\n if (freeze) {\n freeze(cfg);\n }\n CONFIG = cfg;\n };\n /* Keep track of all possible SVG and MathML tags\n * so that we can perform the namespace checks\n * correctly. */\n const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);\n const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);\n /**\n * @param element a DOM element whose namespace is being checked\n * @returns Return false if the element has a\n * namespace that a spec-compliant parser would never\n * return. Return true otherwise.\n */\n const _checkValidNamespace = function _checkValidNamespace(element) {\n let parent = getParentNode(element);\n // In JSDOM, if we're inside shadow DOM, then parentNode\n // can be null. We just simulate parent in this case.\n if (!parent || !parent.tagName) {\n parent = {\n namespaceURI: NAMESPACE,\n tagName: 'template'\n };\n }\n const tagName = stringToLowerCase(element.tagName);\n const parentTagName = stringToLowerCase(parent.tagName);\n if (!ALLOWED_NAMESPACES[element.namespaceURI]) {\n return false;\n }\n if (element.namespaceURI === SVG_NAMESPACE) {\n // The only way to switch from HTML namespace to SVG\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'svg';\n }\n // The only way to switch from MathML to SVG is via`\n // svg if parent is either or MathML\n // text integration points.\n if (parent.namespaceURI === MATHML_NAMESPACE) {\n return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);\n }\n // We only allow elements that are defined in SVG\n // spec. All others are disallowed in SVG namespace.\n return Boolean(ALL_SVG_TAGS[tagName]);\n }\n if (element.namespaceURI === MATHML_NAMESPACE) {\n // The only way to switch from HTML namespace to MathML\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'math';\n }\n // The only way to switch from SVG to MathML is via\n // and HTML integration points\n if (parent.namespaceURI === SVG_NAMESPACE) {\n return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];\n }\n // We only allow elements that are defined in MathML\n // spec. All others are disallowed in MathML namespace.\n return Boolean(ALL_MATHML_TAGS[tagName]);\n }\n if (element.namespaceURI === HTML_NAMESPACE) {\n // The only way to switch from SVG to HTML is via\n // HTML integration points, and from MathML to HTML\n // is via MathML text integration points\n if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n // We disallow tags that are specific for MathML\n // or SVG and should never appear in HTML namespace\n return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);\n }\n // For XHTML and XML documents that support custom namespaces\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {\n return true;\n }\n // The code should never reach this place (this means\n // that the element somehow got namespace that is not\n // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).\n // Return false just in case.\n return false;\n };\n /**\n * _forceRemove\n *\n * @param node a DOM node\n */\n const _forceRemove = function _forceRemove(node) {\n arrayPush(DOMPurify.removed, {\n element: node\n });\n try {\n // eslint-disable-next-line unicorn/prefer-dom-node-remove\n getParentNode(node).removeChild(node);\n } catch (_) {\n remove(node);\n }\n };\n /**\n * _removeAttribute\n *\n * @param name an Attribute name\n * @param element a DOM node\n */\n const _removeAttribute = function _removeAttribute(name, element) {\n try {\n arrayPush(DOMPurify.removed, {\n attribute: element.getAttributeNode(name),\n from: element\n });\n } catch (_) {\n arrayPush(DOMPurify.removed, {\n attribute: null,\n from: element\n });\n }\n element.removeAttribute(name);\n // We void attribute values for unremovable \"is\" attributes\n if (name === 'is') {\n if (RETURN_DOM || RETURN_DOM_FRAGMENT) {\n try {\n _forceRemove(element);\n } catch (_) {}\n } else {\n try {\n element.setAttribute(name, '');\n } catch (_) {}\n }\n }\n };\n /**\n * _initDocument\n *\n * @param dirty - a string of dirty markup\n * @return a DOM, filled with the dirty markup\n */\n const _initDocument = function _initDocument(dirty) {\n /* Create a HTML document */\n let doc = null;\n let leadingWhitespace = null;\n if (FORCE_BODY) {\n dirty = '' + dirty;\n } else {\n /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */\n const matches = stringMatch(dirty, /^[\\r\\n\\t ]+/);\n leadingWhitespace = matches && matches[0];\n }\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {\n // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)\n dirty = '' + dirty + '';\n }\n const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;\n /*\n * Use the DOMParser API by default, fallback later if needs be\n * DOMParser not work for svg when has multiple root element.\n */\n if (NAMESPACE === HTML_NAMESPACE) {\n try {\n doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);\n } catch (_) {}\n }\n /* Use createHTMLDocument in case DOMParser is not available */\n if (!doc || !doc.documentElement) {\n doc = implementation.createDocument(NAMESPACE, 'template', null);\n try {\n doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;\n } catch (_) {\n // Syntax error if dirtyPayload is invalid xml\n }\n }\n const body = doc.body || doc.documentElement;\n if (dirty && leadingWhitespace) {\n body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);\n }\n /* Work on whole document or just its body */\n if (NAMESPACE === HTML_NAMESPACE) {\n return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];\n }\n return WHOLE_DOCUMENT ? doc.documentElement : body;\n };\n /**\n * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.\n *\n * @param root The root element or node to start traversing on.\n * @return The created NodeIterator\n */\n const _createNodeIterator = function _createNodeIterator(root) {\n return createNodeIterator.call(root.ownerDocument || root, root,\n // eslint-disable-next-line no-bitwise\n NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);\n };\n /**\n * _isClobbered\n *\n * @param element element to check for clobbering attacks\n * @return true if clobbered, false if safe\n */\n const _isClobbered = function _isClobbered(element) {\n return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');\n };\n /**\n * Checks whether the given object is a DOM node.\n *\n * @param value object to check whether it's a DOM node\n * @return true is object is a DOM node\n */\n const _isNode = function _isNode(value) {\n return typeof Node === 'function' && value instanceof Node;\n };\n function _executeHooks(hooks, currentNode, data) {\n arrayForEach(hooks, hook => {\n hook.call(DOMPurify, currentNode, data, CONFIG);\n });\n }\n /**\n * _sanitizeElements\n *\n * @protect nodeName\n * @protect textContent\n * @protect removeChild\n * @param currentNode to check for permission to exist\n * @return true if node was killed, false if left alive\n */\n const _sanitizeElements = function _sanitizeElements(currentNode) {\n let content = null;\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeElements, currentNode, null);\n /* Check if element is clobbered or can clobber */\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Now let's check the element's type and name */\n const tagName = transformCaseFunc(currentNode.nodeName);\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeElement, currentNode, {\n tagName,\n allowedTags: ALLOWED_TAGS\n });\n /* Detect mXSS attempts abusing namespace confusion */\n if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\\w!]/g, currentNode.textContent)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any occurrence of processing instructions */\n if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any kind of possibly harmful comments */\n if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\\w]/g, currentNode.data)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove element if anything forbids its presence */\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n /* Check if we have a custom element to handle */\n if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {\n return false;\n }\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {\n return false;\n }\n }\n /* Keep content except for bad-listed elements */\n if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {\n const parentNode = getParentNode(currentNode) || currentNode.parentNode;\n const childNodes = getChildNodes(currentNode) || currentNode.childNodes;\n if (childNodes && parentNode) {\n const childCount = childNodes.length;\n for (let i = childCount - 1; i >= 0; --i) {\n const childClone = cloneNode(childNodes[i], true);\n childClone.__removalCount = (currentNode.__removalCount || 0) + 1;\n parentNode.insertBefore(childClone, getNextSibling(currentNode));\n }\n }\n }\n _forceRemove(currentNode);\n return true;\n }\n /* Check whether element has a valid namespace */\n if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Make sure that older browsers don't get fallback-tag mXSS */\n if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\\/no(script|embed|frames)/i, currentNode.innerHTML)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Sanitize element content to be template-safe */\n if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {\n /* Get the element's text content */\n content = currentNode.textContent;\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n content = stringReplace(content, expr, ' ');\n });\n if (currentNode.textContent !== content) {\n arrayPush(DOMPurify.removed, {\n element: currentNode.cloneNode()\n });\n currentNode.textContent = content;\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeElements, currentNode, null);\n return false;\n };\n /**\n * _isValidAttribute\n *\n * @param lcTag Lowercase tag name of containing element.\n * @param lcName Lowercase attribute name.\n * @param value Attribute value.\n * @return Returns true if `value` is valid, otherwise false.\n */\n // eslint-disable-next-line complexity\n const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {\n /* Make sure attribute cannot clobber */\n if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {\n return false;\n }\n /* Allow valid data-* attributes: At least one character after \"-\"\n (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)\n XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)\n We don't need to check the value; it's always URI safe. */\n if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {\n if (\n // First condition does a very basic check if a) it's basically a valid custom element tagname AND\n // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck\n _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName)) ||\n // Alternative, second condition checks if it's an `is`-attribute, AND\n // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {\n return false;\n }\n /* Check value is safe. First, is attr inert? If so, is safe */\n } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {\n return false;\n } else ;\n return true;\n };\n /**\n * _isBasicCustomElement\n * checks if at least one dash is included in tagName, and it's not the first char\n * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name\n *\n * @param tagName name of the tag of the node to sanitize\n * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.\n */\n const _isBasicCustomElement = function _isBasicCustomElement(tagName) {\n return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);\n };\n /**\n * _sanitizeAttributes\n *\n * @protect attributes\n * @protect nodeName\n * @protect removeAttribute\n * @protect setAttribute\n *\n * @param currentNode to sanitize\n */\n const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);\n const {\n attributes\n } = currentNode;\n /* Check if we have attributes; if not we might have a text node */\n if (!attributes || _isClobbered(currentNode)) {\n return;\n }\n const hookEvent = {\n attrName: '',\n attrValue: '',\n keepAttr: true,\n allowedAttributes: ALLOWED_ATTR,\n forceKeepAttr: undefined\n };\n let l = attributes.length;\n /* Go backwards over all attributes; safely remove bad ones */\n while (l--) {\n const attr = attributes[l];\n const {\n name,\n namespaceURI,\n value: attrValue\n } = attr;\n const lcName = transformCaseFunc(name);\n const initValue = attrValue;\n let value = name === 'value' ? initValue : stringTrim(initValue);\n /* Execute a hook if present */\n hookEvent.attrName = lcName;\n hookEvent.attrValue = value;\n hookEvent.keepAttr = true;\n hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set\n _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);\n value = hookEvent.attrValue;\n /* Full DOM Clobbering protection via namespace isolation,\n * Prefix id and name attributes with `user-content-`\n */\n if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {\n // Remove the attribute with this value\n _removeAttribute(name, currentNode);\n // Prefix the value and later re-create the attribute with the sanitized value\n value = SANITIZE_NAMED_PROPS_PREFIX + value;\n }\n /* Work around a security issue with comments inside attributes */\n if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\\/(style|title)/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (hookEvent.forceKeepAttr) {\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (!hookEvent.keepAttr) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Work around a security issue in jQuery 3.0 */\n if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\\/>/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Sanitize attribute content to be template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n value = stringReplace(value, expr, ' ');\n });\n }\n /* Is `value` valid for this attribute? */\n const lcTag = transformCaseFunc(currentNode.nodeName);\n if (!_isValidAttribute(lcTag, lcName, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Handle attributes that require Trusted Types */\n if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {\n if (namespaceURI) ; else {\n switch (trustedTypes.getAttributeType(lcTag, lcName)) {\n case 'TrustedHTML':\n {\n value = trustedTypesPolicy.createHTML(value);\n break;\n }\n case 'TrustedScriptURL':\n {\n value = trustedTypesPolicy.createScriptURL(value);\n break;\n }\n }\n }\n }\n /* Handle invalid data-* attribute set by try-catching it */\n if (value !== initValue) {\n try {\n if (namespaceURI) {\n currentNode.setAttributeNS(namespaceURI, name, value);\n } else {\n /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. \"x-schema\". */\n currentNode.setAttribute(name, value);\n }\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n } else {\n arrayPop(DOMPurify.removed);\n }\n } catch (_) {\n _removeAttribute(name, currentNode);\n }\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);\n };\n /**\n * _sanitizeShadowDOM\n *\n * @param fragment to iterate over recursively\n */\n const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {\n let shadowNode = null;\n const shadowIterator = _createNodeIterator(fragment);\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);\n while (shadowNode = shadowIterator.nextNode()) {\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);\n /* Sanitize tags and elements */\n _sanitizeElements(shadowNode);\n /* Check attributes next */\n _sanitizeAttributes(shadowNode);\n /* Deep shadow DOM detected */\n if (shadowNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(shadowNode.content);\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);\n };\n // eslint-disable-next-line complexity\n DOMPurify.sanitize = function (dirty) {\n let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let body = null;\n let importedNode = null;\n let currentNode = null;\n let returnNode = null;\n /* Make sure we have a string to sanitize.\n DO NOT return early, as this will return the wrong type if\n the user has requested a DOM object rather than a string */\n IS_EMPTY_INPUT = !dirty;\n if (IS_EMPTY_INPUT) {\n dirty = '';\n }\n /* Stringify, in case dirty is an object */\n if (typeof dirty !== 'string' && !_isNode(dirty)) {\n if (typeof dirty.toString === 'function') {\n dirty = dirty.toString();\n if (typeof dirty !== 'string') {\n throw typeErrorCreate('dirty is not a string, aborting');\n }\n } else {\n throw typeErrorCreate('toString is not a function');\n }\n }\n /* Return dirty HTML if DOMPurify cannot run */\n if (!DOMPurify.isSupported) {\n return dirty;\n }\n /* Assign config vars */\n if (!SET_CONFIG) {\n _parseConfig(cfg);\n }\n /* Clean up removed elements */\n DOMPurify.removed = [];\n /* Check if dirty is correctly typed for IN_PLACE */\n if (typeof dirty === 'string') {\n IN_PLACE = false;\n }\n if (IN_PLACE) {\n /* Do some early pre-sanitization to avoid unsafe root nodes */\n if (dirty.nodeName) {\n const tagName = transformCaseFunc(dirty.nodeName);\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');\n }\n }\n } else if (dirty instanceof Node) {\n /* If dirty is a DOM element, append to an empty document to avoid\n elements being stripped by the parser */\n body = _initDocument('');\n importedNode = body.ownerDocument.importNode(dirty, true);\n if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {\n /* Node is already a body, use as is */\n body = importedNode;\n } else if (importedNode.nodeName === 'HTML') {\n body = importedNode;\n } else {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n body.appendChild(importedNode);\n }\n } else {\n /* Exit directly if we have nothing to do */\n if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&\n // eslint-disable-next-line unicorn/prefer-includes\n dirty.indexOf('<') === -1) {\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;\n }\n /* Initialize the document to work on */\n body = _initDocument(dirty);\n /* Check we have a DOM node from the data */\n if (!body) {\n return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';\n }\n }\n /* Remove first element node (ours) if FORCE_BODY is set */\n if (body && FORCE_BODY) {\n _forceRemove(body.firstChild);\n }\n /* Get node iterator */\n const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);\n /* Now start iterating over the created document */\n while (currentNode = nodeIterator.nextNode()) {\n /* Sanitize tags and elements */\n _sanitizeElements(currentNode);\n /* Check attributes next */\n _sanitizeAttributes(currentNode);\n /* Shadow DOM detected, sanitize it */\n if (currentNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(currentNode.content);\n }\n }\n /* If we sanitized `dirty` in-place, return it. */\n if (IN_PLACE) {\n return dirty;\n }\n /* Return sanitized string or DOM */\n if (RETURN_DOM) {\n if (RETURN_DOM_FRAGMENT) {\n returnNode = createDocumentFragment.call(body.ownerDocument);\n while (body.firstChild) {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n returnNode.appendChild(body.firstChild);\n }\n } else {\n returnNode = body;\n }\n if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {\n /*\n AdoptNode() is not used because internal state is not reset\n (e.g. the past names map of a HTMLFormElement), this is safe\n in theory but we would rather not risk another attack vector.\n The state that is cloned by importNode() is explicitly defined\n by the specs.\n */\n returnNode = importNode.call(originalDocument, returnNode, true);\n }\n return returnNode;\n }\n let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;\n /* Serialize doctype if allowed */\n if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {\n serializedHTML = '\\n' + serializedHTML;\n }\n /* Sanitize final string template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n serializedHTML = stringReplace(serializedHTML, expr, ' ');\n });\n }\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;\n };\n DOMPurify.setConfig = function () {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n _parseConfig(cfg);\n SET_CONFIG = true;\n };\n DOMPurify.clearConfig = function () {\n CONFIG = null;\n SET_CONFIG = false;\n };\n DOMPurify.isValidAttribute = function (tag, attr, value) {\n /* Initialize shared config vars if necessary. */\n if (!CONFIG) {\n _parseConfig({});\n }\n const lcTag = transformCaseFunc(tag);\n const lcName = transformCaseFunc(attr);\n return _isValidAttribute(lcTag, lcName, value);\n };\n DOMPurify.addHook = function (entryPoint, hookFunction) {\n if (typeof hookFunction !== 'function') {\n return;\n }\n arrayPush(hooks[entryPoint], hookFunction);\n };\n DOMPurify.removeHook = function (entryPoint, hookFunction) {\n if (hookFunction !== undefined) {\n const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);\n return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];\n }\n return arrayPop(hooks[entryPoint]);\n };\n DOMPurify.removeHooks = function (entryPoint) {\n hooks[entryPoint] = [];\n };\n DOMPurify.removeAllHooks = function () {\n hooks = _createHooksMap();\n };\n return DOMPurify;\n}\nvar purify = createDOMPurify();\n\nexport { purify as default };\n//# sourceMappingURL=purify.es.mjs.map\n","/**\n * This class represents all the constants needed in a MathType integration among different classes.\n * If a constant should be used across different classes should be defined using attribute\n * accessors.\n */\nexport default class Constants {\n /**\n * Safe XML entities.\n * @type {Object}\n */\n static get safeXmlCharactersEntities() {\n return {\n tagOpener: \"«\",\n tagCloser: \"»\",\n doubleQuote: \"¨\",\n realDoubleQuote: \""\",\n };\n }\n\n /**\n * Blackboard invalid safe characters.\n * @type {Object}\n */\n static get safeBadBlackboardCharacters() {\n return {\n ltElement: \"«mo»<«/mo»\",\n gtElement: \"«mo»>«/mo»\",\n ampElement: \"«mo»&«/mo»\",\n };\n }\n\n /**\n * Blackboard valid safe characters.\n * @type{Object}\n */\n static get safeGoodBlackboardCharacters() {\n return {\n ltElement: \"«mo»§lt;«/mo»\",\n gtElement: \"«mo»§gt;«/mo»\",\n ampElement: \"«mo»§amp;«/mo»\",\n };\n }\n\n /**\n * Standard XML special characters.\n * @type {Object}\n */\n static get xmlCharacters() {\n return {\n id: \"xmlCharacters\",\n tagOpener: \"<\", // Hex: \\x3C.\n tagCloser: \">\", // Hex: \\x3E.\n doubleQuote: '\"', // Hex: \\x22.\n ampersand: \"&\", // Hex: \\x26.\n quote: \"'\", // Hex: \\x27.\n };\n }\n\n /**\n * Safe XML special characters. This characters are used instead the standard\n * the standard to parse the MathML if safeXML save mode is enable. Each XML\n * special character have a UTF-8 representation.\n * @type {Object}\n */\n static get safeXmlCharacters() {\n return {\n id: \"safeXmlCharacters\",\n tagOpener: \"«\", // Hex: \\xAB.\n tagCloser: \"»\", // Hex: \\xBB.\n doubleQuote: \"¨\", // Hex: \\xA8.\n ampersand: \"§\", // Hex: \\xA7.\n quote: \"`\", // Hex: \\x60.\n realDoubleQuote: \"¨\",\n };\n }\n}\n","import Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a class to manage MathML objects.\n */\nexport default class MathML {\n /**\n * Checks if the mathml at position i is inside an HTML attribute or not.\n * @param {string} content - a string containing MathML code.\n * @param {number} i - search index.\n * @return {boolean} true if is inside an HTML attribute. false otherwise.\n */\n static isMathmlInAttribute(content, i) {\n // Regex =\n // '^[\\'\"][\\\\s]*=[\\\\s]*[\\\\w-]+([\\\\s]*(\"[^\"]*\"|\\'[^\\']*\\')[\\\\s]*\n // =[\\\\s]*[\\\\w-]+[\\\\s]*)*[\\\\s]+gmi<';\n const mathAtt = \"['\\\"][\\\\s]*=[\\\\s]*[\\\\w-]+\"; // \"=att OR '=att\n const attContent = \"\\\"[^\\\"]*\\\"|'[^']*'\"; // \"blabla\" OR 'blabla'\n const att = `[\\\\s]*(${attContent})[\\\\s]*=[\\\\s]*[\\\\w-]+[\\\\s]*`; // \"blabla\"=att OR 'blabla'=att\n const atts = `('${att}')*`; // \"blabla\"=att1 \"blabla\"=att2\n const regex = `^${mathAtt}${atts}[\\\\s]+gmi<`; // \"=att \"blabla\"=att1 \"blabla\"=att2 gmi< .\n const expression = new RegExp(regex);\n\n const actualContent = content.substring(0, i);\n const reversed = actualContent.split(\"\").reverse().join(\"\");\n const exists = expression.test(reversed);\n\n return exists;\n }\n\n /**\n * Decodes an encoded MathML with standard XML tags.\n * We use these entities because IE doesn't support html entities\n * on its attributes sometimes. Yes, sometimes.\n * @param {string} input - string to be decoded.\n * @return {string} decoded string.\n */\n static safeXmlDecode(input) {\n let { tagOpener } = Constants.safeXmlCharactersEntities;\n let { tagCloser } = Constants.safeXmlCharactersEntities;\n let { doubleQuote } = Constants.safeXmlCharactersEntities;\n let { realDoubleQuote } = Constants.safeXmlCharactersEntities;\n // Decoding entities.\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n // Added to fix problem due to import from 1.9.x.\n input = input.split(realDoubleQuote).join(Constants.safeXmlCharacters.realDoubleQuote);\n\n // Blackboard.\n const { ltElement } = Constants.safeBadBlackboardCharacters;\n const { gtElement } = Constants.safeBadBlackboardCharacters;\n const { ampElement } = Constants.safeBadBlackboardCharacters;\n if (\"_wrs_blackboard\" in window && window._wrs_blackboard) {\n input = input.split(ltElement).join(Constants.safeGoodBlackboardCharacters.ltElement);\n input = input.split(gtElement).join(Constants.safeGoodBlackboardCharacters.gtElement);\n input = input.split(ampElement).join(Constants.safeGoodBlackboardCharacters.ampElement);\n }\n\n ({ tagOpener } = Constants.safeXmlCharacters);\n ({ tagCloser } = Constants.safeXmlCharacters);\n ({ doubleQuote } = Constants.safeXmlCharacters);\n ({ realDoubleQuote } = Constants.safeXmlCharacters);\n const { ampersand } = Constants.safeXmlCharacters;\n const { quote } = Constants.safeXmlCharacters;\n\n // Decoding characters.\n input = input.split(tagOpener).join(Constants.xmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.xmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.xmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.xmlCharacters.ampersand);\n input = input.split(quote).join(Constants.xmlCharacters.quote);\n\n // We are replacing $ by & when its part of an entity for retro-compatibility.\n // Now, the standard is replace § by &.\n let returnValue = \"\";\n let currentEntity = null;\n\n for (let i = 0; i < input.length; i += 1) {\n const character = input.charAt(i);\n if (currentEntity == null) {\n if (character === \"$\") {\n currentEntity = \"\";\n } else {\n returnValue += character;\n }\n } else if (character === \";\") {\n returnValue += `&${currentEntity}`;\n currentEntity = null;\n } else if (character.match(/([a-zA-Z0-9#._-] | '-')/)) {\n // Character is part of an entity.\n currentEntity += character;\n } else {\n returnValue += `$${currentEntity}`; // Is not an entity.\n currentEntity = null;\n i -= 1; // Parse again the current character.\n }\n }\n\n return returnValue;\n }\n\n /**\n * Encodes a MathML with standard XML tags to a MMathML encoded with safe XML tags.\n * We use these entities because IE doesn't support html entities on its attributes sometimes.\n * @param {string} input - input string to be encoded\n * @returns {string} encoded string.\n */\n static safeXmlEncode(input) {\n const { tagOpener } = Constants.xmlCharacters;\n const { tagCloser } = Constants.xmlCharacters;\n const { doubleQuote } = Constants.xmlCharacters;\n const { ampersand } = Constants.xmlCharacters;\n const { quote } = Constants.xmlCharacters;\n\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.safeXmlCharacters.ampersand);\n input = input.split(quote).join(Constants.safeXmlCharacters.quote);\n\n return input;\n }\n\n /**\n * Converts special symbols (> 128) to entities and replaces all textual\n * entities by its number entities.\n * @param {string} mathml - MathML string containing - or not - special symbols\n * @returns {string} MathML with all textual entities replaced.\n */\n static mathMLEntities(mathml) {\n let toReturn = \"\";\n\n for (let i = 0; i < mathml.length; i += 1) {\n const character = mathml.charAt(i);\n\n // Parsing > 128 characters.\n if (mathml.codePointAt(i) > 128) {\n toReturn += `&#${mathml.codePointAt(i)};`;\n // For UTF-32 characters we need to move the index one position.\n if (mathml.codePointAt(i) > 0xffff) {\n i += 1;\n }\n } else if (character === \"&\") {\n const end = mathml.indexOf(\";\", i + 1);\n if (end >= 0) {\n const container = document.createElement(\"span\");\n container.innerHTML = mathml.substring(i, end + 1);\n toReturn += `&#${Util.fixedCharCodeAt(container.textContent || container.innerText, 0)};`;\n i = end;\n } else {\n toReturn += character;\n }\n } else {\n toReturn += character;\n }\n }\n\n return toReturn;\n }\n\n /**\n * Add a custom editor name with the prefix wrs_ to a MathML class attribute.\n * @param {string} mathml - a MathML string created with a custom editor, like chemistry.\n * @param {string} customEditor - custom editor name.\n * @returns {string} MathML string with his class containing the editor toolbar string.\n */\n static addCustomEditorClassAttribute(mathml, customEditor) {\n let toReturn = \"\";\n\n const start = mathml.indexOf(\"\");\n if (mathml.indexOf(\"class\") === -1) {\n // Adding custom editor type.\n toReturn = `${mathml.substr(start, end)} class=\"wrs_${customEditor}\">`;\n toReturn += mathml.substr(end + 1, mathml.length);\n return toReturn;\n }\n }\n return mathml;\n }\n\n /**\n * Remove a custom editor name from the MathML class attribute.\n * @param {string} mathml - a MathML string.\n * @param {string} customEditor - custom editor name.\n * @returns {string} The input MathML without customEditor name in his class.\n */\n static removeCustomEditorClassAttribute(mathml, customEditor) {\n // Discard MathML without the specified class.\n if (mathml.indexOf(\"class\") === -1 || mathml.indexOf(`wrs_${customEditor}`) === -1) {\n return mathml;\n }\n\n // Trivial case: class attribute value equal to editor name. Then\n // class attribute is removed.\n // First try to remove it with a space before if there is one\n // Otherwise without the space\n if (mathml.indexOf(` class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(` class=\"wrs_${customEditor}\"`, \"\");\n }\n if (mathml.indexOf(`class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(`class=\"wrs_${customEditor}\"`, \"\");\n }\n\n // Non Trivial case: class attribute contains editor name.\n return mathml.replace(`wrs_${customEditor}`, \"\");\n }\n\n /**\n * Adds annotation tag in MathML element.\n * @param {String} mathml - valid MathML.\n * @param {String} content - value to put inside annotation tag.\n * @param {String} annotationEncoding - annotation encoding.\n * @returns {String} - 'mathml' with an annotation that contains\n * 'content' and encoding 'encoding'.\n */\n static addAnnotation(mathml, content, annotationEncoding) {\n // If contains annotation, also contains semantics tag.\n const containsAnnotation = mathml.indexOf(\"\");\n mathmlWithAnnotation = `${mathml.substring(0, closeSemanticsIndex)}${content}${mathml.substring(closeSemanticsIndex)}`;\n } else if (MathML.isEmpty(mathml)) {\n const endIndexInline = mathml.indexOf(\"/>\");\n const endIndexNonInline = mathml.indexOf(\">\");\n const endIndex = endIndexNonInline === endIndexInline ? endIndexInline : endIndexNonInline;\n mathmlWithAnnotation = `${mathml.substring(0, endIndex)}>${content}`;\n } else {\n const beginMathMLContent = mathml.indexOf(\">\") + 1;\n const endMathmlContent = mathml.lastIndexOf(\"\");\n const mathmlContent = mathml.substring(beginMathMLContent, endMathmlContent);\n mathmlWithAnnotation = `${mathml.substring(0, beginMathMLContent)}${mathmlContent}${content}`; // eslint-disable-line max-len\n }\n\n return mathmlWithAnnotation;\n }\n\n /**\n * Removes specific annotation tag in MathML element.\n * In case of remove the unique annotation, also is removed semantics tag.\n * @param {String} mathml - valid MathML.\n * @param {String} annotationEncoding - annotation encoding to remove.\n * @returns {String} - 'mathml' without the annotation encoding specified.\n */\n static removeAnnotation(mathml, annotationEncoding) {\n let mathmlWithoutAnnotation = mathml;\n const openAnnotationTag = ``;\n const closeAnnotationTag = \"\";\n const startAnnotationIndex = mathml.indexOf(openAnnotationTag);\n if (startAnnotationIndex !== -1) {\n let differentAnnotationFound = false;\n let differentAnnotationIndex = mathml.indexOf(\"\\s*?()?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsEndingTagRegex = /(<\\/mrow>)?\\s*/gm;\n\n return mathml.replace(semanticsStartingTagRegex, \"\").replace(semanticsEndingTagRegex, \"\");\n }\n\n /**\n * Removes semantics tag to element that contains mathml.\n * When using Hand to create formulas, it adds the mrow tag due to the semantics one, this one is also removed.\n * @param {string} element - Inner HTML text string.\n * @returns {string} - 'mathml' without semantics tag.\n */\n static removeSafeXMLSemantics(element) {\n // If `mrow` is found right before the `semantics` starting tag, it's removed as well\n const semanticsSafeStartingTagRegex = /«semantics»\\s*?(«mrow»)?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsSafeEndingTagRegex = /(«\\/mrow»)?\\s*«annotation[\\W\\w]*?«\\/semantics»/gm;\n\n return element.replace(semanticsSafeStartingTagRegex, \"\").replace(semanticsSafeEndingTagRegex, \"\");\n }\n\n /**\n * Transforms all xml mathml occurrences that contain semantics to the same\n * xml mathml occurrences without semantics.\n * @param {string} text - string that can contain xml mathml occurrences.\n * @param {Constants} [characters] - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * xmlCharacters by default.\n * @returns {string} - 'text' with all xml mathml occurrences without annotation tag.\n */\n static removeSemanticsOcurrences(text, characters = Constants.xmlCharacters) {\n const mathTagStart = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const mathTagEndline = `/${characters.tagCloser}`;\n const { tagCloser } = characters;\n const semanticsTagStart = `${characters.tagOpener}semantics${characters.tagCloser}`;\n const annotationTagStart = `${characters.tagOpener}annotation encoding=`;\n\n let output = \"\";\n let start = text.indexOf(mathTagStart);\n let end = 0;\n while (start !== -1) {\n output += text.substring(end, start);\n\n // MathML can be written as '' or ''.\n const mathTagEndIndex = text.indexOf(mathTagEnd, start);\n const mathTagEndlineIndex = text.indexOf(mathTagEndline, start);\n const firstTagCloser = text.indexOf(tagCloser, start);\n if (mathTagEndIndex !== -1) {\n end = mathTagEndIndex;\n } else if (mathTagEndlineIndex === firstTagCloser - 1) {\n end = mathTagEndlineIndex;\n }\n\n const semanticsIndex = text.indexOf(semanticsTagStart, start);\n if (semanticsIndex !== -1) {\n const mmlTagStart = text.substring(start, semanticsIndex);\n const annotationIndex = text.indexOf(annotationTagStart, start);\n if (annotationIndex !== -1) {\n const startIndex = semanticsIndex + semanticsTagStart.length;\n const mmlContent = text.substring(startIndex, annotationIndex);\n output += mmlTagStart + mmlContent + mathTagEnd;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n end += mathTagEnd.length;\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n }\n\n output += text.substring(end, text.length);\n return output;\n }\n\n /**\n * Returns true if a MathML contains a certain class.\n * @param {string} mathML - input MathML.\n * @param {string} className - className.\n * @returns {boolean} true if the input MathML contains the input class.\n * false otherwise.\n * @static\n */\n static containClass(mathML, className) {\n const classIndex = mathML.indexOf(\"class\");\n if (classIndex === -1) {\n return false;\n }\n const classTagEndIndex = mathML.indexOf(\">\", classIndex);\n const classTag = mathML.substring(classIndex, classTagEndIndex);\n if (classTag.indexOf(className) !== -1) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns true if mathml is empty. Otherwise, false.\n * @param {string} mathml - valid MathML with standard XML tags.\n * @returns {boolean} - true if mathml is empty. Otherwise, false.\n */\n static isEmpty(mathml) {\n // MathML can have the shape or ''.\n const closeTag = \">\";\n const closeTagInline = \"/>\";\n const firstCloseTagIndex = mathml.indexOf(closeTag);\n const firstCloseTagInlineIndex = mathml.indexOf(closeTagInline);\n let empty = false;\n // MathML is always empty in the second shape.\n if (firstCloseTagInlineIndex !== -1) {\n if (firstCloseTagInlineIndex === firstCloseTagIndex - 1) {\n empty = true;\n }\n }\n\n // MathML is always empty in the first shape when there aren't elements\n // between math tags.\n if (!empty) {\n const mathTagEndRegex = new RegExp(\"\");\n const mathTagEndArray = mathTagEndRegex.exec(mathml);\n if (mathTagEndArray) {\n empty = firstCloseTagIndex + 1 === mathTagEndArray.index;\n }\n }\n\n return empty;\n }\n\n /**\n * Encodes html entities inside properties.\n * @param {String} mathml - valid MathML with standard XML tags.\n * @returns {String} - 'mathml' with property entities encoded.\n */\n static encodeProperties(mathml) {\n // Search all the properties.\n const regex = /\\w+=\".*?\"/g;\n // Encode html entities.\n const replacer = (match) => {\n // It has the shape:\n // .\n const quoteIndex = match.indexOf('\"');\n const propertyValue = match.substring(quoteIndex + 1, match.length - 1);\n const propertyValueEncoded = Util.htmlEntities(propertyValue);\n const matchEncoded = `${match.substring(0, quoteIndex + 1)}${propertyValueEncoded}\"`;\n return matchEncoded;\n };\n\n const mathmlEncoded = mathml.replace(regex, replacer);\n return mathmlEncoded;\n }\n}\n","/**\n * This class represents the configuration class.\n * Usually used to retrieve configuration properties generated in the backend into the frontend.\n */\nexport default class Configuration {\n /**\n * Adds a properties object to {@link Configuration.properties}.\n * @param {Object} properties - properties to append to current properties.\n */\n static addConfiguration(properties) {\n Object.assign(Configuration.properties, properties);\n }\n\n /**\n * Static property.\n * The configuration properties object.\n * @private\n * @type {Object}\n */\n static get properties() {\n return Configuration._properties;\n }\n\n /**\n * Static property setter.\n * Set configuration properties.\n * @param {Object} value - The property value.\n * @ignore\n */\n static set properties(value) {\n Configuration._properties = value;\n }\n\n /**\n * Returns the value of a property key.\n * @param {String} key - Property key\n * @returns {String} Property value\n */\n static get(key) {\n if (!Object.prototype.hasOwnProperty.call(Configuration.properties, key)) {\n // Backwards compatibility.\n if (Object.prototype.hasOwnProperty.call(Configuration.properties, \"_wrs_conf_\")) {\n return Configuration.properties[`_wrs_conf_${key}`];\n }\n return false;\n }\n return Configuration.properties[key];\n }\n\n /**\n * Adds a new property to Configuration class.\n * @param {String} key - Property key.\n * @param {Object} value - Property value.\n */\n static set(key, value) {\n Configuration.properties[key] = value;\n }\n\n /**\n * Updates a property object value with new values.\n * @param {String} key - The property key to be updated.\n * @param {Object} propertyValue - Object containing the new values.\n */\n static update(key, propertyValue) {\n if (!Configuration.get(key)) {\n Configuration.set(key, propertyValue);\n } else {\n const updateProperty = Object.assign(Configuration.get(key), propertyValue);\n Configuration.set(key, updateProperty);\n }\n }\n}\n\n/**\n * Static properties object. Stores all configuration properties.\n * Needed to attribute accessors.\n * @private\n * @type {Object}\n */\nConfiguration._properties = {};\n","export default class TextCache {\n /**\n * @classdesc\n * This class represent a client-side text cache class. Contains pairs of\n * strings (key/value) which can be retrieved in any moment. Usually used\n * to store AJAX responses for text services like mathml2latex\n * (c.f {@link Latex} class) or mathml2accessible (c.f {@link Accessibility} class).\n * @constructs\n */\n constructor() {\n /**\n * Cache array property storing the cache entries.\n * @type {Array.}\n */\n this.cache = [];\n }\n\n /**\n * This method populates a key/value pair into the {@link this.cache} property.\n * @param {String} key - Cache key, usually the service string parameter.\n * @param {String} value - Cache value, usually the service response.\n */\n populate(key, value) {\n this.cache[key] = value;\n }\n\n /**\n * Returns the cache value associated to certain cache key.\n * @param {String} key - Cache key, usually the service string parameter.\n * @return {String} value - Cache value, if exists. False otherwise.\n */\n get(key) {\n if (Object.prototype.hasOwnProperty.call(this.cache, key)) {\n return this.cache[key];\n }\n return false;\n }\n}\n","/**\n * This object represents a custom listener.\n * @typedef {Object} Listener\n * @property {String} Listener.eventName - The listener name.\n * @property {Function} Listener.callback - The listener callback function.\n */\n\nexport default class Listeners {\n /**\n * @classdesc\n * This class represents a custom listeners manager.\n * @constructs\n */\n constructor() {\n /**\n * Array containing all custom listeners.\n * @type {Object[]}\n */\n this.listeners = [];\n }\n\n /**\n * Add a listener to Listener class.\n * @param {Object} listener - A listener object.\n */\n add(listener) {\n this.listeners.push(listener);\n }\n\n /**\n * Fires MathType event listeners\n * @param {String} eventName - event name\n * @param {Event} event - event object.\n * @return {boolean} false if event has been prevented. true otherwise.\n */\n fire(eventName, event) {\n for (let i = 0; i < this.listeners.length && !event.cancelled; i += 1) {\n if (this.listeners[i].eventName === eventName) {\n // Calling listener.\n this.listeners[i].callback(event);\n }\n }\n return event.defaultPrevented;\n }\n\n /**\n * Creates a new listener object.\n * @param {string} eventName - Event name.\n * @param {Object} callback - Callback function.\n * @returns {object} the listener object.\n */\n static newListener(eventName, callback) {\n const listener = {};\n listener.eventName = eventName;\n listener.callback = callback;\n return listener;\n }\n}\n","import Util from \"./util\";\nimport Listeners from \"./listeners\";\nimport Configuration from \"./configuration\";\n\n/**\n * @typedef {Object} ServiceProviderProperties\n * @property {String} URI - Service URI.\n * @property {String} server - Service server language.\n */\n\n/**\n * @classdesc\n * Class representing a serviceProvider. A serviceProvider is a class containing\n * an arbitrary number of services with the correspondent path.\n */\nexport default class ServiceProvider {\n /**\n * Returns Service Provider listeners.\n * @type {Listeners}\n */\n static get listeners() {\n return ServiceProvider._listeners;\n }\n\n /**\n * Adds a {@link Listener} instance to {@link ServiceProvider} class.\n * @param {Listener} listener - Instance of {@link Listener}.\n */\n static addListener(listener) {\n ServiceProvider.listeners.add(listener);\n }\n\n /**\n * Fires events in Service Provider.\n * @param {String} eventName - Event name.\n * @param {Event} event - Event object.\n */\n static fireEvent(eventName, event) {\n ServiceProvider.listeners.fire(eventName, event);\n }\n\n /**\n * Service parameters.\n * @type {ServiceProviderProperties}\n *\n */\n static get parameters() {\n return ServiceProvider._parameters;\n }\n\n /**\n * Service parameters.\n * @private\n * @type {ServiceProviderProperties}\n */\n static set parameters(parameters) {\n ServiceProvider._parameters = parameters;\n }\n\n /**\n * Static property.\n * Return service provider paths.\n * @private\n * @type {String}\n */\n static get servicePaths() {\n return ServiceProvider._servicePaths;\n }\n\n /**\n * Static property setter.\n * Set service paths.\n * @param {String} value - The property value.\n * @ignore\n */\n static set servicePaths(value) {\n ServiceProvider._servicePaths = value;\n }\n\n /**\n * Adds a new service to the ServiceProvider.\n * @param {String} service - Service name.\n * @param {String} path - Service path.\n * @static\n */\n static setServicePath(service, path) {\n ServiceProvider.servicePaths[service] = path;\n }\n\n /**\n * Returns the service path for a certain service.\n * @param {String} serviceName - Service name.\n * @returns {String} The service path.\n * @static\n */\n static getServicePath(serviceName) {\n return ServiceProvider.servicePaths[serviceName];\n }\n\n /**\n * Static property.\n * Service provider integration path.\n * @type {String}\n */\n static get integrationPath() {\n return ServiceProvider._integrationPath;\n }\n\n /**\n * Static property setter.\n * Set service provider integration path.\n * @param {String} value - The property value.\n * @ignore\n */\n static set integrationPath(value) {\n ServiceProvider._integrationPath = value;\n }\n\n /**\n * Returns the server URL in the form protocol://serverName:serverPort.\n * @return {String} The client side server path.\n */\n static getServerURL() {\n const url = window.location.href;\n const arr = url.split(\"/\");\n const result = `${arr[0]}//${arr[2]}`;\n return result;\n }\n\n /**\n * Inits {@link this} class. Uses {@link this.integrationPath} as\n * base path to generate all backend services paths.\n * @param {Object} parameters - Function parameters.\n * @param {String} parameters.integrationPath - Service path.\n */\n static init(parameters) {\n ServiceProvider.parameters = parameters;\n // Services path (tech dependant).\n let configurationURI = ServiceProvider.createServiceURI(\"configurationjs\");\n let createImageURI = ServiceProvider.createServiceURI(\"createimage\");\n let showImageURI = ServiceProvider.createServiceURI(\"showimage\");\n let getMathMLURI = ServiceProvider.createServiceURI(\"getmathml\");\n let serviceURI = ServiceProvider.createServiceURI(\"service\");\n\n // Some backend integrations (like Java o Ruby) have an absolute backend path,\n // for example: /app/service. For them we calculate the absolute URL path, i.e\n // protocol://domain:port/app/service\n if (ServiceProvider.parameters.URI.indexOf(\"/\") === 0) {\n const serverPath = ServiceProvider.getServerURL();\n configurationURI = serverPath + configurationURI;\n showImageURI = serverPath + showImageURI;\n createImageURI = serverPath + createImageURI;\n getMathMLURI = serverPath + getMathMLURI;\n serviceURI = serverPath + serviceURI;\n }\n\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n ServiceProvider.setServicePath(\"showimage\", showImageURI);\n ServiceProvider.setServicePath(\"createimage\", createImageURI);\n ServiceProvider.setServicePath(\"service\", serviceURI);\n ServiceProvider.setServicePath(\"getmathml\", getMathMLURI);\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n\n ServiceProvider.listeners.fire(\"onInit\", {});\n }\n\n /**\n * Gets the content from an URL.\n * @param {String} url - Target URL.\n * @param {Object} [postVariables] - Object containing post variables.\n * null if a GET query should be done.\n * @returns {String} Content of the target URL.\n * @private\n * @static\n */\n static getUrl(url, postVariables) {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n const httpRequest = Util.createHttpRequest();\n\n if (httpRequest) {\n if (typeof postVariables === \"undefined\" || typeof postVariables === \"undefined\") {\n httpRequest.open(\"GET\", url, false);\n } else if (url.substr(0, 1) === \"/\" || url.substr(0, 7) === \"http://\" || url.substr(0, 8) === \"https://\") {\n httpRequest.open(\"POST\", url, false);\n } else {\n httpRequest.open(\"POST\", currentPath + url, false);\n }\n\n let header = Configuration.get(\"customHeaders\");\n if (header) {\n if (typeof header === \"string\") {\n header = Util.convertStringToObject(header);\n }\n Object.entries(header).forEach(([key, val]) => httpRequest.setRequestHeader(key, val));\n }\n\n if (typeof postVariables !== \"undefined\" && postVariables) {\n httpRequest.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded; charset=UTF-8\");\n httpRequest.send(Util.httpBuildQuery(postVariables));\n } else {\n httpRequest.send(null);\n }\n\n return httpRequest.responseText;\n }\n return \"\";\n }\n\n /**\n * Returns the response text of a certain service.\n * @param {String} service - Service name.\n * @param {String} postVariables - Post variables.\n * @param {Boolean} get - True if the request is GET instead of POST. false otherwise.\n * @returns {String} Service response text.\n */\n static getService(service, postVariables, get) {\n let response;\n if (get === true) {\n const getVariables = postVariables ? `?${postVariables}` : \"\";\n const serviceUrl = `${ServiceProvider.getServicePath(service)}${getVariables}`;\n response = ServiceProvider.getUrl(serviceUrl);\n } else {\n const serviceUrl = ServiceProvider.getServicePath(service);\n response = ServiceProvider.getUrl(serviceUrl, postVariables);\n }\n return response;\n }\n\n /**\n * Returns the server language of a certain service. The possible values\n * are: php, aspx, java and ruby.\n * This method has backward compatibility purposes.\n * @param {String} service - The configuration service.\n * @returns {String} - The server technology associated with the configuration service.\n */\n static getServerLanguageFromService(service) {\n if (service.indexOf(\".php\") !== -1) {\n return \"php\";\n }\n if (service.indexOf(\".aspx\") !== -1) {\n return \"aspx\";\n }\n if (service.indexOf(\"wirispluginengine\") !== -1) {\n return \"ruby\";\n }\n return \"java\";\n }\n\n /**\n * Returns the URI associated with a certain service.\n * @param {String} service - The service name.\n * @return {String} The service path.\n */\n static createServiceURI(service) {\n const extension = ServiceProvider.serverExtension();\n return Util.concatenateUrl(ServiceProvider.parameters.URI, service) + extension;\n }\n\n static serverExtension() {\n if (ServiceProvider.parameters.server.indexOf(\"php\") !== -1) {\n return \".php\";\n }\n if (ServiceProvider.parameters.server.indexOf(\"aspx\") !== -1) {\n return \".aspx\";\n }\n return \"\";\n }\n}\n\n/**\n * @property {String} service - The service name.\n * @property {String} path - The service path.\n * @static\n */\nServiceProvider._servicePaths = {};\n\n/**\n * The integration path. Contains the path of the configuration service.\n * Used to define the path for all services.\n * @type {String}\n * @private\n */\nServiceProvider._integrationPath = \"\";\n\n/**\n * ServiceProvider static listeners.\n * @type {Listeners}\n * @private\n */\nServiceProvider._listeners = new Listeners();\n\n/**\n * Service provider parameters.\n * @type {ServiceProviderParameters}\n */\nServiceProvider._parameters = {};\n","import TextCache from \"./textcache\";\nimport MathML from \"./mathml\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a LaTeX parser. Manages the services which allows to convert\n * LaTeX into MathML and MathML into LaTeX.\n */\nexport default class Latex {\n /**\n * Static property.\n * Return latex cache.\n * @private\n * @type {Cache}\n */\n static get cache() {\n return Latex._cache;\n }\n\n /**\n * Static property setter.\n * Set latex cache.\n * @param {Cache} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Latex._cache = value;\n }\n\n /**\n * Converts MathML to LaTeX by calling mathml2latex service. For text services\n * we call a text service with the param mathml2latex.\n * @param {String} mathml - MathML String.\n * @return {String} LaTeX string generated by the MathML argument.\n */\n static getLatexFromMathML(mathml) {\n const mathmlWithoutSemantics = MathML.removeSemantics(mathml);\n /**\n * @type {TextCache}\n */\n const { cache } = Latex;\n\n const data = {\n service: \"mathml2latex\",\n mml: mathmlWithoutSemantics,\n };\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n // TODO: Error handling.\n let latex = \"\";\n\n if (jsonResponse.status === \"ok\") {\n latex = jsonResponse.result.text;\n const latexHtmlEntitiesEncoded = Util.htmlEntities(latex);\n // Inserting LaTeX semantics.\n const mathmlWithSemantics = MathML.addAnnotation(mathml, latexHtmlEntitiesEncoded, \"LaTeX\");\n cache.populate(latex, mathmlWithSemantics);\n }\n\n return latex;\n }\n\n /**\n * Converts LaTeX to MathML by calling latex2mathml service. For text services\n * we call a text service with the param latex2mathml.\n * @param {String} latex - String containing a LaTeX formula.\n * @param {Boolean} includeLatexOnSemantics\n * - If true LaTeX would me included into MathML semantics.\n * @return {String} MathML string generated by the LaTeX argument.\n */\n static getMathMLFromLatex(latex, includeLatexOnSemantics) {\n /**\n * @type {TextCache}\n */\n const latexCache = Latex.cache;\n\n if (Latex.cache.get(latex)) {\n return Latex.cache.get(latex);\n }\n const data = {\n service: \"latex2mathml\",\n latex,\n };\n\n if (includeLatexOnSemantics) {\n data.saveLatex = \"\";\n }\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n let output;\n if (jsonResponse.status === \"ok\") {\n let mathml = jsonResponse.result.text;\n mathml = mathml.split(\"\\r\").join(\"\").split(\"\\n\").join(\" \");\n\n // Populate LatexCache.\n if (mathml.indexOf(\"semantics\") === -1 && mathml.indexOf(\"annotation\") === -1) {\n const content = Util.htmlEntities(latex);\n mathml = MathML.addAnnotation(mathml, content, \"LaTeX\");\n output = mathml;\n } else {\n output = mathml;\n }\n if (!latexCache.get(latex)) {\n latexCache.populate(latex, mathml);\n }\n } else {\n output = `$$${latex}$$`;\n }\n return output;\n }\n\n /**\n * Converts all occurrences of MathML code to LaTeX.\n * The MathML code should containing to be converted.\n * @param {String} content - A string containing MathML valid code.\n * @param {Object} characters - An object containing special characters.\n * @return {String} A string containing all MathML annotated occurrences\n * replaced by the corresponding LaTeX code.\n */\n static parseMathmlToLatex(content, characters) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const openTarget = `${characters.tagOpener}annotation encoding=${characters.doubleQuote}LaTeX${characters.doubleQuote}${characters.tagCloser}`;\n const closeTarget = `${characters.tagOpener}/annotation${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n let mathml;\n let startAnnotation;\n let closeAnnotation;\n\n while (start !== -1) {\n output += content.substring(end, start);\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else {\n end += mathTagEnd.length;\n }\n\n mathml = content.substring(start, end);\n\n startAnnotation = mathml.indexOf(openTarget);\n if (startAnnotation !== -1) {\n startAnnotation += openTarget.length;\n closeAnnotation = mathml.indexOf(closeTarget);\n let latex = mathml.substring(startAnnotation, closeAnnotation);\n if (characters === Constants.safeXmlCharacters) {\n latex = MathML.safeXmlDecode(latex);\n }\n output += `$$${latex}$$`;\n // Populate latex into cache.\n\n Latex.cache.populate(latex, mathml);\n } else {\n output += mathml;\n }\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n\n /**\n * Extracts the latex of a determined position in a text.\n * @param {Node} textNode - textNode to extract the LaTeX\n * @param {Number} caretPosition - Starting position to find LaTeX.\n * @param {Object} latexTags - Optional parameter representing tags between latex is inserted.\n * It has the 'open' attribute for the open tag and the 'close' attribute for the close tag.\n * \"$$\" by default.\n * @return {Object} An object with 3 keys: 'latex', 'start' and 'end'. Null if latex is not found.\n * @static\n */\n static getLatexFromTextNode(textNode, caretPosition, latexTags) {\n // TODO: Set LaTeX Tags as Core variable. Fix the call to this function (third argument).\n // Tags used for LaTeX formulas.\n const defaultLatexTags = {\n open: \"$$\",\n close: \"$$\",\n };\n // latexTags is an optional parameter. If is not set, use default latexTags.\n if (typeof latexTags === \"undefined\" || latexTags == null) {\n latexTags = defaultLatexTags;\n }\n // Looking for the first textNode.\n let startNode = textNode;\n\n while (startNode.previousSibling && startNode.previousSibling.nodeType === 3) {\n // TEXT_NODE.\n startNode = startNode.previousSibling;\n }\n\n /**\n * Returns the next latex position and node from a specific node and position.\n * @param {Node} currentNode - Node where searching latex.\n * @param {Number} currentPosition - Current position inside the currentNode.\n * @param {Object} latexTagsToUse - Tags used at latex beginning and latex final.\n * \"$$\" by default.\n * @param {Boolean} tag - Tag containing the current search.\n * @returns {Object} Object containing the current node and the position.\n */\n function getNextLatexPosition(currentNode, currentPosition, tag) {\n let position = currentNode.nodeValue.indexOf(tag, currentPosition);\n\n while (position === -1) {\n currentNode = currentNode.nextSibling;\n\n if (!currentNode) {\n // TEXT_NODE.\n return null; // Not found.\n }\n\n position = currentNode.nodeValue ? currentNode.nodeValue.indexOf(latexTags.close) : -1;\n }\n\n return {\n node: currentNode,\n position,\n };\n }\n\n /**\n * Determines if a node is previous, or not, to a second one.\n * @param {Node} node - Start node.\n * @param {Number} position - Start node position.\n * @param {Node} endNode - End node.\n * @param {Number} endPosition - End node position.\n * @returns {Boolean} True if the starting node is previous thant the en node. false otherwise.\n */\n function isPrevious(node, position, endNode, endPosition) {\n if (node === endNode) {\n return position <= endPosition;\n }\n while (node && node !== endNode) {\n node = node.nextSibling;\n }\n\n return node === endNode;\n }\n\n let start;\n let end = {\n node: startNode,\n position: 0,\n };\n // Is supposed that open and close tags has the same length.\n const tagLength = latexTags.open.length;\n do {\n start = getNextLatexPosition(end.node, end.position, latexTags.open);\n\n if (start == null || isPrevious(textNode, caretPosition, start.node, start.position)) {\n return null;\n }\n\n end = getNextLatexPosition(start.node, start.position + tagLength, latexTags.close);\n\n if (end == null) {\n return null;\n }\n\n end.position += tagLength;\n } while (isPrevious(end.node, end.position, textNode, caretPosition));\n\n // Isolating latex.\n let latex;\n\n if (start.node === end.node) {\n latex = start.node.nodeValue.substring(start.position + tagLength, end.position - tagLength);\n } else {\n const index = start.position + tagLength;\n latex = start.node.nodeValue.substring(index, start.node.nodeValue.length);\n let currentNode = start.node;\n\n do {\n currentNode = currentNode.nextSibling;\n if (currentNode === end.node) {\n latex += end.node.nodeValue.substring(0, end.position - tagLength);\n } else {\n latex += currentNode.nodeValue ? currentNode.nodeValue : \"\";\n }\n } while (currentNode !== end.node);\n }\n\n return {\n latex,\n startNode: start.node,\n startPosition: start.position,\n endNode: end.node,\n endPosition: end.position,\n };\n }\n}\n\n/**\n * Text cache. Stores all processed LaTeX strings and it's correspondent MathML string.\n * @type {Cache}\n * @static\n */\nLatex._cache = new TextCache();\n","import translations from \"../lang/strings.json\";\n/**\n * This class represents a string manager. It's used to load localized strings.\n */\nexport default class StringManager {\n constructor() {\n throw new Error(\"Static class StringManager can not be instantiated.\");\n }\n\n /**\n * Returns the associated value of certain string key. If the associated value\n * doesn't exits returns the original key.\n * @param {string} key - string key\n * @param {string} lang - DEFAULT = null. Specify the language to translate the string\n * @returns {string} correspondent value. If doesn't exists original key.\n */\n static get(key, lang) {\n // Default language definition\n let { language } = this;\n\n // If parameter language, use it\n if (lang) {\n language = lang;\n }\n\n // Cut down on strings. e.g. en_US -> en\n if (language && language.length > 2) {\n language = language.slice(0, 2);\n }\n\n // Check if we support the language\n if (!this.strings.hasOwnProperty(language)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown language ${language} set in StringManager.`);\n language = \"en\";\n }\n\n // Check if the key is supported in the given language\n if (!this.strings[language].hasOwnProperty(key)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown key ${key} for language ${language} in StringManager.`);\n return key;\n }\n\n return this.strings[language][key];\n }\n}\n\n/**\n * Dictionary of dictionaries:\n * Key: language code\n * Value: Key: id of the string\n * Value: translation of the string\n */\nStringManager.strings = translations;\n\n/**\n * Language of the translations; English by default\n */\nStringManager.language = \"en\";\n","/* eslint-disable no-bitwise */\nimport DOMPurify from \"dompurify\";\nimport MathML from \"./mathml\";\nimport Configuration from \"./configuration\";\nimport Latex from \"./latex\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * This class represents an utility class.\n */\nexport default class Util {\n /**\n * Fires an event in a target.\n * @param {EventTarget} eventTarget - target where event should be fired.\n * @param {string} eventName event to fire.\n * @static\n */\n static fireEvent(eventTarget, eventName) {\n if (document.createEvent) {\n const eventObject = document.createEvent(\"HTMLEvents\");\n eventObject.initEvent(eventName, true, true);\n return !eventTarget.dispatchEvent(eventObject);\n }\n\n const eventObject = document.createEventObject();\n return eventTarget.fireEvent(`on${eventName}`, eventObject);\n }\n\n /**\n * Cross-browser addEventListener/attachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - callback function.\n * @static\n */\n static addEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.addEventListener) {\n eventTarget.addEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.attachEvent) {\n // Backwards compatibility.\n eventTarget.attachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * Cross-browser removeEventListener/detachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - function to remove from the event target.\n * @static\n */\n static removeEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.removeEventListener) {\n eventTarget.removeEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.detachEvent) {\n eventTarget.detachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * Adds the a callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @param {Function} doubleClickHandler - function to run when on dblclick event.\n * @param {Function} mousedownHandler - function to run when on mousedown event.\n * @param {Function} mouseupHandler - function to run when on mouseup event.\n * @static\n */\n static addElementEvents(eventTarget, doubleClickHandler, mousedownHandler, mouseupHandler) {\n if (doubleClickHandler) {\n this.callbackDblclick = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n doubleClickHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"dblclick\", this.callbackDblclick);\n }\n\n if (mousedownHandler) {\n this.callbackMousedown = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mousedownHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"mousedown\", this.callbackMousedown);\n }\n\n if (mouseupHandler) {\n this.callbackMouseup = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mouseupHandler(element, realEvent);\n };\n // Chrome doesn't trigger this event for eventTarget if we release the mouse button\n // while the mouse is outside the editor text field.\n // This is a workaround: we trigger the event independently of where the mouse\n // is when we release its button.\n Util.addEvent(document, \"mouseup\", this.callbackMouseup);\n Util.addEvent(eventTarget, \"mouseup\", this.callbackMouseup);\n }\n }\n\n /**\n * Remove all callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @static\n */\n static removeElementEvents(eventTarget) {\n Util.removeEvent(eventTarget, \"dblclick\", this.callbackDblclick);\n Util.removeEvent(eventTarget, \"mousedown\", this.callbackMousedown);\n Util.removeEvent(document, \"mouseup\", this.callbackMouseup);\n Util.removeEvent(eventTarget, \"mouseup\", this.callbackMouseup);\n }\n\n /**\n * Adds a class name to a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static addClass(element, className) {\n if (!Util.containsClass(element, className)) {\n element.className += ` ${className}`;\n }\n }\n\n /**\n * Checks if a HTMLElement contains a certain class.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the className.\n * @returns {boolean} true if the HTMLElement contains the class name. false otherwise.\n * @static\n */\n static containsClass(element, className) {\n if (element == null || !(\"className\" in element)) {\n return false;\n }\n\n const currentClasses = element.className.split(\" \");\n\n for (let i = currentClasses.length - 1; i >= 0; i -= 1) {\n if (currentClasses[i] === className) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Remove a certain class for a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static removeClass(element, className) {\n let newClassName = \"\";\n const classes = element.className.split(\" \");\n\n for (let i = 0; i < classes.length; i += 1) {\n if (classes[i] !== className) {\n newClassName += `${classes[i]} `;\n }\n }\n element.className = newClassName.trim();\n }\n\n /**\n * Converts old xml initial text attribute (with «») to the correct one(with §lt;§gt;). It's\n * used to parse old applets.\n * @param {string} text - string containing safeXml characters\n * @returns {string} a string with safeXml characters parsed.\n * @static\n */\n static convertOldXmlinitialtextAttribute(text) {\n // Used to fix a bug with Cas imported from Moodle 1.9 to Moodle 2.x.\n // This could be removed in future.\n const val = \"value=\";\n\n const xitpos = text.indexOf(\"xmlinitialtext\");\n const valpos = text.indexOf(val, xitpos);\n const quote = text.charAt(valpos + val.length);\n const startquote = valpos + val.length + 1;\n const endquote = text.indexOf(quote, startquote);\n\n const value = text.substring(startquote, endquote);\n\n let newvalue = value.split(\"«\").join(\"§lt;\");\n newvalue = newvalue.split(\"»\").join(\"§gt;\");\n newvalue = newvalue.split(\"&\").join(\"§\");\n newvalue = newvalue.split(\"¨\").join(\"§quot;\");\n\n text = text.split(value).join(newvalue);\n return text;\n }\n\n /**\n * Convert a string representation of key-value pairs to an object.\n * @param {string} keyValueString - String with key-value pairs in the format key1='value1', key2='value2'\n * @returns {Object} - Object containing the key-value pairs\n */\n static convertStringToObject(keyValueString) {\n if (!keyValueString || typeof keyValueString !== \"string\") {\n return {};\n }\n\n return keyValueString\n .split(\",\")\n .map((pair) => pair.trim().split(\"=\"))\n .reduce((resultObject, [key, value]) => {\n if (key && value) {\n resultObject[key] = value;\n }\n return resultObject;\n }, {});\n }\n\n /**\n * Cross-browser solution for creating new elements.\n * @param {string} tagName - tag name of the wished element.\n * @param {Object} attributes - an object where each key is a wished\n * attribute name and each value is its value.\n * @param {Object} [creator] - if supplied, this function will use\n * the \"createElement\" method from this param. Otherwise\n * document will be used as creator.\n * @returns {Element} The DOM element with the specified attributes assigned.\n * @static\n */\n static createElement(tagName, attributes, creator) {\n if (attributes === undefined) {\n attributes = {};\n }\n\n if (creator === undefined) {\n creator = document;\n }\n\n let element;\n\n /*\n * Internet Explorer fix:\n * If you create a new object dynamically, you can't set a non-standard attribute.\n * For example, you can't set the \"src\" attribute on an \"applet\" object.\n * Other browsers will throw an exception and will run the standard code.\n */\n try {\n let html = `<${tagName}`;\n\n Object.keys(attributes).forEach((attributeName) => {\n html += ` ${attributeName}=\"${Util.htmlEntities(attributes[attributeName])}\"`;\n });\n html += \">\";\n element = creator.createElement(html);\n } catch (e) {\n element = creator.createElement(tagName);\n Object.keys(attributes).forEach((attributeName) => {\n element.setAttribute(attributeName, attributes[attributeName]);\n });\n }\n return element;\n }\n\n /**\n * Creates new HTML from it's HTML code as string.\n * @param {string} objectCode - html code\n * @returns {Element} the HTML element.\n * @static\n */\n static createObject(objectCode, creator) {\n if (creator === undefined) {\n creator = document;\n }\n\n // Internet Explorer can't include \"param\" tag when is setting an innerHTML property.\n objectCode = objectCode\n .split(\"\").join(\"\").split(\"\").join(\"\");\n\n objectCode = objectCode\n .split(\"\").join(\"
\").split(\"\").join(\"
\");\n\n const container = Util.createElement(\"div\", {}, creator);\n container.innerHTML = objectCode;\n\n function recursiveParamsFix(object) {\n if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisParam\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const param = Util.createElement(\"param\", attributesParsed, creator);\n\n // IE fix.\n if (param.NAME) {\n param.name = param.NAME;\n param.value = param.VALUE;\n }\n\n param.removeAttribute(\"wirisObject\");\n object.parentNode.replaceChild(param, object);\n } else if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisApplet\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const applet = Util.createElement(\"applet\", attributesParsed, creator);\n applet.removeAttribute(\"wirisObject\");\n\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n\n if (object.childNodes[i].nodeName.toLowerCase() === \"param\") {\n applet.appendChild(object.childNodes[i]);\n i -= 1; // When we insert the object child into the applet, object loses one child.\n }\n }\n\n object.parentNode.replaceChild(applet, object);\n } else {\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n }\n }\n }\n\n recursiveParamsFix(container);\n return container.firstChild;\n }\n\n /**\n * Converts an Element to its HTML code.\n * @param {Element} element - entry element.\n * @return {string} the HTML code of the input element.\n * @static\n */\n static createObjectCode(element) {\n // In case that the image was not created, the object can be null or undefined.\n if (typeof element === \"undefined\" || element === null) {\n return null;\n }\n\n if (element.nodeType === 1) {\n // ELEMENT_NODE.\n let output = `<${element.tagName}`;\n\n for (let i = 0; i < element.attributes.length; i += 1) {\n if (element.attributes[i].specified) {\n output += ` ${element.attributes[i].name}=\"${Util.htmlEntities(element.attributes[i].value)}\"`;\n }\n }\n\n if (element.childNodes.length > 0) {\n output += \">\";\n\n for (let i = 0; i < element.childNodes.length; i += 1) {\n output += Util.createObject(element.childNodes[i]);\n }\n\n output += ``;\n } else if (element.nodeName === \"DIV\" || element.nodeName === \"SCRIPT\") {\n output += `>`;\n } else {\n output += \"/>\";\n }\n\n return output;\n }\n\n if (element.nodeType === 3) {\n // TEXT_NODE.\n return Util.htmlEntities(element.nodeValue);\n }\n\n return \"\";\n }\n\n /**\n * Concatenates two URL paths.\n * @param {string} path1 - first URL path\n * @param {string} path2 - second URL path\n * @returns {string} new URL.\n */\n static concatenateUrl(path1, path2) {\n let separator = \"\";\n if (path1.indexOf(\"/\") !== path1.length && path2.indexOf(\"/\") !== 0) {\n separator = \"/\";\n }\n return (path1 + separator + path2).replace(/([^:]\\/)\\/+/g, \"$1\");\n }\n\n /**\n * Parses a text and replaces all HTML special characters by their correspondent entities.\n * @param {string} input - text to be parsed.\n * @returns {string} the input text with all their special characters replaced by their entities.\n * @static\n */\n static htmlEntities(input) {\n return input.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\").split('\"').join(\""\");\n }\n\n /**\n * Sanitize HTML to prevent XSS injections.\n * @param {string} html - html to be sanitize.\n * @returns {string} html sanitized.\n * @static\n */\n static htmlSanitize(html) {\n const annotationRegex = /\\/;\n // Get all the annotation content including the tags.\n const annotation = html.match(annotationRegex);\n // Sanitize html code without removing our supported MathML tags and attributes.\n html = DOMPurify.sanitize(html, {\n ADD_TAGS: [\"semantics\", \"annotation\", \"mstack\", \"msline\", \"msrow\", \"none\"],\n ADD_ATTR: [\"linebreak\", \"charalign\", \"stackalign\"],\n });\n // Readd old annotation content.\n return html.replace(annotationRegex, annotation);\n }\n\n /**\n * Parses a text and replaces all the HTML entities by their characters.\n * @param {string} input - text to be parsed\n * @returns {string} the input text with all their entities replaced by characters.\n * @static\n */\n static htmlEntitiesDecode(input) {\n // Textarea element decodes when inner html is set.\n const textarea = document.createElement(\"textarea\");\n textarea.innerHTML = input;\n return textarea.value;\n }\n\n /**\n * Returns a cross-browser http request.\n * @return {object} httpRequest request object.\n * @returns {XMLHttpRequest|ActiveXObject} the proper request object.\n */\n static createHttpRequest() {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n if (currentPath.substr(0, 7) === \"file://\") {\n throw StringManager.get(\"exception_cross_site\");\n }\n\n if (typeof XMLHttpRequest !== \"undefined\") {\n return new XMLHttpRequest();\n }\n\n try {\n return new ActiveXObject(\"Msxml2.XMLHTTP\");\n } catch (e) {\n try {\n return new ActiveXObject(\"Microsoft.XMLHTTP\");\n } catch (oc) {\n return null;\n }\n }\n }\n\n /**\n * Converts a hash to a HTTP query.\n * @param {Object[]} properties - a key/value object.\n * @returns {string} a HTTP query containing all the key value pairs with\n * all the special characters replaced by their entities.\n * @static\n */\n static httpBuildQuery(properties) {\n let result = \"\";\n\n Object.keys(properties).forEach((i) => {\n if (properties[i] != null) {\n result += `${Util.urlEncode(i)}=${Util.urlEncode(properties[i])}&`;\n }\n });\n\n // Deleting last '&' empty character.\n if (result.substring(result.length - 1) === \"&\") {\n result = result.substring(0, result.length - 1);\n }\n\n return result;\n }\n\n /**\n * Convert a hash to string sorting keys to get a deterministic output\n * @param {Object[]} hash - a key/value object.\n * @returns {string} a string with the form key1=value1...keyn=valuen\n * @static\n */\n static propertiesToString(hash) {\n // 1. Sort keys. We sort the keys because we want a deterministic output.\n const keys = [];\n Object.keys(hash).forEach((key) => {\n if (Object.prototype.hasOwnProperty.call(hash, key)) {\n keys.push(key);\n }\n });\n\n const n = keys.length;\n for (let i = 0; i < n; i += 1) {\n for (let j = i + 1; j < n; j += 1) {\n const s1 = keys[i];\n const s2 = keys[j];\n if (Util.compareStrings(s1, s2) > 0) {\n // Swap.\n keys[i] = s2;\n keys[j] = s1;\n }\n }\n }\n\n // 2. Generate output.\n let output = \"\";\n for (let i = 0; i < n; i += 1) {\n const key = keys[i];\n output += key;\n output += \"=\";\n let value = hash[key];\n value = value.replace(\"\\\\\", \"\\\\\\\\\");\n value = value.replace(\"\\n\", \"\\\\n\");\n value = value.replace(\"\\r\", \"\\\\r\");\n value = value.replace(\"\\t\", \"\\\\t\");\n\n output += value;\n output += \"\\n\";\n }\n return output;\n }\n\n /**\n * Compare two strings using charCodeAt method\n * @param {string} a - first string to compare.\n * @param {string} b - second string to compare.\n * @returns {number} the difference between a and b\n * @static\n */\n static compareStrings(a, b) {\n let i;\n const an = a.length;\n const bn = b.length;\n const n = an > bn ? bn : an;\n for (i = 0; i < n; i += 1) {\n const c = Util.fixedCharCodeAt(a, i) - Util.fixedCharCodeAt(b, i);\n if (c !== 0) {\n return c;\n }\n }\n return a.length - b.length;\n }\n\n /**\n * Fix charCodeAt() JavaScript function to handle non-Basic-Multilingual-Plane characters.\n * @param {string} string - input string\n * @param {number} idx - an integer greater than or equal to 0\n * and less than the length of the string\n * @returns {number} an integer representing the UTF-16 code of the string at the given index.\n * @static\n */\n static fixedCharCodeAt(string, idx) {\n idx = idx || 0;\n const code = string.charCodeAt(idx);\n let hi;\n let low;\n\n /* High surrogate (could change last hex to 0xDB7F to treat high\n private surrogates as single characters) */\n\n if (code >= 0xd800 && code <= 0xdbff) {\n hi = code;\n low = string.charCodeAt(idx + 1);\n if (Number.isNaN(low)) {\n throw StringManager.get(\"exception_high_surrogate\");\n }\n return (hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;\n }\n\n if (code >= 0xdc00 && code <= 0xdfff) {\n // Low surrogate.\n /* We return false to allow loops to skip this iteration since should have\n already handled high surrogate above in the previous iteration. */\n return false;\n }\n return code;\n }\n\n /**\n * Returns an URL with it's query params converted into array.\n * @param {string} url - input URL.\n * @returns {Object[]} an array containing all URL query params.\n * @static\n */\n static urlToAssArray(url) {\n let i;\n i = url.indexOf(\"?\");\n if (i > 0) {\n const query = url.substring(i + 1);\n const ss = query.split(\"&\");\n const h = {};\n for (i = 0; i < ss.length; i += 1) {\n const s = ss[i];\n const kv = s.split(\"=\");\n if (kv.length > 1) {\n h[kv[0]] = decodeURIComponent(kv[1].replace(/\\+/g, \" \"));\n }\n }\n return h;\n }\n return {};\n }\n\n /**\n * Returns an encoded URL by replacing each instance of certain characters by\n * one, two, three or four escape sequences using encodeURIComponent method.\n * !'()* . will not be encoded.\n *\n * @param {string} clearString - URL string to be encoded\n * @returns {string} URL with it's special characters replaced.\n * @static\n */\n static urlEncode(clearString) {\n let output = \"\";\n // Method encodeURIComponent doesn't encode !'()*~ .\n output = encodeURIComponent(clearString);\n return output;\n }\n\n // TODO: To parser?\n /**\n * Converts the HTML of a image into the output code that WIRIS must return.\n * By default returns the MathML stored on data-mahml attribute (if imgCode is a formula)\n * or the Wiriscas attribute of a WIRIS applet.\n * @param {string} imgCode - the html code from a formula or a CAS image.\n * @param {boolean} convertToXml - true if the image should be converted to XML.\n * @param {boolean} convertToSafeXml - true if the image should be converted to safeXML.\n * @returns {string} the XML or safeXML of a WIRIS image.\n * @static\n */\n static getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml) {\n const imgObject = Util.createObject(imgCode);\n if (imgObject) {\n if (\n imgObject.className === Configuration.get(\"imageClassName\") ||\n imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"))\n ) {\n if (!convertToXml) {\n return imgCode;\n }\n\n const dataMathML = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n // To handle annotations, first we need the MathML in XML.\n let mathML = MathML.safeXmlDecode(dataMathML);\n\n if (!Configuration.get(\"saveHandTraces\")) {\n mathML = MathML.removeAnnotation(mathML, \"application/json\");\n }\n\n if (mathML == null) {\n mathML = imgObject.getAttribute(\"alt\");\n }\n\n if (convertToSafeXml) {\n const safeMathML = MathML.safeXmlEncode(mathML);\n return safeMathML;\n }\n\n return mathML;\n }\n }\n return imgCode;\n }\n\n /**\n * Gets the node length in characters.\n * @param {Node} node - HTML node.\n * @returns {number} node length.\n * @static\n */\n static getNodeLength(node) {\n const staticNodeLengths = {\n IMG: 1,\n BR: 1,\n };\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return node.nodeValue.length;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n let length = staticNodeLengths[node.nodeName.toUpperCase()];\n\n if (length === undefined) {\n length = 0;\n }\n\n for (let i = 0; i < node.childNodes.length; i += 1) {\n length += Util.getNodeLength(node.childNodes[i]);\n }\n return length;\n }\n return 0;\n }\n\n /**\n * Gets a selected node or text from an editable HTMLElement.\n * If the caret is on a text node, concatenates it with all the previous and next text nodes.\n * @param {HTMLElement} target - the editable HTMLElement.\n * @param {boolean} isIframe - specifies if the target is an iframe or not\n * @param {boolean} forceGetSelection - if true, ignores IE system to get\n * the current selection and uses window.getSelection()\n * @returns {object} an object with the 'node' key set if the item is an\n * element or the keys 'node' and 'caretPosition' if the element is text.\n * @static\n */\n static getSelectedItem(target, isIframe, forceGetSelection) {\n let windowTarget;\n\n if (isIframe) {\n windowTarget = target.contentWindow;\n windowTarget.focus();\n } else {\n windowTarget = window;\n target.focus();\n }\n\n if (document.selection && !forceGetSelection) {\n const range = windowTarget.document.selection.createRange();\n\n if (range.parentElement) {\n if (range.htmlText.length > 0) {\n if (range.text.length === 0) {\n return Util.getSelectedItem(target, isIframe, true);\n }\n\n return null;\n }\n\n windowTarget.document.execCommand(\"InsertImage\", false, \"#\");\n let temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() !== \"IMG\") {\n // IE9 fix: parentElement() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML('');\n temporalObject = windowTarget.document.getElementById(\"wrs_openEditorWindow_temporalObject\");\n }\n\n let node;\n let caretPosition;\n\n if (temporalObject.nextSibling && temporalObject.nextSibling.nodeType === 3) {\n // TEXT_NODE.\n node = temporalObject.nextSibling;\n caretPosition = 0;\n } else if (temporalObject.previousSibling && temporalObject.previousSibling.nodeType === 3) {\n node = temporalObject.previousSibling;\n caretPosition = node.nodeValue.length;\n } else {\n node = windowTarget.document.createTextNode(\"\");\n temporalObject.parentNode.insertBefore(node, temporalObject);\n caretPosition = 0;\n }\n\n temporalObject.parentNode.removeChild(temporalObject);\n\n return {\n node,\n caretPosition,\n };\n }\n\n if (range.length > 1) {\n return null;\n }\n\n return {\n node: range.item(0),\n };\n }\n\n if (windowTarget.getSelection) {\n let range;\n const selection = windowTarget.getSelection();\n\n try {\n range = selection.getRangeAt(0);\n } catch (e) {\n range = windowTarget.document.createRange();\n }\n\n const node = range.startContainer;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return {\n node,\n caretPosition: range.startOffset,\n };\n }\n\n if (node !== range.endContainer) {\n return null;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n const position = range.startOffset;\n\n if (node.childNodes[position]) {\n // In case that a formula is detected but not selected,\n // we create an empty span where we could insert the new formula.\n if (range.startOffset === range.endOffset) {\n if (\n position !== 0 &&\n node.childNodes[position - 1].localName === \"span\" &&\n node.childNodes[position].classList?.contains(\"Wirisformula\")\n ) {\n node.childNodes[position - 1].remove();\n return Util.getSelectedItem(target, isIframe, forceGetSelection);\n }\n if (node.childNodes[position].classList?.contains(\"Wirisformula\")) {\n if (\n (position > 0 && node.childNodes[position - 1].classList?.contains(\"Wirisformula\")) ||\n position === 0\n ) {\n const emptySpan = document.createElement(\"span\");\n node.insertBefore(emptySpan, node.childNodes[position]);\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n\n return null;\n }\n\n /**\n * Returns null if there isn't any item or if it is malformed.\n * Otherwise returns an object containing the node with the MathML image\n * and the cursor position inside the textarea.\n * @param {HTMLTextAreaElement} textarea - textarea element.\n * @returns {Object} An object containing the node, the index of the\n * beginning of the selected text, caret position and the start and end position of the\n * text node.\n * @static\n */\n static getSelectedItemOnTextarea(textarea) {\n const textNode = document.createTextNode(textarea.value);\n const textNodeValues = Latex.getLatexFromTextNode(textNode, textarea.selectionStart);\n if (textNodeValues === null) {\n return null;\n }\n\n return {\n node: textNode,\n caretPosition: textarea.selectionStart,\n startPosition: textNodeValues.startPosition,\n endPosition: textNodeValues.endPosition,\n };\n }\n\n /**\n * Looks for elements that match the given name in a HTML code string.\n * Important: this function is very concrete for WIRIS code.\n * It takes as preconditions lots of behaviors that are not the general case.\n * @param {string} code - HTML code.\n * @param {string} name - element name.\n * @param {boolean} autoClosed - true if the elements are autoClosed.\n * @return {Object[]} an object containing all HTML elements of code matching the name argument.\n * @static\n */\n static getElementsByNameFromString(code, name, autoClosed) {\n const elements = [];\n code = code.toLowerCase();\n name = name.toLowerCase();\n let start = code.indexOf(`<${name} `);\n\n while (start !== -1) {\n // Look for nodes.\n let endString;\n\n if (autoClosed) {\n endString = \">\";\n } else {\n endString = ``;\n }\n\n let end = code.indexOf(endString, start);\n\n if (end !== -1) {\n end += endString.length;\n elements.push({\n start,\n end,\n });\n } else {\n end = start + 1;\n }\n\n start = code.indexOf(`<${name} `, end);\n }\n\n return elements;\n }\n\n /**\n * Returns the numeric value of a base64 character.\n * @param {string} character - base64 character.\n * @returns {number} base64 character numeric value.\n * @static\n */\n static decode64(character) {\n const PLUS = \"+\".charCodeAt(0);\n const SLASH = \"/\".charCodeAt(0);\n const NUMBER = \"0\".charCodeAt(0);\n const LOWER = \"a\".charCodeAt(0);\n const UPPER = \"A\".charCodeAt(0);\n const PLUS_URL_SAFE = \"-\".charCodeAt(0);\n const SLASH_URL_SAFE = \"_\".charCodeAt(0);\n const code = character.charCodeAt(0);\n\n if (code === PLUS || code === PLUS_URL_SAFE) {\n return 62; // Char '+'.\n }\n if (code === SLASH || code === SLASH_URL_SAFE) {\n return 63; // Char '/'.\n }\n if (code < NUMBER) {\n return -1; // No match.\n }\n if (code < NUMBER + 10) {\n return code - NUMBER + 26 + 26;\n }\n if (code < UPPER + 26) {\n return code - UPPER;\n }\n if (code < LOWER + 26) {\n return code - LOWER + 26;\n }\n\n return null;\n }\n\n /**\n * Converts a base64 string to a array of bytes.\n * @param {string} b64String - base64 string.\n * @param {number} length - dimension of byte array (by default whole string).\n * @return {Object[]} the resultant byte array.\n * @static\n */\n static b64ToByteArray(b64String, length) {\n let tmp;\n\n if (b64String.length % 4 > 0) {\n throw new Error(\"Invalid string. Length must be a multiple of 4\"); // Tipped base64. Length is fixed.\n }\n\n const arr = [];\n\n let l;\n let placeHolders;\n if (!length) {\n // All b64String string.\n if (b64String.charAt(b64String.length - 2) === \"=\") {\n placeHolders = 2;\n } else if (b64String.charAt(b64String.length - 1) === \"=\") {\n placeHolders = 1;\n } else {\n placeHolders = 0;\n }\n l = placeHolders > 0 ? b64String.length - 4 : b64String.length;\n } else {\n l = length;\n }\n\n let i;\n for (i = 0; i < l; i += 4) {\n // Ignoring code checker standards (bitewise operators).\n // See https://tracker.moodle.org/browse/CONTRIB-5862 for further information.\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 18) |\n (Util.decode64(b64String.charAt(i + 1)) << 12) |\n (Util.decode64(b64String.charAt(i + 2)) << 6) |\n Util.decode64(b64String.charAt(i + 3));\n\n arr.push((tmp >> 16) & 0xff);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n\n if (placeHolders) {\n if (placeHolders === 2) {\n // Ignoring code checker standards (bitewise operators).\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp = (Util.decode64(b64String.charAt(i)) << 2) | (Util.decode64(b64String.charAt(i + 1)) >> 4);\n arr.push(tmp & 0xff);\n } else if (placeHolders === 1) {\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 10) |\n (Util.decode64(b64String.charAt(i + 1)) << 4) |\n (Util.decode64(b64String.charAt(i + 2)) >> 2);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n }\n return arr;\n }\n\n /**\n * Returns the first 32-bit signed integer from a byte array.\n * @param {Object[]} bytes - array of bytes.\n * @returns {number} the 32-bit signed integer.\n * @static\n */\n static readInt32(bytes) {\n if (bytes.length < 4) {\n return false;\n }\n const int32 = bytes.splice(0, 4);\n // @codingStandardsIgnoreStart¡\n return (int32[0] << 24) | (int32[1] << 16) | (int32[2] << 8) | (int32[3] << 0);\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read the first byte from a byte array.\n * @param {Object} bytes - input byte array.\n * @returns {number} first byte of the byte array.\n * @static\n */\n static readByte(bytes) {\n // @codingStandardsIgnoreStart\n return bytes.shift() << 0;\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read an arbitrary number of bytes, from a fixed position on a byte array.\n * @param {Object[]} bytes - byte array.\n * @param {number} pos - start position.\n * @param {number} len - number of bytes to read.\n * @returns {Object[]} the byte array.\n * @static\n */\n static readBytes(bytes, pos, len) {\n return bytes.splice(pos, len);\n }\n\n /**\n * Inserts or modifies formulas or CAS on a textarea.\n * @param {HTMLTextAreaElement} textarea - textarea target.\n * @param {string} text - text to add in the textarea. For example, to add the link to the image,\n * call this function as (textarea, Parser.createImageSrc(mathml));\n * @static\n */\n static updateTextArea(textarea, text) {\n if (textarea && text) {\n textarea.focus();\n\n if (textarea.selectionStart != null) {\n const { selectionEnd } = textarea;\n const selectionStart = textarea.value.substring(0, textarea.selectionStart);\n const selectionEndSub = textarea.value.substring(selectionEnd, textarea.value.length);\n textarea.value = selectionStart + text + selectionEndSub;\n textarea.selectionEnd = selectionEnd + text.length;\n } else {\n const selection = document.selection.createRange();\n selection.text = text;\n }\n }\n }\n\n /**\n * Modifies existing formula on a textarea.\n * @param {HTMLTextAreaElement} textarea - text area target.\n * @param {string} text - text to add in the textarea. For example, if you want to add the link\n * to the image,you can call this function as\n * Util.updateTextarea(textarea, Parser.createImageSrc(mathml));\n * @param {number} start - beginning index from textarea where it needs to be replaced by text.\n * @param {number} end - ending index from textarea where it needs to be replaced by text\n * @static\n */\n static updateExistingTextOnTextarea(textarea, text, start, end) {\n textarea.focus();\n const textareaStart = textarea.value.substring(0, start);\n textarea.value = textareaStart + text + textarea.value.substring(end, textarea.value.length);\n textarea.selectionEnd = start + text.length;\n }\n\n /**\n * Add a parameter with it's correspondent value to an URL (GET).\n * @param {string} path - URL path\n * @param {string} parameter - parameter\n * @param {string} value - value\n * @static\n */\n static addArgument(path, parameter, value) {\n let sep;\n if (path.indexOf(\"?\") > 0) {\n sep = \"&\";\n } else {\n sep = \"?\";\n }\n return `${path + sep + parameter}=${value}`;\n }\n}\n","import Configuration from \"./configuration\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents MathType Image class. Contains all the logic related\n * to MathType images manipulation.\n * All MathType images are generated using the appropriate MathType\n * integration service: showimage or createimage.\n *\n * There are two available image formats:\n * - svg (default)\n * - png\n *\n * There are two formats for the image src attribute:\n * - A data-uri scheme containing the URL-encoded SVG or a PNG's base64.\n * - A link to the showimage service.\n */\nexport default class Image {\n /**\n * Removes data attributes from an image.\n * @param {HTMLImageElement} img - Image where remove data attributes.\n */\n static removeImgDataAttributes(img) {\n const attributesToRemove = [];\n const { attributes } = img;\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key];\n if (attribute !== undefined && attribute.name !== undefined && attribute.name.indexOf(\"data-\") === 0) {\n // Is preferred keep an array and remove after the search\n // because when attribute is removed the array of attributes\n // is modified.\n attributesToRemove.push(attribute.name);\n }\n });\n\n attributesToRemove.forEach((attribute) => {\n img.removeAttribute(attribute);\n });\n }\n\n /**\n * @static\n * Clones all MathType image attributes from a HTMLImageElement to another.\n * @param {HTMLImageElement} originImg - The original image.\n * @param {HTMLImageElement} destImg - The destination image.\n */\n static clone(originImg, destImg) {\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (!originImg.hasAttribute(customEditorAttributeName)) {\n destImg.removeAttribute(customEditorAttributeName);\n }\n\n const mathmlAttributeName = Configuration.get(\"imageMathmlAttribute\");\n const imgAttributes = [\n mathmlAttributeName,\n customEditorAttributeName,\n \"alt\",\n \"height\",\n \"width\",\n \"style\",\n \"src\",\n \"role\",\n ];\n\n imgAttributes.forEach((iterator) => {\n const originAttribute = originImg.getAttribute(iterator);\n if (originAttribute) {\n destImg.setAttribute(iterator, originAttribute);\n }\n });\n }\n\n /**\n * Determines whether an img src contains an SVG.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src contains an SVG, false otherwise\n */\n static isSvg(img) {\n return img.src.startsWith(\"data:image/svg+xml;\");\n }\n\n /**\n * Determines whether an img src is encoded in base64 or not.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src is encoded in base64, false otherwise\n */\n static isBase64(img) {\n return img.src.startsWith(\"data:image/svg+xml;base64,\") || img.src.startsWith(\"data:image/png;base64,\");\n }\n\n /**\n * Calculates the metrics of a MathType image given the the service response and the image format.\n * @param {HTMLImageElement} img - The HTMLImageElement.\n * @param {String} uri - The URI generated by the image service: can be a data URI scheme or a URL.\n * @param {Boolean} jsonResponse - True the response of the image service is a\n * JSON object. False otherwise.\n */\n static setImgSize(img, uri, jsonResponse) {\n let ar;\n let base64String;\n let bytes;\n let svgString;\n if (jsonResponse) {\n // Cleaning data:image/png;base64.\n if (Image.isSvg(img)) {\n // SVG format.\n // If SVG is encoded in base64 we need to convert the base64 bytes into a SVG string.\n if (!Image.isBase64(img)) {\n ar = Image.getMetricsFromSvgString(uri);\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n svgString = \"\";\n bytes = Util.b64ToByteArray(base64String, base64String.length);\n for (let i = 0; i < bytes.length; i += 1) {\n svgString += String.fromCharCode(bytes[i]);\n }\n ar = Image.getMetricsFromSvgString(svgString);\n }\n // PNG format: we store all metrics information in the first 88 bytes.\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n bytes = Util.b64ToByteArray(base64String, 88);\n ar = Image.getMetricsFromBytes(bytes);\n }\n // Backwards compatibility: we store the metrics into createimage response.\n } else {\n ar = Util.urlToAssArray(uri);\n }\n let width = ar.cw;\n if (!width) {\n return;\n }\n let height = ar.ch;\n let baseline = ar.cb;\n const { dpi } = ar;\n if (dpi) {\n width = (width * 96) / dpi;\n height = (height * 96) / dpi;\n baseline = (baseline * 96) / dpi;\n }\n img.width = width;\n img.height = height;\n img.style.verticalAlign = `-${height - baseline}px`;\n }\n\n /**\n * Calculates the metrics of an image which has been resized. Is used to restore the original\n * metrics of a resized image.\n * @param {HTMLImageElement } img - The resized HTMLImageElement.\n */\n static fixAfterResize(img) {\n img.removeAttribute(\"style\");\n img.removeAttribute(\"width\");\n img.removeAttribute(\"height\");\n // In order to avoid resize with max-width css property.\n img.style.maxWidth = \"none\";\n\n const processImg = (img) => {\n if (img.src.indexOf(\"data:image\") !== -1) {\n if (img.src.indexOf(\"data:image/svg+xml\") !== -1) {\n // Image is in base64: decode it in order to calculate the size, and then bring it back to base64\n // This is a bit of an ugly hack used to recycle the logic of Image.setImgSize instead of rewriting it\n // (which would actually make more sense for readibility and efficiency).\n if (img.src.indexOf(\"data:image/svg+xml;base64,\") !== -1) {\n // 'data:image/svg+xml;base64,'.length === 26\n const base64String = img.getAttribute(\"src\").substring(26);\n const svgString = window.atob(base64String);\n const encodedSvgString = encodeURIComponent(svgString);\n img.setAttribute(\"src\", `data:image/svg+xml;charset=utf8,${encodedSvgString}`);\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n // Return src to base64!\n img.setAttribute(\"src\", `data:image/svg+xml;base64,${base64String}`);\n } else {\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n }\n } else {\n // 'data:image/png;base64,' === 22.\n const base64 = img.src.substring(22, img.src.length);\n Image.setImgSize(img, base64, true);\n }\n } else {\n Image.setImgSize(img, img.src);\n }\n };\n\n // If the image doesn't contain a blob, just process it normally\n if (img.src.indexOf(\"blob:\") === -1) {\n processImg(img);\n // if it does contain a blob, then read that, replace the src with the decoded content, and process it\n } else {\n const reader = new FileReader();\n reader.onload = function () {\n img.setAttribute(\"src\", reader.result);\n processImg(img);\n };\n fetch(img.src)\n .then((r) => r.blob())\n .then((blob) => {\n reader.readAsDataURL(blob);\n });\n }\n }\n\n /**\n * Returns the metrics (height, width and baseline) contained in a SVG image generated\n * by the MathType image service. This image contains as an extra custom attribute:\n * the baseline (wrs:baseline).\n * @param {String} svgString - The SVG image.\n * @return {Array} - The image metrics.\n */\n static getMetricsFromSvgString(svgString) {\n let first = svgString.indexOf('height=\"');\n let last = svgString.indexOf('\"', first + 8, svgString.length);\n const height = svgString.substring(first + 8, last);\n\n first = svgString.indexOf('width=\"');\n last = svgString.indexOf('\"', first + 7, svgString.length);\n const width = svgString.substring(first + 7, last);\n\n first = svgString.indexOf('wrs:baseline=\"');\n last = svgString.indexOf('\"', first + 14, svgString.length);\n const baseline = svgString.substring(first + 14, last);\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n if (typeof baseline !== \"undefined\") {\n arr.cb = baseline;\n }\n return arr;\n }\n return [];\n }\n\n /**\n * Returns the metrics (width, height, baseline and dpi) contained in a PNG byte array.\n * @param {Array.} bytes - png byte array.\n * @return {Array} The png metrics.\n */\n static getMetricsFromBytes(bytes) {\n Util.readBytes(bytes, 0, 8);\n let width;\n let height;\n let typ;\n let baseline;\n let dpi;\n while (bytes.length >= 4) {\n typ = Util.readInt32(bytes);\n if (typ === 0x49484452) {\n width = Util.readInt32(bytes);\n height = Util.readInt32(bytes);\n // Read 5 bytes.\n Util.readInt32(bytes);\n Util.readByte(bytes);\n } else if (typ === 0x62615345) {\n // Baseline: 'baSE'.\n baseline = Util.readInt32(bytes);\n } else if (typ === 0x70485973) {\n // Dpis: 'pHYs'.\n dpi = Util.readInt32(bytes);\n dpi = Math.round(dpi / 39.37);\n Util.readInt32(bytes);\n Util.readByte(bytes);\n }\n Util.readInt32(bytes);\n }\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n arr.dpi = dpi;\n if (baseline) {\n arr.cb = baseline;\n }\n\n return arr;\n }\n return [];\n }\n}\n","import TextCache from \"./textcache\";\nimport ServiceProvider from \"./serviceprovider\";\nimport MathML from \"./mathml\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * @classdesc\n * This class represents MathType accessible class. Converts MathML to accessible text and manages\n * the associated client-side cache.\n */\nexport default class Accessibility {\n /**\n * Static property.\n * Accessibility cache, each entry contains a MathML and its correspondent accessibility text.\n * @type {TextCache}\n */\n static get cache() {\n return Accessibility._cache;\n }\n\n /**\n * Static property setter.\n * Set accessibility cache.\n * @param {TextCahe} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Accessibility._cache = value;\n }\n\n /**\n * Converts MathML strings to its accessible text representation.\n * @param {String} mathML - MathML to be converted to accessible text.\n * @param {String} [language] - Language of the accessible text. 'en' by default.\n * @param {Array.} [data] - Parameters to send to mathml2accessible service.\n * @return {String} Accessibility text.\n */\n static mathMLToAccessible(mathML, language, data) {\n if (typeof language === \"undefined\") {\n language = \"en\";\n }\n // Check MathML class. If the class is chemistry,\n // we add chemistry to data to force accessibility service\n // to load chemistry grammar.\n if (MathML.containClass(mathML, \"wrs_chemistry\")) {\n data.mode = \"chemistry\";\n }\n // Ignore accesibility styles\n data.ignoreStyles = true;\n let accessibleText = \"\";\n\n if (Accessibility.cache.get(mathML)) {\n accessibleText = Accessibility.cache.get(mathML);\n } else {\n data.service = \"mathml2accessible\";\n data.lang = language;\n const accessibleJsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n if (accessibleJsonResponse.status !== \"error\") {\n accessibleText = accessibleJsonResponse.result.text;\n Accessibility.cache.populate(mathML, accessibleText);\n } else {\n accessibleText = StringManager.get(\"error_convert_accessibility\");\n }\n }\n\n return accessibleText;\n }\n}\n\n/**\n * Contains an instance of TextCache class to manage the JavaScript accessible cache.\n * Each entry of the cache object contains the MathML and it's correspondent accessibility text.\n * @private\n * @type {TextCache}\n */\nAccessibility._cache = new TextCache();\n","import Util from \"./util\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport Image from \"./image\";\nimport Accessibility from \"./accessibility\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Configuration from \"./configuration\";\nimport Constants from \"./constants\";\n// eslint-disable-next-line no-unused-vars\nimport md5 from \"./md5\";\n\n/**\n * @classdesc\n * This class represent a MahML parser. Converts MathML into formulas depending on the\n * image format (SVG, PNG, base64) and the save mode (XML, safeXML, Image) configured\n * in the backend.\n */\nexport default class Parser {\n /**\n * Converts a MathML string to an img element.\n * @param {Document} creator - Document object to call createElement method.\n * @param {string} mathml - MathML code\n * @param {Object[]} wirisProperties - object containing WIRIS custom properties\n * @param {language} language - custom language for accessibility.\n * @returns {HTMLImageElement} the formula image corresponding to initial MathML string.\n * @static\n */\n static mathmlToImgObject(creator, mathml, wirisProperties, language) {\n const imgObject = creator.createElement(\"img\");\n imgObject.align = \"middle\";\n imgObject.style.maxWidth = \"none\";\n let data = wirisProperties || {};\n\n // Take into account the backend config\n const wirisEditorProperties = Configuration.get(\"editorParameters\");\n data = { ...wirisEditorProperties, ...data };\n\n data.mml = mathml;\n data.lang = language;\n // Request metrics of the generated image.\n data.metrics = \"true\";\n data.centerbaseline = \"false\";\n\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n // Render js params: _wrs_int_wirisProperties contains some js render params.\n // Since MathML can support render params, js params should be send only to editor.\n\n imgObject.className = Configuration.get(\"imageClassName\");\n\n if (mathml.indexOf('class=\"') !== -1) {\n // We check here if the MathML has been created from a customEditor (such chemistry)\n // to add custom editor name attribute to img object (if necessary).\n let mathmlSubstring = mathml.substring(mathml.indexOf('class=\"') + 'class=\"'.length, mathml.length);\n mathmlSubstring = mathmlSubstring.substring(0, mathmlSubstring.indexOf('\"'));\n mathmlSubstring = mathmlSubstring.substring(4, mathmlSubstring.length);\n imgObject.setAttribute(Configuration.get(\"imageCustomEditorName\"), mathmlSubstring);\n }\n\n // Performance enabled.\n if (\n Configuration.get(\"wirisPluginPerformance\") &&\n (Configuration.get(\"saveMode\") === \"xml\" || Configuration.get(\"saveMode\") === \"safeXml\")\n ) {\n let result = JSON.parse(Parser.createShowImageSrc(data, language));\n if (result.status === \"warning\") {\n // POST call.\n // if the mathml is malformed, this function will throw an exception.\n try {\n result = JSON.parse(ServiceProvider.getService(\"showimage\", data));\n } catch (e) {\n return null;\n }\n }\n ({ result } = result);\n if (result.format === \"png\") {\n imgObject.src = `data:image/png;base64,${result.content}`;\n } else {\n imgObject.src = `data:image/svg+xml;charset=utf8,${Util.urlEncode(result.content)}`;\n }\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n Image.setImgSize(imgObject, result.content, true);\n\n if (Configuration.get(\"enableAccessibility\")) {\n if (typeof result.alt === \"undefined\") {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n } else {\n imgObject.alt = result.alt;\n }\n }\n } else {\n const result = Parser.createImageSrc(mathml, data);\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n imgObject.src = result;\n Image.setImgSize(\n imgObject,\n result,\n Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\",\n );\n if (Configuration.get(\"enableAccessibility\")) {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n }\n }\n\n if (typeof Parser.observer !== \"undefined\") {\n Parser.observer.observe(imgObject);\n }\n\n // Role math https://www.w3.org/TR/wai-aria/roles#math.\n imgObject.setAttribute(\"role\", \"math\");\n return imgObject;\n }\n\n /**\n * Returns the source to showimage service by calling createimage service. The\n * output of the createimage service is a URL path pointing to showimage service.\n * This method is called when performance is disabled.\n * @param {string} mathml - MathML code.\n * @param {Object[]} data - data object containing service parameters.\n * @returns {string} the showimage path.\n */\n static createImageSrc(mathml, data) {\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n let result = ServiceProvider.getService(\"createimage\", data);\n\n if (result.indexOf(\"@BASE@\") !== -1) {\n // Replacing '@BASE@' with the base URL of createimage.\n const baseParts = ServiceProvider.getServicePath(\"createimage\").split(\"/\");\n baseParts.pop();\n result = result.split(\"@BASE@\").join(baseParts.join(\"/\"));\n }\n\n return result;\n }\n\n /**\n * Parses initial HTML code. If the HTML contains data generated by WIRIS,\n * this data would be converted as following:\n *
\n   * MathML code: Image containing the corresponding MathML formulas.\n   * MathML code with LaTeX annotation : LaTeX string.\n   * 
\n * @param {string} code - HTML code containing MathML data.\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code with the original MathML converted into LaTeX and images.\n */\n static initParse(code, language) {\n /* Note: The code inside this function has been inverted.\n If you invert again the code then you cannot use correctly LaTeX\n in Moodle.\n */\n code = Parser.initParseSaveMode(code, language);\n return Parser.initParseEditMode(code);\n }\n\n /**\n * Parses initial HTML code depending on the save mode. Transforms all MathML\n * occurrences for it's correspondent image or LaTeX.\n * @param {string} code - HTML code to be parsed\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code parsed.\n */\n static initParseSaveMode(code, language) {\n if (Configuration.get(\"saveMode\")) {\n // Converting XML to tags.\n code = Latex.parseMathmlToLatex(code, Constants.safeXmlCharacters);\n code = Latex.parseMathmlToLatex(code, Constants.xmlCharacters);\n code = Parser.parseMathmlToImg(code, Constants.safeXmlCharacters, language);\n code = Parser.parseMathmlToImg(code, Constants.xmlCharacters, language);\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"image\") {\n code = Parser.codeImgTransform(code, \"base642showimage\");\n }\n }\n return code;\n }\n\n /**\n * Parses initial HTML code depending on the edit mode.\n * If 'latex' parseMode is enabled all MathML containing an annotation with encoding='LaTeX' will\n * be converted into a LaTeX string instead of an image.\n * @param {string} code - HTML code containing MathML.\n * @returns {string} parsed HTML code.\n */\n static initParseEditMode(code) {\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n const imgList = Util.getElementsByNameFromString(code, \"img\", true);\n const token = 'encoding=\"LaTeX\">';\n // While replacing images with latex, the indexes of the found images changes\n // respecting the original code, so this carry is needed.\n let carry = 0;\n\n for (let i = 0; i < imgList.length; i += 1) {\n const imgCode = code.substring(imgList[i].start + carry, imgList[i].end + carry);\n\n if (imgCode.indexOf(` class=\"${Configuration.get(\"imageClassName\")}\"`) !== -1) {\n let mathmlStartToken = ` ${Configuration.get(\"imageMathmlAttribute\")}=\"`;\n let mathmlStart = imgCode.indexOf(mathmlStartToken);\n\n if (mathmlStart === -1) {\n mathmlStartToken = ' alt=\"';\n mathmlStart = imgCode.indexOf(mathmlStartToken);\n }\n\n if (mathmlStart !== -1) {\n mathmlStart += mathmlStartToken.length;\n const mathmlEnd = imgCode.indexOf('\"', mathmlStart);\n const mathml = Util.htmlSanitize(MathML.safeXmlDecode(imgCode.substring(mathmlStart, mathmlEnd)));\n let latexStartPosition = mathml.indexOf(token);\n\n if (latexStartPosition !== -1) {\n latexStartPosition += token.length;\n const latexEndPosition = mathml.indexOf(\"\", latexStartPosition);\n const latex = mathml.substring(latexStartPosition, latexEndPosition);\n\n const replaceText = `$$${Util.htmlEntitiesDecode(latex)}$$`;\n const start = code.substring(0, imgList[i].start + carry);\n const end = code.substring(imgList[i].end + carry);\n code = start + replaceText + end;\n carry += replaceText.length - (imgList[i].end - imgList[i].start);\n }\n }\n }\n }\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code. The end HTML code is HTML code with embedded images\n * or LaTeX formulas created with MathType.
\n * By default this method converts the formula images and LaTeX strings in MathML.
\n * If image mode is enabled the images will not be converted into MathML. For further information see {@link https://docs.wiris.com/mathtype/en/mathtype-integrations/mathtype-web-interface-features/full-mathml-mode---wirisplugins-js.html}.\n * @param {string} code - HTML to be parsed\n * @returns {string} the HTML code parsed.\n */\n static endParse(code) {\n // Transform LaTeX ocurrences to MathML elements.\n const codeEndParsedEditMode = Parser.endParseEditMode(code);\n // Transform img elements to MathML elements.\n const codeEndParseSaveMode = Parser.endParseSaveMode(codeEndParsedEditMode);\n return codeEndParseSaveMode;\n }\n\n /**\n * Parses end HTML code depending on the edit mode.\n * - LaTeX is an enabled parse mode, all LaTeX occurrences will be converted into MathML.\n * @param {string} code - HTML code to be parsed.\n * @returns {string} HTML code parsed.\n */\n static endParseEditMode(code) {\n // Converting LaTeX to images.\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n let output = \"\";\n let endPosition = 0;\n let startPosition = code.indexOf(\"$$\");\n while (startPosition !== -1) {\n output += code.substring(endPosition, startPosition);\n endPosition = code.indexOf(\"$$\", startPosition + 2);\n\n if (endPosition !== -1) {\n // Before, it was a condition here to execute the next codelines\n // 'latex.indexOf('<') == -1'.\n // We don't know why it was used, but seems to have a conflict with\n // latex formulas that contains '<'.\n const latex = code.substring(startPosition + 2, endPosition);\n const decodedLatex = Util.htmlEntitiesDecode(latex);\n let mathml = Util.htmlSanitize(Latex.getMathMLFromLatex(decodedLatex, true));\n if (!Configuration.get(\"saveHandTraces\")) {\n // Remove hand traces.\n mathml = MathML.removeAnnotation(mathml, \"application/json\");\n }\n output += mathml;\n endPosition += 2;\n } else {\n output += \"$$\";\n endPosition = startPosition + 2;\n }\n\n startPosition = code.indexOf(\"$$\", endPosition);\n }\n\n output += code.substring(endPosition, code.length);\n code = output;\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code depending on the save mode. Converts all\n * images into the element determined by the save mode:\n * - xml: Parses images formulas into MathML.\n * - safeXml: Parses images formulas into safeMAthML\n * - base64: Parses images into base64 images.\n * - image: Parse images into images (no parsing)\n * @param {string} code - HTML code to be parsed\n * @returns {string} HTML code parsed.\n */\n static endParseSaveMode(code) {\n const savemode = Configuration.get(\"saveMode\");\n const base64savemode = Configuration.get(\"base64savemode\");\n\n if (savemode) {\n if (savemode === \"safeXml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"xml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"base64\" && base64savemode === \"image\") {\n code = Parser.codeImgTransform(code, \"img264\");\n }\n }\n\n return code;\n }\n\n /**\n * Auxiliar function that builds the data object to send to the showimage endpoint\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object with the data to send to showimage.\n */\n static createShowImageSrcData(data, language) {\n const dataMd5 = {};\n const renderParams = [\n \"mml\",\n \"color\",\n \"centerbaseline\",\n \"zoom\",\n \"dpi\",\n \"fontSize\",\n \"fontFamily\",\n \"defaultStretchy\",\n \"backgroundColor\",\n \"format\",\n ];\n renderParams.forEach((param) => {\n if (typeof data[param] !== \"undefined\") {\n dataMd5[param] = data[param];\n }\n });\n // Data variables to get.\n const dataObject = {};\n Object.keys(data).forEach((key) => {\n // We don't need mathml in this request we try to get cached.\n // Only need the formula md5 calculated before.\n if (key !== \"mml\") {\n dataObject[key] = data[key];\n }\n });\n\n dataObject.formula = com.wiris.js.JsPluginTools.md5encode(Util.propertiesToString(dataMd5));\n dataObject.lang = typeof language === \"undefined\" ? \"en\" : language;\n dataObject.version = Configuration.get(\"version\");\n\n return dataObject;\n }\n\n /**\n * Returns the result to call showimage service with the formula md5 as parameter.\n * The result could be:\n * - {'status' : warning'} : The image associated to the MathML md5 is not in cache.\n * - {'status' : 'ok' ...} : The image associated to the MathML md5 is in cache.\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object containing showimage response.\n */\n static createShowImageSrc(data, language) {\n const dataObject = this.createShowImageSrcData(data, language);\n const result = ServiceProvider.getService(\"showimage\", Util.httpBuildQuery(dataObject), true);\n return result;\n }\n\n /**\n * Transform html img tags inside a html code to mathml, base64 img tags (i.e with base64 on src)\n * or showimage img tags (i.e with showimage.php on src)\n * @param {string} code - HTML code\n * @param {string} mode - base642showimage or img2mathml or img264 transform.\n * @returns {string} html - code transformed.\n */\n static codeImgTransform(code, mode) {\n let output = \"\";\n let endPosition = 0;\n const pattern = /\") {\n endPosition = i + 1;\n }\n\n i += 1;\n }\n\n if (endPosition < startPosition) {\n // The img tag is stripped.\n output += code.substring(startPosition, code.length);\n return output;\n }\n let imgCode = code.substring(startPosition, endPosition);\n const imgObject = Util.createObject(imgCode);\n let xmlCode = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n let convertToXml;\n let convertToSafeXml;\n\n if (mode === \"base642showimage\") {\n if (xmlCode == null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n imgCode = Parser.mathmlToImgObject(document, xmlCode, null, null);\n output += Util.createObjectCode(imgCode);\n } else if (mode === \"img2mathml\") {\n if (Configuration.get(\"saveMode\")) {\n if (Configuration.get(\"saveMode\") === \"safeXml\") {\n convertToXml = true;\n convertToSafeXml = true;\n } else if (Configuration.get(\"saveMode\") === \"xml\") {\n convertToXml = true;\n convertToSafeXml = false;\n }\n }\n output += Util.getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml);\n } else if (mode === \"img264\") {\n if (xmlCode === null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n\n const properties = {};\n properties.base64 = \"true\";\n imgCode = Parser.mathmlToImgObject(document, xmlCode, properties, null);\n // Metrics.\n Image.setImgSize(imgCode, imgCode.src, true);\n output += Util.createObjectCode(imgCode);\n }\n }\n output += code.substring(endPosition, code.length);\n return output;\n }\n\n /**\n * Converts all occurrences of MathML to the corresponding image.\n * @param {string} content - string with valid MathML code.\n * The MathML code doesn't contain semantics.\n * @param {Constants} characters - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * @param {string} language - a valid language code\n * in order to generate formula accessibility.\n * @returns {string} The input string with all the MathML\n * occurrences replaced by the corresponding image.\n */\n static parseMathmlToImg(content, characters, language) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n\n while (start !== -1) {\n output += content.substring(end, start);\n // Avoid WIRIS images to be parsed.\n const imageMathmlAtrribute = content.indexOf(Configuration.get(\"imageMathmlAttribute\"));\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else if (imageMathmlAtrribute !== -1) {\n // First close tag of img attribute\n // If a mathmlAttribute exists should be inside a img tag.\n end += content.indexOf(\"/>\", start);\n } else {\n end += mathTagEnd.length;\n }\n\n if (!MathML.isMathmlInAttribute(content, start) && imageMathmlAtrribute === -1) {\n let mathml = content.substring(start, end);\n mathml =\n characters.id === Constants.safeXmlCharacters.id\n ? MathML.safeXmlDecode(mathml)\n : MathML.mathMLEntities(mathml);\n output += Util.createObjectCode(Parser.mathmlToImgObject(document, mathml, null, language));\n } else {\n output += content.substring(start, end);\n }\n\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n}\n\n// Mutation observers to avoid wiris image formulas class be removed.\nif (typeof MutationObserver !== \"undefined\") {\n const mutationObserver = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n if (\n mutation.oldValue === Configuration.get(\"imageClassName\") &&\n mutation.attributeName === \"class\" &&\n mutation.target.className.indexOf(Configuration.get(\"imageClassName\")) === -1\n ) {\n mutation.target.className = Configuration.get(\"imageClassName\");\n }\n });\n });\n\n Parser.observer = Object.create(mutationObserver);\n Parser.observer.Config = { attributes: true, attributeOldValue: true };\n // We use own default config.\n Parser.observer.observe = function (target) {\n Object.getPrototypeOf(this).observe(target, this.Config);\n };\n}\n","/* eslint-disable class-methods-use-this */\n/* eslint-disable no-unused-vars */\n/* eslint-disable no-extra-semi */\n\n// The rules above are disabled because we are implementing\n// an external interface.\n\nexport default class EditorListener {\n /**\n * @classdesc\n * Determines if the content of the\n * MathType Editor has changes.\n * @implements {EditorListeners}\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the content of the editor has changed.\n * @type {Boolean}\n */\n this.isContentChanged = false;\n\n /**\n * Indicates if the listener should be waiting for changes in the editor.\n * @type {Boolean}\n */\n this.waitingForChanges = false;\n }\n\n /**\n * Sets {@link EditorListener.isContentChanged} property.\n * @param {Boolean} value - The new vlue.\n */\n setIsContentChanged(value) {\n this.isContentChanged = value;\n }\n\n /**\n * Returns true if the content of the editor has been changed, false otherwise.\n * @return {Boolean}\n */\n getIsContentChanged() {\n return this.isContentChanged;\n }\n\n /**\n * Determines if the EditorListener should wait for any changes.\n * @param {Boolean} value - True if the editor should wait for changes, false otherwise.\n */\n setWaitingForChanges(value) {\n this.waitingForChanges = value;\n }\n\n /**\n * EditorListener method to overwrite.\n * @type {JsEditor}\n * @ignore\n */\n caretPositionChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @type {JsEditor}\n * @ignore\n */\n clipboardChanged(_editor) {}\n\n /**\n * Determines if the content of an editor has been changed.\n * @param {JsEditor} editor - editor object.\n */\n contentChanged(_editor) {\n if (this.waitingForChanges === true && this.isContentChanged === false) {\n this.isContentChanged = true;\n }\n }\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} editor - The editor instance.\n */\n styleChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} - The editor instance.\n */\n transformationReceived(_editor) {}\n}\n","let wasm;\n\nconst cachedTextDecoder =\n typeof TextDecoder !== \"undefined\"\n ? new TextDecoder(\"utf-8\", { ignoreBOM: true, fatal: true })\n : {\n decode: () => {\n throw Error(\"TextDecoder not available\");\n },\n };\n\nif (typeof TextDecoder !== \"undefined\") {\n cachedTextDecoder.decode();\n}\n\nlet cachedUint8Memory0 = null;\n\nfunction getUint8Memory0() {\n if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {\n cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8Memory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));\n}\n\nconst heap = new Array(128).fill(undefined);\n\nheap.push(undefined, null, true, false);\n\nlet heap_next = heap.length;\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction getObject(idx) {\n return heap[idx];\n}\n\nfunction dropObject(idx) {\n if (idx < 132) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nconst cachedTextEncoder =\n typeof TextEncoder !== \"undefined\"\n ? new TextEncoder(\"utf-8\")\n : {\n encode: () => {\n throw Error(\"TextEncoder not available\");\n },\n };\n\nconst encodeString =\n typeof cachedTextEncoder.encodeInto === \"function\"\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n }\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length,\n };\n };\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8Memory0()\n .subarray(ptr, ptr + buf.length)\n .set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8Memory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7f) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0;\n const view = getUint8Memory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nlet cachedInt32Memory0 = null;\n\nfunction getInt32Memory0() {\n if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {\n cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);\n }\n return cachedInt32Memory0;\n}\n\nlet cachedFloat64Memory0 = null;\n\nfunction getFloat64Memory0() {\n if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {\n cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);\n }\n return cachedFloat64Memory0;\n}\n\nlet cachedBigInt64Memory0 = null;\n\nfunction getBigInt64Memory0() {\n if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) {\n cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer);\n }\n return cachedBigInt64Memory0;\n}\n\nfunction debugString(val) {\n // primitive types\n const type = typeof val;\n if (type == \"number\" || type == \"boolean\" || val == null) {\n return `${val}`;\n }\n if (type == \"string\") {\n return `\"${val}\"`;\n }\n if (type == \"symbol\") {\n const description = val.description;\n if (description == null) {\n return \"Symbol\";\n } else {\n return `Symbol(${description})`;\n }\n }\n if (type == \"function\") {\n const name = val.name;\n if (typeof name == \"string\" && name.length > 0) {\n return `Function(${name})`;\n } else {\n return \"Function\";\n }\n }\n // objects\n if (Array.isArray(val)) {\n const length = val.length;\n let debug = \"[\";\n if (length > 0) {\n debug += debugString(val[0]);\n }\n for (let i = 1; i < length; i++) {\n debug += \", \" + debugString(val[i]);\n }\n debug += \"]\";\n return debug;\n }\n // Test for built-in\n const builtInMatches = /\\[object ([^\\]]+)\\]/.exec(toString.call(val));\n let className;\n if (builtInMatches.length > 1) {\n className = builtInMatches[1];\n } else {\n // Failed to match the standard '[object ClassName]'\n return toString.call(val);\n }\n if (className == \"Object\") {\n // we're a user defined class or Object\n // JSON.stringify avoids problems with cycles, and is generally much\n // easier than looping through ownProperties of `val`.\n try {\n return \"Object(\" + JSON.stringify(val) + \")\";\n } catch (_) {\n return \"Object\";\n }\n }\n // errors\n if (val instanceof Error) {\n return `${val.name}: ${val.message}\\n${val.stack}`;\n }\n // TODO we could test for more things here, like `Set`s and `Map`s.\n return className;\n}\n\nfunction makeClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n try {\n return f(state.a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);\n state.a = 0;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_46(arg0, arg1, arg2) {\n wasm.__wbindgen_export_3(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction makeMutClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n const a = state.a;\n state.a = 0;\n try {\n return f(a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);\n } else {\n state.a = a;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_49(arg0, arg1) {\n wasm.__wbindgen_export_4(arg0, arg1);\n}\n\nfunction __wbg_adapter_52(arg0, arg1, arg2) {\n wasm.__wbindgen_export_5(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction handleError(f, args) {\n try {\n return f.apply(this, args);\n } catch (e) {\n wasm.__wbindgen_export_6(addHeapObject(e));\n }\n}\nfunction __wbg_adapter_103(arg0, arg1, arg2, arg3) {\n wasm.__wbindgen_export_7(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));\n}\n\n/**\n */\nexport function main_js() {\n wasm.main_js();\n}\n\nfunction getArrayU8FromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);\n}\n/**\n */\nexport const Level = Object.freeze({\n Err: 0,\n 0: \"Err\",\n Warn: 1,\n 1: \"Warn\",\n Info: 2,\n 2: \"Info\",\n Debug: 3,\n 3: \"Debug\",\n});\n/**\n */\nexport class Telemeter {\n __destroy_into_raw() {\n const ptr = this.__wbg_ptr;\n this.__wbg_ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_telemeter_free(ptr);\n }\n /**\n * @param {any} solution\n * @param {any} hosts\n * @param {any} config\n */\n constructor(solution, hosts, config) {\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n wasm.telemeter_new(retptr, addHeapObject(solution), addHeapObject(hosts), addHeapObject(config));\n var r0 = getInt32Memory0()[retptr / 4 + 0];\n var r1 = getInt32Memory0()[retptr / 4 + 1];\n var r2 = getInt32Memory0()[retptr / 4 + 2];\n if (r2) {\n throw takeObject(r1);\n }\n this.__wbg_ptr = r0 >>> 0;\n return this;\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n }\n }\n /**\n * @param {string} sender_id\n * @returns {Promise}\n */\n identify(sender_id) {\n const ptr0 = passStringToWasm0(sender_id, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_identify(this.__wbg_ptr, ptr0, len0);\n return takeObject(ret);\n }\n /**\n * @param {string} event_type\n * @param {any} event_payload\n * @returns {Promise}\n */\n track(event_type, event_payload) {\n const ptr0 = passStringToWasm0(event_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_track(this.__wbg_ptr, ptr0, len0, addHeapObject(event_payload));\n return takeObject(ret);\n }\n /**\n * @param {any} level\n * @param {string} message\n * @param {any} payload\n * @returns {Promise}\n */\n log(level, message, payload) {\n const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_log(this.__wbg_ptr, addHeapObject(level), ptr0, len0, addHeapObject(payload));\n return takeObject(ret);\n }\n /**\n * @returns {Promise}\n */\n finish() {\n const ptr = this.__destroy_into_raw();\n const ret = wasm.telemeter_finish(ptr);\n return takeObject(ret);\n }\n /**\n * @param {boolean | undefined} [new_debug_status]\n */\n debug(new_debug_status) {\n wasm.telemeter_debug(this.__wbg_ptr, isLikeNone(new_debug_status) ? 0xffffff : new_debug_status ? 1 : 0);\n }\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === \"function\" && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === \"function\") {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n if (module.headers.get(\"Content-Type\") != \"application/wasm\") {\n console.warn(\n \"`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",\n e,\n );\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n}\n\nfunction __wbg_get_imports() {\n const imports = {};\n imports.wbg = {};\n imports.wbg.__wbindgen_string_new = function (arg0, arg1) {\n const ret = getStringFromWasm0(arg0, arg1);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_c728d68b8b34487e = function () {\n const ret = new Object();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_status_7841bb47be2a8f16 = function (arg0) {\n const ret = getObject(arg0).status;\n return ret;\n };\n imports.wbg.__wbg_headers_ea7ef583d1564b08 = function (arg0) {\n const ret = getObject(arg0).headers;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new0_ad75dd38f92424e2 = function () {\n const ret = new Date();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getTime_ed6ee333b702f8fc = function (arg0) {\n const ret = getObject(arg0).getTime();\n return ret;\n };\n imports.wbg.__wbindgen_object_drop_ref = function (arg0) {\n takeObject(arg0);\n };\n imports.wbg.__wbindgen_is_object = function (arg0) {\n const val = getObject(arg0);\n const ret = typeof val === \"object\" && val !== null;\n return ret;\n };\n imports.wbg.__wbg_crypto_58f13aa23ffcb166 = function (arg0) {\n const ret = getObject(arg0).crypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_process_5b786e71d465a513 = function (arg0) {\n const ret = getObject(arg0).process;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_versions_c2ab80650590b6a2 = function (arg0) {\n const ret = getObject(arg0).versions;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_node_523d7bd03ef69fba = function (arg0) {\n const ret = getObject(arg0).node;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_string = function (arg0) {\n const ret = typeof getObject(arg0) === \"string\";\n return ret;\n };\n imports.wbg.__wbg_msCrypto_abcb1295e768d1f2 = function (arg0) {\n const ret = getObject(arg0).msCrypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_require_2784e593a4674877 = function () {\n return handleError(function () {\n const ret = module.require;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_newwithlength_13b5319ab422dcf6 = function (arg0) {\n const ret = new Uint8Array(arg0 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_4a9aa5157afeb382 = function (arg0, arg1) {\n const ret = getObject(arg0)[arg1 >>> 0];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_next_1989a20442400aaa = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).next();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_done_bc26bf4ada718266 = function (arg0) {\n const ret = getObject(arg0).done;\n return ret;\n };\n imports.wbg.__wbg_value_0570714ff7d75f35 = function (arg0) {\n const ret = getObject(arg0).value;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_iterator_7ee1a391d310f8e4 = function () {\n const ret = Symbol.iterator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_2aff440840bb6202 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.get(getObject(arg0), getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_next_15da6a3df9290720 = function (arg0) {\n const ret = getObject(arg0).next;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_function = function (arg0) {\n const ret = typeof getObject(arg0) === \"function\";\n return ret;\n };\n imports.wbg.__wbg_call_669127b9d730c650 = function () {\n return handleError(function (arg0, arg1) {\n const ret = getObject(arg0).call(getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_object_clone_ref = function (arg0) {\n const ret = getObject(arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_self_3fad056edded10bd = function () {\n return handleError(function () {\n const ret = self.self;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_window_a4f46c98a61d4089 = function () {\n return handleError(function () {\n const ret = window.window;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_globalThis_17eff828815f7d84 = function () {\n return handleError(function () {\n const ret = globalThis.globalThis;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_global_46f939f6541643c5 = function () {\n return handleError(function () {\n const ret = global.global;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_is_undefined = function (arg0) {\n const ret = getObject(arg0) === undefined;\n return ret;\n };\n imports.wbg.__wbg_newnoargs_ccdcae30fd002262 = function (arg0, arg1) {\n const ret = new Function(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_isArray_38525be7442aa21e = function (arg0) {\n const ret = Array.isArray(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_call_53fc3abd42e24ec8 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_isSafeInteger_c38b0a16d0c7cef7 = function (arg0) {\n const ret = Number.isSafeInteger(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_new_feb65b865d980ae2 = function (arg0, arg1) {\n try {\n var state0 = { a: arg0, b: arg1 };\n var cb0 = (arg0, arg1) => {\n const a = state0.a;\n state0.a = 0;\n try {\n return __wbg_adapter_103(a, state0.b, arg0, arg1);\n } finally {\n state0.a = a;\n }\n };\n const ret = new Promise(cb0);\n return addHeapObject(ret);\n } finally {\n state0.a = state0.b = 0;\n }\n };\n imports.wbg.__wbindgen_memory = function () {\n const ret = wasm.memory;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_buffer_344d9b41efe96da7 = function (arg0) {\n const ret = getObject(arg0).buffer;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_d8a000788389a31e = function (arg0) {\n const ret = new Uint8Array(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_set_dcfd613a3420f908 = function (arg0, arg1, arg2) {\n getObject(arg0).set(getObject(arg1), arg2 >>> 0);\n };\n imports.wbg.__wbg_length_a5587d6cd79ab197 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbindgen_string_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"string\" ? obj : undefined;\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_stringify_4039297315a25b00 = function () {\n return handleError(function (arg0) {\n const ret = JSON.stringify(getObject(arg0));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_set_40f7786a25a9cc7e = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_has_cdf8b85f6e903c80 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.has(getObject(arg0), getObject(arg1));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_fetch_701fcd2bde06379a = function (arg0, arg1) {\n const ret = getObject(arg0).fetch(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_fetch_b5d6bebed1e6c2d2 = function (arg0) {\n const ret = fetch(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_newwithbyteoffsetandlength_2dc04d99088b15e3 = function (arg0, arg1, arg2) {\n const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_e4960143e41697a4 = function () {\n return handleError(function () {\n const ret = new AbortController();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_signal_1ed842bebd6ae322 = function (arg0) {\n const ret = getObject(arg0).signal;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_abort_8355f201f30300bb = function (arg0) {\n getObject(arg0).abort();\n };\n imports.wbg.__wbindgen_error_new = function (arg0, arg1) {\n const ret = new Error(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_loose_eq = function (arg0, arg1) {\n const ret = getObject(arg0) == getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_boolean_get = function (arg0) {\n const v = getObject(arg0);\n const ret = typeof v === \"boolean\" ? (v ? 1 : 0) : 2;\n return ret;\n };\n imports.wbg.__wbindgen_number_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"number\" ? obj : undefined;\n getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbg_instanceof_Uint8Array_19e6f142a5e7e1e1 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Uint8Array;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_instanceof_ArrayBuffer_c7cc317e5c29cc0d = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof ArrayBuffer;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_entries_6d727b73ee02b7ce = function (arg0) {\n const ret = Object.entries(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_String_917f38a1211cf44b = function (arg0, arg1) {\n const ret = String(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_warn_ade8d3b7ecee11ff = function (arg0, arg1) {\n console.warn(getObject(arg0), getObject(arg1));\n };\n imports.wbg.__wbg_readyState_13e55da5ad6d64e2 = function (arg0) {\n const ret = getObject(arg0).readyState;\n return ret;\n };\n imports.wbg.__wbg_warn_4affe1093892a4ef = function (arg0) {\n console.warn(getObject(arg0));\n };\n imports.wbg.__wbg_close_f4135085ec3fc8f0 = function () {\n return handleError(function (arg0) {\n getObject(arg0).close();\n }, arguments);\n };\n imports.wbg.__wbg_new_b9b318679315404f = function () {\n return handleError(function (arg0, arg1) {\n const ret = new WebSocket(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setbinaryType_dcb62e0f2b346301 = function (arg0, arg1) {\n getObject(arg0).binaryType = takeObject(arg1);\n };\n imports.wbg.__wbg_log_7811587c4c6d2844 = function (arg0) {\n console.log(getObject(arg0));\n };\n imports.wbg.__wbg_error_f0a6627f4b23c19d = function (arg0) {\n console.error(getObject(arg0));\n };\n imports.wbg.__wbg_info_3ca7870690403fee = function (arg0) {\n console.info(getObject(arg0));\n };\n imports.wbg.__wbg_document_183cf1eecfdbffee = function (arg0) {\n const ret = getObject(arg0).document;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n };\n imports.wbg.__wbg_visibilityState_9721703a5ef75faf = function (arg0) {\n const ret = getObject(arg0).visibilityState;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getwithrefkey_3b3c46ba20582127 = function (arg0, arg1) {\n const ret = getObject(arg0)[getObject(arg1)];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_length_cace2e0b3ddc0502 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbg_addEventListener_0f2891b0794e07fa = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).addEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbg_removeEventListener_104d11302bb212d1 = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).removeEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbindgen_is_bigint = function (arg0) {\n const ret = typeof getObject(arg0) === \"bigint\";\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_i64 = function (arg0) {\n const ret = arg0;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_in = function (arg0, arg1) {\n const ret = getObject(arg0) in getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_u64 = function (arg0) {\n const ret = BigInt.asUintN(64, arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_eq = function (arg0, arg1) {\n const ret = getObject(arg0) === getObject(arg1);\n return ret;\n };\n imports.wbg.__wbg_localStorage_e11f72e996a4f5d9 = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).localStorage;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_getItem_c81cd3ae30cd579a = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n const ret = getObject(arg1).getItem(getStringFromWasm0(arg2, arg3));\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n }, arguments);\n };\n imports.wbg.__wbg_navigator_7078da62d92ff5ad = function (arg0) {\n const ret = getObject(arg0).navigator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_mediaDevices_e00b1f64d2b9939f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).mediaDevices;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_enumerateDevices_619d52f5eef34c2f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).enumerateDevices();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setItem_fe04f524052a3839 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbindgen_cb_drop = function (arg0) {\n const obj = takeObject(arg0).original;\n if (obj.cnt-- == 1) {\n obj.a = 0;\n return true;\n }\n const ret = false;\n return ret;\n };\n imports.wbg.__wbg_deviceId_58f7da2228a26c02 = function (arg0, arg1) {\n const ret = getObject(arg1).deviceId;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_instanceof_Response_944e2745b5db71f5 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Response;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_randomFillSync_a0d98aa11c81fe89 = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).randomFillSync(takeObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbg_subarray_6ca5cfa7fbb9abbe = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getRandomValues_504510b5564925af = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).getRandomValues(getObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbindgen_bigint_get_as_i64 = function (arg0, arg1) {\n const v = getObject(arg1);\n const ret = typeof v === \"bigint\" ? v : undefined;\n getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbindgen_debug_string = function (arg0, arg1) {\n const ret = debugString(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbindgen_throw = function (arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n };\n imports.wbg.__wbg_then_89e1c559530b85cf = function (arg0, arg1) {\n const ret = getObject(arg0).then(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_e5949c35d772a669 = function (arg0) {\n queueMicrotask(getObject(arg0));\n };\n imports.wbg.__wbg_then_1bbc9edafd859b06 = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_2be8b97a81fe4d00 = function (arg0) {\n const ret = getObject(arg0).queueMicrotask;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_resolve_a3252b2860f0a09e = function (arg0) {\n const ret = Promise.resolve(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_url_1f609e63ff1a7983 = function (arg0, arg1) {\n const ret = getObject(arg1).url;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_send_2860805104507701 = function () {\n return handleError(function (arg0, arg1, arg2) {\n getObject(arg0).send(getArrayU8FromWasm0(arg1, arg2));\n }, arguments);\n };\n imports.wbg.__wbg_instanceof_Window_cde2416cf5126a72 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Window;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_new_19676474aa414d62 = function () {\n return handleError(function () {\n const ret = new Headers();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_append_feec4143bbf21904 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbg_newwithstrandinit_29038da14d09e330 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_closure_wrapper1532 = function (arg0, arg1, arg2) {\n const ret = makeClosure(arg0, arg1, 76, __wbg_adapter_46);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1602 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_49);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1834 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_52);\n return addHeapObject(ret);\n };\n\n return imports;\n}\n\nfunction __wbg_init_memory(imports, maybe_memory) {}\n\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n __wbg_init.__wbindgen_wasm_module = module;\n cachedBigInt64Memory0 = null;\n cachedFloat64Memory0 = null;\n cachedInt32Memory0 = null;\n cachedUint8Memory0 = null;\n\n wasm.__wbindgen_start();\n return wasm;\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n const imports = __wbg_get_imports();\n\n __wbg_init_memory(imports);\n\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n\n const instance = new WebAssembly.Instance(module, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(input) {\n if (wasm !== undefined) return wasm;\n\n if (typeof input === \"undefined\") {\n input = new URL(\"telemeter_wasm_bg.wasm\", import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (\n typeof input === \"string\" ||\n (typeof Request === \"function\" && input instanceof Request) ||\n (typeof URL === \"function\" && input instanceof URL)\n ) {\n input = fetch(input);\n }\n\n __wbg_init_memory(imports);\n\n const { instance, module } = await __wbg_load(await input, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync };\nexport default __wbg_init;\n","/* eslint-disable-next-line */\nimport init, { Telemeter as TelemeterWASM } from \"../telemeter-wasm\";\n\n/**\n * @classdesc\n * This class implements the @wiris/telemeter-wasm. A utility that helps our Solutions to send the data\n * to Telemetry in a more comfortable and homogeneous way.\n */\nexport default class Telemeter {\n /**\n * Inits Telemeter class.\n * The parameters structures are defiended on {@link [Telemeter API](https://github.com/wiris/telemeter/blob/main/docs/USAGE.md#telemeter-api)}\n * @param {Object} telemeterAttributes.solution - The product that send data to Telemetry.\n * @param {Object} telemeterAttributes.hosts - Data about the environment where solution is integrated.\n * @param {Object} telemeterAttributes.config - Configuration parameters.\n */\n static init(telemeterAttributes) {\n if (!this.telemeter && !this.waitingForInit) {\n this.waitingForInit = true;\n init(telemeterAttributes.url)\n .then(() => {\n this.telemeter = new TelemeterWASM(\n telemeterAttributes.solution,\n telemeterAttributes.hosts,\n telemeterAttributes.config,\n );\n })\n .catch((error) => {\n console.log(error);\n })\n .finally(() => (this.waitingForInit = false));\n }\n }\n\n /**\n * Closes the Telemetry Session. After calling this method no data will be added to the Telemetry Session.\n */\n static async finish() {\n if (!this.telemeter) return;\n\n try {\n const local_telemeter = this.telemeter;\n this.telemeter = undefined;\n await local_telemeter.finish();\n } catch (e) {\n console.error(e);\n }\n }\n}\n","import Configuration from \"./configuration\";\nimport Core from \"./core.src\";\nimport EditorListener from \"./editorlistener\";\nimport Listeners from \"./listeners\";\nimport MathML from \"./mathml\";\nimport Util from \"./util\";\nimport Telemeter from \"./telemeter\";\n\nexport default class ContentManager {\n /**\n * @classdesc\n * This class represents a modal dialog, managing the following:\n * - The insertion of content into the current instance of the {@link ModalDialog} class.\n * - The actions to be done once the modal object has been submitted\n * (submitAction} method).\n * - The update of the content when the {@link ModalDialog} class is also updated,\n * for example when ModalDialog is re-opened.\n * - The communication between the {@link ModalDialog} class and itself, if the content\n * has been changed (hasChanges} method).\n * @constructs\n * @param {Object} contentManagerAttributes - Object containing all attributes needed to\n * create a new instance.\n */\n constructor(contentManagerAttributes) {\n /**\n * An object containing MathType editor parameters. See\n * http://docs.wiris.com/en/mathtype/mathtype_web/sdk-api/parameters for further information.\n * @type {Object}\n */\n this.editorAttributes = {};\n if (\"editorAttributes\" in contentManagerAttributes) {\n this.editorAttributes = contentManagerAttributes.editorAttributes;\n } else {\n throw new Error(\"ContentManager constructor error: editorAttributes property missed.\");\n }\n\n /**\n * CustomEditors instance. Contains the custom editors.\n * @type {CustomEditors}\n */\n this.customEditors = null;\n if (\"customEditors\" in contentManagerAttributes) {\n this.customEditors = contentManagerAttributes.customEditors;\n }\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @type {Object}\n * @property {String} editor - Editor name. Usually the HTML editor.\n * @property {String} mode - Save mode. Xml by default.\n * @property {String} version - Plugin version.\n */\n this.environment = {};\n if (\"environment\" in contentManagerAttributes) {\n this.environment = contentManagerAttributes.environment;\n } else {\n throw new Error(\"ContentManager constructor error: environment property missed\");\n }\n\n /**\n * ContentManager language.\n * @type {String}\n */\n this.language = \"\";\n if (\"language\" in contentManagerAttributes) {\n this.language = contentManagerAttributes.language;\n } else {\n throw new Error(\"ContentManager constructor error: language property missed\");\n }\n\n /**\n * {@link EditorListener} instance. Manages the changes inside the editor.\n * @type {EditorListener}\n */\n this.editorListener = new EditorListener();\n\n /**\n * MathType editor instance.\n * @type {JsEditor}\n */\n this.editor = null;\n\n /**\n * Navigator user agent.\n * @type {String}\n */\n this.ua = navigator.userAgent.toLowerCase();\n\n /**\n * Mobile device properties object\n * @type {DeviceProperties}\n */\n this.deviceProperties = {};\n this.deviceProperties.isAndroid = this.ua.indexOf(\"android\") > -1;\n this.deviceProperties.isIOS = ContentManager.isIOS();\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.toolbar = null;\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.dbclick = null;\n\n /**\n * Instance of the {@link ModalDialog} class associated with the current\n * {@link ContentManager} instance.\n * @type {ModalDialog}\n */\n this.modalDialogInstance = null;\n\n /**\n * ContentManager listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n /**\n * MathML associated to the ContentManager instance.\n * @type {String}\n */\n this.mathML = null;\n\n /**\n * Indicates if the edited element is a new one or not.\n * @type {Boolean}\n */\n this.isNewElement = true;\n\n /**\n * {@link IntegrationModel} instance. Needed to call wrapper methods.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n }\n\n /**\n * Adds a new listener to the current {@link ContentManager} instance.\n * @param {Object} listener - The listener to be added.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Sets an instance of {@link IntegrationModel} class to the current {@link ContentManager}\n * instance.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} instance.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link ModalDialog} instance into the current {@link ContentManager} instance.\n * @param {ModalDialog} modalDialogInstance - The {@link ModalDialog} instance\n */\n setModalDialogInstance(modalDialogInstance) {\n this.modalDialogInstance = modalDialogInstance;\n }\n\n /**\n * Inserts the content into the current {@link ModalDialog} instance updating\n * the title and inserting the JavaScript editor.\n */\n insert() {\n // Before insert the editor we update the modal object title to avoid weird render display.\n this.updateTitle(this.modalDialogInstance);\n this.insertEditor(this.modalDialogInstance);\n }\n\n /**\n * Inserts MathType editor into the {@link ModalDialog.contentContainer}. It waits until\n * editor's JavaScript is loaded.\n */\n insertEditor() {\n if (ContentManager.isEditorLoaded()) {\n this.editor = window.com.wiris.jsEditor.JsEditor.newInstance(this.editorAttributes);\n this.editor.insertInto(this.modalDialogInstance.contentContainer);\n this.editor.focus();\n\n // `editor.action(\"rtl\");` toggles the RTL mode based on the current state, it doesn't just switch to RTL.\n if (this.modalDialogInstance.rtl && !this.editor.getEditorModel().isRTL()) {\n this.editor.action(\"rtl\");\n }\n // Setting div in rtl in case of it's activated.\n if (this.editor.getEditorModel().isRTL()) {\n this.editor.element.style.direction = \"rtl\";\n }\n\n // Editor listener: this object manages the changes logic of editor.\n this.editor.getEditorModel().addEditorListener(this.editorListener);\n\n // iOS events.\n if (this.modalDialogInstance.deviceProperties.isIOS) {\n setTimeout(function () {\n // Make sure the modalDialogInstance is available when the timeout is over\n // to avoid throw errors and stop execution.\n if (this.hasOwnProperty(\"modalDialogInstance\")) this.modalDialogInstance.hideKeyboard(); // eslint-disable-line no-prototype-builtins\n }, 400);\n\n const formulaDisplayDiv = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n Util.addEvent(formulaDisplayDiv, \"focus\", this.modalDialogInstance.handleOpenedIosSoftkeyboard);\n Util.addEvent(formulaDisplayDiv, \"blur\", this.modalDialogInstance.handleClosedIosSoftkeyboard);\n }\n // Fire onLoad event. Necessary to set the MathML into the editor\n // after is loaded.\n this.listeners.fire(\"onLoad\", {});\n } else {\n setTimeout(ContentManager.prototype.insertEditor.bind(this), 100);\n }\n }\n\n /**\n * Initializes the current class by loading MathType script.\n */\n init() {\n if (!ContentManager.isEditorLoaded()) {\n this.addEditorAsExternalDependency();\n }\n }\n\n /**\n * Adds script element to the DOM to include editor externally.\n */\n addEditorAsExternalDependency() {\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n let editorUrl = Configuration.get(\"editorUrl\");\n\n // We create an object url for parse url string and work more efficiently.\n const anchorElement = document.createElement(\"a\");\n\n ContentManager.setHrefToAnchorElement(anchorElement, editorUrl);\n ContentManager.setProtocolToAnchorElement(anchorElement);\n\n editorUrl = ContentManager.getURLFromAnchorElement(anchorElement);\n\n // Load editor URL. We add stats as GET params.\n const stats = this.getEditorStats();\n script.src = `${editorUrl}?lang=${this.language}&stats-editor=${stats.editor}&stats-mode=${stats.mode}&stats-version=${stats.version}`;\n\n document.getElementsByTagName(\"head\")[0].appendChild(script);\n }\n\n /**\n * Sets the specified url to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set 'url'.\n * @param {String} url - URL to set.\n */\n static setHrefToAnchorElement(anchorElement, url) {\n anchorElement.href = url;\n }\n\n /**\n * Sets the current protocol to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set its protocol.\n */\n static setProtocolToAnchorElement(anchorElement) {\n // Change to https if necessary.\n if (window.location.href.indexOf(\"https://\") === 0) {\n // It check if browser is https and configuration is http.\n // If this is so, we will replace protocol.\n if (anchorElement.protocol === \"http:\") {\n anchorElement.protocol = \"https:\";\n }\n }\n }\n\n /**\n * Returns the url of the anchor element adding the current port\n * if it is needed.\n * @param {HTMLAnchorElement} anchorElement - Element where extract the url.\n * @returns {String}\n */\n static getURLFromAnchorElement(anchorElement) {\n // Check protocol and remove port if it's standard.\n const removePort = anchorElement.port === \"80\" || anchorElement.port === \"443\" || anchorElement.port === \"\";\n return `${anchorElement.protocol}//${anchorElement.hostname}${removePort ? \"\" : `:${anchorElement.port}`}${anchorElement.pathname.startsWith(\"/\") ? anchorElement.pathname : `/${anchorElement.pathname}`}`; // eslint-disable-line max-len\n }\n\n /**\n * Returns object with editor stats.\n *\n * @typedef {Object} EditorStatsObject\n * @property {string} editor - Editor name.\n * @property {string} mode - Current configuration for formula save mode.\n * @property {string} version - Current plugins version.\n * @returns {EditorStatsObject}\n */\n getEditorStats() {\n // Editor stats. Use environment property to set it.\n const stats = {};\n if (\"editor\" in this.environment) {\n stats.editor = this.environment.editor;\n } else {\n stats.editor = \"unknown\";\n }\n\n if (\"mode\" in this.environment) {\n stats.mode = this.environment.mode;\n } else {\n stats.mode = Configuration.get(\"saveMode\");\n }\n\n if (\"version\" in this.environment) {\n stats.version = this.environment.version;\n } else {\n stats.version = Configuration.get(\"version\");\n }\n\n return stats;\n }\n\n /**\n * Returns true if device is iOS. Otherwise, false.\n * @returns {Boolean}\n */\n static isIOS() {\n return (\n [\"iPad Simulator\", \"iPhone Simulator\", \"iPod Simulator\", \"iPad\", \"iPhone\", \"iPod\"].includes(navigator.platform) ||\n // iPad on iOS 13 detection\n (navigator.userAgent.includes(\"Mac\") && \"ontouchend\" in document)\n );\n }\n\n /**\n * Returns true if device is Mobile. Otherwise, false.\n * @returns {Boolean}\n */\n static isMobile() {\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n /**\n * Returns true if editor is loaded. Otherwise, false.\n * @returns {Boolean}\n */\n static isEditorLoaded() {\n // To know if editor JavaScript is loaded we need to wait until\n // window.com.wiris.jsEditor.JsEditor.newInstance is ready.\n return (\n window.com &&\n window.com.wiris &&\n window.com.wiris.jsEditor &&\n window.com.wiris.jsEditor.JsEditor &&\n window.com.wiris.jsEditor.JsEditor.newInstance\n );\n }\n\n /**\n * Sets the {@link ContentManager.editor} initial content.\n */\n setInitialContent() {\n if (!this.isNewElement) {\n this.setMathML(this.mathML);\n }\n }\n\n /**\n * Sets a MathML into {@link ContentManager.editor} instance.\n * @param {String} mathml - MathML string.\n * @param {Boolean} focusDisabled - If true editor don't get focus after the MathML is set.\n * False by default.\n */\n setMathML(mathml, focusDisabled) {\n // By default focus is enabled.\n if (typeof focusDisabled === \"undefined\") {\n focusDisabled = false;\n }\n // Using setMathML method is not a change produced by the user but for the API\n // so we set to false the contentChange property of editorListener.\n this.editor.setMathMLWithCallback(mathml, () => {\n this.editorListener.setWaitingForChanges(true);\n });\n\n // We need to wait a little until the callback finish.\n setTimeout(() => {\n this.editorListener.setIsContentChanged(false);\n }, 500);\n\n // In some scenarios - like closing modal object - editor mustn't be focused.\n if (!focusDisabled) {\n this.onFocus();\n }\n }\n\n /**\n * Sets the focus to the current instance of {@link ContentManager.editor}. Triggered by\n * {@link ModalDialog.focus}.\n */\n onFocus() {\n if (typeof this.editor !== \"undefined\" && this.editor != null) {\n this.editor.focus();\n\n // On WordPress integration, the focus gets lost right after setting it.\n // To fix this, we enforce another focus some milliseconds after this behaviour.\n setTimeout(() => {\n this.editor.focus();\n }, 100);\n }\n }\n\n /**\n * Updates the edition area by calling {@link IntegrationModel.updateFormula}.\n * Triggered by {@link ModalDialog.submitAction}.\n */\n submitAction() {\n if (!this.editor.isFormulaEmpty()) {\n let mathML = this.editor.getMathMLWithSemantics();\n // Add class for custom editors.\n if (this.customEditors.getActiveEditor() !== null) {\n const { toolbar } = this.customEditors.getActiveEditor();\n mathML = MathML.addCustomEditorClassAttribute(mathML, toolbar);\n } else {\n // We need - if exists - the editor name from MathML\n // class attribute.\n Object.keys(this.customEditors.editors).forEach((key) => {\n mathML = MathML.removeCustomEditorClassAttribute(mathML, key);\n });\n }\n const mathmlEntitiesEncoded = MathML.mathMLEntities(mathML);\n this.integrationModel.updateFormula(mathmlEntitiesEncoded);\n } else {\n this.integrationModel.updateFormula(null);\n }\n\n this.customEditors.disable();\n this.integrationModel.notifyWindowClosed();\n\n // Set disabled focus to prevent lost focus.\n this.setEmptyMathML();\n this.customEditors.disable();\n }\n\n /**\n * Sets an empty MathML as {@link ContentManager.editor} content.\n * This will open the MT/CT editor with the hand mode.\n * It adds dir rtl in case of it's activated.\n */\n setEmptyMathML() {\n const isMobile = this.deviceProperties.isAndroid || this.deviceProperties.isIOS;\n const isRTL = this.editor.getEditorModel().isRTL();\n\n if (isMobile || this.integrationModel.forcedHandMode) {\n // For mobile devices or forced hand mode, set an empty annotation MATHML to maintain the editor in Hand mode.\n const mathML = `[]`;\n this.setMathML(mathML, true);\n } else {\n // For non-mobile devices or not forced hand mode, set the empty MathML without an annotation.\n const mathML = ``;\n this.setMathML(mathML, true);\n }\n }\n\n /**\n * Open event. Triggered by {@link ModalDialog.open}. Does the following:\n * - Updates the {@link ContentManager.editor} content\n * (with an empty MathML or an existing formula),\n * - Updates the {@link ContentManager.editor} toolbar.\n * - Recovers the the focus.\n */\n onOpen() {\n if (this.isNewElement) {\n this.setEmptyMathML();\n } else {\n this.setMathML(this.mathML);\n }\n const toolbar = this.updateToolbar();\n this.onFocus();\n\n if (this.deviceProperties.isIOS) {\n const zoom = document.documentElement.clientWidth / window.innerWidth;\n\n if (zoom !== 1) {\n // Open editor in Keyboard mode if user use iOS, Safari and page is zoomed.\n this.setKeyboardMode();\n }\n }\n\n const trigger = this.dbclick ? \"formula\" : \"button\";\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"OPENED_MTCT_EDITOR\", {\n toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking OPENED_MTCT_EDITOR\", error);\n }\n\n Core.globalListeners.fire(\"onModalOpen\", {});\n\n if (this.integrationModel.forcedHandMode) {\n this.hideHandModeButton();\n\n // In case we have a keyboard written formula, we still want it to be opened with handMode.\n if (this.mathML && !this.mathML.includes('') && !this.isNewElement) {\n this.openHandOnKeyboardMathML(this.mathML, this.editor);\n }\n }\n }\n\n /**\n * Change Editor in keyboard mode when is loaded\n */\n setKeyboardMode() {\n const wrsEditor = document.getElementsByClassName(\"wrs_handOpen wrs_disablePalette\")[0];\n if (wrsEditor) {\n wrsEditor.classList.remove(\"wrs_handOpen\");\n wrsEditor.classList.remove(\"wrs_disablePalette\");\n } else {\n setTimeout(ContentManager.prototype.setKeyboardMode.bind(this), 100);\n }\n }\n\n /**\n * Hides the hand <-> keyboard mode switch.\n *\n * This method relies completely on the classes used on different HTML elements within the editor itself, meaning\n * any change on those classes will make this code stop working properly.\n *\n * On top of that, some of those classes are changed on runtime (for example, the one that makes some buttons change).\n * This forces us to use some delayed code (this is, a timeout) to make sure everything exists when we need it.\n * @param {*} forced (boolean) Forces the user to stay in Hand mode by hiding the keyboard mode button.\n */\n hideHandModeButton(forced = true) {\n if (this.handSwitchHidden) {\n return; // hand <-> keyboard button already hidden.\n }\n\n // \"Open hand mode\" button takes a little bit to be available.\n // This selector gets the hand <-> keyboard mode switch\n const handModeButtonSelector =\n \"div.wrs_editor.wrs_flexEditor.wrs_withHand.wrs_animated .wrs_handWrapper input[type=button]\";\n\n // If in \"forced mode\", we hide the \"keyboard button\" so the user can't can't change between hand and keyboard modes.\n // We use an observer to ensure that the button it hidden as soon as it appears.\n if (forced) {\n const mutationInstance = new MutationObserver((mutations) => {\n const handModeButton = document.querySelector(handModeButtonSelector);\n if (handModeButton) {\n handModeButton.hidden = true;\n this.handSwitchHidden = true;\n mutationInstance.disconnect();\n }\n });\n mutationInstance.observe(document.body, {\n attributes: true,\n childList: true,\n characterData: true,\n subtree: true,\n });\n }\n }\n\n /**\n * It will open any formula written in Keyboard mode with the hand mode with the default hand trace.\n *\n * @param {String} mathml The original KeyBoard MathML\n * @param {Object} editor The editor object.\n */\n async openHandOnKeyboardMathML(mathml, editor) {\n // First, as an editor requirement, we need to update the editor object with the current MathML formula.\n // Once the MathML formula is updated to the one we want to open with handMode, we will be able to proceed.\n await new Promise((resolve) => {\n editor.setMathMLWithCallback(mathml, resolve);\n });\n\n // We wait until the hand editor object exists.\n await this.waitForHand(editor);\n\n // Logic to get the hand traces and open the formula in hand mode.\n // This logic comes from the editor.\n const handEditor = editor.hand;\n editor.handTemporalMathML = editor.getMathML();\n const handCoordinates = editor.editorModel.getHandStrokes();\n handEditor.setStrokes(handCoordinates);\n handEditor.fitStrokes(true);\n editor.openHand();\n }\n\n /**\n * Waits until the hand editor object exists.\n * @param {Obect} editor The editor object.\n */\n async waitForHand(editor) {\n while (!editor.hand) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Sets the correct toolbar depending if exist other custom toolbars\n * at the same time (e.g: Chemistry).\n */\n updateToolbar() {\n this.updateTitle(this.modalDialogInstance);\n const customEditor = this.customEditors.getActiveEditor();\n\n let toolbar;\n if (customEditor) {\n toolbar = customEditor.toolbar ? customEditor.toolbar : _wrs_int_wirisProperties.toolbar;\n\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n }\n } else {\n toolbar = this.getToolbar();\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n this.customEditors.disable();\n }\n }\n\n return toolbar;\n }\n\n /**\n * Updates the current {@link ModalDialog.title}. If a {@link CustomEditors} is enabled\n * sets the custom editor title. Otherwise sets the default title.\n */\n updateTitle() {\n const customEditor = this.customEditors.getActiveEditor();\n if (customEditor) {\n this.modalDialogInstance.setTitle(customEditor.title);\n } else {\n this.modalDialogInstance.setTitle(\"MathType\");\n }\n }\n\n /**\n * Returns the editor toolbar, depending on the configuration local or server side.\n * @returns {String} - Toolbar identifier.\n */\n getToolbar() {\n let toolbar = \"general\";\n if (\"toolbar\" in this.editorAttributes) {\n ({ toolbar } = this.editorAttributes);\n }\n // TODO: Change global integration variable for integration custom toolbar.\n if (toolbar === \"general\") {\n // eslint-disable-next-line camelcase\n toolbar =\n typeof _wrs_int_wirisProperties === \"undefined\" || typeof _wrs_int_wirisProperties.toolbar === \"undefined\"\n ? \"general\"\n : _wrs_int_wirisProperties.toolbar;\n }\n\n return toolbar;\n }\n\n /**\n * Sets the current {@link ContentManager.editor} instance toolbar.\n * @param {String} toolbar - The toolbar name.\n */\n setToolbar(toolbar) {\n this.toolbar = toolbar;\n this.editor.setParams({ toolbar: this.toolbar });\n }\n\n /**\n * Sets the custom headers added on editor requests.\n * @returns {Object} headers - key value headers.\n */\n setCustomHeaders(headers) {\n let headersObj = {};\n\n // We control that we only get String or Object as the input.\n if (typeof headers === \"object\") {\n headersObj = headers;\n } else if (typeof headers === \"string\") {\n headersObj = Util.convertStringToObject(headers);\n }\n\n this.editor.setParams({ customHeaders: headersObj });\n return headersObj;\n }\n\n /**\n * Returns true if the content of the editor has been changed. The logic of the changes\n * is delegated to {@link EditorListener} class.\n * @returns {Boolean} True if the editor content has been changed. False otherwise.\n */\n hasChanges() {\n return !this.editor.isFormulaEmpty() && this.editorListener.getIsContentChanged();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined && keyboardEvent.repeat === false) {\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n // Code to detect Esc event.\n // There should be only one element with class name 'wrs_pressed' at the same time.\n let list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor3RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor2RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_select wrs_pressed\");\n if (list.length === 0) {\n this.modalDialogInstance.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.modalDialogInstance.submitButton) {\n // Focus is on OK button.\n this.editor.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.querySelector('[title=\"Manual\"]') === document.activeElement) {\n // Focus is on minimize button (_).\n this.modalDialogInstance.closeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.minimizeDiv) {\n // Focus on cancel button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n this.modalDialogInstance.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.modalDialogInstance.cancelButton) {\n // Focus is on X button.\n this.modalDialogInstance.minimizeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.closeDiv) {\n // Focus on help button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n const element = document.querySelector('[title=\"Manual\"]');\n element.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n } else {\n // There should be only one element with class name 'wrs_formulaDisplay'.\n const element = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n if (element.getAttribute(\"class\") === \"wrs_formulaDisplay wrs_focused\") {\n // Focus is on formuladisplay.\n this.modalDialogInstance.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n }\n }\n}\n","/**\n * A custom editor is MathType editor with a different\n * @typedef {Object} CustomEditor\n * @property {String} CustomEditor.name - Custom editor name.\n * @property {String} CustomEditor.toolbar - Custom editor toolbar.\n * @property {String} CustomEditor.icon - Custom editor icon.\n * @property {String} CustomEditor.confVariable - Configuration property to manage\n * the availability of the custom editor.\n * @property {String} CustomEditor.title - Custom editor modal dialog title.\n * @property {String} CustomEditor.tooltip - Custom editor icon tooltip.\n */\n\nexport default class CustomEditors {\n /**\n * @classdesc\n * This class represents the MathType custom editors manager.\n * A custom editor is MathType editor with a custom toolbar.\n * This class associates a {@link CustomEditor} to:\n * - It's own formulas\n * - A custom toolbar\n * - An icon to open it from a HTML editor.\n * - A tooltip for the icon.\n * - A global variable to enable or disable it globally.\n * @constructs\n */\n constructor() {\n /**\n * The custom editors.\n * @type {Array.}\n */\n\n this.editors = [];\n /**\n * The active editor name.\n * @type {String}\n */\n this.activeEditor = \"default\";\n }\n\n /**\n * Adds a {@link CustomEditor} to editors array.\n * @param {String} editorName - The editor name.\n * @param {CustomEditor} editorParams - The custom editor parameters.\n */\n addEditor(editorName, editorParams) {\n const customEditor = {};\n customEditor.name = editorParams.name;\n customEditor.toolbar = editorParams.toolbar;\n customEditor.icon = editorParams.icon;\n customEditor.confVariable = editorParams.confVariable;\n customEditor.title = editorParams.title;\n customEditor.tooltip = editorParams.tooltip;\n this.editors[editorName] = customEditor;\n }\n\n /**\n * Enables a {@link CustomEditor}.\n * @param {String} customEditorName - The custom editor name.\n */\n enable(customEditorName) {\n this.activeEditor = customEditorName;\n }\n\n /**\n * Disables a {@link CustomEditor}.\n */\n disable() {\n this.activeEditor = \"default\";\n }\n\n /**\n * Returns the active editor.\n * @return {CustomEditor} - A {@link CustomEditor} if a custom editor is enabled. Null otherwise.\n */\n getActiveEditor() {\n if (this.activeEditor !== \"default\") {\n return this.editors[this.activeEditor];\n }\n return null;\n }\n}\n","/**\n * Represents the configuration properties generated from the frontend (JavaScript variables).\n * @type {Object}\n * @property {string} imageClassName - Default MathType formula image class.\n * @property {string} imageClassName - Default MathType CAS image class.\n * @ignore\n */\nconst jsProperties = {\n imageCustomEditorName: \"data-custom-editor\",\n imageClassName: \"Wirisformula\",\n CASClassName: \"Wiriscas\",\n};\nexport default jsProperties;\n","export default class Event {\n /**\n * @classdesc\n * This class represents a custom event. Events should be fired by the {@link Listener} class.\n *\n * ```js\n * let customEvent = new Event();\n * customEvent.properties = {};\n *\n * let listeners = new Listeners();\n * listeners.newListener(eventName, callback);\n *\n * listeners.fire(eventName, customEvent) *\n * ```\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the event should be cancelled.\n * @type {Boolean}\n */\n\n this.cancelled = false;\n /**\n * Indicates if the event should be prevented.\n * @type {Boolean}\n */\n this.defaultPrevented = false;\n }\n\n /**\n * Cancels the event.\n */\n cancel() {\n this.cancelled = true;\n }\n\n /**\n * Prevents the default action.\n */\n preventDefault() {\n this.defaultPrevented = true;\n }\n}\n","import IntegrationModel from \"./integrationmodel\";\n\n/**\n\n */\nexport default class PopUpMessage {\n /**\n * @classdesc\n * This class represents a dialog message overlaying a DOM element in order to\n * accept / cancel discard changes. The dialog can be closed i.e the overlay disappears\n * o canceled. In this last case a callback function should be called.\n * @constructs\n * @param {Object} popupMessageAttributes - Object containing popup properties.\n * @param {HTMLElement} popupMessageAttributes.overlayElement - Element to overlay.\n * @param {Object} popupMessageAttributes.callbacks - Contains callback\n * methods for close and cancel actions.\n * @param {Object} popupMessageAttributes.strings - Contains all the strings needed.\n */\n constructor(popupMessageAttributes) {\n /**\n * Element to be overlaid when the popup appears.\n */\n this.overlayElement = popupMessageAttributes.overlayElement;\n\n this.callbacks = popupMessageAttributes.callbacks;\n\n /**\n * HTMLElement element to wrap all HTML elements inside the popupMessage.\n */\n this.overlayWrapper = this.overlayElement.appendChild(document.createElement(\"div\"));\n this.overlayWrapper.setAttribute(\"class\", \"wrs_popupmessage_overlay_envolture\");\n\n /**\n * HTMLElement to display the popup message, close button and cancel button.\n */\n this.message = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n this.message.id = \"wrs_popupmessage\";\n this.message.setAttribute(\"class\", \"wrs_popupmessage_panel\");\n this.message.setAttribute(\"role\", \"dialog\");\n this.message.setAttribute(\"aria-describedby\", \"description_txt\");\n const paragraph = document.createElement(\"p\");\n const text = document.createTextNode(popupMessageAttributes.strings.message);\n paragraph.appendChild(text);\n paragraph.id = \"description_txt\";\n this.message.appendChild(paragraph);\n\n /**\n * HTML element overlaying the overlayElement.\n */\n const overlay = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n overlay.setAttribute(\"class\", \"wrs_popupmessage_overlay\");\n // We create a overlay that close popup message on click in there\n overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n /**\n * HTML element containing cancel and close buttons.\n */\n this.buttonArea = this.message.appendChild(document.createElement(\"div\"));\n this.buttonArea.setAttribute(\"class\", \"wrs_popupmessage_button_area\");\n this.buttonArea.id = \"wrs_popup_button_area\";\n\n // Close button arguments.\n const buttonSubmitArguments = {\n class: \"wrs_button_accept\",\n innerHTML: popupMessageAttributes.strings.submitString,\n id: \"wrs_popup_accept_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-close-button\",\n };\n\n /**\n * Close button arguments.\n */\n this.closeButton = this.createButton(buttonSubmitArguments, this.closeAction.bind(this));\n this.buttonArea.appendChild(this.closeButton);\n\n // Cancel button arguments.\n const buttonCancelArguments = {\n class: \"wrs_button_cancel\",\n innerHTML: popupMessageAttributes.strings.cancelString,\n id: \"wrs_popup_cancel_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-cancel-button\",\n };\n\n /**\n * Cancel button.\n */\n this.cancelButton = this.createButton(buttonCancelArguments, this.cancelAction.bind(this));\n this.buttonArea.appendChild(this.cancelButton);\n }\n\n /**\n * This method create a button with arguments and return button dom object\n * @param {Object} parameters - An object containing id, class and innerHTML button text.\n * @param {String} parameters.id - Button id.\n * @param {String} parameters.class - Button class name.\n * @param {String} parameters.innerHTML - Button innerHTML text.\n * @param {Object} callback- Callback method to call on click event.\n * @returns {HTMLElement} HTML button.\n */\n // eslint-disable-next-line class-methods-use-this\n createButton(parameters, callback) {\n let element = {};\n element = document.createElement(\"button\");\n element.setAttribute(\"id\", parameters.id);\n element.setAttribute(\"class\", parameters.class);\n element.innerHTML = parameters.innerHTML;\n element.addEventListener(\"click\", callback);\n if (parameters[\"data-testid\"]) {\n element.setAttribute(\"data-testid\", parameters[\"data-testid\"]);\n }\n\n return element;\n }\n\n /**\n * Shows the popupmessage containing a message, and two buttons\n * to cancel the action or close the modal dialog.\n */\n show() {\n if (this.overlayWrapper.style.display !== \"block\") {\n // Clear focus with blur for prevent press any key.\n document.activeElement.blur();\n this.overlayWrapper.style.display = \"block\";\n this.closeButton.focus();\n } else {\n this.overlayWrapper.style.display = \"none\";\n // _wrs_modalWindow.focus(); This throws an error of not existing _wrs_modalWindow\n }\n }\n\n /**\n * This method cancels the popupMessage: the dialog disappears revealing the overlaid element.\n * A callback method is called (if defined). For example a method to focus the overlaid element.\n */\n cancelAction() {\n this.overlayWrapper.style.display = \"none\";\n if (typeof this.callbacks.cancelCallback !== \"undefined\") {\n this.callbacks.cancelCallback();\n // Set temporal image to null to prevent loading\n // an existent formula when starting one from scratch. Make focus come back too.\n // IntegrationModel.setActionsOnCancelButtons();\n }\n }\n\n /**\n * This method closes the popupMessage: the dialog disappears and the close callback is called.\n * For example to close the overlaid element.\n */\n closeAction() {\n this.cancelAction();\n if (typeof this.callbacks.closeCallback !== \"undefined\") {\n this.callbacks.closeCallback();\n }\n IntegrationModel.setActionsOnCancelButtons();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Code to detect Esc event.\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n this.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.closeButton) {\n this.cancelButton.focus();\n } else {\n this.closeButton.focus();\n }\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n}\n","/**\n * This module provides protection against external focus management scripts\n * that might interfere with the MathType editor modal.\n */\n\n/**\n * focusProtection function creates and returns methods to prevent external scripts from\n * interfering with the focus of the MathType modal dialog.\n *\n * @returns {Object} An object with protect and unprotect methods.\n */\nconst focusProtection = () => {\n /**\n * Initialize focus protection on the given modal element.\n *\n * @param {HTMLElement} modalElement - The modal element to protect\n * @param {HTMLElement} overlayElement - The overlay element of the modal (not used in current implementation)\n * @param {HTMLElement} editorElement - The editor element inside the modal\n */\n const protect = (modalElement, overlayElement, editorElement) => {\n if (!modalElement || !overlayElement || !editorElement) {\n console.warn(\"FocusProtection: Missing required elements\");\n return;\n }\n\n // Apply the focus protection\n overrideFocusBehavior(modalElement, editorElement);\n };\n\n /**\n * Apply focus protection by overriding focus-related methods\n *\n * @param {HTMLElement} modalElement - The modal element\n * @param {HTMLElement} editorElement - The editor element to keep focused\n * @private\n */\n const overrideFocusBehavior = (modalElement, editorElement) => {\n // Store original focus methods to be able to restore them\n const originalElementFocus = HTMLElement.prototype.focus;\n const originalElementBlur = HTMLElement.prototype.blur;\n\n // Override the focus method for all elements\n HTMLElement.prototype.focus = function (...args) {\n // If the modal is open and this is not part of the modal, prevent focus\n if (modalElement.style.display !== \"none\" && !modalElement.contains(this) && this !== document.body) {\n // If some external script is trying to focus another element, prevent it\n // and restore focus to the editor\n if (editorElement) {\n // Use the original focus method to avoid infinite recursion\n originalElementFocus.apply(editorElement, args);\n }\n return;\n }\n\n // Otherwise, allow the focus to happen\n originalElementFocus.apply(this, args);\n };\n\n // Store the methods to remove them when the modal is closed\n modalElement.originalElementFocus = originalElementFocus;\n modalElement.originalElementBlur = originalElementBlur;\n };\n\n /**\n * Remove focus protection from the modal\n *\n * @param {HTMLElement} modalElement - The modal element to unprotect\n */\n const unprotect = (modalElement) => {\n if (!modalElement) {\n return;\n }\n\n // Restore original focus methods\n if (modalElement.originalElementFocus) {\n HTMLElement.prototype.focus = modalElement.originalElementFocus;\n delete modalElement.originalElementFocus;\n }\n\n if (modalElement.originalElementBlur) {\n HTMLElement.prototype.blur = modalElement.originalElementBlur;\n delete modalElement.originalElementBlur;\n }\n };\n\n return {\n protect,\n unprotect,\n };\n};\n\nexport default focusProtection;\n","// eslint-disable-next-line max-classes-per-file\nimport PopUpMessage from \"./popupmessage\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport Listeners from \"./listeners\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Telemeter from \"./telemeter\";\nimport IntegrationModel from \"./integrationmodel\";\nimport Core from \"./core.src\";\nimport focusProtection from \"./focusprotection\";\nimport closeIcon from \"../styles/icons/general/close_icon.svg\"; //eslint-disable-line\nimport closeHoverIcon from \"../styles/icons/hover/close_icon_h.svg\"; //eslint-disable-line\nimport fullsIcon from \"../styles/icons/general/fulls_icon.svg\"; //eslint-disable-line\nimport fullsHoverIcon from \"../styles/icons/hover/fulls_icon_h.svg\"; //eslint-disable-line\nimport minIcon from \"../styles/icons/general/min_icon.svg\"; //eslint-disable-line\nimport minHoverIcon from \"../styles/icons/hover/min_icon_h.svg\"; //eslint-disable-line\nimport minsIcon from \"../styles/icons/general/mins_icon.svg\"; //eslint-disable-line\nimport minsHoverIcon from \"../styles/icons/hover/mins_icon_h.svg\"; //eslint-disable-line\nimport maxIcon from \"../styles/icons/general/max_icon.svg\"; //eslint-disable-line\nimport maxHoverIcon from \"../styles/icons/hover/max_icon_h.svg\"; //eslint-disable-line\nconst { unprotect, protect } = focusProtection();\n\n/**\n * @typedef {Object} DeviceProperties\n * @property {String} DeviceProperties.orientation - Indicates of the orientation of the device.\n * @property {Boolean} DeviceProperties.isAndroid - True if the device is Android. False otherwise.\n * @property {Boolean} DeviceProperties.isIOS - True if the device is iOS. False otherwise.\n * @property {Boolean} DeviceProperties.isMobile - True if the device is a mobile one.\n * False otherwise.\n * @property {Boolean} DeviceProperties.isDesktop - True if the device is a desktop one.\n * False otherwise.\n */\n\nexport default class ModalDialog {\n /**\n * @classdesc\n * This class represents a modal dialog. The modal dialog admits\n * a {@link ContentManager} instance to manage the content of the dialog.\n * @constructs\n * @param {Object} modalDialogAttributes - An object containing all modal dialog attributes.\n */\n constructor(modalDialogAttributes) {\n this.attributes = modalDialogAttributes;\n\n // Metrics.\n const ua = navigator.userAgent.toLowerCase();\n const isAndroid = ua.indexOf(\"android\") > -1;\n const isIOS = ContentManager.isIOS();\n this.iosSoftkeyboardOpened = false;\n this.iosMeasureUnit = ua.indexOf(\"crios\") === -1 ? \"%\" : \"vh\";\n this.iosDivHeight = `auto`;\n\n const deviceWidth = window.outerWidth;\n const deviceHeight = window.outerHeight;\n\n const landscape = deviceWidth > deviceHeight;\n const portrait = deviceWidth < deviceHeight;\n\n // TODO: Detect isMobile without using editor metrics.\n const isLandscape = landscape && this.attributes.height > deviceHeight;\n const isPortrait = portrait && this.attributes.width > deviceWidth;\n const isMobile = ContentManager.isMobile();\n\n // Obtain number of current instance.\n this.instanceId = document.getElementsByClassName(\"wrs_modal_dialogContainer\").length;\n\n // Device object properties.\n\n /**\n * @type {DeviceProperties}\n */\n this.deviceProperties = {\n orientation: landscape ? \"landscape\" : \"portrait\",\n isAndroid,\n isIOS,\n isMobile,\n isDesktop: !isMobile && !isIOS && !isAndroid,\n };\n\n this.properties = {\n created: false,\n state: \"\",\n previousState: \"\",\n position: { bottom: 0, right: 10 },\n size: { height: 338, width: 580 },\n };\n\n /**\n * Object to keep website's style before change it on lock scroll for mobile devices.\n * @type {Object}\n * @property {String} bodyStylePosition - Previous body style position.\n * @property {String} bodyStyleOverflow - Previous body style overflow.\n * @property {String} htmlStyleOverflow - Previous body style overflow.\n * @property {String} windowScrollX - Previous window's scroll Y.\n * @property {String} windowScrollY - Previous window's scroll X.\n */\n this.websiteBeforeLockParameters = null;\n\n let attributes = {};\n attributes.class = \"wrs_modal_overlay\";\n attributes.id = this.getElementId(attributes.class);\n this.overlay = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title_bar\";\n attributes.id = this.getElementId(attributes.class);\n this.titleBar = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title\";\n attributes.id = this.getElementId(attributes.class);\n this.title = Util.createElement(\"div\", attributes);\n this.title.innerHTML = \"offline\";\n\n attributes = {};\n attributes.class = \"wrs_modal_close_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"close\");\n attributes.style = {};\n this.closeDiv = Util.createElement(\"a\", attributes);\n this.closeDiv.setAttribute(\"role\", \"button\");\n this.closeDiv.setAttribute(\"tabindex\", 3);\n // Apply styles and events after the creation as createElement doesn't process them correctly\n let generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`;\n let hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`;\n this.closeDiv.setAttribute(\"style\", generalStyle);\n this.closeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.closeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identifiy the element in automated testing\n this.closeDiv.setAttribute(\"data-testid\", \"mtcteditor-close-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_stack_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"exit_fullscreen\");\n this.stackDiv = Util.createElement(\"a\", attributes);\n this.stackDiv.setAttribute(\"role\", \"button\");\n this.stackDiv.setAttribute(\"tabindex\", 2);\n generalStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`;\n hoverStyle = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`;\n this.stackDiv.setAttribute(\"style\", generalStyle);\n this.stackDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.stackDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identifiy the element in automated testing\n this.stackDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-disable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_maximize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"fullscreen\");\n this.maximizeDiv = Util.createElement(\"a\", attributes);\n this.maximizeDiv.setAttribute(\"role\", \"button\");\n this.maximizeDiv.setAttribute(\"tabindex\", 2);\n generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`;\n hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`;\n this.maximizeDiv.setAttribute(\"style\", generalStyle);\n this.maximizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.maximizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identifiy the element in automated testing\n this.maximizeDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-enable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_minimize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"minimize\");\n this.minimizeDiv = Util.createElement(\"a\", attributes);\n this.minimizeDiv.setAttribute(\"role\", \"button\");\n this.minimizeDiv.setAttribute(\"tabindex\", 1);\n generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n // To identify the element in automated testing\n this.minimizeDiv.setAttribute(\"data-testid\", \"mtcteditor-minimize-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_dialogContainer\";\n attributes.id = this.getElementId(attributes.class);\n attributes.role = \"dialog\";\n this.container = Util.createElement(\"div\", attributes);\n this.container.setAttribute(\"aria-labeledby\", \"wrs_modal_title[0]\");\n\n attributes = {};\n attributes.class = \"wrs_modal_wrapper\";\n attributes.id = this.getElementId(attributes.class);\n this.wrapper = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_content_container\";\n attributes.id = this.getElementId(attributes.class);\n this.contentContainer = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_controls\";\n attributes.id = this.getElementId(attributes.class);\n this.controls = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_buttons_container\";\n attributes.id = this.getElementId(attributes.class);\n this.buttonContainer = Util.createElement(\"div\", attributes);\n\n // Buttons: all button must be created using createSubmitButton method.\n this.submitButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_accept\"),\n class: \"wrs_modal_button_accept\",\n innerHTML: StringManager.get(\"accept\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-insert-button\",\n },\n this.submitAction.bind(this),\n );\n\n this.cancelButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_cancel\"),\n class: \"wrs_modal_button_cancel\",\n innerHTML: StringManager.get(\"cancel\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cancel-button\",\n },\n this.cancelAction.bind(this),\n );\n\n this.contentManager = null;\n\n // Overlay popup.\n const popupStrings = {\n cancelString: StringManager.get(\"cancel\"),\n submitString: StringManager.get(\"close\"),\n message: StringManager.get(\"close_modal_warning\"),\n };\n\n const callbacks = {\n closeCallback: () => {\n this.close(\"mtc_close\");\n },\n cancelCallback: () => {\n this.focus();\n },\n };\n\n const popupupProperties = {\n overlayElement: this.container,\n callbacks,\n strings: popupStrings,\n };\n\n this.popup = new PopUpMessage(popupupProperties);\n\n /**\n * Indicates if directionality of the modal dialog is RTL. false by default.\n * @type {Boolean}\n */\n this.rtl = false;\n if (\"rtl\" in this.attributes) {\n this.rtl = this.attributes.rtl;\n }\n\n // Event handlers need modal instance context.\n this.handleOpenedIosSoftkeyboard = this.handleOpenedIosSoftkeyboard.bind(this);\n this.handleClosedIosSoftkeyboard = this.handleClosedIosSoftkeyboard.bind(this);\n }\n\n /**\n * This method sets an ContentManager instance to ModalDialog. ContentManager\n * manages the logic of ModalDialog content: submit, update, close and changes.\n * @param {ContentManager} contentManager - ContentManager instance.\n */\n setContentManager(contentManager) {\n this.contentManager = contentManager;\n }\n\n /**\n * Returns the modal contentElement object.\n * @returns {ContentManager} the instance of the ContentManager class.\n */\n getContentManager() {\n return this.contentManager;\n }\n\n /**\n * This method is called when the modal object has been submitted. Calls\n * contentElement submitAction method - if exists - and closes the modal\n * object. No logic about the content should be placed here,\n * contentElement.submitAction is the responsible of the content logic.\n */\n async submitAction() {\n if (typeof this.contentManager.submitAction !== \"undefined\") {\n this.contentManager.submitAction();\n }\n\n await this.close(\"mtc_insert\");\n }\n\n /**\n * Performs the cancel action.\n * If there are no changes in the content, it closes the modal.\n * Otherwise, it shows a pop-up message to confirm the cancel action.\n * @returns {Promise} - A promise that resolves when the modal is closed.\n */\n async cancelAction() {\n if (typeof this.contentManager.hasChanges === \"undefined\" || !this.contentManager.hasChanges()) {\n IntegrationModel.setActionsOnCancelButtons();\n await this.close(\"mtc_close\");\n } else {\n this.showPopUpMessage();\n }\n }\n\n /**\n * Returns a button element.\n * @param {Object} properties - Input button properties.\n * @param {String} properties.class - Input button class.\n * @param {String} properties.innerHTML - Input button innerHTML.\n * @param {Object} callback - Callback function associated to click event.\n * @returns {HTMLButtonElement} The button element.\n *\n */\n // eslint-disable-next-line class-methods-use-this\n createSubmitButton(properties, callback) {\n class SubmitButton {\n constructor() {\n this.element = document.createElement(\"button\");\n this.element.id = properties.id;\n this.element.className = properties.class;\n this.element.innerHTML = properties.innerHTML;\n this.element.dataset.testid = properties[\"data-testid\"];\n Util.addEvent(this.element, \"click\", callback);\n }\n\n getElement() {\n return this.element;\n }\n }\n return new SubmitButton(properties, callback).getElement();\n }\n\n /**\n * Creates the modal window object inserting a contentElement object.\n */\n create() {\n /* Modal Window Structure\n _____________________________________________________________________________________\n |wrs_modal_dialog_Container |\n | _________________________________________________________________________________ |\n | |title_bar minimize_button stack_button close_button | |\n | |_______________________________________________________________________________| |\n | |wrapper | |\n | | _____________________________________________________________________________ | |\n | | |content | | |\n | | | | | |\n | | | | | |\n | | |___________________________________________________________________________| | |\n | | _____________________________________________________________________________ | |\n | | |controls | | |\n | | | ___________________________________ | | |\n | | | |buttonContainer | | | |\n | | | | _______________________________ | | | |\n | | | | |button_accept | button_cancel| | | | |\n | | | |_|_____________ |______________|_| | | |\n | | |___________________________________________________________________________| | |\n | |_______________________________________________________________________________| |\n |___________________________________________________________________________________| */\n\n this.titleBar.appendChild(this.closeDiv);\n this.titleBar.appendChild(this.stackDiv);\n this.titleBar.appendChild(this.maximizeDiv);\n this.titleBar.appendChild(this.minimizeDiv);\n this.titleBar.appendChild(this.title);\n\n if (this.deviceProperties.isDesktop) {\n this.container.appendChild(this.titleBar);\n }\n\n this.wrapper.appendChild(this.contentContainer);\n this.wrapper.appendChild(this.controls);\n\n this.controls.appendChild(this.buttonContainer);\n\n this.buttonContainer.appendChild(this.submitButton);\n this.buttonContainer.appendChild(this.cancelButton);\n\n this.container.appendChild(this.wrapper);\n\n // Check if browser has scrollBar before modal has modified.\n this.recalculateScrollBar();\n\n document.body.appendChild(this.container);\n document.body.appendChild(this.overlay);\n\n if (this.deviceProperties.isDesktop) {\n // Desktop.\n this.createModalWindowDesktop();\n this.createResizeButtons();\n\n this.addListeners();\n // Maximize window only when the configuration is set and the device is not iOS or Android.\n if (Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n } else if (this.deviceProperties.isAndroid) {\n this.createModalWindowAndroid();\n } else if (this.deviceProperties.isIOS) {\n this.createModalWindowIos();\n }\n\n if (this.contentManager != null) {\n this.contentManager.insert(this);\n }\n\n this.properties.open = true;\n this.properties.created = true;\n\n // Checks language directionality.\n if (this.isRTL()) {\n this.container.style.right = `${window.innerWidth - this.scrollbarWidth - this.container.offsetWidth}px`;\n this.container.className += \" wrs_modal_rtl\";\n }\n }\n\n /**\n * Creates a button in the modal object to resize it.\n */\n createResizeButtons() {\n // This is a definition of Resize Button Bottom-Right.\n this.resizerBR = document.createElement(\"div\");\n this.resizerBR.className = \"wrs_bottom_right_resizer\";\n this.resizerBR.innerHTML = \"◢\";\n // To identifiy the element in automated testing\n this.resizerBR.dataset.testid = \"mtcteditor-resize-button-right\";\n // This is a definition of Resize Button Top-Left.\n this.resizerTL = document.createElement(\"div\");\n this.resizerTL.className = \"wrs_bottom_left_resizer\";\n // To identifiy the element in automated testing\n this.resizerTL.dataset.testid = \"mtcteditor-resize-button-left\";\n // Append resize buttons to modal.\n this.container.appendChild(this.resizerBR);\n this.titleBar.appendChild(this.resizerTL);\n // Add events to resize on click and drag.\n Util.addEvent(this.resizerBR, \"mousedown\", this.activateResizeStateBR.bind(this));\n Util.addEvent(this.resizerTL, \"mousedown\", this.activateResizeStateTL.bind(this));\n }\n\n /**\n * Initialize variables for Bottom-Right resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateBR(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, false);\n }\n\n /**\n * Initialize variables for Top-Left resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateTL(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, true);\n }\n\n /**\n * Common method to initialize variables at resize.\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n initializeResizeProperties(mouseEvent, leftOption) {\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n this.resizeDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Save Initial state of modal to compare on drag and obtain the difference.\n this.initialWidth = parseInt(this.container.style.width, 10);\n this.initialHeight = parseInt(this.container.style.height, 10);\n if (!leftOption) {\n this.initialRight = parseInt(this.container.style.right, 10);\n this.initialBottom = parseInt(this.container.style.bottom, 10);\n } else {\n this.leftScale = true;\n }\n if (!this.initialRight) {\n this.initialRight = 0;\n }\n if (!this.initialBottom) {\n this.initialBottom = 0;\n }\n // Disable mouse events on editor when we start to drag modal.\n document.body.style[\"user-select\"] = \"none\";\n }\n\n /**\n * This method opens the modal window, restoring the previous state, position and metrics,\n * if exists. By default the modal object opens in stack mode.\n */\n open() {\n // Removing close class.\n this.removeClass(\"wrs_closed\");\n // Hiding keyboard for mobile devices.\n const { isIOS } = this.deviceProperties;\n const { isAndroid } = this.deviceProperties;\n const { isMobile } = this.deviceProperties;\n if (isIOS || isAndroid || isMobile) {\n // Restore scale to 1.\n this.restoreWebsiteScale();\n this.lockWebsiteScroll();\n // Due to editor wait we need to wait until editor focus.\n setTimeout(() => {\n this.hideKeyboard();\n }, 400);\n }\n\n // New modal window. He need to create the whole object.\n if (!this.properties.created) {\n this.create();\n } else {\n // Previous state closed. Open method can be called even the previous state is open,\n // for example updating the content of the modal object.\n if (!this.properties.open) {\n this.properties.open = true;\n\n // Restoring the previous open state: if the modal object has been closed\n // re-open it should preserve the state and the metrics.\n if (!this.deviceProperties.isAndroid && !this.deviceProperties.isIOS) {\n this.restoreState();\n }\n }\n\n // Maximize window only when the configuration is set and the device is not iOs or Android.\n if (this.deviceProperties.isDesktop && Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n\n // In iOS we need to recalculate the size of the modal object because\n // iOS keyboard is a float div which can overlay the modal object.\n if (this.deviceProperties.isIOS) {\n this.iosSoftkeyboardOpened = false;\n }\n }\n\n if (!ContentManager.isEditorLoaded()) {\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.displayEditor();\n });\n this.contentManager.addListener(listener);\n } else {\n this.displayEditor();\n }\n }\n\n /**\n * Prepares and displays the editor in the modal.\n *\n * This method is responsible for displaying the MathType editor inside the modal container.\n *\n * For Moodle environments, it applies focus protection to prevent external scripts\n * from hijacking focus away from the editor while it's open. This is particularly\n * important in Moodle which may have its own focus management scripts.\n * @returns {void}\n */\n displayEditor() {\n if (this.contentManager.integrationModel.isMoodle) {\n protect(this.container, this.overlay, this.contentContainer);\n }\n\n // Initialize and open the editor using the contentManager.\n this.contentManager.onOpen(this);\n }\n\n /**\n * Closes the modal.\n * Removes specific CSS classes, saves modal properties, unlocks website scroll,\n * sets the 'open' property to false, and triggers the 'onModalClose' event.\n * If a close trigger is defined, it tracks the telemetry event 'CLOSED_MTCT_EDITOR' with the trigger.\n * @returns {Promise} A promise that resolves when the modal is closed.\n */\n async close(trigger) {\n // Remove focus protection before closing\n unprotect(this.container);\n\n this.removeClass(\"wrs_maximized\");\n this.removeClass(\"wrs_minimized\");\n this.removeClass(\"wrs_stack\");\n this.addClass(\"wrs_closed\");\n this.saveModalProperties();\n this.unlockWebsiteScroll();\n this.properties.open = false;\n\n if (trigger) {\n try {\n await Telemeter.telemeter.track(\"CLOSED_MTCT_EDITOR\", {\n toolbar: this.contentManager.toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking CLOSED_MTCT_EDITOR\", error);\n }\n }\n\n Core.globalListeners.fire(\"onModalClose\", {});\n }\n\n /**\n * Closes modal window and destroys the object.\n */\n destroy() {\n // Remove focus protection before destroying\n unprotect(this.container);\n\n // Close modal window.\n this.close();\n // Remove listeners and destroy the object.\n this.removeListeners();\n this.overlay.remove();\n this.container.remove();\n // Reset properties to allow open again.\n this.properties.created = false;\n }\n\n /**\n * Sets the website scale to one.\n */\n // eslint-disable-next-line class-methods-use-this\n restoreWebsiteScale() {\n let viewportmeta = document.querySelector(\"meta[name=viewport]\");\n // Let the equal symbols in order to search and make meta's final content.\n const contentAttrsToUpdate = [\"initial-scale=\", \"minimum-scale=\", \"maximum-scale=\"];\n const contentAttrsValuesToUpdate = [\"1.0\", \"1.0\", \"1.0\"];\n const setMetaAttrFunc = (viewportelement, contentAttrs) => {\n const contentAttr = viewportelement.getAttribute(\"content\");\n // If it exists, we need to maintain old values and put our values.\n if (contentAttr) {\n const attrArray = contentAttr.split(\",\");\n let finalContentMeta = \"\";\n const oldAttrs = [];\n for (let i = 0; i < attrArray.length; i += 1) {\n let isAttrToUpdate = false;\n let j = 0;\n while (!isAttrToUpdate && j < contentAttrs.length) {\n if (attrArray[i].indexOf(contentAttrs[j])) {\n isAttrToUpdate = true;\n }\n j += 1;\n }\n\n if (!isAttrToUpdate) {\n oldAttrs.push(attrArray[i]);\n }\n }\n\n for (let i = 0; i < contentAttrs.length; i += 1) {\n const attr = contentAttrs[i] + contentAttrsValuesToUpdate[i];\n finalContentMeta += i === 0 ? attr : `,${attr}`;\n }\n\n for (let i = 0; i < oldAttrs.length; i += 1) {\n finalContentMeta += `,${oldAttrs[i]}`;\n }\n viewportelement.setAttribute(\"content\", finalContentMeta);\n // It needs to set to empty because setAttribute refresh only when attribute is different.\n viewportelement.setAttribute(\"content\", \"\");\n viewportelement.setAttribute(\"content\", contentAttr);\n } else {\n viewportelement.setAttribute(\"content\", \"initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0\");\n viewportelement.removeAttribute(\"content\");\n }\n };\n\n if (!viewportmeta) {\n viewportmeta = document.createElement(\"meta\");\n document.getElementsByTagName(\"head\")[0].appendChild(viewportmeta);\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n viewportmeta.remove();\n } else {\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n }\n }\n\n /**\n * Locks website scroll for mobile devices.\n */\n lockWebsiteScroll() {\n this.websiteBeforeLockParameters = {\n bodyStylePosition: document.body.style.position ? document.body.style.position : \"\",\n bodyStyleOverflow: document.body.style.overflow ? document.body.style.overflow : \"\",\n htmlStyleOverflow: document.documentElement.style.overflow ? document.documentElement.style.overflow : \"\",\n windowScrollX: window.scrollX,\n windowScrollY: window.scrollY,\n };\n }\n\n /**\n * Unlocks website scroll for mobile devices.\n */\n unlockWebsiteScroll() {\n if (this.websiteBeforeLockParameters) {\n document.body.style.position = this.websiteBeforeLockParameters.bodyStylePosition;\n document.body.style.overflow = this.websiteBeforeLockParameters.bodyStyleOverflow;\n document.documentElement.style.overflow = this.websiteBeforeLockParameters.htmlStyleOverflow;\n const { windowScrollX } = this.websiteBeforeLockParameters;\n const { windowScrollY } = this.websiteBeforeLockParameters;\n window.scrollTo(windowScrollX, windowScrollY);\n this.websiteBeforeLockParameters = null;\n }\n }\n\n /**\n * Util function to known if browser is IE11.\n * @returns {Boolean} true if the browser is IE11. false otherwise.\n */\n // eslint-disable-next-line class-methods-use-this\n isIE11() {\n if (\n navigator.userAgent.search(\"Msie/\") >= 0 ||\n navigator.userAgent.search(\"Trident/\") >= 0 ||\n navigator.userAgent.search(\"Edge/\") >= 0\n ) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns if the current language type is RTL.\n * @return {Boolean} true if current language is RTL. false otherwise.\n */\n isRTL() {\n if (this.attributes.language === \"ar\" || this.attributes.language === \"he\") {\n return true;\n }\n return this.rtl;\n }\n\n /**\n * Adds a class to all modal ModalDialog DOM elements.\n * @param {String} className - Class name.\n */\n addClass(className) {\n Util.addClass(this.overlay, className);\n Util.addClass(this.titleBar, className);\n Util.addClass(this.overlay, className);\n Util.addClass(this.container, className);\n Util.addClass(this.contentContainer, className);\n Util.addClass(this.stackDiv, className);\n Util.addClass(this.minimizeDiv, className);\n Util.addClass(this.maximizeDiv, className);\n Util.addClass(this.wrapper, className);\n }\n\n /**\n * Remove a class from all modal DOM elements.\n * @param {String} className - Class name.\n */\n removeClass(className) {\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.titleBar, className);\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.container, className);\n Util.removeClass(this.contentContainer, className);\n Util.removeClass(this.stackDiv, className);\n Util.removeClass(this.minimizeDiv, className);\n Util.removeClass(this.maximizeDiv, className);\n Util.removeClass(this.wrapper, className);\n }\n\n /**\n * Create modal dialog for desktop.\n */\n createModalWindowDesktop() {\n this.addClass(\"wrs_modal_desktop\");\n this.stack();\n }\n\n /**\n * Create modal dialog for non android devices.\n */\n createModalWindowAndroid() {\n this.addClass(\"wrs_modal_android\");\n window.addEventListener(\"resize\", this.orientationChangeAndroidSoftkeyboard.bind(this));\n }\n\n /**\n * Create modal dialog for iOS devices.\n */\n createModalWindowIos() {\n this.addClass(\"wrs_modal_ios\");\n // Refresh the size when the orientation is changed.\n window.addEventListener(\"resize\", this.orientationChangeIosSoftkeyboard.bind(this));\n }\n\n /**\n * Restore previous state, position and size of previous stacked modal dialog.\n */\n restoreState() {\n if (this.properties.state === \"maximized\") {\n // Reset states for prevent return to stack state.\n this.maximize();\n } else if (this.properties.state === \"minimized\") {\n // Reset states for prevent return to stack state.\n this.properties.state = this.properties.previousState;\n this.properties.previousState = \"\";\n this.minimize();\n } else {\n this.stack();\n }\n }\n\n /**\n * Stacks the modal object.\n */\n stack() {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"stack\";\n this.removeClass(\"wrs_maximized\");\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n this.addClass(\"wrs_stack\");\n\n // Change maximize/minimize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n\n this.restoreModalProperties();\n\n if (typeof this.resizerBR !== \"undefined\" && typeof this.resizerTL !== \"undefined\") {\n this.setResizeButtonsVisibility();\n }\n\n // Need recalculate position of actual modal because window can was changed in fullscreenmode.\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n this.focus();\n }\n\n /**\n * Minimizes the modal object.\n */\n minimize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n this.title.style.cursor = \"pointer\";\n if (this.properties.state === \"minimized\" && this.properties.previousState === \"stack\") {\n this.stack();\n } else if (this.properties.state === \"minimized\" && this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n // Setting css to prevent important tag into css style.\n this.container.style.height = \"30px\";\n this.container.style.width = \"250px\";\n this.container.style.bottom = \"0px\";\n this.container.style.right = \"10px\";\n\n this.removeListeners();\n this.properties.previousState = this.properties.state;\n this.properties.state = \"minimized\";\n this.setResizeButtonsVisibility();\n this.minimizeDiv.title = StringManager.get(\"maximize\");\n\n if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.removeClass(\"wrs_stack\");\n } else {\n this.removeClass(\"wrs_maximized\");\n }\n this.addClass(\"wrs_minimized\");\n\n // Change minimize icon to maximize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n }\n }\n\n /**\n * Maximizes the modal object.\n */\n maximize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n if (this.properties.state !== \"maximized\") {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"maximized\";\n }\n // Don't permit resize on maximize mode.\n this.setResizeButtonsVisibility();\n\n if (Util.containsClass(this.overlay, \"wrs_minimized\")) {\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n } else if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.container.style.left = null;\n this.container.style.top = null;\n this.removeClass(\"wrs_stack\");\n }\n\n this.addClass(\"wrs_maximized\");\n\n // Change maximize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.setAttribute(\"onmouseover\", `this.style = \"${hoverStyle}\";`);\n this.minimizeDiv.setAttribute(\"onmouseout\", `this.style = \"${generalStyle}\";`);\n\n // Set size to 80% screen with a max size.\n this.setSize(parseInt(window.innerHeight * 0.8, 10), parseInt(window.innerWidth * 0.8, 10));\n if (this.container.clientHeight > 700) {\n this.container.style.height = \"700px\";\n }\n if (this.container.clientWidth > 1200) {\n this.container.style.width = \"1200px\";\n }\n\n // Setting modal position in center on screen.\n const { innerHeight } = window;\n const { innerWidth } = window;\n const { offsetHeight } = this.container;\n const { offsetWidth } = this.container;\n const bottom = innerHeight / 2 - offsetHeight / 2;\n const right = innerWidth / 2 - offsetWidth / 2;\n\n this.setPosition(bottom, right);\n this.recalculateScale();\n this.recalculatePosition();\n this.recalculateSize();\n this.focus();\n }\n\n /**\n * Expand again the modal object from a minimized state.\n */\n reExpand() {\n if (this.properties.state === \"minimized\") {\n if (this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n this.stack();\n }\n this.title.style.cursor = \"\";\n }\n }\n\n /**\n * Sets modal size.\n * @param {Number} height - Height of the ModalDialog\n * @param {Number} width - Width of the ModalDialog.\n */\n setSize(height, width) {\n this.container.style.height = `${height}px`;\n this.container.style.width = `${width}px`;\n this.recalculateSize();\n }\n\n /**\n * Sets modal position using bottom and right style attributes.\n * @param {number} bottom - bottom attribute.\n * @param {number} right - right attribute.\n */\n setPosition(bottom, right) {\n this.container.style.bottom = `${bottom}px`;\n this.container.style.right = `${right}px`;\n }\n\n /**\n * Saves position and size parameters of and open ModalDialog. This attributes\n * are needed to restore it on re-open.\n */\n saveModalProperties() {\n // Saving values of modal only when modal is in stack state.\n if (this.properties.state === \"stack\") {\n this.properties.position.bottom = parseInt(this.container.style.bottom, 10);\n this.properties.position.right = parseInt(this.container.style.right, 10);\n this.properties.size.width = parseInt(this.container.style.width, 10);\n this.properties.size.height = parseInt(this.container.style.height, 10);\n }\n }\n\n /**\n * Restore ModalDialog position and size parameters.\n */\n restoreModalProperties() {\n if (this.properties.state === \"stack\") {\n // Restoring Bottom and Right values from last modal.\n this.setPosition(this.properties.position.bottom, this.properties.position.right);\n // Restoring Height and Left values from last modal.\n this.setSize(this.properties.size.height, this.properties.size.width);\n }\n }\n\n /**\n * Sets the modal dialog initial size.\n */\n recalculateSize() {\n this.contentContainer.style.height = `${parseInt(this.wrapper.offsetHeight - 50, 10)}px`;\n }\n\n /**\n * Enable or disable visibility of resize buttons in modal window depend on state.\n */\n setResizeButtonsVisibility() {\n if (this.properties.state === \"stack\") {\n this.resizerTL.style.visibility = \"visible\";\n this.resizerBR.style.visibility = \"visible\";\n } else {\n this.resizerTL.style.visibility = \"hidden\";\n this.resizerBR.style.visibility = \"hidden\";\n }\n }\n\n /**\n * Makes an object draggable adding mouse and touch events.\n */\n addListeners() {\n // Button events (maximize, minimize, stack and close).\n this.maximizeDiv.addEventListener(\"click\", this.maximize.bind(this), true);\n this.stackDiv.addEventListener(\"click\", this.stack.bind(this), true);\n this.minimizeDiv.addEventListener(\"click\", this.minimize.bind(this), true);\n this.closeDiv.addEventListener(\"click\", this.cancelAction.bind(this));\n this.maximizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n }\n },\n true,\n );\n this.stackDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.minimizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.closeDiv.addEventListener(\"keypress\", (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n });\n this.title.addEventListener(\"click\", this.reExpand.bind(this));\n\n // Overlay events (close).\n this.overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n // Mouse events.\n Util.addEvent(window, \"mousedown\", this.startDrag.bind(this));\n Util.addEvent(window, \"mouseup\", this.stopDrag.bind(this));\n Util.addEvent(window, \"mousemove\", this.drag.bind(this));\n Util.addEvent(window, \"resize\", this.onWindowResize.bind(this));\n // Key events.\n Util.addEvent(window, \"keydown\", this.onKeyDown.bind(this));\n }\n\n /**\n * Removes draggable events from an object.\n */\n removeListeners() {\n // Mouse events.\n Util.removeEvent(window, \"mousedown\", this.startDrag);\n Util.removeEvent(window, \"mouseup\", this.stopDrag);\n Util.removeEvent(window, \"mousemove\", this.drag);\n Util.removeEvent(window, \"resize\", this.onWindowResize);\n // Key events.\n Util.removeEvent(window, \"keydown\", this.onKeyDown);\n }\n\n /**\n * Returns mouse or touch coordinates (on touch events ev.ClientX doesn't exists)\n * @param {MouseEvent} mouseEvent - Mouse event.\n * @return {Object} With the X and Y coordinates.\n */\n // eslint-disable-next-line class-methods-use-this\n eventClient(mouseEvent) {\n if (typeof mouseEvent.clientX === \"undefined\" && mouseEvent.changedTouches) {\n const client = {\n X: mouseEvent.changedTouches[0].clientX,\n Y: mouseEvent.changedTouches[0].clientY,\n };\n return client;\n }\n const client = {\n X: mouseEvent.clientX,\n Y: mouseEvent.clientY,\n };\n return client;\n }\n\n /**\n * Start drag function: set the object dragDataObject with the draggable\n * object offsets coordinates.\n * when drag starts (on touchstart or mousedown events).\n * @param {MouseEvent} mouseEvent - Touchstart or mousedown event.\n */\n startDrag(mouseEvent) {\n if (this.properties.state === \"minimized\") {\n return;\n }\n if (mouseEvent.target === this.title) {\n if (typeof this.dragDataObject === \"undefined\" || this.dragDataObject === null) {\n // Save first click mouse point on screen.\n this.dragDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Reset last drag position when start drag.\n this.lastDrag = {\n x: \"0px\",\n y: \"0px\",\n };\n // Init right and bottom values for window modal if it isn't exist.\n if (this.container.style.right === \"\") {\n this.container.style.right = \"0px\";\n }\n if (this.container.style.bottom === \"\") {\n this.container.style.bottom = \"0px\";\n }\n\n // Needed for IE11 for apply disabled mouse events on editor because\n // internet explorer needs a dynamic object to apply this property.\n if (this.isIE11()) {\n // this.iframe.style['position'] = 'relative';\n }\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n // Obtain screen limits for prevent overflow.\n this.limitWindow = this.getLimitWindow();\n }\n }\n }\n\n /**\n * Updates dragDataObject with the draggable object coordinates when\n * the draggable object is being moved.\n * @param {MouseEvent} mouseEvent - The mouse event.\n */\n drag(mouseEvent) {\n if (this.dragDataObject) {\n mouseEvent.preventDefault();\n // Calculate max and min between actual mouse position and limit of screeen.\n // It restric the movement of modal into window.\n let limitY = Math.min(this.eventClient(mouseEvent).Y, this.limitWindow.minPointer.y);\n limitY = Math.max(this.limitWindow.maxPointer.y, limitY);\n let limitX = Math.min(this.eventClient(mouseEvent).X, this.limitWindow.minPointer.x);\n limitX = Math.max(this.limitWindow.maxPointer.x, limitX);\n // Subtract limit with first position to obtain relative pixels increment\n // to the anchor point.\n const dragX = `${limitX - this.dragDataObject.x}px`;\n const dragY = `${limitY - this.dragDataObject.y}px`;\n // Save last valid position of modal before window overflow.\n this.lastDrag = {\n x: dragX,\n y: dragY,\n };\n // This move modal with hardware acceleration.\n this.container.style.transform = `translate3d(${dragX},${dragY},0)`;\n }\n if (this.resizeDataObject) {\n const { innerWidth } = window;\n const { innerHeight } = window;\n let limitX = Math.min(this.eventClient(mouseEvent).X, innerWidth - this.scrollbarWidth - 7);\n let limitY = Math.min(this.eventClient(mouseEvent).Y, innerHeight - 7);\n if (limitX < 0) {\n limitX = 0;\n }\n\n if (limitY < 0) {\n limitY = 0;\n }\n\n let scaleMultiplier;\n if (this.leftScale) {\n scaleMultiplier = -1;\n } else {\n scaleMultiplier = 1;\n }\n\n this.container.style.width = `${this.initialWidth + scaleMultiplier * (limitX - this.resizeDataObject.x)}px`;\n this.container.style.height = `${this.initialHeight + scaleMultiplier * (limitY - this.resizeDataObject.y)}px`;\n if (!this.leftScale) {\n if (this.resizeDataObject.x - limitX - this.initialWidth < -580) {\n this.container.style.right = `${this.initialRight - (limitX - this.resizeDataObject.x)}px`;\n } else {\n this.container.style.right = `${this.initialRight + this.initialWidth - 580}px`;\n this.container.style.width = \"580px\";\n }\n if (this.resizeDataObject.y - limitY < this.initialHeight - 338) {\n this.container.style.bottom = `${this.initialBottom - (limitY - this.resizeDataObject.y)}px`;\n } else {\n this.container.style.bottom = `${this.initialBottom + this.initialHeight - 338}px`;\n this.container.style.height = \"338px\";\n }\n }\n this.recalculateScale();\n this.recalculatePosition();\n }\n }\n\n /**\n * Returns the boundaries of actual window to limit modal movement.\n * @return {Object} Object containing mouseX and mouseY coordinates of actual mouse on screen.\n */\n getLimitWindow() {\n // Obtain dimensions of window page.\n const maxWidth = window.innerWidth;\n const maxHeight = window.innerHeight;\n\n // Calculate relative position of mouse point into window.\n const { offsetHeight } = this.container;\n const contStyleBottom = parseInt(this.container.style.bottom, 10);\n const contStyleRight = parseInt(this.container.style.right, 10);\n\n const { pageXOffset } = window;\n const dragY = this.dragDataObject.y;\n const dragX = this.dragDataObject.x;\n\n const offSetToolbarY = offsetHeight + contStyleBottom - (maxHeight - (dragY - pageXOffset));\n const offSetToolbarX = maxWidth - this.scrollbarWidth - (dragX - pageXOffset) - contStyleRight;\n\n // Calculate limits with sizes of window, modal and mouse position.\n const minPointerY = maxHeight - this.container.offsetHeight + offSetToolbarY;\n const maxPointerY = this.title.offsetHeight - (this.title.offsetHeight - offSetToolbarY);\n const minPointerX = maxWidth - offSetToolbarX - this.scrollbarWidth;\n const maxPointerX = this.container.offsetWidth - offSetToolbarX;\n const minPointer = { x: minPointerX, y: minPointerY };\n const maxPointer = { x: maxPointerX, y: maxPointerY };\n return { minPointer, maxPointer };\n }\n\n /**\n * Returns the scrollbar width size of browser\n * @returns {Number} The scrollbar width.\n */\n // eslint-disable-next-line class-methods-use-this\n getScrollBarWidth() {\n // Create a paragraph with full width of page.\n const inner = document.createElement(\"p\");\n inner.style.width = \"100%\";\n inner.style.height = \"200px\";\n\n // Create a hidden div to compare sizes.\n const outer = document.createElement(\"div\");\n outer.style.position = \"absolute\";\n outer.style.top = \"0px\";\n outer.style.left = \"0px\";\n outer.style.visibility = \"hidden\";\n outer.style.width = \"200px\";\n outer.style.height = \"150px\";\n outer.style.overflow = \"hidden\";\n outer.appendChild(inner);\n\n document.body.appendChild(outer);\n const widthOuter = inner.offsetWidth;\n\n // Change type overflow of paragraph for measure scrollbar.\n outer.style.overflow = \"scroll\";\n let widthInner = inner.offsetWidth;\n\n // If measure is the same, we compare with internal div.\n if (widthOuter === widthInner) {\n widthInner = outer.clientWidth;\n }\n document.body.removeChild(outer);\n\n return widthOuter - widthInner;\n }\n\n /**\n * Set the dragDataObject to null.\n */\n stopDrag() {\n // Due to we have multiple events that call this function, we need only to execute\n // the next modifiers one time,\n // when the user stops to drag and dragDataObject is not null (the object to drag is attached).\n if (this.dragDataObject || this.resizeDataObject) {\n // If modal doesn't change, it's not necessary to set position with interpolation.\n this.container.style.transform = \"\";\n if (this.dragDataObject) {\n this.container.style.right = `${parseInt(this.container.style.right, 10) - parseInt(this.lastDrag.x, 10)}px`;\n this.container.style.bottom = `${parseInt(this.container.style.bottom, 10) - parseInt(this.lastDrag.y, 10)}px`;\n }\n // We make focus on editor after drag modal windows to prevent lose focus.\n this.focus();\n // Restore mouse events on iframe.\n // this.iframe.style['pointer-events'] = 'auto';\n document.body.style[\"user-select\"] = \"\";\n // Restore static state of iframe if we use Internet Explorer.\n if (this.isIE11()) {\n // this.iframe.style['position'] = null;\n }\n // Active text select event.\n Util.removeClass(document.body, \"wrs_noselect\");\n Util.removeClass(this.overlay, \"wrs_overlay_active\");\n }\n this.dragDataObject = null;\n this.resizeDataObject = null;\n this.initialWidth = null;\n this.leftScale = null;\n }\n\n /**\n * Recalculates scale for modal when resize browser window.\n */\n onWindowResize() {\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n }\n\n /**\n * Triggers keyboard events:\n * - Tab key tab to go to submit button.\n * - Esc key to close the modal dialog.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Popupmessage is not oppened.\n if (this.popup.overlayWrapper.style.display !== \"block\") {\n // Code to detect Esc event\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n if (this.properties.open) {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.cancelButton) {\n this.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.submitButton) {\n this.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n }\n } else {\n // Popupmessage oppened.\n this.popup.onKeyDown(keyboardEvent);\n }\n }\n }\n\n /**\n * Recalculating position for modal dialog when the browser is resized.\n */\n recalculatePosition() {\n this.container.style.right = `${Math.min(parseInt(this.container.style.right, 10), window.innerWidth - this.scrollbarWidth - this.container.offsetWidth)}px`;\n if (parseInt(this.container.style.right, 10) < 0) {\n this.container.style.right = \"0px\";\n }\n this.container.style.bottom = `${Math.min(parseInt(this.container.style.bottom, 10), window.innerHeight - this.container.offsetHeight)}px`;\n if (parseInt(this.container.style.bottom, 10) < 0) {\n this.container.style.bottom = \"0px\";\n }\n }\n\n /**\n * Recalculating scale for modal when the browser is resized.\n */\n recalculateScale() {\n let sizeModified = false;\n\n if (parseInt(this.container.style.width, 10) > 580) {\n this.container.style.width = `${Math.min(parseInt(this.container.style.width, 10), window.innerWidth - this.scrollbarWidth)}px`;\n sizeModified = true;\n } else {\n this.container.style.width = \"580px\";\n sizeModified = true;\n }\n\n if (parseInt(this.container.style.height, 10) > 338) {\n this.container.style.height = `${Math.min(parseInt(this.container.style.height, 10), window.innerHeight)}px`;\n sizeModified = true;\n } else {\n this.container.style.height = \"338px\";\n sizeModified = true;\n }\n\n if (sizeModified) {\n this.recalculateSize();\n }\n }\n\n /**\n * Recalculating width of browser scroll bar.\n */\n recalculateScrollBar() {\n this.hasScrollBar = window.innerWidth > document.documentElement.clientWidth;\n if (this.hasScrollBar) {\n this.scrollbarWidth = this.getScrollBarWidth();\n } else {\n this.scrollbarWidth = 0;\n }\n }\n\n /**\n * Hide soft keyboards on iOS devices.\n */\n // eslint-disable-next-line class-methods-use-this\n hideKeyboard() {\n // iOS keyboard can't be detected or hide directly from JavaScript.\n // So, this method simulates that user focus a text input and blur\n // the selection.\n const inputField = document.createElement(\"input\");\n this.container.appendChild(inputField);\n inputField.focus();\n inputField.blur();\n // Is removed to not see it.\n inputField.remove();\n }\n\n /**\n * Focus to contentManager object.\n */\n focus() {\n if (this.contentManager != null && typeof this.contentManager.onFocus !== \"undefined\") {\n this.contentManager.onFocus();\n }\n }\n\n /**\n * Returns true when the device is on portrait mode.\n */\n // eslint-disable-next-line class-methods-use-this\n portraitMode() {\n return window.innerHeight > window.innerWidth;\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is opened.\n */\n handleOpenedIosSoftkeyboard() {\n if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `auto`) {\n if (this.portraitMode()) {\n this.setContainerHeight(`60${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`35${this.iosMeasureUnit}`);\n }\n }\n this.iosSoftkeyboardOpened = true;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is closed.\n */\n handleClosedIosSoftkeyboard() {\n this.iosSoftkeyboardOpened = false;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Change container sizes when orientation is changed on iOS.\n */\n orientationChangeIosSoftkeyboard() {\n if (this.iosSoftkeyboardOpened) {\n if (this.portraitMode()) {\n this.setContainerHeight(`65${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`45${this.iosMeasureUnit}`);\n }\n } else {\n this.wrapper.style.flexGrow = \"1\";\n }\n }\n\n /**\n * Change container sizes when orientation is changed on Android.\n */\n orientationChangeAndroidSoftkeyboard() {\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Set iframe container height.\n * @param {Number} height - New height.\n */\n setContainerHeight(height) {\n this.iosDivHeight = height;\n this.wrapper.style.height = height;\n }\n\n /**\n * Check content of editor before close action.\n */\n showPopUpMessage() {\n if (this.properties.state === \"minimized\") {\n this.stack();\n }\n this.popup.show();\n }\n\n /**\n * Sets the title of the modal dialog.\n * @param {String} title - Modal dialog title.\n */\n setTitle(title) {\n this.title.innerHTML = title;\n }\n\n /**\n * Returns the id of an element, adding the instance number to\n * the element class name:\n * className --> className[idNumber]\n * @param {String} className - The element class name.\n * @returns {String} A string appending the instance id to the className.\n */\n getElementId(className) {\n return `${className}[${this.instanceId}]`;\n }\n}\n","/* eslint-disable */\nvar polyfills;\nexport default polyfills;\n\n// Polyfills.\n/*! http://mths.be/codepointat v0.1.0 by @mathias */\nif (!String.prototype.codePointAt) {\n (function () {\n \"use strict\"; // needed to support `apply`/`call` with `undefined`/`null`\n var codePointAt = function (position) {\n if (this == null) {\n throw TypeError();\n }\n var string = String(this);\n var size = string.length;\n // `ToInteger`\n var index = position ? Number(position) : 0;\n if (index != index) {\n // better `isNaN`\n index = 0;\n }\n // Account for out-of-bounds indices:\n if (index < 0 || index >= size) {\n return undefined;\n }\n // Get the first code unit\n var first = string.charCodeAt(index);\n var second;\n if (\n // check if it’s the start of a surrogate pair\n first >= 0xd800 &&\n first <= 0xdbff && // high surrogate\n size > index + 1 // there is a next code unit\n ) {\n second = string.charCodeAt(index + 1);\n if (second >= 0xdc00 && second <= 0xdfff) {\n // low surrogate\n // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000;\n }\n }\n return first;\n };\n if (Object.defineProperty) {\n Object.defineProperty(String.prototype, \"codePointAt\", {\n value: codePointAt,\n configurable: true,\n writable: true,\n });\n } else {\n String.prototype.codePointAt = codePointAt;\n }\n })();\n}\n\n// Object.assign polyfill.\nif (typeof Object.assign != \"function\") {\n // Must be writable: true, enumerable: false, configurable: true\n Object.defineProperty(Object, \"assign\", {\n value: function assign(target, varArgs) {\n // .length of function is 2\n \"use strict\";\n if (target == null) {\n // TypeError if undefined or null\n throw new TypeError(\"Cannot convert undefined or null to object\");\n }\n\n var to = Object(target);\n\n for (var index = 1; index < arguments.length; index++) {\n var nextSource = arguments[index];\n\n if (nextSource != null) {\n // Skip over if undefined or null\n for (var nextKey in nextSource) {\n // Avoid bugs when hasOwnProperty is shadowed\n if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {\n to[nextKey] = nextSource[nextKey];\n }\n }\n }\n }\n return to;\n },\n writable: true,\n configurable: true,\n });\n}\n\n// https://tc39.github.io/ecma262/#sec-array.prototype.includes\nif (!Array.prototype.includes) {\n Object.defineProperty(Array.prototype, \"includes\", {\n value: function (searchElement, fromIndex) {\n if (this == null) {\n throw new TypeError('\"this\" s null or is not defined');\n }\n\n // 1. Let O be ? ToObject(this value).\n var o = Object(this);\n\n // 2. Let len be ? ToLength(? Get(O, \"length\")).\n var len = o.length >>> 0;\n\n // 3. if len is 0, return false.\n if (len === 0) {\n return false;\n }\n\n // 4. Let n be ? ToInteger(fromIndex).\n // (if fromIndex is undefinedo, this step generates the value 0.)\n var n = fromIndex | 0;\n\n // 5. if n ≥ 0, then\n // a. Let k be n.\n // 6. Else n < 0,\n // a. Let k be len + n.\n // b. if k < 0, let k be 0.\n var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);\n\n function sameValueZero(x, y) {\n return x === y || (typeof x === \"number\" && typeof y === \"number\" && isNaN(x) && isNaN(y));\n }\n\n // 7. Repeat while k < len\n while (k < len) {\n // a. let element k be the result of ? Get(O, ! ToString(k)).\n // b. if SameValueZero(searchElement, elementK) is true, return true.\n if (sameValueZero(o[k], searchElement)) {\n return true;\n }\n // c. Increase k by 1.\n k++;\n }\n\n // 8. Return false\n return false;\n },\n });\n}\n\nif (!String.prototype.includes) {\n String.prototype.includes = function (search, start) {\n \"use strict\";\n\n if (search instanceof RegExp) {\n throw TypeError(\"first argument must not be a RegExp\");\n }\n if (start === undefined) {\n start = 0;\n }\n return this.indexOf(search, start) !== -1;\n };\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, \"startsWith\", {\n value: function (search, rawPos) {\n var pos = rawPos > 0 ? rawPos | 0 : 0;\n return this.substring(pos, pos + search.length) === search;\n },\n });\n}\n","import Parser from \"./parser\";\nimport Util from \"./util\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport CustomEditors from \"./customeditors\";\nimport Configuration from \"./configuration\";\nimport jsProperties from \"./jsvariables\";\nimport Event from \"./event\";\nimport Listeners from \"./listeners\";\nimport Image from \"./image\";\nimport ServiceProvider from \"./serviceprovider\";\nimport ModalDialog from \"./modal\";\nimport Telemeter from \"./telemeter\";\nimport \"./polyfills\";\nimport \"../styles/styles.css\";\n\n/**\n * @typedef {Object} CoreProperties\n * @property {ServiceProviderProperties} serviceProviderProperties\n * - The ServiceProvider class properties. *\n */\nexport default class Core {\n /**\n * @classdesc\n * This class represents MathType integration Core, managing the following:\n * - Integration initialization.\n * - Event managing.\n * - Insertion of formulas into the edit area.\n * ```js\n * let core = new Core();\n * core.addListener(listener);\n * core.language = 'en';\n *\n * // Initializing Core class.\n * core.init(configurationService);\n * ```\n * @constructs\n * Core constructor.\n * @param {CoreProperties}\n */\n constructor(coreProperties) {\n /**\n * Language. Needed for accessibility and locales. 'en' by default.\n * @type {String}\n */\n this.language = \"en\";\n\n /**\n * Edit mode, 'images' by default. Admits the following values:\n * - images\n * - latex\n * @type {String}\n */\n this.editMode = \"images\";\n\n /**\n * Modal dialog instance.\n * @type {ModalDialog}\n */\n this.modalDialog = null;\n\n /**\n * The instance of {@link CustomEditors}. By default\n * the only custom editor is the Chemistry editor.\n * @type {CustomEditors}\n */\n this.customEditors = new CustomEditors();\n\n /**\n * Chemistry editor.\n * @type {CustomEditor}\n */\n const chemEditorParams = {\n name: \"Chemistry\",\n toolbar: \"chemistry\",\n icon: \"chem.png\",\n confVariable: \"chemEnabled\",\n title: \"ChemType\",\n tooltip: \"Insert a chemistry formula - ChemType\", // TODO: Localize tooltip.\n };\n\n this.customEditors.addEditor(\"chemistry\", chemEditorParams);\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @typedef IntegrationEnvironment\n * @property {String} IntegrationEnvironment.editor - Editor name. For example the HTML editor.\n * @property {String} IntegrationEnvironment.mode - Integration save mode.\n * @property {String} IntegrationEnvironment.version - Integration version.\n *\n */\n\n /**\n * The environment properties object.\n * @type {IntegrationEnvironment}\n */\n this.environment = {};\n\n /**\n * @typedef EditionProperties\n * @property {Boolean} editionProperties.isNewElement - True if the formula is a new one.\n * False otherwise.\n * @property {HTMLImageElement} editionProperties.temporalImage- The image element.\n * Null if the formula is new.\n * @property {Range} editionProperties.latexRange - Tha range that contains the LaTeX formula.\n * @property {Range} editionProperties.range - The range that contains the image element.\n * @property {String} editionProperties.editMode - The edition mode. 'images' by default.\n */\n\n /**\n * The properties of the current edition process.\n * @type {EditionProperties}\n */\n this.editionProperties = {};\n\n this.editionProperties.isNewElement = true;\n this.editionProperties.temporalImage = null;\n this.editionProperties.latexRange = null;\n this.editionProperties.range = null;\n this.editionProperties.editionStartTime = null;\n\n /**\n * The {@link IntegrationModel} instance.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n\n /**\n * The {@link ContentManager} instance.\n * @type {ContentManager}\n */\n this.contentManager = null;\n\n /**\n * The current browser.\n * @type {String}\n */\n this.browser = (() => {\n const ua = navigator.userAgent;\n let browser = \"none\";\n if (ua.search(\"Edge/\") >= 0) {\n browser = \"EDGE\";\n } else if (ua.search(\"Chrome/\") >= 0) {\n browser = \"CHROME\";\n } else if (ua.search(\"Trident/\") >= 0) {\n browser = \"IE\";\n } else if (ua.search(\"Firefox/\") >= 0) {\n browser = \"FIREFOX\";\n } else if (ua.search(\"Safari/\") >= 0) {\n browser = \"SAFARI\";\n }\n return browser;\n })();\n\n /**\n * Plugin listeners.\n * @type {Array.}\n */\n this.listeners = new Listeners();\n\n /**\n * Service provider properties.\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = {};\n if (\"serviceProviderProperties\" in coreProperties) {\n this.serviceProviderProperties = coreProperties.serviceProviderProperties;\n } else {\n throw new Error(\"serviceProviderProperties property missing.\");\n }\n }\n\n /**\n * Static property.\n * Core listeners.\n * @private\n * @type {Listeners}\n */\n static get globalListeners() {\n return Core._globalListeners;\n }\n\n /**\n * Static property setter.\n * Set core listeners.\n * @param {Listeners} value - The property value.\n * @ignore\n */\n static set globalListeners(value) {\n Core._globalListeners = value;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * True when Core.init was called. Otherwise, false.\n * @private\n * @type {Boolean}\n */\n static get initialized() {\n return Core._initialized;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * @param {Boolean} value - True to say that Core.init was called. Otherwise, false.\n * @ignore\n */\n static set initialized(value) {\n Core._initialized = value;\n }\n\n /**\n * Sets the {@link Core.integrationModel} property.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} property.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link Core.environment} property.\n * @param {IntegrationEnvironment} integrationEnvironment -\n * The {@link IntegrationEnvironment} object.\n */\n setEnvironment(integrationEnvironment) {\n if (\"editor\" in integrationEnvironment) {\n this.environment.editor = integrationEnvironment.editor;\n }\n if (\"mode\" in integrationEnvironment) {\n this.environment.mode = integrationEnvironment.mode;\n }\n if (\"version\" in integrationEnvironment) {\n this.environment.version = integrationEnvironment.version;\n }\n }\n\n /**\n * Sets the custom headers added on editor requests if contentManager isn't undefined.\n * @returns {Object} headers - key value headers.\n */\n setHeaders(headers) {\n const headerObject = this?.contentManager?.setCustomHeaders(headers) || headers;\n Configuration.set(\"customHeaders\", headerObject);\n }\n\n /**\n * Returns the current {@link ModalDialog} instance.\n * @returns {ModalDialog} The current {@link ModalDialog} instance.\n */\n getModalDialog() {\n return this.modalDialog;\n }\n\n /**\n * Inits the {@link Core} class, doing the following:\n * - Calls asynchronously configuration service, retrieving the backend configuration in a JSON.\n * - Updates {@link Configuration} class with the previous configuration properties.\n * - Updates the {@link ServiceProvider} class using the configuration service path as reference.\n * - Loads language strings.\n * - Fires onLoad event.\n * @param {Object} serviceParameters - Service parameters.\n */\n init() {\n if (!Core.initialized) {\n const serviceProviderListener = Listeners.newListener(\"onInit\", () => {\n const jsConfiguration = ServiceProvider.getService(\"configurationjs\", \"\", \"get\");\n const jsonConfiguration = JSON.parse(jsConfiguration);\n Configuration.addConfiguration(jsonConfiguration);\n // Adding JavaScript (not backend) configuration variables.\n Configuration.addConfiguration(jsProperties);\n // Fire 'onLoad' event:\n // All integration must listen this event in order to know if the plugin\n // has been properly loaded.\n StringManager.language = this.language;\n this.listeners.fire(\"onLoad\", {});\n });\n\n ServiceProvider.addListener(serviceProviderListener);\n ServiceProvider.init(this.serviceProviderProperties);\n\n Core.initialized = true;\n } else {\n // Case when there are more than two editor instances.\n // After the first editor all the other editors don't need to load any file or service.\n this.listeners.fire(\"onLoad\", {});\n }\n }\n\n /**\n * Adds a {@link Listener} to the current instance of the {@link Core} class.\n * @param {Listener} listener - The listener object.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Adds the global {@link Listener} instance to {@link Core} class.\n * @param {Listener} listener - The event listener to be added.\n * @static\n */\n static addGlobalListener(listener) {\n Core.globalListeners.add(listener);\n }\n\n beforeUpdateFormula(mathml, wirisProperties) {\n /**\n * This event is fired before updating the formula.\n * @type {Object}\n * @property {String} mathml - MathML to be transformed.\n * @property {String} editMode - Edit mode.\n * @property {Object} wirisProperties - Extra attributes for the formula.\n * @property {String} language - Formula language.\n */\n const beforeUpdateEvent = new Event();\n\n beforeUpdateEvent.mathml = mathml;\n\n // Cloning wirisProperties object\n // We don't want wirisProperties object modified.\n beforeUpdateEvent.wirisProperties = {};\n\n if (wirisProperties != null) {\n Object.keys(wirisProperties).forEach((attr) => {\n beforeUpdateEvent.wirisProperties[attr] = wirisProperties[attr];\n });\n }\n\n // Read only.\n beforeUpdateEvent.language = this.language;\n beforeUpdateEvent.editMode = this.editMode;\n\n if (this.listeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n return {\n mathml: beforeUpdateEvent.mathml,\n wirisProperties: beforeUpdateEvent.wirisProperties,\n };\n }\n\n /**\n * Converts a MathML into it's correspondent image and inserts the image is\n * inserted in a HTMLElement target by creating\n * a new image or updating an existing one.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the insertion.\n * @param {Window} windowTarget - The window element where the editable content is.\n * @param {String} mathml - The MathML.\n * @param {Array.} wirisProperties - The extra attributes for the formula.\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n /**\n * It is the object with the information of the node or latex to insert.\n * @typedef ReturnObject\n * @property {Node} [node] - The DOM node to insert.\n * @property {String} [latex] - The latex to insert.\n */\n const returnObject = {};\n\n if (!mathml) {\n this.insertElementOnSelection(null, focusElement, windowTarget);\n } else if (this.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n // this.integrationModel.getNonLatexNode is an integration wrapper\n // to have special behaviours for nonLatex.\n // Not all the integrations have special behaviours for nonLatex.\n if (!!this.integrationModel.fillNonLatexNode && !returnObject.latex) {\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.latex = returnObject.latex;\n this.integrationModel.fillNonLatexNode(afterUpdateEvent, windowTarget, mathml);\n } else {\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n }\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n } else {\n returnObject.node = Parser.mathmlToImgObject(windowTarget.document, mathml, wirisProperties, this.language);\n\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n }\n\n return returnObject;\n }\n\n afterUpdateFormula(focusElement, windowTarget, node, latex) {\n /**\n * This event is fired after update the formula.\n * @type {Event}\n * @param {String} editMode - edit mode.\n * @param {Object} windowTarget - target window.\n * @param {Object} focusElement - target element to be focused after update.\n * @param {String} latex - LaTeX generated by the formula (editMode=latex).\n * @param {Object} node - node generated after update the formula (text if LaTeX img otherwise).\n */\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.node = node;\n afterUpdateEvent.latex = latex;\n\n if (this.listeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n return {};\n }\n\n /**\n * Sets the caret after a given Node and set the focus to the owner document.\n * @param {Node} node - The Node element.\n */\n placeCaretAfterNode(node) {\n if (node === null) return;\n\n this.integrationModel.getSelection();\n const nodeDocument = node.ownerDocument;\n if (typeof nodeDocument.getSelection !== \"undefined\" && !!node.parentElement) {\n const range = nodeDocument.createRange();\n range.setStartAfter(node);\n range.collapse(true);\n const selection = nodeDocument.getSelection();\n selection.removeAllRanges();\n selection.addRange(range);\n nodeDocument.body.focus();\n }\n }\n\n /**\n * Replaces a Selection object with an HTMLElement.\n * @param {HTMLElement} element - The HTMLElement to replace the selection.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the replace.\n * @param {Window} windowTarget - The window target.\n */\n insertElementOnSelection(element, focusElement, windowTarget) {\n let mathmlOrigin = null;\n if (this.editionProperties.isNewElement) {\n if (element) {\n if (focusElement.type === \"textarea\") {\n Util.updateTextArea(focusElement, element.textContent);\n } else if (document.selection && document.getSelection === 0) {\n let range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n\n if (!(\"parentElement\" in range)) {\n windowTarget.document.execCommand(\"delete\", false);\n range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n }\n\n if (\"parentElement\" in range) {\n const temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() === \"IMG\") {\n temporalObject.parentNode.replaceChild(element, temporalObject);\n } else {\n // IE9 fix: parentNode() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML(Util.createObjectCode(element));\n }\n }\n } else {\n let range = null;\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n if (this.editionProperties.range) {\n ({ range } = this.editionProperties);\n this.editionProperties.range = null;\n } else {\n const editorSelection = this.integrationModel.getSelection();\n range = editorSelection.getRangeAt(0);\n }\n\n // Delete if something was surrounded.\n range.deleteContents();\n\n let node = range.startContainer;\n const position = range.startOffset;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n node = node.splitText(position);\n node.parentNode.insertBefore(element, node);\n } else if (node.nodeType === 1) {\n // ELEMENT_NODE.\n node.insertBefore(element, node.childNodes[position]);\n }\n\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n focusElement.focus();\n } else {\n const editorSelection = this.integrationModel.getSelection();\n editorSelection.removeAllRanges();\n\n if (this.editionProperties.range) {\n const { range } = this.editionProperties;\n this.editionProperties.range = null;\n editorSelection.addRange(range);\n }\n }\n } else if (this.editionProperties.latexRange) {\n if (document.selection && document.getSelection === 0) {\n this.editionProperties.isNewElement = true;\n this.editionProperties.latexRange.select();\n this.insertElementOnSelection(element, focusElement, windowTarget);\n } else {\n this.editionProperties.latexRange.deleteContents();\n this.editionProperties.latexRange.insertNode(element);\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n let item;\n // Wrapper for some integrations that can have special behaviours to show latex.\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n item = this.integrationModel.getSelectedItem(focusElement, false);\n } else {\n item = Util.getSelectedItemOnTextarea(focusElement);\n }\n Util.updateExistingTextOnTextarea(focusElement, element.textContent, item.startPosition, item.endPosition);\n } else {\n mathmlOrigin = this.editionProperties.temporalImage?.dataset.mathml;\n if (element && element.nodeName.toLowerCase() === \"img\") {\n // Editor empty, formula has been erased on edit.\n // There are editors (e.g: CKEditor) that put attributes in images.\n // We don't allow that behaviour in our images.\n Image.removeImgDataAttributes(this.editionProperties.temporalImage);\n // Clone is needed to maintain event references to temporalImage.\n Image.clone(element, this.editionProperties.temporalImage);\n } else {\n this.editionProperties.temporalImage.remove();\n }\n this.placeCaretAfterNode(this.editionProperties.temporalImage);\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const mathml = element?.dataset?.mathml;\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove the desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n }\n\n /**\n * Opens a modal dialog containing MathType editor..\n * @param {HTMLElement} target - The target HTMLElement where formulas should be inserted.\n * @param {Boolean} isIframe - True if the target HTMLElement is an iframe. False otherwise.\n */\n openModalDialog(target, isIframe) {\n // Count the time since the editor is open\n this.editionProperties.editionStartTime = Date.now();\n\n // Textarea elements don't have normal document ranges. It only accepts latex edit.\n this.editMode = \"images\";\n\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n try {\n if (isIframe) {\n // Is needed focus the target first.\n target.contentWindow.focus();\n const selection = target.contentWindow.getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n } else {\n // Is needed focus the target first.\n target.focus();\n const selection = getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n }\n } catch (e) {\n this.editionProperties.range = null;\n }\n\n if (isIframe === undefined) {\n isIframe = true;\n }\n\n this.editionProperties.latexRange = null;\n\n if (target) {\n let selectedItem;\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n selectedItem = this.integrationModel.getSelectedItem(target, isIframe);\n } else {\n selectedItem = Util.getSelectedItem(target, isIframe);\n }\n\n // Check LaTeX if and only if the node is a text node (nodeType==3).\n if (selectedItem) {\n // Case when image was selected and button pressed.\n if (!selectedItem.caretPosition && Util.containsClass(selectedItem.node, Configuration.get(\"imageClassName\"))) {\n this.editionProperties.temporalImage = selectedItem.node;\n this.editionProperties.isNewElement = false;\n } else if (selectedItem.node.nodeType === 3) {\n // If it's a text node means that editor is working with LaTeX.\n if (this.integrationModel.getMathmlFromTextNode) {\n // If integration has this function it isn't set range due to we don't\n // know if it will be put into a textarea as a text or image.\n const mathml = this.integrationModel.getMathmlFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (mathml) {\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n }\n } else {\n const latexResult = Latex.getLatexFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (latexResult) {\n const mathml = Latex.getMathMLFromLatex(latexResult.latex);\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n const windowTarget = isIframe ? target.contentWindow : window;\n\n if (target.tagName.toLowerCase() !== \"textarea\") {\n if (document.selection) {\n let leftOffset = 0;\n let previousNode = latexResult.startNode.previousSibling;\n\n while (previousNode) {\n leftOffset += Util.getNodeLength(previousNode);\n previousNode = previousNode.previousSibling;\n }\n\n this.editionProperties.latexRange = windowTarget.document.selection.createRange();\n this.editionProperties.latexRange.moveToElementText(latexResult.startNode.parentNode);\n this.editionProperties.latexRange.move(\"character\", leftOffset + latexResult.startPosition);\n this.editionProperties.latexRange.moveEnd(\"character\", latexResult.latex.length + 4); // Plus 4 for the '$$' characters.\n } else {\n this.editionProperties.latexRange = windowTarget.document.createRange();\n this.editionProperties.latexRange.setStart(latexResult.startNode, latexResult.startPosition);\n this.editionProperties.latexRange.setEnd(latexResult.endNode, latexResult.endPosition);\n }\n }\n }\n }\n }\n } else if (target.tagName.toLowerCase() === \"textarea\") {\n // By default editMode is 'images', but when target is a textarea it needs to be 'latex'.\n this.editMode = \"latex\";\n }\n }\n\n // Setting an object with the editor parameters.\n // Editor parameters can be customized in several ways:\n // 1 - editorAttributes: Contains the default editor attributes,\n // usually the metrics in a comma separated string. Always exists.\n // 2 - editorParameters: Object containing custom editor parameters.\n // These parameters are defined in the backend. So they affects all integration instances.\n\n // The backend send the default editor attributes in a coma separated\n // with the following structure: key1=value1,key2=value2...\n const defaultEditorAttributesArray = Configuration.get(\"editorAttributes\").split(\", \");\n const defaultEditorAttributes = {};\n for (let i = 0, len = defaultEditorAttributesArray.length; i < len; i += 1) {\n const tempAttribute = defaultEditorAttributesArray[i].split(\"=\");\n const key = tempAttribute[0];\n const value = tempAttribute[1];\n defaultEditorAttributes[key] = value;\n }\n // Custom editor parameters.\n const editorAttributes = {\n language: this.language, // Default language value\n };\n // Editor parameters in backend, usually configuration.ini.\n const serverEditorParameters = Configuration.get(\"editorParameters\");\n // Editor parameters through JavaScript configuration.\n const clientEditorParameters = this.integrationModel.editorParameters;\n Object.assign(editorAttributes, defaultEditorAttributes, serverEditorParameters);\n Object.assign(editorAttributes, defaultEditorAttributes, clientEditorParameters);\n\n // Now, update backwards: if user has set a custom language, pass that back to core properties\n this.language = editorAttributes.language;\n StringManager.language = this.language;\n\n editorAttributes.rtl = this.integrationModel.rtl;\n\n const customHeaders = Configuration.get(\"customHeaders\");\n // This is not being used in the code, we are keeping it just in case it's needed.\n // We check if it is a string since we have a setter that will make the customHeaders an object. And we do the conversion for the case when we get the headers from the backend.\n editorAttributes.customHeaders =\n typeof customHeaders === \"string\" ? Util.convertStringToObject(customHeaders) : customHeaders;\n\n const contentManagerAttributes = {};\n contentManagerAttributes.editorAttributes = editorAttributes;\n contentManagerAttributes.language = this.language;\n contentManagerAttributes.customEditors = this.customEditors;\n contentManagerAttributes.environment = this.environment;\n\n if (this.modalDialog == null) {\n this.modalDialog = new ModalDialog(editorAttributes);\n this.contentManager = new ContentManager(contentManagerAttributes);\n // When an instance of ContentManager is created we need to wait until\n // the ContentManager is ready by listening 'onLoad' event.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n });\n this.contentManager.addListener(listener);\n this.contentManager.init();\n this.modalDialog.setContentManager(this.contentManager);\n this.contentManager.setModalDialogInstance(this.modalDialog);\n } else {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n }\n this.contentManager.setIntegrationModel(this.integrationModel);\n this.modalDialog.open();\n }\n\n /**\n * Returns the {@link CustomEditors} instance.\n * @return {CustomEditors} The current {@link CustomEditors} instance.\n */\n getCustomEditors() {\n return this.customEditors;\n }\n}\n\n/**\n * Core static listeners.\n * @type {Listeners}\n * @private\n */\nCore._globalListeners = new Listeners();\n\n/**\n * Resources state. Says if they were loaded or not.\n * @type {Boolean}\n * @private\n */\nCore._initialized = false;\n","// eslint-disable-next-line no-unused-vars, import/named\nimport Core from \"./core.src\";\nimport Image from \"./image\";\nimport Listeners from \"./listeners\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Telemeter from \"./telemeter\";\nimport warnIcon from \"../styles/icons/general/warn_icon.svg\"; //eslint-disable-line\n\n/**\n * @typedef {Object} IntegrationModelProperties\n * @property {string} configurationService - Configuration service path.\n * This parameter is needed to determine all services paths.\n * @property {HTMLElement} integrationModelProperties.target - HTML target.\n * @property {string} integrationModelProperties.scriptName - Integration script name.\n * Usually the name of the integration script.\n * @property {Object} integrationModelProperties.environment - integration environment properties.\n * @property {Object} [integrationModelProperties.callbackMethodArguments] - object containing\n * callback method arguments.\n * @property {string} [integrationModelProperties.version] - integration version number.\n * @property {Object} [integrationModelProperties.editorObject] - object containing\n * the integration editor instance.\n * @property {boolean} [integrationModelProperties.rtl] - true if the editor is in RTL mode.\n * false otherwise.\n * @property {ServiceProviderProperties} [integrationModelProperties.serviceProviderProperties]\n * - The service parameters.\n * @property {Object} [integrationModelProperties.integrationParameters]\n * - Overwritten integration parameters.\n */\n\nexport default class IntegrationModel {\n /**\n * @classdesc\n * This class represents an integration model, allowing the integration script to\n * communicate with Core class. Each integration must extend this class.\n * @constructs\n * @param {IntegrationModelProperties} integrationModelProperties\n */\n constructor(integrationModelProperties) {\n /**\n * Language. Needed for accessibility and locales. English by default.\n */\n this.language = \"en\";\n\n /**\n * Service parameters\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = integrationModelProperties.serviceProviderProperties ?? {};\n\n /**\n * Configuration service path. The integration service is needed by Core class to\n * load all the backend configuration into the frontend and also to create the paths\n * of all services (all services lives in the same route). Mandatory property.\n */\n this.configurationService = \"\";\n if (\"configurationService\" in integrationModelProperties) {\n this.serviceProviderProperties.URI = integrationModelProperties.configurationService;\n console.warn(\"Deprecated property configurationService. Use serviceParameters on instead.\", [\n integrationModelProperties.configurationService,\n ]);\n }\n\n /**\n * Plugin version. Needed to stats and caching.\n * @type {string}\n */\n this.version = \"version\" in integrationModelProperties ? integrationModelProperties.version : \"\";\n\n /**\n * DOM target in which the plugin works. Needed to associate events, insert formulas, etc.\n * Mandatory property.\n */\n this.target = null;\n if (\"target\" in integrationModelProperties) {\n this.target = integrationModelProperties.target;\n } else {\n throw new Error(\"IntegrationModel constructor error: target property missed.\");\n }\n\n /**\n * Integration script name. Needed to know the plugin path.\n */\n if (\"scriptName\" in integrationModelProperties) {\n this.scriptName = integrationModelProperties.scriptName;\n }\n\n /**\n * Object containing the arguments needed by the callback function.\n */\n this.callbackMethodArguments = integrationModelProperties.callbackMethodArguments ?? {};\n\n /**\n * Contains information about the integration environment:\n * like the name of the editor, the version, etc.\n */\n this.environment = integrationModelProperties.environment ?? {};\n\n /**\n * Indicates if the DOM target is - or not - and iframe.\n */\n this.isIframe = false;\n if (this.target != null) {\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Instance of the integration editor object. Usually the entry point to access the API\n * of a HTML editor.\n */\n this.editorObject = integrationModelProperties.editorObject ?? null;\n\n /**\n * Specifies if the direction of the text is RTL. false by default.\n */\n this.rtl = integrationModelProperties.rtl ?? false;\n\n /**\n * Specifies if the integration model exposes the locale strings. false by default.\n */\n this.managesLanguage = integrationModelProperties.managesLanguage ?? false;\n\n /**\n * Specify if editor will open in hand mode only\n */\n this.forcedHandMode = integrationModelProperties?.integrationParameters?.forcedHandMode ?? false;\n\n /**\n * Indicates if an image is selected. Needed to resize the image to the original size in case\n * the image is resized.\n * @type {boolean}\n */\n this.temporalImageResizing = false;\n\n /**\n * The Core class instance associated to the integration model.\n * @type {Core}\n */\n this.core = null;\n\n /**\n * Integration model listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n // Parameters overwrite.\n if (\"integrationParameters\" in integrationModelProperties) {\n IntegrationModel.integrationParameters.forEach((parameter) => {\n if (parameter in integrationModelProperties.integrationParameters) {\n // Don't add empty parameters.\n const value = integrationModelProperties.integrationParameters[parameter];\n if (Object.keys(value).length !== 0) {\n this[parameter] = value;\n }\n }\n });\n }\n }\n\n /**\n * Init function. Usually called from the integration side once the core.js file is loaded.\n */\n init() {\n // Check if language is an object and select the property necessary\n this.language = this.getLanguage();\n\n // We need to wait until Core class is loaded ('onLoad' event) before\n // call the callback method.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.callbackFunction(this.callbackMethodArguments);\n });\n\n // Backwards compatibility.\n if (this.serviceProviderProperties.URI.indexOf(\"configuration\") !== -1) {\n const uri = this.serviceProviderProperties.URI;\n const server = ServiceProvider.getServerLanguageFromService(uri);\n this.serviceProviderProperties.server = server;\n const configurationIndex = this.serviceProviderProperties.URI.indexOf(\"configuration\");\n const subsTring = this.serviceProviderProperties.URI.substring(0, configurationIndex);\n this.serviceProviderProperties.URI = subsTring;\n }\n\n let serviceParametersURI = this.serviceProviderProperties.URI;\n serviceParametersURI =\n serviceParametersURI.indexOf(\"/\") === 0 || serviceParametersURI.indexOf(\"http\") === 0\n ? serviceParametersURI\n : Util.concatenateUrl(this.getPath(), serviceParametersURI);\n\n this.serviceProviderProperties.URI = serviceParametersURI;\n\n const coreProperties = {};\n coreProperties.serviceProviderProperties = this.serviceProviderProperties;\n\n this.setCore(new Core(coreProperties));\n this.core.addListener(listener);\n this.core.language = this.language;\n\n // Initializing Core class.\n this.core.init();\n // TODO: Move to Core constructor.\n this.core.setEnvironment(this.environment);\n\n // No internet connection modal.\n let attributes = {};\n attributes.class = attributes.id = \"wrs_modal_offline\";\n this.offlineModal = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_content_offline\";\n this.offlineModalContent = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_close\";\n this.offlineModalClose = Util.createElement(\"span\", attributes);\n this.offlineModalClose.innerHTML = \"×\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_warn\";\n this.offlineModalWarn = Util.createElement(\"span\", attributes);\n const generalStyle = `background-image: url(data:image/svg+xml;base64,${window.btoa(warnIcon)})`;\n this.offlineModalWarn.setAttribute(\"style\", generalStyle);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_container\";\n this.offlineModalMessage = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_warn\";\n this.offlineModalMessage1 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage1.innerHTML = \"You are not online!\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text\";\n this.offlineModalMessage2 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage2.innerHTML = `Thank you for using MathType. We have detected you are disconnected from the network. We remind you that you'll need to be connected to use MathType.

Please refresh the page if this message continues appearing.`;\n\n // Append offline modal elements\n this.offlineModalContent.appendChild(this.offlineModalClose);\n this.offlineModalMessage.appendChild(this.offlineModalMessage1);\n this.offlineModalMessage.appendChild(this.offlineModalMessage2);\n this.offlineModalContent.appendChild(this.offlineModalMessage);\n this.offlineModalContent.appendChild(this.offlineModalWarn);\n this.offlineModal.appendChild(this.offlineModalContent);\n document.body.appendChild(this.offlineModal);\n\n const modal = document.getElementById(\"wrs_modal_offline\");\n this.offlineModalClose.addEventListener(\"click\", () => {\n modal.style.display = \"none\";\n });\n\n // Store editor name for telemetry purposes.\n let editorName = this.environment.editor;\n editorName = editorName.slice(0, -1); // Remove version number from editors\n if (editorName.includes(\"TinyMCE\")) editorName = \"TinyMCE\"; // Remove version from Tinymce editor.\n if (editorName.includes(\"Generic\")) editorName = \"Generic\"; // Remove version from Generic editor.\n let solutionTelemeter = editorName;\n\n // If moodle, add information to hosts and solution.\n const isMoodle = !!(typeof M === \"object\" && M !== null);\n let lms;\n\n if (isMoodle) {\n solutionTelemeter = \"Moodle\";\n lms = {\n nam: \"moodle\",\n fam: \"lms\",\n ver: this.environment.moodleVersion,\n category: this.environment.moodleCourseCategory,\n course: this.environment.moodleCourseName,\n };\n if (!editorName.includes(\"TinyMCE\")) {\n editorName = \"Atto\";\n }\n }\n\n // Get the OS and its version.\n const OSData = this.getOS();\n\n // Get the broswer and its version.\n const broswerData = this.getBrowser();\n\n // Create list of hosts to send to telemetry.\n let hosts = [\n {\n nam: broswerData.detectedBrowser,\n fam: \"browser\",\n ver: broswerData.versionBrowser,\n },\n {\n nam: editorName.toLowerCase(),\n fam: \"html-editor\",\n ver: this.environment.editorVersion,\n },\n {\n nam: OSData.detectedOS,\n fam: \"os\",\n ver: OSData.versionOS,\n },\n {\n nam: window.location.hostname,\n fam: \"domain\",\n },\n lms,\n ];\n\n // Filter hosts to remove empty objects and empty keys.\n hosts = hosts.filter((element) => {\n if (element) Object.keys(element).forEach((key) => (element[key] === \"unknown\" ? delete element[key] : {}));\n return element !== undefined;\n });\n\n // Initialize telemeter\n Telemeter.init({\n solution: {\n name: `MathType for ${solutionTelemeter}`,\n version: this.version,\n },\n hosts,\n config: {\n test: false, // True to use the staging Telemetry endpoint instead of the production one.\n debug: false, // True to show more information about Telemeter's execution and use dev-tools.\n dry_run: false, // True to skip sending data to the Telemetry endpoint (for example for unit tests).\n api_key: \"eda2ce9b-0e8a-46f2-acdd-c228a615314e\", // to auth against Telemetry. Data team is the responsible of providing it.\n },\n url: undefined,\n });\n }\n\n /**\n * Returns the Browser name and its version.\n * @return {array} - detectedBrowser = Operating System name.\n * versionBrowser = Operating System version.\n */\n getBrowser() {\n // default value for OS just in case nothing is detected\n let detectedBrowser = \"unknown\";\n let versionBrowser = \"unknown\";\n\n const userAgent = window.navigator.userAgent;\n\n if (/Brave/.test(userAgent)) {\n detectedBrowser = \"brave\";\n if (userAgent.indexOf(\"Brave/\")) {\n const start = userAgent.indexOf(\"Brave\") + 6;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (userAgent.indexOf(\"Edg/\") !== -1) {\n detectedBrowser = \"edge_chromium\";\n const start = userAgent.indexOf(\"Edg/\") + 4;\n versionBrowser = userAgent\n .substring(start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Edg/.test(userAgent)) {\n detectedBrowser = \"edge\";\n let start = userAgent.indexOf(\"Edg\") + 3;\n start += userAgent.substring(start).indexOf(\"/\");\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Firefox/.test(userAgent) || /FxiOS/.test(userAgent)) {\n detectedBrowser = \"firefox\";\n let start = userAgent.indexOf(\"Firefox\");\n start = start === -1 ? userAgent.indexOf(\"FxiOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/OPR/.test(userAgent)) {\n detectedBrowser = \"opera\";\n const start = userAgent.indexOf(\"OPR/\") + 4;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Chrome/.test(userAgent) || /CriOS/.test(userAgent)) {\n detectedBrowser = \"chrome\";\n let start = userAgent.indexOf(\"Chrome\");\n start = start === -1 ? userAgent.indexOf(\"CriOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/Safari/.test(userAgent)) {\n detectedBrowser = \"safari\";\n let start = userAgent.indexOf(\"Version/\");\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n }\n\n return { detectedBrowser, versionBrowser };\n }\n\n /**\n * Returns the operating system and its version.\n * @return {array} - detectedOS = Operating System name.\n * versionOS = Operating System version.\n */\n getOS() {\n // default value for OS just in case nothing is detected\n let detectedOS = \"unknown\";\n let versionOS = \"unknown\";\n\n // Retrieve properties to easily detect the OS\n const userAgent = window.navigator.userAgent;\n const platform = window.navigator.platform;\n const macosPlatforms = [\"Macintosh\", \"MacIntel\", \"MacPPC\", \"Mac68K\"];\n const windowsPlatforms = [\"Win32\", \"Win64\", \"Windows\", \"WinCE\"];\n const iosPlatforms = [\"iPhone\", \"iPad\", \"iPod\"];\n\n // Find OS and their respective versions\n if (macosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"macos\";\n if (userAgent.indexOf(\"OS X\") !== -1) {\n const start = userAgent.indexOf(\"OS X\") + 5;\n const end = userAgent.substring(start).indexOf(\" \");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (iosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"ios\";\n if (userAgent.indexOf(\"OS \") !== -1) {\n const start = userAgent.indexOf(\"OS \") + 3;\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (windowsPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"windows\";\n const start = userAgent.indexOf(\"Windows\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Android/.test(userAgent)) {\n detectedOS = \"android\";\n const start = userAgent.indexOf(\"Android\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/CrOS/.test(userAgent)) {\n detectedOS = \"chromeos\";\n let start = userAgent.indexOf(\"CrOS \") + 5;\n start += userAgent.substring(start).indexOf(\" \");\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (detectedOS === \"unknown\" && /Linux/.test(platform)) {\n detectedOS = \"linux\";\n }\n\n return { detectedOS, versionOS };\n }\n\n /**\n * Returns the absolute path of the integration script.\n * @return {string} - Absolute path for the integration script.\n */\n getPath() {\n if (typeof this.scriptName === \"undefined\") {\n throw new Error(\"scriptName property needed for getPath.\");\n }\n const col = document.getElementsByTagName(\"script\");\n let path = \"\";\n for (let i = 0; i < col.length; i += 1) {\n const j = col[i].src.lastIndexOf(this.scriptName);\n if (j >= 0) {\n path = col[i].src.substr(0, j - 1);\n }\n }\n return path;\n }\n\n /**\n * Returns integration model plugin version\n * @param {string} - Plugin version\n */\n getVersion() {\n return this.version;\n }\n\n /**\n * Sets the language property.\n * @param {string} language - language code.\n */\n setLanguage(language) {\n this.language = language;\n }\n\n /**\n * Sets a Core instance.\n * @param {Core} core - instance of Core class.\n */\n setCore(core) {\n this.core = core;\n core.setIntegrationModel(this);\n }\n\n /**\n * Returns the Core instance.\n * @returns {Core} instance of Core class.\n */\n getCore() {\n return this.core;\n }\n\n /**\n * Sets the object target and updates the iframe property.\n * @param {HTMLElement} target - target object.\n */\n setTarget(target) {\n this.target = target;\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Sets the editor object.\n * @param {Object} editorObject - The editor object.\n */\n setEditorObject(editorObject) {\n this.editorObject = editorObject;\n }\n\n /**\n * Opens formula editor to editing a new formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openNewFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.dbclick = false;\n this.core.editionProperties.isNewElement = true;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Opens formula editor to editing an existing formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openExistingFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.isNewElement = false;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Wrapper to Core.updateFormula method.\n * Transform a MathML into a image formula.\n * Then the image formula is inserted in the specified target, creating a new image (new formula)\n * or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n */\n updateFormula(mathml) {\n if (this.editorParameters) {\n mathml = com.wiris.editor.util.EditorUtils.addAnnotation(\n mathml,\n \"application/vnd.wiris.mtweb-params+json\",\n JSON.stringify(this.editorParameters),\n );\n }\n let focusElement;\n let windowTarget;\n const wirisProperties = null;\n\n if (this.isIframe) {\n focusElement = this.target.contentWindow;\n windowTarget = this.target.contentWindow;\n } else {\n focusElement = this.target;\n windowTarget = window;\n }\n\n let obj = this.core.beforeUpdateFormula(mathml, wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n obj = this.insertFormula(focusElement, windowTarget, obj.mathml, obj.wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n return this.core.afterUpdateFormula(obj.focusElement, obj.windowTarget, obj.node, obj.latex);\n }\n\n /**\n * Wrapper to Core.insertFormula method.\n * Inserts the formula in the specified target, creating\n * a new image (new formula) or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n const obj = this.core.insertFormula(focusElement, windowTarget, mathml, wirisProperties);\n\n // Delete temporal image when inserted\n this.core.editionProperties.temporalImage = null;\n\n return obj;\n }\n\n /**\n * Returns the target selection.\n * @returns {Selection} target selection.\n */\n getSelection() {\n if (this.isIframe) {\n this.target.contentWindow.focus();\n return this.target.contentWindow.getSelection();\n }\n this.target.focus();\n return window.getSelection();\n }\n\n /**\n * Add events to formulas in the DOM target. The events added are the following:\n * - doubleClickHandler: handles Double-click event on formulas by opening an editor\n * to edit them.\n * - mouseDownHandler: handles mouse down event on formulas by saving the size of the formula\n * in case the the formula is resized.\n * - mouseUpHandler: handles mouse up event on formulas by restoring the saved formula size\n * in case the formula is resized.\n */\n addEvents() {\n const eventTarget = this.isIframe ? this.target.contentWindow.document : this.target;\n Util.addElementEvents(\n eventTarget,\n (element, event) => {\n this.doubleClickHandler(element, event);\n // Avoid creating the double click listener more than once for each element.\n event.stopImmediatePropagation();\n },\n (element, event) => {\n this.mousedownHandler(element, event);\n },\n (element, event) => {\n this.mouseupHandler(element, event);\n },\n );\n }\n\n /**\n * Remove events to formulas in the DOM target.\n */\n removeEvents() {\n const eventTarget =\n this.isIframe && this.target.contentWindow?.document ? this.target.contentWindow.document : this.target;\n\n if (!eventTarget) {\n return;\n }\n\n Util.removeElementEvents(eventTarget);\n }\n\n /**\n * Remove events, modals and set this.editorObject to null in order to prevent memory leaks.\n */\n destroy() {\n this.removeEvents();\n // Destroy modal dialog if exists.\n if (this.core.modalDialog) {\n this.core.modalDialog.destroy();\n }\n\n // Remove offline modal dialog if exists.\n if (this.offlineModal) {\n this.offlineModal.remove();\n }\n\n this.editorObject = null;\n }\n\n /**\n * Handles a Double-click on the target element. Opens an editor\n * to re-edit the double-clicked formula.\n * @param {HTMLElement} element - DOM object target.\n */\n doubleClickHandler(element) {\n this.core.editionProperties.dbclick = true;\n if (element.nodeName.toLowerCase() === \"img\") {\n this.core.getCustomEditors().disable();\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (element.hasAttribute(customEditorAttributeName)) {\n const customEditor = element.getAttribute(customEditorAttributeName);\n this.core.getCustomEditors().enable(customEditor);\n }\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.core.editionProperties.temporalImage = element;\n this.core.editionProperties.isNewElement = true;\n this.openExistingFormulaEditor();\n }\n }\n }\n\n /**\n * Handles a mouse up event on the target element. Restores the image size to avoid\n * resizing formulas.\n */\n mouseupHandler() {\n if (this.temporalImageResizing) {\n setTimeout(() => {\n Image.fixAfterResize(this.temporalImageResizing);\n }, 10);\n }\n }\n\n /**\n * Handles a mouse down event on the target element. Saves the formula size to avoid\n * resizing formulas.\n * @param {HTMLElement} element - target element.\n */\n mousedownHandler(element) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.temporalImageResizing = element;\n }\n }\n }\n\n /**\n * Returns the integration language. By default the browser agent. This method\n * should be overwritten to obtain the integration language, for example using the\n * plugin API of an HTML editor.\n * @returns {string} integration language.\n */\n getLanguage() {\n return this.getBrowserLanguage();\n }\n\n /**\n * Returns the browser language.\n * @returns {string} the browser language.\n */\n // eslint-disable-next-line class-methods-use-this\n getBrowserLanguage() {\n let language = \"en\";\n if (navigator.userLanguage) {\n language = navigator.userLanguage.substring(0, 2);\n } else if (navigator.language) {\n language = navigator.language.substring(0, 2);\n } else {\n language = \"en\";\n }\n return language;\n }\n\n /**\n * This function is called once the {@link Core} is loaded. IntegrationModel class\n * will fire this method when {@link Core} 'onLoad' event is fired.\n * This method should content all the logic to init\n * the integration.\n */\n callbackFunction() {\n // It's needed to wait until the integration target is ready. The event is fired\n // from the integration side.\n const listener = Listeners.newListener(\"onTargetReady\", () => {\n this.addEvents(this.target);\n });\n this.listeners.add(listener);\n }\n\n /**\n * Function called when the content submits an action.\n */\n // eslint-disable-next-line class-methods-use-this\n notifyWindowClosed() {\n // Nothing.\n }\n\n /**\n * Wrapper.\n * Extracts mathml of a determined text node. This function is used as a wrapper inside core.js\n * in order to get mathml from a text node that can contain normal LaTeX or other chosen text.\n * @param {string} textNode - text node to extract the MathML.\n * @param {int} caretPosition - caret position inside the text node.\n * @returns {string} MathML inside the text node.\n */\n\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getMathmlFromTextNode(textNode, caretPosition) {}\n\n /**\n * Wrapper\n * It fills wrs event object of nonLatex with the desired data.\n * @param {Object} event - event object.\n * @param {Object} window dom window object.\n * @param {string} mathml valid mathml.\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n fillNonLatexNode(event, window, mathml) {}\n\n /**\n Wrapper.\n * Returns selected item from the target.\n * @param {HTMLElement} target - target element\n * @param {boolean} iframe\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getSelectedItem(target, isIframe) {}\n\n // Set temporal image to null and make focus come back.\n static setActionsOnCancelButtons() {\n // Make focus come back on the previous place it was when click cancel button\n const currentInstance = WirisPlugin.currentInstance;\n const editorSelection = currentInstance.getSelection();\n editorSelection.removeAllRanges();\n\n if (currentInstance.core.editionProperties.range) {\n const { range } = currentInstance.core.editionProperties;\n currentInstance.core.editionProperties.range = null;\n editorSelection.addRange(range);\n if (range.startOffset !== range.endOffset) {\n currentInstance.core.placeCaretAfterNode(currentInstance.core.editionProperties.temporalImage);\n }\n }\n\n // eslint-disable-next-line no-undef\n if (WirisPlugin.currentInstance) {\n WirisPlugin.currentInstance.core.editionProperties.temporalImage = null; // eslint-disable-line\n }\n }\n}\n\n// To know if the integration that extends this class implements\n// wrapper methods, they are set as undefined.\nIntegrationModel.prototype.getMathmlFromTextNode = undefined;\nIntegrationModel.prototype.fillNonLatexNode = undefined;\nIntegrationModel.prototype.getSelectedItem = undefined;\n\n/**\n * An object containing a list with the overwritable class constructor properties.\n * @type {Object}\n */\nIntegrationModel.integrationParameters = [\"serviceProviderProperties\", \"editorParameters\"];\n","/* eslint-disable */\nvar md5;\nexport default md5;\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n delete Array.prototype.__class__;\n})();\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n})();\ndelete Array.prototype.__class__;\n// @codingStandardsIgnoreEnd\n","import IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Telemeter from \"@wiris/mathtype-html-integration-devkit/src/telemeter.js\";\n\n/**\n * This class represents the MathType integration for CKEditor5.\n * @extends {IntegrationModel}\n */\nexport default class CKEditor5Integration extends IntegrationModel {\n constructor(ckeditorIntegrationModelProperties) {\n const editor = ckeditorIntegrationModelProperties.editorObject;\n\n if (typeof editor.config !== \"undefined\" && typeof editor.config.get(\"mathTypeParameters\") !== \"undefined\") {\n ckeditorIntegrationModelProperties.integrationParameters = editor.config.get(\"mathTypeParameters\");\n }\n /**\n * CKEditor5 Integration.\n *\n * @param {integrationModelProperties} integrationModelAttributes\n */\n super(ckeditorIntegrationModelProperties);\n\n /**\n * Folder name used for the integration inside CKEditor plugins folder.\n */\n this.integrationFolderName = \"ckeditor_wiris\";\n }\n\n /**\n * @inheritdoc\n * @returns {string} - The CKEditor instance language.\n * @override\n */\n getLanguage() {\n // Returns the CKEDitor instance language taking into account that the language can be an object.\n // Try to get editorParameters.language, fail silently otherwise\n try {\n return this.editorParameters.language;\n } catch (e) {}\n const languageObject = this.editorObject.config.get(\"language\");\n if (languageObject != null) {\n if (typeof languageObject === \"object\") {\n if (Object.prototype.hasOwnProperty.call(languageObject, \"ui\")) {\n return languageObject.ui;\n }\n return languageObject;\n }\n return languageObject;\n }\n return super.getLanguage();\n }\n\n /**\n * Adds callbacks to the following CKEditor listeners:\n * - 'focus' - updates the current instance.\n * - 'contentDom' - adds 'doubleclick' callback.\n * - 'doubleclick' - sets to null data.dialog property to avoid modifications for MathType formulas.\n * - 'setData' - parses the data converting MathML into images.\n * - 'afterSetData' - adds an observer to MathType formulas to avoid modifications.\n * - 'getData' - parses the data converting images into selected save mode (MathML by default).\n * - 'mode' - recalculates the active element.\n */\n addEditorListeners() {\n const editor = this.editorObject;\n\n if (typeof editor.config.wirislistenersdisabled === \"undefined\" || !editor.config.wirislistenersdisabled) {\n this.checkElement();\n }\n }\n\n /**\n * Checks the current container and assign events in case that it doesn't have them.\n * CKEditor replaces several times the element element during its execution,\n * so we must assign the events again to editor element.\n */\n checkElement() {\n const editor = this.editorObject;\n const newElement = editor.sourceElement;\n\n // If the element wasn't treated, add the events.\n if (!newElement.wirisActive) {\n this.setTarget(newElement);\n this.addEvents();\n // Set the element as treated\n newElement.wirisActive = true;\n }\n }\n\n /**\n * @inheritdoc\n * @param {HTMLElement} element - HTMLElement target.\n * @param {MouseEvent} event - event which trigger the handler.\n */\n doubleClickHandler(element, event) {\n this.core.editionProperties.dbclick = true;\n if (this.editorObject.isReadOnly === false) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n // Some plugins (image2, image) open a dialog on Double-click. On formulas\n // doubleclick event ends here.\n if (typeof event.stopPropagation !== \"undefined\") {\n // old I.E compatibility.\n event.stopPropagation();\n } else {\n event.returnValue = false;\n }\n this.core.getCustomEditors().disable();\n const customEditorAttr = element.getAttribute(Configuration.get(\"imageCustomEditorName\"));\n if (customEditorAttr) {\n this.core.getCustomEditors().enable(customEditorAttr);\n }\n this.core.editionProperties.temporalImage = element;\n this.openExistingFormulaEditor();\n }\n }\n }\n }\n\n /** @inheritdoc */\n static getCorePath() {\n return null; // TODO\n }\n\n /** @inheritdoc */\n callbackFunction() {\n super.callbackFunction();\n this.addEditorListeners();\n }\n\n openNewFormulaEditor() {\n // Store the editor selection as it will be lost upon opening the modal\n this.core.editionProperties.selection = this.editorObject.editing.view.document.selection;\n\n // Focus on the selected editor when multiple editor instances are present\n WirisPlugin.currentInstance = this;\n\n return super.openNewFormulaEditor();\n }\n\n /**\n * Replaces old formula with new MathML or inserts it in caret position if new\n * @param {String} mathml MathML to update old one or insert\n * @returns {module:engine/model/element~Element} The model element corresponding to the inserted image\n */\n insertMathml(mathml) {\n // This returns the value returned by the callback function (writer => {...})\n return this.editorObject.model.change((writer) => {\n const core = this.getCore();\n const selection = this.editorObject.model.document.selection;\n\n const modelElementNew = writer.createElement(\"mathml\", {\n formula: mathml,\n ...Object.fromEntries(selection.getAttributes()), // To keep the format, such as style and font\n });\n\n // Obtain the DOM object corresponding to the formula\n if (core.editionProperties.isNewElement) {\n // Don't bother inserting anything at all if the MathML is empty.\n if (!mathml) return;\n\n const viewSelection =\n this.core.editionProperties.selection || this.editorObject.editing.view.document.selection;\n const modelPosition = this.editorObject.editing.mapper.toModelPosition(viewSelection.getLastPosition());\n\n this.editorObject.model.insertObject(modelElementNew, modelPosition);\n\n // Remove selection\n if (!viewSelection.isCollapsed) {\n for (const range of viewSelection.getRanges()) {\n writer.remove(this.editorObject.editing.mapper.toModelRange(range));\n }\n }\n\n // Set carret after the formula\n const position = this.editorObject.model.createPositionAfter(modelElementNew);\n writer.setSelection(position);\n } else {\n const img = core.editionProperties.temporalImage;\n const viewElement = this.editorObject.editing.view.domConverter.domToView(img).parent;\n const modelElementOld = this.editorObject.editing.mapper.toModelElement(viewElement);\n\n // Insert the new and remove the old one\n const position = this.editorObject.model.createPositionBefore(modelElementOld);\n\n // If the given MathML is empty, don't insert a new formula.\n if (mathml) {\n this.editorObject.model.insertObject(modelElementNew, position);\n }\n writer.remove(modelElementOld);\n }\n\n // eslint-disable-next-line consistent-return\n return modelElementNew;\n });\n }\n\n /**\n * Finds the text node corresponding to given DOM text element.\n * @param {element} viewElement Element to find corresponding text node of.\n * @returns {module:engine/model/text~Text|undefined} Text node corresponding to the given element or undefined if it doesn't exist.\n */\n findText(viewElement) {\n // eslint-disable-line consistent-return\n // mapper always converts text nodes to *new* model elements so we need to convert the text's parents and then come back down\n let pivot = viewElement;\n let element;\n while (!element) {\n element = this.editorObject.editing.mapper.toModelElement(\n this.editorObject.editing.view.domConverter.domToView(pivot),\n );\n pivot = pivot.parentElement;\n }\n\n // Navigate through all the subtree under `pivot` in order to find the correct text node\n const range = this.editorObject.model.createRangeIn(element);\n const descendants = Array.from(range.getItems());\n for (const node of descendants) {\n let viewElementData = viewElement.data;\n if (viewElement.nodeType === 3) {\n // Remove invisible white spaces\n viewElementData = viewElementData.replaceAll(String.fromCharCode(8288), \"\");\n }\n if (node.is(\"textProxy\") && node.data === viewElementData.replace(String.fromCharCode(160), \" \")) {\n return node.textNode;\n }\n }\n }\n\n /** @inheritdoc */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n // eslint-disable-line no-unused-vars\n const returnObject = {};\n\n let mathmlOrigin;\n if (!mathml) {\n this.insertMathml(\"\");\n } else if (this.core.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n\n this.editorObject.model.change((writer) => {\n const { latexRange } = this.core.editionProperties;\n\n const startNode = this.findText(latexRange.startContainer);\n const endNode = this.findText(latexRange.endContainer);\n\n let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);\n let endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);\n\n let range = writer.createRange(startPosition, endPosition);\n\n // When Latex is next to image/formula.\n if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {\n // Get the position of the latex to be replaced.\n const latexEdited = `$$${Latex.getLatexFromMathML(\n MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml),\n )}$$`;\n let data = latexRange.startContainer.data;\n\n // Remove invisible characters.\n data = data.replaceAll(String.fromCharCode(8288), \"\");\n\n // Get to the start of the latex we are editing.\n const offset = data.indexOf(latexEdited);\n const dataOffset = data.substring(offset);\n const second$ = dataOffset.substring(2).indexOf(\"$$\") + 4;\n const substring = dataOffset.substr(0, second$);\n data = data.replace(substring, \"\");\n\n if (!data) {\n startPosition = writer.createPositionBefore(startNode);\n range = startNode;\n } else {\n startPosition = startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + offset);\n endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + second$ + offset);\n range = writer.createRange(startPosition, endPosition);\n }\n }\n\n writer.remove(range);\n writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);\n });\n } else {\n mathmlOrigin = this.core.editionProperties.temporalImage?.dataset.mathml;\n try {\n returnObject.node = this.editorObject.editing.view.domConverter.viewToDom(\n this.editorObject.editing.mapper.toViewElement(this.insertMathml(mathml)),\n windowTarget.document,\n );\n } catch (e) {\n const x = e.toString();\n if (x.includes(\"CKEditorError: Cannot read property 'parent' of undefined\")) {\n this.core.modalDialog.cancelAction();\n }\n }\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.core.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n\n /* Due to PLUGINS-1329, we add the onChange event to the CK4 insertFormula.\n We probably should add it here as well, but we should look further into how */\n // this.editorObject.fire('change');\n\n // Remove temporal image of inserted formula\n this.core.editionProperties.temporalImage = null;\n\n return returnObject;\n }\n\n /**\n * Function called when the content submits an action.\n */\n notifyWindowClosed() {\n this.editorObject.editing.view.focus();\n }\n}\n","/* eslint-disable max-classes-per-file */\nimport { Command } from \"ckeditor5/src/core.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\n/**\n * Command for opening the MathType editor\n */\nexport class MathTypeCommand extends Command {\n execute(options = {}) {\n // Check we get a valid integration\n // eslint-disable-next-line no-prototype-builtins\n if (!options.hasOwnProperty(\"integration\") || !(options.integration instanceof CKEditor5Integration)) {\n throw 'Must pass a valid CKEditor5Integration instance as attribute \"integration\" of options';\n }\n\n // Save the integration instance as a property of the command.\n this.integration = options.integration;\n\n // Set custom editor or disable it\n this.setEditor();\n\n // Open the editor\n this.openEditor();\n }\n\n /**\n * Sets the appropriate custom editor, if any, or disables them.\n */\n setEditor() {\n // It's possible that a custom editor was last used.\n // We need to disable it to avoid wrong behaviors.\n this.integration.core.getCustomEditors().disable();\n }\n\n /**\n * Checks whether we are editing an existing formula or a new one and opens the editor.\n */\n openEditor() {\n this.integration.core.editionProperties.dbclick = false;\n const image = this._getSelectedImage();\n if (\n typeof image !== \"undefined\" &&\n image !== null &&\n image.classList.contains(WirisPlugin.Configuration.get(\"imageClassName\"))\n ) {\n this.integration.core.editionProperties.temporalImage = image;\n this.integration.openExistingFormulaEditor();\n } else {\n this.integration.openNewFormulaEditor();\n }\n }\n\n /**\n * Gets the currently selected formula image\n * @returns {Element} selected image, if any, undefined otherwise\n */\n _getSelectedImage() {\n const { selection } = this.editor.editing.view.document;\n\n // If we can not extract the formula, fall back to default behavior.\n if (selection.isCollapsed || selection.rangeCount !== 1) {\n return;\n }\n\n // Look for the wrapping the formula and then for the inside\n\n const range = selection.getFirstRange();\n\n let image;\n\n for (const span of range) {\n if (span.item.name !== \"span\") {\n return;\n }\n image = span.item.getChild(0);\n break;\n }\n\n if (!image) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n return this.editor.editing.view.domConverter.mapViewToDom(image);\n }\n}\n\n/**\n * Command for opening the ChemType editor\n */\nexport class ChemTypeCommand extends MathTypeCommand {\n setEditor() {\n this.integration.core.getCustomEditors().enable(\"chemistry\");\n }\n}\n","// CKEditor imports\nimport { Plugin } from \"ckeditor5/src/core.js\";\nimport { ButtonView } from \"ckeditor5/src/ui.js\";\nimport { ClickObserver, HtmlDataProcessor, XmlDataProcessor, ViewUpcastWriter } from \"ckeditor5/src/engine.js\";\nimport { Widget, toWidget, viewToModelPositionOutsideModelElement } from \"ckeditor5/src/widget.js\";\n\n// MathType API imports\nimport IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Core from \"@wiris/mathtype-html-integration-devkit/src/core.src.js\";\nimport Parser from \"@wiris/mathtype-html-integration-devkit/src/parser.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Image from \"@wiris/mathtype-html-integration-devkit/src/image.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Listeners from \"@wiris/mathtype-html-integration-devkit/src/listeners.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport StringManager from \"@wiris/mathtype-html-integration-devkit/src/stringmanager.js\";\nimport \"@wiris/mathtype-html-integration-devkit/src/md5.js\";\n\n// Local imports\nimport { MathTypeCommand, ChemTypeCommand } from \"./commands.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\nimport mathIcon from \"../theme/icons/ckeditor5-formula.svg\";\nimport chemIcon from \"../theme/icons/ckeditor5-chem.svg\";\n\nimport packageInfo from \"../package.json\";\n\nexport let currentInstance = null; // eslint-disable-line import/no-mutable-exports\n\nexport default class MathType extends Plugin {\n static get requires() {\n return [Widget];\n }\n\n static get pluginName() {\n return \"MathType\";\n }\n\n init() {\n // Create the MathType API Integration object\n const integration = this._addIntegration();\n currentInstance = integration;\n\n // Add the MathType and ChemType commands to the editor\n this._addCommands();\n\n // Add the buttons for MathType and ChemType\n this._addViews(integration);\n\n // Registers the element in the schema\n this._addSchema();\n\n // Add the downcast and upcast converters\n this._addConverters(integration);\n\n // Expose the WirisPlugin variable to the window\n this._exposeWiris();\n }\n\n /**\n * Inherited from Plugin class: Executed when CKEditor5 is destroyed\n */\n destroy() {\n // eslint-disable-line class-methods-use-this\n currentInstance?.destroy();\n }\n\n /**\n * Create the MathType API Integration object\n * @returns {CKEditor5Integration} the integration object\n */\n _addIntegration() {\n const { editor } = this;\n\n /**\n * Integration model constructor attributes.\n * @type {integrationModelProperties}\n */\n const integrationProperties = {};\n integrationProperties.environment = {};\n integrationProperties.environment.editor = \"CKEditor5\";\n integrationProperties.environment.editorVersion = \"5.x\";\n integrationProperties.version = packageInfo.version;\n integrationProperties.editorObject = editor;\n integrationProperties.serviceProviderProperties = {};\n integrationProperties.serviceProviderProperties.URI = \"https://www.wiris.net/demo/plugins/app\";\n integrationProperties.serviceProviderProperties.server = \"java\";\n integrationProperties.target = editor.sourceElement;\n integrationProperties.scriptName = \"bundle.js\";\n integrationProperties.managesLanguage = true;\n // etc\n\n // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.\n // To avoid a wrong behavior, this integration only starts if the workspace container exists.\n let integration;\n if (integrationProperties.target) {\n // Instance of the integration associated to this editor instance\n integration = new CKEditor5Integration(integrationProperties);\n integration.init();\n integration.listeners.fire(\"onTargetReady\", {});\n\n integration.checkElement();\n\n this.listenTo(\n editor.editing.view.document,\n \"click\",\n (evt, data) => {\n // Is Double-click\n if (data.domEvent.detail === 2) {\n integration.doubleClickHandler(data.domTarget, data.domEvent);\n evt.stop();\n }\n },\n { priority: \"highest\" },\n );\n }\n\n return integration;\n }\n\n /**\n * Add the MathType and ChemType commands to the editor\n */\n _addCommands() {\n const { editor } = this;\n\n // Add command to open the formula editor\n editor.commands.add(\"MathType\", new MathTypeCommand(editor));\n\n // Add command to open the chemistry formula editor\n editor.commands.add(\"ChemType\", new ChemTypeCommand(editor));\n }\n\n /**\n * Add the buttons for MathType and ChemType\n * @param {CKEditor5Integration} integration the integration object\n */\n _addViews(integration) {\n const { editor } = this;\n\n // Check if MathType editor is enabled\n if (Configuration.get(\"editorEnabled\")) {\n // Add button for the formula editor\n editor.ui.componentFactory.add(\"MathType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"MathType\"), \"isEnabled\");\n view.set({\n label: StringManager.get(\"insert_math\", integration.getLanguage()),\n icon: mathIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"MathType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Check if ChemType editor is enabled\n if (Configuration.get(\"chemEnabled\")) {\n // Add button for the chemistry formula editor\n editor.ui.componentFactory.add(\"ChemType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"ChemType\"), \"isEnabled\");\n\n view.set({\n label: StringManager.get(\"insert_chem\", integration.getLanguage()),\n icon: chemIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"ChemType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Observer for the Double-click event\n editor.editing.view.addObserver(ClickObserver);\n }\n\n /**\n * Registers the element in the schema\n */\n _addSchema() {\n const { schema } = this.editor.model;\n\n schema.register(\"mathml\", {\n inheritAllFrom: \"$inlineObject\",\n allowAttributes: [\"formula\", \"htmlContent\"],\n });\n }\n\n /**\n * Add the downcast and upcast converters\n */\n _addConverters(integration) {\n const { editor } = this;\n\n // Editing view -> Model\n editor.conversion.for(\"upcast\").elementToElement({\n view: {\n name: \"span\",\n classes: \"ck-math-widget\",\n },\n model: (viewElement, { writer: modelWriter }) => {\n const formula = MathML.safeXmlDecode(viewElement.getChild(0).getAttribute(\"data-mathml\"));\n return modelWriter.createElement(\"mathml\", {\n formula,\n });\n },\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\"element:math\", (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // When element was already consumed then skip it.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // If we encounter any with a LaTeX annotation inside,\n // convert it into a \"$$...$$\" string.\n const isLatex = mathIsLatex(viewItem); // eslint-disable-line no-use-before-define\n\n // Get the formula of the (which is all its children).\n const processor = new XmlDataProcessor(editor.editing.view.document);\n\n // Only god knows why the following line makes viewItem lose all of its children,\n // so we obtain isLatex before doing this because we need viewItem's children for that.\n const upcastWriter = new ViewUpcastWriter(editor.editing.view.document);\n const viewDocumentFragment = upcastWriter.createDocumentFragment(viewItem.getChildren());\n\n // and obtain the attributes of too!\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n\n // We process the document fragment\n let formula = processor.toData(viewDocumentFragment) || \"\";\n\n // And obtain the complete formula\n formula = Util.htmlSanitize(`${formula}`);\n\n // Replaces the < & > characters to its HTMLEntity to avoid render issues.\n formula = formula.replaceAll('\"<\"', '\"<\"').replaceAll('\">\"', '\">\"').replaceAll(\"><<\", \"><<\");\n\n /* Model node that contains what's going to actually be inserted. This can be either:\n - A element with a formula attribute set to the given formula, or\n - If the original had a LaTeX annotation, then the annotation surrounded by \"$$...$$\" */\n const modelNode = isLatex\n ? writer.createText(Parser.initParse(formula, integration.getLanguage()))\n : writer.createElement(\"mathml\", { formula });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\n \"element:img\",\n (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // Only upcast when is wiris formula\n if (viewItem.getClassNames().next().value !== \"Wirisformula\") {\n return;\n }\n\n // The following code ensures that the element's name, attributes, and classes are consumed.\n // This means that they are marked as handled so that other parts of the system or plugins don't process them again.\n\n // Check if we can consume the element name.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // Consume the name, attributes, and classes so nothing else processes it.\n consumable.consume(viewItem, { name: true });\n for (const attrName of viewItem.getAttributes()) {\n consumable.consume(viewItem, { attributes: [attrName] });\n }\n\n for (const className of viewItem.getClassNames()) {\n consumable.consume(viewItem, { classes: [className] });\n }\n\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n const htmlContent = Util.htmlSanitize(``);\n\n const modelNode = writer.createElement(\"mathml\", { htmlContent });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n },\n // Ensures MathType processes the Wiris formulas before other plugins, preventing conflicts.\n { priority: \"high\" },\n );\n\n /**\n * Whether the given view element has a LaTeX annotation element.\n * @param {*} math\n * @returns {bool}\n */\n function mathIsLatex(math) {\n const semantics = math.getChild(0);\n if (!semantics || semantics.name !== \"semantics\") return false;\n for (const child of semantics.getChildren()) {\n if (child.name === \"annotation\" && child.getAttribute(\"encoding\") === \"LaTeX\") {\n return true;\n }\n }\n return false;\n }\n\n function createViewWidget(modelItem, { writer: viewWriter }) {\n const widgetElement = viewWriter.createContainerElement(\"span\", {\n class: \"ck-math-widget\",\n });\n\n const mathUIElement = createViewImage(modelItem, { writer: viewWriter }); // eslint-disable-line no-use-before-define\n\n if (mathUIElement) {\n viewWriter.insert(viewWriter.createPositionAt(widgetElement, 0), mathUIElement);\n }\n\n return toWidget(widgetElement, viewWriter);\n }\n\n function createViewImage(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n const formula = modelItem.getAttribute(\"formula\");\n const htmlContent = modelItem.getAttribute(\"htmlContent\");\n\n if (!formula && !htmlContent) {\n return null;\n }\n\n let imgElement = null;\n\n if (htmlContent) {\n imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);\n } else if (formula) {\n const mathString = formula.replaceAll('ref=\"<\"', 'ref=\"<\"');\n\n const imgHtml = Parser.initParse(mathString, integration.getLanguage());\n imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);\n\n // Add HTML element () to model\n viewWriter.setAttribute(\"htmlContent\", imgHtml, modelItem);\n }\n\n /* Although we use the HtmlDataProcessor to obtain the attributes,\n * we must create a new EmptyElement which is independent of the\n * DataProcessor being used by this editor instance\n */\n if (imgElement) {\n return viewWriter.createEmptyElement(\"img\", imgElement.getAttributes(), {\n renderUnsafeAttributes: [\"src\"],\n });\n }\n\n return null;\n }\n\n // Model -> Editing view\n editor.conversion.for(\"editingDowncast\").elementToElement({\n model: \"mathml\",\n view: createViewWidget,\n });\n\n // Model -> Data view\n editor.conversion.for(\"dataDowncast\").elementToElement({\n model: \"mathml\",\n view: createDataString, // eslint-disable-line no-use-before-define\n });\n\n /**\n * Makes a copy of the given view node.\n * @param {module:engine/view/node~Node} sourceNode Node to copy.\n * @returns {module:engine/view/node~Node} Copy of the node.\n */\n function clone(viewWriter, sourceNode) {\n if (sourceNode.is(\"text\")) {\n return viewWriter.createText(sourceNode.data);\n }\n if (sourceNode.is(\"element\")) {\n if (sourceNode.is(\"emptyElement\")) {\n return viewWriter.createEmptyElement(sourceNode.name, sourceNode.getAttributes());\n }\n const element = viewWriter.createContainerElement(sourceNode.name, sourceNode.getAttributes());\n for (const child of sourceNode.getChildren()) {\n viewWriter.insert(viewWriter.createPositionAt(element, \"end\"), clone(viewWriter, child));\n }\n return element;\n }\n\n throw new Exception(\"Given node has unsupported type.\"); // eslint-disable-line no-undef\n }\n\n function createDataString(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n // Load img element\n const mathString =\n modelItem.getAttribute(\"htmlContent\") || Parser.endParseSaveMode(modelItem.getAttribute(\"formula\"));\n\n const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);\n\n return clone(viewWriter, sourceMathElement);\n }\n\n // This stops the view selection getting into the s and messing up caret movement\n editor.editing.mapper.on(\n \"viewToModelPosition\",\n viewToModelPositionOutsideModelElement(editor.model, (viewElement) => viewElement.hasClass(\"ck-math-widget\")),\n );\n\n // Keep a reference to the original get and set function.\n const { get, set } = editor.data;\n\n /**\n * Hack to transform $$latex$$ into in editor.getData()'s output.\n */\n editor.data.on(\n \"get\",\n (e) => {\n const output = e.return;\n const parsedResult = Parser.endParse(output);\n\n // Cleans all the semantics tag for safexml\n // including the handwritten data points\n e.return = MathML.removeSafeXMLSemantics(parsedResult);\n },\n { priority: \"low\" },\n );\n\n /**\n * Hack to transform with LaTeX into $$LaTeX$$ and formula images in editor.setData().\n */\n editor.data.on(\n \"set\",\n (e, args) => {\n // Retrieve the data to be set on the CKEditor.\n let modifiedData = args[0];\n // Regex to find all mathml formulas.\n const regexp = /(]*>)|()/gm;\n const formulas = [];\n let formula;\n\n // Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.\n while ((formula = regexp.exec(modifiedData)) !== null) {\n formulas.push(formula[0]);\n }\n\n // Loop to find LaTeX and formula images and replace the MathML for the both.\n formulas.forEach((formula) => {\n if (formula.includes('encoding=\"LaTeX\"')) {\n // LaTeX found.\n const latex = `$$$${Latex.getLatexFromMathML(formula)}$$$`; // We add $$$ instead of $$ because the replace function ignores one $.\n modifiedData = modifiedData.replace(formula, latex);\n } else if (formula.includes(\" 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {\n args[_key - 2] = arguments[_key];\n }\n return func.apply(thisArg, args);\n };\n}\nif (!construct) {\n construct = function construct(Func) {\n for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {\n args[_key2 - 1] = arguments[_key2];\n }\n return new Func(...args);\n };\n}\nconst arrayForEach = unapply(Array.prototype.forEach);\nconst arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);\nconst arrayPop = unapply(Array.prototype.pop);\nconst arrayPush = unapply(Array.prototype.push);\nconst arraySplice = unapply(Array.prototype.splice);\nconst stringToLowerCase = unapply(String.prototype.toLowerCase);\nconst stringToString = unapply(String.prototype.toString);\nconst stringMatch = unapply(String.prototype.match);\nconst stringReplace = unapply(String.prototype.replace);\nconst stringIndexOf = unapply(String.prototype.indexOf);\nconst stringTrim = unapply(String.prototype.trim);\nconst objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);\nconst regExpTest = unapply(RegExp.prototype.test);\nconst typeErrorCreate = unconstruct(TypeError);\n/**\n * Creates a new function that calls the given function with a specified thisArg and arguments.\n *\n * @param func - The function to be wrapped and called.\n * @returns A new function that calls the given function with a specified thisArg and arguments.\n */\nfunction unapply(func) {\n return function (thisArg) {\n if (thisArg instanceof RegExp) {\n thisArg.lastIndex = 0;\n }\n for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {\n args[_key3 - 1] = arguments[_key3];\n }\n return apply(func, thisArg, args);\n };\n}\n/**\n * Creates a new function that constructs an instance of the given constructor function with the provided arguments.\n *\n * @param func - The constructor function to be wrapped and called.\n * @returns A new function that constructs an instance of the given constructor function with the provided arguments.\n */\nfunction unconstruct(Func) {\n return function () {\n for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {\n args[_key4] = arguments[_key4];\n }\n return construct(Func, args);\n };\n}\n/**\n * Add properties to a lookup table\n *\n * @param set - The set to which elements will be added.\n * @param array - The array containing elements to be added to the set.\n * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.\n * @returns The modified set with added elements.\n */\nfunction addToSet(set, array) {\n let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;\n if (setPrototypeOf) {\n // Make 'in' and truthy checks like Boolean(set.constructor)\n // independent of any properties defined on Object.prototype.\n // Prevent prototype setters from intercepting set as a this value.\n setPrototypeOf(set, null);\n }\n let l = array.length;\n while (l--) {\n let element = array[l];\n if (typeof element === 'string') {\n const lcElement = transformCaseFunc(element);\n if (lcElement !== element) {\n // Config presets (e.g. tags.js, attrs.js) are immutable.\n if (!isFrozen(array)) {\n array[l] = lcElement;\n }\n element = lcElement;\n }\n }\n set[element] = true;\n }\n return set;\n}\n/**\n * Clean up an array to harden against CSPP\n *\n * @param array - The array to be cleaned.\n * @returns The cleaned version of the array\n */\nfunction cleanArray(array) {\n for (let index = 0; index < array.length; index++) {\n const isPropertyExist = objectHasOwnProperty(array, index);\n if (!isPropertyExist) {\n array[index] = null;\n }\n }\n return array;\n}\n/**\n * Shallow clone an object\n *\n * @param object - The object to be cloned.\n * @returns A new object that copies the original.\n */\nfunction clone(object) {\n const newObject = create(null);\n for (const [property, value] of entries(object)) {\n const isPropertyExist = objectHasOwnProperty(object, property);\n if (isPropertyExist) {\n if (Array.isArray(value)) {\n newObject[property] = cleanArray(value);\n } else if (value && typeof value === 'object' && value.constructor === Object) {\n newObject[property] = clone(value);\n } else {\n newObject[property] = value;\n }\n }\n }\n return newObject;\n}\n/**\n * This method automatically checks if the prop is function or getter and behaves accordingly.\n *\n * @param object - The object to look up the getter function in its prototype chain.\n * @param prop - The property name for which to find the getter function.\n * @returns The getter function found in the prototype chain or a fallback function.\n */\nfunction lookupGetter(object, prop) {\n while (object !== null) {\n const desc = getOwnPropertyDescriptor(object, prop);\n if (desc) {\n if (desc.get) {\n return unapply(desc.get);\n }\n if (typeof desc.value === 'function') {\n return unapply(desc.value);\n }\n }\n object = getPrototypeOf(object);\n }\n function fallbackValue() {\n return null;\n }\n return fallbackValue;\n}\n\nconst html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);\nconst svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);\nconst svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);\n// List of SVG elements that are disallowed by default.\n// We still need to know them so that we can do namespace\n// checks properly in case one wants to add them to\n// allow-list.\nconst svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);\nconst mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);\n// Similarly to SVG, we want to know all MathML elements,\n// even those that we disallow by default.\nconst mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);\nconst text = freeze(['#text']);\n\nconst html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);\nconst svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);\nconst mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnsalign', 'columnlines', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lspace', 'lquote', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);\nconst xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);\n\n// eslint-disable-next-line unicorn/better-regex\nconst MUSTACHE_EXPR = seal(/\\{\\{[\\w\\W]*|[\\w\\W]*\\}\\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode\nconst ERB_EXPR = seal(/<%[\\w\\W]*|[\\w\\W]*%>/gm);\nconst TMPLIT_EXPR = seal(/\\$\\{[\\w\\W]*/gm); // eslint-disable-line unicorn/better-regex\nconst DATA_ATTR = seal(/^data-[\\-\\w.\\u00B7-\\uFFFF]+$/); // eslint-disable-line no-useless-escape\nconst ARIA_ATTR = seal(/^aria-[\\-\\w]+$/); // eslint-disable-line no-useless-escape\nconst IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\\-]+(?:[^a-z+.\\-:]|$))/i // eslint-disable-line no-useless-escape\n);\nconst IS_SCRIPT_OR_DATA = seal(/^(?:\\w+script|data):/i);\nconst ATTR_WHITESPACE = seal(/[\\u0000-\\u0020\\u00A0\\u1680\\u180E\\u2000-\\u2029\\u205F\\u3000]/g // eslint-disable-line no-control-regex\n);\nconst DOCTYPE_NAME = seal(/^html$/i);\nconst CUSTOM_ELEMENT = seal(/^[a-z][.\\w]*(-[.\\w]+)+$/i);\n\nvar EXPRESSIONS = /*#__PURE__*/Object.freeze({\n __proto__: null,\n ARIA_ATTR: ARIA_ATTR,\n ATTR_WHITESPACE: ATTR_WHITESPACE,\n CUSTOM_ELEMENT: CUSTOM_ELEMENT,\n DATA_ATTR: DATA_ATTR,\n DOCTYPE_NAME: DOCTYPE_NAME,\n ERB_EXPR: ERB_EXPR,\n IS_ALLOWED_URI: IS_ALLOWED_URI,\n IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,\n MUSTACHE_EXPR: MUSTACHE_EXPR,\n TMPLIT_EXPR: TMPLIT_EXPR\n});\n\n/* eslint-disable @typescript-eslint/indent */\n// https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType\nconst NODE_TYPE = {\n element: 1,\n attribute: 2,\n text: 3,\n cdataSection: 4,\n entityReference: 5,\n // Deprecated\n entityNode: 6,\n // Deprecated\n progressingInstruction: 7,\n comment: 8,\n document: 9,\n documentType: 10,\n documentFragment: 11,\n notation: 12 // Deprecated\n};\nconst getGlobal = function getGlobal() {\n return typeof window === 'undefined' ? null : window;\n};\n/**\n * Creates a no-op policy for internal use only.\n * Don't export this function outside this module!\n * @param trustedTypes The policy factory.\n * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).\n * @return The policy created (or null, if Trusted Types\n * are not supported or creating the policy failed).\n */\nconst _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {\n if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {\n return null;\n }\n // Allow the callers to control the unique policy name\n // by adding a data-tt-policy-suffix to the script element with the DOMPurify.\n // Policy creation with duplicate names throws in Trusted Types.\n let suffix = null;\n const ATTR_NAME = 'data-tt-policy-suffix';\n if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {\n suffix = purifyHostElement.getAttribute(ATTR_NAME);\n }\n const policyName = 'dompurify' + (suffix ? '#' + suffix : '');\n try {\n return trustedTypes.createPolicy(policyName, {\n createHTML(html) {\n return html;\n },\n createScriptURL(scriptUrl) {\n return scriptUrl;\n }\n });\n } catch (_) {\n // Policy creation failed (most likely another DOMPurify script has\n // already run). Skip creating the policy, as this will only cause errors\n // if TT are enforced.\n console.warn('TrustedTypes policy ' + policyName + ' could not be created.');\n return null;\n }\n};\nconst _createHooksMap = function _createHooksMap() {\n return {\n afterSanitizeAttributes: [],\n afterSanitizeElements: [],\n afterSanitizeShadowDOM: [],\n beforeSanitizeAttributes: [],\n beforeSanitizeElements: [],\n beforeSanitizeShadowDOM: [],\n uponSanitizeAttribute: [],\n uponSanitizeElement: [],\n uponSanitizeShadowNode: []\n };\n};\nfunction createDOMPurify() {\n let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();\n const DOMPurify = root => createDOMPurify(root);\n DOMPurify.version = '3.3.0';\n DOMPurify.removed = [];\n if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {\n // Not running in a browser, provide a factory function\n // so that you can pass your own Window\n DOMPurify.isSupported = false;\n return DOMPurify;\n }\n let {\n document\n } = window;\n const originalDocument = document;\n const currentScript = originalDocument.currentScript;\n const {\n DocumentFragment,\n HTMLTemplateElement,\n Node,\n Element,\n NodeFilter,\n NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,\n HTMLFormElement,\n DOMParser,\n trustedTypes\n } = window;\n const ElementPrototype = Element.prototype;\n const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');\n const remove = lookupGetter(ElementPrototype, 'remove');\n const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');\n const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');\n const getParentNode = lookupGetter(ElementPrototype, 'parentNode');\n // As per issue #47, the web-components registry is inherited by a\n // new document created via createHTMLDocument. As per the spec\n // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)\n // a new empty registry is used when creating a template contents owner\n // document, so we use that as our parent document to ensure nothing\n // is inherited.\n if (typeof HTMLTemplateElement === 'function') {\n const template = document.createElement('template');\n if (template.content && template.content.ownerDocument) {\n document = template.content.ownerDocument;\n }\n }\n let trustedTypesPolicy;\n let emptyHTML = '';\n const {\n implementation,\n createNodeIterator,\n createDocumentFragment,\n getElementsByTagName\n } = document;\n const {\n importNode\n } = originalDocument;\n let hooks = _createHooksMap();\n /**\n * Expose whether this browser supports running the full DOMPurify.\n */\n DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;\n const {\n MUSTACHE_EXPR,\n ERB_EXPR,\n TMPLIT_EXPR,\n DATA_ATTR,\n ARIA_ATTR,\n IS_SCRIPT_OR_DATA,\n ATTR_WHITESPACE,\n CUSTOM_ELEMENT\n } = EXPRESSIONS;\n let {\n IS_ALLOWED_URI: IS_ALLOWED_URI$1\n } = EXPRESSIONS;\n /**\n * We consider the elements and attributes below to be safe. Ideally\n * don't add any new ones but feel free to remove unwanted ones.\n */\n /* allowed element names */\n let ALLOWED_TAGS = null;\n const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);\n /* Allowed attribute names */\n let ALLOWED_ATTR = null;\n const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);\n /*\n * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.\n * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)\n * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)\n * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.\n */\n let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {\n tagNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n attributeNameCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n allowCustomizedBuiltInElements: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: false\n }\n }));\n /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */\n let FORBID_TAGS = null;\n /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */\n let FORBID_ATTR = null;\n /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */\n const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {\n tagCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n },\n attributeCheck: {\n writable: true,\n configurable: false,\n enumerable: true,\n value: null\n }\n }));\n /* Decide if ARIA attributes are okay */\n let ALLOW_ARIA_ATTR = true;\n /* Decide if custom data attributes are okay */\n let ALLOW_DATA_ATTR = true;\n /* Decide if unknown protocols are okay */\n let ALLOW_UNKNOWN_PROTOCOLS = false;\n /* Decide if self-closing tags in attributes are allowed.\n * Usually removed due to a mXSS issue in jQuery 3.0 */\n let ALLOW_SELF_CLOSE_IN_ATTR = true;\n /* Output should be safe for common template engines.\n * This means, DOMPurify removes data attributes, mustaches and ERB\n */\n let SAFE_FOR_TEMPLATES = false;\n /* Output should be safe even for XML used within HTML and alike.\n * This means, DOMPurify removes comments when containing risky content.\n */\n let SAFE_FOR_XML = true;\n /* Decide if document with ... should be returned */\n let WHOLE_DOCUMENT = false;\n /* Track whether config is already set on this instance of DOMPurify. */\n let SET_CONFIG = false;\n /* Decide if all elements (e.g. style, script) must be children of\n * document.body. By default, browsers might move them to document.head */\n let FORCE_BODY = false;\n /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported).\n * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead\n */\n let RETURN_DOM = false;\n /* Decide if a DOM `DocumentFragment` should be returned, instead of a html\n * string (or a TrustedHTML object if Trusted Types are supported) */\n let RETURN_DOM_FRAGMENT = false;\n /* Try to return a Trusted Type object instead of a string, return a string in\n * case Trusted Types are not supported */\n let RETURN_TRUSTED_TYPE = false;\n /* Output should be free from DOM clobbering attacks?\n * This sanitizes markups named with colliding, clobberable built-in DOM APIs.\n */\n let SANITIZE_DOM = true;\n /* Achieve full DOM Clobbering protection by isolating the namespace of named\n * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.\n *\n * HTML/DOM spec rules that enable DOM Clobbering:\n * - Named Access on Window (§7.3.3)\n * - DOM Tree Accessors (§3.1.5)\n * - Form Element Parent-Child Relations (§4.10.3)\n * - Iframe srcdoc / Nested WindowProxies (§4.8.5)\n * - HTMLCollection (§4.2.10.2)\n *\n * Namespace isolation is implemented by prefixing `id` and `name` attributes\n * with a constant string, i.e., `user-content-`\n */\n let SANITIZE_NAMED_PROPS = false;\n const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';\n /* Keep element content when removing element? */\n let KEEP_CONTENT = true;\n /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead\n * of importing it into a new Document and returning a sanitized copy */\n let IN_PLACE = false;\n /* Allow usage of profiles like html, svg and mathMl */\n let USE_PROFILES = {};\n /* Tags to ignore content of when KEEP_CONTENT is true */\n let FORBID_CONTENTS = null;\n const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);\n /* Tags that are safe for data: URIs */\n let DATA_URI_TAGS = null;\n const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);\n /* Attributes safe for values like \"javascript:\" */\n let URI_SAFE_ATTRIBUTES = null;\n const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);\n const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';\n const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';\n const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';\n /* Document namespace */\n let NAMESPACE = HTML_NAMESPACE;\n let IS_EMPTY_INPUT = false;\n /* Allowed XHTML+XML namespaces */\n let ALLOWED_NAMESPACES = null;\n const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);\n let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);\n let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);\n // Certain elements are allowed in both SVG and HTML\n // namespace. We need to specify them explicitly\n // so that they don't get erroneously deleted from\n // HTML namespace.\n const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);\n /* Parsing of strict XHTML documents */\n let PARSER_MEDIA_TYPE = null;\n const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];\n const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';\n let transformCaseFunc = null;\n /* Keep a reference to config to pass to hooks */\n let CONFIG = null;\n /* Ideally, do not touch anything below this line */\n /* ______________________________________________ */\n const formElement = document.createElement('form');\n const isRegexOrFunction = function isRegexOrFunction(testValue) {\n return testValue instanceof RegExp || testValue instanceof Function;\n };\n /**\n * _parseConfig\n *\n * @param cfg optional config literal\n */\n // eslint-disable-next-line complexity\n const _parseConfig = function _parseConfig() {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n if (CONFIG && CONFIG === cfg) {\n return;\n }\n /* Shield configuration object from tampering */\n if (!cfg || typeof cfg !== 'object') {\n cfg = {};\n }\n /* Shield configuration object from prototype pollution */\n cfg = clone(cfg);\n PARSER_MEDIA_TYPE =\n // eslint-disable-next-line unicorn/prefer-includes\n SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;\n // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.\n transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;\n /* Set configuration parameters */\n ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;\n ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;\n ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;\n URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;\n DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;\n FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;\n FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});\n FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});\n USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;\n ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true\n ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true\n ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false\n ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true\n SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false\n SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true\n WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false\n RETURN_DOM = cfg.RETURN_DOM || false; // Default false\n RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false\n RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false\n FORCE_BODY = cfg.FORCE_BODY || false; // Default false\n SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true\n SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false\n KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true\n IN_PLACE = cfg.IN_PLACE || false; // Default false\n IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;\n NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;\n MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;\n HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;\n CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {\n CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;\n }\n if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {\n CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;\n }\n if (SAFE_FOR_TEMPLATES) {\n ALLOW_DATA_ATTR = false;\n }\n if (RETURN_DOM_FRAGMENT) {\n RETURN_DOM = true;\n }\n /* Parse profile info */\n if (USE_PROFILES) {\n ALLOWED_TAGS = addToSet({}, text);\n ALLOWED_ATTR = [];\n if (USE_PROFILES.html === true) {\n addToSet(ALLOWED_TAGS, html$1);\n addToSet(ALLOWED_ATTR, html);\n }\n if (USE_PROFILES.svg === true) {\n addToSet(ALLOWED_TAGS, svg$1);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.svgFilters === true) {\n addToSet(ALLOWED_TAGS, svgFilters);\n addToSet(ALLOWED_ATTR, svg);\n addToSet(ALLOWED_ATTR, xml);\n }\n if (USE_PROFILES.mathMl === true) {\n addToSet(ALLOWED_TAGS, mathMl$1);\n addToSet(ALLOWED_ATTR, mathMl);\n addToSet(ALLOWED_ATTR, xml);\n }\n }\n /* Merge configuration parameters */\n if (cfg.ADD_TAGS) {\n if (typeof cfg.ADD_TAGS === 'function') {\n EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;\n } else {\n if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {\n ALLOWED_TAGS = clone(ALLOWED_TAGS);\n }\n addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);\n }\n }\n if (cfg.ADD_ATTR) {\n if (typeof cfg.ADD_ATTR === 'function') {\n EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;\n } else {\n if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {\n ALLOWED_ATTR = clone(ALLOWED_ATTR);\n }\n addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);\n }\n }\n if (cfg.ADD_URI_SAFE_ATTR) {\n addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);\n }\n if (cfg.FORBID_CONTENTS) {\n if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {\n FORBID_CONTENTS = clone(FORBID_CONTENTS);\n }\n addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);\n }\n /* Add #text in case KEEP_CONTENT is set to true */\n if (KEEP_CONTENT) {\n ALLOWED_TAGS['#text'] = true;\n }\n /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */\n if (WHOLE_DOCUMENT) {\n addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);\n }\n /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */\n if (ALLOWED_TAGS.table) {\n addToSet(ALLOWED_TAGS, ['tbody']);\n delete FORBID_TAGS.tbody;\n }\n if (cfg.TRUSTED_TYPES_POLICY) {\n if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createHTML\" hook.');\n }\n if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {\n throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a \"createScriptURL\" hook.');\n }\n // Overwrite existing TrustedTypes policy.\n trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;\n // Sign local variables required by `sanitize`.\n emptyHTML = trustedTypesPolicy.createHTML('');\n } else {\n // Uninitialized policy, attempt to initialize the internal dompurify policy.\n if (trustedTypesPolicy === undefined) {\n trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);\n }\n // If creating the internal policy succeeded sign internal variables.\n if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {\n emptyHTML = trustedTypesPolicy.createHTML('');\n }\n }\n // Prevent further manipulation of configuration.\n // Not available in IE8, Safari 5, etc.\n if (freeze) {\n freeze(cfg);\n }\n CONFIG = cfg;\n };\n /* Keep track of all possible SVG and MathML tags\n * so that we can perform the namespace checks\n * correctly. */\n const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);\n const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);\n /**\n * @param element a DOM element whose namespace is being checked\n * @returns Return false if the element has a\n * namespace that a spec-compliant parser would never\n * return. Return true otherwise.\n */\n const _checkValidNamespace = function _checkValidNamespace(element) {\n let parent = getParentNode(element);\n // In JSDOM, if we're inside shadow DOM, then parentNode\n // can be null. We just simulate parent in this case.\n if (!parent || !parent.tagName) {\n parent = {\n namespaceURI: NAMESPACE,\n tagName: 'template'\n };\n }\n const tagName = stringToLowerCase(element.tagName);\n const parentTagName = stringToLowerCase(parent.tagName);\n if (!ALLOWED_NAMESPACES[element.namespaceURI]) {\n return false;\n }\n if (element.namespaceURI === SVG_NAMESPACE) {\n // The only way to switch from HTML namespace to SVG\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'svg';\n }\n // The only way to switch from MathML to SVG is via`\n // svg if parent is either or MathML\n // text integration points.\n if (parent.namespaceURI === MATHML_NAMESPACE) {\n return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);\n }\n // We only allow elements that are defined in SVG\n // spec. All others are disallowed in SVG namespace.\n return Boolean(ALL_SVG_TAGS[tagName]);\n }\n if (element.namespaceURI === MATHML_NAMESPACE) {\n // The only way to switch from HTML namespace to MathML\n // is via . If it happens via any other tag, then\n // it should be killed.\n if (parent.namespaceURI === HTML_NAMESPACE) {\n return tagName === 'math';\n }\n // The only way to switch from SVG to MathML is via\n // and HTML integration points\n if (parent.namespaceURI === SVG_NAMESPACE) {\n return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];\n }\n // We only allow elements that are defined in MathML\n // spec. All others are disallowed in MathML namespace.\n return Boolean(ALL_MATHML_TAGS[tagName]);\n }\n if (element.namespaceURI === HTML_NAMESPACE) {\n // The only way to switch from SVG to HTML is via\n // HTML integration points, and from MathML to HTML\n // is via MathML text integration points\n if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {\n return false;\n }\n // We disallow tags that are specific for MathML\n // or SVG and should never appear in HTML namespace\n return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);\n }\n // For XHTML and XML documents that support custom namespaces\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {\n return true;\n }\n // The code should never reach this place (this means\n // that the element somehow got namespace that is not\n // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).\n // Return false just in case.\n return false;\n };\n /**\n * _forceRemove\n *\n * @param node a DOM node\n */\n const _forceRemove = function _forceRemove(node) {\n arrayPush(DOMPurify.removed, {\n element: node\n });\n try {\n // eslint-disable-next-line unicorn/prefer-dom-node-remove\n getParentNode(node).removeChild(node);\n } catch (_) {\n remove(node);\n }\n };\n /**\n * _removeAttribute\n *\n * @param name an Attribute name\n * @param element a DOM node\n */\n const _removeAttribute = function _removeAttribute(name, element) {\n try {\n arrayPush(DOMPurify.removed, {\n attribute: element.getAttributeNode(name),\n from: element\n });\n } catch (_) {\n arrayPush(DOMPurify.removed, {\n attribute: null,\n from: element\n });\n }\n element.removeAttribute(name);\n // We void attribute values for unremovable \"is\" attributes\n if (name === 'is') {\n if (RETURN_DOM || RETURN_DOM_FRAGMENT) {\n try {\n _forceRemove(element);\n } catch (_) {}\n } else {\n try {\n element.setAttribute(name, '');\n } catch (_) {}\n }\n }\n };\n /**\n * _initDocument\n *\n * @param dirty - a string of dirty markup\n * @return a DOM, filled with the dirty markup\n */\n const _initDocument = function _initDocument(dirty) {\n /* Create a HTML document */\n let doc = null;\n let leadingWhitespace = null;\n if (FORCE_BODY) {\n dirty = '' + dirty;\n } else {\n /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */\n const matches = stringMatch(dirty, /^[\\r\\n\\t ]+/);\n leadingWhitespace = matches && matches[0];\n }\n if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {\n // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)\n dirty = '' + dirty + '';\n }\n const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;\n /*\n * Use the DOMParser API by default, fallback later if needs be\n * DOMParser not work for svg when has multiple root element.\n */\n if (NAMESPACE === HTML_NAMESPACE) {\n try {\n doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);\n } catch (_) {}\n }\n /* Use createHTMLDocument in case DOMParser is not available */\n if (!doc || !doc.documentElement) {\n doc = implementation.createDocument(NAMESPACE, 'template', null);\n try {\n doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;\n } catch (_) {\n // Syntax error if dirtyPayload is invalid xml\n }\n }\n const body = doc.body || doc.documentElement;\n if (dirty && leadingWhitespace) {\n body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);\n }\n /* Work on whole document or just its body */\n if (NAMESPACE === HTML_NAMESPACE) {\n return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];\n }\n return WHOLE_DOCUMENT ? doc.documentElement : body;\n };\n /**\n * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.\n *\n * @param root The root element or node to start traversing on.\n * @return The created NodeIterator\n */\n const _createNodeIterator = function _createNodeIterator(root) {\n return createNodeIterator.call(root.ownerDocument || root, root,\n // eslint-disable-next-line no-bitwise\n NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);\n };\n /**\n * _isClobbered\n *\n * @param element element to check for clobbering attacks\n * @return true if clobbered, false if safe\n */\n const _isClobbered = function _isClobbered(element) {\n return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');\n };\n /**\n * Checks whether the given object is a DOM node.\n *\n * @param value object to check whether it's a DOM node\n * @return true is object is a DOM node\n */\n const _isNode = function _isNode(value) {\n return typeof Node === 'function' && value instanceof Node;\n };\n function _executeHooks(hooks, currentNode, data) {\n arrayForEach(hooks, hook => {\n hook.call(DOMPurify, currentNode, data, CONFIG);\n });\n }\n /**\n * _sanitizeElements\n *\n * @protect nodeName\n * @protect textContent\n * @protect removeChild\n * @param currentNode to check for permission to exist\n * @return true if node was killed, false if left alive\n */\n const _sanitizeElements = function _sanitizeElements(currentNode) {\n let content = null;\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeElements, currentNode, null);\n /* Check if element is clobbered or can clobber */\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Now let's check the element's type and name */\n const tagName = transformCaseFunc(currentNode.nodeName);\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeElement, currentNode, {\n tagName,\n allowedTags: ALLOWED_TAGS\n });\n /* Detect mXSS attempts abusing namespace confusion */\n if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\\w!]/g, currentNode.textContent)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any occurrence of processing instructions */\n if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove any kind of possibly harmful comments */\n if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\\w]/g, currentNode.data)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Remove element if anything forbids its presence */\n if (!(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName])) {\n /* Check if we have a custom element to handle */\n if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {\n return false;\n }\n if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {\n return false;\n }\n }\n /* Keep content except for bad-listed elements */\n if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {\n const parentNode = getParentNode(currentNode) || currentNode.parentNode;\n const childNodes = getChildNodes(currentNode) || currentNode.childNodes;\n if (childNodes && parentNode) {\n const childCount = childNodes.length;\n for (let i = childCount - 1; i >= 0; --i) {\n const childClone = cloneNode(childNodes[i], true);\n childClone.__removalCount = (currentNode.__removalCount || 0) + 1;\n parentNode.insertBefore(childClone, getNextSibling(currentNode));\n }\n }\n }\n _forceRemove(currentNode);\n return true;\n }\n /* Check whether element has a valid namespace */\n if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Make sure that older browsers don't get fallback-tag mXSS */\n if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\\/no(script|embed|frames)/i, currentNode.innerHTML)) {\n _forceRemove(currentNode);\n return true;\n }\n /* Sanitize element content to be template-safe */\n if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {\n /* Get the element's text content */\n content = currentNode.textContent;\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n content = stringReplace(content, expr, ' ');\n });\n if (currentNode.textContent !== content) {\n arrayPush(DOMPurify.removed, {\n element: currentNode.cloneNode()\n });\n currentNode.textContent = content;\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeElements, currentNode, null);\n return false;\n };\n /**\n * _isValidAttribute\n *\n * @param lcTag Lowercase tag name of containing element.\n * @param lcName Lowercase attribute name.\n * @param value Attribute value.\n * @return Returns true if `value` is valid, otherwise false.\n */\n // eslint-disable-next-line complexity\n const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {\n /* Make sure attribute cannot clobber */\n if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {\n return false;\n }\n /* Allow valid data-* attributes: At least one character after \"-\"\n (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)\n XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)\n We don't need to check the value; it's always URI safe. */\n if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {\n if (\n // First condition does a very basic check if a) it's basically a valid custom element tagname AND\n // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck\n _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||\n // Alternative, second condition checks if it's an `is`-attribute, AND\n // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck\n lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {\n return false;\n }\n /* Check value is safe. First, is attr inert? If so, is safe */\n } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {\n return false;\n } else ;\n return true;\n };\n /**\n * _isBasicCustomElement\n * checks if at least one dash is included in tagName, and it's not the first char\n * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name\n *\n * @param tagName name of the tag of the node to sanitize\n * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.\n */\n const _isBasicCustomElement = function _isBasicCustomElement(tagName) {\n return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);\n };\n /**\n * _sanitizeAttributes\n *\n * @protect attributes\n * @protect nodeName\n * @protect removeAttribute\n * @protect setAttribute\n *\n * @param currentNode to sanitize\n */\n const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);\n const {\n attributes\n } = currentNode;\n /* Check if we have attributes; if not we might have a text node */\n if (!attributes || _isClobbered(currentNode)) {\n return;\n }\n const hookEvent = {\n attrName: '',\n attrValue: '',\n keepAttr: true,\n allowedAttributes: ALLOWED_ATTR,\n forceKeepAttr: undefined\n };\n let l = attributes.length;\n /* Go backwards over all attributes; safely remove bad ones */\n while (l--) {\n const attr = attributes[l];\n const {\n name,\n namespaceURI,\n value: attrValue\n } = attr;\n const lcName = transformCaseFunc(name);\n const initValue = attrValue;\n let value = name === 'value' ? initValue : stringTrim(initValue);\n /* Execute a hook if present */\n hookEvent.attrName = lcName;\n hookEvent.attrValue = value;\n hookEvent.keepAttr = true;\n hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set\n _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);\n value = hookEvent.attrValue;\n /* Full DOM Clobbering protection via namespace isolation,\n * Prefix id and name attributes with `user-content-`\n */\n if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {\n // Remove the attribute with this value\n _removeAttribute(name, currentNode);\n // Prefix the value and later re-create the attribute with the sanitized value\n value = SANITIZE_NAMED_PROPS_PREFIX + value;\n }\n /* Work around a security issue with comments inside attributes */\n if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\\/(style|title|textarea)/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Make sure we cannot easily use animated hrefs, even if animations are allowed */\n if (lcName === 'attributename' && stringMatch(value, 'href')) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (hookEvent.forceKeepAttr) {\n continue;\n }\n /* Did the hooks approve of the attribute? */\n if (!hookEvent.keepAttr) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Work around a security issue in jQuery 3.0 */\n if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\\/>/i, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Sanitize attribute content to be template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n value = stringReplace(value, expr, ' ');\n });\n }\n /* Is `value` valid for this attribute? */\n const lcTag = transformCaseFunc(currentNode.nodeName);\n if (!_isValidAttribute(lcTag, lcName, value)) {\n _removeAttribute(name, currentNode);\n continue;\n }\n /* Handle attributes that require Trusted Types */\n if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {\n if (namespaceURI) ; else {\n switch (trustedTypes.getAttributeType(lcTag, lcName)) {\n case 'TrustedHTML':\n {\n value = trustedTypesPolicy.createHTML(value);\n break;\n }\n case 'TrustedScriptURL':\n {\n value = trustedTypesPolicy.createScriptURL(value);\n break;\n }\n }\n }\n }\n /* Handle invalid data-* attribute set by try-catching it */\n if (value !== initValue) {\n try {\n if (namespaceURI) {\n currentNode.setAttributeNS(namespaceURI, name, value);\n } else {\n /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. \"x-schema\". */\n currentNode.setAttribute(name, value);\n }\n if (_isClobbered(currentNode)) {\n _forceRemove(currentNode);\n } else {\n arrayPop(DOMPurify.removed);\n }\n } catch (_) {\n _removeAttribute(name, currentNode);\n }\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);\n };\n /**\n * _sanitizeShadowDOM\n *\n * @param fragment to iterate over recursively\n */\n const _sanitizeShadowDOM = function _sanitizeShadowDOM(fragment) {\n let shadowNode = null;\n const shadowIterator = _createNodeIterator(fragment);\n /* Execute a hook if present */\n _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);\n while (shadowNode = shadowIterator.nextNode()) {\n /* Execute a hook if present */\n _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);\n /* Sanitize tags and elements */\n _sanitizeElements(shadowNode);\n /* Check attributes next */\n _sanitizeAttributes(shadowNode);\n /* Deep shadow DOM detected */\n if (shadowNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(shadowNode.content);\n }\n }\n /* Execute a hook if present */\n _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);\n };\n // eslint-disable-next-line complexity\n DOMPurify.sanitize = function (dirty) {\n let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};\n let body = null;\n let importedNode = null;\n let currentNode = null;\n let returnNode = null;\n /* Make sure we have a string to sanitize.\n DO NOT return early, as this will return the wrong type if\n the user has requested a DOM object rather than a string */\n IS_EMPTY_INPUT = !dirty;\n if (IS_EMPTY_INPUT) {\n dirty = '';\n }\n /* Stringify, in case dirty is an object */\n if (typeof dirty !== 'string' && !_isNode(dirty)) {\n if (typeof dirty.toString === 'function') {\n dirty = dirty.toString();\n if (typeof dirty !== 'string') {\n throw typeErrorCreate('dirty is not a string, aborting');\n }\n } else {\n throw typeErrorCreate('toString is not a function');\n }\n }\n /* Return dirty HTML if DOMPurify cannot run */\n if (!DOMPurify.isSupported) {\n return dirty;\n }\n /* Assign config vars */\n if (!SET_CONFIG) {\n _parseConfig(cfg);\n }\n /* Clean up removed elements */\n DOMPurify.removed = [];\n /* Check if dirty is correctly typed for IN_PLACE */\n if (typeof dirty === 'string') {\n IN_PLACE = false;\n }\n if (IN_PLACE) {\n /* Do some early pre-sanitization to avoid unsafe root nodes */\n if (dirty.nodeName) {\n const tagName = transformCaseFunc(dirty.nodeName);\n if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {\n throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');\n }\n }\n } else if (dirty instanceof Node) {\n /* If dirty is a DOM element, append to an empty document to avoid\n elements being stripped by the parser */\n body = _initDocument('');\n importedNode = body.ownerDocument.importNode(dirty, true);\n if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {\n /* Node is already a body, use as is */\n body = importedNode;\n } else if (importedNode.nodeName === 'HTML') {\n body = importedNode;\n } else {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n body.appendChild(importedNode);\n }\n } else {\n /* Exit directly if we have nothing to do */\n if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&\n // eslint-disable-next-line unicorn/prefer-includes\n dirty.indexOf('<') === -1) {\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;\n }\n /* Initialize the document to work on */\n body = _initDocument(dirty);\n /* Check we have a DOM node from the data */\n if (!body) {\n return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';\n }\n }\n /* Remove first element node (ours) if FORCE_BODY is set */\n if (body && FORCE_BODY) {\n _forceRemove(body.firstChild);\n }\n /* Get node iterator */\n const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);\n /* Now start iterating over the created document */\n while (currentNode = nodeIterator.nextNode()) {\n /* Sanitize tags and elements */\n _sanitizeElements(currentNode);\n /* Check attributes next */\n _sanitizeAttributes(currentNode);\n /* Shadow DOM detected, sanitize it */\n if (currentNode.content instanceof DocumentFragment) {\n _sanitizeShadowDOM(currentNode.content);\n }\n }\n /* If we sanitized `dirty` in-place, return it. */\n if (IN_PLACE) {\n return dirty;\n }\n /* Return sanitized string or DOM */\n if (RETURN_DOM) {\n if (RETURN_DOM_FRAGMENT) {\n returnNode = createDocumentFragment.call(body.ownerDocument);\n while (body.firstChild) {\n // eslint-disable-next-line unicorn/prefer-dom-node-append\n returnNode.appendChild(body.firstChild);\n }\n } else {\n returnNode = body;\n }\n if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {\n /*\n AdoptNode() is not used because internal state is not reset\n (e.g. the past names map of a HTMLFormElement), this is safe\n in theory but we would rather not risk another attack vector.\n The state that is cloned by importNode() is explicitly defined\n by the specs.\n */\n returnNode = importNode.call(originalDocument, returnNode, true);\n }\n return returnNode;\n }\n let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;\n /* Serialize doctype if allowed */\n if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {\n serializedHTML = '\\n' + serializedHTML;\n }\n /* Sanitize final string template-safe */\n if (SAFE_FOR_TEMPLATES) {\n arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {\n serializedHTML = stringReplace(serializedHTML, expr, ' ');\n });\n }\n return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;\n };\n DOMPurify.setConfig = function () {\n let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};\n _parseConfig(cfg);\n SET_CONFIG = true;\n };\n DOMPurify.clearConfig = function () {\n CONFIG = null;\n SET_CONFIG = false;\n };\n DOMPurify.isValidAttribute = function (tag, attr, value) {\n /* Initialize shared config vars if necessary. */\n if (!CONFIG) {\n _parseConfig({});\n }\n const lcTag = transformCaseFunc(tag);\n const lcName = transformCaseFunc(attr);\n return _isValidAttribute(lcTag, lcName, value);\n };\n DOMPurify.addHook = function (entryPoint, hookFunction) {\n if (typeof hookFunction !== 'function') {\n return;\n }\n arrayPush(hooks[entryPoint], hookFunction);\n };\n DOMPurify.removeHook = function (entryPoint, hookFunction) {\n if (hookFunction !== undefined) {\n const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);\n return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];\n }\n return arrayPop(hooks[entryPoint]);\n };\n DOMPurify.removeHooks = function (entryPoint) {\n hooks[entryPoint] = [];\n };\n DOMPurify.removeAllHooks = function () {\n hooks = _createHooksMap();\n };\n return DOMPurify;\n}\nvar purify = createDOMPurify();\n\nexport { purify as default };\n//# sourceMappingURL=purify.es.mjs.map\n","/**\n * This class represents all the constants needed in a MathType integration among different classes.\n * If a constant should be used across different classes should be defined using attribute\n * accessors.\n */\nexport default class Constants {\n /**\n * Safe XML entities.\n * @type {Object}\n */\n static get safeXmlCharactersEntities() {\n return {\n tagOpener: \"«\",\n tagCloser: \"»\",\n doubleQuote: \"¨\",\n realDoubleQuote: \""\",\n };\n }\n\n /**\n * Blackboard invalid safe characters.\n * @type {Object}\n */\n static get safeBadBlackboardCharacters() {\n return {\n ltElement: \"«mo»<«/mo»\",\n gtElement: \"«mo»>«/mo»\",\n ampElement: \"«mo»&«/mo»\",\n };\n }\n\n /**\n * Blackboard valid safe characters.\n * @type{Object}\n */\n static get safeGoodBlackboardCharacters() {\n return {\n ltElement: \"«mo»§lt;«/mo»\",\n gtElement: \"«mo»§gt;«/mo»\",\n ampElement: \"«mo»§amp;«/mo»\",\n };\n }\n\n /**\n * Standard XML special characters.\n * @type {Object}\n */\n static get xmlCharacters() {\n return {\n id: \"xmlCharacters\",\n tagOpener: \"<\", // Hex: \\x3C.\n tagCloser: \">\", // Hex: \\x3E.\n doubleQuote: '\"', // Hex: \\x22.\n ampersand: \"&\", // Hex: \\x26.\n quote: \"'\", // Hex: \\x27.\n };\n }\n\n /**\n * Safe XML special characters. This characters are used instead the standard\n * the standard to parse the MathML if safeXML save mode is enable. Each XML\n * special character have a UTF-8 representation.\n * @type {Object}\n */\n static get safeXmlCharacters() {\n return {\n id: \"safeXmlCharacters\",\n tagOpener: \"«\", // Hex: \\xAB.\n tagCloser: \"»\", // Hex: \\xBB.\n doubleQuote: \"¨\", // Hex: \\xA8.\n ampersand: \"§\", // Hex: \\xA7.\n quote: \"`\", // Hex: \\x60.\n realDoubleQuote: \"¨\",\n };\n }\n}\n","import Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a class to manage MathML objects.\n */\nexport default class MathML {\n /**\n * Checks if the mathml at position i is inside an HTML attribute or not.\n * @param {string} content - a string containing MathML code.\n * @param {number} i - search index.\n * @return {boolean} true if is inside an HTML attribute. false otherwise.\n */\n static isMathmlInAttribute(content, i) {\n // Regex =\n // '^[\\'\"][\\\\s]*=[\\\\s]*[\\\\w-]+([\\\\s]*(\"[^\"]*\"|\\'[^\\']*\\')[\\\\s]*\n // =[\\\\s]*[\\\\w-]+[\\\\s]*)*[\\\\s]+gmi<';\n const mathAtt = \"['\\\"][\\\\s]*=[\\\\s]*[\\\\w-]+\"; // \"=att OR '=att\n const attContent = \"\\\"[^\\\"]*\\\"|'[^']*'\"; // \"blabla\" OR 'blabla'\n const att = `[\\\\s]*(${attContent})[\\\\s]*=[\\\\s]*[\\\\w-]+[\\\\s]*`; // \"blabla\"=att OR 'blabla'=att\n const atts = `('${att}')*`; // \"blabla\"=att1 \"blabla\"=att2\n const regex = `^${mathAtt}${atts}[\\\\s]+gmi<`; // \"=att \"blabla\"=att1 \"blabla\"=att2 gmi< .\n const expression = new RegExp(regex);\n\n const actualContent = content.substring(0, i);\n const reversed = actualContent.split(\"\").reverse().join(\"\");\n const exists = expression.test(reversed);\n\n return exists;\n }\n\n /**\n * Decodes an encoded MathML with standard XML tags.\n * We use these entities because IE doesn't support html entities\n * on its attributes sometimes. Yes, sometimes.\n * @param {string} input - string to be decoded.\n * @return {string} decoded string.\n */\n static safeXmlDecode(input) {\n let { tagOpener } = Constants.safeXmlCharactersEntities;\n let { tagCloser } = Constants.safeXmlCharactersEntities;\n let { doubleQuote } = Constants.safeXmlCharactersEntities;\n let { realDoubleQuote } = Constants.safeXmlCharactersEntities;\n // Decoding entities.\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n // Added to fix problem due to import from 1.9.x.\n input = input.split(realDoubleQuote).join(Constants.safeXmlCharacters.realDoubleQuote);\n\n // Blackboard.\n const { ltElement } = Constants.safeBadBlackboardCharacters;\n const { gtElement } = Constants.safeBadBlackboardCharacters;\n const { ampElement } = Constants.safeBadBlackboardCharacters;\n if (\"_wrs_blackboard\" in window && window._wrs_blackboard) {\n input = input.split(ltElement).join(Constants.safeGoodBlackboardCharacters.ltElement);\n input = input.split(gtElement).join(Constants.safeGoodBlackboardCharacters.gtElement);\n input = input.split(ampElement).join(Constants.safeGoodBlackboardCharacters.ampElement);\n }\n\n ({ tagOpener } = Constants.safeXmlCharacters);\n ({ tagCloser } = Constants.safeXmlCharacters);\n ({ doubleQuote } = Constants.safeXmlCharacters);\n ({ realDoubleQuote } = Constants.safeXmlCharacters);\n const { ampersand } = Constants.safeXmlCharacters;\n const { quote } = Constants.safeXmlCharacters;\n\n // Decoding characters.\n input = input.split(tagOpener).join(Constants.xmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.xmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.xmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.xmlCharacters.ampersand);\n input = input.split(quote).join(Constants.xmlCharacters.quote);\n\n // We are replacing $ by & when its part of an entity for retro-compatibility.\n // Now, the standard is replace § by &.\n let returnValue = \"\";\n let currentEntity = null;\n\n for (let i = 0; i < input.length; i += 1) {\n const character = input.charAt(i);\n if (currentEntity == null) {\n if (character === \"$\") {\n currentEntity = \"\";\n } else {\n returnValue += character;\n }\n } else if (character === \";\") {\n returnValue += `&${currentEntity}`;\n currentEntity = null;\n } else if (character.match(/([a-zA-Z0-9#._-] | '-')/)) {\n // Character is part of an entity.\n currentEntity += character;\n } else {\n returnValue += `$${currentEntity}`; // Is not an entity.\n currentEntity = null;\n i -= 1; // Parse again the current character.\n }\n }\n\n return returnValue;\n }\n\n /**\n * Encodes a MathML with standard XML tags to a MMathML encoded with safe XML tags.\n * We use these entities because IE doesn't support html entities on its attributes sometimes.\n * @param {string} input - input string to be encoded\n * @returns {string} encoded string.\n */\n static safeXmlEncode(input) {\n const { tagOpener } = Constants.xmlCharacters;\n const { tagCloser } = Constants.xmlCharacters;\n const { doubleQuote } = Constants.xmlCharacters;\n const { ampersand } = Constants.xmlCharacters;\n const { quote } = Constants.xmlCharacters;\n\n input = input.split(tagOpener).join(Constants.safeXmlCharacters.tagOpener);\n input = input.split(tagCloser).join(Constants.safeXmlCharacters.tagCloser);\n input = input.split(doubleQuote).join(Constants.safeXmlCharacters.doubleQuote);\n input = input.split(ampersand).join(Constants.safeXmlCharacters.ampersand);\n input = input.split(quote).join(Constants.safeXmlCharacters.quote);\n\n return input;\n }\n\n /**\n * Converts special symbols (> 128) to entities and replaces all textual\n * entities by its number entities.\n * @param {string} mathml - MathML string containing - or not - special symbols\n * @returns {string} MathML with all textual entities replaced.\n */\n static mathMLEntities(mathml) {\n let toReturn = \"\";\n\n for (let i = 0; i < mathml.length; i += 1) {\n const character = mathml.charAt(i);\n\n // Parsing > 128 characters.\n if (mathml.codePointAt(i) > 128) {\n toReturn += `&#${mathml.codePointAt(i)};`;\n // For UTF-32 characters we need to move the index one position.\n if (mathml.codePointAt(i) > 0xffff) {\n i += 1;\n }\n } else if (character === \"&\") {\n const end = mathml.indexOf(\";\", i + 1);\n if (end >= 0) {\n const container = document.createElement(\"span\");\n container.innerHTML = mathml.substring(i, end + 1);\n toReturn += `&#${Util.fixedCharCodeAt(container.textContent || container.innerText, 0)};`;\n i = end;\n } else {\n toReturn += character;\n }\n } else {\n toReturn += character;\n }\n }\n\n return toReturn;\n }\n\n /**\n * Add a custom editor name with the prefix wrs_ to a MathML class attribute.\n * @param {string} mathml - a MathML string created with a custom editor, like chemistry.\n * @param {string} customEditor - custom editor name.\n * @returns {string} MathML string with his class containing the editor toolbar string.\n */\n static addCustomEditorClassAttribute(mathml, customEditor) {\n let toReturn = \"\";\n\n const start = mathml.indexOf(\"\");\n if (mathml.indexOf(\"class\") === -1) {\n // Adding custom editor type.\n toReturn = `${mathml.substr(start, end)} class=\"wrs_${customEditor}\">`;\n toReturn += mathml.substr(end + 1, mathml.length);\n return toReturn;\n }\n }\n return mathml;\n }\n\n /**\n * Remove a custom editor name from the MathML class attribute.\n * @param {string} mathml - a MathML string.\n * @param {string} customEditor - custom editor name.\n * @returns {string} The input MathML without customEditor name in his class.\n */\n static removeCustomEditorClassAttribute(mathml, customEditor) {\n // Discard MathML without the specified class.\n if (mathml.indexOf(\"class\") === -1 || mathml.indexOf(`wrs_${customEditor}`) === -1) {\n return mathml;\n }\n\n // Trivial case: class attribute value equal to editor name. Then\n // class attribute is removed.\n // First try to remove it with a space before if there is one\n // Otherwise without the space\n if (mathml.indexOf(` class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(` class=\"wrs_${customEditor}\"`, \"\");\n }\n if (mathml.indexOf(`class=\"wrs_${customEditor}\"`) !== -1) {\n return mathml.replace(`class=\"wrs_${customEditor}\"`, \"\");\n }\n\n // Non Trivial case: class attribute contains editor name.\n return mathml.replace(`wrs_${customEditor}`, \"\");\n }\n\n /**\n * Adds annotation tag in MathML element.\n * @param {String} mathml - valid MathML.\n * @param {String} content - value to put inside annotation tag.\n * @param {String} annotationEncoding - annotation encoding.\n * @returns {String} - 'mathml' with an annotation that contains\n * 'content' and encoding 'encoding'.\n */\n static addAnnotation(mathml, content, annotationEncoding) {\n // If contains annotation, also contains semantics tag.\n const containsAnnotation = mathml.indexOf(\"\");\n mathmlWithAnnotation = `${mathml.substring(0, closeSemanticsIndex)}${content}${mathml.substring(closeSemanticsIndex)}`;\n } else if (MathML.isEmpty(mathml)) {\n const endIndexInline = mathml.indexOf(\"/>\");\n const endIndexNonInline = mathml.indexOf(\">\");\n const endIndex = endIndexNonInline === endIndexInline ? endIndexInline : endIndexNonInline;\n mathmlWithAnnotation = `${mathml.substring(0, endIndex)}>${content}`;\n } else {\n const beginMathMLContent = mathml.indexOf(\">\") + 1;\n const endMathmlContent = mathml.lastIndexOf(\"\");\n const mathmlContent = mathml.substring(beginMathMLContent, endMathmlContent);\n mathmlWithAnnotation = `${mathml.substring(0, beginMathMLContent)}${mathmlContent}${content}`; // eslint-disable-line max-len\n }\n\n return mathmlWithAnnotation;\n }\n\n /**\n * Removes specific annotation tag in MathML element.\n * In case of remove the unique annotation, also is removed semantics tag.\n * @param {String} mathml - valid MathML.\n * @param {String} annotationEncoding - annotation encoding to remove.\n * @returns {String} - 'mathml' without the annotation encoding specified.\n */\n static removeAnnotation(mathml, annotationEncoding) {\n let mathmlWithoutAnnotation = mathml;\n const openAnnotationTag = ``;\n const closeAnnotationTag = \"\";\n const startAnnotationIndex = mathml.indexOf(openAnnotationTag);\n if (startAnnotationIndex !== -1) {\n let differentAnnotationFound = false;\n let differentAnnotationIndex = mathml.indexOf(\"\\s*?()?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsEndingTagRegex = /(<\\/mrow>)?\\s*/gm;\n\n return mathml.replace(semanticsStartingTagRegex, \"\").replace(semanticsEndingTagRegex, \"\");\n }\n\n /**\n * Removes semantics tag to element that contains mathml.\n * When using Hand to create formulas, it adds the mrow tag due to the semantics one, this one is also removed.\n * @param {string} element - Inner HTML text string.\n * @returns {string} - 'mathml' without semantics tag.\n */\n static removeSafeXMLSemantics(element) {\n // If `mrow` is found right before the `semantics` starting tag, it's removed as well\n const semanticsSafeStartingTagRegex = /«semantics»\\s*?(«mrow»)?/gm;\n\n // If `mrow` is found right after the `annotation` ending tag, it's removed as well\n // alongside `semantics` closing tag and the whole `annotation` tag and its contents.\n const semanticsSafeEndingTagRegex = /(«\\/mrow»)?\\s*«annotation[\\W\\w]*?«\\/semantics»/gm;\n\n return element.replace(semanticsSafeStartingTagRegex, \"\").replace(semanticsSafeEndingTagRegex, \"\");\n }\n\n /**\n * Transforms all xml mathml occurrences that contain semantics to the same\n * xml mathml occurrences without semantics.\n * @param {string} text - string that can contain xml mathml occurrences.\n * @param {Constants} [characters] - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * xmlCharacters by default.\n * @returns {string} - 'text' with all xml mathml occurrences without annotation tag.\n */\n static removeSemanticsOcurrences(text, characters = Constants.xmlCharacters) {\n const mathTagStart = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const mathTagEndline = `/${characters.tagCloser}`;\n const { tagCloser } = characters;\n const semanticsTagStart = `${characters.tagOpener}semantics${characters.tagCloser}`;\n const annotationTagStart = `${characters.tagOpener}annotation encoding=`;\n\n let output = \"\";\n let start = text.indexOf(mathTagStart);\n let end = 0;\n while (start !== -1) {\n output += text.substring(end, start);\n\n // MathML can be written as '' or ''.\n const mathTagEndIndex = text.indexOf(mathTagEnd, start);\n const mathTagEndlineIndex = text.indexOf(mathTagEndline, start);\n const firstTagCloser = text.indexOf(tagCloser, start);\n if (mathTagEndIndex !== -1) {\n end = mathTagEndIndex;\n } else if (mathTagEndlineIndex === firstTagCloser - 1) {\n end = mathTagEndlineIndex;\n }\n\n const semanticsIndex = text.indexOf(semanticsTagStart, start);\n if (semanticsIndex !== -1) {\n const mmlTagStart = text.substring(start, semanticsIndex);\n const annotationIndex = text.indexOf(annotationTagStart, start);\n if (annotationIndex !== -1) {\n const startIndex = semanticsIndex + semanticsTagStart.length;\n const mmlContent = text.substring(startIndex, annotationIndex);\n output += mmlTagStart + mmlContent + mathTagEnd;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n end += mathTagEnd.length;\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n } else {\n end = start;\n start = text.indexOf(mathTagStart, start + mathTagStart.length);\n }\n }\n\n output += text.substring(end, text.length);\n return output;\n }\n\n /**\n * Returns true if a MathML contains a certain class.\n * @param {string} mathML - input MathML.\n * @param {string} className - className.\n * @returns {boolean} true if the input MathML contains the input class.\n * false otherwise.\n * @static\n */\n static containClass(mathML, className) {\n const classIndex = mathML.indexOf(\"class\");\n if (classIndex === -1) {\n return false;\n }\n const classTagEndIndex = mathML.indexOf(\">\", classIndex);\n const classTag = mathML.substring(classIndex, classTagEndIndex);\n if (classTag.indexOf(className) !== -1) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns true if mathml is empty. Otherwise, false.\n * @param {string} mathml - valid MathML with standard XML tags.\n * @returns {boolean} - true if mathml is empty. Otherwise, false.\n */\n static isEmpty(mathml) {\n // MathML can have the shape or ''.\n const closeTag = \">\";\n const closeTagInline = \"/>\";\n const firstCloseTagIndex = mathml.indexOf(closeTag);\n const firstCloseTagInlineIndex = mathml.indexOf(closeTagInline);\n let empty = false;\n // MathML is always empty in the second shape.\n if (firstCloseTagInlineIndex !== -1) {\n if (firstCloseTagInlineIndex === firstCloseTagIndex - 1) {\n empty = true;\n }\n }\n\n // MathML is always empty in the first shape when there aren't elements\n // between math tags.\n if (!empty) {\n const mathTagEndRegex = new RegExp(\"\");\n const mathTagEndArray = mathTagEndRegex.exec(mathml);\n if (mathTagEndArray) {\n empty = firstCloseTagIndex + 1 === mathTagEndArray.index;\n }\n }\n\n return empty;\n }\n\n /**\n * Encodes html entities inside properties.\n * @param {String} mathml - valid MathML with standard XML tags.\n * @returns {String} - 'mathml' with property entities encoded.\n */\n static encodeProperties(mathml) {\n // Search all the properties.\n const regex = /\\w+=\".*?\"/g;\n // Encode html entities.\n const replacer = (match) => {\n // It has the shape:\n // .\n const quoteIndex = match.indexOf('\"');\n const propertyValue = match.substring(quoteIndex + 1, match.length - 1);\n const propertyValueEncoded = Util.htmlEntities(propertyValue);\n const matchEncoded = `${match.substring(0, quoteIndex + 1)}${propertyValueEncoded}\"`;\n return matchEncoded;\n };\n\n const mathmlEncoded = mathml.replace(regex, replacer);\n return mathmlEncoded;\n }\n}\n","/**\n * This class represents the configuration class.\n * Usually used to retrieve configuration properties generated in the backend into the frontend.\n */\nexport default class Configuration {\n /**\n * Adds a properties object to {@link Configuration.properties}.\n * @param {Object} properties - properties to append to current properties.\n */\n static addConfiguration(properties) {\n Object.assign(Configuration.properties, properties);\n }\n\n /**\n * Static property.\n * The configuration properties object.\n * @private\n * @type {Object}\n */\n static get properties() {\n return Configuration._properties;\n }\n\n /**\n * Static property setter.\n * Set configuration properties.\n * @param {Object} value - The property value.\n * @ignore\n */\n static set properties(value) {\n Configuration._properties = value;\n }\n\n /**\n * Returns the value of a property key.\n * @param {String} key - Property key\n * @returns {String} Property value\n */\n static get(key) {\n if (!Object.prototype.hasOwnProperty.call(Configuration.properties, key)) {\n // Backwards compatibility.\n if (Object.prototype.hasOwnProperty.call(Configuration.properties, \"_wrs_conf_\")) {\n return Configuration.properties[`_wrs_conf_${key}`];\n }\n return false;\n }\n return Configuration.properties[key];\n }\n\n /**\n * Adds a new property to Configuration class.\n * @param {String} key - Property key.\n * @param {Object} value - Property value.\n */\n static set(key, value) {\n Configuration.properties[key] = value;\n }\n\n /**\n * Updates a property object value with new values.\n * @param {String} key - The property key to be updated.\n * @param {Object} propertyValue - Object containing the new values.\n */\n static update(key, propertyValue) {\n if (!Configuration.get(key)) {\n Configuration.set(key, propertyValue);\n } else {\n const updateProperty = Object.assign(Configuration.get(key), propertyValue);\n Configuration.set(key, updateProperty);\n }\n }\n}\n\n/**\n * Static properties object. Stores all configuration properties.\n * Needed to attribute accessors.\n * @private\n * @type {Object}\n */\nConfiguration._properties = {};\n","export default class TextCache {\n /**\n * @classdesc\n * This class represent a client-side text cache class. Contains pairs of\n * strings (key/value) which can be retrieved in any moment. Usually used\n * to store AJAX responses for text services like mathml2latex\n * (c.f {@link Latex} class) or mathml2accessible (c.f {@link Accessibility} class).\n * @constructs\n */\n constructor() {\n /**\n * Cache array property storing the cache entries.\n * @type {Array.}\n */\n this.cache = [];\n }\n\n /**\n * This method populates a key/value pair into the {@link this.cache} property.\n * @param {String} key - Cache key, usually the service string parameter.\n * @param {String} value - Cache value, usually the service response.\n */\n populate(key, value) {\n this.cache[key] = value;\n }\n\n /**\n * Returns the cache value associated to certain cache key.\n * @param {String} key - Cache key, usually the service string parameter.\n * @return {String} value - Cache value, if exists. False otherwise.\n */\n get(key) {\n if (Object.prototype.hasOwnProperty.call(this.cache, key)) {\n return this.cache[key];\n }\n return false;\n }\n}\n","/**\n * This object represents a custom listener.\n * @typedef {Object} Listener\n * @property {String} Listener.eventName - The listener name.\n * @property {Function} Listener.callback - The listener callback function.\n */\n\nexport default class Listeners {\n /**\n * @classdesc\n * This class represents a custom listeners manager.\n * @constructs\n */\n constructor() {\n /**\n * Array containing all custom listeners.\n * @type {Object[]}\n */\n this.listeners = [];\n }\n\n /**\n * Add a listener to Listener class.\n * @param {Object} listener - A listener object.\n */\n add(listener) {\n this.listeners.push(listener);\n }\n\n /**\n * Fires MathType event listeners\n * @param {String} eventName - event name\n * @param {Event} event - event object.\n * @return {boolean} false if event has been prevented. true otherwise.\n */\n fire(eventName, event) {\n for (let i = 0; i < this.listeners.length && !event.cancelled; i += 1) {\n if (this.listeners[i].eventName === eventName) {\n // Calling listener.\n this.listeners[i].callback(event);\n }\n }\n return event.defaultPrevented;\n }\n\n /**\n * Creates a new listener object.\n * @param {string} eventName - Event name.\n * @param {Object} callback - Callback function.\n * @returns {object} the listener object.\n */\n static newListener(eventName, callback) {\n const listener = {};\n listener.eventName = eventName;\n listener.callback = callback;\n return listener;\n }\n}\n","import Util from \"./util\";\nimport Listeners from \"./listeners\";\nimport Configuration from \"./configuration\";\n\n/**\n * @typedef {Object} ServiceProviderProperties\n * @property {String} URI - Service URI.\n * @property {String} server - Service server language.\n */\n\n/**\n * @classdesc\n * Class representing a serviceProvider. A serviceProvider is a class containing\n * an arbitrary number of services with the correspondent path.\n */\nexport default class ServiceProvider {\n /**\n * Returns Service Provider listeners.\n * @type {Listeners}\n */\n static get listeners() {\n return ServiceProvider._listeners;\n }\n\n /**\n * Adds a {@link Listener} instance to {@link ServiceProvider} class.\n * @param {Listener} listener - Instance of {@link Listener}.\n */\n static addListener(listener) {\n ServiceProvider.listeners.add(listener);\n }\n\n /**\n * Fires events in Service Provider.\n * @param {String} eventName - Event name.\n * @param {Event} event - Event object.\n */\n static fireEvent(eventName, event) {\n ServiceProvider.listeners.fire(eventName, event);\n }\n\n /**\n * Service parameters.\n * @type {ServiceProviderProperties}\n *\n */\n static get parameters() {\n return ServiceProvider._parameters;\n }\n\n /**\n * Service parameters.\n * @private\n * @type {ServiceProviderProperties}\n */\n static set parameters(parameters) {\n ServiceProvider._parameters = parameters;\n }\n\n /**\n * Static property.\n * Return service provider paths.\n * @private\n * @type {String}\n */\n static get servicePaths() {\n return ServiceProvider._servicePaths;\n }\n\n /**\n * Static property setter.\n * Set service paths.\n * @param {String} value - The property value.\n * @ignore\n */\n static set servicePaths(value) {\n ServiceProvider._servicePaths = value;\n }\n\n /**\n * Adds a new service to the ServiceProvider.\n * @param {String} service - Service name.\n * @param {String} path - Service path.\n * @static\n */\n static setServicePath(service, path) {\n ServiceProvider.servicePaths[service] = path;\n }\n\n /**\n * Returns the service path for a certain service.\n * @param {String} serviceName - Service name.\n * @returns {String} The service path.\n * @static\n */\n static getServicePath(serviceName) {\n return ServiceProvider.servicePaths[serviceName];\n }\n\n /**\n * Static property.\n * Service provider integration path.\n * @type {String}\n */\n static get integrationPath() {\n return ServiceProvider._integrationPath;\n }\n\n /**\n * Static property setter.\n * Set service provider integration path.\n * @param {String} value - The property value.\n * @ignore\n */\n static set integrationPath(value) {\n ServiceProvider._integrationPath = value;\n }\n\n /**\n * Returns the server URL in the form protocol://serverName:serverPort.\n * @return {String} The client side server path.\n */\n static getServerURL() {\n const url = window.location.href;\n const arr = url.split(\"/\");\n const result = `${arr[0]}//${arr[2]}`;\n return result;\n }\n\n /**\n * Inits {@link this} class. Uses {@link this.integrationPath} as\n * base path to generate all backend services paths.\n * @param {Object} parameters - Function parameters.\n * @param {String} parameters.integrationPath - Service path.\n */\n static init(parameters) {\n ServiceProvider.parameters = parameters;\n // Services path (tech dependant).\n let configurationURI = ServiceProvider.createServiceURI(\"configurationjs\");\n let createImageURI = ServiceProvider.createServiceURI(\"createimage\");\n let showImageURI = ServiceProvider.createServiceURI(\"showimage\");\n let getMathMLURI = ServiceProvider.createServiceURI(\"getmathml\");\n let serviceURI = ServiceProvider.createServiceURI(\"service\");\n\n // Some backend integrations (like Java o Ruby) have an absolute backend path,\n // for example: /app/service. For them we calculate the absolute URL path, i.e\n // protocol://domain:port/app/service\n if (ServiceProvider.parameters.URI.indexOf(\"/\") === 0) {\n const serverPath = ServiceProvider.getServerURL();\n configurationURI = serverPath + configurationURI;\n showImageURI = serverPath + showImageURI;\n createImageURI = serverPath + createImageURI;\n getMathMLURI = serverPath + getMathMLURI;\n serviceURI = serverPath + serviceURI;\n }\n\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n ServiceProvider.setServicePath(\"showimage\", showImageURI);\n ServiceProvider.setServicePath(\"createimage\", createImageURI);\n ServiceProvider.setServicePath(\"service\", serviceURI);\n ServiceProvider.setServicePath(\"getmathml\", getMathMLURI);\n ServiceProvider.setServicePath(\"configurationjs\", configurationURI);\n\n ServiceProvider.listeners.fire(\"onInit\", {});\n }\n\n /**\n * Gets the content from an URL.\n * @param {String} url - Target URL.\n * @param {Object} [postVariables] - Object containing post variables.\n * null if a GET query should be done.\n * @returns {String} Content of the target URL.\n * @private\n * @static\n */\n static getUrl(url, postVariables) {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n const httpRequest = Util.createHttpRequest();\n\n if (httpRequest) {\n if (typeof postVariables === \"undefined\" || typeof postVariables === \"undefined\") {\n httpRequest.open(\"GET\", url, false);\n } else if (url.substr(0, 1) === \"/\" || url.substr(0, 7) === \"http://\" || url.substr(0, 8) === \"https://\") {\n httpRequest.open(\"POST\", url, false);\n } else {\n httpRequest.open(\"POST\", currentPath + url, false);\n }\n\n let header = Configuration.get(\"customHeaders\");\n if (header) {\n if (typeof header === \"string\") {\n header = Util.convertStringToObject(header);\n }\n Object.entries(header).forEach(([key, val]) => httpRequest.setRequestHeader(key, val));\n }\n\n if (typeof postVariables !== \"undefined\" && postVariables) {\n httpRequest.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded; charset=UTF-8\");\n httpRequest.send(Util.httpBuildQuery(postVariables));\n } else {\n httpRequest.send(null);\n }\n\n return httpRequest.responseText;\n }\n return \"\";\n }\n\n /**\n * Returns the response text of a certain service.\n * @param {String} service - Service name.\n * @param {String} postVariables - Post variables.\n * @param {Boolean} get - True if the request is GET instead of POST. false otherwise.\n * @returns {String} Service response text.\n */\n static getService(service, postVariables, get) {\n let response;\n if (get === true) {\n const getVariables = postVariables ? `?${postVariables}` : \"\";\n const serviceUrl = `${ServiceProvider.getServicePath(service)}${getVariables}`;\n response = ServiceProvider.getUrl(serviceUrl);\n } else {\n const serviceUrl = ServiceProvider.getServicePath(service);\n response = ServiceProvider.getUrl(serviceUrl, postVariables);\n }\n return response;\n }\n\n /**\n * Returns the server language of a certain service. The possible values\n * are: php, aspx, java and ruby.\n * This method has backward compatibility purposes.\n * @param {String} service - The configuration service.\n * @returns {String} - The server technology associated with the configuration service.\n */\n static getServerLanguageFromService(service) {\n if (service.indexOf(\".php\") !== -1) {\n return \"php\";\n }\n if (service.indexOf(\".aspx\") !== -1) {\n return \"aspx\";\n }\n if (service.indexOf(\"wirispluginengine\") !== -1) {\n return \"ruby\";\n }\n return \"java\";\n }\n\n /**\n * Returns the URI associated with a certain service.\n * @param {String} service - The service name.\n * @return {String} The service path.\n */\n static createServiceURI(service) {\n const extension = ServiceProvider.serverExtension();\n return Util.concatenateUrl(ServiceProvider.parameters.URI, service) + extension;\n }\n\n static serverExtension() {\n if (ServiceProvider.parameters.server.indexOf(\"php\") !== -1) {\n return \".php\";\n }\n if (ServiceProvider.parameters.server.indexOf(\"aspx\") !== -1) {\n return \".aspx\";\n }\n return \"\";\n }\n}\n\n/**\n * @property {String} service - The service name.\n * @property {String} path - The service path.\n * @static\n */\nServiceProvider._servicePaths = {};\n\n/**\n * The integration path. Contains the path of the configuration service.\n * Used to define the path for all services.\n * @type {String}\n * @private\n */\nServiceProvider._integrationPath = \"\";\n\n/**\n * ServiceProvider static listeners.\n * @type {Listeners}\n * @private\n */\nServiceProvider._listeners = new Listeners();\n\n/**\n * Service provider parameters.\n * @type {ServiceProviderParameters}\n */\nServiceProvider._parameters = {};\n","import TextCache from \"./textcache\";\nimport MathML from \"./mathml\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Constants from \"./constants\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents a LaTeX parser. Manages the services which allows to convert\n * LaTeX into MathML and MathML into LaTeX.\n */\nexport default class Latex {\n /**\n * Static property.\n * Return latex cache.\n * @private\n * @type {Cache}\n */\n static get cache() {\n return Latex._cache;\n }\n\n /**\n * Static property setter.\n * Set latex cache.\n * @param {Cache} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Latex._cache = value;\n }\n\n /**\n * Converts MathML to LaTeX by calling mathml2latex service. For text services\n * we call a text service with the param mathml2latex.\n * @param {String} mathml - MathML String.\n * @return {String} LaTeX string generated by the MathML argument.\n */\n static getLatexFromMathML(mathml) {\n const mathmlWithoutSemantics = MathML.removeSemantics(mathml);\n /**\n * @type {TextCache}\n */\n const { cache } = Latex;\n\n const data = {\n service: \"mathml2latex\",\n mml: mathmlWithoutSemantics,\n };\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n // TODO: Error handling.\n let latex = \"\";\n\n if (jsonResponse.status === \"ok\") {\n latex = jsonResponse.result.text;\n const latexHtmlEntitiesEncoded = Util.htmlEntities(latex);\n // Inserting LaTeX semantics.\n const mathmlWithSemantics = MathML.addAnnotation(mathml, latexHtmlEntitiesEncoded, \"LaTeX\");\n cache.populate(latex, mathmlWithSemantics);\n }\n\n return latex;\n }\n\n /**\n * Converts LaTeX to MathML by calling latex2mathml service. For text services\n * we call a text service with the param latex2mathml.\n * @param {String} latex - String containing a LaTeX formula.\n * @param {Boolean} includeLatexOnSemantics\n * - If true LaTeX would me included into MathML semantics.\n * @return {String} MathML string generated by the LaTeX argument.\n */\n static getMathMLFromLatex(latex, includeLatexOnSemantics) {\n /**\n * @type {TextCache}\n */\n const latexCache = Latex.cache;\n\n if (Latex.cache.get(latex)) {\n return Latex.cache.get(latex);\n }\n const data = {\n service: \"latex2mathml\",\n latex,\n };\n\n if (includeLatexOnSemantics) {\n data.saveLatex = \"\";\n }\n\n const jsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n\n let output;\n if (jsonResponse.status === \"ok\") {\n let mathml = jsonResponse.result.text;\n mathml = mathml.split(\"\\r\").join(\"\").split(\"\\n\").join(\" \");\n\n // Populate LatexCache.\n if (mathml.indexOf(\"semantics\") === -1 && mathml.indexOf(\"annotation\") === -1) {\n const content = Util.htmlEntities(latex);\n mathml = MathML.addAnnotation(mathml, content, \"LaTeX\");\n output = mathml;\n } else {\n output = mathml;\n }\n if (!latexCache.get(latex)) {\n latexCache.populate(latex, mathml);\n }\n } else {\n output = `$$${latex}$$`;\n }\n return output;\n }\n\n /**\n * Converts all occurrences of MathML code to LaTeX.\n * The MathML code should containing to be converted.\n * @param {String} content - A string containing MathML valid code.\n * @param {Object} characters - An object containing special characters.\n * @return {String} A string containing all MathML annotated occurrences\n * replaced by the corresponding LaTeX code.\n */\n static parseMathmlToLatex(content, characters) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n const openTarget = `${characters.tagOpener}annotation encoding=${characters.doubleQuote}LaTeX${characters.doubleQuote}${characters.tagCloser}`;\n const closeTarget = `${characters.tagOpener}/annotation${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n let mathml;\n let startAnnotation;\n let closeAnnotation;\n\n while (start !== -1) {\n output += content.substring(end, start);\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else {\n end += mathTagEnd.length;\n }\n\n mathml = content.substring(start, end);\n\n startAnnotation = mathml.indexOf(openTarget);\n if (startAnnotation !== -1) {\n startAnnotation += openTarget.length;\n closeAnnotation = mathml.indexOf(closeTarget);\n let latex = mathml.substring(startAnnotation, closeAnnotation);\n if (characters === Constants.safeXmlCharacters) {\n latex = MathML.safeXmlDecode(latex);\n }\n output += `$$${latex}$$`;\n // Populate latex into cache.\n\n Latex.cache.populate(latex, mathml);\n } else {\n output += mathml;\n }\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n\n /**\n * Extracts the latex of a determined position in a text.\n * @param {Node} textNode - textNode to extract the LaTeX\n * @param {Number} caretPosition - Starting position to find LaTeX.\n * @param {Object} latexTags - Optional parameter representing tags between latex is inserted.\n * It has the 'open' attribute for the open tag and the 'close' attribute for the close tag.\n * \"$$\" by default.\n * @return {Object} An object with 3 keys: 'latex', 'start' and 'end'. Null if latex is not found.\n * @static\n */\n static getLatexFromTextNode(textNode, caretPosition, latexTags) {\n // TODO: Set LaTeX Tags as Core variable. Fix the call to this function (third argument).\n // Tags used for LaTeX formulas.\n const defaultLatexTags = {\n open: \"$$\",\n close: \"$$\",\n };\n // latexTags is an optional parameter. If is not set, use default latexTags.\n if (typeof latexTags === \"undefined\" || latexTags == null) {\n latexTags = defaultLatexTags;\n }\n // Looking for the first textNode.\n let startNode = textNode;\n\n while (startNode.previousSibling && startNode.previousSibling.nodeType === 3) {\n // TEXT_NODE.\n startNode = startNode.previousSibling;\n }\n\n /**\n * Returns the next latex position and node from a specific node and position.\n * @param {Node} currentNode - Node where searching latex.\n * @param {Number} currentPosition - Current position inside the currentNode.\n * @param {Object} latexTagsToUse - Tags used at latex beginning and latex final.\n * \"$$\" by default.\n * @param {Boolean} tag - Tag containing the current search.\n * @returns {Object} Object containing the current node and the position.\n */\n function getNextLatexPosition(currentNode, currentPosition, tag) {\n let position = currentNode.nodeValue.indexOf(tag, currentPosition);\n\n while (position === -1) {\n currentNode = currentNode.nextSibling;\n\n if (!currentNode) {\n // TEXT_NODE.\n return null; // Not found.\n }\n\n position = currentNode.nodeValue ? currentNode.nodeValue.indexOf(latexTags.close) : -1;\n }\n\n return {\n node: currentNode,\n position,\n };\n }\n\n /**\n * Determines if a node is previous, or not, to a second one.\n * @param {Node} node - Start node.\n * @param {Number} position - Start node position.\n * @param {Node} endNode - End node.\n * @param {Number} endPosition - End node position.\n * @returns {Boolean} True if the starting node is previous thant the en node. false otherwise.\n */\n function isPrevious(node, position, endNode, endPosition) {\n if (node === endNode) {\n return position <= endPosition;\n }\n while (node && node !== endNode) {\n node = node.nextSibling;\n }\n\n return node === endNode;\n }\n\n let start;\n let end = {\n node: startNode,\n position: 0,\n };\n // Is supposed that open and close tags has the same length.\n const tagLength = latexTags.open.length;\n do {\n start = getNextLatexPosition(end.node, end.position, latexTags.open);\n\n if (start == null || isPrevious(textNode, caretPosition, start.node, start.position)) {\n return null;\n }\n\n end = getNextLatexPosition(start.node, start.position + tagLength, latexTags.close);\n\n if (end == null) {\n return null;\n }\n\n end.position += tagLength;\n } while (isPrevious(end.node, end.position, textNode, caretPosition));\n\n // Isolating latex.\n let latex;\n\n if (start.node === end.node) {\n latex = start.node.nodeValue.substring(start.position + tagLength, end.position - tagLength);\n } else {\n const index = start.position + tagLength;\n latex = start.node.nodeValue.substring(index, start.node.nodeValue.length);\n let currentNode = start.node;\n\n do {\n currentNode = currentNode.nextSibling;\n if (currentNode === end.node) {\n latex += end.node.nodeValue.substring(0, end.position - tagLength);\n } else {\n latex += currentNode.nodeValue ? currentNode.nodeValue : \"\";\n }\n } while (currentNode !== end.node);\n }\n\n return {\n latex,\n startNode: start.node,\n startPosition: start.position,\n endNode: end.node,\n endPosition: end.position,\n };\n }\n}\n\n/**\n * Text cache. Stores all processed LaTeX strings and it's correspondent MathML string.\n * @type {Cache}\n * @static\n */\nLatex._cache = new TextCache();\n","import translations from \"../lang/strings.json\";\n/**\n * This class represents a string manager. It's used to load localized strings.\n */\nexport default class StringManager {\n constructor() {\n throw new Error(\"Static class StringManager can not be instantiated.\");\n }\n\n /**\n * Returns the associated value of certain string key. If the associated value\n * doesn't exits returns the original key.\n * @param {string} key - string key\n * @param {string} lang - DEFAULT = null. Specify the language to translate the string\n * @returns {string} correspondent value. If doesn't exists original key.\n */\n static get(key, lang) {\n // Default language definition\n let { language } = this;\n\n // If parameter language, use it\n if (lang) {\n language = lang;\n }\n\n // Cut down on strings. e.g. en_US -> en\n if (language && language.length > 2) {\n language = language.slice(0, 2);\n }\n\n // Check if we support the language\n if (!this.strings.hasOwnProperty(language)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown language ${language} set in StringManager.`);\n language = \"en\";\n }\n\n // Check if the key is supported in the given language\n if (!this.strings[language].hasOwnProperty(key)) {\n // eslint-disable-line no-prototype-builtins\n console.warn(`Unknown key ${key} for language ${language} in StringManager.`);\n return key;\n }\n\n return this.strings[language][key];\n }\n}\n\n/**\n * Dictionary of dictionaries:\n * Key: language code\n * Value: Key: id of the string\n * Value: translation of the string\n */\nStringManager.strings = translations;\n\n/**\n * Language of the translations; English by default\n */\nStringManager.language = \"en\";\n","/* eslint-disable no-bitwise */\nimport DOMPurify from \"dompurify\";\nimport MathML from \"./mathml\";\nimport Configuration from \"./configuration\";\nimport Latex from \"./latex\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * This class represents an utility class.\n */\nexport default class Util {\n /**\n * Fires an event in a target.\n * @param {EventTarget} eventTarget - target where event should be fired.\n * @param {string} eventName event to fire.\n * @static\n */\n static fireEvent(eventTarget, eventName) {\n if (document.createEvent) {\n const eventObject = document.createEvent(\"HTMLEvents\");\n eventObject.initEvent(eventName, true, true);\n return !eventTarget.dispatchEvent(eventObject);\n }\n\n const eventObject = document.createEventObject();\n return eventTarget.fireEvent(`on${eventName}`, eventObject);\n }\n\n /**\n * Cross-browser addEventListener/attachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - callback function.\n * @static\n */\n static addEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.addEventListener) {\n eventTarget.addEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.attachEvent) {\n // Backwards compatibility.\n eventTarget.attachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * Cross-browser removeEventListener/detachEvent function.\n * @param {EventTarget} eventTarget - target to add the event.\n * @param {string} eventName - specifies the type of event.\n * @param {Function} callBackFunction - function to remove from the event target.\n * @static\n */\n static removeEvent(eventTarget, eventName, callBackFunction) {\n if (eventTarget.removeEventListener) {\n eventTarget.removeEventListener(eventName, callBackFunction, true);\n } else if (eventTarget.detachEvent) {\n eventTarget.detachEvent(`on${eventName}`, callBackFunction);\n }\n }\n\n /**\n * A map from event target to event handlers so we can remove the event\n * listeners in removeElementEvents\n *\n * @type {Map}\n * @static\n */\n static elementEventsMap = new Map();\n\n /**\n * Adds the a callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @param {Function} doubleClickHandler - function to run when on dblclick event.\n * @param {Function} mousedownHandler - function to run when on mousedown event.\n * @param {Function} mouseupHandler - function to run when on mouseup event.\n * @static\n */\n static addElementEvents(eventTarget, doubleClickHandler, mousedownHandler, mouseupHandler) {\n // Make sure not to leak event listeners if we've already added events to\n // this element\n Util.removeElementEvents(eventTarget);\n\n let entry = {};\n Util.elementEventsMap.set(eventTarget, entry);\n\n if (doubleClickHandler) {\n entry.callbackDblclick = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n doubleClickHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"dblclick\", entry.callbackDblclick);\n }\n\n if (mousedownHandler) {\n entry.callbackMousedown = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mousedownHandler(element, realEvent);\n };\n\n Util.addEvent(eventTarget, \"mousedown\", entry.callbackMousedown);\n }\n\n if (mouseupHandler) {\n entry.callbackMouseup = (event) => {\n const realEvent = event || window.event;\n const element = realEvent.srcElement ? realEvent.srcElement : realEvent.target;\n mouseupHandler(element, realEvent);\n };\n // Chrome doesn't trigger this event for eventTarget if we release the mouse button\n // while the mouse is outside the editor text field.\n // This is a workaround: we trigger the event independently of where the mouse\n // is when we release its button.\n Util.addEvent(document, \"mouseup\", entry.callbackMouseup);\n Util.addEvent(eventTarget, \"mouseup\", entry.callbackMouseup);\n }\n }\n\n /**\n * Remove all callback function, for a certain event target, to the following event types:\n * - dblclick\n * - mousedown\n * - mouseup\n * @param {EventTarget} eventTarget - event target.\n * @static\n */\n static removeElementEvents(eventTarget) {\n let entry = Util.elementEventsMap.get(eventTarget);\n if (!entry) {\n return;\n }\n\n Util.elementEventsMap.delete(eventTarget);\n\n Util.removeEvent(eventTarget, \"dblclick\", entry.callbackDblclick);\n Util.removeEvent(eventTarget, \"mousedown\", entry.callbackMousedown);\n Util.removeEvent(document, \"mouseup\", entry.callbackMouseup);\n Util.removeEvent(eventTarget, \"mouseup\", entry.callbackMouseup);\n }\n\n /**\n * Adds a class name to a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static addClass(element, className) {\n if (!Util.containsClass(element, className)) {\n element.className += ` ${className}`;\n }\n }\n\n /**\n * Checks if a HTMLElement contains a certain class.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the className.\n * @returns {boolean} true if the HTMLElement contains the class name. false otherwise.\n * @static\n */\n static containsClass(element, className) {\n if (element == null || !(\"className\" in element)) {\n return false;\n }\n\n const currentClasses = element.className.split(\" \");\n\n for (let i = currentClasses.length - 1; i >= 0; i -= 1) {\n if (currentClasses[i] === className) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Remove a certain class for a HTMLElement.\n * @param {HTMLElement} element - the HTML element.\n * @param {string} className - the class name.\n * @static\n */\n static removeClass(element, className) {\n let newClassName = \"\";\n const classes = element.className.split(\" \");\n\n for (let i = 0; i < classes.length; i += 1) {\n if (classes[i] !== className) {\n newClassName += `${classes[i]} `;\n }\n }\n element.className = newClassName.trim();\n }\n\n /**\n * Converts old xml initial text attribute (with «») to the correct one(with §lt;§gt;). It's\n * used to parse old applets.\n * @param {string} text - string containing safeXml characters\n * @returns {string} a string with safeXml characters parsed.\n * @static\n */\n static convertOldXmlinitialtextAttribute(text) {\n // Used to fix a bug with Cas imported from Moodle 1.9 to Moodle 2.x.\n // This could be removed in future.\n const val = \"value=\";\n\n const xitpos = text.indexOf(\"xmlinitialtext\");\n const valpos = text.indexOf(val, xitpos);\n const quote = text.charAt(valpos + val.length);\n const startquote = valpos + val.length + 1;\n const endquote = text.indexOf(quote, startquote);\n\n const value = text.substring(startquote, endquote);\n\n let newvalue = value.split(\"«\").join(\"§lt;\");\n newvalue = newvalue.split(\"»\").join(\"§gt;\");\n newvalue = newvalue.split(\"&\").join(\"§\");\n newvalue = newvalue.split(\"¨\").join(\"§quot;\");\n\n text = text.split(value).join(newvalue);\n return text;\n }\n\n /**\n * Convert a string representation of key-value pairs to an object.\n * @param {string} keyValueString - String with key-value pairs in the format key1='value1', key2='value2'\n * @returns {Object} - Object containing the key-value pairs\n */\n static convertStringToObject(keyValueString) {\n if (!keyValueString || typeof keyValueString !== \"string\") {\n return {};\n }\n\n return keyValueString\n .split(\",\")\n .map((pair) => pair.trim().split(\"=\"))\n .reduce((resultObject, [key, value]) => {\n if (key && value) {\n resultObject[key] = value;\n }\n return resultObject;\n }, {});\n }\n\n /**\n * Cross-browser solution for creating new elements.\n * @param {string} tagName - tag name of the wished element.\n * @param {Object} attributes - an object where each key is a wished\n * attribute name and each value is its value.\n * @param {Object} [creator] - if supplied, this function will use\n * the \"createElement\" method from this param. Otherwise\n * document will be used as creator.\n * @returns {Element} The DOM element with the specified attributes assigned.\n * @static\n */\n static createElement(tagName, attributes, creator) {\n if (attributes === undefined) {\n attributes = {};\n }\n\n if (creator === undefined) {\n creator = document;\n }\n\n let element;\n\n /*\n * Internet Explorer fix:\n * If you create a new object dynamically, you can't set a non-standard attribute.\n * For example, you can't set the \"src\" attribute on an \"applet\" object.\n * Other browsers will throw an exception and will run the standard code.\n */\n try {\n let html = `<${tagName}`;\n\n Object.keys(attributes).forEach((attributeName) => {\n html += ` ${attributeName}=\"${Util.htmlEntities(attributes[attributeName])}\"`;\n });\n html += \">\";\n element = creator.createElement(html);\n } catch (e) {\n element = creator.createElement(tagName);\n Object.keys(attributes).forEach((attributeName) => {\n element.setAttribute(attributeName, attributes[attributeName]);\n });\n }\n return element;\n }\n\n /**\n * Creates new HTML from it's HTML code as string.\n * @param {string} objectCode - html code\n * @returns {Element} the HTML element.\n * @static\n */\n static createObject(objectCode, creator) {\n if (creator === undefined) {\n creator = document;\n }\n\n // Internet Explorer can't include \"param\" tag when is setting an innerHTML property.\n objectCode = objectCode\n .split(\"\").join(\"\").split(\"\").join(\"\");\n\n objectCode = objectCode\n .split(\"\").join(\"
\").split(\"\").join(\"
\");\n\n const container = Util.createElement(\"div\", {}, creator);\n container.innerHTML = objectCode;\n\n function recursiveParamsFix(object) {\n if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisParam\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const param = Util.createElement(\"param\", attributesParsed, creator);\n\n // IE fix.\n if (param.NAME) {\n param.name = param.NAME;\n param.value = param.VALUE;\n }\n\n param.removeAttribute(\"wirisObject\");\n object.parentNode.replaceChild(param, object);\n } else if (object.getAttribute && object.getAttribute(\"wirisObject\") === \"WirisApplet\") {\n const attributesParsed = {};\n\n for (let i = 0; i < object.attributes.length; i += 1) {\n if (object.attributes[i].nodeValue !== null) {\n attributesParsed[object.attributes[i].nodeName] = object.attributes[i].nodeValue;\n }\n }\n\n const applet = Util.createElement(\"applet\", attributesParsed, creator);\n applet.removeAttribute(\"wirisObject\");\n\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n\n if (object.childNodes[i].nodeName.toLowerCase() === \"param\") {\n applet.appendChild(object.childNodes[i]);\n i -= 1; // When we insert the object child into the applet, object loses one child.\n }\n }\n\n object.parentNode.replaceChild(applet, object);\n } else {\n for (let i = 0; i < object.childNodes.length; i += 1) {\n recursiveParamsFix(object.childNodes[i]);\n }\n }\n }\n\n recursiveParamsFix(container);\n return container.firstChild;\n }\n\n /**\n * Converts an Element to its HTML code.\n * @param {Element} element - entry element.\n * @return {string} the HTML code of the input element.\n * @static\n */\n static createObjectCode(element) {\n // In case that the image was not created, the object can be null or undefined.\n if (typeof element === \"undefined\" || element === null) {\n return null;\n }\n\n if (element.nodeType === 1) {\n // ELEMENT_NODE.\n let output = `<${element.tagName}`;\n\n for (let i = 0; i < element.attributes.length; i += 1) {\n if (element.attributes[i].specified) {\n output += ` ${element.attributes[i].name}=\"${Util.htmlEntities(element.attributes[i].value)}\"`;\n }\n }\n\n if (element.childNodes.length > 0) {\n output += \">\";\n\n for (let i = 0; i < element.childNodes.length; i += 1) {\n output += Util.createObject(element.childNodes[i]);\n }\n\n output += ``;\n } else if (element.nodeName === \"DIV\" || element.nodeName === \"SCRIPT\") {\n output += `>`;\n } else {\n output += \"/>\";\n }\n\n return output;\n }\n\n if (element.nodeType === 3) {\n // TEXT_NODE.\n return Util.htmlEntities(element.nodeValue);\n }\n\n return \"\";\n }\n\n /**\n * Concatenates two URL paths.\n * @param {string} path1 - first URL path\n * @param {string} path2 - second URL path\n * @returns {string} new URL.\n */\n static concatenateUrl(path1, path2) {\n let separator = \"\";\n if (path1.indexOf(\"/\") !== path1.length && path2.indexOf(\"/\") !== 0) {\n separator = \"/\";\n }\n return (path1 + separator + path2).replace(/([^:]\\/)\\/+/g, \"$1\");\n }\n\n /**\n * Parses a text and replaces all HTML special characters by their correspondent entities.\n * @param {string} input - text to be parsed.\n * @returns {string} the input text with all their special characters replaced by their entities.\n * @static\n */\n static htmlEntities(input) {\n return input.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\").split('\"').join(\""\");\n }\n\n /**\n * Sanitize HTML to prevent XSS injections.\n * @param {string} html - html to be sanitize.\n * @returns {string} html sanitized.\n * @static\n */\n static htmlSanitize(html) {\n const annotationRegex = /\\/;\n // Get all the annotation content including the tags.\n const annotation = html.match(annotationRegex);\n // Sanitize html code without removing our supported MathML tags and attributes.\n html = DOMPurify.sanitize(html, {\n ADD_TAGS: [\"semantics\", \"annotation\", \"mstack\", \"msline\", \"msrow\", \"none\"],\n ADD_ATTR: [\"linebreak\", \"charalign\", \"stackalign\"],\n });\n // Readd old annotation content.\n return html.replace(annotationRegex, annotation);\n }\n\n /**\n * Parses a text and replaces all the HTML entities by their characters.\n * @param {string} input - text to be parsed\n * @returns {string} the input text with all their entities replaced by characters.\n * @static\n */\n static htmlEntitiesDecode(input) {\n // Textarea element decodes when inner html is set.\n const textarea = document.createElement(\"textarea\");\n textarea.innerHTML = input;\n return textarea.value;\n }\n\n /**\n * Returns a cross-browser http request.\n * @return {object} httpRequest request object.\n * @returns {XMLHttpRequest|ActiveXObject} the proper request object.\n */\n static createHttpRequest() {\n const currentPath = window.location.toString().substr(0, window.location.toString().lastIndexOf(\"/\") + 1);\n if (currentPath.substr(0, 7) === \"file://\") {\n throw StringManager.get(\"exception_cross_site\");\n }\n\n if (typeof XMLHttpRequest !== \"undefined\") {\n return new XMLHttpRequest();\n }\n\n try {\n return new ActiveXObject(\"Msxml2.XMLHTTP\");\n } catch (e) {\n try {\n return new ActiveXObject(\"Microsoft.XMLHTTP\");\n } catch (oc) {\n return null;\n }\n }\n }\n\n /**\n * Converts a hash to a HTTP query.\n * @param {Object[]} properties - a key/value object.\n * @returns {string} a HTTP query containing all the key value pairs with\n * all the special characters replaced by their entities.\n * @static\n */\n static httpBuildQuery(properties) {\n let result = \"\";\n\n Object.keys(properties).forEach((i) => {\n if (properties[i] != null) {\n result += `${Util.urlEncode(i)}=${Util.urlEncode(properties[i])}&`;\n }\n });\n\n // Deleting last '&' empty character.\n if (result.substring(result.length - 1) === \"&\") {\n result = result.substring(0, result.length - 1);\n }\n\n return result;\n }\n\n /**\n * Convert a hash to string sorting keys to get a deterministic output\n * @param {Object[]} hash - a key/value object.\n * @returns {string} a string with the form key1=value1...keyn=valuen\n * @static\n */\n static propertiesToString(hash) {\n // 1. Sort keys. We sort the keys because we want a deterministic output.\n const keys = [];\n Object.keys(hash).forEach((key) => {\n if (Object.prototype.hasOwnProperty.call(hash, key)) {\n keys.push(key);\n }\n });\n\n const n = keys.length;\n for (let i = 0; i < n; i += 1) {\n for (let j = i + 1; j < n; j += 1) {\n const s1 = keys[i];\n const s2 = keys[j];\n if (Util.compareStrings(s1, s2) > 0) {\n // Swap.\n keys[i] = s2;\n keys[j] = s1;\n }\n }\n }\n\n // 2. Generate output.\n let output = \"\";\n for (let i = 0; i < n; i += 1) {\n const key = keys[i];\n output += key;\n output += \"=\";\n let value = hash[key];\n value = value.replace(\"\\\\\", \"\\\\\\\\\");\n value = value.replace(\"\\n\", \"\\\\n\");\n value = value.replace(\"\\r\", \"\\\\r\");\n value = value.replace(\"\\t\", \"\\\\t\");\n\n output += value;\n output += \"\\n\";\n }\n return output;\n }\n\n /**\n * Compare two strings using charCodeAt method\n * @param {string} a - first string to compare.\n * @param {string} b - second string to compare.\n * @returns {number} the difference between a and b\n * @static\n */\n static compareStrings(a, b) {\n let i;\n const an = a.length;\n const bn = b.length;\n const n = an > bn ? bn : an;\n for (i = 0; i < n; i += 1) {\n const c = Util.fixedCharCodeAt(a, i) - Util.fixedCharCodeAt(b, i);\n if (c !== 0) {\n return c;\n }\n }\n return a.length - b.length;\n }\n\n /**\n * Fix charCodeAt() JavaScript function to handle non-Basic-Multilingual-Plane characters.\n * @param {string} string - input string\n * @param {number} idx - an integer greater than or equal to 0\n * and less than the length of the string\n * @returns {number} an integer representing the UTF-16 code of the string at the given index.\n * @static\n */\n static fixedCharCodeAt(string, idx) {\n idx = idx || 0;\n const code = string.charCodeAt(idx);\n let hi;\n let low;\n\n /* High surrogate (could change last hex to 0xDB7F to treat high\n private surrogates as single characters) */\n\n if (code >= 0xd800 && code <= 0xdbff) {\n hi = code;\n low = string.charCodeAt(idx + 1);\n if (Number.isNaN(low)) {\n throw StringManager.get(\"exception_high_surrogate\");\n }\n return (hi - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;\n }\n\n if (code >= 0xdc00 && code <= 0xdfff) {\n // Low surrogate.\n /* We return false to allow loops to skip this iteration since should have\n already handled high surrogate above in the previous iteration. */\n return false;\n }\n return code;\n }\n\n /**\n * Returns an URL with it's query params converted into array.\n * @param {string} url - input URL.\n * @returns {Object[]} an array containing all URL query params.\n * @static\n */\n static urlToAssArray(url) {\n let i;\n i = url.indexOf(\"?\");\n if (i > 0) {\n const query = url.substring(i + 1);\n const ss = query.split(\"&\");\n const h = {};\n for (i = 0; i < ss.length; i += 1) {\n const s = ss[i];\n const kv = s.split(\"=\");\n if (kv.length > 1) {\n h[kv[0]] = decodeURIComponent(kv[1].replace(/\\+/g, \" \"));\n }\n }\n return h;\n }\n return {};\n }\n\n /**\n * Returns an encoded URL by replacing each instance of certain characters by\n * one, two, three or four escape sequences using encodeURIComponent method.\n * !'()* . will not be encoded.\n *\n * @param {string} clearString - URL string to be encoded\n * @returns {string} URL with it's special characters replaced.\n * @static\n */\n static urlEncode(clearString) {\n let output = \"\";\n // Method encodeURIComponent doesn't encode !'()*~ .\n output = encodeURIComponent(clearString);\n return output;\n }\n\n // TODO: To parser?\n /**\n * Converts the HTML of a image into the output code that WIRIS must return.\n * By default returns the MathML stored on data-mahml attribute (if imgCode is a formula)\n * or the Wiriscas attribute of a WIRIS applet.\n * @param {string} imgCode - the html code from a formula or a CAS image.\n * @param {boolean} convertToXml - true if the image should be converted to XML.\n * @param {boolean} convertToSafeXml - true if the image should be converted to safeXML.\n * @returns {string} the XML or safeXML of a WIRIS image.\n * @static\n */\n static getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml) {\n const imgObject = Util.createObject(imgCode);\n if (imgObject) {\n if (\n imgObject.className === Configuration.get(\"imageClassName\") ||\n imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"))\n ) {\n if (!convertToXml) {\n return imgCode;\n }\n\n const dataMathML = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n // To handle annotations, first we need the MathML in XML.\n let mathML = MathML.safeXmlDecode(dataMathML);\n\n if (!Configuration.get(\"saveHandTraces\")) {\n mathML = MathML.removeAnnotation(mathML, \"application/json\");\n }\n\n if (mathML == null) {\n mathML = imgObject.getAttribute(\"alt\");\n }\n\n if (convertToSafeXml) {\n const safeMathML = MathML.safeXmlEncode(mathML);\n return safeMathML;\n }\n\n return mathML;\n }\n }\n return imgCode;\n }\n\n /**\n * Gets the node length in characters.\n * @param {Node} node - HTML node.\n * @returns {number} node length.\n * @static\n */\n static getNodeLength(node) {\n const staticNodeLengths = {\n IMG: 1,\n BR: 1,\n };\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return node.nodeValue.length;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n let length = staticNodeLengths[node.nodeName.toUpperCase()];\n\n if (length === undefined) {\n length = 0;\n }\n\n for (let i = 0; i < node.childNodes.length; i += 1) {\n length += Util.getNodeLength(node.childNodes[i]);\n }\n return length;\n }\n return 0;\n }\n\n /**\n * Gets a selected node or text from an editable HTMLElement.\n * If the caret is on a text node, concatenates it with all the previous and next text nodes.\n * @param {HTMLElement} target - the editable HTMLElement.\n * @param {boolean} isIframe - specifies if the target is an iframe or not\n * @param {boolean} forceGetSelection - if true, ignores IE system to get\n * the current selection and uses window.getSelection()\n * @returns {object} an object with the 'node' key set if the item is an\n * element or the keys 'node' and 'caretPosition' if the element is text.\n * @static\n */\n static getSelectedItem(target, isIframe, forceGetSelection) {\n let windowTarget;\n\n if (isIframe) {\n windowTarget = target.contentWindow;\n windowTarget.focus();\n } else {\n windowTarget = window;\n target.focus();\n }\n\n if (document.selection && !forceGetSelection) {\n const range = windowTarget.document.selection.createRange();\n\n if (range.parentElement) {\n if (range.htmlText.length > 0) {\n if (range.text.length === 0) {\n return Util.getSelectedItem(target, isIframe, true);\n }\n\n return null;\n }\n\n windowTarget.document.execCommand(\"InsertImage\", false, \"#\");\n let temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() !== \"IMG\") {\n // IE9 fix: parentElement() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML('');\n temporalObject = windowTarget.document.getElementById(\"wrs_openEditorWindow_temporalObject\");\n }\n\n let node;\n let caretPosition;\n\n if (temporalObject.nextSibling && temporalObject.nextSibling.nodeType === 3) {\n // TEXT_NODE.\n node = temporalObject.nextSibling;\n caretPosition = 0;\n } else if (temporalObject.previousSibling && temporalObject.previousSibling.nodeType === 3) {\n node = temporalObject.previousSibling;\n caretPosition = node.nodeValue.length;\n } else {\n node = windowTarget.document.createTextNode(\"\");\n temporalObject.parentNode.insertBefore(node, temporalObject);\n caretPosition = 0;\n }\n\n temporalObject.parentNode.removeChild(temporalObject);\n\n return {\n node,\n caretPosition,\n };\n }\n\n if (range.length > 1) {\n return null;\n }\n\n return {\n node: range.item(0),\n };\n }\n\n if (windowTarget.getSelection) {\n let range;\n const selection = windowTarget.getSelection();\n\n try {\n range = selection.getRangeAt(0);\n } catch (e) {\n range = windowTarget.document.createRange();\n }\n\n const node = range.startContainer;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n return {\n node,\n caretPosition: range.startOffset,\n };\n }\n\n if (node !== range.endContainer) {\n return null;\n }\n\n if (node.nodeType === 1) {\n // ELEMENT_NODE.\n const position = range.startOffset;\n\n if (node.childNodes[position]) {\n // In case that a formula is detected but not selected,\n // we create an empty span where we could insert the new formula.\n if (range.startOffset === range.endOffset) {\n if (\n position !== 0 &&\n node.childNodes[position - 1].localName === \"span\" &&\n node.childNodes[position].classList?.contains(\"Wirisformula\")\n ) {\n node.childNodes[position - 1].remove();\n return Util.getSelectedItem(target, isIframe, forceGetSelection);\n }\n if (node.childNodes[position].classList?.contains(\"Wirisformula\")) {\n if (\n (position > 0 && node.childNodes[position - 1].classList?.contains(\"Wirisformula\")) ||\n position === 0\n ) {\n const emptySpan = document.createElement(\"span\");\n node.insertBefore(emptySpan, node.childNodes[position]);\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n return {\n node: node.childNodes[position],\n };\n }\n }\n }\n\n return null;\n }\n\n /**\n * Returns null if there isn't any item or if it is malformed.\n * Otherwise returns an object containing the node with the MathML image\n * and the cursor position inside the textarea.\n * @param {HTMLTextAreaElement} textarea - textarea element.\n * @returns {Object} An object containing the node, the index of the\n * beginning of the selected text, caret position and the start and end position of the\n * text node.\n * @static\n */\n static getSelectedItemOnTextarea(textarea) {\n const textNode = document.createTextNode(textarea.value);\n const textNodeValues = Latex.getLatexFromTextNode(textNode, textarea.selectionStart);\n if (textNodeValues === null) {\n return null;\n }\n\n return {\n node: textNode,\n caretPosition: textarea.selectionStart,\n startPosition: textNodeValues.startPosition,\n endPosition: textNodeValues.endPosition,\n };\n }\n\n /**\n * Looks for elements that match the given name in a HTML code string.\n * Important: this function is very concrete for WIRIS code.\n * It takes as preconditions lots of behaviors that are not the general case.\n * @param {string} code - HTML code.\n * @param {string} name - element name.\n * @param {boolean} autoClosed - true if the elements are autoClosed.\n * @return {Object[]} an object containing all HTML elements of code matching the name argument.\n * @static\n */\n static getElementsByNameFromString(code, name, autoClosed) {\n const elements = [];\n code = code.toLowerCase();\n name = name.toLowerCase();\n let start = code.indexOf(`<${name} `);\n\n while (start !== -1) {\n // Look for nodes.\n let endString;\n\n if (autoClosed) {\n endString = \">\";\n } else {\n endString = ``;\n }\n\n let end = code.indexOf(endString, start);\n\n if (end !== -1) {\n end += endString.length;\n elements.push({\n start,\n end,\n });\n } else {\n end = start + 1;\n }\n\n start = code.indexOf(`<${name} `, end);\n }\n\n return elements;\n }\n\n /**\n * Returns the numeric value of a base64 character.\n * @param {string} character - base64 character.\n * @returns {number} base64 character numeric value.\n * @static\n */\n static decode64(character) {\n const PLUS = \"+\".charCodeAt(0);\n const SLASH = \"/\".charCodeAt(0);\n const NUMBER = \"0\".charCodeAt(0);\n const LOWER = \"a\".charCodeAt(0);\n const UPPER = \"A\".charCodeAt(0);\n const PLUS_URL_SAFE = \"-\".charCodeAt(0);\n const SLASH_URL_SAFE = \"_\".charCodeAt(0);\n const code = character.charCodeAt(0);\n\n if (code === PLUS || code === PLUS_URL_SAFE) {\n return 62; // Char '+'.\n }\n if (code === SLASH || code === SLASH_URL_SAFE) {\n return 63; // Char '/'.\n }\n if (code < NUMBER) {\n return -1; // No match.\n }\n if (code < NUMBER + 10) {\n return code - NUMBER + 26 + 26;\n }\n if (code < UPPER + 26) {\n return code - UPPER;\n }\n if (code < LOWER + 26) {\n return code - LOWER + 26;\n }\n\n return null;\n }\n\n /**\n * Converts a base64 string to a array of bytes.\n * @param {string} b64String - base64 string.\n * @param {number} length - dimension of byte array (by default whole string).\n * @return {Object[]} the resultant byte array.\n * @static\n */\n static b64ToByteArray(b64String, length) {\n let tmp;\n\n if (b64String.length % 4 > 0) {\n throw new Error(\"Invalid string. Length must be a multiple of 4\"); // Tipped base64. Length is fixed.\n }\n\n const arr = [];\n\n let l;\n let placeHolders;\n if (!length) {\n // All b64String string.\n if (b64String.charAt(b64String.length - 2) === \"=\") {\n placeHolders = 2;\n } else if (b64String.charAt(b64String.length - 1) === \"=\") {\n placeHolders = 1;\n } else {\n placeHolders = 0;\n }\n l = placeHolders > 0 ? b64String.length - 4 : b64String.length;\n } else {\n l = length;\n }\n\n let i;\n for (i = 0; i < l; i += 4) {\n // Ignoring code checker standards (bitewise operators).\n // See https://tracker.moodle.org/browse/CONTRIB-5862 for further information.\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 18) |\n (Util.decode64(b64String.charAt(i + 1)) << 12) |\n (Util.decode64(b64String.charAt(i + 2)) << 6) |\n Util.decode64(b64String.charAt(i + 3));\n\n arr.push((tmp >> 16) & 0xff);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n\n if (placeHolders) {\n if (placeHolders === 2) {\n // Ignoring code checker standards (bitewise operators).\n // @codingStandardsIgnoreStart\n // eslint-disable-next-line max-len\n tmp = (Util.decode64(b64String.charAt(i)) << 2) | (Util.decode64(b64String.charAt(i + 1)) >> 4);\n arr.push(tmp & 0xff);\n } else if (placeHolders === 1) {\n // eslint-disable-next-line max-len\n tmp =\n (Util.decode64(b64String.charAt(i)) << 10) |\n (Util.decode64(b64String.charAt(i + 1)) << 4) |\n (Util.decode64(b64String.charAt(i + 2)) >> 2);\n arr.push((tmp >> 8) & 0xff);\n arr.push(tmp & 0xff);\n // @codingStandardsIgnoreEnd\n }\n }\n return arr;\n }\n\n /**\n * Returns the first 32-bit signed integer from a byte array.\n * @param {Object[]} bytes - array of bytes.\n * @returns {number} the 32-bit signed integer.\n * @static\n */\n static readInt32(bytes) {\n if (bytes.length < 4) {\n return false;\n }\n const int32 = bytes.splice(0, 4);\n // @codingStandardsIgnoreStart¡\n return (int32[0] << 24) | (int32[1] << 16) | (int32[2] << 8) | (int32[3] << 0);\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read the first byte from a byte array.\n * @param {Object} bytes - input byte array.\n * @returns {number} first byte of the byte array.\n * @static\n */\n static readByte(bytes) {\n // @codingStandardsIgnoreStart\n return bytes.shift() << 0;\n // @codingStandardsIgnoreEnd\n }\n\n /**\n * Read an arbitrary number of bytes, from a fixed position on a byte array.\n * @param {Object[]} bytes - byte array.\n * @param {number} pos - start position.\n * @param {number} len - number of bytes to read.\n * @returns {Object[]} the byte array.\n * @static\n */\n static readBytes(bytes, pos, len) {\n return bytes.splice(pos, len);\n }\n\n /**\n * Inserts or modifies formulas or CAS on a textarea.\n * @param {HTMLTextAreaElement} textarea - textarea target.\n * @param {string} text - text to add in the textarea. For example, to add the link to the image,\n * call this function as (textarea, Parser.createImageSrc(mathml));\n * @static\n */\n static updateTextArea(textarea, text) {\n if (textarea && text) {\n textarea.focus();\n\n if (textarea.selectionStart != null) {\n const { selectionEnd } = textarea;\n const selectionStart = textarea.value.substring(0, textarea.selectionStart);\n const selectionEndSub = textarea.value.substring(selectionEnd, textarea.value.length);\n textarea.value = selectionStart + text + selectionEndSub;\n textarea.selectionEnd = selectionEnd + text.length;\n } else {\n const selection = document.selection.createRange();\n selection.text = text;\n }\n }\n }\n\n /**\n * Modifies existing formula on a textarea.\n * @param {HTMLTextAreaElement} textarea - text area target.\n * @param {string} text - text to add in the textarea. For example, if you want to add the link\n * to the image,you can call this function as\n * Util.updateTextarea(textarea, Parser.createImageSrc(mathml));\n * @param {number} start - beginning index from textarea where it needs to be replaced by text.\n * @param {number} end - ending index from textarea where it needs to be replaced by text\n * @static\n */\n static updateExistingTextOnTextarea(textarea, text, start, end) {\n textarea.focus();\n const textareaStart = textarea.value.substring(0, start);\n textarea.value = textareaStart + text + textarea.value.substring(end, textarea.value.length);\n textarea.selectionEnd = start + text.length;\n }\n\n /**\n * Add a parameter with it's correspondent value to an URL (GET).\n * @param {string} path - URL path\n * @param {string} parameter - parameter\n * @param {string} value - value\n * @static\n */\n static addArgument(path, parameter, value) {\n let sep;\n if (path.indexOf(\"?\") > 0) {\n sep = \"&\";\n } else {\n sep = \"?\";\n }\n return `${path + sep + parameter}=${value}`;\n }\n}\n","import Configuration from \"./configuration\";\nimport Util from \"./util\";\n\n/**\n * @classdesc\n * This class represents MathType Image class. Contains all the logic related\n * to MathType images manipulation.\n * All MathType images are generated using the appropriate MathType\n * integration service: showimage or createimage.\n *\n * There are two available image formats:\n * - svg (default)\n * - png\n *\n * There are two formats for the image src attribute:\n * - A data-uri scheme containing the URL-encoded SVG or a PNG's base64.\n * - A link to the showimage service.\n */\nexport default class Image {\n /**\n * Removes data attributes from an image.\n * @param {HTMLImageElement} img - Image where remove data attributes.\n */\n static removeImgDataAttributes(img) {\n const attributesToRemove = [];\n const { attributes } = img;\n\n Object.keys(attributes).forEach((key) => {\n const attribute = attributes[key];\n if (attribute !== undefined && attribute.name !== undefined && attribute.name.indexOf(\"data-\") === 0) {\n // Is preferred keep an array and remove after the search\n // because when attribute is removed the array of attributes\n // is modified.\n attributesToRemove.push(attribute.name);\n }\n });\n\n attributesToRemove.forEach((attribute) => {\n img.removeAttribute(attribute);\n });\n }\n\n /**\n * @static\n * Clones all MathType image attributes from a HTMLImageElement to another.\n * @param {HTMLImageElement} originImg - The original image.\n * @param {HTMLImageElement} destImg - The destination image.\n */\n static clone(originImg, destImg) {\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (!originImg.hasAttribute(customEditorAttributeName)) {\n destImg.removeAttribute(customEditorAttributeName);\n }\n\n const mathmlAttributeName = Configuration.get(\"imageMathmlAttribute\");\n const imgAttributes = [\n mathmlAttributeName,\n customEditorAttributeName,\n \"alt\",\n \"height\",\n \"width\",\n \"style\",\n \"src\",\n \"role\",\n ];\n\n imgAttributes.forEach((iterator) => {\n const originAttribute = originImg.getAttribute(iterator);\n if (originAttribute) {\n destImg.setAttribute(iterator, originAttribute);\n }\n });\n }\n\n /**\n * Determines whether an img src contains an SVG.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src contains an SVG, false otherwise\n */\n static isSvg(img) {\n return img.src.startsWith(\"data:image/svg+xml;\");\n }\n\n /**\n * Determines whether an img src is encoded in base64 or not.\n * @param {HTMLImageElement} img the img element to inspect\n * @returns true if the img src is encoded in base64, false otherwise\n */\n static isBase64(img) {\n return img.src.startsWith(\"data:image/svg+xml;base64,\") || img.src.startsWith(\"data:image/png;base64,\");\n }\n\n /**\n * Calculates the metrics of a MathType image given the the service response and the image format.\n * @param {HTMLImageElement} img - The HTMLImageElement.\n * @param {String} uri - The URI generated by the image service: can be a data URI scheme or a URL.\n * @param {Boolean} jsonResponse - True the response of the image service is a\n * JSON object. False otherwise.\n */\n static setImgSize(img, uri, jsonResponse) {\n let ar;\n let base64String;\n let bytes;\n let svgString;\n if (jsonResponse) {\n // Cleaning data:image/png;base64.\n if (Image.isSvg(img)) {\n // SVG format.\n // If SVG is encoded in base64 we need to convert the base64 bytes into a SVG string.\n if (!Image.isBase64(img)) {\n ar = Image.getMetricsFromSvgString(uri);\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n svgString = \"\";\n bytes = Util.b64ToByteArray(base64String, base64String.length);\n for (let i = 0; i < bytes.length; i += 1) {\n svgString += String.fromCharCode(bytes[i]);\n }\n ar = Image.getMetricsFromSvgString(svgString);\n }\n // PNG format: we store all metrics information in the first 88 bytes.\n } else {\n base64String = img.src.substr(img.src.indexOf(\"base64,\") + 7, img.src.length);\n bytes = Util.b64ToByteArray(base64String, 88);\n ar = Image.getMetricsFromBytes(bytes);\n }\n // Backwards compatibility: we store the metrics into createimage response.\n } else {\n ar = Util.urlToAssArray(uri);\n }\n let width = ar.cw;\n if (!width) {\n return;\n }\n let height = ar.ch;\n let baseline = ar.cb;\n const { dpi } = ar;\n if (dpi) {\n width = (width * 96) / dpi;\n height = (height * 96) / dpi;\n baseline = (baseline * 96) / dpi;\n }\n img.width = width;\n img.height = height;\n img.style.verticalAlign = `-${height - baseline}px`;\n }\n\n /**\n * Calculates the metrics of an image which has been resized. Is used to restore the original\n * metrics of a resized image.\n * @param {HTMLImageElement } img - The resized HTMLImageElement.\n */\n static fixAfterResize(img) {\n img.removeAttribute(\"style\");\n img.removeAttribute(\"width\");\n img.removeAttribute(\"height\");\n // In order to avoid resize with max-width css property.\n img.style.maxWidth = \"none\";\n\n const processImg = (img) => {\n if (img.src.indexOf(\"data:image\") !== -1) {\n if (img.src.indexOf(\"data:image/svg+xml\") !== -1) {\n // Image is in base64: decode it in order to calculate the size, and then bring it back to base64\n // This is a bit of an ugly hack used to recycle the logic of Image.setImgSize instead of rewriting it\n // (which would actually make more sense for readibility and efficiency).\n if (img.src.indexOf(\"data:image/svg+xml;base64,\") !== -1) {\n // 'data:image/svg+xml;base64,'.length === 26\n const base64String = img.getAttribute(\"src\").substring(26);\n const svgString = window.atob(base64String);\n const encodedSvgString = encodeURIComponent(svgString);\n img.setAttribute(\"src\", `data:image/svg+xml;charset=utf8,${encodedSvgString}`);\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n // Return src to base64!\n img.setAttribute(\"src\", `data:image/svg+xml;base64,${base64String}`);\n } else {\n // 'data:image/svg+xml;charset=utf8,'.length === 32.\n const svg = decodeURIComponent(img.src.substring(32, img.src.length));\n Image.setImgSize(img, svg, true);\n }\n } else {\n // 'data:image/png;base64,' === 22.\n const base64 = img.src.substring(22, img.src.length);\n Image.setImgSize(img, base64, true);\n }\n } else {\n Image.setImgSize(img, img.src);\n }\n };\n\n // If the image doesn't contain a blob, just process it normally\n if (img.src.indexOf(\"blob:\") === -1) {\n processImg(img);\n // if it does contain a blob, then read that, replace the src with the decoded content, and process it\n } else {\n const reader = new FileReader();\n reader.onload = function () {\n img.setAttribute(\"src\", reader.result);\n processImg(img);\n };\n fetch(img.src)\n .then((r) => r.blob())\n .then((blob) => {\n reader.readAsDataURL(blob);\n });\n }\n }\n\n /**\n * Returns the metrics (height, width and baseline) contained in a SVG image generated\n * by the MathType image service. This image contains as an extra custom attribute:\n * the baseline (wrs:baseline).\n * @param {String} svgString - The SVG image.\n * @return {Array} - The image metrics.\n */\n static getMetricsFromSvgString(svgString) {\n let first = svgString.indexOf('height=\"');\n let last = svgString.indexOf('\"', first + 8, svgString.length);\n const height = svgString.substring(first + 8, last);\n\n first = svgString.indexOf('width=\"');\n last = svgString.indexOf('\"', first + 7, svgString.length);\n const width = svgString.substring(first + 7, last);\n\n first = svgString.indexOf('wrs:baseline=\"');\n last = svgString.indexOf('\"', first + 14, svgString.length);\n const baseline = svgString.substring(first + 14, last);\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n if (typeof baseline !== \"undefined\") {\n arr.cb = baseline;\n }\n return arr;\n }\n return [];\n }\n\n /**\n * Returns the metrics (width, height, baseline and dpi) contained in a PNG byte array.\n * @param {Array.} bytes - png byte array.\n * @return {Array} The png metrics.\n */\n static getMetricsFromBytes(bytes) {\n Util.readBytes(bytes, 0, 8);\n let width;\n let height;\n let typ;\n let baseline;\n let dpi;\n while (bytes.length >= 4) {\n typ = Util.readInt32(bytes);\n if (typ === 0x49484452) {\n width = Util.readInt32(bytes);\n height = Util.readInt32(bytes);\n // Read 5 bytes.\n Util.readInt32(bytes);\n Util.readByte(bytes);\n } else if (typ === 0x62615345) {\n // Baseline: 'baSE'.\n baseline = Util.readInt32(bytes);\n } else if (typ === 0x70485973) {\n // Dpis: 'pHYs'.\n dpi = Util.readInt32(bytes);\n dpi = Math.round(dpi / 39.37);\n Util.readInt32(bytes);\n Util.readByte(bytes);\n }\n Util.readInt32(bytes);\n }\n\n if (typeof width !== \"undefined\") {\n const arr = [];\n arr.cw = width;\n arr.ch = height;\n arr.dpi = dpi;\n if (baseline) {\n arr.cb = baseline;\n }\n\n return arr;\n }\n return [];\n }\n}\n","import TextCache from \"./textcache\";\nimport ServiceProvider from \"./serviceprovider\";\nimport MathML from \"./mathml\";\nimport StringManager from \"./stringmanager\";\n\n/**\n * @classdesc\n * This class represents MathType accessible class. Converts MathML to accessible text and manages\n * the associated client-side cache.\n */\nexport default class Accessibility {\n /**\n * Static property.\n * Accessibility cache, each entry contains a MathML and its correspondent accessibility text.\n * @type {TextCache}\n */\n static get cache() {\n return Accessibility._cache;\n }\n\n /**\n * Static property setter.\n * Set accessibility cache.\n * @param {TextCahe} value - The property value.\n * @ignore\n */\n static set cache(value) {\n Accessibility._cache = value;\n }\n\n /**\n * Converts MathML strings to its accessible text representation.\n * @param {String} mathML - MathML to be converted to accessible text.\n * @param {String} [language] - Language of the accessible text. 'en' by default.\n * @param {Array.} [data] - Parameters to send to mathml2accessible service.\n * @return {String} Accessibility text.\n */\n static mathMLToAccessible(mathML, language, data) {\n if (typeof language === \"undefined\") {\n language = \"en\";\n }\n // Check MathML class. If the class is chemistry,\n // we add chemistry to data to force accessibility service\n // to load chemistry grammar.\n if (MathML.containClass(mathML, \"wrs_chemistry\")) {\n data.mode = \"chemistry\";\n }\n // Ignore accesibility styles\n data.ignoreStyles = true;\n let accessibleText = \"\";\n\n if (Accessibility.cache.get(mathML)) {\n accessibleText = Accessibility.cache.get(mathML);\n } else {\n data.service = \"mathml2accessible\";\n data.lang = language;\n const accessibleJsonResponse = JSON.parse(ServiceProvider.getService(\"service\", data));\n if (accessibleJsonResponse.status !== \"error\") {\n accessibleText = accessibleJsonResponse.result.text;\n Accessibility.cache.populate(mathML, accessibleText);\n } else {\n accessibleText = StringManager.get(\"error_convert_accessibility\");\n }\n }\n\n return accessibleText;\n }\n}\n\n/**\n * Contains an instance of TextCache class to manage the JavaScript accessible cache.\n * Each entry of the cache object contains the MathML and it's correspondent accessibility text.\n * @private\n * @type {TextCache}\n */\nAccessibility._cache = new TextCache();\n","import Util from \"./util\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport Image from \"./image\";\nimport Accessibility from \"./accessibility\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Configuration from \"./configuration\";\nimport Constants from \"./constants\";\n// eslint-disable-next-line no-unused-vars\nimport md5 from \"./md5\";\n\n/**\n * @classdesc\n * This class represent a MahML parser. Converts MathML into formulas depending on the\n * image format (SVG, PNG, base64) and the save mode (XML, safeXML, Image) configured\n * in the backend.\n */\nexport default class Parser {\n /**\n * Converts a MathML string to an img element.\n * @param {Document} creator - Document object to call createElement method.\n * @param {string} mathml - MathML code\n * @param {Object[]} wirisProperties - object containing WIRIS custom properties\n * @param {language} language - custom language for accessibility.\n * @returns {HTMLImageElement} the formula image corresponding to initial MathML string.\n * @static\n */\n static mathmlToImgObject(creator, mathml, wirisProperties, language) {\n const imgObject = creator.createElement(\"img\");\n imgObject.align = \"middle\";\n imgObject.style.maxWidth = \"none\";\n let data = wirisProperties || {};\n\n // Take into account the backend config\n const wirisEditorProperties = Configuration.get(\"editorParameters\");\n data = { ...wirisEditorProperties, ...data };\n\n data.mml = mathml;\n data.lang = language;\n // Request metrics of the generated image.\n data.metrics = \"true\";\n data.centerbaseline = \"false\";\n\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n // Render js params: _wrs_int_wirisProperties contains some js render params.\n // Since MathML can support render params, js params should be send only to editor.\n\n imgObject.className = Configuration.get(\"imageClassName\");\n\n if (mathml.indexOf('class=\"') !== -1) {\n // We check here if the MathML has been created from a customEditor (such chemistry)\n // to add custom editor name attribute to img object (if necessary).\n let mathmlSubstring = mathml.substring(mathml.indexOf('class=\"') + 'class=\"'.length, mathml.length);\n mathmlSubstring = mathmlSubstring.substring(0, mathmlSubstring.indexOf('\"'));\n mathmlSubstring = mathmlSubstring.substring(4, mathmlSubstring.length);\n imgObject.setAttribute(Configuration.get(\"imageCustomEditorName\"), mathmlSubstring);\n }\n\n // Performance enabled.\n if (\n Configuration.get(\"wirisPluginPerformance\") &&\n (Configuration.get(\"saveMode\") === \"xml\" || Configuration.get(\"saveMode\") === \"safeXml\")\n ) {\n let result = JSON.parse(Parser.createShowImageSrc(data, language));\n if (result.status === \"warning\") {\n // POST call.\n // if the mathml is malformed, this function will throw an exception.\n try {\n result = JSON.parse(ServiceProvider.getService(\"showimage\", data));\n } catch (e) {\n return null;\n }\n }\n ({ result } = result);\n if (result.format === \"png\") {\n imgObject.src = `data:image/png;base64,${result.content}`;\n } else {\n imgObject.src = `data:image/svg+xml;charset=utf8,${Util.urlEncode(result.content)}`;\n }\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n Image.setImgSize(imgObject, result.content, true);\n\n if (Configuration.get(\"enableAccessibility\")) {\n if (typeof result.alt === \"undefined\") {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n } else {\n imgObject.alt = result.alt;\n }\n }\n } else {\n const result = Parser.createImageSrc(mathml, data);\n imgObject.setAttribute(Configuration.get(\"imageMathmlAttribute\"), MathML.safeXmlEncode(mathml));\n imgObject.src = result;\n Image.setImgSize(\n imgObject,\n result,\n Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\",\n );\n if (Configuration.get(\"enableAccessibility\")) {\n imgObject.alt = Accessibility.mathMLToAccessible(mathml, language, data);\n }\n }\n\n if (typeof Parser.observer !== \"undefined\") {\n Parser.observer.observe(imgObject);\n }\n\n // Role math https://www.w3.org/TR/wai-aria/roles#math.\n imgObject.setAttribute(\"role\", \"math\");\n return imgObject;\n }\n\n /**\n * Returns the source to showimage service by calling createimage service. The\n * output of the createimage service is a URL path pointing to showimage service.\n * This method is called when performance is disabled.\n * @param {string} mathml - MathML code.\n * @param {Object[]} data - data object containing service parameters.\n * @returns {string} the showimage path.\n */\n static createImageSrc(mathml, data) {\n // Full base64 method (edit & save).\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"default\") {\n data.base64 = true;\n }\n\n let result = ServiceProvider.getService(\"createimage\", data);\n\n if (result.indexOf(\"@BASE@\") !== -1) {\n // Replacing '@BASE@' with the base URL of createimage.\n const baseParts = ServiceProvider.getServicePath(\"createimage\").split(\"/\");\n baseParts.pop();\n result = result.split(\"@BASE@\").join(baseParts.join(\"/\"));\n }\n\n return result;\n }\n\n /**\n * Parses initial HTML code. If the HTML contains data generated by WIRIS,\n * this data would be converted as following:\n *
\n   * MathML code: Image containing the corresponding MathML formulas.\n   * MathML code with LaTeX annotation : LaTeX string.\n   * 
\n * @param {string} code - HTML code containing MathML data.\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code with the original MathML converted into LaTeX and images.\n */\n static initParse(code, language) {\n /* Note: The code inside this function has been inverted.\n If you invert again the code then you cannot use correctly LaTeX\n in Moodle.\n */\n code = Parser.initParseSaveMode(code, language);\n return Parser.initParseEditMode(code);\n }\n\n /**\n * Parses initial HTML code depending on the save mode. Transforms all MathML\n * occurrences for it's correspondent image or LaTeX.\n * @param {string} code - HTML code to be parsed\n * @param {string} language - language to create image alt text.\n * @returns {string} HTML code parsed.\n */\n static initParseSaveMode(code, language) {\n if (Configuration.get(\"saveMode\")) {\n // Converting XML to tags.\n code = Latex.parseMathmlToLatex(code, Constants.safeXmlCharacters);\n code = Latex.parseMathmlToLatex(code, Constants.xmlCharacters);\n code = Parser.parseMathmlToImg(code, Constants.safeXmlCharacters, language);\n code = Parser.parseMathmlToImg(code, Constants.xmlCharacters, language);\n if (Configuration.get(\"saveMode\") === \"base64\" && Configuration.get(\"base64savemode\") === \"image\") {\n code = Parser.codeImgTransform(code, \"base642showimage\");\n }\n }\n return code;\n }\n\n /**\n * Parses initial HTML code depending on the edit mode.\n * If 'latex' parseMode is enabled all MathML containing an annotation with encoding='LaTeX' will\n * be converted into a LaTeX string instead of an image.\n * @param {string} code - HTML code containing MathML.\n * @returns {string} parsed HTML code.\n */\n static initParseEditMode(code) {\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n const imgList = Util.getElementsByNameFromString(code, \"img\", true);\n const token = 'encoding=\"LaTeX\">';\n // While replacing images with latex, the indexes of the found images changes\n // respecting the original code, so this carry is needed.\n let carry = 0;\n\n for (let i = 0; i < imgList.length; i += 1) {\n const imgCode = code.substring(imgList[i].start + carry, imgList[i].end + carry);\n\n if (imgCode.indexOf(` class=\"${Configuration.get(\"imageClassName\")}\"`) !== -1) {\n let mathmlStartToken = ` ${Configuration.get(\"imageMathmlAttribute\")}=\"`;\n let mathmlStart = imgCode.indexOf(mathmlStartToken);\n\n if (mathmlStart === -1) {\n mathmlStartToken = ' alt=\"';\n mathmlStart = imgCode.indexOf(mathmlStartToken);\n }\n\n if (mathmlStart !== -1) {\n mathmlStart += mathmlStartToken.length;\n const mathmlEnd = imgCode.indexOf('\"', mathmlStart);\n const mathml = Util.htmlSanitize(MathML.safeXmlDecode(imgCode.substring(mathmlStart, mathmlEnd)));\n let latexStartPosition = mathml.indexOf(token);\n\n if (latexStartPosition !== -1) {\n latexStartPosition += token.length;\n const latexEndPosition = mathml.indexOf(\"\", latexStartPosition);\n const latex = mathml.substring(latexStartPosition, latexEndPosition);\n\n const replaceText = `$$${Util.htmlEntitiesDecode(latex)}$$`;\n const start = code.substring(0, imgList[i].start + carry);\n const end = code.substring(imgList[i].end + carry);\n code = start + replaceText + end;\n carry += replaceText.length - (imgList[i].end - imgList[i].start);\n }\n }\n }\n }\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code. The end HTML code is HTML code with embedded images\n * or LaTeX formulas created with MathType.
\n * By default this method converts the formula images and LaTeX strings in MathML.
\n * If image mode is enabled the images will not be converted into MathML. For further information see {@link https://docs.wiris.com/mathtype/en/mathtype-integrations/mathtype-web-interface-features/full-mathml-mode---wirisplugins-js.html}.\n * @param {string} code - HTML to be parsed\n * @returns {string} the HTML code parsed.\n */\n static endParse(code) {\n // Transform LaTeX ocurrences to MathML elements.\n const codeEndParsedEditMode = Parser.endParseEditMode(code);\n // Transform img elements to MathML elements.\n const codeEndParseSaveMode = Parser.endParseSaveMode(codeEndParsedEditMode);\n return codeEndParseSaveMode;\n }\n\n /**\n * Parses end HTML code depending on the edit mode.\n * - LaTeX is an enabled parse mode, all LaTeX occurrences will be converted into MathML.\n * @param {string} code - HTML code to be parsed.\n * @returns {string} HTML code parsed.\n */\n static endParseEditMode(code) {\n // Converting LaTeX to images.\n if (Configuration.get(\"parseModes\").indexOf(\"latex\") !== -1) {\n let output = \"\";\n let endPosition = 0;\n let startPosition = code.indexOf(\"$$\");\n while (startPosition !== -1) {\n output += code.substring(endPosition, startPosition);\n endPosition = code.indexOf(\"$$\", startPosition + 2);\n\n if (endPosition !== -1) {\n // Before, it was a condition here to execute the next codelines\n // 'latex.indexOf('<') == -1'.\n // We don't know why it was used, but seems to have a conflict with\n // latex formulas that contains '<'.\n const latex = code.substring(startPosition + 2, endPosition);\n const decodedLatex = Util.htmlEntitiesDecode(latex);\n let mathml = Util.htmlSanitize(Latex.getMathMLFromLatex(decodedLatex, true));\n if (!Configuration.get(\"saveHandTraces\")) {\n // Remove hand traces.\n mathml = MathML.removeAnnotation(mathml, \"application/json\");\n }\n output += mathml;\n endPosition += 2;\n } else {\n output += \"$$\";\n endPosition = startPosition + 2;\n }\n\n startPosition = code.indexOf(\"$$\", endPosition);\n }\n\n output += code.substring(endPosition, code.length);\n code = output;\n }\n\n return code;\n }\n\n /**\n * Parses end HTML code depending on the save mode. Converts all\n * images into the element determined by the save mode:\n * - xml: Parses images formulas into MathML.\n * - safeXml: Parses images formulas into safeMAthML\n * - base64: Parses images into base64 images.\n * - image: Parse images into images (no parsing)\n * @param {string} code - HTML code to be parsed\n * @returns {string} HTML code parsed.\n */\n static endParseSaveMode(code) {\n const savemode = Configuration.get(\"saveMode\");\n const base64savemode = Configuration.get(\"base64savemode\");\n\n if (savemode) {\n if (savemode === \"safeXml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"xml\") {\n code = Parser.codeImgTransform(code, \"img2mathml\");\n } else if (savemode === \"base64\" && base64savemode === \"image\") {\n code = Parser.codeImgTransform(code, \"img264\");\n }\n }\n\n return code;\n }\n\n /**\n * Auxiliar function that builds the data object to send to the showimage endpoint\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object with the data to send to showimage.\n */\n static createShowImageSrcData(data, language) {\n const dataMd5 = {};\n const renderParams = [\n \"mml\",\n \"color\",\n \"centerbaseline\",\n \"zoom\",\n \"dpi\",\n \"fontSize\",\n \"fontFamily\",\n \"defaultStretchy\",\n \"backgroundColor\",\n \"format\",\n ];\n renderParams.forEach((param) => {\n if (typeof data[param] !== \"undefined\") {\n dataMd5[param] = data[param];\n }\n });\n // Data variables to get.\n const dataObject = {};\n Object.keys(data).forEach((key) => {\n // We don't need mathml in this request we try to get cached.\n // Only need the formula md5 calculated before.\n if (key !== \"mml\") {\n dataObject[key] = data[key];\n }\n });\n\n dataObject.formula = com.wiris.js.JsPluginTools.md5encode(Util.propertiesToString(dataMd5));\n dataObject.lang = typeof language === \"undefined\" ? \"en\" : language;\n dataObject.version = Configuration.get(\"version\");\n\n return dataObject;\n }\n\n /**\n * Returns the result to call showimage service with the formula md5 as parameter.\n * The result could be:\n * - {'status' : warning'} : The image associated to the MathML md5 is not in cache.\n * - {'status' : 'ok' ...} : The image associated to the MathML md5 is in cache.\n * @param {Object[]} data - object containing showimage service parameters.\n * @param {string} language - string containing the language of the formula.\n * @returns {Object} JSON object containing showimage response.\n */\n static createShowImageSrc(data, language) {\n const dataObject = this.createShowImageSrcData(data, language);\n const result = ServiceProvider.getService(\"showimage\", Util.httpBuildQuery(dataObject), true);\n return result;\n }\n\n /**\n * Transform html img tags inside a html code to mathml, base64 img tags (i.e with base64 on src)\n * or showimage img tags (i.e with showimage.php on src)\n * @param {string} code - HTML code\n * @param {string} mode - base642showimage or img2mathml or img264 transform.\n * @returns {string} html - code transformed.\n */\n static codeImgTransform(code, mode) {\n let output = \"\";\n let endPosition = 0;\n const pattern = /\") {\n endPosition = i + 1;\n }\n\n i += 1;\n }\n\n if (endPosition < startPosition) {\n // The img tag is stripped.\n output += code.substring(startPosition, code.length);\n return output;\n }\n let imgCode = code.substring(startPosition, endPosition);\n const imgObject = Util.createObject(imgCode);\n let xmlCode = imgObject.getAttribute(Configuration.get(\"imageMathmlAttribute\"));\n let convertToXml;\n let convertToSafeXml;\n\n if (mode === \"base642showimage\") {\n if (xmlCode == null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n imgCode = Parser.mathmlToImgObject(document, xmlCode, null, null);\n output += Util.createObjectCode(imgCode);\n } else if (mode === \"img2mathml\") {\n if (Configuration.get(\"saveMode\")) {\n if (Configuration.get(\"saveMode\") === \"safeXml\") {\n convertToXml = true;\n convertToSafeXml = true;\n } else if (Configuration.get(\"saveMode\") === \"xml\") {\n convertToXml = true;\n convertToSafeXml = false;\n }\n }\n output += Util.getWIRISImageOutput(imgCode, convertToXml, convertToSafeXml);\n } else if (mode === \"img264\") {\n if (xmlCode === null) {\n xmlCode = imgObject.getAttribute(\"alt\");\n }\n xmlCode = MathML.safeXmlDecode(xmlCode);\n\n const properties = {};\n properties.base64 = \"true\";\n imgCode = Parser.mathmlToImgObject(document, xmlCode, properties, null);\n // Metrics.\n Image.setImgSize(imgCode, imgCode.src, true);\n output += Util.createObjectCode(imgCode);\n }\n }\n output += code.substring(endPosition, code.length);\n return output;\n }\n\n /**\n * Converts all occurrences of MathML to the corresponding image.\n * @param {string} content - string with valid MathML code.\n * The MathML code doesn't contain semantics.\n * @param {Constants} characters - Constant object containing xmlCharacters\n * or safeXmlCharacters relation.\n * @param {string} language - a valid language code\n * in order to generate formula accessibility.\n * @returns {string} The input string with all the MathML\n * occurrences replaced by the corresponding image.\n */\n static parseMathmlToImg(content, characters, language) {\n let output = \"\";\n const mathTagBegin = `${characters.tagOpener}math`;\n const mathTagEnd = `${characters.tagOpener}/math${characters.tagCloser}`;\n let start = content.indexOf(mathTagBegin);\n let end = 0;\n\n while (start !== -1) {\n output += content.substring(end, start);\n // Avoid WIRIS images to be parsed.\n const imageMathmlAtrribute = content.indexOf(Configuration.get(\"imageMathmlAttribute\"));\n end = content.indexOf(mathTagEnd, start);\n\n if (end === -1) {\n end = content.length - 1;\n } else if (imageMathmlAtrribute !== -1) {\n // First close tag of img attribute\n // If a mathmlAttribute exists should be inside a img tag.\n end += content.indexOf(\"/>\", start);\n } else {\n end += mathTagEnd.length;\n }\n\n if (!MathML.isMathmlInAttribute(content, start) && imageMathmlAtrribute === -1) {\n let mathml = content.substring(start, end);\n mathml =\n characters.id === Constants.safeXmlCharacters.id\n ? MathML.safeXmlDecode(mathml)\n : MathML.mathMLEntities(mathml);\n output += Util.createObjectCode(Parser.mathmlToImgObject(document, mathml, null, language));\n } else {\n output += content.substring(start, end);\n }\n\n start = content.indexOf(mathTagBegin, end);\n }\n\n output += content.substring(end, content.length);\n return output;\n }\n}\n\n// Mutation observers to avoid wiris image formulas class be removed.\nif (typeof MutationObserver !== \"undefined\") {\n const mutationObserver = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n if (\n mutation.oldValue === Configuration.get(\"imageClassName\") &&\n mutation.attributeName === \"class\" &&\n mutation.target.className.indexOf(Configuration.get(\"imageClassName\")) === -1\n ) {\n mutation.target.className = Configuration.get(\"imageClassName\");\n }\n });\n });\n\n Parser.observer = Object.create(mutationObserver);\n Parser.observer.Config = { attributes: true, attributeOldValue: true };\n // We use own default config.\n Parser.observer.observe = function (target) {\n Object.getPrototypeOf(this).observe(target, this.Config);\n };\n}\n","/* eslint-disable class-methods-use-this */\n/* eslint-disable no-unused-vars */\n/* eslint-disable no-extra-semi */\n\n// The rules above are disabled because we are implementing\n// an external interface.\n\nexport default class EditorListener {\n /**\n * @classdesc\n * Determines if the content of the\n * MathType Editor has changes.\n * @implements {EditorListeners}\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the content of the editor has changed.\n * @type {Boolean}\n */\n this.isContentChanged = false;\n\n /**\n * Indicates if the listener should be waiting for changes in the editor.\n * @type {Boolean}\n */\n this.waitingForChanges = false;\n }\n\n /**\n * Sets {@link EditorListener.isContentChanged} property.\n * @param {Boolean} value - The new vlue.\n */\n setIsContentChanged(value) {\n this.isContentChanged = value;\n }\n\n /**\n * Returns true if the content of the editor has been changed, false otherwise.\n * @return {Boolean}\n */\n getIsContentChanged() {\n return this.isContentChanged;\n }\n\n /**\n * Determines if the EditorListener should wait for any changes.\n * @param {Boolean} value - True if the editor should wait for changes, false otherwise.\n */\n setWaitingForChanges(value) {\n this.waitingForChanges = value;\n }\n\n /**\n * EditorListener method to overwrite.\n * @type {JsEditor}\n * @ignore\n */\n caretPositionChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @type {JsEditor}\n * @ignore\n */\n clipboardChanged(_editor) {}\n\n /**\n * Determines if the content of an editor has been changed.\n * @param {JsEditor} editor - editor object.\n */\n contentChanged(_editor) {\n if (this.waitingForChanges === true && this.isContentChanged === false) {\n this.isContentChanged = true;\n }\n }\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} editor - The editor instance.\n */\n styleChanged(_editor) {}\n\n /**\n * EditorListener method to overwrite\n * @param {JsEditor} - The editor instance.\n */\n transformationReceived(_editor) {}\n}\n","let wasm;\n\nconst cachedTextDecoder =\n typeof TextDecoder !== \"undefined\"\n ? new TextDecoder(\"utf-8\", { ignoreBOM: true, fatal: true })\n : {\n decode: () => {\n throw Error(\"TextDecoder not available\");\n },\n };\n\nif (typeof TextDecoder !== \"undefined\") {\n cachedTextDecoder.decode();\n}\n\nlet cachedUint8Memory0 = null;\n\nfunction getUint8Memory0() {\n if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {\n cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8Memory0;\n}\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));\n}\n\nconst heap = new Array(128).fill(undefined);\n\nheap.push(undefined, null, true, false);\n\nlet heap_next = heap.length;\n\nfunction addHeapObject(obj) {\n if (heap_next === heap.length) heap.push(heap.length + 1);\n const idx = heap_next;\n heap_next = heap[idx];\n\n heap[idx] = obj;\n return idx;\n}\n\nfunction getObject(idx) {\n return heap[idx];\n}\n\nfunction dropObject(idx) {\n if (idx < 132) return;\n heap[idx] = heap_next;\n heap_next = idx;\n}\n\nfunction takeObject(idx) {\n const ret = getObject(idx);\n dropObject(idx);\n return ret;\n}\n\nlet WASM_VECTOR_LEN = 0;\n\nconst cachedTextEncoder =\n typeof TextEncoder !== \"undefined\"\n ? new TextEncoder(\"utf-8\")\n : {\n encode: () => {\n throw Error(\"TextEncoder not available\");\n },\n };\n\nconst encodeString =\n typeof cachedTextEncoder.encodeInto === \"function\"\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n }\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length,\n };\n };\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8Memory0()\n .subarray(ptr, ptr + buf.length)\n .set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8Memory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7f) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0;\n const view = getUint8Memory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nfunction isLikeNone(x) {\n return x === undefined || x === null;\n}\n\nlet cachedInt32Memory0 = null;\n\nfunction getInt32Memory0() {\n if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {\n cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);\n }\n return cachedInt32Memory0;\n}\n\nlet cachedFloat64Memory0 = null;\n\nfunction getFloat64Memory0() {\n if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {\n cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);\n }\n return cachedFloat64Memory0;\n}\n\nlet cachedBigInt64Memory0 = null;\n\nfunction getBigInt64Memory0() {\n if (cachedBigInt64Memory0 === null || cachedBigInt64Memory0.byteLength === 0) {\n cachedBigInt64Memory0 = new BigInt64Array(wasm.memory.buffer);\n }\n return cachedBigInt64Memory0;\n}\n\nfunction debugString(val) {\n // primitive types\n const type = typeof val;\n if (type == \"number\" || type == \"boolean\" || val == null) {\n return `${val}`;\n }\n if (type == \"string\") {\n return `\"${val}\"`;\n }\n if (type == \"symbol\") {\n const description = val.description;\n if (description == null) {\n return \"Symbol\";\n } else {\n return `Symbol(${description})`;\n }\n }\n if (type == \"function\") {\n const name = val.name;\n if (typeof name == \"string\" && name.length > 0) {\n return `Function(${name})`;\n } else {\n return \"Function\";\n }\n }\n // objects\n if (Array.isArray(val)) {\n const length = val.length;\n let debug = \"[\";\n if (length > 0) {\n debug += debugString(val[0]);\n }\n for (let i = 1; i < length; i++) {\n debug += \", \" + debugString(val[i]);\n }\n debug += \"]\";\n return debug;\n }\n // Test for built-in\n const builtInMatches = /\\[object ([^\\]]+)\\]/.exec(toString.call(val));\n let className;\n if (builtInMatches.length > 1) {\n className = builtInMatches[1];\n } else {\n // Failed to match the standard '[object ClassName]'\n return toString.call(val);\n }\n if (className == \"Object\") {\n // we're a user defined class or Object\n // JSON.stringify avoids problems with cycles, and is generally much\n // easier than looping through ownProperties of `val`.\n try {\n return \"Object(\" + JSON.stringify(val) + \")\";\n } catch (_) {\n return \"Object\";\n }\n }\n // errors\n if (val instanceof Error) {\n return `${val.name}: ${val.message}\\n${val.stack}`;\n }\n // TODO we could test for more things here, like `Set`s and `Map`s.\n return className;\n}\n\nfunction makeClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n try {\n return f(state.a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(state.a, state.b);\n state.a = 0;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_46(arg0, arg1, arg2) {\n wasm.__wbindgen_export_3(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction makeMutClosure(arg0, arg1, dtor, f) {\n const state = { a: arg0, b: arg1, cnt: 1, dtor };\n const real = (...args) => {\n // First up with a closure we increment the internal reference\n // count. This ensures that the Rust closure environment won't\n // be deallocated while we're invoking it.\n state.cnt++;\n const a = state.a;\n state.a = 0;\n try {\n return f(a, state.b, ...args);\n } finally {\n if (--state.cnt === 0) {\n wasm.__wbindgen_export_2.get(state.dtor)(a, state.b);\n } else {\n state.a = a;\n }\n }\n };\n real.original = state;\n\n return real;\n}\nfunction __wbg_adapter_49(arg0, arg1) {\n wasm.__wbindgen_export_4(arg0, arg1);\n}\n\nfunction __wbg_adapter_52(arg0, arg1, arg2) {\n wasm.__wbindgen_export_5(arg0, arg1, addHeapObject(arg2));\n}\n\nfunction handleError(f, args) {\n try {\n return f.apply(this, args);\n } catch (e) {\n wasm.__wbindgen_export_6(addHeapObject(e));\n }\n}\nfunction __wbg_adapter_103(arg0, arg1, arg2, arg3) {\n wasm.__wbindgen_export_7(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));\n}\n\n/**\n */\nexport function main_js() {\n wasm.main_js();\n}\n\nfunction getArrayU8FromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);\n}\n/**\n */\nexport const Level = Object.freeze({\n Err: 0,\n 0: \"Err\",\n Warn: 1,\n 1: \"Warn\",\n Info: 2,\n 2: \"Info\",\n Debug: 3,\n 3: \"Debug\",\n});\n/**\n */\nexport class Telemeter {\n __destroy_into_raw() {\n const ptr = this.__wbg_ptr;\n this.__wbg_ptr = 0;\n\n return ptr;\n }\n\n free() {\n const ptr = this.__destroy_into_raw();\n wasm.__wbg_telemeter_free(ptr);\n }\n /**\n * @param {any} solution\n * @param {any} hosts\n * @param {any} config\n */\n constructor(solution, hosts, config) {\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n wasm.telemeter_new(retptr, addHeapObject(solution), addHeapObject(hosts), addHeapObject(config));\n var r0 = getInt32Memory0()[retptr / 4 + 0];\n var r1 = getInt32Memory0()[retptr / 4 + 1];\n var r2 = getInt32Memory0()[retptr / 4 + 2];\n if (r2) {\n throw takeObject(r1);\n }\n this.__wbg_ptr = r0 >>> 0;\n return this;\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n }\n }\n /**\n * @param {string} sender_id\n * @returns {Promise}\n */\n identify(sender_id) {\n const ptr0 = passStringToWasm0(sender_id, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_identify(this.__wbg_ptr, ptr0, len0);\n return takeObject(ret);\n }\n /**\n * @param {string} event_type\n * @param {any} event_payload\n * @returns {Promise}\n */\n track(event_type, event_payload) {\n const ptr0 = passStringToWasm0(event_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_track(this.__wbg_ptr, ptr0, len0, addHeapObject(event_payload));\n return takeObject(ret);\n }\n /**\n * @param {any} level\n * @param {string} message\n * @param {any} payload\n * @returns {Promise}\n */\n log(level, message, payload) {\n const ptr0 = passStringToWasm0(message, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.telemeter_log(this.__wbg_ptr, addHeapObject(level), ptr0, len0, addHeapObject(payload));\n return takeObject(ret);\n }\n /**\n * @returns {Promise}\n */\n finish() {\n const ptr = this.__destroy_into_raw();\n const ret = wasm.telemeter_finish(ptr);\n return takeObject(ret);\n }\n /**\n * @param {boolean | undefined} [new_debug_status]\n */\n debug(new_debug_status) {\n wasm.telemeter_debug(this.__wbg_ptr, isLikeNone(new_debug_status) ? 0xffffff : new_debug_status ? 1 : 0);\n }\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === \"function\" && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === \"function\") {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n } catch (e) {\n if (module.headers.get(\"Content-Type\") != \"application/wasm\") {\n console.warn(\n \"`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\",\n e,\n );\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n } else {\n return instance;\n }\n }\n}\n\nfunction __wbg_get_imports() {\n const imports = {};\n imports.wbg = {};\n imports.wbg.__wbindgen_string_new = function (arg0, arg1) {\n const ret = getStringFromWasm0(arg0, arg1);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_c728d68b8b34487e = function () {\n const ret = new Object();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_status_7841bb47be2a8f16 = function (arg0) {\n const ret = getObject(arg0).status;\n return ret;\n };\n imports.wbg.__wbg_headers_ea7ef583d1564b08 = function (arg0) {\n const ret = getObject(arg0).headers;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new0_ad75dd38f92424e2 = function () {\n const ret = new Date();\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getTime_ed6ee333b702f8fc = function (arg0) {\n const ret = getObject(arg0).getTime();\n return ret;\n };\n imports.wbg.__wbindgen_object_drop_ref = function (arg0) {\n takeObject(arg0);\n };\n imports.wbg.__wbindgen_is_object = function (arg0) {\n const val = getObject(arg0);\n const ret = typeof val === \"object\" && val !== null;\n return ret;\n };\n imports.wbg.__wbg_crypto_58f13aa23ffcb166 = function (arg0) {\n const ret = getObject(arg0).crypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_process_5b786e71d465a513 = function (arg0) {\n const ret = getObject(arg0).process;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_versions_c2ab80650590b6a2 = function (arg0) {\n const ret = getObject(arg0).versions;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_node_523d7bd03ef69fba = function (arg0) {\n const ret = getObject(arg0).node;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_string = function (arg0) {\n const ret = typeof getObject(arg0) === \"string\";\n return ret;\n };\n imports.wbg.__wbg_msCrypto_abcb1295e768d1f2 = function (arg0) {\n const ret = getObject(arg0).msCrypto;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_require_2784e593a4674877 = function () {\n return handleError(function () {\n const ret = module.require;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_newwithlength_13b5319ab422dcf6 = function (arg0) {\n const ret = new Uint8Array(arg0 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_4a9aa5157afeb382 = function (arg0, arg1) {\n const ret = getObject(arg0)[arg1 >>> 0];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_next_1989a20442400aaa = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).next();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_done_bc26bf4ada718266 = function (arg0) {\n const ret = getObject(arg0).done;\n return ret;\n };\n imports.wbg.__wbg_value_0570714ff7d75f35 = function (arg0) {\n const ret = getObject(arg0).value;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_iterator_7ee1a391d310f8e4 = function () {\n const ret = Symbol.iterator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_get_2aff440840bb6202 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.get(getObject(arg0), getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_next_15da6a3df9290720 = function (arg0) {\n const ret = getObject(arg0).next;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_is_function = function (arg0) {\n const ret = typeof getObject(arg0) === \"function\";\n return ret;\n };\n imports.wbg.__wbg_call_669127b9d730c650 = function () {\n return handleError(function (arg0, arg1) {\n const ret = getObject(arg0).call(getObject(arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_object_clone_ref = function (arg0) {\n const ret = getObject(arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_self_3fad056edded10bd = function () {\n return handleError(function () {\n const ret = self.self;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_window_a4f46c98a61d4089 = function () {\n return handleError(function () {\n const ret = window.window;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_globalThis_17eff828815f7d84 = function () {\n return handleError(function () {\n const ret = globalThis.globalThis;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_global_46f939f6541643c5 = function () {\n return handleError(function () {\n const ret = global.global;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_is_undefined = function (arg0) {\n const ret = getObject(arg0) === undefined;\n return ret;\n };\n imports.wbg.__wbg_newnoargs_ccdcae30fd002262 = function (arg0, arg1) {\n const ret = new Function(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_isArray_38525be7442aa21e = function (arg0) {\n const ret = Array.isArray(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_call_53fc3abd42e24ec8 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_isSafeInteger_c38b0a16d0c7cef7 = function (arg0) {\n const ret = Number.isSafeInteger(getObject(arg0));\n return ret;\n };\n imports.wbg.__wbg_new_feb65b865d980ae2 = function (arg0, arg1) {\n try {\n var state0 = { a: arg0, b: arg1 };\n var cb0 = (arg0, arg1) => {\n const a = state0.a;\n state0.a = 0;\n try {\n return __wbg_adapter_103(a, state0.b, arg0, arg1);\n } finally {\n state0.a = a;\n }\n };\n const ret = new Promise(cb0);\n return addHeapObject(ret);\n } finally {\n state0.a = state0.b = 0;\n }\n };\n imports.wbg.__wbindgen_memory = function () {\n const ret = wasm.memory;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_buffer_344d9b41efe96da7 = function (arg0) {\n const ret = getObject(arg0).buffer;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_d8a000788389a31e = function (arg0) {\n const ret = new Uint8Array(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_set_dcfd613a3420f908 = function (arg0, arg1, arg2) {\n getObject(arg0).set(getObject(arg1), arg2 >>> 0);\n };\n imports.wbg.__wbg_length_a5587d6cd79ab197 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbindgen_string_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"string\" ? obj : undefined;\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_stringify_4039297315a25b00 = function () {\n return handleError(function (arg0) {\n const ret = JSON.stringify(getObject(arg0));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_set_40f7786a25a9cc7e = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_has_cdf8b85f6e903c80 = function () {\n return handleError(function (arg0, arg1) {\n const ret = Reflect.has(getObject(arg0), getObject(arg1));\n return ret;\n }, arguments);\n };\n imports.wbg.__wbg_fetch_701fcd2bde06379a = function (arg0, arg1) {\n const ret = getObject(arg0).fetch(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_fetch_b5d6bebed1e6c2d2 = function (arg0) {\n const ret = fetch(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_newwithbyteoffsetandlength_2dc04d99088b15e3 = function (arg0, arg1, arg2) {\n const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_new_e4960143e41697a4 = function () {\n return handleError(function () {\n const ret = new AbortController();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_signal_1ed842bebd6ae322 = function (arg0) {\n const ret = getObject(arg0).signal;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_abort_8355f201f30300bb = function (arg0) {\n getObject(arg0).abort();\n };\n imports.wbg.__wbindgen_error_new = function (arg0, arg1) {\n const ret = new Error(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_loose_eq = function (arg0, arg1) {\n const ret = getObject(arg0) == getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_boolean_get = function (arg0) {\n const v = getObject(arg0);\n const ret = typeof v === \"boolean\" ? (v ? 1 : 0) : 2;\n return ret;\n };\n imports.wbg.__wbindgen_number_get = function (arg0, arg1) {\n const obj = getObject(arg1);\n const ret = typeof obj === \"number\" ? obj : undefined;\n getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbg_instanceof_Uint8Array_19e6f142a5e7e1e1 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Uint8Array;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_instanceof_ArrayBuffer_c7cc317e5c29cc0d = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof ArrayBuffer;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_entries_6d727b73ee02b7ce = function (arg0) {\n const ret = Object.entries(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_String_917f38a1211cf44b = function (arg0, arg1) {\n const ret = String(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_warn_ade8d3b7ecee11ff = function (arg0, arg1) {\n console.warn(getObject(arg0), getObject(arg1));\n };\n imports.wbg.__wbg_readyState_13e55da5ad6d64e2 = function (arg0) {\n const ret = getObject(arg0).readyState;\n return ret;\n };\n imports.wbg.__wbg_warn_4affe1093892a4ef = function (arg0) {\n console.warn(getObject(arg0));\n };\n imports.wbg.__wbg_close_f4135085ec3fc8f0 = function () {\n return handleError(function (arg0) {\n getObject(arg0).close();\n }, arguments);\n };\n imports.wbg.__wbg_new_b9b318679315404f = function () {\n return handleError(function (arg0, arg1) {\n const ret = new WebSocket(getStringFromWasm0(arg0, arg1));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setbinaryType_dcb62e0f2b346301 = function (arg0, arg1) {\n getObject(arg0).binaryType = takeObject(arg1);\n };\n imports.wbg.__wbg_log_7811587c4c6d2844 = function (arg0) {\n console.log(getObject(arg0));\n };\n imports.wbg.__wbg_error_f0a6627f4b23c19d = function (arg0) {\n console.error(getObject(arg0));\n };\n imports.wbg.__wbg_info_3ca7870690403fee = function (arg0) {\n console.info(getObject(arg0));\n };\n imports.wbg.__wbg_document_183cf1eecfdbffee = function (arg0) {\n const ret = getObject(arg0).document;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n };\n imports.wbg.__wbg_visibilityState_9721703a5ef75faf = function (arg0) {\n const ret = getObject(arg0).visibilityState;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getwithrefkey_3b3c46ba20582127 = function (arg0, arg1) {\n const ret = getObject(arg0)[getObject(arg1)];\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_length_cace2e0b3ddc0502 = function (arg0) {\n const ret = getObject(arg0).length;\n return ret;\n };\n imports.wbg.__wbg_addEventListener_0f2891b0794e07fa = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).addEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbg_removeEventListener_104d11302bb212d1 = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n getObject(arg0).removeEventListener(getStringFromWasm0(arg1, arg2), getObject(arg3));\n }, arguments);\n };\n imports.wbg.__wbindgen_is_bigint = function (arg0) {\n const ret = typeof getObject(arg0) === \"bigint\";\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_i64 = function (arg0) {\n const ret = arg0;\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_in = function (arg0, arg1) {\n const ret = getObject(arg0) in getObject(arg1);\n return ret;\n };\n imports.wbg.__wbindgen_bigint_from_u64 = function (arg0) {\n const ret = BigInt.asUintN(64, arg0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_jsval_eq = function (arg0, arg1) {\n const ret = getObject(arg0) === getObject(arg1);\n return ret;\n };\n imports.wbg.__wbg_localStorage_e11f72e996a4f5d9 = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).localStorage;\n return isLikeNone(ret) ? 0 : addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_getItem_c81cd3ae30cd579a = function () {\n return handleError(function (arg0, arg1, arg2, arg3) {\n const ret = getObject(arg1).getItem(getStringFromWasm0(arg2, arg3));\n var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n var len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n }, arguments);\n };\n imports.wbg.__wbg_navigator_7078da62d92ff5ad = function (arg0) {\n const ret = getObject(arg0).navigator;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_mediaDevices_e00b1f64d2b9939f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).mediaDevices;\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_enumerateDevices_619d52f5eef34c2f = function () {\n return handleError(function (arg0) {\n const ret = getObject(arg0).enumerateDevices();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_setItem_fe04f524052a3839 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).setItem(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbindgen_cb_drop = function (arg0) {\n const obj = takeObject(arg0).original;\n if (obj.cnt-- == 1) {\n obj.a = 0;\n return true;\n }\n const ret = false;\n return ret;\n };\n imports.wbg.__wbg_deviceId_58f7da2228a26c02 = function (arg0, arg1) {\n const ret = getObject(arg1).deviceId;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_instanceof_Response_944e2745b5db71f5 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Response;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_randomFillSync_a0d98aa11c81fe89 = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).randomFillSync(takeObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbg_subarray_6ca5cfa7fbb9abbe = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_getRandomValues_504510b5564925af = function () {\n return handleError(function (arg0, arg1) {\n getObject(arg0).getRandomValues(getObject(arg1));\n }, arguments);\n };\n imports.wbg.__wbindgen_bigint_get_as_i64 = function (arg0, arg1) {\n const v = getObject(arg1);\n const ret = typeof v === \"bigint\" ? v : undefined;\n getBigInt64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? BigInt(0) : ret;\n getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret);\n };\n imports.wbg.__wbindgen_debug_string = function (arg0, arg1) {\n const ret = debugString(getObject(arg1));\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbindgen_throw = function (arg0, arg1) {\n throw new Error(getStringFromWasm0(arg0, arg1));\n };\n imports.wbg.__wbg_then_89e1c559530b85cf = function (arg0, arg1) {\n const ret = getObject(arg0).then(getObject(arg1));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_e5949c35d772a669 = function (arg0) {\n queueMicrotask(getObject(arg0));\n };\n imports.wbg.__wbg_then_1bbc9edafd859b06 = function (arg0, arg1, arg2) {\n const ret = getObject(arg0).then(getObject(arg1), getObject(arg2));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_queueMicrotask_2be8b97a81fe4d00 = function (arg0) {\n const ret = getObject(arg0).queueMicrotask;\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_resolve_a3252b2860f0a09e = function (arg0) {\n const ret = Promise.resolve(getObject(arg0));\n return addHeapObject(ret);\n };\n imports.wbg.__wbg_url_1f609e63ff1a7983 = function (arg0, arg1) {\n const ret = getObject(arg1).url;\n const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n getInt32Memory0()[arg0 / 4 + 1] = len1;\n getInt32Memory0()[arg0 / 4 + 0] = ptr1;\n };\n imports.wbg.__wbg_send_2860805104507701 = function () {\n return handleError(function (arg0, arg1, arg2) {\n getObject(arg0).send(getArrayU8FromWasm0(arg1, arg2));\n }, arguments);\n };\n imports.wbg.__wbg_instanceof_Window_cde2416cf5126a72 = function (arg0) {\n let result;\n try {\n result = getObject(arg0) instanceof Window;\n } catch (_) {\n result = false;\n }\n const ret = result;\n return ret;\n };\n imports.wbg.__wbg_new_19676474aa414d62 = function () {\n return handleError(function () {\n const ret = new Headers();\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbg_append_feec4143bbf21904 = function () {\n return handleError(function (arg0, arg1, arg2, arg3, arg4) {\n getObject(arg0).append(getStringFromWasm0(arg1, arg2), getStringFromWasm0(arg3, arg4));\n }, arguments);\n };\n imports.wbg.__wbg_newwithstrandinit_29038da14d09e330 = function () {\n return handleError(function (arg0, arg1, arg2) {\n const ret = new Request(getStringFromWasm0(arg0, arg1), getObject(arg2));\n return addHeapObject(ret);\n }, arguments);\n };\n imports.wbg.__wbindgen_closure_wrapper1532 = function (arg0, arg1, arg2) {\n const ret = makeClosure(arg0, arg1, 76, __wbg_adapter_46);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1602 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_49);\n return addHeapObject(ret);\n };\n imports.wbg.__wbindgen_closure_wrapper1834 = function (arg0, arg1, arg2) {\n const ret = makeMutClosure(arg0, arg1, 76, __wbg_adapter_52);\n return addHeapObject(ret);\n };\n\n return imports;\n}\n\nfunction __wbg_init_memory(imports, maybe_memory) {}\n\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n __wbg_init.__wbindgen_wasm_module = module;\n cachedBigInt64Memory0 = null;\n cachedFloat64Memory0 = null;\n cachedInt32Memory0 = null;\n cachedUint8Memory0 = null;\n\n wasm.__wbindgen_start();\n return wasm;\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n const imports = __wbg_get_imports();\n\n __wbg_init_memory(imports);\n\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n\n const instance = new WebAssembly.Instance(module, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(input) {\n if (wasm !== undefined) return wasm;\n\n if (typeof input === \"undefined\") {\n input = new URL(\"telemeter_wasm_bg.wasm\", import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (\n typeof input === \"string\" ||\n (typeof Request === \"function\" && input instanceof Request) ||\n (typeof URL === \"function\" && input instanceof URL)\n ) {\n input = fetch(input);\n }\n\n __wbg_init_memory(imports);\n\n const { instance, module } = await __wbg_load(await input, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync };\nexport default __wbg_init;\n","/* eslint-disable-next-line */\nimport init, { Telemeter as TelemeterWASM } from \"../telemeter-wasm\";\n\n/**\n * @classdesc\n * This class implements the @wiris/telemeter-wasm. A utility that helps our Solutions to send the data\n * to Telemetry in a more comfortable and homogeneous way.\n */\nexport default class Telemeter {\n /**\n * Inits Telemeter class.\n * The parameters structures are defiended on {@link [Telemeter API](https://github.com/wiris/telemeter/blob/main/docs/USAGE.md#telemeter-api)}\n * @param {Object} telemeterAttributes.solution - The product that send data to Telemetry.\n * @param {Object} telemeterAttributes.hosts - Data about the environment where solution is integrated.\n * @param {Object} telemeterAttributes.config - Configuration parameters.\n */\n static init(telemeterAttributes) {\n if (!this.telemeter && !this.waitingForInit) {\n this.waitingForInit = true;\n init(telemeterAttributes.url)\n .then(() => {\n this.telemeter = new TelemeterWASM(\n telemeterAttributes.solution,\n telemeterAttributes.hosts,\n telemeterAttributes.config,\n );\n })\n .catch((error) => {\n console.log(error);\n })\n .finally(() => (this.waitingForInit = false));\n }\n }\n\n /**\n * Closes the Telemetry Session. After calling this method no data will be added to the Telemetry Session.\n */\n static async finish() {\n if (!this.telemeter) return;\n\n try {\n const local_telemeter = this.telemeter;\n this.telemeter = undefined;\n await local_telemeter.finish();\n } catch (e) {\n console.error(e);\n }\n }\n}\n","import Configuration from \"./configuration\";\nimport Core from \"./core.src\";\nimport EditorListener from \"./editorlistener\";\nimport Listeners from \"./listeners\";\nimport MathML from \"./mathml\";\nimport Util from \"./util\";\nimport Telemeter from \"./telemeter\";\n\nexport default class ContentManager {\n /**\n * @classdesc\n * This class represents a modal dialog, managing the following:\n * - The insertion of content into the current instance of the {@link ModalDialog} class.\n * - The actions to be done once the modal object has been submitted\n * (submitAction} method).\n * - The update of the content when the {@link ModalDialog} class is also updated,\n * for example when ModalDialog is re-opened.\n * - The communication between the {@link ModalDialog} class and itself, if the content\n * has been changed (hasChanges} method).\n * @constructs\n * @param {Object} contentManagerAttributes - Object containing all attributes needed to\n * create a new instance.\n */\n constructor(contentManagerAttributes) {\n /**\n * An object containing MathType editor parameters. See\n * http://docs.wiris.com/en/mathtype/mathtype_web/sdk-api/parameters for further information.\n * @type {Object}\n */\n this.editorAttributes = {};\n if (\"editorAttributes\" in contentManagerAttributes) {\n this.editorAttributes = contentManagerAttributes.editorAttributes;\n } else {\n throw new Error(\"ContentManager constructor error: editorAttributes property missed.\");\n }\n\n /**\n * CustomEditors instance. Contains the custom editors.\n * @type {CustomEditors}\n */\n this.customEditors = null;\n if (\"customEditors\" in contentManagerAttributes) {\n this.customEditors = contentManagerAttributes.customEditors;\n }\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @type {Object}\n * @property {String} editor - Editor name. Usually the HTML editor.\n * @property {String} mode - Save mode. Xml by default.\n * @property {String} version - Plugin version.\n */\n this.environment = {};\n if (\"environment\" in contentManagerAttributes) {\n this.environment = contentManagerAttributes.environment;\n } else {\n throw new Error(\"ContentManager constructor error: environment property missed\");\n }\n\n /**\n * ContentManager language.\n * @type {String}\n */\n this.language = \"\";\n if (\"language\" in contentManagerAttributes) {\n this.language = contentManagerAttributes.language;\n } else {\n throw new Error(\"ContentManager constructor error: language property missed\");\n }\n\n /**\n * {@link EditorListener} instance. Manages the changes inside the editor.\n * @type {EditorListener}\n */\n this.editorListener = new EditorListener();\n\n /**\n * MathType editor instance.\n * @type {JsEditor}\n */\n this.editor = null;\n\n /**\n * Navigator user agent.\n * @type {String}\n */\n this.ua = navigator.userAgent.toLowerCase();\n\n /**\n * Mobile device properties object\n * @type {DeviceProperties}\n */\n this.deviceProperties = {};\n this.deviceProperties.isAndroid = this.ua.indexOf(\"android\") > -1;\n this.deviceProperties.isIOS = ContentManager.isIOS();\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.toolbar = null;\n\n /**\n * Custom editor toolbar.\n * @type {String}\n */\n this.dbclick = null;\n\n /**\n * Instance of the {@link ModalDialog} class associated with the current\n * {@link ContentManager} instance.\n * @type {ModalDialog}\n */\n this.modalDialogInstance = null;\n\n /**\n * ContentManager listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n /**\n * MathML associated to the ContentManager instance.\n * @type {String}\n */\n this.mathML = null;\n\n /**\n * Indicates if the edited element is a new one or not.\n * @type {Boolean}\n */\n this.isNewElement = true;\n\n /**\n * {@link IntegrationModel} instance. Needed to call wrapper methods.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n }\n\n /**\n * Adds a new listener to the current {@link ContentManager} instance.\n * @param {Object} listener - The listener to be added.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Sets an instance of {@link IntegrationModel} class to the current {@link ContentManager}\n * instance.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} instance.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link ModalDialog} instance into the current {@link ContentManager} instance.\n * @param {ModalDialog} modalDialogInstance - The {@link ModalDialog} instance\n */\n setModalDialogInstance(modalDialogInstance) {\n this.modalDialogInstance = modalDialogInstance;\n }\n\n /**\n * Inserts the content into the current {@link ModalDialog} instance updating\n * the title and inserting the JavaScript editor.\n */\n insert() {\n // Before insert the editor we update the modal object title to avoid weird render display.\n this.updateTitle(this.modalDialogInstance);\n this.insertEditor(this.modalDialogInstance);\n }\n\n /**\n * Inserts MathType editor into the {@link ModalDialog.contentContainer}. It waits until\n * editor's JavaScript is loaded.\n */\n insertEditor() {\n if (ContentManager.isEditorLoaded()) {\n this.editor = window.com.wiris.jsEditor.JsEditor.newInstance(this.editorAttributes);\n this.editor.insertInto(this.modalDialogInstance.contentContainer);\n this.editor.focus();\n\n // `editor.action(\"rtl\");` toggles the RTL mode based on the current state, it doesn't just switch to RTL.\n if (this.modalDialogInstance.rtl && !this.editor.getEditorModel().isRTL()) {\n this.editor.action(\"rtl\");\n }\n // Setting div in rtl in case of it's activated.\n if (this.editor.getEditorModel().isRTL()) {\n this.editor.element.style.direction = \"rtl\";\n }\n\n // Editor listener: this object manages the changes logic of editor.\n this.editor.getEditorModel().addEditorListener(this.editorListener);\n\n // iOS events.\n if (this.modalDialogInstance.deviceProperties.isIOS) {\n setTimeout(function () {\n // Make sure the modalDialogInstance is available when the timeout is over\n // to avoid throw errors and stop execution.\n if (this.hasOwnProperty(\"modalDialogInstance\")) this.modalDialogInstance.hideKeyboard(); // eslint-disable-line no-prototype-builtins\n }, 400);\n\n const formulaDisplayDiv = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n Util.addEvent(formulaDisplayDiv, \"focus\", this.modalDialogInstance.handleOpenedIosSoftkeyboard);\n Util.addEvent(formulaDisplayDiv, \"blur\", this.modalDialogInstance.handleClosedIosSoftkeyboard);\n }\n // Fire onLoad event. Necessary to set the MathML into the editor\n // after is loaded.\n this.listeners.fire(\"onLoad\", {});\n } else {\n setTimeout(ContentManager.prototype.insertEditor.bind(this), 100);\n }\n }\n\n /**\n * Initializes the current class by loading MathType script.\n */\n init() {\n if (!ContentManager.isEditorLoaded()) {\n this.addEditorAsExternalDependency();\n }\n }\n\n /**\n * Adds script element to the DOM to include editor externally.\n */\n addEditorAsExternalDependency() {\n const script = document.createElement(\"script\");\n script.type = \"text/javascript\";\n let editorUrl = Configuration.get(\"editorUrl\");\n\n // We create an object url for parse url string and work more efficiently.\n const anchorElement = document.createElement(\"a\");\n\n ContentManager.setHrefToAnchorElement(anchorElement, editorUrl);\n ContentManager.setProtocolToAnchorElement(anchorElement);\n\n editorUrl = ContentManager.getURLFromAnchorElement(anchorElement);\n\n // Load editor URL. We add stats as GET params.\n const stats = this.getEditorStats();\n script.src = `${editorUrl}?lang=${this.language}&stats-editor=${stats.editor}&stats-mode=${stats.mode}&stats-version=${stats.version}`;\n\n document.getElementsByTagName(\"head\")[0].appendChild(script);\n }\n\n /**\n * Sets the specified url to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set 'url'.\n * @param {String} url - URL to set.\n */\n static setHrefToAnchorElement(anchorElement, url) {\n anchorElement.href = url;\n }\n\n /**\n * Sets the current protocol to the anchor element.\n * @param {HTMLAnchorElement} anchorElement - Element where set its protocol.\n */\n static setProtocolToAnchorElement(anchorElement) {\n // Change to https if necessary.\n if (window.location.href.indexOf(\"https://\") === 0) {\n // It check if browser is https and configuration is http.\n // If this is so, we will replace protocol.\n if (anchorElement.protocol === \"http:\") {\n anchorElement.protocol = \"https:\";\n }\n }\n }\n\n /**\n * Returns the url of the anchor element adding the current port\n * if it is needed.\n * @param {HTMLAnchorElement} anchorElement - Element where extract the url.\n * @returns {String}\n */\n static getURLFromAnchorElement(anchorElement) {\n // Check protocol and remove port if it's standard.\n const removePort = anchorElement.port === \"80\" || anchorElement.port === \"443\" || anchorElement.port === \"\";\n return `${anchorElement.protocol}//${anchorElement.hostname}${removePort ? \"\" : `:${anchorElement.port}`}${anchorElement.pathname.startsWith(\"/\") ? anchorElement.pathname : `/${anchorElement.pathname}`}`; // eslint-disable-line max-len\n }\n\n /**\n * Returns object with editor stats.\n *\n * @typedef {Object} EditorStatsObject\n * @property {string} editor - Editor name.\n * @property {string} mode - Current configuration for formula save mode.\n * @property {string} version - Current plugins version.\n * @returns {EditorStatsObject}\n */\n getEditorStats() {\n // Editor stats. Use environment property to set it.\n const stats = {};\n if (\"editor\" in this.environment) {\n stats.editor = this.environment.editor;\n } else {\n stats.editor = \"unknown\";\n }\n\n if (\"mode\" in this.environment) {\n stats.mode = this.environment.mode;\n } else {\n stats.mode = Configuration.get(\"saveMode\");\n }\n\n if (\"version\" in this.environment) {\n stats.version = this.environment.version;\n } else {\n stats.version = Configuration.get(\"version\");\n }\n\n return stats;\n }\n\n /**\n * Returns true if device is iOS. Otherwise, false.\n * @returns {Boolean}\n */\n static isIOS() {\n return (\n [\"iPad Simulator\", \"iPhone Simulator\", \"iPod Simulator\", \"iPad\", \"iPhone\", \"iPod\"].includes(navigator.platform) ||\n // iPad on iOS 13 detection\n (navigator.userAgent.includes(\"Mac\") && \"ontouchend\" in document)\n );\n }\n\n /**\n * Returns true if device is Mobile. Otherwise, false.\n * @returns {Boolean}\n */\n static isMobile() {\n return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);\n }\n\n /**\n * Returns true if editor is loaded. Otherwise, false.\n * @returns {Boolean}\n */\n static isEditorLoaded() {\n // To know if editor JavaScript is loaded we need to wait until\n // window.com.wiris.jsEditor.JsEditor.newInstance is ready.\n return (\n window.com &&\n window.com.wiris &&\n window.com.wiris.jsEditor &&\n window.com.wiris.jsEditor.JsEditor &&\n window.com.wiris.jsEditor.JsEditor.newInstance\n );\n }\n\n /**\n * Sets the {@link ContentManager.editor} initial content.\n */\n setInitialContent() {\n if (!this.isNewElement) {\n this.setMathML(this.mathML);\n }\n }\n\n /**\n * Sets a MathML into {@link ContentManager.editor} instance.\n * @param {String} mathml - MathML string.\n * @param {Boolean} focusDisabled - If true editor don't get focus after the MathML is set.\n * False by default.\n */\n setMathML(mathml, focusDisabled) {\n // By default focus is enabled.\n if (typeof focusDisabled === \"undefined\") {\n focusDisabled = false;\n }\n // Using setMathML method is not a change produced by the user but for the API\n // so we set to false the contentChange property of editorListener.\n this.editor.setMathMLWithCallback(mathml, () => {\n this.editorListener.setWaitingForChanges(true);\n });\n\n // We need to wait a little until the callback finish.\n setTimeout(() => {\n this.editorListener.setIsContentChanged(false);\n }, 500);\n\n // In some scenarios - like closing modal object - editor mustn't be focused.\n if (!focusDisabled) {\n this.onFocus();\n }\n }\n\n /**\n * Sets the focus to the current instance of {@link ContentManager.editor}. Triggered by\n * {@link ModalDialog.focus}.\n */\n onFocus() {\n if (typeof this.editor !== \"undefined\" && this.editor != null) {\n this.editor.focus();\n\n // On WordPress integration, the focus gets lost right after setting it.\n // To fix this, we enforce another focus some milliseconds after this behaviour.\n setTimeout(() => {\n this.editor.focus();\n }, 100);\n }\n }\n\n /**\n * Updates the edition area by calling {@link IntegrationModel.updateFormula}.\n * Triggered by {@link ModalDialog.submitAction}.\n */\n submitAction() {\n if (!this.editor.isFormulaEmpty()) {\n let mathML = this.editor.getMathMLWithSemantics();\n // Add class for custom editors.\n if (this.customEditors.getActiveEditor() !== null) {\n const { toolbar } = this.customEditors.getActiveEditor();\n mathML = MathML.addCustomEditorClassAttribute(mathML, toolbar);\n } else {\n // We need - if exists - the editor name from MathML\n // class attribute.\n Object.keys(this.customEditors.editors).forEach((key) => {\n mathML = MathML.removeCustomEditorClassAttribute(mathML, key);\n });\n }\n const mathmlEntitiesEncoded = MathML.mathMLEntities(mathML);\n this.integrationModel.updateFormula(mathmlEntitiesEncoded);\n } else {\n this.integrationModel.updateFormula(null);\n }\n\n this.customEditors.disable();\n this.integrationModel.notifyWindowClosed();\n\n // Set disabled focus to prevent lost focus.\n this.setEmptyMathML();\n this.customEditors.disable();\n }\n\n /**\n * Sets an empty MathML as {@link ContentManager.editor} content.\n * This will open the MT/CT editor with the hand mode.\n * It adds dir rtl in case of it's activated.\n */\n setEmptyMathML() {\n const isMobile = this.deviceProperties.isAndroid || this.deviceProperties.isIOS;\n const isRTL = this.editor.getEditorModel().isRTL();\n\n if (isMobile || this.integrationModel.forcedHandMode) {\n // For mobile devices or forced hand mode, set an empty annotation MATHML to maintain the editor in Hand mode.\n const mathML = `[]`;\n this.setMathML(mathML, true);\n } else {\n // For non-mobile devices or not forced hand mode, set the empty MathML without an annotation.\n const mathML = ``;\n this.setMathML(mathML, true);\n }\n }\n\n /**\n * Open event. Triggered by {@link ModalDialog.open}. Does the following:\n * - Updates the {@link ContentManager.editor} content\n * (with an empty MathML or an existing formula),\n * - Updates the {@link ContentManager.editor} toolbar.\n * - Recovers the the focus.\n */\n onOpen() {\n if (this.isNewElement) {\n this.setEmptyMathML();\n } else {\n this.setMathML(this.mathML);\n }\n const toolbar = this.updateToolbar();\n this.onFocus();\n\n if (this.deviceProperties.isIOS) {\n const zoom = document.documentElement.clientWidth / window.innerWidth;\n\n if (zoom !== 1) {\n // Open editor in Keyboard mode if user use iOS, Safari and page is zoomed.\n this.setKeyboardMode();\n }\n }\n\n const trigger = this.dbclick ? \"formula\" : \"button\";\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"OPENED_MTCT_EDITOR\", {\n toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking OPENED_MTCT_EDITOR\", error);\n }\n\n Core.globalListeners.fire(\"onModalOpen\", {});\n\n if (this.integrationModel.forcedHandMode) {\n this.hideHandModeButton();\n\n // In case we have a keyboard written formula, we still want it to be opened with handMode.\n if (this.mathML && !this.mathML.includes('') && !this.isNewElement) {\n this.openHandOnKeyboardMathML(this.mathML, this.editor);\n }\n }\n }\n\n /**\n * Change Editor in keyboard mode when is loaded\n */\n setKeyboardMode() {\n const wrsEditor = document.getElementsByClassName(\"wrs_handOpen wrs_disablePalette\")[0];\n if (wrsEditor) {\n wrsEditor.classList.remove(\"wrs_handOpen\");\n wrsEditor.classList.remove(\"wrs_disablePalette\");\n } else {\n setTimeout(ContentManager.prototype.setKeyboardMode.bind(this), 100);\n }\n }\n\n /**\n * Hides the hand <-> keyboard mode switch.\n *\n * This method relies completely on the classes used on different HTML elements within the editor itself, meaning\n * any change on those classes will make this code stop working properly.\n *\n * On top of that, some of those classes are changed on runtime (for example, the one that makes some buttons change).\n * This forces us to use some delayed code (this is, a timeout) to make sure everything exists when we need it.\n * @param {*} forced (boolean) Forces the user to stay in Hand mode by hiding the keyboard mode button.\n */\n hideHandModeButton(forced = true) {\n if (this.handSwitchHidden) {\n return; // hand <-> keyboard button already hidden.\n }\n\n // \"Open hand mode\" button takes a little bit to be available.\n // This selector gets the hand <-> keyboard mode switch\n const handModeButtonSelector =\n \"div.wrs_editor.wrs_flexEditor.wrs_withHand.wrs_animated .wrs_handWrapper input[type=button]\";\n\n // If in \"forced mode\", we hide the \"keyboard button\" so the user can't can't change between hand and keyboard modes.\n // We use an observer to ensure that the button it hidden as soon as it appears.\n if (forced) {\n const mutationInstance = new MutationObserver((mutations) => {\n const handModeButton = document.querySelector(handModeButtonSelector);\n if (handModeButton) {\n handModeButton.hidden = true;\n this.handSwitchHidden = true;\n mutationInstance.disconnect();\n }\n });\n mutationInstance.observe(document.body, {\n attributes: true,\n childList: true,\n characterData: true,\n subtree: true,\n });\n }\n }\n\n /**\n * It will open any formula written in Keyboard mode with the hand mode with the default hand trace.\n *\n * @param {String} mathml The original KeyBoard MathML\n * @param {Object} editor The editor object.\n */\n async openHandOnKeyboardMathML(mathml, editor) {\n // First, as an editor requirement, we need to update the editor object with the current MathML formula.\n // Once the MathML formula is updated to the one we want to open with handMode, we will be able to proceed.\n await new Promise((resolve) => {\n editor.setMathMLWithCallback(mathml, resolve);\n });\n\n // We wait until the hand editor object exists.\n await this.waitForHand(editor);\n\n // Logic to get the hand traces and open the formula in hand mode.\n // This logic comes from the editor.\n const handEditor = editor.hand;\n editor.handTemporalMathML = editor.getMathML();\n const handCoordinates = editor.editorModel.getHandStrokes();\n handEditor.setStrokes(handCoordinates);\n handEditor.fitStrokes(true);\n editor.openHand();\n }\n\n /**\n * Waits until the hand editor object exists.\n * @param {Obect} editor The editor object.\n */\n async waitForHand(editor) {\n while (!editor.hand) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Sets the correct toolbar depending if exist other custom toolbars\n * at the same time (e.g: Chemistry).\n */\n updateToolbar() {\n this.updateTitle(this.modalDialogInstance);\n const customEditor = this.customEditors.getActiveEditor();\n\n let toolbar;\n if (customEditor) {\n toolbar = customEditor.toolbar ? customEditor.toolbar : _wrs_int_wirisProperties.toolbar;\n\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n }\n } else {\n toolbar = this.getToolbar();\n if (this.toolbar == null || this.toolbar !== toolbar) {\n this.setToolbar(toolbar);\n this.customEditors.disable();\n }\n }\n\n return toolbar;\n }\n\n /**\n * Updates the current {@link ModalDialog.title}. If a {@link CustomEditors} is enabled\n * sets the custom editor title. Otherwise sets the default title.\n */\n updateTitle() {\n const customEditor = this.customEditors.getActiveEditor();\n if (customEditor) {\n this.modalDialogInstance.setTitle(customEditor.title);\n } else {\n this.modalDialogInstance.setTitle(\"MathType\");\n }\n }\n\n /**\n * Returns the editor toolbar, depending on the configuration local or server side.\n * @returns {String} - Toolbar identifier.\n */\n getToolbar() {\n let toolbar = \"general\";\n if (\"toolbar\" in this.editorAttributes) {\n ({ toolbar } = this.editorAttributes);\n }\n // TODO: Change global integration variable for integration custom toolbar.\n if (toolbar === \"general\") {\n // eslint-disable-next-line camelcase\n toolbar =\n typeof _wrs_int_wirisProperties === \"undefined\" || typeof _wrs_int_wirisProperties.toolbar === \"undefined\"\n ? \"general\"\n : _wrs_int_wirisProperties.toolbar;\n }\n\n return toolbar;\n }\n\n /**\n * Sets the current {@link ContentManager.editor} instance toolbar.\n * @param {String} toolbar - The toolbar name.\n */\n setToolbar(toolbar) {\n this.toolbar = toolbar;\n this.editor.setParams({ toolbar: this.toolbar });\n }\n\n /**\n * Sets the custom headers added on editor requests.\n * @returns {Object} headers - key value headers.\n */\n setCustomHeaders(headers) {\n let headersObj = {};\n\n // We control that we only get String or Object as the input.\n if (typeof headers === \"object\") {\n headersObj = headers;\n } else if (typeof headers === \"string\") {\n headersObj = Util.convertStringToObject(headers);\n }\n\n this.editor.setParams({ customHeaders: headersObj });\n return headersObj;\n }\n\n /**\n * Returns true if the content of the editor has been changed. The logic of the changes\n * is delegated to {@link EditorListener} class.\n * @returns {Boolean} True if the editor content has been changed. False otherwise.\n */\n hasChanges() {\n return !this.editor.isFormulaEmpty() && this.editorListener.getIsContentChanged();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined && keyboardEvent.repeat === false) {\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n // Code to detect Esc event.\n // There should be only one element with class name 'wrs_pressed' at the same time.\n let list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor3RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_expandButton wrs_expandButtonFor2RowsLayout wrs_pressed\");\n if (list.length === 0) {\n list = document.getElementsByClassName(\"wrs_select wrs_pressed\");\n if (list.length === 0) {\n this.modalDialogInstance.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.modalDialogInstance.submitButton) {\n // Focus is on OK button.\n this.editor.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.querySelector('[title=\"Manual\"]') === document.activeElement) {\n // Focus is on minimize button (_).\n this.modalDialogInstance.closeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.minimizeDiv) {\n // Focus on cancel button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n this.modalDialogInstance.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.modalDialogInstance.cancelButton) {\n // Focus is on X button.\n this.modalDialogInstance.minimizeDiv.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (document.activeElement === this.modalDialogInstance.closeDiv) {\n // Focus on help button.\n if (!(this.modalDialogInstance.properties.state === \"minimized\")) {\n const element = document.querySelector('[title=\"Manual\"]');\n element.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n } else {\n // There should be only one element with class name 'wrs_formulaDisplay'.\n const element = document.getElementsByClassName(\"wrs_formulaDisplay\")[0];\n if (element.getAttribute(\"class\") === \"wrs_formulaDisplay wrs_focused\") {\n // Focus is on formuladisplay.\n this.modalDialogInstance.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n }\n }\n}\n","/**\n * A custom editor is MathType editor with a different\n * @typedef {Object} CustomEditor\n * @property {String} CustomEditor.name - Custom editor name.\n * @property {String} CustomEditor.toolbar - Custom editor toolbar.\n * @property {String} CustomEditor.icon - Custom editor icon.\n * @property {String} CustomEditor.confVariable - Configuration property to manage\n * the availability of the custom editor.\n * @property {String} CustomEditor.title - Custom editor modal dialog title.\n * @property {String} CustomEditor.tooltip - Custom editor icon tooltip.\n */\n\nexport default class CustomEditors {\n /**\n * @classdesc\n * This class represents the MathType custom editors manager.\n * A custom editor is MathType editor with a custom toolbar.\n * This class associates a {@link CustomEditor} to:\n * - It's own formulas\n * - A custom toolbar\n * - An icon to open it from a HTML editor.\n * - A tooltip for the icon.\n * - A global variable to enable or disable it globally.\n * @constructs\n */\n constructor() {\n /**\n * The custom editors.\n * @type {Array.}\n */\n\n this.editors = [];\n /**\n * The active editor name.\n * @type {String}\n */\n this.activeEditor = \"default\";\n }\n\n /**\n * Adds a {@link CustomEditor} to editors array.\n * @param {String} editorName - The editor name.\n * @param {CustomEditor} editorParams - The custom editor parameters.\n */\n addEditor(editorName, editorParams) {\n const customEditor = {};\n customEditor.name = editorParams.name;\n customEditor.toolbar = editorParams.toolbar;\n customEditor.icon = editorParams.icon;\n customEditor.confVariable = editorParams.confVariable;\n customEditor.title = editorParams.title;\n customEditor.tooltip = editorParams.tooltip;\n this.editors[editorName] = customEditor;\n }\n\n /**\n * Enables a {@link CustomEditor}.\n * @param {String} customEditorName - The custom editor name.\n */\n enable(customEditorName) {\n this.activeEditor = customEditorName;\n }\n\n /**\n * Disables a {@link CustomEditor}.\n */\n disable() {\n this.activeEditor = \"default\";\n }\n\n /**\n * Returns the active editor.\n * @return {CustomEditor} - A {@link CustomEditor} if a custom editor is enabled. Null otherwise.\n */\n getActiveEditor() {\n if (this.activeEditor !== \"default\") {\n return this.editors[this.activeEditor];\n }\n return null;\n }\n}\n","/**\n * Represents the configuration properties generated from the frontend (JavaScript variables).\n * @type {Object}\n * @property {string} imageClassName - Default MathType formula image class.\n * @property {string} imageClassName - Default MathType CAS image class.\n * @ignore\n */\nconst jsProperties = {\n imageCustomEditorName: \"data-custom-editor\",\n imageClassName: \"Wirisformula\",\n CASClassName: \"Wiriscas\",\n};\nexport default jsProperties;\n","export default class Event {\n /**\n * @classdesc\n * This class represents a custom event. Events should be fired by the {@link Listener} class.\n *\n * ```js\n * let customEvent = new Event();\n * customEvent.properties = {};\n *\n * let listeners = new Listeners();\n * listeners.newListener(eventName, callback);\n *\n * listeners.fire(eventName, customEvent) *\n * ```\n * @constructs\n */\n constructor() {\n /**\n * Indicates if the event should be cancelled.\n * @type {Boolean}\n */\n\n this.cancelled = false;\n /**\n * Indicates if the event should be prevented.\n * @type {Boolean}\n */\n this.defaultPrevented = false;\n }\n\n /**\n * Cancels the event.\n */\n cancel() {\n this.cancelled = true;\n }\n\n /**\n * Prevents the default action.\n */\n preventDefault() {\n this.defaultPrevented = true;\n }\n}\n","import IntegrationModel from \"./integrationmodel\";\n\n/**\n\n */\nexport default class PopUpMessage {\n /**\n * @classdesc\n * This class represents a dialog message overlaying a DOM element in order to\n * accept / cancel discard changes. The dialog can be closed i.e the overlay disappears\n * o canceled. In this last case a callback function should be called.\n * @constructs\n * @param {Object} popupMessageAttributes - Object containing popup properties.\n * @param {HTMLElement} popupMessageAttributes.overlayElement - Element to overlay.\n * @param {Object} popupMessageAttributes.callbacks - Contains callback\n * methods for close and cancel actions.\n * @param {Object} popupMessageAttributes.strings - Contains all the strings needed.\n */\n constructor(popupMessageAttributes) {\n /**\n * Element to be overlaid when the popup appears.\n */\n this.overlayElement = popupMessageAttributes.overlayElement;\n\n this.callbacks = popupMessageAttributes.callbacks;\n\n /**\n * HTMLElement element to wrap all HTML elements inside the popupMessage.\n */\n this.overlayWrapper = this.overlayElement.appendChild(document.createElement(\"div\"));\n this.overlayWrapper.setAttribute(\"class\", \"wrs_popupmessage_overlay_envolture\");\n\n /**\n * HTMLElement to display the popup message, close button and cancel button.\n */\n this.message = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n this.message.id = \"wrs_popupmessage\";\n this.message.setAttribute(\"class\", \"wrs_popupmessage_panel\");\n this.message.setAttribute(\"role\", \"dialog\");\n this.message.setAttribute(\"aria-describedby\", \"description_txt\");\n const paragraph = document.createElement(\"p\");\n const text = document.createTextNode(popupMessageAttributes.strings.message);\n paragraph.appendChild(text);\n paragraph.id = \"description_txt\";\n this.message.appendChild(paragraph);\n\n /**\n * HTML element overlaying the overlayElement.\n */\n const overlay = this.overlayWrapper.appendChild(document.createElement(\"div\"));\n overlay.setAttribute(\"class\", \"wrs_popupmessage_overlay\");\n // We create a overlay that close popup message on click in there\n overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n /**\n * HTML element containing cancel and close buttons.\n */\n this.buttonArea = this.message.appendChild(document.createElement(\"div\"));\n this.buttonArea.setAttribute(\"class\", \"wrs_popupmessage_button_area\");\n this.buttonArea.id = \"wrs_popup_button_area\";\n\n // Close button arguments.\n const buttonSubmitArguments = {\n class: \"wrs_button_accept\",\n innerHTML: popupMessageAttributes.strings.submitString,\n id: \"wrs_popup_accept_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-close-button\",\n };\n\n /**\n * Close button arguments.\n */\n this.closeButton = this.createButton(buttonSubmitArguments, this.closeAction.bind(this));\n this.buttonArea.appendChild(this.closeButton);\n\n // Cancel button arguments.\n const buttonCancelArguments = {\n class: \"wrs_button_cancel\",\n innerHTML: popupMessageAttributes.strings.cancelString,\n id: \"wrs_popup_cancel_button\",\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cd-cancel-button\",\n };\n\n /**\n * Cancel button.\n */\n this.cancelButton = this.createButton(buttonCancelArguments, this.cancelAction.bind(this));\n this.buttonArea.appendChild(this.cancelButton);\n }\n\n /**\n * This method create a button with arguments and return button dom object\n * @param {Object} parameters - An object containing id, class and innerHTML button text.\n * @param {String} parameters.id - Button id.\n * @param {String} parameters.class - Button class name.\n * @param {String} parameters.innerHTML - Button innerHTML text.\n * @param {Object} callback- Callback method to call on click event.\n * @returns {HTMLElement} HTML button.\n */\n // eslint-disable-next-line class-methods-use-this\n createButton(parameters, callback) {\n let element = {};\n element = document.createElement(\"button\");\n element.setAttribute(\"id\", parameters.id);\n element.setAttribute(\"class\", parameters.class);\n element.innerHTML = parameters.innerHTML;\n element.addEventListener(\"click\", callback);\n if (parameters[\"data-testid\"]) {\n element.setAttribute(\"data-testid\", parameters[\"data-testid\"]);\n }\n\n return element;\n }\n\n /**\n * Shows the popupmessage containing a message, and two buttons\n * to cancel the action or close the modal dialog.\n */\n show() {\n if (this.overlayWrapper.style.display !== \"block\") {\n // Clear focus with blur for prevent press any key.\n document.activeElement.blur();\n this.overlayWrapper.style.display = \"block\";\n this.closeButton.focus();\n } else {\n this.overlayWrapper.style.display = \"none\";\n // _wrs_modalWindow.focus(); This throws an error of not existing _wrs_modalWindow\n }\n }\n\n /**\n * This method cancels the popupMessage: the dialog disappears revealing the overlaid element.\n * A callback method is called (if defined). For example a method to focus the overlaid element.\n */\n cancelAction() {\n this.overlayWrapper.style.display = \"none\";\n if (typeof this.callbacks.cancelCallback !== \"undefined\") {\n this.callbacks.cancelCallback();\n // Set temporal image to null to prevent loading\n // an existent formula when starting one from scratch. Make focus come back too.\n // IntegrationModel.setActionsOnCancelButtons();\n }\n }\n\n /**\n * This method closes the popupMessage: the dialog disappears and the close callback is called.\n * For example to close the overlaid element.\n */\n closeAction() {\n this.cancelAction();\n if (typeof this.callbacks.closeCallback !== \"undefined\") {\n this.callbacks.closeCallback();\n }\n IntegrationModel.setActionsOnCancelButtons();\n }\n\n /**\n * Handle keyboard events detected in modal when elements of this class intervene.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Code to detect Esc event.\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n this.cancelAction();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.closeButton) {\n this.cancelButton.focus();\n } else {\n this.closeButton.focus();\n }\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n }\n }\n }\n}\n","/**\n * This module provides protection against external focus management scripts\n * that might interfere with the MathType editor modal.\n */\n\n/**\n * focusProtection function creates and returns methods to prevent external scripts from\n * interfering with the focus of the MathType modal dialog.\n *\n * @returns {Object} An object with protect and unprotect methods.\n */\nconst focusProtection = () => {\n /**\n * Initialize focus protection on the given modal element.\n *\n * @param {HTMLElement} modalElement - The modal element to protect\n * @param {HTMLElement} overlayElement - The overlay element of the modal (not used in current implementation)\n * @param {HTMLElement} editorElement - The editor element inside the modal\n */\n const protect = (modalElement, overlayElement, editorElement) => {\n if (!modalElement || !overlayElement || !editorElement) {\n console.warn(\"FocusProtection: Missing required elements\");\n return;\n }\n\n // Apply the focus protection\n overrideFocusBehavior(modalElement, editorElement);\n };\n\n /**\n * Apply focus protection by overriding focus-related methods\n *\n * @param {HTMLElement} modalElement - The modal element\n * @param {HTMLElement} editorElement - The editor element to keep focused\n * @private\n */\n const overrideFocusBehavior = (modalElement, editorElement) => {\n // Store original focus methods to be able to restore them\n const originalElementFocus = HTMLElement.prototype.focus;\n const originalElementBlur = HTMLElement.prototype.blur;\n\n // Override the focus method for all elements\n HTMLElement.prototype.focus = function (...args) {\n // If the modal is open and this is not part of the modal, prevent focus\n if (modalElement.style.display !== \"none\" && !modalElement.contains(this) && this !== document.body) {\n // If some external script is trying to focus another element, prevent it\n // and restore focus to the editor\n if (editorElement) {\n // Use the original focus method to avoid infinite recursion\n originalElementFocus.apply(editorElement, args);\n }\n return;\n }\n\n // Otherwise, allow the focus to happen\n originalElementFocus.apply(this, args);\n };\n\n // Store the methods to remove them when the modal is closed\n modalElement.originalElementFocus = originalElementFocus;\n modalElement.originalElementBlur = originalElementBlur;\n };\n\n /**\n * Remove focus protection from the modal\n *\n * @param {HTMLElement} modalElement - The modal element to unprotect\n */\n const unprotect = (modalElement) => {\n if (!modalElement) {\n return;\n }\n\n // Restore original focus methods\n if (modalElement.originalElementFocus) {\n HTMLElement.prototype.focus = modalElement.originalElementFocus;\n delete modalElement.originalElementFocus;\n }\n\n if (modalElement.originalElementBlur) {\n HTMLElement.prototype.blur = modalElement.originalElementBlur;\n delete modalElement.originalElementBlur;\n }\n };\n\n return {\n protect,\n unprotect,\n };\n};\n\nexport default focusProtection;\n","// eslint-disable-next-line max-classes-per-file\nimport PopUpMessage from \"./popupmessage\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport Listeners from \"./listeners\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Telemeter from \"./telemeter\";\nimport IntegrationModel from \"./integrationmodel\";\nimport Core from \"./core.src\";\nimport focusProtection from \"./focusprotection\";\nimport closeIcon from \"../styles/icons/general/close_icon.svg\"; //eslint-disable-line\nimport closeHoverIcon from \"../styles/icons/hover/close_icon_h.svg\"; //eslint-disable-line\nimport fullsIcon from \"../styles/icons/general/fulls_icon.svg\"; //eslint-disable-line\nimport fullsHoverIcon from \"../styles/icons/hover/fulls_icon_h.svg\"; //eslint-disable-line\nimport minIcon from \"../styles/icons/general/min_icon.svg\"; //eslint-disable-line\nimport minHoverIcon from \"../styles/icons/hover/min_icon_h.svg\"; //eslint-disable-line\nimport minsIcon from \"../styles/icons/general/mins_icon.svg\"; //eslint-disable-line\nimport minsHoverIcon from \"../styles/icons/hover/mins_icon_h.svg\"; //eslint-disable-line\nimport maxIcon from \"../styles/icons/general/max_icon.svg\"; //eslint-disable-line\nimport maxHoverIcon from \"../styles/icons/hover/max_icon_h.svg\"; //eslint-disable-line\nconst { unprotect, protect } = focusProtection();\n\n/**\n * @typedef {Object} DeviceProperties\n * @property {String} DeviceProperties.orientation - Indicates of the orientation of the device.\n * @property {Boolean} DeviceProperties.isAndroid - True if the device is Android. False otherwise.\n * @property {Boolean} DeviceProperties.isIOS - True if the device is iOS. False otherwise.\n * @property {Boolean} DeviceProperties.isMobile - True if the device is a mobile one.\n * False otherwise.\n * @property {Boolean} DeviceProperties.isDesktop - True if the device is a desktop one.\n * False otherwise.\n */\n\nexport default class ModalDialog {\n /**\n * @classdesc\n * This class represents a modal dialog. The modal dialog admits\n * a {@link ContentManager} instance to manage the content of the dialog.\n * @constructs\n * @param {Object} modalDialogAttributes - An object containing all modal dialog attributes.\n */\n constructor(modalDialogAttributes) {\n this.attributes = modalDialogAttributes;\n\n // Metrics.\n const ua = navigator.userAgent.toLowerCase();\n const isAndroid = ua.indexOf(\"android\") > -1;\n const isIOS = ContentManager.isIOS();\n this.iosSoftkeyboardOpened = false;\n this.iosMeasureUnit = ua.indexOf(\"crios\") === -1 ? \"%\" : \"vh\";\n this.iosDivHeight = `auto`;\n\n const deviceWidth = window.outerWidth;\n const deviceHeight = window.outerHeight;\n\n const landscape = deviceWidth > deviceHeight;\n const portrait = deviceWidth < deviceHeight;\n\n // TODO: Detect isMobile without using editor metrics.\n const isLandscape = landscape && this.attributes.height > deviceHeight;\n const isPortrait = portrait && this.attributes.width > deviceWidth;\n const isMobile = ContentManager.isMobile();\n\n // Obtain number of current instance.\n this.instanceId = document.getElementsByClassName(\"wrs_modal_dialogContainer\").length;\n\n // Device object properties.\n\n /**\n * @type {DeviceProperties}\n */\n this.deviceProperties = {\n orientation: landscape ? \"landscape\" : \"portrait\",\n isAndroid,\n isIOS,\n isMobile,\n isDesktop: !isMobile && !isIOS && !isAndroid,\n };\n\n this.properties = {\n created: false,\n state: \"\",\n previousState: \"\",\n position: { bottom: 0, right: 10 },\n size: { height: 338, width: 580 },\n };\n\n /**\n * Object to keep website's style before change it on lock scroll for mobile devices.\n * @type {Object}\n * @property {String} bodyStylePosition - Previous body style position.\n * @property {String} bodyStyleOverflow - Previous body style overflow.\n * @property {String} htmlStyleOverflow - Previous body style overflow.\n * @property {String} windowScrollX - Previous window's scroll Y.\n * @property {String} windowScrollY - Previous window's scroll X.\n */\n this.websiteBeforeLockParameters = null;\n\n let attributes = {};\n attributes.class = \"wrs_modal_overlay\";\n attributes.id = this.getElementId(attributes.class);\n this.overlay = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title_bar\";\n attributes.id = this.getElementId(attributes.class);\n this.titleBar = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_title\";\n attributes.id = this.getElementId(attributes.class);\n this.title = Util.createElement(\"div\", attributes);\n this.title.innerHTML = \"offline\";\n\n attributes = {};\n attributes.class = \"wrs_modal_close_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"close\");\n attributes.style = {};\n this.closeDiv = Util.createElement(\"a\", attributes);\n this.closeDiv.setAttribute(\"role\", \"button\");\n this.closeDiv.setAttribute(\"tabindex\", 3);\n // Apply styles and events after the creation as createElement doesn't process them correctly\n const generalStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeIcon)})`;\n const hoverStyleClose = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(closeHoverIcon)})`;\n this.closeDiv.setAttribute(\"style\", generalStyleClose);\n this.closeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleClose));\n this.closeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleClose));\n // To identifiy the element in automated testing\n this.closeDiv.setAttribute(\"data-testid\", \"mtcteditor-close-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_stack_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"exit_fullscreen\");\n this.stackDiv = Util.createElement(\"a\", attributes);\n this.stackDiv.setAttribute(\"role\", \"button\");\n this.stackDiv.setAttribute(\"tabindex\", 2);\n const generalStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsIcon)})`;\n const hoverStyleStack = `background-size: 10px; background-image: url(data:image/svg+xml;base64,${window.btoa(minsHoverIcon)})`;\n this.stackDiv.setAttribute(\"style\", generalStyleStack);\n this.stackDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleStack));\n this.stackDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleStack));\n // To identifiy the element in automated testing\n this.stackDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-disable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_maximize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"fullscreen\");\n this.maximizeDiv = Util.createElement(\"a\", attributes);\n this.maximizeDiv.setAttribute(\"role\", \"button\");\n this.maximizeDiv.setAttribute(\"tabindex\", 2);\n const generalStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsIcon)})`;\n const hoverStyleMaximize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(fullsHoverIcon)})`;\n this.maximizeDiv.setAttribute(\"style\", generalStyleMaximize);\n this.maximizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleMaximize));\n this.maximizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleMaximize));\n // To identifiy the element in automated testing\n this.maximizeDiv.setAttribute(\"data-testid\", \"mtcteditor-fullscreen-enable-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_minimize_button\";\n attributes.id = this.getElementId(attributes.class);\n attributes.title = StringManager.get(\"minimize\");\n this.minimizeDiv = Util.createElement(\"a\", attributes);\n this.minimizeDiv.setAttribute(\"role\", \"button\");\n this.minimizeDiv.setAttribute(\"tabindex\", 1);\n const generalStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyleMinimize = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyleMinimize);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyleMinimize));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyleMinimize));\n // To identify the element in automated testing\n this.minimizeDiv.setAttribute(\"data-testid\", \"mtcteditor-minimize-button\");\n\n attributes = {};\n attributes.class = \"wrs_modal_dialogContainer\";\n attributes.id = this.getElementId(attributes.class);\n attributes.role = \"dialog\";\n this.container = Util.createElement(\"div\", attributes);\n this.container.setAttribute(\"aria-labeledby\", \"wrs_modal_title[0]\");\n\n attributes = {};\n attributes.class = \"wrs_modal_wrapper\";\n attributes.id = this.getElementId(attributes.class);\n this.wrapper = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_content_container\";\n attributes.id = this.getElementId(attributes.class);\n this.contentContainer = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_controls\";\n attributes.id = this.getElementId(attributes.class);\n this.controls = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_buttons_container\";\n attributes.id = this.getElementId(attributes.class);\n this.buttonContainer = Util.createElement(\"div\", attributes);\n\n // Buttons: all button must be created using createSubmitButton method.\n this.submitButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_accept\"),\n class: \"wrs_modal_button_accept\",\n innerHTML: StringManager.get(\"accept\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-insert-button\",\n },\n this.submitAction.bind(this),\n );\n\n this.cancelButton = this.createSubmitButton(\n {\n id: this.getElementId(\"wrs_modal_button_cancel\"),\n class: \"wrs_modal_button_cancel\",\n innerHTML: StringManager.get(\"cancel\"),\n // To identifiy the element in automated testing\n \"data-testid\": \"mtcteditor-cancel-button\",\n },\n this.cancelAction.bind(this),\n );\n\n this.contentManager = null;\n\n // Overlay popup.\n const popupStrings = {\n cancelString: StringManager.get(\"cancel\"),\n submitString: StringManager.get(\"close\"),\n message: StringManager.get(\"close_modal_warning\"),\n };\n\n const callbacks = {\n closeCallback: () => {\n this.close(\"mtc_close\");\n },\n cancelCallback: () => {\n this.focus();\n },\n };\n\n const popupupProperties = {\n overlayElement: this.container,\n callbacks,\n strings: popupStrings,\n };\n\n this.popup = new PopUpMessage(popupupProperties);\n\n /**\n * Indicates if directionality of the modal dialog is RTL. false by default.\n * @type {Boolean}\n */\n this.rtl = false;\n if (\"rtl\" in this.attributes) {\n this.rtl = this.attributes.rtl;\n }\n\n // Event handlers need modal instance context.\n this.handleOpenedIosSoftkeyboard = this.handleOpenedIosSoftkeyboard.bind(this);\n this.handleClosedIosSoftkeyboard = this.handleClosedIosSoftkeyboard.bind(this);\n }\n\n /**\n * This method sets an ContentManager instance to ModalDialog. ContentManager\n * manages the logic of ModalDialog content: submit, update, close and changes.\n * @param {ContentManager} contentManager - ContentManager instance.\n */\n setContentManager(contentManager) {\n this.contentManager = contentManager;\n }\n\n /**\n * Returns the modal contentElement object.\n * @returns {ContentManager} the instance of the ContentManager class.\n */\n getContentManager() {\n return this.contentManager;\n }\n\n /**\n * This method is called when the modal object has been submitted. Calls\n * contentElement submitAction method - if exists - and closes the modal\n * object. No logic about the content should be placed here,\n * contentElement.submitAction is the responsible of the content logic.\n */\n async submitAction() {\n if (typeof this.contentManager.submitAction !== \"undefined\") {\n this.contentManager.submitAction();\n }\n\n await this.close(\"mtc_insert\");\n }\n\n /**\n * Performs the cancel action.\n * If there are no changes in the content, it closes the modal.\n * Otherwise, it shows a pop-up message to confirm the cancel action.\n * @returns {Promise} - A promise that resolves when the modal is closed.\n */\n async cancelAction() {\n if (typeof this.contentManager.hasChanges === \"undefined\" || !this.contentManager.hasChanges()) {\n IntegrationModel.setActionsOnCancelButtons();\n await this.close(\"mtc_close\");\n } else {\n this.showPopUpMessage();\n }\n }\n\n /**\n * Returns a button element.\n * @param {Object} properties - Input button properties.\n * @param {String} properties.class - Input button class.\n * @param {String} properties.innerHTML - Input button innerHTML.\n * @param {Object} callback - Callback function associated to click event.\n * @returns {HTMLButtonElement} The button element.\n *\n */\n // eslint-disable-next-line class-methods-use-this\n createSubmitButton(properties, callback) {\n class SubmitButton {\n constructor() {\n this.element = document.createElement(\"button\");\n this.element.id = properties.id;\n this.element.className = properties.class;\n this.element.innerHTML = properties.innerHTML;\n this.element.dataset.testid = properties[\"data-testid\"];\n Util.addEvent(this.element, \"click\", callback);\n }\n\n getElement() {\n return this.element;\n }\n }\n return new SubmitButton(properties, callback).getElement();\n }\n\n /**\n * Creates the modal window object inserting a contentElement object.\n */\n create() {\n /* Modal Window Structure\n _____________________________________________________________________________________\n |wrs_modal_dialog_Container |\n | _________________________________________________________________________________ |\n | |title_bar minimize_button stack_button close_button | |\n | |_______________________________________________________________________________| |\n | |wrapper | |\n | | _____________________________________________________________________________ | |\n | | |content | | |\n | | | | | |\n | | | | | |\n | | |___________________________________________________________________________| | |\n | | _____________________________________________________________________________ | |\n | | |controls | | |\n | | | ___________________________________ | | |\n | | | |buttonContainer | | | |\n | | | | _______________________________ | | | |\n | | | | |button_accept | button_cancel| | | | |\n | | | |_|_____________ |______________|_| | | |\n | | |___________________________________________________________________________| | |\n | |_______________________________________________________________________________| |\n |___________________________________________________________________________________| */\n\n this.titleBar.appendChild(this.closeDiv);\n this.titleBar.appendChild(this.stackDiv);\n this.titleBar.appendChild(this.maximizeDiv);\n this.titleBar.appendChild(this.minimizeDiv);\n this.titleBar.appendChild(this.title);\n\n if (this.deviceProperties.isDesktop) {\n this.container.appendChild(this.titleBar);\n }\n\n this.wrapper.appendChild(this.contentContainer);\n this.wrapper.appendChild(this.controls);\n\n this.controls.appendChild(this.buttonContainer);\n\n this.buttonContainer.appendChild(this.submitButton);\n this.buttonContainer.appendChild(this.cancelButton);\n\n this.container.appendChild(this.wrapper);\n\n // Check if browser has scrollBar before modal has modified.\n this.recalculateScrollBar();\n\n document.body.appendChild(this.container);\n document.body.appendChild(this.overlay);\n\n if (this.deviceProperties.isDesktop) {\n // Desktop.\n this.createModalWindowDesktop();\n this.createResizeButtons();\n\n this.addListeners();\n // Maximize window only when the configuration is set and the device is not iOS or Android.\n if (Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n } else if (this.deviceProperties.isAndroid) {\n this.createModalWindowAndroid();\n } else if (this.deviceProperties.isIOS) {\n this.createModalWindowIos();\n }\n\n if (this.contentManager != null) {\n this.contentManager.insert(this);\n }\n\n this.properties.open = true;\n this.properties.created = true;\n\n // Checks language directionality.\n if (this.isRTL()) {\n this.container.style.right = `${window.innerWidth - this.scrollbarWidth - this.container.offsetWidth}px`;\n this.container.className += \" wrs_modal_rtl\";\n }\n }\n\n /**\n * Creates a button in the modal object to resize it.\n */\n createResizeButtons() {\n // This is a definition of Resize Button Bottom-Right.\n this.resizerBR = document.createElement(\"div\");\n this.resizerBR.className = \"wrs_bottom_right_resizer\";\n this.resizerBR.innerHTML = \"◢\";\n // To identifiy the element in automated testing\n this.resizerBR.dataset.testid = \"mtcteditor-resize-button-right\";\n // This is a definition of Resize Button Top-Left.\n this.resizerTL = document.createElement(\"div\");\n this.resizerTL.className = \"wrs_bottom_left_resizer\";\n // To identifiy the element in automated testing\n this.resizerTL.dataset.testid = \"mtcteditor-resize-button-left\";\n // Append resize buttons to modal.\n this.container.appendChild(this.resizerBR);\n this.titleBar.appendChild(this.resizerTL);\n // Add events to resize on click and drag.\n Util.addEvent(this.resizerBR, \"mousedown\", this.activateResizeStateBR.bind(this));\n Util.addEvent(this.resizerTL, \"mousedown\", this.activateResizeStateTL.bind(this));\n }\n\n /**\n * Initialize variables for Bottom-Right resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateBR(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, false);\n }\n\n /**\n * Initialize variables for Top-Left resize button\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n activateResizeStateTL(mouseEvent) {\n this.initializeResizeProperties(mouseEvent, true);\n }\n\n /**\n * Common method to initialize variables at resize.\n * @param {MouseEvent} mouseEvent - Mouse event.\n */\n initializeResizeProperties(mouseEvent, leftOption) {\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n this.resizeDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Save Initial state of modal to compare on drag and obtain the difference.\n this.initialWidth = parseInt(this.container.style.width, 10);\n this.initialHeight = parseInt(this.container.style.height, 10);\n if (!leftOption) {\n this.initialRight = parseInt(this.container.style.right, 10);\n this.initialBottom = parseInt(this.container.style.bottom, 10);\n } else {\n this.leftScale = true;\n }\n if (!this.initialRight) {\n this.initialRight = 0;\n }\n if (!this.initialBottom) {\n this.initialBottom = 0;\n }\n // Disable mouse events on editor when we start to drag modal.\n document.body.style[\"user-select\"] = \"none\";\n }\n\n /**\n * This method opens the modal window, restoring the previous state, position and metrics,\n * if exists. By default the modal object opens in stack mode.\n */\n open() {\n // Removing close class.\n this.removeClass(\"wrs_closed\");\n // Hiding keyboard for mobile devices.\n const { isIOS } = this.deviceProperties;\n const { isAndroid } = this.deviceProperties;\n const { isMobile } = this.deviceProperties;\n if (isIOS || isAndroid || isMobile) {\n // Restore scale to 1.\n this.restoreWebsiteScale();\n this.lockWebsiteScroll();\n // Due to editor wait we need to wait until editor focus.\n setTimeout(() => {\n this.hideKeyboard();\n }, 400);\n }\n\n // New modal window. He need to create the whole object.\n if (!this.properties.created) {\n this.create();\n } else {\n // Previous state closed. Open method can be called even the previous state is open,\n // for example updating the content of the modal object.\n if (!this.properties.open) {\n this.properties.open = true;\n\n // Restoring the previous open state: if the modal object has been closed\n // re-open it should preserve the state and the metrics.\n if (!this.deviceProperties.isAndroid && !this.deviceProperties.isIOS) {\n this.restoreState();\n }\n }\n\n // Maximize window only when the configuration is set and the device is not iOs or Android.\n if (this.deviceProperties.isDesktop && Configuration.get(\"modalWindowFullScreen\")) {\n this.maximize();\n }\n\n // In iOS we need to recalculate the size of the modal object because\n // iOS keyboard is a float div which can overlay the modal object.\n if (this.deviceProperties.isIOS) {\n this.iosSoftkeyboardOpened = false;\n }\n }\n\n if (!ContentManager.isEditorLoaded()) {\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.displayEditor();\n });\n this.contentManager.addListener(listener);\n } else {\n this.displayEditor();\n }\n }\n\n /**\n * Prepares and displays the editor in the modal.\n *\n * This method is responsible for displaying the MathType editor inside the modal container.\n *\n * For Moodle environments, it applies focus protection to prevent external scripts\n * from hijacking focus away from the editor while it's open. This is particularly\n * important in Moodle which may have its own focus management scripts.\n * @returns {void}\n */\n displayEditor() {\n if (this.contentManager.integrationModel.isMoodle) {\n protect(this.container, this.overlay, this.contentContainer);\n }\n\n // Initialize and open the editor using the contentManager.\n this.contentManager.onOpen(this);\n }\n\n /**\n * Closes the modal.\n * Removes specific CSS classes, saves modal properties, unlocks website scroll,\n * sets the 'open' property to false, and triggers the 'onModalClose' event.\n * If a close trigger is defined, it tracks the telemetry event 'CLOSED_MTCT_EDITOR' with the trigger.\n * @returns {Promise} A promise that resolves when the modal is closed.\n */\n async close(trigger) {\n // Remove focus protection before closing\n unprotect(this.container);\n\n this.removeClass(\"wrs_maximized\");\n this.removeClass(\"wrs_minimized\");\n this.removeClass(\"wrs_stack\");\n this.addClass(\"wrs_closed\");\n this.saveModalProperties();\n this.unlockWebsiteScroll();\n this.properties.open = false;\n\n if (trigger) {\n try {\n await Telemeter.telemeter.track(\"CLOSED_MTCT_EDITOR\", {\n toolbar: this.contentManager.toolbar,\n trigger,\n });\n } catch (error) {\n console.error(\"Error tracking CLOSED_MTCT_EDITOR\", error);\n }\n }\n\n Core.globalListeners.fire(\"onModalClose\", {});\n }\n\n /**\n * Closes modal window and destroys the object.\n */\n destroy() {\n // Remove focus protection before destroying\n unprotect(this.container);\n\n // Close modal window.\n this.close();\n // Remove listeners and destroy the object.\n this.removeListeners();\n this.overlay.remove();\n this.container.remove();\n // Reset properties to allow open again.\n this.properties.created = false;\n }\n\n /**\n * Sets the website scale to one.\n */\n // eslint-disable-next-line class-methods-use-this\n restoreWebsiteScale() {\n let viewportmeta = document.querySelector(\"meta[name=viewport]\");\n // Let the equal symbols in order to search and make meta's final content.\n const contentAttrsToUpdate = [\"initial-scale=\", \"minimum-scale=\", \"maximum-scale=\"];\n const contentAttrsValuesToUpdate = [\"1.0\", \"1.0\", \"1.0\"];\n const setMetaAttrFunc = (viewportelement, contentAttrs) => {\n const contentAttr = viewportelement.getAttribute(\"content\");\n // If it exists, we need to maintain old values and put our values.\n if (contentAttr) {\n const attrArray = contentAttr.split(\",\");\n let finalContentMeta = \"\";\n const oldAttrs = [];\n for (let i = 0; i < attrArray.length; i += 1) {\n let isAttrToUpdate = false;\n let j = 0;\n while (!isAttrToUpdate && j < contentAttrs.length) {\n if (attrArray[i].indexOf(contentAttrs[j])) {\n isAttrToUpdate = true;\n }\n j += 1;\n }\n\n if (!isAttrToUpdate) {\n oldAttrs.push(attrArray[i]);\n }\n }\n\n for (let i = 0; i < contentAttrs.length; i += 1) {\n const attr = contentAttrs[i] + contentAttrsValuesToUpdate[i];\n finalContentMeta += i === 0 ? attr : `,${attr}`;\n }\n\n for (let i = 0; i < oldAttrs.length; i += 1) {\n finalContentMeta += `,${oldAttrs[i]}`;\n }\n viewportelement.setAttribute(\"content\", finalContentMeta);\n // It needs to set to empty because setAttribute refresh only when attribute is different.\n viewportelement.setAttribute(\"content\", \"\");\n viewportelement.setAttribute(\"content\", contentAttr);\n } else {\n viewportelement.setAttribute(\"content\", \"initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0\");\n viewportelement.removeAttribute(\"content\");\n }\n };\n\n if (!viewportmeta) {\n viewportmeta = document.createElement(\"meta\");\n document.getElementsByTagName(\"head\")[0].appendChild(viewportmeta);\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n viewportmeta.remove();\n } else {\n setMetaAttrFunc(viewportmeta, contentAttrsToUpdate, contentAttrsValuesToUpdate);\n }\n }\n\n /**\n * Locks website scroll for mobile devices.\n */\n lockWebsiteScroll() {\n this.websiteBeforeLockParameters = {\n bodyStylePosition: document.body.style.position ? document.body.style.position : \"\",\n bodyStyleOverflow: document.body.style.overflow ? document.body.style.overflow : \"\",\n htmlStyleOverflow: document.documentElement.style.overflow ? document.documentElement.style.overflow : \"\",\n windowScrollX: window.scrollX,\n windowScrollY: window.scrollY,\n };\n }\n\n /**\n * Unlocks website scroll for mobile devices.\n */\n unlockWebsiteScroll() {\n if (this.websiteBeforeLockParameters) {\n document.body.style.position = this.websiteBeforeLockParameters.bodyStylePosition;\n document.body.style.overflow = this.websiteBeforeLockParameters.bodyStyleOverflow;\n document.documentElement.style.overflow = this.websiteBeforeLockParameters.htmlStyleOverflow;\n const { windowScrollX } = this.websiteBeforeLockParameters;\n const { windowScrollY } = this.websiteBeforeLockParameters;\n window.scrollTo(windowScrollX, windowScrollY);\n this.websiteBeforeLockParameters = null;\n }\n }\n\n /**\n * Util function to known if browser is IE11.\n * @returns {Boolean} true if the browser is IE11. false otherwise.\n */\n // eslint-disable-next-line class-methods-use-this\n isIE11() {\n if (\n navigator.userAgent.search(\"Msie/\") >= 0 ||\n navigator.userAgent.search(\"Trident/\") >= 0 ||\n navigator.userAgent.search(\"Edge/\") >= 0\n ) {\n return true;\n }\n return false;\n }\n\n /**\n * Returns if the current language type is RTL.\n * @return {Boolean} true if current language is RTL. false otherwise.\n */\n isRTL() {\n if (this.attributes.language === \"ar\" || this.attributes.language === \"he\") {\n return true;\n }\n return this.rtl;\n }\n\n /**\n * Adds a class to all modal ModalDialog DOM elements.\n * @param {String} className - Class name.\n */\n addClass(className) {\n Util.addClass(this.overlay, className);\n Util.addClass(this.titleBar, className);\n Util.addClass(this.overlay, className);\n Util.addClass(this.container, className);\n Util.addClass(this.contentContainer, className);\n Util.addClass(this.stackDiv, className);\n Util.addClass(this.minimizeDiv, className);\n Util.addClass(this.maximizeDiv, className);\n Util.addClass(this.wrapper, className);\n }\n\n /**\n * Remove a class from all modal DOM elements.\n * @param {String} className - Class name.\n */\n removeClass(className) {\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.titleBar, className);\n Util.removeClass(this.overlay, className);\n Util.removeClass(this.container, className);\n Util.removeClass(this.contentContainer, className);\n Util.removeClass(this.stackDiv, className);\n Util.removeClass(this.minimizeDiv, className);\n Util.removeClass(this.maximizeDiv, className);\n Util.removeClass(this.wrapper, className);\n }\n\n /**\n * Create modal dialog for desktop.\n */\n createModalWindowDesktop() {\n this.addClass(\"wrs_modal_desktop\");\n this.stack();\n }\n\n /**\n * Create modal dialog for non android devices.\n */\n createModalWindowAndroid() {\n this.addClass(\"wrs_modal_android\");\n window.addEventListener(\"resize\", this.orientationChangeAndroidSoftkeyboard.bind(this));\n }\n\n /**\n * Create modal dialog for iOS devices.\n */\n createModalWindowIos() {\n this.addClass(\"wrs_modal_ios\");\n // Refresh the size when the orientation is changed.\n window.addEventListener(\"resize\", this.orientationChangeIosSoftkeyboard.bind(this));\n }\n\n /**\n * Restore previous state, position and size of previous stacked modal dialog.\n */\n restoreState() {\n if (this.properties.state === \"maximized\") {\n // Reset states for prevent return to stack state.\n this.maximize();\n } else if (this.properties.state === \"minimized\") {\n // Reset states for prevent return to stack state.\n this.properties.state = this.properties.previousState;\n this.properties.previousState = \"\";\n this.minimize();\n } else {\n this.stack();\n }\n }\n\n /**\n * Stacks the modal object.\n */\n stack() {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"stack\";\n this.removeClass(\"wrs_maximized\");\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n this.addClass(\"wrs_stack\");\n\n // Change maximize/minimize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyle));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyle));\n\n this.restoreModalProperties();\n\n if (typeof this.resizerBR !== \"undefined\" && typeof this.resizerTL !== \"undefined\") {\n this.setResizeButtonsVisibility();\n }\n\n // Need recalculate position of actual modal because window can was changed in fullscreenmode.\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n this.focus();\n }\n\n /**\n * Minimizes the modal object.\n */\n minimize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n this.title.style.cursor = \"pointer\";\n if (this.properties.state === \"minimized\" && this.properties.previousState === \"stack\") {\n this.stack();\n } else if (this.properties.state === \"minimized\" && this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n // Setting css to prevent important tag into css style.\n this.container.style.height = \"30px\";\n this.container.style.width = \"250px\";\n this.container.style.bottom = \"0px\";\n this.container.style.right = \"10px\";\n\n this.removeListeners();\n this.properties.previousState = this.properties.state;\n this.properties.state = \"minimized\";\n this.setResizeButtonsVisibility();\n this.minimizeDiv.title = StringManager.get(\"maximize\");\n\n if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.removeClass(\"wrs_stack\");\n } else {\n this.removeClass(\"wrs_maximized\");\n }\n this.addClass(\"wrs_minimized\");\n\n // Change minimize icon to maximize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(maxHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyle));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyle));\n }\n }\n\n /**\n * Maximizes the modal object.\n */\n maximize() {\n // Saving width, height, top and bottom parameters to restore when opening.\n this.saveModalProperties();\n if (this.properties.state !== \"maximized\") {\n this.properties.previousState = this.properties.state;\n this.properties.state = \"maximized\";\n }\n // Don't permit resize on maximize mode.\n this.setResizeButtonsVisibility();\n\n if (Util.containsClass(this.overlay, \"wrs_minimized\")) {\n this.minimizeDiv.title = StringManager.get(\"minimize\");\n this.removeClass(\"wrs_minimized\");\n } else if (Util.containsClass(this.overlay, \"wrs_stack\")) {\n this.container.style.left = null;\n this.container.style.top = null;\n this.removeClass(\"wrs_stack\");\n }\n\n this.addClass(\"wrs_maximized\");\n\n // Change maximize icon to minimize icon\n const generalStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minIcon)})`;\n const hoverStyle = `background-size: 10px; background-repeat: no-repeat; background-image: url(data:image/svg+xml;base64,${window.btoa(minHoverIcon)})`;\n this.minimizeDiv.setAttribute(\"style\", generalStyle);\n this.minimizeDiv.addEventListener(\"mouseover\", (e) => (e.target.style = hoverStyle));\n this.minimizeDiv.addEventListener(\"mouseout\", (e) => (e.target.style = generalStyle));\n\n // Set size to 80% screen with a max size.\n this.setSize(parseInt(window.innerHeight * 0.8, 10), parseInt(window.innerWidth * 0.8, 10));\n if (this.container.clientHeight > 700) {\n this.container.style.height = \"700px\";\n }\n if (this.container.clientWidth > 1200) {\n this.container.style.width = \"1200px\";\n }\n\n // Setting modal position in center on screen.\n const { innerHeight } = window;\n const { innerWidth } = window;\n const { offsetHeight } = this.container;\n const { offsetWidth } = this.container;\n const bottom = innerHeight / 2 - offsetHeight / 2;\n const right = innerWidth / 2 - offsetWidth / 2;\n\n this.setPosition(bottom, right);\n this.recalculateScale();\n this.recalculatePosition();\n this.recalculateSize();\n this.focus();\n }\n\n /**\n * Expand again the modal object from a minimized state.\n */\n reExpand() {\n if (this.properties.state === \"minimized\") {\n if (this.properties.previousState === \"maximized\") {\n this.maximize();\n } else {\n this.stack();\n }\n this.title.style.cursor = \"\";\n }\n }\n\n /**\n * Sets modal size.\n * @param {Number} height - Height of the ModalDialog\n * @param {Number} width - Width of the ModalDialog.\n */\n setSize(height, width) {\n this.container.style.height = `${height}px`;\n this.container.style.width = `${width}px`;\n this.recalculateSize();\n }\n\n /**\n * Sets modal position using bottom and right style attributes.\n * @param {number} bottom - bottom attribute.\n * @param {number} right - right attribute.\n */\n setPosition(bottom, right) {\n this.container.style.bottom = `${bottom}px`;\n this.container.style.right = `${right}px`;\n }\n\n /**\n * Saves position and size parameters of and open ModalDialog. This attributes\n * are needed to restore it on re-open.\n */\n saveModalProperties() {\n // Saving values of modal only when modal is in stack state.\n if (this.properties.state === \"stack\") {\n this.properties.position.bottom = parseInt(this.container.style.bottom, 10);\n this.properties.position.right = parseInt(this.container.style.right, 10);\n this.properties.size.width = parseInt(this.container.style.width, 10);\n this.properties.size.height = parseInt(this.container.style.height, 10);\n }\n }\n\n /**\n * Restore ModalDialog position and size parameters.\n */\n restoreModalProperties() {\n if (this.properties.state === \"stack\") {\n // Restoring Bottom and Right values from last modal.\n this.setPosition(this.properties.position.bottom, this.properties.position.right);\n // Restoring Height and Left values from last modal.\n this.setSize(this.properties.size.height, this.properties.size.width);\n }\n }\n\n /**\n * Sets the modal dialog initial size.\n */\n recalculateSize() {\n this.contentContainer.style.height = `${parseInt(this.wrapper.offsetHeight - 50, 10)}px`;\n }\n\n /**\n * Enable or disable visibility of resize buttons in modal window depend on state.\n */\n setResizeButtonsVisibility() {\n if (this.properties.state === \"stack\") {\n this.resizerTL.style.visibility = \"visible\";\n this.resizerBR.style.visibility = \"visible\";\n } else {\n this.resizerTL.style.visibility = \"hidden\";\n this.resizerBR.style.visibility = \"hidden\";\n }\n }\n\n /**\n * Makes an object draggable adding mouse and touch events.\n */\n addListeners() {\n // Button events (maximize, minimize, stack and close).\n this.maximizeDiv.addEventListener(\"click\", this.maximize.bind(this), true);\n this.stackDiv.addEventListener(\"click\", this.stack.bind(this), true);\n this.minimizeDiv.addEventListener(\"click\", this.minimize.bind(this), true);\n this.closeDiv.addEventListener(\"click\", this.cancelAction.bind(this));\n this.maximizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n }\n },\n true,\n );\n this.stackDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.minimizeDiv.addEventListener(\n \"keypress\",\n (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n },\n true,\n );\n this.closeDiv.addEventListener(\"keypress\", (e) => {\n if (e.key === \"Enter\" || e.key === \" \" || e.keyCode === 13 || e.keyCode === 32) {\n // Handle enter and space.\n e.target.click();\n e.preventDefault();\n }\n });\n this.title.addEventListener(\"click\", this.reExpand.bind(this));\n\n // Overlay events (close).\n this.overlay.addEventListener(\"click\", this.cancelAction.bind(this));\n\n // Mouse events.\n Util.addEvent(window, \"mousedown\", this.startDrag.bind(this));\n Util.addEvent(window, \"mouseup\", this.stopDrag.bind(this));\n Util.addEvent(window, \"mousemove\", this.drag.bind(this));\n Util.addEvent(window, \"resize\", this.onWindowResize.bind(this));\n // Key events.\n Util.addEvent(window, \"keydown\", this.onKeyDown.bind(this));\n }\n\n /**\n * Removes draggable events from an object.\n */\n removeListeners() {\n // Mouse events.\n Util.removeEvent(window, \"mousedown\", this.startDrag);\n Util.removeEvent(window, \"mouseup\", this.stopDrag);\n Util.removeEvent(window, \"mousemove\", this.drag);\n Util.removeEvent(window, \"resize\", this.onWindowResize);\n // Key events.\n Util.removeEvent(window, \"keydown\", this.onKeyDown);\n }\n\n /**\n * Returns mouse or touch coordinates (on touch events ev.ClientX doesn't exists)\n * @param {MouseEvent} mouseEvent - Mouse event.\n * @return {Object} With the X and Y coordinates.\n */\n // eslint-disable-next-line class-methods-use-this\n eventClient(mouseEvent) {\n if (typeof mouseEvent.clientX === \"undefined\" && mouseEvent.changedTouches) {\n const client = {\n X: mouseEvent.changedTouches[0].clientX,\n Y: mouseEvent.changedTouches[0].clientY,\n };\n return client;\n }\n const client = {\n X: mouseEvent.clientX,\n Y: mouseEvent.clientY,\n };\n return client;\n }\n\n /**\n * Start drag function: set the object dragDataObject with the draggable\n * object offsets coordinates.\n * when drag starts (on touchstart or mousedown events).\n * @param {MouseEvent} mouseEvent - Touchstart or mousedown event.\n */\n startDrag(mouseEvent) {\n if (this.properties.state === \"minimized\") {\n return;\n }\n if (mouseEvent.target === this.title) {\n if (typeof this.dragDataObject === \"undefined\" || this.dragDataObject === null) {\n // Save first click mouse point on screen.\n this.dragDataObject = {\n x: this.eventClient(mouseEvent).X,\n y: this.eventClient(mouseEvent).Y,\n };\n // Reset last drag position when start drag.\n this.lastDrag = {\n x: \"0px\",\n y: \"0px\",\n };\n // Init right and bottom values for window modal if it isn't exist.\n if (this.container.style.right === \"\") {\n this.container.style.right = \"0px\";\n }\n if (this.container.style.bottom === \"\") {\n this.container.style.bottom = \"0px\";\n }\n\n // Needed for IE11 for apply disabled mouse events on editor because\n // internet explorer needs a dynamic object to apply this property.\n if (this.isIE11()) {\n // this.iframe.style['position'] = 'relative';\n }\n // Apply class for disable involuntary select text when drag.\n Util.addClass(document.body, \"wrs_noselect\");\n Util.addClass(this.overlay, \"wrs_overlay_active\");\n // Obtain screen limits for prevent overflow.\n this.limitWindow = this.getLimitWindow();\n }\n }\n }\n\n /**\n * Updates dragDataObject with the draggable object coordinates when\n * the draggable object is being moved.\n * @param {MouseEvent} mouseEvent - The mouse event.\n */\n drag(mouseEvent) {\n if (this.dragDataObject) {\n mouseEvent.preventDefault();\n // Calculate max and min between actual mouse position and limit of screeen.\n // It restric the movement of modal into window.\n let limitY = Math.min(this.eventClient(mouseEvent).Y, this.limitWindow.minPointer.y);\n limitY = Math.max(this.limitWindow.maxPointer.y, limitY);\n let limitX = Math.min(this.eventClient(mouseEvent).X, this.limitWindow.minPointer.x);\n limitX = Math.max(this.limitWindow.maxPointer.x, limitX);\n // Subtract limit with first position to obtain relative pixels increment\n // to the anchor point.\n const dragX = `${limitX - this.dragDataObject.x}px`;\n const dragY = `${limitY - this.dragDataObject.y}px`;\n // Save last valid position of modal before window overflow.\n this.lastDrag = {\n x: dragX,\n y: dragY,\n };\n // This move modal with hardware acceleration.\n this.container.style.transform = `translate3d(${dragX},${dragY},0)`;\n }\n if (this.resizeDataObject) {\n const { innerWidth } = window;\n const { innerHeight } = window;\n let limitX = Math.min(this.eventClient(mouseEvent).X, innerWidth - this.scrollbarWidth - 7);\n let limitY = Math.min(this.eventClient(mouseEvent).Y, innerHeight - 7);\n if (limitX < 0) {\n limitX = 0;\n }\n\n if (limitY < 0) {\n limitY = 0;\n }\n\n let scaleMultiplier;\n if (this.leftScale) {\n scaleMultiplier = -1;\n } else {\n scaleMultiplier = 1;\n }\n\n this.container.style.width = `${this.initialWidth + scaleMultiplier * (limitX - this.resizeDataObject.x)}px`;\n this.container.style.height = `${this.initialHeight + scaleMultiplier * (limitY - this.resizeDataObject.y)}px`;\n if (!this.leftScale) {\n if (this.resizeDataObject.x - limitX - this.initialWidth < -580) {\n this.container.style.right = `${this.initialRight - (limitX - this.resizeDataObject.x)}px`;\n } else {\n this.container.style.right = `${this.initialRight + this.initialWidth - 580}px`;\n this.container.style.width = \"580px\";\n }\n if (this.resizeDataObject.y - limitY < this.initialHeight - 338) {\n this.container.style.bottom = `${this.initialBottom - (limitY - this.resizeDataObject.y)}px`;\n } else {\n this.container.style.bottom = `${this.initialBottom + this.initialHeight - 338}px`;\n this.container.style.height = \"338px\";\n }\n }\n this.recalculateScale();\n this.recalculatePosition();\n }\n }\n\n /**\n * Returns the boundaries of actual window to limit modal movement.\n * @return {Object} Object containing mouseX and mouseY coordinates of actual mouse on screen.\n */\n getLimitWindow() {\n // Obtain dimensions of window page.\n const maxWidth = window.innerWidth;\n const maxHeight = window.innerHeight;\n\n // Calculate relative position of mouse point into window.\n const { offsetHeight } = this.container;\n const contStyleBottom = parseInt(this.container.style.bottom, 10);\n const contStyleRight = parseInt(this.container.style.right, 10);\n\n const { pageXOffset } = window;\n const dragY = this.dragDataObject.y;\n const dragX = this.dragDataObject.x;\n\n const offSetToolbarY = offsetHeight + contStyleBottom - (maxHeight - (dragY - pageXOffset));\n const offSetToolbarX = maxWidth - this.scrollbarWidth - (dragX - pageXOffset) - contStyleRight;\n\n // Calculate limits with sizes of window, modal and mouse position.\n const minPointerY = maxHeight - this.container.offsetHeight + offSetToolbarY;\n const maxPointerY = this.title.offsetHeight - (this.title.offsetHeight - offSetToolbarY);\n const minPointerX = maxWidth - offSetToolbarX - this.scrollbarWidth;\n const maxPointerX = this.container.offsetWidth - offSetToolbarX;\n const minPointer = { x: minPointerX, y: minPointerY };\n const maxPointer = { x: maxPointerX, y: maxPointerY };\n return { minPointer, maxPointer };\n }\n\n /**\n * Returns the scrollbar width size of browser\n * @returns {Number} The scrollbar width.\n */\n // eslint-disable-next-line class-methods-use-this\n getScrollBarWidth() {\n // Create a paragraph with full width of page.\n const inner = document.createElement(\"p\");\n inner.style.width = \"100%\";\n inner.style.height = \"200px\";\n\n // Create a hidden div to compare sizes.\n const outer = document.createElement(\"div\");\n outer.style.position = \"absolute\";\n outer.style.top = \"0px\";\n outer.style.left = \"0px\";\n outer.style.visibility = \"hidden\";\n outer.style.width = \"200px\";\n outer.style.height = \"150px\";\n outer.style.overflow = \"hidden\";\n outer.appendChild(inner);\n\n document.body.appendChild(outer);\n const widthOuter = inner.offsetWidth;\n\n // Change type overflow of paragraph for measure scrollbar.\n outer.style.overflow = \"scroll\";\n let widthInner = inner.offsetWidth;\n\n // If measure is the same, we compare with internal div.\n if (widthOuter === widthInner) {\n widthInner = outer.clientWidth;\n }\n document.body.removeChild(outer);\n\n return widthOuter - widthInner;\n }\n\n /**\n * Set the dragDataObject to null.\n */\n stopDrag() {\n // Due to we have multiple events that call this function, we need only to execute\n // the next modifiers one time,\n // when the user stops to drag and dragDataObject is not null (the object to drag is attached).\n if (this.dragDataObject || this.resizeDataObject) {\n // If modal doesn't change, it's not necessary to set position with interpolation.\n this.container.style.transform = \"\";\n if (this.dragDataObject) {\n this.container.style.right = `${parseInt(this.container.style.right, 10) - parseInt(this.lastDrag.x, 10)}px`;\n this.container.style.bottom = `${parseInt(this.container.style.bottom, 10) - parseInt(this.lastDrag.y, 10)}px`;\n }\n // We make focus on editor after drag modal windows to prevent lose focus.\n this.focus();\n // Restore mouse events on iframe.\n // this.iframe.style['pointer-events'] = 'auto';\n document.body.style[\"user-select\"] = \"\";\n // Restore static state of iframe if we use Internet Explorer.\n if (this.isIE11()) {\n // this.iframe.style['position'] = null;\n }\n // Active text select event.\n Util.removeClass(document.body, \"wrs_noselect\");\n Util.removeClass(this.overlay, \"wrs_overlay_active\");\n }\n this.dragDataObject = null;\n this.resizeDataObject = null;\n this.initialWidth = null;\n this.leftScale = null;\n }\n\n /**\n * Recalculates scale for modal when resize browser window.\n */\n onWindowResize() {\n this.recalculateScrollBar();\n this.recalculatePosition();\n this.recalculateScale();\n }\n\n /**\n * Triggers keyboard events:\n * - Tab key tab to go to submit button.\n * - Esc key to close the modal dialog.\n * @param {KeyboardEvent} keyboardEvent - The keyboard event.\n */\n onKeyDown(keyboardEvent) {\n if (keyboardEvent.key !== undefined) {\n // Popupmessage is not oppened.\n if (this.popup.overlayWrapper.style.display !== \"block\") {\n // Code to detect Esc event\n if (keyboardEvent.key === \"Escape\" || keyboardEvent.key === \"Esc\") {\n if (this.properties.open) {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.shiftKey && keyboardEvent.key === \"Tab\") {\n // Code to detect shift Tab event.\n if (document.activeElement === this.cancelButton) {\n this.submitButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n } else if (keyboardEvent.key === \"Tab\") {\n // Code to detect Tab event.\n if (document.activeElement === this.submitButton) {\n this.cancelButton.focus();\n keyboardEvent.stopPropagation();\n keyboardEvent.preventDefault();\n } else {\n this.contentManager.onKeyDown(keyboardEvent);\n }\n }\n } else {\n // Popupmessage oppened.\n this.popup.onKeyDown(keyboardEvent);\n }\n }\n }\n\n /**\n * Recalculating position for modal dialog when the browser is resized.\n */\n recalculatePosition() {\n this.container.style.right = `${Math.min(parseInt(this.container.style.right, 10), window.innerWidth - this.scrollbarWidth - this.container.offsetWidth)}px`;\n if (parseInt(this.container.style.right, 10) < 0) {\n this.container.style.right = \"0px\";\n }\n this.container.style.bottom = `${Math.min(parseInt(this.container.style.bottom, 10), window.innerHeight - this.container.offsetHeight)}px`;\n if (parseInt(this.container.style.bottom, 10) < 0) {\n this.container.style.bottom = \"0px\";\n }\n }\n\n /**\n * Recalculating scale for modal when the browser is resized.\n */\n recalculateScale() {\n let sizeModified = false;\n\n if (parseInt(this.container.style.width, 10) > 580) {\n this.container.style.width = `${Math.min(parseInt(this.container.style.width, 10), window.innerWidth - this.scrollbarWidth)}px`;\n sizeModified = true;\n } else {\n this.container.style.width = \"580px\";\n sizeModified = true;\n }\n\n if (parseInt(this.container.style.height, 10) > 338) {\n this.container.style.height = `${Math.min(parseInt(this.container.style.height, 10), window.innerHeight)}px`;\n sizeModified = true;\n } else {\n this.container.style.height = \"338px\";\n sizeModified = true;\n }\n\n if (sizeModified) {\n this.recalculateSize();\n }\n }\n\n /**\n * Recalculating width of browser scroll bar.\n */\n recalculateScrollBar() {\n this.hasScrollBar = window.innerWidth > document.documentElement.clientWidth;\n if (this.hasScrollBar) {\n this.scrollbarWidth = this.getScrollBarWidth();\n } else {\n this.scrollbarWidth = 0;\n }\n }\n\n /**\n * Hide soft keyboards on iOS devices.\n */\n // eslint-disable-next-line class-methods-use-this\n hideKeyboard() {\n // iOS keyboard can't be detected or hide directly from JavaScript.\n // So, this method simulates that user focus a text input and blur\n // the selection.\n const inputField = document.createElement(\"input\");\n this.container.appendChild(inputField);\n inputField.focus();\n inputField.blur();\n // Is removed to not see it.\n inputField.remove();\n }\n\n /**\n * Focus to contentManager object.\n */\n focus() {\n if (this.contentManager != null && typeof this.contentManager.onFocus !== \"undefined\") {\n this.contentManager.onFocus();\n }\n }\n\n /**\n * Returns true when the device is on portrait mode.\n */\n // eslint-disable-next-line class-methods-use-this\n portraitMode() {\n return window.innerHeight > window.innerWidth;\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is opened.\n */\n handleOpenedIosSoftkeyboard() {\n if (!this.iosSoftkeyboardOpened && this.iosDivHeight != null && this.iosDivHeight === `auto`) {\n if (this.portraitMode()) {\n this.setContainerHeight(`60${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`35${this.iosMeasureUnit}`);\n }\n }\n this.iosSoftkeyboardOpened = true;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Event handler that change container size when IOS soft keyboard is closed.\n */\n handleClosedIosSoftkeyboard() {\n this.iosSoftkeyboardOpened = false;\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Change container sizes when orientation is changed on iOS.\n */\n orientationChangeIosSoftkeyboard() {\n if (this.iosSoftkeyboardOpened) {\n if (this.portraitMode()) {\n this.setContainerHeight(`65${this.iosMeasureUnit}`);\n } else {\n this.setContainerHeight(`45${this.iosMeasureUnit}`);\n }\n } else {\n this.wrapper.style.flexGrow = \"1\";\n }\n }\n\n /**\n * Change container sizes when orientation is changed on Android.\n */\n orientationChangeAndroidSoftkeyboard() {\n this.wrapper.style.flexGrow = \"1\";\n }\n\n /**\n * Set iframe container height.\n * @param {Number} height - New height.\n */\n setContainerHeight(height) {\n this.iosDivHeight = height;\n this.wrapper.style.height = height;\n }\n\n /**\n * Check content of editor before close action.\n */\n showPopUpMessage() {\n if (this.properties.state === \"minimized\") {\n this.stack();\n }\n this.popup.show();\n }\n\n /**\n * Sets the title of the modal dialog.\n * @param {String} title - Modal dialog title.\n */\n setTitle(title) {\n this.title.innerHTML = title;\n }\n\n /**\n * Returns the id of an element, adding the instance number to\n * the element class name:\n * className --> className[idNumber]\n * @param {String} className - The element class name.\n * @returns {String} A string appending the instance id to the className.\n */\n getElementId(className) {\n return `${className}[${this.instanceId}]`;\n }\n}\n","/* eslint-disable */\nvar polyfills;\nexport default polyfills;\n\n// Polyfills.\n/*! http://mths.be/codepointat v0.1.0 by @mathias */\nif (!String.prototype.codePointAt) {\n (function () {\n \"use strict\"; // needed to support `apply`/`call` with `undefined`/`null`\n var codePointAt = function (position) {\n if (this == null) {\n throw TypeError();\n }\n var string = String(this);\n var size = string.length;\n // `ToInteger`\n var index = position ? Number(position) : 0;\n if (index != index) {\n // better `isNaN`\n index = 0;\n }\n // Account for out-of-bounds indices:\n if (index < 0 || index >= size) {\n return undefined;\n }\n // Get the first code unit\n var first = string.charCodeAt(index);\n var second;\n if (\n // check if it’s the start of a surrogate pair\n first >= 0xd800 &&\n first <= 0xdbff && // high surrogate\n size > index + 1 // there is a next code unit\n ) {\n second = string.charCodeAt(index + 1);\n if (second >= 0xdc00 && second <= 0xdfff) {\n // low surrogate\n // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae\n return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000;\n }\n }\n return first;\n };\n if (Object.defineProperty) {\n Object.defineProperty(String.prototype, \"codePointAt\", {\n value: codePointAt,\n configurable: true,\n writable: true,\n });\n } else {\n String.prototype.codePointAt = codePointAt;\n }\n })();\n}\n\n// Object.assign polyfill.\nif (typeof Object.assign != \"function\") {\n // Must be writable: true, enumerable: false, configurable: true\n Object.defineProperty(Object, \"assign\", {\n value: function assign(target, varArgs) {\n // .length of function is 2\n \"use strict\";\n if (target == null) {\n // TypeError if undefined or null\n throw new TypeError(\"Cannot convert undefined or null to object\");\n }\n\n var to = Object(target);\n\n for (var index = 1; index < arguments.length; index++) {\n var nextSource = arguments[index];\n\n if (nextSource != null) {\n // Skip over if undefined or null\n for (var nextKey in nextSource) {\n // Avoid bugs when hasOwnProperty is shadowed\n if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {\n to[nextKey] = nextSource[nextKey];\n }\n }\n }\n }\n return to;\n },\n writable: true,\n configurable: true,\n });\n}\n\n// https://tc39.github.io/ecma262/#sec-array.prototype.includes\nif (!Array.prototype.includes) {\n Object.defineProperty(Array.prototype, \"includes\", {\n value: function (searchElement, fromIndex) {\n if (this == null) {\n throw new TypeError('\"this\" s null or is not defined');\n }\n\n // 1. Let O be ? ToObject(this value).\n var o = Object(this);\n\n // 2. Let len be ? ToLength(? Get(O, \"length\")).\n var len = o.length >>> 0;\n\n // 3. if len is 0, return false.\n if (len === 0) {\n return false;\n }\n\n // 4. Let n be ? ToInteger(fromIndex).\n // (if fromIndex is undefinedo, this step generates the value 0.)\n var n = fromIndex | 0;\n\n // 5. if n ≥ 0, then\n // a. Let k be n.\n // 6. Else n < 0,\n // a. Let k be len + n.\n // b. if k < 0, let k be 0.\n var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);\n\n function sameValueZero(x, y) {\n return x === y || (typeof x === \"number\" && typeof y === \"number\" && isNaN(x) && isNaN(y));\n }\n\n // 7. Repeat while k < len\n while (k < len) {\n // a. let element k be the result of ? Get(O, ! ToString(k)).\n // b. if SameValueZero(searchElement, elementK) is true, return true.\n if (sameValueZero(o[k], searchElement)) {\n return true;\n }\n // c. Increase k by 1.\n k++;\n }\n\n // 8. Return false\n return false;\n },\n });\n}\n\nif (!String.prototype.includes) {\n String.prototype.includes = function (search, start) {\n \"use strict\";\n\n if (search instanceof RegExp) {\n throw TypeError(\"first argument must not be a RegExp\");\n }\n if (start === undefined) {\n start = 0;\n }\n return this.indexOf(search, start) !== -1;\n };\n}\n\nif (!String.prototype.startsWith) {\n Object.defineProperty(String.prototype, \"startsWith\", {\n value: function (search, rawPos) {\n var pos = rawPos > 0 ? rawPos | 0 : 0;\n return this.substring(pos, pos + search.length) === search;\n },\n });\n}\n","import Parser from \"./parser\";\nimport Util from \"./util\";\nimport StringManager from \"./stringmanager\";\nimport ContentManager from \"./contentmanager\";\nimport Latex from \"./latex\";\nimport MathML from \"./mathml\";\nimport CustomEditors from \"./customeditors\";\nimport Configuration from \"./configuration\";\nimport jsProperties from \"./jsvariables\";\nimport Event from \"./event\";\nimport Listeners from \"./listeners\";\nimport Image from \"./image\";\nimport ServiceProvider from \"./serviceprovider\";\nimport ModalDialog from \"./modal\";\nimport Telemeter from \"./telemeter\";\nimport \"./polyfills\";\nimport \"../styles/styles.css\";\n\n/**\n * @typedef {Object} CoreProperties\n * @property {ServiceProviderProperties} serviceProviderProperties\n * - The ServiceProvider class properties. *\n */\nexport default class Core {\n /**\n * @classdesc\n * This class represents MathType integration Core, managing the following:\n * - Integration initialization.\n * - Event managing.\n * - Insertion of formulas into the edit area.\n * ```js\n * let core = new Core();\n * core.addListener(listener);\n * core.language = 'en';\n *\n * // Initializing Core class.\n * core.init(configurationService);\n * ```\n * @constructs\n * Core constructor.\n * @param {CoreProperties}\n */\n constructor(coreProperties) {\n /**\n * Language. Needed for accessibility and locales. 'en' by default.\n * @type {String}\n */\n this.language = \"en\";\n\n /**\n * Edit mode, 'images' by default. Admits the following values:\n * - images\n * - latex\n * @type {String}\n */\n this.editMode = \"images\";\n\n /**\n * Modal dialog instance.\n * @type {ModalDialog}\n */\n this.modalDialog = null;\n\n /**\n * The instance of {@link CustomEditors}. By default\n * the only custom editor is the Chemistry editor.\n * @type {CustomEditors}\n */\n this.customEditors = new CustomEditors();\n\n /**\n * Chemistry editor.\n * @type {CustomEditor}\n */\n const chemEditorParams = {\n name: \"Chemistry\",\n toolbar: \"chemistry\",\n icon: \"chem.png\",\n confVariable: \"chemEnabled\",\n title: \"ChemType\",\n tooltip: \"Insert a chemistry formula - ChemType\", // TODO: Localize tooltip.\n };\n\n this.customEditors.addEditor(\"chemistry\", chemEditorParams);\n\n /**\n * Environment properties. This object contains data about the integration platform.\n * @typedef IntegrationEnvironment\n * @property {String} IntegrationEnvironment.editor - Editor name. For example the HTML editor.\n * @property {String} IntegrationEnvironment.mode - Integration save mode.\n * @property {String} IntegrationEnvironment.version - Integration version.\n *\n */\n\n /**\n * The environment properties object.\n * @type {IntegrationEnvironment}\n */\n this.environment = {};\n\n /**\n * @typedef EditionProperties\n * @property {Boolean} editionProperties.isNewElement - True if the formula is a new one.\n * False otherwise.\n * @property {HTMLImageElement} editionProperties.temporalImage- The image element.\n * Null if the formula is new.\n * @property {Range} editionProperties.latexRange - Tha range that contains the LaTeX formula.\n * @property {Range} editionProperties.range - The range that contains the image element.\n * @property {String} editionProperties.editMode - The edition mode. 'images' by default.\n */\n\n /**\n * The properties of the current edition process.\n * @type {EditionProperties}\n */\n this.editionProperties = {};\n\n this.editionProperties.isNewElement = true;\n this.editionProperties.temporalImage = null;\n this.editionProperties.latexRange = null;\n this.editionProperties.range = null;\n this.editionProperties.editionStartTime = null;\n\n /**\n * The {@link IntegrationModel} instance.\n * @type {IntegrationModel}\n */\n this.integrationModel = null;\n\n /**\n * The {@link ContentManager} instance.\n * @type {ContentManager}\n */\n this.contentManager = null;\n\n /**\n * The current browser.\n * @type {String}\n */\n this.browser = (() => {\n const ua = navigator.userAgent;\n let browser = \"none\";\n if (ua.search(\"Edge/\") >= 0) {\n browser = \"EDGE\";\n } else if (ua.search(\"Chrome/\") >= 0) {\n browser = \"CHROME\";\n } else if (ua.search(\"Trident/\") >= 0) {\n browser = \"IE\";\n } else if (ua.search(\"Firefox/\") >= 0) {\n browser = \"FIREFOX\";\n } else if (ua.search(\"Safari/\") >= 0) {\n browser = \"SAFARI\";\n }\n return browser;\n })();\n\n /**\n * Plugin listeners.\n * @type {Array.}\n */\n this.listeners = new Listeners();\n\n /**\n * Service provider properties.\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = {};\n if (\"serviceProviderProperties\" in coreProperties) {\n this.serviceProviderProperties = coreProperties.serviceProviderProperties;\n } else {\n throw new Error(\"serviceProviderProperties property missing.\");\n }\n }\n\n /**\n * Static property.\n * Core listeners.\n * @private\n * @type {Listeners}\n */\n static get globalListeners() {\n return Core._globalListeners;\n }\n\n /**\n * Static property setter.\n * Set core listeners.\n * @param {Listeners} value - The property value.\n * @ignore\n */\n static set globalListeners(value) {\n Core._globalListeners = value;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * True when Core.init was called. Otherwise, false.\n * @private\n * @type {Boolean}\n */\n static get initialized() {\n return Core._initialized;\n }\n\n /**\n * Core state. Says if it was loaded previously.\n * @param {Boolean} value - True to say that Core.init was called. Otherwise, false.\n * @ignore\n */\n static set initialized(value) {\n Core._initialized = value;\n }\n\n /**\n * Sets the {@link Core.integrationModel} property.\n * @param {IntegrationModel} integrationModel - The {@link IntegrationModel} property.\n */\n setIntegrationModel(integrationModel) {\n this.integrationModel = integrationModel;\n }\n\n /**\n * Sets the {@link Core.environment} property.\n * @param {IntegrationEnvironment} integrationEnvironment -\n * The {@link IntegrationEnvironment} object.\n */\n setEnvironment(integrationEnvironment) {\n if (\"editor\" in integrationEnvironment) {\n this.environment.editor = integrationEnvironment.editor;\n }\n if (\"mode\" in integrationEnvironment) {\n this.environment.mode = integrationEnvironment.mode;\n }\n if (\"version\" in integrationEnvironment) {\n this.environment.version = integrationEnvironment.version;\n }\n }\n\n /**\n * Sets the custom headers added on editor requests if contentManager isn't undefined.\n * @returns {Object} headers - key value headers.\n */\n setHeaders(headers) {\n const headerObject = this?.contentManager?.setCustomHeaders(headers) || headers;\n Configuration.set(\"customHeaders\", headerObject);\n }\n\n /**\n * Returns the current {@link ModalDialog} instance.\n * @returns {ModalDialog} The current {@link ModalDialog} instance.\n */\n getModalDialog() {\n return this.modalDialog;\n }\n\n /**\n * Inits the {@link Core} class, doing the following:\n * - Calls asynchronously configuration service, retrieving the backend configuration in a JSON.\n * - Updates {@link Configuration} class with the previous configuration properties.\n * - Updates the {@link ServiceProvider} class using the configuration service path as reference.\n * - Loads language strings.\n * - Fires onLoad event.\n * @param {Object} serviceParameters - Service parameters.\n */\n init() {\n if (!Core.initialized) {\n const serviceProviderListener = Listeners.newListener(\"onInit\", () => {\n const jsConfiguration = ServiceProvider.getService(\"configurationjs\", \"\", \"get\");\n const jsonConfiguration = JSON.parse(jsConfiguration);\n Configuration.addConfiguration(jsonConfiguration);\n // Adding JavaScript (not backend) configuration variables.\n Configuration.addConfiguration(jsProperties);\n // Fire 'onLoad' event:\n // All integration must listen this event in order to know if the plugin\n // has been properly loaded.\n StringManager.language = this.language;\n this.listeners.fire(\"onLoad\", {});\n });\n\n ServiceProvider.addListener(serviceProviderListener);\n ServiceProvider.init(this.serviceProviderProperties);\n\n Core.initialized = true;\n } else {\n // Case when there are more than two editor instances.\n // After the first editor all the other editors don't need to load any file or service.\n this.listeners.fire(\"onLoad\", {});\n }\n }\n\n /**\n * Adds a {@link Listener} to the current instance of the {@link Core} class.\n * @param {Listener} listener - The listener object.\n */\n addListener(listener) {\n this.listeners.add(listener);\n }\n\n /**\n * Adds the global {@link Listener} instance to {@link Core} class.\n * @param {Listener} listener - The event listener to be added.\n * @static\n */\n static addGlobalListener(listener) {\n Core.globalListeners.add(listener);\n }\n\n beforeUpdateFormula(mathml, wirisProperties) {\n /**\n * This event is fired before updating the formula.\n * @type {Object}\n * @property {String} mathml - MathML to be transformed.\n * @property {String} editMode - Edit mode.\n * @property {Object} wirisProperties - Extra attributes for the formula.\n * @property {String} language - Formula language.\n */\n const beforeUpdateEvent = new Event();\n\n beforeUpdateEvent.mathml = mathml;\n\n // Cloning wirisProperties object\n // We don't want wirisProperties object modified.\n beforeUpdateEvent.wirisProperties = {};\n\n if (wirisProperties != null) {\n Object.keys(wirisProperties).forEach((attr) => {\n beforeUpdateEvent.wirisProperties[attr] = wirisProperties[attr];\n });\n }\n\n // Read only.\n beforeUpdateEvent.language = this.language;\n beforeUpdateEvent.editMode = this.editMode;\n\n if (this.listeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onBeforeFormulaInsertion\", beforeUpdateEvent)) {\n return {};\n }\n\n return {\n mathml: beforeUpdateEvent.mathml,\n wirisProperties: beforeUpdateEvent.wirisProperties,\n };\n }\n\n /**\n * Converts a MathML into it's correspondent image and inserts the image is\n * inserted in a HTMLElement target by creating\n * a new image or updating an existing one.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the insertion.\n * @param {Window} windowTarget - The window element where the editable content is.\n * @param {String} mathml - The MathML.\n * @param {Array.} wirisProperties - The extra attributes for the formula.\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n /**\n * It is the object with the information of the node or latex to insert.\n * @typedef ReturnObject\n * @property {Node} [node] - The DOM node to insert.\n * @property {String} [latex] - The latex to insert.\n */\n const returnObject = {};\n\n if (!mathml) {\n this.insertElementOnSelection(null, focusElement, windowTarget);\n } else if (this.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n // this.integrationModel.getNonLatexNode is an integration wrapper\n // to have special behaviours for nonLatex.\n // Not all the integrations have special behaviours for nonLatex.\n if (!!this.integrationModel.fillNonLatexNode && !returnObject.latex) {\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.latex = returnObject.latex;\n this.integrationModel.fillNonLatexNode(afterUpdateEvent, windowTarget, mathml);\n } else {\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n }\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n } else {\n returnObject.node = Parser.mathmlToImgObject(windowTarget.document, mathml, wirisProperties, this.language);\n\n this.insertElementOnSelection(returnObject.node, focusElement, windowTarget);\n }\n\n return returnObject;\n }\n\n afterUpdateFormula(focusElement, windowTarget, node, latex) {\n /**\n * This event is fired after update the formula.\n * @type {Event}\n * @param {String} editMode - edit mode.\n * @param {Object} windowTarget - target window.\n * @param {Object} focusElement - target element to be focused after update.\n * @param {String} latex - LaTeX generated by the formula (editMode=latex).\n * @param {Object} node - node generated after update the formula (text if LaTeX img otherwise).\n */\n const afterUpdateEvent = new Event();\n afterUpdateEvent.editMode = this.editMode;\n afterUpdateEvent.windowTarget = windowTarget;\n afterUpdateEvent.focusElement = focusElement;\n afterUpdateEvent.node = node;\n afterUpdateEvent.latex = latex;\n\n if (this.listeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n if (Core.globalListeners.fire(\"onAfterFormulaInsertion\", afterUpdateEvent)) {\n return {};\n }\n\n return {};\n }\n\n /**\n * Sets the caret after a given Node and set the focus to the owner document.\n * @param {Node} node - The Node element.\n */\n placeCaretAfterNode(node) {\n if (node === null) return;\n\n this.integrationModel.getSelection();\n const nodeDocument = node.ownerDocument;\n if (typeof nodeDocument.getSelection !== \"undefined\" && !!node.parentElement) {\n const range = nodeDocument.createRange();\n range.setStartAfter(node);\n range.collapse(true);\n const selection = nodeDocument.getSelection();\n selection.removeAllRanges();\n selection.addRange(range);\n nodeDocument.body.focus();\n }\n }\n\n /**\n * Replaces a Selection object with an HTMLElement.\n * @param {HTMLElement} element - The HTMLElement to replace the selection.\n * @param {HTMLElement} focusElement - The HTMLElement to be focused after the replace.\n * @param {Window} windowTarget - The window target.\n */\n insertElementOnSelection(element, focusElement, windowTarget) {\n let mathmlOrigin = null;\n if (this.editionProperties.isNewElement) {\n if (element) {\n if (focusElement.type === \"textarea\") {\n Util.updateTextArea(focusElement, element.textContent);\n } else if (document.selection && document.getSelection === 0) {\n let range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n\n if (!(\"parentElement\" in range)) {\n windowTarget.document.execCommand(\"delete\", false);\n range = windowTarget.document.selection.createRange();\n windowTarget.document.execCommand(\"InsertImage\", false, element.src);\n }\n\n if (\"parentElement\" in range) {\n const temporalObject = range.parentElement();\n\n if (temporalObject.nodeName.toUpperCase() === \"IMG\") {\n temporalObject.parentNode.replaceChild(element, temporalObject);\n } else {\n // IE9 fix: parentNode() does not return the IMG node,\n // returns the parent DIV node. In IE < 9, pasteHTML does not work well.\n range.pasteHTML(Util.createObjectCode(element));\n }\n }\n } else {\n let range = null;\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n if (this.editionProperties.range) {\n ({ range } = this.editionProperties);\n this.editionProperties.range = null;\n } else {\n const editorSelection = this.integrationModel.getSelection();\n range = editorSelection.getRangeAt(0);\n }\n\n // Delete if something was surrounded.\n range.deleteContents();\n\n let node = range.startContainer;\n const position = range.startOffset;\n\n if (node.nodeType === 3) {\n // TEXT_NODE.\n node = node.splitText(position);\n node.parentNode.insertBefore(element, node);\n } else if (node.nodeType === 1) {\n // ELEMENT_NODE.\n node.insertBefore(element, node.childNodes[position]);\n }\n\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n focusElement.focus();\n } else {\n const editorSelection = this.integrationModel.getSelection();\n editorSelection.removeAllRanges();\n\n if (this.editionProperties.range) {\n const { range } = this.editionProperties;\n this.editionProperties.range = null;\n editorSelection.addRange(range);\n }\n }\n } else if (this.editionProperties.latexRange) {\n if (document.selection && document.getSelection === 0) {\n this.editionProperties.isNewElement = true;\n this.editionProperties.latexRange.select();\n this.insertElementOnSelection(element, focusElement, windowTarget);\n } else {\n this.editionProperties.latexRange.deleteContents();\n this.editionProperties.latexRange.insertNode(element);\n this.placeCaretAfterNode(element);\n }\n } else if (focusElement.type === \"textarea\") {\n let item;\n // Wrapper for some integrations that can have special behaviours to show latex.\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n item = this.integrationModel.getSelectedItem(focusElement, false);\n } else {\n item = Util.getSelectedItemOnTextarea(focusElement);\n }\n Util.updateExistingTextOnTextarea(focusElement, element.textContent, item.startPosition, item.endPosition);\n } else {\n mathmlOrigin = this.editionProperties.temporalImage?.dataset.mathml;\n if (element && element.nodeName.toLowerCase() === \"img\") {\n // Editor empty, formula has been erased on edit.\n // There are editors (e.g: CKEditor) that put attributes in images.\n // We don't allow that behaviour in our images.\n Image.removeImgDataAttributes(this.editionProperties.temporalImage);\n // Clone is needed to maintain event references to temporalImage.\n Image.clone(element, this.editionProperties.temporalImage);\n } else {\n this.editionProperties.temporalImage.remove();\n }\n this.placeCaretAfterNode(this.editionProperties.temporalImage);\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const mathml = element?.dataset?.mathml;\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove the desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n }\n\n /**\n * Opens a modal dialog containing MathType editor..\n * @param {HTMLElement} target - The target HTMLElement where formulas should be inserted.\n * @param {Boolean} isIframe - True if the target HTMLElement is an iframe. False otherwise.\n */\n openModalDialog(target, isIframe) {\n // Count the time since the editor is open\n this.editionProperties.editionStartTime = Date.now();\n\n // Textarea elements don't have normal document ranges. It only accepts latex edit.\n this.editMode = \"images\";\n\n // In IE is needed keep the range due to after focus the modal window\n // it can't be retrieved the last selection.\n try {\n if (isIframe) {\n // Is needed focus the target first.\n target.contentWindow.focus();\n const selection = target.contentWindow.getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n } else {\n // Is needed focus the target first.\n target.focus();\n const selection = getSelection();\n this.editionProperties.range = selection.getRangeAt(0);\n }\n } catch (e) {\n this.editionProperties.range = null;\n }\n\n if (isIframe === undefined) {\n isIframe = true;\n }\n\n this.editionProperties.latexRange = null;\n\n if (target) {\n let selectedItem;\n if (typeof this.integrationModel.getSelectedItem !== \"undefined\") {\n selectedItem = this.integrationModel.getSelectedItem(target, isIframe);\n } else {\n selectedItem = Util.getSelectedItem(target, isIframe);\n }\n\n // Check LaTeX if and only if the node is a text node (nodeType==3).\n if (selectedItem) {\n // Case when image was selected and button pressed.\n if (!selectedItem.caretPosition && Util.containsClass(selectedItem.node, Configuration.get(\"imageClassName\"))) {\n this.editionProperties.temporalImage = selectedItem.node;\n this.editionProperties.isNewElement = false;\n } else if (selectedItem.node.nodeType === 3) {\n // If it's a text node means that editor is working with LaTeX.\n if (this.integrationModel.getMathmlFromTextNode) {\n // If integration has this function it isn't set range due to we don't\n // know if it will be put into a textarea as a text or image.\n const mathml = this.integrationModel.getMathmlFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (mathml) {\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n }\n } else {\n const latexResult = Latex.getLatexFromTextNode(selectedItem.node, selectedItem.caretPosition);\n if (latexResult) {\n const mathml = Latex.getMathMLFromLatex(latexResult.latex);\n this.editMode = \"latex\";\n this.editionProperties.isNewElement = false;\n this.editionProperties.temporalImage = document.createElement(\"img\");\n this.editionProperties.temporalImage.setAttribute(\n Configuration.get(\"imageMathmlAttribute\"),\n MathML.safeXmlEncode(mathml),\n );\n const windowTarget = isIframe ? target.contentWindow : window;\n\n if (target.tagName.toLowerCase() !== \"textarea\") {\n if (document.selection) {\n let leftOffset = 0;\n let previousNode = latexResult.startNode.previousSibling;\n\n while (previousNode) {\n leftOffset += Util.getNodeLength(previousNode);\n previousNode = previousNode.previousSibling;\n }\n\n this.editionProperties.latexRange = windowTarget.document.selection.createRange();\n this.editionProperties.latexRange.moveToElementText(latexResult.startNode.parentNode);\n this.editionProperties.latexRange.move(\"character\", leftOffset + latexResult.startPosition);\n this.editionProperties.latexRange.moveEnd(\"character\", latexResult.latex.length + 4); // Plus 4 for the '$$' characters.\n } else {\n this.editionProperties.latexRange = windowTarget.document.createRange();\n this.editionProperties.latexRange.setStart(latexResult.startNode, latexResult.startPosition);\n this.editionProperties.latexRange.setEnd(latexResult.endNode, latexResult.endPosition);\n }\n }\n }\n }\n }\n } else if (target.tagName.toLowerCase() === \"textarea\") {\n // By default editMode is 'images', but when target is a textarea it needs to be 'latex'.\n this.editMode = \"latex\";\n }\n }\n\n // Setting an object with the editor parameters.\n // Editor parameters can be customized in several ways:\n // 1 - editorAttributes: Contains the default editor attributes,\n // usually the metrics in a comma separated string. Always exists.\n // 2 - editorParameters: Object containing custom editor parameters.\n // These parameters are defined in the backend. So they affects all integration instances.\n\n // The backend send the default editor attributes in a coma separated\n // with the following structure: key1=value1,key2=value2...\n const defaultEditorAttributesArray = Configuration.get(\"editorAttributes\").split(\", \");\n const defaultEditorAttributes = {};\n for (let i = 0, len = defaultEditorAttributesArray.length; i < len; i += 1) {\n const tempAttribute = defaultEditorAttributesArray[i].split(\"=\");\n const key = tempAttribute[0];\n const value = tempAttribute[1];\n defaultEditorAttributes[key] = value;\n }\n // Custom editor parameters.\n const editorAttributes = {\n language: this.language, // Default language value\n };\n // Editor parameters in backend, usually configuration.ini.\n const serverEditorParameters = Configuration.get(\"editorParameters\");\n // Editor parameters through JavaScript configuration.\n const clientEditorParameters = this.integrationModel.editorParameters;\n Object.assign(editorAttributes, defaultEditorAttributes, serverEditorParameters);\n Object.assign(editorAttributes, defaultEditorAttributes, clientEditorParameters);\n\n // Now, update backwards: if user has set a custom language, pass that back to core properties\n this.language = editorAttributes.language;\n StringManager.language = this.language;\n\n editorAttributes.rtl = this.integrationModel.rtl;\n\n const customHeaders = Configuration.get(\"customHeaders\");\n // This is not being used in the code, we are keeping it just in case it's needed.\n // We check if it is a string since we have a setter that will make the customHeaders an object. And we do the conversion for the case when we get the headers from the backend.\n editorAttributes.customHeaders =\n typeof customHeaders === \"string\" ? Util.convertStringToObject(customHeaders) : customHeaders;\n\n const contentManagerAttributes = {};\n contentManagerAttributes.editorAttributes = editorAttributes;\n contentManagerAttributes.language = this.language;\n contentManagerAttributes.customEditors = this.customEditors;\n contentManagerAttributes.environment = this.environment;\n\n if (this.modalDialog == null) {\n this.modalDialog = new ModalDialog(editorAttributes);\n this.contentManager = new ContentManager(contentManagerAttributes);\n // When an instance of ContentManager is created we need to wait until\n // the ContentManager is ready by listening 'onLoad' event.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n });\n this.contentManager.addListener(listener);\n this.contentManager.init();\n this.modalDialog.setContentManager(this.contentManager);\n this.contentManager.setModalDialogInstance(this.modalDialog);\n } else {\n this.contentManager.dbclick = this.editionProperties.dbclick;\n this.contentManager.isNewElement = this.editionProperties.isNewElement;\n if (this.editionProperties.temporalImage != null) {\n const mathML = MathML.safeXmlDecode(\n this.editionProperties.temporalImage.getAttribute(Configuration.get(\"imageMathmlAttribute\")),\n );\n this.contentManager.mathML = mathML;\n }\n }\n this.contentManager.setIntegrationModel(this.integrationModel);\n this.modalDialog.open();\n }\n\n /**\n * Returns the {@link CustomEditors} instance.\n * @return {CustomEditors} The current {@link CustomEditors} instance.\n */\n getCustomEditors() {\n return this.customEditors;\n }\n}\n\n/**\n * Core static listeners.\n * @type {Listeners}\n * @private\n */\nCore._globalListeners = new Listeners();\n\n/**\n * Resources state. Says if they were loaded or not.\n * @type {Boolean}\n * @private\n */\nCore._initialized = false;\n","// eslint-disable-next-line no-unused-vars, import/named\nimport Core from \"./core.src\";\nimport Image from \"./image\";\nimport Listeners from \"./listeners\";\nimport Util from \"./util\";\nimport Configuration from \"./configuration\";\nimport ServiceProvider from \"./serviceprovider\";\nimport Telemeter from \"./telemeter\";\nimport warnIcon from \"../styles/icons/general/warn_icon.svg\"; //eslint-disable-line\n\n/**\n * @typedef {Object} IntegrationModelProperties\n * @property {string} configurationService - Configuration service path.\n * This parameter is needed to determine all services paths.\n * @property {HTMLElement} integrationModelProperties.target - HTML target.\n * @property {string} integrationModelProperties.scriptName - Integration script name.\n * Usually the name of the integration script.\n * @property {Object} integrationModelProperties.environment - integration environment properties.\n * @property {Object} [integrationModelProperties.callbackMethodArguments] - object containing\n * callback method arguments.\n * @property {string} [integrationModelProperties.version] - integration version number.\n * @property {Object} [integrationModelProperties.editorObject] - object containing\n * the integration editor instance.\n * @property {boolean} [integrationModelProperties.rtl] - true if the editor is in RTL mode.\n * false otherwise.\n * @property {ServiceProviderProperties} [integrationModelProperties.serviceProviderProperties]\n * - The service parameters.\n * @property {Object} [integrationModelProperties.integrationParameters]\n * - Overwritten integration parameters.\n */\n\nexport default class IntegrationModel {\n /**\n * @classdesc\n * This class represents an integration model, allowing the integration script to\n * communicate with Core class. Each integration must extend this class.\n * @constructs\n * @param {IntegrationModelProperties} integrationModelProperties\n */\n constructor(integrationModelProperties) {\n /**\n * Language. Needed for accessibility and locales. English by default.\n */\n this.language = \"en\";\n\n /**\n * Service parameters\n * @type {ServiceProviderProperties}\n */\n this.serviceProviderProperties = integrationModelProperties.serviceProviderProperties ?? {};\n\n /**\n * Configuration service path. The integration service is needed by Core class to\n * load all the backend configuration into the frontend and also to create the paths\n * of all services (all services lives in the same route). Mandatory property.\n */\n this.configurationService = \"\";\n if (\"configurationService\" in integrationModelProperties) {\n this.serviceProviderProperties.URI = integrationModelProperties.configurationService;\n console.warn(\"Deprecated property configurationService. Use serviceParameters on instead.\", [\n integrationModelProperties.configurationService,\n ]);\n }\n\n /**\n * Plugin version. Needed to stats and caching.\n * @type {string}\n */\n this.version = \"version\" in integrationModelProperties ? integrationModelProperties.version : \"\";\n\n /**\n * DOM target in which the plugin works. Needed to associate events, insert formulas, etc.\n * Mandatory property.\n */\n this.target = null;\n if (\"target\" in integrationModelProperties) {\n this.target = integrationModelProperties.target;\n } else {\n throw new Error(\"IntegrationModel constructor error: target property missed.\");\n }\n\n /**\n * Integration script name. Needed to know the plugin path.\n */\n if (\"scriptName\" in integrationModelProperties) {\n this.scriptName = integrationModelProperties.scriptName;\n }\n\n /**\n * Object containing the arguments needed by the callback function.\n */\n this.callbackMethodArguments = integrationModelProperties.callbackMethodArguments ?? {};\n\n /**\n * Contains information about the integration environment:\n * like the name of the editor, the version, etc.\n */\n this.environment = integrationModelProperties.environment ?? {};\n\n /**\n * Indicates if the DOM target is - or not - and iframe.\n */\n this.isIframe = false;\n if (this.target != null) {\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Instance of the integration editor object. Usually the entry point to access the API\n * of a HTML editor.\n */\n this.editorObject = integrationModelProperties.editorObject ?? null;\n\n /**\n * Specifies if the direction of the text is RTL. false by default.\n */\n this.rtl = integrationModelProperties.rtl ?? false;\n\n /**\n * Specifies if the integration model exposes the locale strings. false by default.\n */\n this.managesLanguage = integrationModelProperties.managesLanguage ?? false;\n\n /**\n * Specify if editor will open in hand mode only\n */\n this.forcedHandMode = integrationModelProperties?.integrationParameters?.forcedHandMode ?? false;\n\n /**\n * Indicates if an image is selected. Needed to resize the image to the original size in case\n * the image is resized.\n * @type {boolean}\n */\n this.temporalImageResizing = false;\n\n /**\n * The Core class instance associated to the integration model.\n * @type {Core}\n */\n this.core = null;\n\n /**\n * Integration model listeners.\n * @type {Listeners}\n */\n this.listeners = new Listeners();\n\n // Parameters overwrite.\n if (\"integrationParameters\" in integrationModelProperties) {\n IntegrationModel.integrationParameters.forEach((parameter) => {\n if (parameter in integrationModelProperties.integrationParameters) {\n // Don't add empty parameters.\n const value = integrationModelProperties.integrationParameters[parameter];\n if (Object.keys(value).length !== 0) {\n this[parameter] = value;\n }\n }\n });\n }\n }\n\n /**\n * Init function. Usually called from the integration side once the core.js file is loaded.\n */\n init() {\n // Check if language is an object and select the property necessary\n this.language = this.getLanguage();\n\n // We need to wait until Core class is loaded ('onLoad' event) before\n // call the callback method.\n const listener = Listeners.newListener(\"onLoad\", () => {\n this.callbackFunction(this.callbackMethodArguments);\n });\n\n // Backwards compatibility.\n if (this.serviceProviderProperties.URI.indexOf(\"configuration\") !== -1) {\n const uri = this.serviceProviderProperties.URI;\n const server = ServiceProvider.getServerLanguageFromService(uri);\n this.serviceProviderProperties.server = server;\n const configurationIndex = this.serviceProviderProperties.URI.indexOf(\"configuration\");\n const subsTring = this.serviceProviderProperties.URI.substring(0, configurationIndex);\n this.serviceProviderProperties.URI = subsTring;\n }\n\n let serviceParametersURI = this.serviceProviderProperties.URI;\n serviceParametersURI =\n serviceParametersURI.indexOf(\"/\") === 0 || serviceParametersURI.indexOf(\"http\") === 0\n ? serviceParametersURI\n : Util.concatenateUrl(this.getPath(), serviceParametersURI);\n\n this.serviceProviderProperties.URI = serviceParametersURI;\n\n const coreProperties = {};\n coreProperties.serviceProviderProperties = this.serviceProviderProperties;\n\n this.setCore(new Core(coreProperties));\n this.core.addListener(listener);\n this.core.language = this.language;\n\n // Initializing Core class.\n this.core.init();\n // TODO: Move to Core constructor.\n this.core.setEnvironment(this.environment);\n\n // No internet connection modal.\n let attributes = {};\n attributes.class = attributes.id = \"wrs_modal_offline\";\n this.offlineModal = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_content_offline\";\n this.offlineModalContent = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_close\";\n this.offlineModalClose = Util.createElement(\"span\", attributes);\n this.offlineModalClose.innerHTML = \"×\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_warn\";\n this.offlineModalWarn = Util.createElement(\"span\", attributes);\n const generalStyle = `background-image: url(data:image/svg+xml;base64,${window.btoa(warnIcon)})`;\n this.offlineModalWarn.setAttribute(\"style\", generalStyle);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_container\";\n this.offlineModalMessage = Util.createElement(\"div\", attributes);\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text_warn\";\n this.offlineModalMessage1 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage1.innerHTML = \"You are not online!\";\n\n attributes = {};\n attributes.class = \"wrs_modal_offline_text\";\n this.offlineModalMessage2 = Util.createElement(\"p\", attributes);\n this.offlineModalMessage2.innerHTML = `Thank you for using MathType. We have detected you are disconnected from the network. We remind you that you'll need to be connected to use MathType.

Please refresh the page if this message continues appearing.`;\n\n // Append offline modal elements\n this.offlineModalContent.appendChild(this.offlineModalClose);\n this.offlineModalMessage.appendChild(this.offlineModalMessage1);\n this.offlineModalMessage.appendChild(this.offlineModalMessage2);\n this.offlineModalContent.appendChild(this.offlineModalMessage);\n this.offlineModalContent.appendChild(this.offlineModalWarn);\n this.offlineModal.appendChild(this.offlineModalContent);\n document.body.appendChild(this.offlineModal);\n\n const modal = document.getElementById(\"wrs_modal_offline\");\n this.offlineModalClose.addEventListener(\"click\", () => {\n modal.style.display = \"none\";\n });\n\n // Store editor name for telemetry purposes.\n let editorName = this.environment.editor;\n editorName = editorName.slice(0, -1); // Remove version number from editors\n if (editorName.includes(\"TinyMCE\")) editorName = \"TinyMCE\"; // Remove version from Tinymce editor.\n if (editorName.includes(\"Generic\")) editorName = \"Generic\"; // Remove version from Generic editor.\n let solutionTelemeter = editorName;\n\n // If moodle, add information to hosts and solution.\n const isMoodle = !!(typeof M === \"object\" && M !== null);\n let lms;\n\n if (isMoodle) {\n solutionTelemeter = \"Moodle\";\n lms = {\n nam: \"moodle\",\n fam: \"lms\",\n ver: this.environment.moodleVersion,\n category: this.environment.moodleCourseCategory,\n course: this.environment.moodleCourseName,\n };\n if (!editorName.includes(\"TinyMCE\")) {\n editorName = \"Atto\";\n }\n }\n\n // Get the OS and its version.\n const OSData = this.getOS();\n\n // Get the broswer and its version.\n const broswerData = this.getBrowser();\n\n // Create list of hosts to send to telemetry.\n let hosts = [\n {\n nam: broswerData.detectedBrowser,\n fam: \"browser\",\n ver: broswerData.versionBrowser,\n },\n {\n nam: editorName.toLowerCase(),\n fam: \"html-editor\",\n ver: this.environment.editorVersion,\n },\n {\n nam: OSData.detectedOS,\n fam: \"os\",\n ver: OSData.versionOS,\n },\n {\n nam: window.location.hostname,\n fam: \"domain\",\n },\n lms,\n ];\n\n // Filter hosts to remove empty objects and empty keys.\n hosts = hosts.filter((element) => {\n if (element) Object.keys(element).forEach((key) => (element[key] === \"unknown\" ? delete element[key] : {}));\n return element !== undefined;\n });\n\n // Initialize telemeter\n Telemeter.init({\n solution: {\n name: `MathType for ${solutionTelemeter}`,\n version: this.version,\n },\n hosts,\n config: {\n test: false, // True to use the staging Telemetry endpoint instead of the production one.\n debug: false, // True to show more information about Telemeter's execution and use dev-tools.\n dry_run: false, // True to skip sending data to the Telemetry endpoint (for example for unit tests).\n api_key: \"eda2ce9b-0e8a-46f2-acdd-c228a615314e\", // to auth against Telemetry. Data team is the responsible of providing it.\n },\n url: undefined,\n });\n }\n\n /**\n * Returns the Browser name and its version.\n * @return {array} - detectedBrowser = Operating System name.\n * versionBrowser = Operating System version.\n */\n getBrowser() {\n // default value for OS just in case nothing is detected\n let detectedBrowser = \"unknown\";\n let versionBrowser = \"unknown\";\n\n const userAgent = window.navigator.userAgent;\n\n if (/Brave/.test(userAgent)) {\n detectedBrowser = \"brave\";\n if (userAgent.indexOf(\"Brave/\")) {\n const start = userAgent.indexOf(\"Brave\") + 6;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (userAgent.indexOf(\"Edg/\") !== -1) {\n detectedBrowser = \"edge_chromium\";\n const start = userAgent.indexOf(\"Edg/\") + 4;\n versionBrowser = userAgent\n .substring(start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Edg/.test(userAgent)) {\n detectedBrowser = \"edge\";\n let start = userAgent.indexOf(\"Edg\") + 3;\n start += userAgent.substring(start).indexOf(\"/\");\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Firefox/.test(userAgent) || /FxiOS/.test(userAgent)) {\n detectedBrowser = \"firefox\";\n let start = userAgent.indexOf(\"Firefox\");\n start = start === -1 ? userAgent.indexOf(\"FxiOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/OPR/.test(userAgent)) {\n detectedBrowser = \"opera\";\n const start = userAgent.indexOf(\"OPR/\") + 4;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Chrome/.test(userAgent) || /CriOS/.test(userAgent)) {\n detectedBrowser = \"chrome\";\n let start = userAgent.indexOf(\"Chrome\");\n start = start === -1 ? userAgent.indexOf(\"CriOS\") : start;\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n } else if (/Safari/.test(userAgent)) {\n detectedBrowser = \"safari\";\n let start = userAgent.indexOf(\"Version/\");\n start = start + userAgent.substring(start).indexOf(\"/\") + 1;\n let end = userAgent.substring(start).indexOf(\" \");\n end = end === -1 ? userAgent.lastIndexOf(\"\") : end;\n versionBrowser = userAgent.substring(start, end + start).replace(\"_\", \".\");\n }\n\n return { detectedBrowser, versionBrowser };\n }\n\n /**\n * Returns the operating system and its version.\n * @return {array} - detectedOS = Operating System name.\n * versionOS = Operating System version.\n */\n getOS() {\n // default value for OS just in case nothing is detected\n let detectedOS = \"unknown\";\n let versionOS = \"unknown\";\n\n // Retrieve properties to easily detect the OS\n const userAgent = window.navigator.userAgent;\n const platform = window.navigator.platform;\n const macosPlatforms = [\"Macintosh\", \"MacIntel\", \"MacPPC\", \"Mac68K\"];\n const windowsPlatforms = [\"Win32\", \"Win64\", \"Windows\", \"WinCE\"];\n const iosPlatforms = [\"iPhone\", \"iPad\", \"iPod\"];\n\n // Find OS and their respective versions\n if (macosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"macos\";\n if (userAgent.indexOf(\"OS X\") !== -1) {\n const start = userAgent.indexOf(\"OS X\") + 5;\n const end = userAgent.substring(start).indexOf(\" \");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (iosPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"ios\";\n if (userAgent.indexOf(\"OS \") !== -1) {\n const start = userAgent.indexOf(\"OS \") + 3;\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n }\n } else if (windowsPlatforms.indexOf(platform) !== -1) {\n detectedOS = \"windows\";\n const start = userAgent.indexOf(\"Windows\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/Android/.test(userAgent)) {\n detectedOS = \"android\";\n const start = userAgent.indexOf(\"Android\");\n let end = userAgent.substring(start).indexOf(\";\");\n if (end === -1) {\n end = userAgent.substring(start).indexOf(\")\");\n }\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (/CrOS/.test(userAgent)) {\n detectedOS = \"chromeos\";\n let start = userAgent.indexOf(\"CrOS \") + 5;\n start += userAgent.substring(start).indexOf(\" \");\n const end = userAgent.substring(start).indexOf(\")\");\n versionOS = userAgent\n .substring(start, end + start)\n .replace(\"_\", \".\")\n .replace(/[^\\d.-]/g, \"\");\n } else if (detectedOS === \"unknown\" && /Linux/.test(platform)) {\n detectedOS = \"linux\";\n }\n\n return { detectedOS, versionOS };\n }\n\n /**\n * Returns the absolute path of the integration script.\n * @return {string} - Absolute path for the integration script.\n */\n getPath() {\n if (typeof this.scriptName === \"undefined\") {\n throw new Error(\"scriptName property needed for getPath.\");\n }\n const col = document.getElementsByTagName(\"script\");\n let path = \"\";\n for (let i = 0; i < col.length; i += 1) {\n const j = col[i].src.lastIndexOf(this.scriptName);\n if (j >= 0) {\n path = col[i].src.substr(0, j - 1);\n }\n }\n return path;\n }\n\n /**\n * Returns integration model plugin version\n * @param {string} - Plugin version\n */\n getVersion() {\n return this.version;\n }\n\n /**\n * Sets the language property.\n * @param {string} language - language code.\n */\n setLanguage(language) {\n this.language = language;\n }\n\n /**\n * Sets a Core instance.\n * @param {Core} core - instance of Core class.\n */\n setCore(core) {\n this.core = core;\n core.setIntegrationModel(this);\n }\n\n /**\n * Returns the Core instance.\n * @returns {Core} instance of Core class.\n */\n getCore() {\n return this.core;\n }\n\n /**\n * Sets the object target and updates the iframe property.\n * @param {HTMLElement} target - target object.\n */\n setTarget(target) {\n this.target = target;\n this.isIframe = this.target.tagName.toUpperCase() === \"IFRAME\";\n }\n\n /**\n * Sets the editor object.\n * @param {Object} editorObject - The editor object.\n */\n setEditorObject(editorObject) {\n this.editorObject = editorObject;\n }\n\n /**\n * Opens formula editor to editing a new formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openNewFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.dbclick = false;\n this.core.editionProperties.isNewElement = true;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Opens formula editor to editing an existing formula. Can be overwritten in order to make some\n * actions from integration part before the formula is edited.\n */\n openExistingFormulaEditor() {\n if (window.navigator.onLine) {\n this.core.editionProperties.isNewElement = false;\n this.core.openModalDialog(this.target, this.isIframe);\n } else {\n const modal = document.getElementById(\"wrs_modal_offline\");\n modal.style.display = \"block\";\n }\n }\n\n /**\n * Wrapper to Core.updateFormula method.\n * Transform a MathML into a image formula.\n * Then the image formula is inserted in the specified target, creating a new image (new formula)\n * or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n */\n updateFormula(mathml) {\n if (this.editorParameters) {\n mathml = com.wiris.editor.util.EditorUtils.addAnnotation(\n mathml,\n \"application/vnd.wiris.mtweb-params+json\",\n JSON.stringify(this.editorParameters),\n );\n }\n let focusElement;\n let windowTarget;\n const wirisProperties = null;\n\n if (this.isIframe) {\n focusElement = this.target.contentWindow;\n windowTarget = this.target.contentWindow;\n } else {\n focusElement = this.target;\n windowTarget = window;\n }\n\n let obj = this.core.beforeUpdateFormula(mathml, wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n obj = this.insertFormula(focusElement, windowTarget, obj.mathml, obj.wirisProperties);\n\n if (!obj) {\n return \"\";\n }\n\n return this.core.afterUpdateFormula(obj.focusElement, obj.windowTarget, obj.node, obj.latex);\n }\n\n /**\n * Wrapper to Core.insertFormula method.\n * Inserts the formula in the specified target, creating\n * a new image (new formula) or updating an existing one.\n * @param {string} mathml - MathML to generate the formula.\n * @param {string} editMode - Edit Mode (LaTeX or images).\n * @returns {ReturnObject} - Object with the information of the node or latex to insert.\n */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n const obj = this.core.insertFormula(focusElement, windowTarget, mathml, wirisProperties);\n\n // Delete temporal image when inserted\n this.core.editionProperties.temporalImage = null;\n\n return obj;\n }\n\n /**\n * Returns the target selection.\n * @returns {Selection} target selection.\n */\n getSelection() {\n if (this.isIframe) {\n this.target.contentWindow.focus();\n return this.target.contentWindow.getSelection();\n }\n this.target.focus();\n return window.getSelection();\n }\n\n /**\n * Add events to formulas in the DOM target. The events added are the following:\n * - doubleClickHandler: handles Double-click event on formulas by opening an editor\n * to edit them.\n * - mouseDownHandler: handles mouse down event on formulas by saving the size of the formula\n * in case the the formula is resized.\n * - mouseUpHandler: handles mouse up event on formulas by restoring the saved formula size\n * in case the formula is resized.\n */\n addEvents() {\n const eventTarget = this.isIframe ? this.target.contentWindow.document : this.target;\n Util.addElementEvents(\n eventTarget,\n (element, event) => {\n this.doubleClickHandler(element, event);\n // Avoid creating the double click listener more than once for each element.\n // This also allows CKEditor4 to add their own double click listener.\n event.preventDefault();\n },\n (element, event) => {\n this.mousedownHandler(element, event);\n },\n (element, event) => {\n this.mouseupHandler(element, event);\n },\n );\n }\n\n /**\n * Remove events to formulas in the DOM target.\n */\n removeEvents() {\n const eventTarget =\n this.isIframe && this.target.contentWindow?.document ? this.target.contentWindow.document : this.target;\n\n if (!eventTarget) {\n return;\n }\n\n Util.removeElementEvents(eventTarget);\n }\n\n /**\n * Remove events, modals and set this.editorObject to null in order to prevent memory leaks.\n */\n destroy() {\n this.removeEvents();\n // Destroy modal dialog if exists.\n if (this.core.modalDialog) {\n this.core.modalDialog.destroy();\n }\n\n // Remove offline modal dialog if exists.\n if (this.offlineModal) {\n this.offlineModal.remove();\n }\n\n this.editorObject = null;\n }\n\n /**\n * Handles a Double-click on the target element. Opens an editor\n * to re-edit the double-clicked formula.\n * @param {HTMLElement} element - DOM object target.\n */\n doubleClickHandler(element) {\n this.core.editionProperties.dbclick = true;\n if (element.nodeName.toLowerCase() === \"img\") {\n this.core.getCustomEditors().disable();\n const customEditorAttributeName = Configuration.get(\"imageCustomEditorName\");\n if (element.hasAttribute(customEditorAttributeName)) {\n const customEditor = element.getAttribute(customEditorAttributeName);\n this.core.getCustomEditors().enable(customEditor);\n }\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.core.editionProperties.temporalImage = element;\n this.core.editionProperties.isNewElement = true;\n this.openExistingFormulaEditor();\n }\n }\n }\n\n /**\n * Handles a mouse up event on the target element. Restores the image size to avoid\n * resizing formulas.\n */\n mouseupHandler() {\n if (this.temporalImageResizing) {\n setTimeout(() => {\n Image.fixAfterResize(this.temporalImageResizing);\n }, 10);\n }\n }\n\n /**\n * Handles a mouse down event on the target element. Saves the formula size to avoid\n * resizing formulas.\n * @param {HTMLElement} element - target element.\n */\n mousedownHandler(element) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n this.temporalImageResizing = element;\n }\n }\n }\n\n /**\n * Returns the integration language. By default the browser agent. This method\n * should be overwritten to obtain the integration language, for example using the\n * plugin API of an HTML editor.\n * @returns {string} integration language.\n */\n getLanguage() {\n return this.getBrowserLanguage();\n }\n\n /**\n * Returns the browser language.\n * @returns {string} the browser language.\n */\n // eslint-disable-next-line class-methods-use-this\n getBrowserLanguage() {\n let language = \"en\";\n if (navigator.userLanguage) {\n language = navigator.userLanguage.substring(0, 2);\n } else if (navigator.language) {\n language = navigator.language.substring(0, 2);\n } else {\n language = \"en\";\n }\n return language;\n }\n\n /**\n * This function is called once the {@link Core} is loaded. IntegrationModel class\n * will fire this method when {@link Core} 'onLoad' event is fired.\n * This method should content all the logic to init\n * the integration.\n */\n callbackFunction() {\n // It's needed to wait until the integration target is ready. The event is fired\n // from the integration side.\n const listener = Listeners.newListener(\"onTargetReady\", () => {\n this.addEvents(this.target);\n });\n this.listeners.add(listener);\n }\n\n /**\n * Function called when the content submits an action.\n */\n // eslint-disable-next-line class-methods-use-this\n notifyWindowClosed() {\n // Nothing.\n }\n\n /**\n * Wrapper.\n * Extracts mathml of a determined text node. This function is used as a wrapper inside core.js\n * in order to get mathml from a text node that can contain normal LaTeX or other chosen text.\n * @param {string} textNode - text node to extract the MathML.\n * @param {int} caretPosition - caret position inside the text node.\n * @returns {string} MathML inside the text node.\n */\n\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getMathmlFromTextNode(textNode, caretPosition) {}\n\n /**\n * Wrapper\n * It fills wrs event object of nonLatex with the desired data.\n * @param {Object} event - event object.\n * @param {Object} window dom window object.\n * @param {string} mathml valid mathml.\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n fillNonLatexNode(event, window, mathml) {}\n\n /**\n Wrapper.\n * Returns selected item from the target.\n * @param {HTMLElement} target - target element\n * @param {boolean} iframe\n */\n // eslint-disable-next-line class-methods-use-this, no-unused-vars\n getSelectedItem(target, isIframe) {}\n\n // Set temporal image to null and make focus come back.\n static setActionsOnCancelButtons() {\n // Make focus come back on the previous place it was when click cancel button\n const currentInstance = WirisPlugin.currentInstance;\n const editorSelection = currentInstance.getSelection();\n editorSelection.removeAllRanges();\n\n if (currentInstance.core.editionProperties.range) {\n const { range } = currentInstance.core.editionProperties;\n currentInstance.core.editionProperties.range = null;\n editorSelection.addRange(range);\n if (range.startOffset !== range.endOffset) {\n currentInstance.core.placeCaretAfterNode(currentInstance.core.editionProperties.temporalImage);\n }\n }\n\n // eslint-disable-next-line no-undef\n if (WirisPlugin.currentInstance) {\n WirisPlugin.currentInstance.core.editionProperties.temporalImage = null; // eslint-disable-line\n }\n }\n}\n\n// To know if the integration that extends this class implements\n// wrapper methods, they are set as undefined.\nIntegrationModel.prototype.getMathmlFromTextNode = undefined;\nIntegrationModel.prototype.fillNonLatexNode = undefined;\nIntegrationModel.prototype.getSelectedItem = undefined;\n\n/**\n * An object containing a list with the overwritable class constructor properties.\n * @type {Object}\n */\nIntegrationModel.integrationParameters = [\"serviceProviderProperties\", \"editorParameters\"];\n","/* eslint-disable */\nvar md5;\nexport default md5;\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n delete Array.prototype.__class__;\n})();\n\n(function () {\n var HxOverrides = function () {};\n HxOverrides.__name__ = true;\n HxOverrides.dateStr = function (date) {\n var m = date.getMonth() + 1;\n var d = date.getDate();\n var h = date.getHours();\n var mi = date.getMinutes();\n var s = date.getSeconds();\n return (\n date.getFullYear() +\n \"-\" +\n (m < 10 ? \"0\" + m : \"\" + m) +\n \"-\" +\n (d < 10 ? \"0\" + d : \"\" + d) +\n \" \" +\n (h < 10 ? \"0\" + h : \"\" + h) +\n \":\" +\n (mi < 10 ? \"0\" + mi : \"\" + mi) +\n \":\" +\n (s < 10 ? \"0\" + s : \"\" + s)\n );\n };\n HxOverrides.strDate = function (s) {\n switch (s.length) {\n case 8:\n var k = s.split(\":\");\n var d = new Date();\n d.setTime(0);\n d.setUTCHours(k[0]);\n d.setUTCMinutes(k[1]);\n d.setUTCSeconds(k[2]);\n return d;\n case 10:\n var k = s.split(\"-\");\n return new Date(k[0], k[1] - 1, k[2], 0, 0, 0);\n case 19:\n var k = s.split(\" \");\n var y = k[0].split(\"-\");\n var t = k[1].split(\":\");\n return new Date(y[0], y[1] - 1, y[2], t[0], t[1], t[2]);\n default:\n throw \"Invalid date format : \" + s;\n }\n };\n HxOverrides.cca = function (s, index) {\n var x = s.charCodeAt(index);\n if (x != x) return undefined;\n return x;\n };\n HxOverrides.substr = function (s, pos, len) {\n if (pos != null && pos != 0 && len != null && len < 0) return \"\";\n if (len == null) len = s.length;\n if (pos < 0) {\n pos = s.length + pos;\n if (pos < 0) pos = 0;\n } else if (len < 0) len = s.length + len - pos;\n return s.substr(pos, len);\n };\n HxOverrides.remove = function (a, obj) {\n var i = 0;\n var l = a.length;\n while (i < l) {\n if (a[i] == obj) {\n a.splice(i, 1);\n return true;\n }\n i++;\n }\n return false;\n };\n HxOverrides.iter = function (a) {\n return {\n cur: 0,\n arr: a,\n hasNext: function () {\n return this.cur < this.arr.length;\n },\n next: function () {\n return this.arr[this.cur++];\n },\n };\n };\n var IntIter = function (min, max) {\n this.min = min;\n this.max = max;\n };\n IntIter.__name__ = true;\n IntIter.prototype = {\n next: function () {\n return this.min++;\n },\n hasNext: function () {\n return this.min < this.max;\n },\n __class__: IntIter,\n };\n var Std = function () {};\n Std.__name__ = true;\n Std[\"is\"] = function (v, t) {\n return js.Boot.__instanceof(v, t);\n };\n Std.string = function (s) {\n return js.Boot.__string_rec(s, \"\");\n };\n Std[\"int\"] = function (x) {\n return x | 0;\n };\n Std.parseInt = function (x) {\n var v = parseInt(x, 10);\n if (v == 0 && (HxOverrides.cca(x, 1) == 120 || HxOverrides.cca(x, 1) == 88)) v = parseInt(x);\n if (isNaN(v)) return null;\n return v;\n };\n Std.parseFloat = function (x) {\n return parseFloat(x);\n };\n Std.random = function (x) {\n return Math.floor(Math.random() * x);\n };\n var com = com || {};\n if (!com.wiris) com.wiris = {};\n if (!com.wiris.js) com.wiris.js = {};\n com.wiris.js.JsPluginTools = function () {\n this.tryReady();\n };\n com.wiris.js.JsPluginTools.__name__ = true;\n com.wiris.js.JsPluginTools.main = function () {\n var ev;\n ev = com.wiris.js.JsPluginTools.getInstance();\n haxe.Timer.delay($bind(ev, ev.tryReady), 100);\n };\n com.wiris.js.JsPluginTools.getInstance = function () {\n if (com.wiris.js.JsPluginTools.instance == null)\n com.wiris.js.JsPluginTools.instance = new com.wiris.js.JsPluginTools();\n return com.wiris.js.JsPluginTools.instance;\n };\n com.wiris.js.JsPluginTools.bypassEncapsulation = function () {\n if (window.com == null) window.com = {};\n if (window.com.wiris == null) window.com.wiris = {};\n if (window.com.wiris.js == null) window.com.wiris.js = {};\n if (window.com.wiris.js.JsPluginTools == null)\n window.com.wiris.js.JsPluginTools = com.wiris.js.JsPluginTools.getInstance();\n };\n com.wiris.js.JsPluginTools.prototype = {\n md5encode: function (content) {\n return haxe.Md5.encode(content);\n },\n doLoad: function () {\n this.ready = true;\n com.wiris.js.JsPluginTools.instance = this;\n com.wiris.js.JsPluginTools.bypassEncapsulation();\n },\n tryReady: function () {\n this.ready = false;\n if (js.Lib.document.readyState) {\n this.doLoad();\n this.ready = true;\n }\n if (!this.ready) haxe.Timer.delay($bind(this, this.tryReady), 100);\n },\n __class__: com.wiris.js.JsPluginTools,\n };\n var haxe = haxe || {};\n haxe.Log = function () {};\n haxe.Log.__name__ = true;\n haxe.Log.trace = function (v, infos) {\n js.Boot.__trace(v, infos);\n };\n haxe.Log.clear = function () {\n js.Boot.__clear_trace();\n };\n haxe.Md5 = function () {};\n haxe.Md5.__name__ = true;\n haxe.Md5.encode = function (s) {\n return new haxe.Md5().doEncode(s);\n };\n haxe.Md5.prototype = {\n doEncode: function (str) {\n var x = this.str2blks(str);\n var a = 1732584193;\n var b = -271733879;\n var c = -1732584194;\n var d = 271733878;\n var step;\n var i = 0;\n while (i < x.length) {\n var olda = a;\n var oldb = b;\n var oldc = c;\n var oldd = d;\n step = 0;\n a = this.ff(a, b, c, d, x[i], 7, -680876936);\n d = this.ff(d, a, b, c, x[i + 1], 12, -389564586);\n c = this.ff(c, d, a, b, x[i + 2], 17, 606105819);\n b = this.ff(b, c, d, a, x[i + 3], 22, -1044525330);\n a = this.ff(a, b, c, d, x[i + 4], 7, -176418897);\n d = this.ff(d, a, b, c, x[i + 5], 12, 1200080426);\n c = this.ff(c, d, a, b, x[i + 6], 17, -1473231341);\n b = this.ff(b, c, d, a, x[i + 7], 22, -45705983);\n a = this.ff(a, b, c, d, x[i + 8], 7, 1770035416);\n d = this.ff(d, a, b, c, x[i + 9], 12, -1958414417);\n c = this.ff(c, d, a, b, x[i + 10], 17, -42063);\n b = this.ff(b, c, d, a, x[i + 11], 22, -1990404162);\n a = this.ff(a, b, c, d, x[i + 12], 7, 1804603682);\n d = this.ff(d, a, b, c, x[i + 13], 12, -40341101);\n c = this.ff(c, d, a, b, x[i + 14], 17, -1502002290);\n b = this.ff(b, c, d, a, x[i + 15], 22, 1236535329);\n a = this.gg(a, b, c, d, x[i + 1], 5, -165796510);\n d = this.gg(d, a, b, c, x[i + 6], 9, -1069501632);\n c = this.gg(c, d, a, b, x[i + 11], 14, 643717713);\n b = this.gg(b, c, d, a, x[i], 20, -373897302);\n a = this.gg(a, b, c, d, x[i + 5], 5, -701558691);\n d = this.gg(d, a, b, c, x[i + 10], 9, 38016083);\n c = this.gg(c, d, a, b, x[i + 15], 14, -660478335);\n b = this.gg(b, c, d, a, x[i + 4], 20, -405537848);\n a = this.gg(a, b, c, d, x[i + 9], 5, 568446438);\n d = this.gg(d, a, b, c, x[i + 14], 9, -1019803690);\n c = this.gg(c, d, a, b, x[i + 3], 14, -187363961);\n b = this.gg(b, c, d, a, x[i + 8], 20, 1163531501);\n a = this.gg(a, b, c, d, x[i + 13], 5, -1444681467);\n d = this.gg(d, a, b, c, x[i + 2], 9, -51403784);\n c = this.gg(c, d, a, b, x[i + 7], 14, 1735328473);\n b = this.gg(b, c, d, a, x[i + 12], 20, -1926607734);\n a = this.hh(a, b, c, d, x[i + 5], 4, -378558);\n d = this.hh(d, a, b, c, x[i + 8], 11, -2022574463);\n c = this.hh(c, d, a, b, x[i + 11], 16, 1839030562);\n b = this.hh(b, c, d, a, x[i + 14], 23, -35309556);\n a = this.hh(a, b, c, d, x[i + 1], 4, -1530992060);\n d = this.hh(d, a, b, c, x[i + 4], 11, 1272893353);\n c = this.hh(c, d, a, b, x[i + 7], 16, -155497632);\n b = this.hh(b, c, d, a, x[i + 10], 23, -1094730640);\n a = this.hh(a, b, c, d, x[i + 13], 4, 681279174);\n d = this.hh(d, a, b, c, x[i], 11, -358537222);\n c = this.hh(c, d, a, b, x[i + 3], 16, -722521979);\n b = this.hh(b, c, d, a, x[i + 6], 23, 76029189);\n a = this.hh(a, b, c, d, x[i + 9], 4, -640364487);\n d = this.hh(d, a, b, c, x[i + 12], 11, -421815835);\n c = this.hh(c, d, a, b, x[i + 15], 16, 530742520);\n b = this.hh(b, c, d, a, x[i + 2], 23, -995338651);\n a = this.ii(a, b, c, d, x[i], 6, -198630844);\n d = this.ii(d, a, b, c, x[i + 7], 10, 1126891415);\n c = this.ii(c, d, a, b, x[i + 14], 15, -1416354905);\n b = this.ii(b, c, d, a, x[i + 5], 21, -57434055);\n a = this.ii(a, b, c, d, x[i + 12], 6, 1700485571);\n d = this.ii(d, a, b, c, x[i + 3], 10, -1894986606);\n c = this.ii(c, d, a, b, x[i + 10], 15, -1051523);\n b = this.ii(b, c, d, a, x[i + 1], 21, -2054922799);\n a = this.ii(a, b, c, d, x[i + 8], 6, 1873313359);\n d = this.ii(d, a, b, c, x[i + 15], 10, -30611744);\n c = this.ii(c, d, a, b, x[i + 6], 15, -1560198380);\n b = this.ii(b, c, d, a, x[i + 13], 21, 1309151649);\n a = this.ii(a, b, c, d, x[i + 4], 6, -145523070);\n d = this.ii(d, a, b, c, x[i + 11], 10, -1120210379);\n c = this.ii(c, d, a, b, x[i + 2], 15, 718787259);\n b = this.ii(b, c, d, a, x[i + 9], 21, -343485551);\n a = this.addme(a, olda);\n b = this.addme(b, oldb);\n c = this.addme(c, oldc);\n d = this.addme(d, oldd);\n i += 16;\n }\n return this.rhex(a) + this.rhex(b) + this.rhex(c) + this.rhex(d);\n },\n ii: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(c, this.bitOR(b, ~d)), a, b, x, s, t);\n },\n hh: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitXOR(this.bitXOR(b, c), d), a, b, x, s, t);\n },\n gg: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, d), this.bitAND(c, ~d)), a, b, x, s, t);\n },\n ff: function (a, b, c, d, x, s, t) {\n return this.cmn(this.bitOR(this.bitAND(b, c), this.bitAND(~b, d)), a, b, x, s, t);\n },\n cmn: function (q, a, b, x, s, t) {\n return this.addme(this.rol(this.addme(this.addme(a, q), this.addme(x, t)), s), b);\n },\n rol: function (num, cnt) {\n return (num << cnt) | (num >>> (32 - cnt));\n },\n str2blks: function (str) {\n var nblk = ((str.length + 8) >> 6) + 1;\n var blks = new Array();\n var _g1 = 0,\n _g = nblk * 16;\n while (_g1 < _g) {\n var i = _g1++;\n blks[i] = 0;\n }\n var i = 0;\n while (i < str.length) {\n blks[i >> 2] |= HxOverrides.cca(str, i) << (((str.length * 8 + i) % 4) * 8);\n i++;\n }\n blks[i >> 2] |= 128 << (((str.length * 8 + i) % 4) * 8);\n var l = str.length * 8;\n var k = nblk * 16 - 2;\n blks[k] = l & 255;\n blks[k] |= ((l >>> 8) & 255) << 8;\n blks[k] |= ((l >>> 16) & 255) << 16;\n blks[k] |= ((l >>> 24) & 255) << 24;\n return blks;\n },\n rhex: function (num) {\n var str = \"\";\n var hex_chr = \"0123456789abcdef\";\n var _g = 0;\n while (_g < 4) {\n var j = _g++;\n str += hex_chr.charAt((num >> (j * 8 + 4)) & 15) + hex_chr.charAt((num >> (j * 8)) & 15);\n }\n return str;\n },\n addme: function (x, y) {\n var lsw = (x & 65535) + (y & 65535);\n var msw = (x >> 16) + (y >> 16) + (lsw >> 16);\n return (msw << 16) | (lsw & 65535);\n },\n bitAND: function (a, b) {\n var lsb = a & 1 & (b & 1);\n var msb31 = (a >>> 1) & (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitXOR: function (a, b) {\n var lsb = (a & 1) ^ (b & 1);\n var msb31 = (a >>> 1) ^ (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n bitOR: function (a, b) {\n var lsb = (a & 1) | (b & 1);\n var msb31 = (a >>> 1) | (b >>> 1);\n return (msb31 << 1) | lsb;\n },\n __class__: haxe.Md5,\n };\n haxe.Timer = function (time_ms) {\n var me = this;\n this.id = window.setInterval(function () {\n me.run();\n }, time_ms);\n };\n haxe.Timer.__name__ = true;\n haxe.Timer.delay = function (f, time_ms) {\n var t = new haxe.Timer(time_ms);\n t.run = function () {\n t.stop();\n f();\n };\n return t;\n };\n haxe.Timer.measure = function (f, pos) {\n var t0 = haxe.Timer.stamp();\n var r = f();\n haxe.Log.trace(haxe.Timer.stamp() - t0 + \"s\", pos);\n return r;\n };\n haxe.Timer.stamp = function () {\n return new Date().getTime() / 1000;\n };\n haxe.Timer.prototype = {\n run: function () {},\n stop: function () {\n if (this.id == null) return;\n window.clearInterval(this.id);\n this.id = null;\n },\n __class__: haxe.Timer,\n };\n var js = js || {};\n js.Boot = function () {};\n js.Boot.__name__ = true;\n js.Boot.__unhtml = function (s) {\n return s.split(\"&\").join(\"&\").split(\"<\").join(\"<\").split(\">\").join(\">\");\n };\n js.Boot.__trace = function (v, i) {\n var msg = i != null ? i.fileName + \":\" + i.lineNumber + \": \" : \"\";\n msg += js.Boot.__string_rec(v, \"\");\n var d;\n if (typeof document != \"undefined\" && (d = document.getElementById(\"haxe:trace\")) != null)\n d.innerHTML += js.Boot.__unhtml(msg) + \"
\";\n else if (typeof console != \"undefined\" && console.log != null) console.log(msg);\n };\n js.Boot.__clear_trace = function () {\n var d = document.getElementById(\"haxe:trace\");\n if (d != null) d.innerHTML = \"\";\n };\n js.Boot.isClass = function (o) {\n return o.__name__;\n };\n js.Boot.isEnum = function (e) {\n return e.__ename__;\n };\n js.Boot.getClass = function (o) {\n return o.__class__;\n };\n js.Boot.__string_rec = function (o, s) {\n if (o == null) return \"null\";\n if (s.length >= 5) return \"<...>\";\n var t = typeof o;\n if (t == \"function\" && (o.__name__ || o.__ename__)) t = \"object\";\n switch (t) {\n case \"object\":\n if (o instanceof Array) {\n if (o.__enum__) {\n if (o.length == 2) return o[0];\n var str = o[0] + \"(\";\n s += \"\\t\";\n var _g1 = 2,\n _g = o.length;\n while (_g1 < _g) {\n var i = _g1++;\n if (i != 2) str += \",\" + js.Boot.__string_rec(o[i], s);\n else str += js.Boot.__string_rec(o[i], s);\n }\n return str + \")\";\n }\n var l = o.length;\n var i;\n var str = \"[\";\n s += \"\\t\";\n var _g = 0;\n while (_g < l) {\n var i1 = _g++;\n str += (i1 > 0 ? \",\" : \"\") + js.Boot.__string_rec(o[i1], s);\n }\n str += \"]\";\n return str;\n }\n var tostr;\n try {\n tostr = o.toString;\n } catch (e) {\n return \"???\";\n }\n if (tostr != null && tostr != Object.toString) {\n var s2 = o.toString();\n if (s2 != \"[object Object]\") return s2;\n }\n var k = null;\n var str = \"{\\n\";\n s += \"\\t\";\n var hasp = o.hasOwnProperty != null;\n for (var k in o) {\n if (hasp && !o.hasOwnProperty(k)) {\n continue;\n }\n if (\n k == \"prototype\" ||\n k == \"__class__\" ||\n k == \"__super__\" ||\n k == \"__interfaces__\" ||\n k == \"__properties__\"\n ) {\n continue;\n }\n if (str.length != 2) str += \", \\n\";\n str += s + k + \" : \" + js.Boot.__string_rec(o[k], s);\n }\n s = s.substring(1);\n str += \"\\n\" + s + \"}\";\n return str;\n case \"function\":\n return \"\";\n case \"string\":\n return o;\n default:\n return String(o);\n }\n };\n js.Boot.__interfLoop = function (cc, cl) {\n if (cc == null) return false;\n if (cc == cl) return true;\n var intf = cc.__interfaces__;\n if (intf != null) {\n var _g1 = 0,\n _g = intf.length;\n while (_g1 < _g) {\n var i = _g1++;\n var i1 = intf[i];\n if (i1 == cl || js.Boot.__interfLoop(i1, cl)) return true;\n }\n }\n return js.Boot.__interfLoop(cc.__super__, cl);\n };\n js.Boot.__instanceof = function (o, cl) {\n try {\n if (o instanceof cl) {\n if (cl == Array) return o.__enum__ == null;\n return true;\n }\n if (js.Boot.__interfLoop(o.__class__, cl)) return true;\n } catch (e) {\n if (cl == null) return false;\n }\n switch (cl) {\n case Int:\n return Math.ceil(o % 2147483648.0) === o;\n case Float:\n return typeof o == \"number\";\n case Bool:\n return o === true || o === false;\n case String:\n return typeof o == \"string\";\n case Dynamic:\n return true;\n default:\n if (o == null) return false;\n if (cl == Class && o.__name__ != null) return true;\n else null;\n if (cl == Enum && o.__ename__ != null) return true;\n else null;\n return o.__enum__ == cl;\n }\n };\n js.Boot.__cast = function (o, t) {\n if (js.Boot.__instanceof(o, t)) return o;\n else throw \"Cannot cast \" + Std.string(o) + \" to \" + Std.string(t);\n };\n js.Lib = function () {};\n js.Lib.__name__ = true;\n js.Lib.debug = function () {\n debugger;\n };\n js.Lib.alert = function (v) {\n alert(js.Boot.__string_rec(v, \"\"));\n };\n js.Lib.eval = function (code) {\n return eval(code);\n };\n js.Lib.setErrorHandler = function (f) {\n js.Lib.onerror = f;\n };\n var $_;\n function $bind(o, m) {\n var f = function () {\n return f.method.apply(f.scope, arguments);\n };\n f.scope = o;\n f.method = m;\n return f;\n }\n if (Array.prototype.indexOf)\n HxOverrides.remove = function (a, o) {\n var i = a.indexOf(o);\n if (i == -1) return false;\n a.splice(i, 1);\n return true;\n };\n else null;\n Math.__name__ = [\"Math\"];\n Math.NaN = Number.NaN;\n Math.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;\n Math.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;\n Math.isFinite = function (i) {\n return isFinite(i);\n };\n Math.isNaN = function (i) {\n return isNaN(i);\n };\n String.prototype.__class__ = String;\n String.__name__ = true;\n Array.prototype.__class__ = Array;\n Array.__name__ = true;\n Date.prototype.__class__ = Date;\n Date.__name__ = [\"Date\"];\n var Int = { __name__: [\"Int\"] };\n var Dynamic = { __name__: [\"Dynamic\"] };\n var Float = Number;\n Float.__name__ = [\"Float\"];\n var Bool = Boolean;\n Bool.__ename__ = [\"Bool\"];\n var Class = { __name__: [\"Class\"] };\n var Enum = {};\n var Void = { __ename__: [\"Void\"] };\n if (typeof document != \"undefined\") js.Lib.document = document;\n if (typeof window != \"undefined\") {\n js.Lib.window = window;\n js.Lib.window.onerror = function (msg, url, line) {\n var f = js.Lib.onerror;\n if (f == null) return false;\n return f(msg, [url + \":\" + line]);\n };\n }\n com.wiris.js.JsPluginTools.main();\n})();\ndelete Array.prototype.__class__;\n// @codingStandardsIgnoreEnd\n","import IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Telemeter from \"@wiris/mathtype-html-integration-devkit/src/telemeter.js\";\n\n/**\n * This class represents the MathType integration for CKEditor5.\n * @extends {IntegrationModel}\n */\nexport default class CKEditor5Integration extends IntegrationModel {\n constructor(ckeditorIntegrationModelProperties) {\n const editor = ckeditorIntegrationModelProperties.editorObject;\n\n if (typeof editor.config !== \"undefined\" && typeof editor.config.get(\"mathTypeParameters\") !== \"undefined\") {\n ckeditorIntegrationModelProperties.integrationParameters = editor.config.get(\"mathTypeParameters\");\n }\n /**\n * CKEditor5 Integration.\n *\n * @param {integrationModelProperties} integrationModelAttributes\n */\n super(ckeditorIntegrationModelProperties);\n\n /**\n * Folder name used for the integration inside CKEditor plugins folder.\n */\n this.integrationFolderName = \"ckeditor_wiris\";\n }\n\n /**\n * @inheritdoc\n * @returns {string} - The CKEditor instance language.\n * @override\n */\n getLanguage() {\n // Returns the CKEDitor instance language taking into account that the language can be an object.\n // Try to get editorParameters.language, fail silently otherwise\n try {\n return this.editorParameters.language;\n } catch (e) {}\n const languageObject = this.editorObject.config.get(\"language\");\n if (languageObject != null) {\n if (typeof languageObject === \"object\") {\n if (Object.prototype.hasOwnProperty.call(languageObject, \"ui\")) {\n return languageObject.ui;\n }\n return this.editorObject.locale.uiLanguage;\n }\n return languageObject;\n }\n return super.getLanguage();\n }\n\n /**\n * Adds callbacks to the following CKEditor listeners:\n * - 'focus' - updates the current instance.\n * - 'contentDom' - adds 'doubleclick' callback.\n * - 'doubleclick' - sets to null data.dialog property to avoid modifications for MathType formulas.\n * - 'setData' - parses the data converting MathML into images.\n * - 'afterSetData' - adds an observer to MathType formulas to avoid modifications.\n * - 'getData' - parses the data converting images into selected save mode (MathML by default).\n * - 'mode' - recalculates the active element.\n */\n addEditorListeners() {\n const editor = this.editorObject;\n\n if (typeof editor.config.wirislistenersdisabled === \"undefined\" || !editor.config.wirislistenersdisabled) {\n this.checkElement();\n }\n }\n\n /**\n * Checks the current container and assign events in case that it doesn't have them.\n * CKEditor replaces several times the element element during its execution,\n * so we must assign the events again to editor element.\n */\n checkElement() {\n const editor = this.editorObject;\n const newElement = editor.sourceElement;\n\n // If the element wasn't treated, add the events.\n if (!newElement.wirisActive) {\n this.setTarget(newElement);\n this.addEvents();\n // Set the element as treated\n newElement.wirisActive = true;\n }\n }\n\n /**\n * @inheritdoc\n * @param {HTMLElement} element - HTMLElement target.\n * @param {MouseEvent} event - event which trigger the handler.\n */\n doubleClickHandler(element, event) {\n this.core.editionProperties.dbclick = true;\n if (this.editorObject.isReadOnly === false) {\n if (element.nodeName.toLowerCase() === \"img\") {\n if (Util.containsClass(element, Configuration.get(\"imageClassName\"))) {\n // Some plugins (image2, image) open a dialog on Double-click. On formulas\n // doubleclick event ends here.\n if (typeof event.stopPropagation !== \"undefined\") {\n // old I.E compatibility.\n event.stopPropagation();\n } else {\n event.returnValue = false;\n }\n this.core.getCustomEditors().disable();\n const customEditorAttr = element.getAttribute(Configuration.get(\"imageCustomEditorName\"));\n if (customEditorAttr) {\n this.core.getCustomEditors().enable(customEditorAttr);\n }\n this.core.editionProperties.temporalImage = element;\n this.openExistingFormulaEditor();\n }\n }\n }\n }\n\n /** @inheritdoc */\n static getCorePath() {\n return null; // TODO\n }\n\n /** @inheritdoc */\n callbackFunction() {\n super.callbackFunction();\n this.addEditorListeners();\n }\n\n openNewFormulaEditor() {\n // Store the editor selection as it will be lost upon opening the modal\n this.core.editionProperties.selection = this.editorObject.editing.view.document.selection;\n\n // Focus on the selected editor when multiple editor instances are present\n WirisPlugin.currentInstance = this;\n\n return super.openNewFormulaEditor();\n }\n\n /**\n * Replaces old formula with new MathML or inserts it in caret position if new\n * @param {String} mathml MathML to update old one or insert\n * @returns {module:engine/model/element~Element} The model element corresponding to the inserted image\n */\n insertMathml(mathml) {\n // This returns the value returned by the callback function (writer => {...})\n return this.editorObject.model.change((writer) => {\n const core = this.getCore();\n const selection = this.editorObject.model.document.selection;\n\n const modelElementNew = writer.createElement(\"mathml\", {\n formula: mathml,\n ...Object.fromEntries(selection.getAttributes()), // To keep the format, such as style and font\n });\n\n // Obtain the DOM object corresponding to the formula\n if (core.editionProperties.isNewElement) {\n // Don't bother inserting anything at all if the MathML is empty.\n if (!mathml) return;\n\n const viewSelection =\n this.core.editionProperties.selection || this.editorObject.editing.view.document.selection;\n const modelPosition = this.editorObject.editing.mapper.toModelPosition(viewSelection.getLastPosition());\n\n this.editorObject.model.insertObject(modelElementNew, modelPosition);\n\n // Remove selection\n if (!viewSelection.isCollapsed) {\n for (const range of viewSelection.getRanges()) {\n writer.remove(this.editorObject.editing.mapper.toModelRange(range));\n }\n }\n\n // Set carret after the formula\n const position = this.editorObject.model.createPositionAfter(modelElementNew);\n writer.setSelection(position);\n } else {\n const img = core.editionProperties.temporalImage;\n const viewElement = this.editorObject.editing.view.domConverter.domToView(img).parent;\n const modelElementOld = this.editorObject.editing.mapper.toModelElement(viewElement);\n\n // Insert the new and remove the old one\n const position = this.editorObject.model.createPositionBefore(modelElementOld);\n\n // If the given MathML is empty, don't insert a new formula.\n if (mathml) {\n this.editorObject.model.insertObject(modelElementNew, position);\n }\n writer.remove(modelElementOld);\n }\n\n // eslint-disable-next-line consistent-return\n return modelElementNew;\n });\n }\n\n /**\n * Finds the text node corresponding to given DOM text element.\n * @param {element} viewElement Element to find corresponding text node of.\n * @returns {module:engine/model/text~Text|undefined} Text node corresponding to the given element or undefined if it doesn't exist.\n */\n findText(viewElement) {\n // eslint-disable-line consistent-return\n // mapper always converts text nodes to *new* model elements so we need to convert the text's parents and then come back down\n let pivot = viewElement;\n let element;\n while (!element) {\n element = this.editorObject.editing.mapper.toModelElement(\n this.editorObject.editing.view.domConverter.domToView(pivot),\n );\n pivot = pivot.parentElement;\n }\n\n // Navigate through all the subtree under `pivot` in order to find the correct text node\n const range = this.editorObject.model.createRangeIn(element);\n const descendants = Array.from(range.getItems());\n for (const node of descendants) {\n let viewElementData = viewElement.data;\n if (viewElement.nodeType === 3) {\n // Remove invisible white spaces\n viewElementData = viewElementData.replaceAll(String.fromCharCode(8288), \"\");\n }\n if (node.is(\"textProxy\") && node.data === viewElementData.replace(String.fromCharCode(160), \" \")) {\n return node.textNode;\n }\n }\n }\n\n /** @inheritdoc */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n // eslint-disable-line no-unused-vars\n const returnObject = {};\n\n let mathmlOrigin;\n if (!mathml) {\n this.insertMathml(\"\");\n } else if (this.core.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n\n this.editorObject.model.change((writer) => {\n const { latexRange } = this.core.editionProperties;\n\n const startNode = this.findText(latexRange.startContainer);\n const endNode = this.findText(latexRange.endContainer);\n\n let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);\n let endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);\n\n let range = writer.createRange(startPosition, endPosition);\n\n // When Latex is next to image/formula.\n if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {\n // Get the position of the latex to be replaced.\n const latexEdited = `$$${Latex.getLatexFromMathML(\n MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml),\n )}$$`;\n let data = latexRange.startContainer.data;\n\n // Remove invisible characters.\n data = data.replaceAll(String.fromCharCode(8288), \"\");\n\n // Get to the start of the latex we are editing.\n const offset = data.indexOf(latexEdited);\n const dataOffset = data.substring(offset);\n const second$ = dataOffset.substring(2).indexOf(\"$$\") + 4;\n const substring = dataOffset.substr(0, second$);\n data = data.replace(substring, \"\");\n\n if (!data) {\n startPosition = writer.createPositionBefore(startNode);\n range = startNode;\n } else {\n startPosition = startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + offset);\n endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + second$ + offset);\n range = writer.createRange(startPosition, endPosition);\n }\n }\n\n writer.remove(range);\n writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);\n });\n } else {\n mathmlOrigin = this.core.editionProperties.temporalImage?.dataset.mathml;\n try {\n returnObject.node = this.editorObject.editing.view.domConverter.viewToDom(\n this.editorObject.editing.mapper.toViewElement(this.insertMathml(mathml)),\n windowTarget.document,\n );\n } catch (e) {\n const x = e.toString();\n if (x.includes(\"CKEditorError: Cannot read property 'parent' of undefined\")) {\n this.core.modalDialog.cancelAction();\n }\n }\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.core.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n\n /* Due to PLUGINS-1329, we add the onChange event to the CK4 insertFormula.\n We probably should add it here as well, but we should look further into how */\n // this.editorObject.fire('change');\n\n // Remove temporal image of inserted formula\n this.core.editionProperties.temporalImage = null;\n\n return returnObject;\n }\n\n /**\n * Function called when the content submits an action.\n */\n notifyWindowClosed() {\n this.editorObject.editing.view.focus();\n }\n}\n","/* eslint-disable max-classes-per-file */\nimport { Command } from \"ckeditor5/src/core.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\n/**\n * Command for opening the MathType editor\n */\nexport class MathTypeCommand extends Command {\n execute(options = {}) {\n // Check we get a valid integration\n // eslint-disable-next-line no-prototype-builtins\n if (!options.hasOwnProperty(\"integration\") || !(options.integration instanceof CKEditor5Integration)) {\n throw 'Must pass a valid CKEditor5Integration instance as attribute \"integration\" of options';\n }\n\n // Save the integration instance as a property of the command.\n this.integration = options.integration;\n\n // Set custom editor or disable it\n this.setEditor();\n\n // Open the editor\n this.openEditor();\n }\n\n /**\n * Sets the appropriate custom editor, if any, or disables them.\n */\n setEditor() {\n // It's possible that a custom editor was last used.\n // We need to disable it to avoid wrong behaviors.\n this.integration.core.getCustomEditors().disable();\n }\n\n /**\n * Checks whether we are editing an existing formula or a new one and opens the editor.\n */\n openEditor() {\n this.integration.core.editionProperties.dbclick = false;\n const image = this._getSelectedImage();\n if (\n typeof image !== \"undefined\" &&\n image !== null &&\n image.classList.contains(WirisPlugin.Configuration.get(\"imageClassName\"))\n ) {\n this.integration.core.editionProperties.temporalImage = image;\n this.integration.openExistingFormulaEditor();\n } else {\n this.integration.openNewFormulaEditor();\n }\n }\n\n /**\n * Gets the currently selected formula image\n * @returns {Element} selected image, if any, undefined otherwise\n */\n _getSelectedImage() {\n const { selection } = this.editor.editing.view.document;\n\n // If we can not extract the formula, fall back to default behavior.\n if (selection.isCollapsed || selection.rangeCount !== 1) {\n return;\n }\n\n // Look for the wrapping the formula and then for the inside\n\n const range = selection.getFirstRange();\n\n let image;\n\n for (const span of range) {\n if (span.item.name !== \"span\") {\n return;\n }\n image = span.item.getChild(0);\n break;\n }\n\n if (!image) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n return this.editor.editing.view.domConverter.mapViewToDom(image);\n }\n}\n\n/**\n * Command for opening the ChemType editor\n */\nexport class ChemTypeCommand extends MathTypeCommand {\n setEditor() {\n this.integration.core.getCustomEditors().enable(\"chemistry\");\n }\n}\n","// CKEditor imports\nimport { Plugin } from \"ckeditor5/src/core.js\";\nimport { ButtonView } from \"ckeditor5/src/ui.js\";\nimport { ClickObserver, HtmlDataProcessor, XmlDataProcessor, ViewUpcastWriter } from \"ckeditor5/src/engine.js\";\nimport { Widget, toWidget, viewToModelPositionOutsideModelElement } from \"ckeditor5/src/widget.js\";\n\n// MathType API imports\nimport IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Core from \"@wiris/mathtype-html-integration-devkit/src/core.src.js\";\nimport Parser from \"@wiris/mathtype-html-integration-devkit/src/parser.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Image from \"@wiris/mathtype-html-integration-devkit/src/image.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Listeners from \"@wiris/mathtype-html-integration-devkit/src/listeners.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport StringManager from \"@wiris/mathtype-html-integration-devkit/src/stringmanager.js\";\nimport \"@wiris/mathtype-html-integration-devkit/src/md5.js\";\n\n// Local imports\nimport { MathTypeCommand, ChemTypeCommand } from \"./commands.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\nimport mathIcon from \"../theme/icons/ckeditor5-formula.svg\";\nimport chemIcon from \"../theme/icons/ckeditor5-chem.svg\";\n\nimport packageInfo from \"../package.json\";\n\nexport let currentInstance = null; // eslint-disable-line import/no-mutable-exports\n\nexport default class MathType extends Plugin {\n static get requires() {\n return [Widget];\n }\n\n static get pluginName() {\n return \"MathType\";\n }\n\n init() {\n // Create the MathType API Integration object\n const integration = this._addIntegration();\n currentInstance = integration;\n\n // Add the MathType and ChemType commands to the editor\n this._addCommands();\n\n // Add the buttons for MathType and ChemType\n this._addViews(integration);\n\n // Registers the element in the schema\n this._addSchema();\n\n // Add the downcast and upcast converters\n this._addConverters(integration);\n\n // Expose the WirisPlugin variable to the window\n this._exposeWiris();\n }\n\n /**\n * Inherited from Plugin class: Executed when CKEditor5 is destroyed\n */\n destroy() {\n // eslint-disable-line class-methods-use-this\n currentInstance?.destroy();\n }\n\n /**\n * Create the MathType API Integration object\n * @returns {CKEditor5Integration} the integration object\n */\n _addIntegration() {\n const { editor } = this;\n\n /**\n * Integration model constructor attributes.\n * @type {integrationModelProperties}\n */\n const integrationProperties = {};\n integrationProperties.environment = {};\n integrationProperties.environment.editor = \"CKEditor5\";\n integrationProperties.environment.editorVersion = \"5.x\";\n integrationProperties.version = packageInfo.version;\n integrationProperties.editorObject = editor;\n integrationProperties.serviceProviderProperties = {};\n integrationProperties.serviceProviderProperties.URI = \"https://www.wiris.net/demo/plugins/app\";\n integrationProperties.serviceProviderProperties.server = \"java\";\n integrationProperties.target = editor.sourceElement;\n integrationProperties.scriptName = \"bundle.js\";\n integrationProperties.managesLanguage = true;\n // etc\n\n // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.\n // To avoid a wrong behavior, this integration only starts if the workspace container exists.\n let integration;\n if (integrationProperties.target) {\n // Instance of the integration associated to this editor instance\n integration = new CKEditor5Integration(integrationProperties);\n integration.init();\n integration.listeners.fire(\"onTargetReady\", {});\n\n integration.checkElement();\n\n this.listenTo(\n editor.editing.view.document,\n \"click\",\n (evt, data) => {\n // Is Double-click\n if (data.domEvent.detail === 2) {\n integration.doubleClickHandler(data.domTarget, data.domEvent);\n evt.stop();\n }\n },\n { priority: \"highest\" },\n );\n }\n\n return integration;\n }\n\n /**\n * Add the MathType and ChemType commands to the editor\n */\n _addCommands() {\n const { editor } = this;\n\n // Add command to open the formula editor\n editor.commands.add(\"MathType\", new MathTypeCommand(editor));\n\n // Add command to open the chemistry formula editor\n editor.commands.add(\"ChemType\", new ChemTypeCommand(editor));\n }\n\n /**\n * Add the buttons for MathType and ChemType\n * @param {CKEditor5Integration} integration the integration object\n */\n _addViews(integration) {\n const { editor } = this;\n\n // Check if MathType editor is enabled\n if (Configuration.get(\"editorEnabled\")) {\n // Add button for the formula editor\n editor.ui.componentFactory.add(\"MathType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"MathType\"), \"isEnabled\");\n view.set({\n label: StringManager.get(\"insert_math\", integration.getLanguage()),\n icon: mathIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"MathType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Check if ChemType editor is enabled\n if (Configuration.get(\"chemEnabled\")) {\n // Add button for the chemistry formula editor\n editor.ui.componentFactory.add(\"ChemType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"ChemType\"), \"isEnabled\");\n\n view.set({\n label: StringManager.get(\"insert_chem\", integration.getLanguage()),\n icon: chemIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"ChemType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Observer for the Double-click event\n editor.editing.view.addObserver(ClickObserver);\n }\n\n /**\n * Registers the element in the schema\n */\n _addSchema() {\n const { schema } = this.editor.model;\n\n schema.register(\"mathml\", {\n inheritAllFrom: \"$inlineObject\",\n allowAttributes: [\"formula\", \"htmlContent\"],\n });\n }\n\n /**\n * Add the downcast and upcast converters\n */\n _addConverters(integration) {\n const { editor } = this;\n\n // Editing view -> Model\n editor.conversion.for(\"upcast\").elementToElement({\n view: {\n name: \"span\",\n classes: \"ck-math-widget\",\n },\n model: (viewElement, { writer: modelWriter }) => {\n const formula = MathML.safeXmlDecode(viewElement.getChild(0).getAttribute(\"data-mathml\"));\n return modelWriter.createElement(\"mathml\", {\n formula,\n });\n },\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\"element:math\", (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // When element was already consumed then skip it.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // If we encounter any with a LaTeX annotation inside,\n // convert it into a \"$$...$$\" string.\n const isLatex = mathIsLatex(viewItem); // eslint-disable-line no-use-before-define\n\n // Get the formula of the (which is all its children).\n const processor = new XmlDataProcessor(editor.editing.view.document);\n\n // Only god knows why the following line makes viewItem lose all of its children,\n // so we obtain isLatex before doing this because we need viewItem's children for that.\n const upcastWriter = new ViewUpcastWriter(editor.editing.view.document);\n const viewDocumentFragment = upcastWriter.createDocumentFragment(viewItem.getChildren());\n\n // and obtain the attributes of too!\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n\n // We process the document fragment\n let formula = processor.toData(viewDocumentFragment) || \"\";\n\n // And obtain the complete formula\n formula = Util.htmlSanitize(`${formula}`);\n\n // Replaces the < & > characters to its HTMLEntity to avoid render issues.\n formula = formula.replaceAll('\"<\"', '\"<\"').replaceAll('\">\"', '\">\"').replaceAll(\"><<\", \"><<\");\n\n /* Model node that contains what's going to actually be inserted. This can be either:\n - A element with a formula attribute set to the given formula, or\n - If the original had a LaTeX annotation, then the annotation surrounded by \"$$...$$\" */\n const modelNode = isLatex\n ? writer.createText(Parser.initParse(formula, integration.getLanguage()))\n : writer.createElement(\"mathml\", { formula });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\n \"element:img\",\n (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // Only upcast when is wiris formula\n if (viewItem.getClassNames().next().value !== \"Wirisformula\") {\n return;\n }\n\n // The following code ensures that the element's name, attributes, and classes are consumed.\n // This means that they are marked as handled so that other parts of the system or plugins don't process them again.\n\n // Check if we can consume the element name.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // Consume the name, attributes, and classes so nothing else processes it.\n consumable.consume(viewItem, { name: true });\n for (const attrName of viewItem.getAttributes()) {\n consumable.consume(viewItem, { attributes: [attrName] });\n }\n\n for (const className of viewItem.getClassNames()) {\n consumable.consume(viewItem, { classes: [className] });\n }\n\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n const htmlContent = Util.htmlSanitize(``);\n\n const modelNode = writer.createElement(\"mathml\", { htmlContent });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n },\n // Ensures MathType processes the Wiris formulas before other plugins, preventing conflicts.\n { priority: \"high\" },\n );\n\n /**\n * Whether the given view element has a LaTeX annotation element.\n * @param {*} math\n * @returns {bool}\n */\n function mathIsLatex(math) {\n const semantics = math.getChild(0);\n if (!semantics || semantics.name !== \"semantics\") return false;\n for (const child of semantics.getChildren()) {\n if (child.name === \"annotation\" && child.getAttribute(\"encoding\") === \"LaTeX\") {\n return true;\n }\n }\n return false;\n }\n\n function createViewWidget(modelItem, { writer: viewWriter }) {\n const widgetElement = viewWriter.createContainerElement(\"span\", {\n class: \"ck-math-widget\",\n });\n\n const mathUIElement = createViewImage(modelItem, { writer: viewWriter }); // eslint-disable-line no-use-before-define\n\n if (mathUIElement) {\n viewWriter.insert(viewWriter.createPositionAt(widgetElement, 0), mathUIElement);\n }\n\n return toWidget(widgetElement, viewWriter);\n }\n\n function createViewImage(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n const formula = modelItem.getAttribute(\"formula\");\n const htmlContent = modelItem.getAttribute(\"htmlContent\");\n\n if (!formula && !htmlContent) {\n return null;\n }\n\n let imgElement = null;\n\n if (htmlContent) {\n imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);\n } else if (formula) {\n const mathString = formula.replaceAll('ref=\"<\"', 'ref=\"<\"');\n\n const imgHtml = Parser.initParse(mathString, integration.getLanguage());\n imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);\n\n // Add HTML element () to model\n viewWriter.setAttribute(\"htmlContent\", imgHtml, modelItem);\n }\n\n /* Although we use the HtmlDataProcessor to obtain the attributes,\n * we must create a new EmptyElement which is independent of the\n * DataProcessor being used by this editor instance\n */\n if (imgElement) {\n return viewWriter.createEmptyElement(\"img\", imgElement.getAttributes(), {\n renderUnsafeAttributes: [\"src\"],\n });\n }\n\n return null;\n }\n\n // Model -> Editing view\n editor.conversion.for(\"editingDowncast\").elementToElement({\n model: \"mathml\",\n view: createViewWidget,\n });\n\n // Model -> Data view\n editor.conversion.for(\"dataDowncast\").elementToElement({\n model: \"mathml\",\n view: createDataString, // eslint-disable-line no-use-before-define\n });\n\n /**\n * Makes a copy of the given view node.\n * @param {module:engine/view/node~Node} sourceNode Node to copy.\n * @returns {module:engine/view/node~Node} Copy of the node.\n */\n function clone(viewWriter, sourceNode) {\n if (sourceNode.is(\"text\")) {\n return viewWriter.createText(sourceNode.data);\n }\n if (sourceNode.is(\"element\")) {\n if (sourceNode.is(\"emptyElement\")) {\n return viewWriter.createEmptyElement(sourceNode.name, sourceNode.getAttributes());\n }\n const element = viewWriter.createContainerElement(sourceNode.name, sourceNode.getAttributes());\n for (const child of sourceNode.getChildren()) {\n viewWriter.insert(viewWriter.createPositionAt(element, \"end\"), clone(viewWriter, child));\n }\n return element;\n }\n\n throw new Exception(\"Given node has unsupported type.\"); // eslint-disable-line no-undef\n }\n\n function createDataString(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n // Load img element\n const mathString =\n modelItem.getAttribute(\"htmlContent\") || Parser.endParseSaveMode(modelItem.getAttribute(\"formula\"));\n\n const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);\n\n return clone(viewWriter, sourceMathElement);\n }\n\n // This stops the view selection getting into the s and messing up caret movement\n editor.editing.mapper.on(\n \"viewToModelPosition\",\n viewToModelPositionOutsideModelElement(editor.model, (viewElement) => viewElement.hasClass(\"ck-math-widget\")),\n );\n\n // Keep a reference to the original get and set function.\n const { get, set } = editor.data;\n\n /**\n * Hack to transform $$latex$$ into in editor.getData()'s output.\n */\n editor.data.on(\n \"get\",\n (e) => {\n const output = e.return;\n const parsedResult = Parser.endParse(output);\n\n // Cleans all the semantics tag for safexml\n // including the handwritten data points\n e.return = MathML.removeSafeXMLSemantics(parsedResult);\n },\n { priority: \"low\" },\n );\n\n /**\n * Hack to transform with LaTeX into $$LaTeX$$ and formula images in editor.setData().\n */\n editor.data.on(\n \"set\",\n (e, args) => {\n // Retrieve the data to be set on the CKEditor.\n let modifiedData = args[0];\n // Regex to find all mathml formulas.\n const regexp = /(]*>)|()/gm;\n const formulas = [];\n let formula;\n\n // Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.\n while ((formula = regexp.exec(modifiedData)) !== null) {\n formulas.push(formula[0]);\n }\n\n // Loop to find LaTeX and formula images and replace the MathML for the both.\n formulas.forEach((formula) => {\n if (formula.includes('encoding=\"LaTeX\"')) {\n // LaTeX found.\n const latex = `$$$${Latex.getLatexFromMathML(formula)}$$$`; // We add $$$ instead of $$ because the replace function ignores one $.\n modifiedData = modifiedData.replace(formula, latex);\n } else if (formula.includes(\" {...})\n return this.editorObject.model.change((writer) => {\n const core = this.getCore();\n const selection = this.editorObject.model.document.selection;\n\n const modelElementNew = writer.createElement(\"mathml\", {\n formula: mathml,\n ...Object.fromEntries(selection.getAttributes()), // To keep the format, such as style and font\n });\n\n // Obtain the DOM object corresponding to the formula\n if (core.editionProperties.isNewElement) {\n // Don't bother inserting anything at all if the MathML is empty.\n if (!mathml) return;\n\n const viewSelection =\n this.core.editionProperties.selection || this.editorObject.editing.view.document.selection;\n const modelPosition = this.editorObject.editing.mapper.toModelPosition(viewSelection.getLastPosition());\n\n this.editorObject.model.insertObject(modelElementNew, modelPosition);\n\n // Remove selection\n if (!viewSelection.isCollapsed) {\n for (const range of viewSelection.getRanges()) {\n writer.remove(this.editorObject.editing.mapper.toModelRange(range));\n }\n }\n\n // Set carret after the formula\n const position = this.editorObject.model.createPositionAfter(modelElementNew);\n writer.setSelection(position);\n } else {\n const img = core.editionProperties.temporalImage;\n const viewElement = this.editorObject.editing.view.domConverter.domToView(img).parent;\n const modelElementOld = this.editorObject.editing.mapper.toModelElement(viewElement);\n\n // Insert the new and remove the old one\n const position = this.editorObject.model.createPositionBefore(modelElementOld);\n\n // If the given MathML is empty, don't insert a new formula.\n if (mathml) {\n this.editorObject.model.insertObject(modelElementNew, position);\n }\n writer.remove(modelElementOld);\n }\n\n // eslint-disable-next-line consistent-return\n return modelElementNew;\n });\n }\n\n /**\n * Finds the text node corresponding to given DOM text element.\n * @param {element} viewElement Element to find corresponding text node of.\n * @returns {module:engine/model/text~Text|undefined} Text node corresponding to the given element or undefined if it doesn't exist.\n */\n findText(viewElement) {\n // eslint-disable-line consistent-return\n // mapper always converts text nodes to *new* model elements so we need to convert the text's parents and then come back down\n let pivot = viewElement;\n let element;\n while (!element) {\n element = this.editorObject.editing.mapper.toModelElement(\n this.editorObject.editing.view.domConverter.domToView(pivot),\n );\n pivot = pivot.parentElement;\n }\n\n // Navigate through all the subtree under `pivot` in order to find the correct text node\n const range = this.editorObject.model.createRangeIn(element);\n const descendants = Array.from(range.getItems());\n for (const node of descendants) {\n let viewElementData = viewElement.data;\n if (viewElement.nodeType === 3) {\n // Remove invisible white spaces\n viewElementData = viewElementData.replaceAll(String.fromCharCode(8288), \"\");\n }\n if (node.is(\"textProxy\") && node.data === viewElementData.replace(String.fromCharCode(160), \" \")) {\n return node.textNode;\n }\n }\n }\n\n /** @inheritdoc */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n // eslint-disable-line no-unused-vars\n const returnObject = {};\n\n let mathmlOrigin;\n if (!mathml) {\n this.insertMathml(\"\");\n } else if (this.core.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n\n this.editorObject.model.change((writer) => {\n const { latexRange } = this.core.editionProperties;\n\n const startNode = this.findText(latexRange.startContainer);\n const endNode = this.findText(latexRange.endContainer);\n\n let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);\n let endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);\n\n let range = writer.createRange(startPosition, endPosition);\n\n // When Latex is next to image/formula.\n if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {\n // Get the position of the latex to be replaced.\n const latexEdited = `$$${Latex.getLatexFromMathML(\n MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml),\n )}$$`;\n let data = latexRange.startContainer.data;\n\n // Remove invisible characters.\n data = data.replaceAll(String.fromCharCode(8288), \"\");\n\n // Get to the start of the latex we are editing.\n const offset = data.indexOf(latexEdited);\n const dataOffset = data.substring(offset);\n const second$ = dataOffset.substring(2).indexOf(\"$$\") + 4;\n const substring = dataOffset.substr(0, second$);\n data = data.replace(substring, \"\");\n\n if (!data) {\n startPosition = writer.createPositionBefore(startNode);\n range = startNode;\n } else {\n startPosition = startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + offset);\n endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + second$ + offset);\n range = writer.createRange(startPosition, endPosition);\n }\n }\n\n writer.remove(range);\n writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);\n });\n } else {\n mathmlOrigin = this.core.editionProperties.temporalImage?.dataset.mathml;\n try {\n returnObject.node = this.editorObject.editing.view.domConverter.viewToDom(\n this.editorObject.editing.mapper.toViewElement(this.insertMathml(mathml)),\n windowTarget.document,\n );\n } catch (e) {\n const x = e.toString();\n if (x.includes(\"CKEditorError: Cannot read property 'parent' of undefined\")) {\n this.core.modalDialog.cancelAction();\n }\n }\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.core.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n\n /* Due to PLUGINS-1329, we add the onChange event to the CK4 insertFormula.\n We probably should add it here as well, but we should look further into how */\n // this.editorObject.fire('change');\n\n // Remove temporal image of inserted formula\n this.core.editionProperties.temporalImage = null;\n\n return returnObject;\n }\n\n /**\n * Function called when the content submits an action.\n */\n notifyWindowClosed() {\n this.editorObject.editing.view.focus();\n }\n}\n","/* eslint-disable max-classes-per-file */\nimport { Command } from \"ckeditor5/src/core.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\n/**\n * Command for opening the MathType editor\n */\nexport class MathTypeCommand extends Command {\n execute(options = {}) {\n // Check we get a valid integration\n // eslint-disable-next-line no-prototype-builtins\n if (!options.hasOwnProperty(\"integration\") || !(options.integration instanceof CKEditor5Integration)) {\n throw 'Must pass a valid CKEditor5Integration instance as attribute \"integration\" of options';\n }\n\n // Save the integration instance as a property of the command.\n this.integration = options.integration;\n\n // Set custom editor or disable it\n this.setEditor();\n\n // Open the editor\n this.openEditor();\n }\n\n /**\n * Sets the appropriate custom editor, if any, or disables them.\n */\n setEditor() {\n // It's possible that a custom editor was last used.\n // We need to disable it to avoid wrong behaviors.\n this.integration.core.getCustomEditors().disable();\n }\n\n /**\n * Checks whether we are editing an existing formula or a new one and opens the editor.\n */\n openEditor() {\n this.integration.core.editionProperties.dbclick = false;\n const image = this._getSelectedImage();\n if (\n typeof image !== \"undefined\" &&\n image !== null &&\n image.classList.contains(WirisPlugin.Configuration.get(\"imageClassName\"))\n ) {\n this.integration.core.editionProperties.temporalImage = image;\n this.integration.openExistingFormulaEditor();\n } else {\n this.integration.openNewFormulaEditor();\n }\n }\n\n /**\n * Gets the currently selected formula image\n * @returns {Element} selected image, if any, undefined otherwise\n */\n _getSelectedImage() {\n const { selection } = this.editor.editing.view.document;\n\n // If we can not extract the formula, fall back to default behavior.\n if (selection.isCollapsed || selection.rangeCount !== 1) {\n return;\n }\n\n // Look for the wrapping the formula and then for the inside\n\n const range = selection.getFirstRange();\n\n let image;\n\n for (const span of range) {\n if (span.item.name !== \"span\") {\n return;\n }\n image = span.item.getChild(0);\n break;\n }\n\n if (!image) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n return this.editor.editing.view.domConverter.mapViewToDom(image);\n }\n}\n\n/**\n * Command for opening the ChemType editor\n */\nexport class ChemTypeCommand extends MathTypeCommand {\n setEditor() {\n this.integration.core.getCustomEditors().enable(\"chemistry\");\n }\n}\n","// CKEditor imports\nimport { Plugin } from \"ckeditor5/src/core.js\";\nimport { ButtonView } from \"ckeditor5/src/ui.js\";\nimport { ClickObserver, HtmlDataProcessor, XmlDataProcessor, ViewUpcastWriter } from \"ckeditor5/src/engine.js\";\nimport { Widget, toWidget, viewToModelPositionOutsideModelElement } from \"ckeditor5/src/widget.js\";\n\n// MathType API imports\nimport IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Core from \"@wiris/mathtype-html-integration-devkit/src/core.src.js\";\nimport Parser from \"@wiris/mathtype-html-integration-devkit/src/parser.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Image from \"@wiris/mathtype-html-integration-devkit/src/image.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Listeners from \"@wiris/mathtype-html-integration-devkit/src/listeners.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport StringManager from \"@wiris/mathtype-html-integration-devkit/src/stringmanager.js\";\nimport \"@wiris/mathtype-html-integration-devkit/src/md5.js\";\n\n// Local imports\nimport { MathTypeCommand, ChemTypeCommand } from \"./commands.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\nimport mathIcon from \"../theme/icons/ckeditor5-formula.svg\";\nimport chemIcon from \"../theme/icons/ckeditor5-chem.svg\";\n\nimport packageInfo from \"../package.json\";\n\nexport let currentInstance = null; // eslint-disable-line import/no-mutable-exports\n\nexport default class MathType extends Plugin {\n static get requires() {\n return [Widget];\n }\n\n static get pluginName() {\n return \"MathType\";\n }\n\n init() {\n // Create the MathType API Integration object\n const integration = this._addIntegration();\n currentInstance = integration;\n\n // Add the MathType and ChemType commands to the editor\n this._addCommands();\n\n // Add the buttons for MathType and ChemType\n this._addViews(integration);\n\n // Registers the element in the schema\n this._addSchema();\n\n // Add the downcast and upcast converters\n this._addConverters(integration);\n\n // Expose the WirisPlugin variable to the window\n this._exposeWiris();\n }\n\n /**\n * Inherited from Plugin class: Executed when CKEditor5 is destroyed\n */\n destroy() {\n // eslint-disable-line class-methods-use-this\n currentInstance?.destroy();\n }\n\n /**\n * Create the MathType API Integration object\n * @returns {CKEditor5Integration} the integration object\n */\n _addIntegration() {\n const { editor } = this;\n\n /**\n * Integration model constructor attributes.\n * @type {integrationModelProperties}\n */\n const integrationProperties = {};\n integrationProperties.environment = {};\n integrationProperties.environment.editor = \"CKEditor5\";\n integrationProperties.environment.editorVersion = \"5.x\";\n integrationProperties.version = packageInfo.version;\n integrationProperties.editorObject = editor;\n integrationProperties.serviceProviderProperties = {};\n integrationProperties.serviceProviderProperties.URI = \"https://www.wiris.net/demo/plugins/app\";\n integrationProperties.serviceProviderProperties.server = \"java\";\n integrationProperties.target = editor.sourceElement;\n integrationProperties.scriptName = \"bundle.js\";\n integrationProperties.managesLanguage = true;\n // etc\n\n // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.\n // To avoid a wrong behavior, this integration only starts if the workspace container exists.\n let integration;\n if (integrationProperties.target) {\n // Instance of the integration associated to this editor instance\n integration = new CKEditor5Integration(integrationProperties);\n integration.init();\n integration.listeners.fire(\"onTargetReady\", {});\n\n integration.checkElement();\n\n this.listenTo(\n editor.editing.view.document,\n \"click\",\n (evt, data) => {\n // Is Double-click\n if (data.domEvent.detail === 2) {\n integration.doubleClickHandler(data.domTarget, data.domEvent);\n evt.stop();\n }\n },\n { priority: \"highest\" },\n );\n }\n\n return integration;\n }\n\n /**\n * Add the MathType and ChemType commands to the editor\n */\n _addCommands() {\n const { editor } = this;\n\n // Add command to open the formula editor\n editor.commands.add(\"MathType\", new MathTypeCommand(editor));\n\n // Add command to open the chemistry formula editor\n editor.commands.add(\"ChemType\", new ChemTypeCommand(editor));\n }\n\n /**\n * Add the buttons for MathType and ChemType\n * @param {CKEditor5Integration} integration the integration object\n */\n _addViews(integration) {\n const { editor } = this;\n\n // Check if MathType editor is enabled\n if (Configuration.get(\"editorEnabled\")) {\n // Add button for the formula editor\n editor.ui.componentFactory.add(\"MathType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"MathType\"), \"isEnabled\");\n view.set({\n label: StringManager.get(\"insert_math\", integration.getLanguage()),\n icon: mathIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"MathType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Check if ChemType editor is enabled\n if (Configuration.get(\"chemEnabled\")) {\n // Add button for the chemistry formula editor\n editor.ui.componentFactory.add(\"ChemType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"ChemType\"), \"isEnabled\");\n\n view.set({\n label: StringManager.get(\"insert_chem\", integration.getLanguage()),\n icon: chemIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"ChemType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Observer for the Double-click event\n editor.editing.view.addObserver(ClickObserver);\n }\n\n /**\n * Registers the element in the schema\n */\n _addSchema() {\n const { schema } = this.editor.model;\n\n schema.register(\"mathml\", {\n inheritAllFrom: \"$inlineObject\",\n allowAttributes: [\"formula\", \"htmlContent\"],\n });\n }\n\n /**\n * Add the downcast and upcast converters\n */\n _addConverters(integration) {\n const { editor } = this;\n\n // Editing view -> Model\n editor.conversion.for(\"upcast\").elementToElement({\n view: {\n name: \"span\",\n classes: \"ck-math-widget\",\n },\n model: (viewElement, { writer: modelWriter }) => {\n const formula = MathML.safeXmlDecode(viewElement.getChild(0).getAttribute(\"data-mathml\"));\n return modelWriter.createElement(\"mathml\", {\n formula,\n });\n },\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\"element:math\", (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // When element was already consumed then skip it.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // If we encounter any with a LaTeX annotation inside,\n // convert it into a \"$$...$$\" string.\n const isLatex = mathIsLatex(viewItem); // eslint-disable-line no-use-before-define\n\n // Get the formula of the (which is all its children).\n const processor = new XmlDataProcessor(editor.editing.view.document);\n\n // Only god knows why the following line makes viewItem lose all of its children,\n // so we obtain isLatex before doing this because we need viewItem's children for that.\n const upcastWriter = new ViewUpcastWriter(editor.editing.view.document);\n const viewDocumentFragment = upcastWriter.createDocumentFragment(viewItem.getChildren());\n\n // and obtain the attributes of too!\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n\n // We process the document fragment\n let formula = processor.toData(viewDocumentFragment) || \"\";\n\n // And obtain the complete formula\n formula = Util.htmlSanitize(`${formula}`);\n\n // Replaces the < & > characters to its HTMLEntity to avoid render issues.\n formula = formula.replaceAll('\"<\"', '\"<\"').replaceAll('\">\"', '\">\"').replaceAll(\"><<\", \"><<\");\n\n /* Model node that contains what's going to actually be inserted. This can be either:\n - A element with a formula attribute set to the given formula, or\n - If the original had a LaTeX annotation, then the annotation surrounded by \"$$...$$\" */\n const modelNode = isLatex\n ? writer.createText(Parser.initParse(formula, integration.getLanguage()))\n : writer.createElement(\"mathml\", { formula });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\n \"element:img\",\n (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // Only upcast when is wiris formula\n if (viewItem.getClassNames().next().value !== \"Wirisformula\") {\n return;\n }\n\n // The following code ensures that the element's name, attributes, and classes are consumed.\n // This means that they are marked as handled so that other parts of the system or plugins don't process them again.\n\n // Check if we can consume the element name.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // Consume the name, attributes, and classes so nothing else processes it.\n consumable.consume(viewItem, { name: true });\n for (const attrName of viewItem.getAttributes()) {\n consumable.consume(viewItem, { attributes: [attrName] });\n }\n\n for (const className of viewItem.getClassNames()) {\n consumable.consume(viewItem, { classes: [className] });\n }\n\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n const htmlContent = Util.htmlSanitize(``);\n\n const modelNode = writer.createElement(\"mathml\", { htmlContent });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n },\n // Ensures MathType processes the Wiris formulas before other plugins, preventing conflicts.\n { priority: \"high\" },\n );\n\n /**\n * Whether the given view element has a LaTeX annotation element.\n * @param {*} math\n * @returns {bool}\n */\n function mathIsLatex(math) {\n const semantics = math.getChild(0);\n if (!semantics || semantics.name !== \"semantics\") return false;\n for (const child of semantics.getChildren()) {\n if (child.name === \"annotation\" && child.getAttribute(\"encoding\") === \"LaTeX\") {\n return true;\n }\n }\n return false;\n }\n\n function createViewWidget(modelItem, { writer: viewWriter }) {\n const widgetElement = viewWriter.createContainerElement(\"span\", {\n class: \"ck-math-widget\",\n });\n\n const mathUIElement = createViewImage(modelItem, { writer: viewWriter }); // eslint-disable-line no-use-before-define\n\n if (mathUIElement) {\n viewWriter.insert(viewWriter.createPositionAt(widgetElement, 0), mathUIElement);\n }\n\n return toWidget(widgetElement, viewWriter);\n }\n\n function createViewImage(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n const formula = modelItem.getAttribute(\"formula\");\n const htmlContent = modelItem.getAttribute(\"htmlContent\");\n\n if (!formula && !htmlContent) {\n return null;\n }\n\n let imgElement = null;\n\n if (htmlContent) {\n imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);\n } else if (formula) {\n const mathString = formula.replaceAll('ref=\"<\"', 'ref=\"<\"');\n\n const imgHtml = Parser.initParse(mathString, integration.getLanguage());\n imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);\n\n // Add HTML element () to model\n viewWriter.setAttribute(\"htmlContent\", imgHtml, modelItem);\n }\n\n /* Although we use the HtmlDataProcessor to obtain the attributes,\n * we must create a new EmptyElement which is independent of the\n * DataProcessor being used by this editor instance\n */\n if (imgElement) {\n return viewWriter.createEmptyElement(\"img\", imgElement.getAttributes(), {\n renderUnsafeAttributes: [\"src\"],\n });\n }\n\n return null;\n }\n\n // Model -> Editing view\n editor.conversion.for(\"editingDowncast\").elementToElement({\n model: \"mathml\",\n view: createViewWidget,\n });\n\n // Model -> Data view\n editor.conversion.for(\"dataDowncast\").elementToElement({\n model: \"mathml\",\n view: createDataString, // eslint-disable-line no-use-before-define\n });\n\n /**\n * Makes a copy of the given view node.\n * @param {module:engine/view/node~Node} sourceNode Node to copy.\n * @returns {module:engine/view/node~Node} Copy of the node.\n */\n function clone(viewWriter, sourceNode) {\n if (sourceNode.is(\"text\")) {\n return viewWriter.createText(sourceNode.data);\n }\n if (sourceNode.is(\"element\")) {\n if (sourceNode.is(\"emptyElement\")) {\n return viewWriter.createEmptyElement(sourceNode.name, sourceNode.getAttributes());\n }\n const element = viewWriter.createContainerElement(sourceNode.name, sourceNode.getAttributes());\n for (const child of sourceNode.getChildren()) {\n viewWriter.insert(viewWriter.createPositionAt(element, \"end\"), clone(viewWriter, child));\n }\n return element;\n }\n\n throw new Exception(\"Given node has unsupported type.\"); // eslint-disable-line no-undef\n }\n\n function createDataString(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n // Load img element\n const mathString =\n modelItem.getAttribute(\"htmlContent\") || Parser.endParseSaveMode(modelItem.getAttribute(\"formula\"));\n\n const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);\n\n return clone(viewWriter, sourceMathElement);\n }\n\n // This stops the view selection getting into the s and messing up caret movement\n editor.editing.mapper.on(\n \"viewToModelPosition\",\n viewToModelPositionOutsideModelElement(editor.model, (viewElement) => viewElement.hasClass(\"ck-math-widget\")),\n );\n\n // Keep a reference to the original get and set function.\n const { get, set } = editor.data;\n\n /**\n * Hack to transform $$latex$$ into in editor.getData()'s output.\n */\n editor.data.on(\n \"get\",\n (e) => {\n const output = e.return;\n const parsedResult = Parser.endParse(output);\n\n // Cleans all the semantics tag for safexml\n // including the handwritten data points\n e.return = MathML.removeSafeXMLSemantics(parsedResult);\n },\n { priority: \"low\" },\n );\n\n /**\n * Hack to transform with LaTeX into $$LaTeX$$ and formula images in editor.setData().\n */\n editor.data.on(\n \"set\",\n (e, args) => {\n // Retrieve the data to be set on the CKEditor.\n let modifiedData = args[0];\n // Regex to find all mathml formulas.\n const regexp = /(]*>)|()/gm;\n const formulas = [];\n let formula;\n\n // Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.\n while ((formula = regexp.exec(modifiedData)) !== null) {\n formulas.push(formula[0]);\n }\n\n // Loop to find LaTeX and formula images and replace the MathML for the both.\n formulas.forEach((formula) => {\n if (formula.includes('encoding=\"LaTeX\"')) {\n // LaTeX found.\n const latex = `$$$${Latex.getLatexFromMathML(formula)}$$$`; // We add $$$ instead of $$ because the replace function ignores one $.\n modifiedData = modifiedData.replace(formula, latex);\n } else if (formula.includes(\" {...})\n return this.editorObject.model.change((writer) => {\n const core = this.getCore();\n const selection = this.editorObject.model.document.selection;\n\n const modelElementNew = writer.createElement(\"mathml\", {\n formula: mathml,\n ...Object.fromEntries(selection.getAttributes()), // To keep the format, such as style and font\n });\n\n // Obtain the DOM object corresponding to the formula\n if (core.editionProperties.isNewElement) {\n // Don't bother inserting anything at all if the MathML is empty.\n if (!mathml) return;\n\n const viewSelection =\n this.core.editionProperties.selection || this.editorObject.editing.view.document.selection;\n const modelPosition = this.editorObject.editing.mapper.toModelPosition(viewSelection.getLastPosition());\n\n this.editorObject.model.insertObject(modelElementNew, modelPosition);\n\n // Remove selection\n if (!viewSelection.isCollapsed) {\n for (const range of viewSelection.getRanges()) {\n writer.remove(this.editorObject.editing.mapper.toModelRange(range));\n }\n }\n\n // Set carret after the formula\n const position = this.editorObject.model.createPositionAfter(modelElementNew);\n writer.setSelection(position);\n } else {\n const img = core.editionProperties.temporalImage;\n const viewElement = this.editorObject.editing.view.domConverter.domToView(img).parent;\n const modelElementOld = this.editorObject.editing.mapper.toModelElement(viewElement);\n\n // Insert the new and remove the old one\n const position = this.editorObject.model.createPositionBefore(modelElementOld);\n\n // If the given MathML is empty, don't insert a new formula.\n if (mathml) {\n this.editorObject.model.insertObject(modelElementNew, position);\n }\n writer.remove(modelElementOld);\n }\n\n // eslint-disable-next-line consistent-return\n return modelElementNew;\n });\n }\n\n /**\n * Finds the text node corresponding to given DOM text element.\n * @param {element} viewElement Element to find corresponding text node of.\n * @returns {module:engine/model/text~Text|undefined} Text node corresponding to the given element or undefined if it doesn't exist.\n */\n findText(viewElement) {\n // eslint-disable-line consistent-return\n // mapper always converts text nodes to *new* model elements so we need to convert the text's parents and then come back down\n let pivot = viewElement;\n let element;\n while (!element) {\n element = this.editorObject.editing.mapper.toModelElement(\n this.editorObject.editing.view.domConverter.domToView(pivot),\n );\n pivot = pivot.parentElement;\n }\n\n // Navigate through all the subtree under `pivot` in order to find the correct text node\n const range = this.editorObject.model.createRangeIn(element);\n const descendants = Array.from(range.getItems());\n for (const node of descendants) {\n let viewElementData = viewElement.data;\n if (viewElement.nodeType === 3) {\n // Remove invisible white spaces\n viewElementData = viewElementData.replaceAll(String.fromCharCode(8288), \"\");\n }\n if (node.is(\"textProxy\") && node.data === viewElementData.replace(String.fromCharCode(160), \" \")) {\n return node.textNode;\n }\n }\n }\n\n /** @inheritdoc */\n insertFormula(focusElement, windowTarget, mathml, wirisProperties) {\n // eslint-disable-line no-unused-vars\n const returnObject = {};\n\n let mathmlOrigin;\n if (!mathml) {\n this.insertMathml(\"\");\n } else if (this.core.editMode === \"latex\") {\n returnObject.latex = Latex.getLatexFromMathML(mathml);\n returnObject.node = windowTarget.document.createTextNode(`$$${returnObject.latex}$$`);\n\n this.editorObject.model.change((writer) => {\n const { latexRange } = this.core.editionProperties;\n\n const startNode = this.findText(latexRange.startContainer);\n const endNode = this.findText(latexRange.endContainer);\n\n let startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + latexRange.startOffset);\n let endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + latexRange.endOffset);\n\n let range = writer.createRange(startPosition, endPosition);\n\n // When Latex is next to image/formula.\n if (latexRange.startContainer.nodeType === 3 && latexRange.startContainer.previousSibling?.nodeType === 1) {\n // Get the position of the latex to be replaced.\n const latexEdited = `$$${Latex.getLatexFromMathML(\n MathML.safeXmlDecode(this.core.editionProperties.temporalImage.dataset.mathml),\n )}$$`;\n let data = latexRange.startContainer.data;\n\n // Remove invisible characters.\n data = data.replaceAll(String.fromCharCode(8288), \"\");\n\n // Get to the start of the latex we are editing.\n const offset = data.indexOf(latexEdited);\n const dataOffset = data.substring(offset);\n const second$ = dataOffset.substring(2).indexOf(\"$$\") + 4;\n const substring = dataOffset.substr(0, second$);\n data = data.replace(substring, \"\");\n\n if (!data) {\n startPosition = writer.createPositionBefore(startNode);\n range = startNode;\n } else {\n startPosition = startPosition = writer.createPositionAt(startNode.parent, startNode.startOffset + offset);\n endPosition = writer.createPositionAt(endNode.parent, endNode.startOffset + second$ + offset);\n range = writer.createRange(startPosition, endPosition);\n }\n }\n\n writer.remove(range);\n writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);\n });\n } else {\n mathmlOrigin = this.core.editionProperties.temporalImage?.dataset.mathml;\n try {\n returnObject.node = this.editorObject.editing.view.domConverter.viewToDom(\n this.editorObject.editing.mapper.toViewElement(this.insertMathml(mathml)),\n windowTarget.document,\n );\n } catch (e) {\n const x = e.toString();\n if (x.includes(\"CKEditorError: Cannot read property 'parent' of undefined\")) {\n this.core.modalDialog.cancelAction();\n }\n }\n }\n\n // Build the telemeter payload separated to delete null/undefined entries.\n const payload = {\n mathml_origin: mathmlOrigin ? MathML.safeXmlDecode(mathmlOrigin) : mathmlOrigin,\n mathml: mathml ? MathML.safeXmlDecode(mathml) : mathml,\n elapsed_time: Date.now() - this.core.editionProperties.editionStartTime,\n editor_origin: null, // TODO read formula to find out whether it comes from Oxygen Desktop\n toolbar: this.core.modalDialog.contentManager.toolbar,\n size: mathml?.length,\n };\n\n // Remove desired null keys.\n Object.keys(payload).forEach((key) => {\n if (key === \"mathml_origin\" || key === \"editor_origin\") !payload[key] ? delete payload[key] : {};\n });\n\n // Call Telemetry service to track the event.\n try {\n Telemeter.telemeter.track(\"INSERTED_FORMULA\", {\n ...payload,\n });\n } catch (error) {\n console.error(\"Error tracking INSERTED_FORMULA\", error);\n }\n\n /* Due to PLUGINS-1329, we add the onChange event to the CK4 insertFormula.\n We probably should add it here as well, but we should look further into how */\n // this.editorObject.fire('change');\n\n // Remove temporal image of inserted formula\n this.core.editionProperties.temporalImage = null;\n\n return returnObject;\n }\n\n /**\n * Function called when the content submits an action.\n */\n notifyWindowClosed() {\n this.editorObject.editing.view.focus();\n }\n}\n","/* eslint-disable max-classes-per-file */\nimport { Command } from \"ckeditor5/src/core.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\n/**\n * Command for opening the MathType editor\n */\nexport class MathTypeCommand extends Command {\n execute(options = {}) {\n // Check we get a valid integration\n // eslint-disable-next-line no-prototype-builtins\n if (!options.hasOwnProperty(\"integration\") || !(options.integration instanceof CKEditor5Integration)) {\n throw 'Must pass a valid CKEditor5Integration instance as attribute \"integration\" of options';\n }\n\n // Save the integration instance as a property of the command.\n this.integration = options.integration;\n\n // Set custom editor or disable it\n this.setEditor();\n\n // Open the editor\n this.openEditor();\n }\n\n /**\n * Sets the appropriate custom editor, if any, or disables them.\n */\n setEditor() {\n // It's possible that a custom editor was last used.\n // We need to disable it to avoid wrong behaviors.\n this.integration.core.getCustomEditors().disable();\n }\n\n /**\n * Checks whether we are editing an existing formula or a new one and opens the editor.\n */\n openEditor() {\n this.integration.core.editionProperties.dbclick = false;\n const image = this._getSelectedImage();\n if (\n typeof image !== \"undefined\" &&\n image !== null &&\n image.classList.contains(WirisPlugin.Configuration.get(\"imageClassName\"))\n ) {\n this.integration.core.editionProperties.temporalImage = image;\n this.integration.openExistingFormulaEditor();\n } else {\n this.integration.openNewFormulaEditor();\n }\n }\n\n /**\n * Gets the currently selected formula image\n * @returns {Element} selected image, if any, undefined otherwise\n */\n _getSelectedImage() {\n const { selection } = this.editor.editing.view.document;\n\n // If we can not extract the formula, fall back to default behavior.\n if (selection.isCollapsed || selection.rangeCount !== 1) {\n return;\n }\n\n // Look for the wrapping the formula and then for the inside\n\n const range = selection.getFirstRange();\n\n let image;\n\n for (const span of range) {\n if (span.item.name !== \"span\") {\n return;\n }\n image = span.item.getChild(0);\n break;\n }\n\n if (!image) {\n return;\n }\n\n // eslint-disable-next-line consistent-return\n return this.editor.editing.view.domConverter.mapViewToDom(image);\n }\n}\n\n/**\n * Command for opening the ChemType editor\n */\nexport class ChemTypeCommand extends MathTypeCommand {\n setEditor() {\n this.integration.core.getCustomEditors().enable(\"chemistry\");\n }\n}\n","// CKEditor imports\nimport { Plugin } from \"ckeditor5/src/core.js\";\nimport { ButtonView } from \"ckeditor5/src/ui.js\";\nimport { ClickObserver, HtmlDataProcessor, XmlDataProcessor, ViewUpcastWriter } from \"ckeditor5/src/engine.js\";\nimport { Widget, toWidget, viewToModelPositionOutsideModelElement } from \"ckeditor5/src/widget.js\";\n\n// MathType API imports\nimport IntegrationModel from \"@wiris/mathtype-html-integration-devkit/src/integrationmodel.js\";\nimport Core from \"@wiris/mathtype-html-integration-devkit/src/core.src.js\";\nimport Parser from \"@wiris/mathtype-html-integration-devkit/src/parser.js\";\nimport Util from \"@wiris/mathtype-html-integration-devkit/src/util.js\";\nimport Image from \"@wiris/mathtype-html-integration-devkit/src/image.js\";\nimport Configuration from \"@wiris/mathtype-html-integration-devkit/src/configuration.js\";\nimport Listeners from \"@wiris/mathtype-html-integration-devkit/src/listeners.js\";\nimport MathML from \"@wiris/mathtype-html-integration-devkit/src/mathml.js\";\nimport Latex from \"@wiris/mathtype-html-integration-devkit/src/latex.js\";\nimport StringManager from \"@wiris/mathtype-html-integration-devkit/src/stringmanager.js\";\nimport \"@wiris/mathtype-html-integration-devkit/src/md5.js\";\n\n// Local imports\nimport { MathTypeCommand, ChemTypeCommand } from \"./commands.js\";\nimport CKEditor5Integration from \"./integration.js\";\n\nimport mathIcon from \"../theme/icons/ckeditor5-formula.svg\";\nimport chemIcon from \"../theme/icons/ckeditor5-chem.svg\";\n\nimport packageInfo from \"../package.json\";\n\nexport let currentInstance = null; // eslint-disable-line import/no-mutable-exports\n\nexport default class MathType extends Plugin {\n static get requires() {\n return [Widget];\n }\n\n static get pluginName() {\n return \"MathType\";\n }\n\n init() {\n // Create the MathType API Integration object\n const integration = this._addIntegration();\n currentInstance = integration;\n\n // Add the MathType and ChemType commands to the editor\n this._addCommands();\n\n // Add the buttons for MathType and ChemType\n this._addViews(integration);\n\n // Registers the element in the schema\n this._addSchema();\n\n // Add the downcast and upcast converters\n this._addConverters(integration);\n\n // Expose the WirisPlugin variable to the window\n this._exposeWiris();\n }\n\n /**\n * Inherited from Plugin class: Executed when CKEditor5 is destroyed\n */\n destroy() {\n // eslint-disable-line class-methods-use-this\n currentInstance?.destroy();\n }\n\n /**\n * Create the MathType API Integration object\n * @returns {CKEditor5Integration} the integration object\n */\n _addIntegration() {\n const { editor } = this;\n\n /**\n * Integration model constructor attributes.\n * @type {integrationModelProperties}\n */\n const integrationProperties = {};\n integrationProperties.environment = {};\n integrationProperties.environment.editor = \"CKEditor5\";\n integrationProperties.environment.editorVersion = \"5.x\";\n integrationProperties.version = packageInfo.version;\n integrationProperties.editorObject = editor;\n integrationProperties.serviceProviderProperties = {};\n integrationProperties.serviceProviderProperties.URI = \"https://www.wiris.net/demo/plugins/app\";\n integrationProperties.serviceProviderProperties.server = \"java\";\n integrationProperties.target = editor.sourceElement;\n integrationProperties.scriptName = \"bundle.js\";\n integrationProperties.managesLanguage = true;\n // etc\n\n // There are platforms like Drupal that initialize CKEditor but they hide or remove the container element.\n // To avoid a wrong behavior, this integration only starts if the workspace container exists.\n let integration;\n if (integrationProperties.target) {\n // Instance of the integration associated to this editor instance\n integration = new CKEditor5Integration(integrationProperties);\n integration.init();\n integration.listeners.fire(\"onTargetReady\", {});\n\n integration.checkElement();\n\n this.listenTo(\n editor.editing.view.document,\n \"click\",\n (evt, data) => {\n // Is Double-click\n if (data.domEvent.detail === 2) {\n integration.doubleClickHandler(data.domTarget, data.domEvent);\n evt.stop();\n }\n },\n { priority: \"highest\" },\n );\n }\n\n return integration;\n }\n\n /**\n * Add the MathType and ChemType commands to the editor\n */\n _addCommands() {\n const { editor } = this;\n\n // Add command to open the formula editor\n editor.commands.add(\"MathType\", new MathTypeCommand(editor));\n\n // Add command to open the chemistry formula editor\n editor.commands.add(\"ChemType\", new ChemTypeCommand(editor));\n }\n\n /**\n * Add the buttons for MathType and ChemType\n * @param {CKEditor5Integration} integration the integration object\n */\n _addViews(integration) {\n const { editor } = this;\n\n // Check if MathType editor is enabled\n if (Configuration.get(\"editorEnabled\")) {\n // Add button for the formula editor\n editor.ui.componentFactory.add(\"MathType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"MathType\"), \"isEnabled\");\n view.set({\n label: StringManager.get(\"insert_math\", integration.getLanguage()),\n icon: mathIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"MathType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Check if ChemType editor is enabled\n if (Configuration.get(\"chemEnabled\")) {\n // Add button for the chemistry formula editor\n editor.ui.componentFactory.add(\"ChemType\", (locale) => {\n const view = new ButtonView(locale);\n\n // View is enabled iff command is enabled\n view.bind(\"isEnabled\").to(editor.commands.get(\"ChemType\"), \"isEnabled\");\n\n view.set({\n label: StringManager.get(\"insert_chem\", integration.getLanguage()),\n icon: chemIcon,\n tooltip: true,\n });\n\n // Callback executed once the image is clicked.\n view.on(\"execute\", () => {\n editor.execute(\"ChemType\", {\n integration, // Pass integration as parameter\n });\n });\n\n return view;\n });\n }\n\n // Observer for the Double-click event\n editor.editing.view.addObserver(ClickObserver);\n }\n\n /**\n * Registers the element in the schema\n */\n _addSchema() {\n const { schema } = this.editor.model;\n\n schema.register(\"mathml\", {\n inheritAllFrom: \"$inlineObject\",\n allowAttributes: [\"formula\", \"htmlContent\"],\n });\n }\n\n /**\n * Add the downcast and upcast converters\n */\n _addConverters(integration) {\n const { editor } = this;\n\n // Editing view -> Model\n editor.conversion.for(\"upcast\").elementToElement({\n view: {\n name: \"span\",\n classes: \"ck-math-widget\",\n },\n model: (viewElement, { writer: modelWriter }) => {\n const formula = MathML.safeXmlDecode(viewElement.getChild(0).getAttribute(\"data-mathml\"));\n return modelWriter.createElement(\"mathml\", {\n formula,\n });\n },\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\"element:math\", (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // When element was already consumed then skip it.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // If we encounter any with a LaTeX annotation inside,\n // convert it into a \"$$...$$\" string.\n const isLatex = mathIsLatex(viewItem); // eslint-disable-line no-use-before-define\n\n // Get the formula of the (which is all its children).\n const processor = new XmlDataProcessor(editor.editing.view.document);\n\n // Only god knows why the following line makes viewItem lose all of its children,\n // so we obtain isLatex before doing this because we need viewItem's children for that.\n const upcastWriter = new ViewUpcastWriter(editor.editing.view.document);\n const viewDocumentFragment = upcastWriter.createDocumentFragment(viewItem.getChildren());\n\n // and obtain the attributes of too!\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n\n // We process the document fragment\n let formula = processor.toData(viewDocumentFragment) || \"\";\n\n // And obtain the complete formula\n formula = Util.htmlSanitize(`${formula}`);\n\n // Replaces the < & > characters to its HTMLEntity to avoid render issues.\n formula = formula.replaceAll('\"<\"', '\"<\"').replaceAll('\">\"', '\">\"').replaceAll(\"><<\", \"><<\");\n\n /* Model node that contains what's going to actually be inserted. This can be either:\n - A element with a formula attribute set to the given formula, or\n - If the original had a LaTeX annotation, then the annotation surrounded by \"$$...$$\" */\n const modelNode = isLatex\n ? writer.createText(Parser.initParse(formula, integration.getLanguage()))\n : writer.createElement(\"mathml\", { formula });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n });\n\n // Data view -> Model\n editor.data.upcastDispatcher.on(\n \"element:img\",\n (evt, data, conversionApi) => {\n const { consumable, writer } = conversionApi;\n const { viewItem } = data;\n\n // Only upcast when is wiris formula\n if (viewItem.getClassNames().next().value !== \"Wirisformula\") {\n return;\n }\n\n // The following code ensures that the element's name, attributes, and classes are consumed.\n // This means that they are marked as handled so that other parts of the system or plugins don't process them again.\n\n // Check if we can consume the element name.\n if (!consumable.test(viewItem, { name: true })) {\n return;\n }\n\n // Consume the name, attributes, and classes so nothing else processes it.\n consumable.consume(viewItem, { name: true });\n for (const attrName of viewItem.getAttributes()) {\n consumable.consume(viewItem, { attributes: [attrName] });\n }\n\n for (const className of viewItem.getClassNames()) {\n consumable.consume(viewItem, { classes: [className] });\n }\n\n const mathAttributes = [...viewItem.getAttributes()].map(([key, value]) => ` ${key}=\"${value}\"`).join(\"\");\n const htmlContent = Util.htmlSanitize(``);\n\n const modelNode = writer.createElement(\"mathml\", { htmlContent });\n\n // Find allowed parent for element that we are going to insert.\n // If current parent does not allow to insert element but one of the ancestors does\n // then split nodes to allowed parent.\n const splitResult = conversionApi.splitToAllowedParent(modelNode, data.modelCursor);\n\n // When there is no split result it means that we can't insert element to model tree, so let's skip it.\n if (!splitResult) {\n return;\n }\n\n // Insert element on allowed position.\n conversionApi.writer.insert(modelNode, splitResult.position);\n\n // Consume appropriate value from consumable values list.\n consumable.consume(viewItem, { name: true });\n\n const parts = conversionApi.getSplitParts(modelNode);\n\n // Set conversion result range.\n data.modelRange = writer.createRange(\n conversionApi.writer.createPositionBefore(modelNode),\n conversionApi.writer.createPositionAfter(parts[parts.length - 1]),\n );\n\n // Now we need to check where the `modelCursor` should be.\n if (splitResult.cursorParent) {\n // If we split parent to insert our element then we want to continue conversion in the new part of the split parent.\n //\n // before: foo[]\n // after: foo[]\n\n data.modelCursor = conversionApi.writer.createPositionAt(splitResult.cursorParent, 0);\n } else {\n // Otherwise just continue after inserted element.\n data.modelCursor = data.modelRange.end;\n }\n },\n // Ensures MathType processes the Wiris formulas before other plugins, preventing conflicts.\n { priority: \"high\" },\n );\n\n /**\n * Whether the given view element has a LaTeX annotation element.\n * @param {*} math\n * @returns {bool}\n */\n function mathIsLatex(math) {\n const semantics = math.getChild(0);\n if (!semantics || semantics.name !== \"semantics\") return false;\n for (const child of semantics.getChildren()) {\n if (child.name === \"annotation\" && child.getAttribute(\"encoding\") === \"LaTeX\") {\n return true;\n }\n }\n return false;\n }\n\n function createViewWidget(modelItem, { writer: viewWriter }) {\n const widgetElement = viewWriter.createContainerElement(\"span\", {\n class: \"ck-math-widget\",\n });\n\n const mathUIElement = createViewImage(modelItem, { writer: viewWriter }); // eslint-disable-line no-use-before-define\n\n if (mathUIElement) {\n viewWriter.insert(viewWriter.createPositionAt(widgetElement, 0), mathUIElement);\n }\n\n return toWidget(widgetElement, viewWriter);\n }\n\n function createViewImage(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n const formula = modelItem.getAttribute(\"formula\");\n const htmlContent = modelItem.getAttribute(\"htmlContent\");\n\n if (!formula && !htmlContent) {\n return null;\n }\n\n let imgElement = null;\n\n if (htmlContent) {\n imgElement = htmlDataProcessor.toView(htmlContent).getChild(0);\n } else if (formula) {\n const mathString = formula.replaceAll('ref=\"<\"', 'ref=\"<\"');\n\n const imgHtml = Parser.initParse(mathString, integration.getLanguage());\n imgElement = htmlDataProcessor.toView(imgHtml).getChild(0);\n\n // Add HTML element () to model\n viewWriter.setAttribute(\"htmlContent\", imgHtml, modelItem);\n }\n\n /* Although we use the HtmlDataProcessor to obtain the attributes,\n * we must create a new EmptyElement which is independent of the\n * DataProcessor being used by this editor instance\n */\n if (imgElement) {\n return viewWriter.createEmptyElement(\"img\", imgElement.getAttributes(), {\n renderUnsafeAttributes: [\"src\"],\n });\n }\n\n return null;\n }\n\n // Model -> Editing view\n editor.conversion.for(\"editingDowncast\").elementToElement({\n model: \"mathml\",\n view: createViewWidget,\n });\n\n // Model -> Data view\n editor.conversion.for(\"dataDowncast\").elementToElement({\n model: \"mathml\",\n view: createDataString, // eslint-disable-line no-use-before-define\n });\n\n /**\n * Makes a copy of the given view node.\n * @param {module:engine/view/node~Node} sourceNode Node to copy.\n * @returns {module:engine/view/node~Node} Copy of the node.\n */\n function clone(viewWriter, sourceNode) {\n if (sourceNode.is(\"text\")) {\n return viewWriter.createText(sourceNode.data);\n }\n if (sourceNode.is(\"element\")) {\n if (sourceNode.is(\"emptyElement\")) {\n return viewWriter.createEmptyElement(sourceNode.name, sourceNode.getAttributes());\n }\n const element = viewWriter.createContainerElement(sourceNode.name, sourceNode.getAttributes());\n for (const child of sourceNode.getChildren()) {\n viewWriter.insert(viewWriter.createPositionAt(element, \"end\"), clone(viewWriter, child));\n }\n return element;\n }\n\n throw new Exception(\"Given node has unsupported type.\"); // eslint-disable-line no-undef\n }\n\n function createDataString(modelItem, { writer: viewWriter }) {\n const htmlDataProcessor = new HtmlDataProcessor(viewWriter.document);\n\n // Load img element\n const mathString =\n modelItem.getAttribute(\"htmlContent\") || Parser.endParseSaveMode(modelItem.getAttribute(\"formula\"));\n\n const sourceMathElement = htmlDataProcessor.toView(mathString).getChild(0);\n\n return clone(viewWriter, sourceMathElement);\n }\n\n // This stops the view selection getting into the s and messing up caret movement\n editor.editing.mapper.on(\n \"viewToModelPosition\",\n viewToModelPositionOutsideModelElement(editor.model, (viewElement) => viewElement.hasClass(\"ck-math-widget\")),\n );\n\n // Keep a reference to the original get and set function.\n const { get, set } = editor.data;\n\n /**\n * Hack to transform $$latex$$ into in editor.getData()'s output.\n */\n editor.data.on(\n \"get\",\n (e) => {\n const output = e.return;\n const parsedResult = Parser.endParse(output);\n\n // Cleans all the semantics tag for safexml\n // including the handwritten data points\n e.return = MathML.removeSafeXMLSemantics(parsedResult);\n },\n { priority: \"low\" },\n );\n\n /**\n * Hack to transform with LaTeX into $$LaTeX$$ and formula images in editor.setData().\n */\n editor.data.on(\n \"set\",\n (e, args) => {\n // Retrieve the data to be set on the CKEditor.\n let modifiedData = args[0];\n // Regex to find all mathml formulas.\n const regexp = /(]*>)|()/gm;\n const formulas = [];\n let formula;\n\n // Both data.set from the source plugin and console command are taken into account as the data received is MathML or an image containing the MathML.\n while ((formula = regexp.exec(modifiedData)) !== null) {\n formulas.push(formula[0]);\n }\n\n // Loop to find LaTeX and formula images and replace the MathML for the both.\n formulas.forEach((formula) => {\n if (formula.includes('encoding=\"LaTeX\"')) {\n // LaTeX found.\n const latex = `$$$${Latex.getLatexFromMathML(formula)}$$$`; // We add $$$ instead of $$ because the replace function ignores one $.\n modifiedData = modifiedData.replace(formula, latex);\n } else if (formula.includes(\"