From ff07c5502244e22859be8bb4fb334dbc312b9c94 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Sun, 3 Dec 2017 22:02:54 +0100 Subject: [PATCH] more specific highlighting options for carea, par, line and inline, #3 --- dist/hocr.fullscreen.js | 2 +- dist/hocr.viewer.js | 2 +- src/browser/viewer.js | 7 ++++--- src/sass/hocr-viewer.scss | 38 ++++++++++++++++++++------------------ 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/dist/hocr.fullscreen.js b/dist/hocr.fullscreen.js index aea9714..cf9f502 100644 --- a/dist/hocr.fullscreen.js +++ b/dist/hocr.fullscreen.js @@ -1 +1 @@ -!function(e){function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}var t={};n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="",n(n.s=5)}([function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.HocrViewer=n.defaultConfig=void 0;var o=function(){function e(e,n){for(var t=0;tthis.config.debugLevel)){for(var t=arguments.length,o=Array(t>1?t-1:0),r=1;ri&&n[o]>e[o]&&(r-=n[o]-e[o],n.style.fontSize=r+"px");r>i&&n[t]>e[t];)r-=1,n.style.fontSize=r+"px";this.cache.scaleFont[e.textContent]=r}e.style.fontSize=this.cache.scaleFont[e.textContent]+"px"}}},{key:"toggleTooltips",value:function(e){var n=this,t=document.querySelector("#"+this.config.features.tooltips.styleId);if(e){var o={},r=!0,i=!1,a=void 0;try{for(var s,l=this.findByOcrClass()[Symbol.iterator]();!(r=(s=l.next()).done);r=!0){o[s.value.getAttribute("class")]=!0}}catch(e){i=!0,a=e}finally{try{!r&&l.return&&l.return()}finally{if(i)throw a}}this.log(0,"Detected OCR classes",Object.keys(o)),t||(t=document.createElement("style")).setAttribute("id",this.config.features.tooltips.styleId),t.appendChild(document.createTextNode(Object.keys(o).map(function(e){return"."+n.config.rootClass+" ."+e+':hover::before { content: "'+e+'"; }\n'}).join("\n"))),document.head.appendChild(t)}else t&&t.remove()}},{key:"toggleBackgroundImage",value:function(e){var n=this,t=this.root.querySelector(".ocr_page");e?this.findByOcrClass({title:"image"}).forEach(function(e){var o=n.parser.image(e);t.style.backgroundImage="url("+o+")"}):t.style.backgroundImage=""}},{key:"toggleContentEditable",value:function(e){var n=this,t=function(e){console.warn("Scaling of contentEditable is broken right now"),n.config.features.scaleFont.enabled&&(n.scaleFont(e.target),n.findByOcrClass({context:e.target}).forEach(function(e){n.scaleFont(e)}))};this.findByOcrClass({class:["line","x_word"],clauses:""}).forEach(function(n){e?(n.setAttribute("contentEditable","true"),n.addEventListener("input",t)):(n.removeAttribute("contentEditable"),n.removeEventListener("input",t))})}},{key:"toggleExpandToolbar",value:function(e){this.toolbar.classList.toggle("expanded",e)}},{key:"toggleFeature",value:function(e,n){this.root.classList.toggle("feature-"+e,n);var t="toggle"+e.substr(0,1).toUpperCase()+e.substring(1);t in this&&(this.log(0,"Calling this."+t),this[t](n))}},{key:"addToolbar",value:function(){var e=this;if(this.toolbar=document.querySelector("#"+this.config.toolbarId),!this.toolbar){this.toolbar=document.createElement("div"),this.toolbar.setAttribute("id",this.config.toolbarId),this.toolbar.classList.toggle("expanded",this.config.expandToolbar),document.body.appendChild(this.toolbar),this.toolbar.innerHTML="\n
\n
\n >
>
>
>
>
>
>
>
>
\n
\n
\n <
<
<
<
<
<
<
<
<
\n
\n
\n
\n

Font

\n \n

Features

\n
    \n
\n

Zoom

\n \n
",this.toolbar.querySelector(".toggler").addEventListener("click",function(n){e.config.expandToolbar=!e.config.expandToolbar,e.toggleExpandToolbar(e.config.expandToolbar)});var n=this.toolbar.querySelector("select.fontlist");console.log(n),Object.keys(this.config.fonts).forEach(function(e){var t=document.createElement("option");t.innerHTML=e,t.style.fontSize="large",t.style.fontFamily=e,n.appendChild(t)}),n.addEventListener("change",function(n){var t=n.target.options[n.target.selectedIndex].innerHTML;e.findByOcrClass().forEach(function(e){e.style.fontFamily=t}),e.onConfigChange()}),Object.keys(this.config.features).forEach(function(n){var t=document.createElement("li"),o=document.createElement("input"),r=document.createElement("label");t.appendChild(o),t.appendChild(r),e.toolbar.querySelector(".features").appendChild(t),r.innerHTML=n,o.setAttribute("type","checkbox"),o.checked=e.config.features[n].enabled,t.classList.toggle("checked",o.checked);t.addEventListener("click",function(r){o.checked=!o.checked,t.classList.toggle("checked"),e.config.features[n].enabled=o.checked,e.toggleFeature(n,o.checked)}),o.addEventListener("change",function(r){t.classList.toggle("checked",o.checked),e.config.features[n].enabled=o.checked,e.toggleFeature(n,o.checked)})});this.toolbar.querySelector(".zoom").addEventListener("input",function(n){var t=n.target.value/100,o=e.root.querySelector(".ocr_page");o.style.transform="scale("+t+")",o.style.transformOrigin="top left"})}}},{key:"onConfigChange",value:function(){var e=this;Object.keys(this.config.features).forEach(function(n){e.toggleFeature(n,e.config.features[n].enabled)})}},{key:"init",value:function(){var e=this;this.root.classList.add(this.config.rootClass),this.config.enableToolbar&&this.addToolbar(),this.placeOcrElements(),this.onConfigChange(),window.addEventListener("resize",function(){return e.onConfigChange()})}}]),e}()},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(e,n){for(var t=0;t=0&&b.splice(n,1)}function s(e){var n=document.createElement("style");return e.attrs.type="text/css",l(n,e.attrs),i(e,n),n}function l(e,n){Object.keys(n).forEach(function(t){e.setAttribute(t,n[t])})}function c(e,n){var t,o,r,c;if(n.transform&&e.css){if(!(c=n.transform(e.css)))return function(){};e.css=c}if(n.singleton){var f=p++;t=g||(g=s(n)),o=d.bind(null,t,f,!1),r=d.bind(null,t,f,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(t=function(e){var n=document.createElement("link");return e.attrs.type="text/css",e.attrs.rel="stylesheet",l(n,e.attrs),i(e,n),n}(n),o=function(e,n,t){var o=t.css,r=t.sourceMap,i=void 0===n.convertToAbsoluteUrls&&r;(n.convertToAbsoluteUrls||i)&&(o=m(o));r&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var a=new Blob([o],{type:"text/css"}),s=e.href;e.href=URL.createObjectURL(a),s&&URL.revokeObjectURL(s)}.bind(null,t,n),r=function(){a(t),t.href&&URL.revokeObjectURL(t.href)}):(t=s(n),o=function(e,n){var t=n.css,o=n.media;o&&e.setAttribute("media",o);if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}.bind(null,t),r=function(){a(t)});return o(e),function(n){if(n){if(n.css===e.css&&n.media===e.media&&n.sourceMap===e.sourceMap)return;o(e=n)}else r()}}function d(e,n,t,o){var r=t?"":o.css;if(e.styleSheet)e.styleSheet.cssText=v(n,r);else{var i=document.createTextNode(r),a=e.childNodes;a[n]&&e.removeChild(a[n]),a.length?e.insertBefore(i,a[n]):e.appendChild(i)}}var f={},u=function(e){var n;return function(){return void 0===n&&(n=e.apply(this,arguments)),n}}(function(){return window&&document&&document.all&&!window.atob}),h=function(e){var n={};return function(e){if(void 0===n[e]){var t=function(e){return document.querySelector(e)}.call(this,e);if(t instanceof window.HTMLIFrameElement)try{t=t.contentDocument.head}catch(e){t=null}n[e]=t}return n[e]}}(),g=null,p=0,b=[],m=t(8);e.exports=function(e,n){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(n=n||{}).attrs="object"==typeof n.attrs?n.attrs:{},n.singleton||(n.singleton=u()),n.insertInto||(n.insertInto="head"),n.insertAt||(n.insertAt="bottom");var t=r(e,n);return o(t,n),function(e){for(var i=[],a=0;athis.config.debugLevel)){for(var t=arguments.length,o=Array(t>1?t-1:0),r=1;ri&&n[o]>e[o]&&(r-=n[o]-e[o],n.style.fontSize=r+"px");r>i&&n[t]>e[t];)r-=1,n.style.fontSize=r+"px";this.cache.scaleFont[e.textContent]=r}e.style.fontSize=this.cache.scaleFont[e.textContent]+"px"}}},{key:"toggleTooltips",value:function(e){var n=this,t=document.querySelector("#"+this.config.features.tooltips.styleId);if(e){var o={},r=!0,i=!1,a=void 0;try{for(var s,l=this.findByOcrClass()[Symbol.iterator]();!(r=(s=l.next()).done);r=!0){o[s.value.getAttribute("class")]=!0}}catch(e){i=!0,a=e}finally{try{!r&&l.return&&l.return()}finally{if(i)throw a}}this.log(0,"Detected OCR classes",Object.keys(o)),t||(t=document.createElement("style")).setAttribute("id",this.config.features.tooltips.styleId),t.appendChild(document.createTextNode(Object.keys(o).map(function(e){return"."+n.config.rootClass+" ."+e+':hover::before { content: "'+e+'"; }\n'}).join("\n"))),document.head.appendChild(t)}else t&&t.remove()}},{key:"toggleBackgroundImage",value:function(e){var n=this,t=this.root.querySelector(".ocr_page");e?this.findByOcrClass({title:"image"}).forEach(function(e){var o=n.parser.image(e);t.style.backgroundImage="url("+o+")"}):t.style.backgroundImage=""}},{key:"toggleContentEditable",value:function(e){var n=this,t=function(e){console.warn("Scaling of contentEditable is broken right now"),n.config.features.scaleFont.enabled&&(n.scaleFont(e.target),n.findByOcrClass({context:e.target}).forEach(function(e){n.scaleFont(e)}))};this.findByOcrClass({class:["line","x_word"],clauses:""}).forEach(function(n){e?(n.setAttribute("contentEditable","true"),n.addEventListener("input",t)):(n.removeAttribute("contentEditable"),n.removeEventListener("input",t))})}},{key:"toggleExpandToolbar",value:function(e){this.toolbar.classList.toggle("expanded",e)}},{key:"toggleFeature",value:function(e,n){this.root.classList.toggle("feature-"+e,n);var t="toggle"+e.substr(0,1).toUpperCase()+e.substring(1);t in this&&(this.log(0,"Calling this."+t),this[t](n))}},{key:"addToolbar",value:function(){var e=this;if(this.toolbar=document.querySelector("#"+this.config.toolbarId),!this.toolbar){this.toolbar=document.createElement("div"),this.toolbar.setAttribute("id",this.config.toolbarId),this.toolbar.classList.toggle("expanded",this.config.expandToolbar),document.body.appendChild(this.toolbar),this.toolbar.innerHTML="\n
\n
\n >
>
>
>
>
>
>
>
>
\n
\n
\n <
<
<
<
<
<
<
<
<
\n
\n
\n
\n

Font

\n \n

Features

\n
    \n
\n

Zoom

\n \n
",this.toolbar.querySelector(".toggler").addEventListener("click",function(n){e.config.expandToolbar=!e.config.expandToolbar,e.toggleExpandToolbar(e.config.expandToolbar)});var n=this.toolbar.querySelector("select.fontlist");console.log(n),Object.keys(this.config.fonts).forEach(function(e){var t=document.createElement("option");t.innerHTML=e,t.style.fontSize="large",t.style.fontFamily=e,n.appendChild(t)}),n.addEventListener("change",function(n){var t=n.target.options[n.target.selectedIndex].innerHTML;e.findByOcrClass().forEach(function(e){e.style.fontFamily=t}),e.onConfigChange()}),Object.keys(this.config.features).forEach(function(n){var t=document.createElement("li"),o=document.createElement("input"),r=document.createElement("label");t.appendChild(o),t.appendChild(r),e.toolbar.querySelector(".features").appendChild(t),r.innerHTML=n,o.setAttribute("type","checkbox"),o.checked=e.config.features[n].enabled,t.classList.toggle("checked",o.checked);t.addEventListener("click",function(r){o.checked=!o.checked,t.classList.toggle("checked"),e.config.features[n].enabled=o.checked,e.toggleFeature(n,o.checked)}),o.addEventListener("change",function(r){t.classList.toggle("checked",o.checked),e.config.features[n].enabled=o.checked,e.toggleFeature(n,o.checked)})});this.toolbar.querySelector(".zoom").addEventListener("input",function(n){var t=n.target.value/100,o=e.root.querySelector(".ocr_page");o.style.transform="scale("+t+")",o.style.transformOrigin="top left"})}}},{key:"onConfigChange",value:function(){var e=this;Object.keys(this.config.features).forEach(function(n){e.toggleFeature(n,e.config.features[n].enabled)})}},{key:"init",value:function(){var e=this;this.root.classList.add(this.config.rootClass),this.config.enableToolbar&&this.addToolbar(),this.placeOcrElements(),this.onConfigChange(),window.addEventListener("resize",function(){return e.onConfigChange()})}}]),e}()},function(e,n,t){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(e,n){for(var t=0;t=0&&b.splice(n,1)}function s(e){var n=document.createElement("style");return e.attrs.type="text/css",l(n,e.attrs),i(e,n),n}function l(e,n){Object.keys(n).forEach(function(t){e.setAttribute(t,n[t])})}function c(e,n){var t,o,r,c;if(n.transform&&e.css){if(!(c=n.transform(e.css)))return function(){};e.css=c}if(n.singleton){var f=p++;t=g||(g=s(n)),o=d.bind(null,t,f,!1),r=d.bind(null,t,f,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(t=function(e){var n=document.createElement("link");return e.attrs.type="text/css",e.attrs.rel="stylesheet",l(n,e.attrs),i(e,n),n}(n),o=function(e,n,t){var o=t.css,r=t.sourceMap,i=void 0===n.convertToAbsoluteUrls&&r;(n.convertToAbsoluteUrls||i)&&(o=m(o));r&&(o+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(r))))+" */");var a=new Blob([o],{type:"text/css"}),s=e.href;e.href=URL.createObjectURL(a),s&&URL.revokeObjectURL(s)}.bind(null,t,n),r=function(){a(t),t.href&&URL.revokeObjectURL(t.href)}):(t=s(n),o=function(e,n){var t=n.css,o=n.media;o&&e.setAttribute("media",o);if(e.styleSheet)e.styleSheet.cssText=t;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(t))}}.bind(null,t),r=function(){a(t)});return o(e),function(n){if(n){if(n.css===e.css&&n.media===e.media&&n.sourceMap===e.sourceMap)return;o(e=n)}else r()}}function d(e,n,t,o){var r=t?"":o.css;if(e.styleSheet)e.styleSheet.cssText=v(n,r);else{var i=document.createTextNode(r),a=e.childNodes;a[n]&&e.removeChild(a[n]),a.length?e.insertBefore(i,a[n]):e.appendChild(i)}}var f={},u=function(e){var n;return function(){return void 0===n&&(n=e.apply(this,arguments)),n}}(function(){return window&&document&&document.all&&!window.atob}),h=function(e){var n={};return function(e){if(void 0===n[e]){var t=function(e){return document.querySelector(e)}.call(this,e);if(t instanceof window.HTMLIFrameElement)try{t=t.contentDocument.head}catch(e){t=null}n[e]=t}return n[e]}}(),g=null,p=0,b=[],m=t(8);e.exports=function(e,n){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(n=n||{}).attrs="object"==typeof n.attrs?n.attrs:{},n.singleton||(n.singleton=u()),n.insertInto||(n.insertInto="head"),n.insertAt||(n.insertAt="bottom");var t=r(e,n);return o(t,n),function(e){for(var i=[],a=0;athis.config.debugLevel)){for(var n=arguments.length,o=Array(n>1?n-1:0),r=1;ri&&t[o]>e[o]&&(r-=t[o]-e[o],t.style.fontSize=r+"px");r>i&&t[n]>e[n];)r-=1,t.style.fontSize=r+"px";this.cache.scaleFont[e.textContent]=r}e.style.fontSize=this.cache.scaleFont[e.textContent]+"px"}}},{key:"toggleTooltips",value:function(e){var t=this,n=document.querySelector("#"+this.config.features.tooltips.styleId);if(e){var o={},r=!0,i=!1,a=void 0;try{for(var s,l=this.findByOcrClass()[Symbol.iterator]();!(r=(s=l.next()).done);r=!0){o[s.value.getAttribute("class")]=!0}}catch(e){i=!0,a=e}finally{try{!r&&l.return&&l.return()}finally{if(i)throw a}}this.log(0,"Detected OCR classes",Object.keys(o)),n||(n=document.createElement("style")).setAttribute("id",this.config.features.tooltips.styleId),n.appendChild(document.createTextNode(Object.keys(o).map(function(e){return"."+t.config.rootClass+" ."+e+':hover::before { content: "'+e+'"; }\n'}).join("\n"))),document.head.appendChild(n)}else n&&n.remove()}},{key:"toggleBackgroundImage",value:function(e){var t=this,n=this.root.querySelector(".ocr_page");e?this.findByOcrClass({title:"image"}).forEach(function(e){var o=t.parser.image(e);n.style.backgroundImage="url("+o+")"}):n.style.backgroundImage=""}},{key:"toggleContentEditable",value:function(e){var t=this,n=function(e){console.warn("Scaling of contentEditable is broken right now"),t.config.features.scaleFont.enabled&&(t.scaleFont(e.target),t.findByOcrClass({context:e.target}).forEach(function(e){t.scaleFont(e)}))};this.findByOcrClass({class:["line","x_word"],clauses:""}).forEach(function(t){e?(t.setAttribute("contentEditable","true"),t.addEventListener("input",n)):(t.removeAttribute("contentEditable"),t.removeEventListener("input",n))})}},{key:"toggleExpandToolbar",value:function(e){this.toolbar.classList.toggle("expanded",e)}},{key:"toggleFeature",value:function(e,t){this.root.classList.toggle("feature-"+e,t);var n="toggle"+e.substr(0,1).toUpperCase()+e.substring(1);n in this&&(this.log(0,"Calling this."+n),this[n](t))}},{key:"addToolbar",value:function(){var e=this;if(this.toolbar=document.querySelector("#"+this.config.toolbarId),!this.toolbar){this.toolbar=document.createElement("div"),this.toolbar.setAttribute("id",this.config.toolbarId),this.toolbar.classList.toggle("expanded",this.config.expandToolbar),document.body.appendChild(this.toolbar),this.toolbar.innerHTML="\n
\n
\n >
>
>
>
>
>
>
>
>
\n
\n
\n <
<
<
<
<
<
<
<
<
\n
\n
\n
\n

Font

\n \n

Features

\n
    \n
\n

Zoom

\n \n
",this.toolbar.querySelector(".toggler").addEventListener("click",function(t){e.config.expandToolbar=!e.config.expandToolbar,e.toggleExpandToolbar(e.config.expandToolbar)});var t=this.toolbar.querySelector("select.fontlist");console.log(t),Object.keys(this.config.fonts).forEach(function(e){var n=document.createElement("option");n.innerHTML=e,n.style.fontSize="large",n.style.fontFamily=e,t.appendChild(n)}),t.addEventListener("change",function(t){var n=t.target.options[t.target.selectedIndex].innerHTML;e.findByOcrClass().forEach(function(e){e.style.fontFamily=n}),e.onConfigChange()}),Object.keys(this.config.features).forEach(function(t){var n=document.createElement("li"),o=document.createElement("input"),r=document.createElement("label");n.appendChild(o),n.appendChild(r),e.toolbar.querySelector(".features").appendChild(n),r.innerHTML=t,o.setAttribute("type","checkbox"),o.checked=e.config.features[t].enabled,n.classList.toggle("checked",o.checked);n.addEventListener("click",function(r){o.checked=!o.checked,n.classList.toggle("checked"),e.config.features[t].enabled=o.checked,e.toggleFeature(t,o.checked)}),o.addEventListener("change",function(r){n.classList.toggle("checked",o.checked),e.config.features[t].enabled=o.checked,e.toggleFeature(t,o.checked)})});this.toolbar.querySelector(".zoom").addEventListener("input",function(t){var n=t.target.value/100,o=e.root.querySelector(".ocr_page");o.style.transform="scale("+n+")",o.style.transformOrigin="top left"})}}},{key:"onConfigChange",value:function(){var e=this;Object.keys(this.config.features).forEach(function(t){e.toggleFeature(t,e.config.features[t].enabled)})}},{key:"init",value:function(){var e=this;this.root.classList.add(this.config.rootClass),this.config.enableToolbar&&this.addToolbar(),this.placeOcrElements(),this.onConfigChange(),window.addEventListener("resize",function(){return e.onConfigChange()})}}]),e}()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;nthis.config.debugLevel)){for(var n=arguments.length,o=Array(n>1?n-1:0),r=1;ri&&t[o]>e[o]&&(r-=t[o]-e[o],t.style.fontSize=r+"px");r>i&&t[n]>e[n];)r-=1,t.style.fontSize=r+"px";this.cache.scaleFont[e.textContent]=r}e.style.fontSize=this.cache.scaleFont[e.textContent]+"px"}}},{key:"toggleTooltips",value:function(e){var t=this,n=document.querySelector("#"+this.config.features.tooltips.styleId);if(e){var o={},r=!0,i=!1,a=void 0;try{for(var s,l=this.findByOcrClass()[Symbol.iterator]();!(r=(s=l.next()).done);r=!0){o[s.value.getAttribute("class")]=!0}}catch(e){i=!0,a=e}finally{try{!r&&l.return&&l.return()}finally{if(i)throw a}}this.log(0,"Detected OCR classes",Object.keys(o)),n||(n=document.createElement("style")).setAttribute("id",this.config.features.tooltips.styleId),n.appendChild(document.createTextNode(Object.keys(o).map(function(e){return"."+t.config.rootClass+" ."+e+':hover::before { content: "'+e+'"; }\n'}).join("\n"))),document.head.appendChild(n)}else n&&n.remove()}},{key:"toggleBackgroundImage",value:function(e){var t=this,n=this.root.querySelector(".ocr_page");e?this.findByOcrClass({title:"image"}).forEach(function(e){var o=t.parser.image(e);n.style.backgroundImage="url("+o+")"}):n.style.backgroundImage=""}},{key:"toggleContentEditable",value:function(e){var t=this,n=function(e){console.warn("Scaling of contentEditable is broken right now"),t.config.features.scaleFont.enabled&&(t.scaleFont(e.target),t.findByOcrClass({context:e.target}).forEach(function(e){t.scaleFont(e)}))};this.findByOcrClass({class:["line","x_word"],clauses:""}).forEach(function(t){e?(t.setAttribute("contentEditable","true"),t.addEventListener("input",n)):(t.removeAttribute("contentEditable"),t.removeEventListener("input",n))})}},{key:"toggleExpandToolbar",value:function(e){this.toolbar.classList.toggle("expanded",e)}},{key:"toggleFeature",value:function(e,t){this.root.classList.toggle("feature-"+e,t);var n="toggle"+e.substr(0,1).toUpperCase()+e.substring(1);n in this&&(this.log(0,"Calling this."+n),this[n](t))}},{key:"addToolbar",value:function(){var e=this;if(this.toolbar=document.querySelector("#"+this.config.toolbarId),!this.toolbar){this.toolbar=document.createElement("div"),this.toolbar.setAttribute("id",this.config.toolbarId),this.toolbar.classList.toggle("expanded",this.config.expandToolbar),document.body.appendChild(this.toolbar),this.toolbar.innerHTML="\n
\n
\n >
>
>
>
>
>
>
>
>
\n
\n
\n <
<
<
<
<
<
<
<
<
\n
\n
\n
\n

Font

\n \n

Features

\n
    \n
\n

Zoom

\n \n
",this.toolbar.querySelector(".toggler").addEventListener("click",function(t){e.config.expandToolbar=!e.config.expandToolbar,e.toggleExpandToolbar(e.config.expandToolbar)});var t=this.toolbar.querySelector("select.fontlist");console.log(t),Object.keys(this.config.fonts).forEach(function(e){var n=document.createElement("option");n.innerHTML=e,n.style.fontSize="large",n.style.fontFamily=e,t.appendChild(n)}),t.addEventListener("change",function(t){var n=t.target.options[t.target.selectedIndex].innerHTML;e.findByOcrClass().forEach(function(e){e.style.fontFamily=n}),e.onConfigChange()}),Object.keys(this.config.features).forEach(function(t){var n=document.createElement("li"),o=document.createElement("input"),r=document.createElement("label");n.appendChild(o),n.appendChild(r),e.toolbar.querySelector(".features").appendChild(n),r.innerHTML=t,o.setAttribute("type","checkbox"),o.checked=e.config.features[t].enabled,n.classList.toggle("checked",o.checked);n.addEventListener("click",function(r){o.checked=!o.checked,n.classList.toggle("checked"),e.config.features[t].enabled=o.checked,e.toggleFeature(t,o.checked)}),o.addEventListener("change",function(r){n.classList.toggle("checked",o.checked),e.config.features[t].enabled=o.checked,e.toggleFeature(t,o.checked)})});this.toolbar.querySelector(".zoom").addEventListener("input",function(t){var n=t.target.value/100,o=e.root.querySelector(".ocr_page");o.style.transform="scale("+n+")",o.style.transformOrigin="top left"})}}},{key:"onConfigChange",value:function(){var e=this;Object.keys(this.config.features).forEach(function(t){e.toggleFeature(t,e.config.features[t].enabled)})}},{key:"init",value:function(){var e=this;this.root.classList.add(this.config.rootClass),this.config.enableToolbar&&this.addToolbar(),this.placeOcrElements(),this.onConfigChange(),window.addEventListener("resize",function(){return e.onConfigChange()})}}]),e}()},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n