@internetarchive/bookreader 5.0.0-120 → 5.0.0-121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BookReader/ia-bookreader.js +1 -1
- package/BookReader/plugins/plugin.text_selection.js +1 -1
- package/BookReader/plugins/plugin.text_selection.js.map +1 -1
- package/BookReader/plugins/plugin.translate.js +1 -1
- package/BookReader/plugins/plugin.translate.js.map +1 -1
- package/dist/esm/ia-bookreader.js +1 -1
- package/dist/esm/plugins/plugin.text_selection.js +1 -1
- package/dist/esm/plugins/plugin.text_selection.js.map +1 -1
- package/dist/esm/plugins/plugin.translate.js +1 -1
- package/dist/esm/plugins/plugin.translate.js.map +1 -1
- package/package.json +1 -1
- package/src/plugins/plugin.text_selection.js +1 -1
- package/src/util/TextSelectionManager.js +15 -8
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{BatchTranslator as e}from"@internetarchive/bergamot-translator/translator.js";import{default as t}from"iso-language-codes";import"@internetarchive/icon-share";import"@internetarchive/icon-ellipses";export const __webpack_esm_ids__=[444];export const __webpack_esm_modules__={706:(e,t,n)=>{var r=n(350).PROPER,i=n(9039),o=n(7452);e.exports=function(e){return i(function(){return!!o[e]()||"
"!=="
"[e]()||r&&o[e].name!==e})}},3802:(e,t,n)=>{var r=n(9504),i=n(7750),o=n(655),a=n(7452),s=r("".replace),l=RegExp("^["+a+"]+"),c=RegExp("(^|[^"+a+"])["+a+"]+$"),d=function(e){return function(t){var n=o(i(t));return 1&e&&(n=s(n,l,"")),2&e&&(n=s(n,c,"$1")),n}};e.exports={start:d(1),end:d(2),Bq:d(3)}},7452:e=>{e.exports="\t\n\v\f\r \u2028\u2029\ufeff"},2762:(e,t,n)=>{var r=n(6518),i=n(3802).Bq;r({target:"String",proto:!0,forced:n(706)("trim")},{trim:function(){return i(this)}})},6869:(e,t,n)=>{n.d(t,{S:()=>r});class r{constructor(e){this.br=e,this.options}setup(e){this.options=Object.assign({},this.options,e)}init(){}_configurePageContainer(e){}_configureToolbar(e){}_bindNavigationHandlers(){}extendNavBar(e){}}},271:(t,n,r)=>{r.d(n,{L:()=>q,U:()=>F}),r(9463),r(3792),r(3362),r(7495),r(5440),r(2953);var i=r(7597),o=r(6869),a=r(6054),s=r(5369),l=r(9748);function c(e,t,n){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class d{constructor(){c(this,"alreadyTranslated",new s.l(100)),c(this,"modelRegistry",{}),c(this,"currentlyTranslating",{}),c(this,"fromLanguages",[]),c(this,"toLanguages",[]),c(this,"active",!1),c(this,"publicPath",""),c(this,"getTranslation",async(e,t,n,r,i,o)=>{if(this.active=!0,e==t||!e||!t)return;const a="".concat(e).concat(t,"-").concat(n,":").concat(r),s=this.alreadyTranslated.entries.find(e=>e.index==a);if(s)return s.response;if(a in this.currentlyTranslating)return this.currentlyTranslating[a].promise;let l=null,c=null;const d=new Promise((e,t)=>{l=e,c=t});return this.currentlyTranslating[a]={promise:d,resolve:l,reject:c},i?(this.translator.translate({to:t,from:e,text:i,html:!1,priority:o}).then(e=>{const t=e;this.currentlyTranslating[a].resolve(t.target.text),this.alreadyTranslated.add({index:a,response:t.target.text}),delete this.currentlyTranslating[a]}),d):(this.currentlyTranslating[a].reject("No text was provided"),d)}),c(this,"getTranslationModel",async(e,t)=>this.translator.backing.getTranslationModel({from:e,to:t}).catch(n=>{console.error("An error occurred while trying to retreive the ".concat(e,"-").concat(t," model"))}));const e={code:"en",name:"English (en)",type:"prod"};this.fromLanguages.push(e),this.toLanguages.push(e)}async initWorker(){if(this.initPromise)return this.initPromise;this.initPromise=new Promise((e,t)=>{this._initResolve=e,this._initReject=t});const t="https://cors.archive.org/cors/mozilla-translate-models/firefox_models/",n=await fetch(t+"registry.json").then(e=>e.json());for(const e of Object.values(n))for(const n of Object.values(e))n.name=t+n.name;this.translator=new e({registryUrl:"data:application/json,".concat(encodeURIComponent(JSON.stringify(n))),workers:2,batchSize:4,workerUrl:this.publicPath+"/translator-worker.js"});const r=await this.translator.backing.registry,i={};for(const e of Object.values(r)){const t=e.from,n=e.to,r=e.files;if(i["".concat(t).concat(n)]=r,"en"!==t){const e="".concat((0,l._4)(t)," (").concat((0,l.YH)(t),")");this.fromLanguages.push({code:t,name:e,type:"prod"})}if("en"!==n){const e="".concat((0,l._4)(n)," (").concat((0,l.YH)(n),")");this.toLanguages.push({code:n,name:e,type:"prod"})}}return this._initResolve([this.modelRegistry]),this.initPromise}}var u,h,p,g,f,m,y,v,b,w=r(9880),k=r(3991),E=(r(6376),r(1669));function x(){x=function(){return e};var e={elementsDefinitionOrder:[["method"],["field"]],initializeInstanceElements:function(e,t){["method","field"].forEach(function(n){t.forEach(function(t){t.kind===n&&"own"===t.placement&&this.defineClassElement(e,t)},this)},this)},initializeClassElements:function(e,t){var n=e.prototype;["method","field"].forEach(function(r){t.forEach(function(t){var i=t.placement;if(t.kind===r&&("static"===i||"prototype"===i)){var o="static"===i?e:n;this.defineClassElement(o,t)}},this)},this)},defineClassElement:function(e,t){var n=t.descriptor;if("field"===t.kind){var r=t.initializer;n={enumerable:n.enumerable,writable:n.writable,configurable:n.configurable,value:void 0===r?void 0:r.call(e)}}Object.defineProperty(e,t.key,n)},decorateClass:function(e,t){var n=[],r=[],i={static:[],prototype:[],own:[]};if(e.forEach(function(e){this.addElementPlacement(e,i)},this),e.forEach(function(e){if(!C(e))return n.push(e);var t=this.decorateElement(e,i);n.push(t.element),n.push.apply(n,t.extras),r.push.apply(r,t.finishers)},this),!t)return{elements:n,finishers:r};var o=this.decorateConstructor(n,t);return r.push.apply(r,o.finishers),o.finishers=r,o},addElementPlacement:function(e,t,n){var r=t[e.placement];if(!n&&-1!==r.indexOf(e.key))throw new TypeError("Duplicated element ("+e.key+")");r.push(e.key)},decorateElement:function(e,t){for(var n=[],r=[],i=e.decorators,o=i.length-1;o>=0;o--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,i[o])(s)||s);e=l.element,this.addElementPlacement(e,t),l.finisher&&r.push(l.finisher);var c=l.extras;if(c){for(var d=0;d<c.length;d++)this.addElementPlacement(c[d],t);n.push.apply(n,c)}}return{element:e,finishers:r,extras:n}},decorateConstructor:function(e,t){for(var n=[],r=t.length-1;r>=0;r--){var i=this.fromClassDescriptor(e),o=this.toClassDescriptor((0,t[r])(i)||i);if(void 0!==o.finisher&&n.push(o.finisher),void 0!==o.elements){e=o.elements;for(var a=0;a<e.length-1;a++)for(var s=a+1;s<e.length;s++)if(e[a].key===e[s].key&&e[a].placement===e[s].placement)throw new TypeError("Duplicated element ("+e[a].key+")")}}return{elements:e,finishers:n}},fromElementDescriptor:function(e){var t={kind:e.kind,key:e.key,placement:e.placement,descriptor:e.descriptor};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),"field"===e.kind&&(t.initializer=e.initializer),t},toElementDescriptors:function(e){if(void 0!==e)return(t=e,function(e){if(Array.isArray(e))return e}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return R(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?R(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map(function(e){var t=this.toElementDescriptor(e);return this.disallowProperty(e,"finisher","An element descriptor"),this.disallowProperty(e,"extras","An element descriptor"),t},this);var t},toElementDescriptor:function(e){var t=e.kind+"";if("method"!==t&&"field"!==t)throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "'+t+'"');var n=N(e.key),r=e.placement+"";if("static"!==r&&"prototype"!==r&&"own"!==r)throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "'+r+'"');var i=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var o={kind:t,key:n,placement:r,descriptor:Object.assign({},i)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(i,"get","The property descriptor of a field descriptor"),this.disallowProperty(i,"set","The property descriptor of a field descriptor"),this.disallowProperty(i,"value","The property descriptor of a field descriptor"),o.initializer=e.initializer),o},toElementFinisherExtras:function(e){return{element:this.toElementDescriptor(e),finisher:_(e,"finisher"),extras:this.toElementDescriptors(e.extras)}},fromClassDescriptor:function(e){var t={kind:"class",elements:e.map(this.fromElementDescriptor,this)};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),t},toClassDescriptor:function(e){var t=e.kind+"";if("class"!==t)throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "'+t+'"');this.disallowProperty(e,"key","A class descriptor"),this.disallowProperty(e,"placement","A class descriptor"),this.disallowProperty(e,"descriptor","A class descriptor"),this.disallowProperty(e,"initializer","A class descriptor"),this.disallowProperty(e,"extras","A class descriptor");var n=_(e,"finisher");return{elements:this.toElementDescriptors(e.elements),finisher:n}},runClassFinishers:function(e,t){for(var n=0;n<t.length;n++){var r=(0,t[n])(e);if(void 0!==r){if("function"!=typeof r)throw new TypeError("Finishers must return a constructor.");e=r}}return e},disallowProperty:function(e,t,n){if(void 0!==e[t])throw new TypeError(n+" can't have a ."+t+" property.")}};return e}function T(e){var t,n=N(e.key);"method"===e.kind?t={value:e.value,writable:!0,configurable:!0,enumerable:!1}:"get"===e.kind?t={get:e.value,configurable:!0,enumerable:!1}:"set"===e.kind?t={set:e.value,configurable:!0,enumerable:!1}:"field"===e.kind&&(t={configurable:!0,writable:!0,enumerable:!0});var r={kind:"field"===e.kind?"field":"method",key:n,placement:e.static?"static":"field"===e.kind?"own":"prototype",descriptor:t};return e.decorators&&(r.decorators=e.decorators),"field"===e.kind&&(r.initializer=e.value),r}function S(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function C(e){return e.decorators&&e.decorators.length}function L(e){return void 0!==e&&!(void 0===e.value&&void 0===e.writable)}function _(e,t){var n=e[t];if(void 0!==n&&"function"!=typeof n)throw new TypeError("Expected '"+t+"' to be a function");return n}function R(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function P(){return P="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=A(e)););return e}(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},P.apply(null,arguments)}function A(e){return A=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},A(e)}function M(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function O(e,t,n){return(t=N(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}const D=window.BookReader;class F extends o.S{constructor(){super(...arguments),O(this,"options",{enabled:!0,panelDisclaimerText:"Translations are in alpha"}),O(this,"translationManager",new d),O(this,"worker",void 0),O(this,"toLanguages",[]),O(this,"langFromCode",void 0),O(this,"langToCode",void 0),O(this,"_panel",void 0),O(this,"userToggleTranslate",void 0),O(this,"loadingModel",!0),O(this,"textSelectionManager",new k.bg(".BRtranslateLayer",this.br,{selectionElement:[".BRlineElement"]},1)),O(this,"getParagraphsOnPage",e=>e?Array.from(e.querySelectorAll(".BRtextLayer > .BRparagraphElement")):[]),O(this,"handleFromLangChange",async e=>{this.clearAllTranslations();const t=e.detail.value;this.langFromCode=t,this._panel.requestUpdate(),this.translationManager.toLanguages.some(e=>e.code===t)||this.translationManager.toLanguages.push({code:t,name:this.translationManager.fromLanguages.find(e=>e.code==t).name}),this._panel.toLanguages=this.translationManager.toLanguages,console.log(this.langFromCode,this.langToCode),this._render(),this.langFromCode!==this.langToCode&&this.translateActivePageContainerElements()}),O(this,"handleToLangChange",async e=>{this.clearAllTranslations(),this.langToCode=e.detail.value,this._render(),this.translateActivePageContainerElements()}),O(this,"handleToggleTranslation",async()=>{if(!this.userToggleTranslate&&!this.isSourceLanguageSupported())return this.userToggleTranslate=!1,this.translationManager.active=!1,void this._render();this.userToggleTranslate=!this.userToggleTranslate,this.translationManager.active=this.userToggleTranslate,this._render(),this.userToggleTranslate?(this.br.trigger("translationEnabled",{}),this.translateActivePageContainerElements(),this.textSelectionManager.attach()):(this.clearAllTranslations(),this.br.trigger("translationDisabled",{}),this.textSelectionManager.detach())})}async init(){if(!this.options.enabled)return;const e=this.br.options.bookLanguage||"",t=(0,l.YH)(e);this.langFromCode=null!=t?t:"en",this.textSelectionManager.init(),this.translationManager.publicPath=this.br.options.imagesBaseURL.replace(/\/+$/,"")+"/..",this.br.on("textLayerRendered",async(e,t)=>{t.pageIndex;let n=t.pageContainer;if(this.translationManager&&this.translationManager.active){const e=n.$container[0];this.translateRenderedLayer(e)}}),this.br.on("pageVisible",(e,t)=>{let n=t.pageContainerEl;if(this.translationManager.active)for(const e of n.querySelectorAll(".BRtranslateLayer > .BRparagraphElement"))e.textContent&&this.fitVisiblePage(e)}),await this.translationManager.initWorker(),this.langToCode=this.translationManager.toLanguages[0].code,this._render()}translateActivePageContainerElements(){const e=this.br.getActivePageContainerElements(),t=e.filter(e=>e.classList.contains("BRpage-visible")),n=e.filter(e=>!e.classList.contains("BRpage-visible"));for(const e of t)this.translateRenderedLayer(e,0);for(const e of n)this.translateRenderedLayer(e,1e3)}async translateRenderedLayer(e,t){var n;if(this.br.mode==this.br.constModeThumb||!this.userToggleTranslate||this.langFromCode==this.langToCode)return;const r=e.dataset.index;let i;e.querySelector(".BRPageLayer.BRtranslateLayer")?i=e.querySelector(".BRPageLayer.BRtranslateLayer"):(i=document.createElement("div"),i.classList.add("BRPageLayer","BRtranslateLayer","BRtranslateLayerLoading"),i.setAttribute("lang","".concat(this.langToCode)),e.prepend(i));const o=e.querySelector(".BRtextLayer");E(i).css({width:o.style.width,height:o.style.height,transform:o.style.transform,"pointer-events":o.style.pointerEvents,"z-index":3}),o.classList.add("showingTranslation");const a=this.getParagraphsOnPage(e),s=a.map(async(n,o)=>{let s=e.querySelector("[data-translate-index='".concat(r,"-").concat(o,"']"));if(!s){s=document.createElement("p"),s.setAttribute("data-translate-index","".concat(r,"-").concat(o)),s.className="BRparagraphElement";const e=a[o];n.classList.contains("ocr-role-header-footer")&&(s.ariaHidden="true",s.classList.add("ocr-role-header-footer"));const t="".concat(parseInt(E(e).css("font-size")),"px");E(s).css({"margin-left":E(e).css("margin-left"),"margin-top":E(e).css("margin-top"),top:E(e).css("top"),height:E(e).css("height"),width:E(e).css("width"),"font-size":t}),i.append(s)}if(0!==n.textContent.length){var l,c;const i=parseFloat(r)+t+o;this.translationManager.getTranslationModel(this.langFromCode,this.langToCode).then(()=>{this._panel.loadingModel=!1,this.loadingModel=!1});const d=await this.translationManager.getTranslation(this.langFromCode,this.langToCode,r,o,n.textContent,i);null===(l=s.firstElementChild)||void 0===l||l.remove();const u=null===(c=a[o])||void 0===c||null===(c=c.firstChild)||void 0===c?void 0:c.firstChild,h=document.createElement("span");h.className="BRlineElement",h.textContent=d,s.appendChild(h),E(h).css({"text-indent":E(u).css("padding-left")}),e.classList.contains("BRpage-visible")&&this.fitVisiblePage(s)}});null===(n=this.textSelectionManager)||void 0===n||n.stopPageFlip(this.br.refs.$brContainer),await Promise.all(s),this.br.trigger("translateLayerRendered",{leafIndex:r,translateLayer:i})}async getTranslateLayers(e){const t=this.br.getActivePageContainerElementsForIndex(e),n=E(t).filter("[data-index='".concat(e,"']")).find(".BRtranslateLayer");return n.length?n.toArray():new Promise((t,n)=>{const r=async(n,i)=>{i.leafIndex==e&&(this.br.off("translateLayerRendered",r),t([i.translateLayer]))};this.br.on("translateLayerRendered",r)})}clearAllTranslations(){const e=this.br.refs.$br[0];e.querySelectorAll(".BRtranslateLayer").forEach(e=>e.remove()),e.querySelectorAll(".showingTranslation").forEach(e=>e.classList.remove("showingTranslation"))}fitVisiblePage(e){let t=parseInt(E(e).css("font-size"));for(;e.clientHeight<e.scrollHeight&&t>0;)t--,E(e).css({"font-size":"".concat(t,"px")});const n=e.firstElementChild.clientHeight,r=e.scrollHeight;if(n<r){const i=r/(n/t);E(e).css({"line-height":"".concat(i,"px"),overflow:"visible"})}}isSourceLanguageSupported(){return this.translationManager.fromLanguages.some(e=>e.code==this.langFromCode)}_render(){this.br.shell.menuProviders.translate={id:"translate",icon:(0,i.qy)(u||(u=M(["<img src='",'/translate.svg\' width="26"/>'])),this.br.options.imagesBaseURL),label:"Translate",component:(0,i.qy)(h||(h=M(['<br-translate-panel\n @connected="','"\n @langFromChanged="','"\n @langToChanged="','"\n @toggleTranslation="','"\n .fromLanguages="','"\n .toLanguages="','"\n .disclaimerMessage="','"\n .userTranslationActive=',"\n .detectedFromLang=","\n .detectedToLang=","\n .loadingModel=","\n .sourceLanguageSupported=",'\n class="translate-panel"\n />'])),e=>{this._panel=e.target,this._panel.fromLanguages=this.translationManager.fromLanguages,this._panel.toLanguages=this.translationManager.toLanguages,this._panel.userTranslationActive=this.userToggleTranslate,this._panel.detectedToLang=this.langToCode,this._panel.detectedFromLang=this.langFromCode,this._panel.loadingModel=this.loadingModel,this._panel.sourceLanguageSupported=this.isSourceLanguageSupported()},this.handleFromLangChange,this.handleToLangChange,this.handleToggleTranslation,this.translationManager.fromLanguages,this.translationManager.toLanguages,this.options.panelDisclaimerText,this.userToggleTranslate,this.langFromCode,this.langToCode,this.loadingModel,this.isSourceLanguageSupported())},this.br.shell.updateMenuContents()}}null==D||D.registerPlugin("translate",F);let q=(I=[(0,a.EM)("br-translate-panel")],B=i.WF,j=x(),H=function(e,t){class n extends t{constructor(){super(...arguments),e(this)}}return{F:n,d:[{kind:"field",decorators:[(0,a.MZ)({type:Array})],key:"fromLanguages",value:()=>[]},{kind:"field",decorators:[(0,a.MZ)({type:Array})],key:"toLanguages",value:()=>[]},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"prevSelectedLang",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"disclaimerMessage",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:Boolean})],key:"userTranslationActive",value:()=>!1},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"detectedFromLang",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"detectedToLang",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:Boolean})],key:"loadingModel",value:void 0},{kind:"field",decorators:[(0,a.MZ)({type:Boolean})],key:"sourceLanguageSupported",value:()=>!0},{kind:"field",decorators:[(0,a.P)("#lang-from")],key:"langFromDropdown",value:void 0},{kind:"field",decorators:[(0,a.P)("#lang-to")],key:"langToDropdown",value:void 0},{kind:"field",static:!0,key:"styles",value:()=>(0,i.AH)(p||(p=M(["\n .disclaimer {\n padding: 10px;\n border-radius: 8px;\n font-size: 12px;\n margin: 0 0 10px;\n background-color: rgba(255, 255, 255, 0.1);\n color: rgba(255, 255, 255, 0.9);\n }\n\n .disclaimer--warning {\n margin: 10px 0;\n background-color: rgba(255, 186, 8, 0.18);\n color: #ffe7a3;\n }\n "])))},{kind:"method",key:"connectedCallback",value:function(){var e,t,r,i,o;(e=n,t="connectedCallback",r=this,o=P(A(1&(i=3)?e.prototype:e),t,r),2&i&&"function"==typeof o?function(e){return o.apply(r,e)}:o)([]),this.dispatchEvent(new CustomEvent("connected"))}},{kind:"method",key:"render",value:function(){const e=this._statusWarning();return(0,i.qy)(g||(g=M(['<div class="app" style="margin-top: 5%;padding-right: 5px;">\n <div\n class="disclaimer"\n id="disclaimerMessage"\n >','</div>\n\n <div class="panel panel--to" style="padding: 0 10px;">\n <label>\n <span style="font-size: 12px;color: #ccc;">Translate To</span>\n <select id="lang-to" name="to" class="lang-select" style="display:block; width:100%;" @change="','">\n ','\n </select>\n </label>\n </div>\n\n <div class="panel panel--start" style="text-align: right;padding: 0 10px;/*! font-size: 18px; */margin-top: 10px;">\n <button class="start-translation-brn" @click="','" ?disabled=',">\n ",'\n </button>\n </div>\n\n <div class="panel panel--from" style="font-size: 12px;color: #ccc;text-align: center;padding: 8px 10px;">\n <details style="display: contents">\n <summary style="text-decoration: underline white; cursor:pointer; display:inline-block"> \n <i>\n Source: '," ",' \n </i> Change \n </summary>\n <select id="lang-from" name="from" class="lang-select" value=',' @change="','" style="width:65%; margin-top: 3%; margin-bottom: 3%">\n ','\n </select>\n </details>\n </div>\n <div class="footer" id="status" style="margin-top:5%">\n ','\n </div>\n\n <div class="lang-models-loading"> \n ',"\n </div>\n </div>"])),this.disclaimerMessage,this._onLangToChange,(0,w.Ul)(this.toLanguages,e=>e.name.toLowerCase()).map(e=>(0,i.qy)(f||(f=M(['<option value="','" \n ?selected=',"\n > "," </option>"])),e.code,e.code==this.detectedToLang,e.name?e.name:e.code)),this._toggleTranslation,!this.sourceLanguageSupported,this.userTranslationActive?"Stop Translating":"Translate",this._getLangName(this.detectedFromLang),this.prevSelectedLang?"":"(detected)",this.detectedFromLang,this._onLangFromChange,(0,w.Ul)(this.fromLanguages,e=>e.name.toLowerCase()).map(e=>(0,i.qy)(m||(m=M(['<option value="','"\n ?selected=',"\n >"," </option>"])),e.code,e.code==this.detectedFromLang,e.name?e.name:e.code)),e?(0,i.qy)(y||(y=M(['\n <div class="disclaimer disclaimer--warning">',"</div>\n "])),e):"",this._languageModelStatus())}},{kind:"method",key:"_onLangFromChange",value:function(e){const t=new CustomEvent("langFromChanged",{detail:{value:e.target.value},bubbles:!0,composed:!0});this.dispatchEvent(t),this._getSelectedLang("to")!==this._getSelectedLang("from")&&(this.prevSelectedLang=this._getSelectedLang("from")),this.loadingModel=!0,this.detectedFromLang=e.target.value}},{kind:"method",key:"_onLangToChange",value:function(e){const t=new CustomEvent("langToChanged",{detail:{value:e.target.value},bubbles:!0,composed:!0});this.dispatchEvent(t),this._getSelectedLang("from")!==e.target.value&&(this.prevSelectedLang=this._getSelectedLang("from")),this.loadingModel=!0,this.detectedToLang=e.target.value}},{kind:"method",key:"_getSelectedLang",value:function(e){const t="from"===e?this.langFromDropdown:this.langToDropdown;return t?t.value:""}},{kind:"method",key:"_getLangName",value:function(e){const t=[...this.fromLanguages,...this.toLanguages].find(t=>t.code===e);return(null==t?void 0:t.name)||(0,l._4)(e)||e}},{kind:"method",key:"_toggleTranslation",value:function(e){if(!this.sourceLanguageSupported)return;const t=new CustomEvent("toggleTranslation",{detail:{value:e.target.value},bubbles:!0,composed:!0});this.userTranslationActive=!this.userTranslationActive,this.dispatchEvent(t)}},{kind:"method",key:"_statusWarning",value:function(){return this.sourceLanguageSupported?this.detectedFromLang==this.detectedToLang?"Translate To language is the same as the Source language":"":"Translating from ".concat(this._getLangName(this.detectedFromLang)," is not supported")}},{kind:"method",key:"_languageModelStatus",value:function(){return this.userTranslationActive?this.loadingModel?(0,i.qy)(v||(v=M(['\n <ia-activity-indicator mode="processing" style="display:block; width: 40px; height: 40px; margin: 0 auto;"></ia-activity-indicator>\n <p>Downloading language model</p>\n ']))):(0,i.qy)(b||(b=M(["<p>Language model loaded</p>"]))):""}}]}}(function(e){j.initializeInstanceElements(e,z.elements)},B),z=j.decorateClass(function(e){for(var t=[],n=function(e){return"method"===e.kind&&e.key===o.key&&e.placement===o.placement},r=0;r<e.length;r++){var i,o=e[r];if("method"===o.kind&&(i=t.find(n)))if(L(o.descriptor)||L(i.descriptor)){if(C(o)||C(i))throw new ReferenceError("Duplicated methods ("+o.key+") can't be decorated.");i.descriptor=o.descriptor}else{if(C(o)){if(C(i))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+o.key+").");i.decorators=o.decorators}S(o,i)}else t.push(o)}return t}(H.d.map(T)),I),j.initializeClassElements(H.F,z.elements),j.runClassFinishers(H.F,z.finishers));var I,B,j,H,z},9748:(e,n,r)=>{r.d(n,{$x:()=>c,ND:()=>l,YH:()=>o,_4:()=>a}),r(4423),r(3792),r(3362),r(2953);const i={"zh-hans":"中文 (Zhōngwén)"};function o(e){if(!e)return null;if(e=e.toLocaleLowerCase(),i[e])return e;const t=s(e,["iso639_1"])||s(e,["iso639_2T"])||s(e,["iso639_2B","name","nativeName"]);return t?t.iso639_1:null}function a(e){if(!e)return null;if(e=e.toLocaleLowerCase(),i[e])return i[e];const t=s(e,["iso639_1"])||s(e,["iso639_2T"])||s(e,["iso639_2B","name","nativeName"]);return null!=t&&t.nativeName?t.nativeName.split(", ")[0]:null}function s(e,n){if(!e)return null;e=e.toLowerCase();for(const i of t)for(const t of n){var r;if(null!==(r=i[t])&&void 0!==r&&r.toLowerCase().split(", ").includes(e))return i}return null}function l(){try{return!!window.localStorage}catch(e){return!1}}const c=-1!=location.toString().indexOf("_debugReadAloud=true")},3991:(e,t,n)=>{n.d(t,{yc:()=>ce,bg:()=>X,lB:()=>ae});var r=n.cw(function(e,t){var r=n(3724),i=n(2106),o=n(5213),a=n(7979);r&&!o.correct&&(i(RegExp.prototype,"flags",{configurable:!0,get:a}),o.correct=!0)}),i=n.cw(function(e,t){var r=n(6518),i=n(9565),o=n(7476),a=n(3994),s=n(2529),l=n(7750),c=n(8014),d=n(655),u=n(8551),h=n(34),p=n(2195),g=n(788),f=n(1034),m=n(5966),y=n(6840),v=n(9039),b=n(8227),w=n(2293),k=n(7829),E=n(6682),x=n(1181),T=n(6395),S=b("matchAll"),C="RegExp String",L=C+" Iterator",_=x.set,R=x.getterFor(L),P=RegExp.prototype,A=TypeError,M=o("".indexOf),O=o("".matchAll),N=!!O&&!v(function(){O("a",/./)}),D=a(function(e,t,n,r){_(this,{type:L,regexp:e,string:t,global:n,unicode:r,done:!1})},C,function(){var e=R(this);if(e.done)return s(void 0,!0);var t=e.regexp,n=e.string,r=E(t,n);return null===r?(e.done=!0,s(void 0,!0)):e.global?(""===d(r[0])&&(t.lastIndex=k(n,c(t.lastIndex),e.unicode)),s(r,!1)):(e.done=!0,s(r,!1))}),F=function(e){var t,n,r,i=u(this),o=d(e),a=w(i,RegExp),s=d(f(i));return t=new a(a===RegExp?i.source:i,s),n=!!~M(s,"g"),r=!!~M(s,"u")||!!~M(s,"v"),t.lastIndex=c(i.lastIndex),new D(t,o,n,r)};r({target:"String",proto:!0,forced:N},{matchAll:function(e){var t,n,r,o,a=l(this);if(h(e)){if(g(e)&&(t=d(l(f(e))),!~M(t,"g")))throw new A("`.matchAll` does not allow non-global regexes");if(N)return O(a,e);if(void 0===(r=m(e,S))&&T&&"RegExp"===p(e)&&(r=F),r)return i(r,e,a)}else if(N)return O(a,e);return n=d(a),o=new RegExp(e,"g"),T?i(F,o,n):o[S](n)}}),T||S in P||y(P,S,F)}),o=n.cw(function(e,t){i()});n(4423),n(9463),n(3792),n(3362),n(4864),n(7495),r(),n(5440),n(2762),o(),n(2953),n(8408);var a=n(8965),s=n(1669);function l(e,t,n){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class c{constructor(e,t){l(this,"selecting",!1),l(this,"startedInSelector",!1),l(this,"target",null),l(this,"lastKnownFocusNode",null),l(this,"_onSelectionChange",()=>{const e=window.getSelection();if(!e)return;const t=function(e){if(!e.isCollapsed)return!1;for(let t=0;t<e.rangeCount;t++)if(!e.getRangeAt(t).collapsed)return!1;return!0}(e);if(!this.selecting&&e.toString()){const t=s(e.anchorNode).closest(this.selector)[0];if(!t)return;this.target=t,this.selecting=!0,this.lastKnownFocusNode=e.focusNode,this.handler("started",this.target)}this.selecting&&this.lastKnownFocusNode!=e.focusNode&&e.toString()&&!t&&(this.lastKnownFocusNode=e.focusNode,this.handler("changed",this.target)),!this.selecting||!t&&e.toString()&&s(e.anchorNode).closest(this.selector)[0]||(this.selecting=!1,this.lastKnownFocusNode=null,this.handler("cleared",this.target))}),this.selector=e,this.handler=t}attach(){document.addEventListener("selectionchange",this._onSelectionChange)}detach(){document.removeEventListener("selectionchange",this._onSelectionChange)}}var d,u,h,p,g,f,m,y,v,b,w,k,E,x,T,S,C,L=n(9880),_=n(7597),R=n(6054),P=n(6248),A=(n(790),n(395)),M=n(4297),O=n(1669);function N(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function D(e,t,n,r){var i=F();if(r)for(var o=0;o<r.length;o++)i=r[o](i);var a=t(function(e){i.initializeInstanceElements(e,s.elements)},n),s=i.decorateClass(function(e){for(var t=[],n=function(e){return"method"===e.kind&&e.key===o.key&&e.placement===o.placement},r=0;r<e.length;r++){var i,o=e[r];if("method"===o.kind&&(i=t.find(n)))if(j(o.descriptor)||j(i.descriptor)){if(B(o)||B(i))throw new ReferenceError("Duplicated methods ("+o.key+") can't be decorated.");i.descriptor=o.descriptor}else{if(B(o)){if(B(i))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+o.key+").");i.decorators=o.decorators}I(o,i)}else t.push(o)}return t}(a.d.map(q)),e);return i.initializeClassElements(a.F,s.elements),i.runClassFinishers(a.F,s.finishers)}function F(){F=function(){return e};var e={elementsDefinitionOrder:[["method"],["field"]],initializeInstanceElements:function(e,t){["method","field"].forEach(function(n){t.forEach(function(t){t.kind===n&&"own"===t.placement&&this.defineClassElement(e,t)},this)},this)},initializeClassElements:function(e,t){var n=e.prototype;["method","field"].forEach(function(r){t.forEach(function(t){var i=t.placement;if(t.kind===r&&("static"===i||"prototype"===i)){var o="static"===i?e:n;this.defineClassElement(o,t)}},this)},this)},defineClassElement:function(e,t){var n=t.descriptor;if("field"===t.kind){var r=t.initializer;n={enumerable:n.enumerable,writable:n.writable,configurable:n.configurable,value:void 0===r?void 0:r.call(e)}}Object.defineProperty(e,t.key,n)},decorateClass:function(e,t){var n=[],r=[],i={static:[],prototype:[],own:[]};if(e.forEach(function(e){this.addElementPlacement(e,i)},this),e.forEach(function(e){if(!B(e))return n.push(e);var t=this.decorateElement(e,i);n.push(t.element),n.push.apply(n,t.extras),r.push.apply(r,t.finishers)},this),!t)return{elements:n,finishers:r};var o=this.decorateConstructor(n,t);return r.push.apply(r,o.finishers),o.finishers=r,o},addElementPlacement:function(e,t,n){var r=t[e.placement];if(!n&&-1!==r.indexOf(e.key))throw new TypeError("Duplicated element ("+e.key+")");r.push(e.key)},decorateElement:function(e,t){for(var n=[],r=[],i=e.decorators,o=i.length-1;o>=0;o--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,i[o])(s)||s);e=l.element,this.addElementPlacement(e,t),l.finisher&&r.push(l.finisher);var c=l.extras;if(c){for(var d=0;d<c.length;d++)this.addElementPlacement(c[d],t);n.push.apply(n,c)}}return{element:e,finishers:r,extras:n}},decorateConstructor:function(e,t){for(var n=[],r=t.length-1;r>=0;r--){var i=this.fromClassDescriptor(e),o=this.toClassDescriptor((0,t[r])(i)||i);if(void 0!==o.finisher&&n.push(o.finisher),void 0!==o.elements){e=o.elements;for(var a=0;a<e.length-1;a++)for(var s=a+1;s<e.length;s++)if(e[a].key===e[s].key&&e[a].placement===e[s].placement)throw new TypeError("Duplicated element ("+e[a].key+")")}}return{elements:e,finishers:n}},fromElementDescriptor:function(e){var t={kind:e.kind,key:e.key,placement:e.placement,descriptor:e.descriptor};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),"field"===e.kind&&(t.initializer=e.initializer),t},toElementDescriptors:function(e){if(void 0!==e)return(t=e,function(e){if(Array.isArray(e))return e}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return z(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?z(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map(function(e){var t=this.toElementDescriptor(e);return this.disallowProperty(e,"finisher","An element descriptor"),this.disallowProperty(e,"extras","An element descriptor"),t},this);var t},toElementDescriptor:function(e){var t=e.kind+"";if("method"!==t&&"field"!==t)throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "'+t+'"');var n=J(e.key),r=e.placement+"";if("static"!==r&&"prototype"!==r&&"own"!==r)throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "'+r+'"');var i=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var o={kind:t,key:n,placement:r,descriptor:Object.assign({},i)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(i,"get","The property descriptor of a field descriptor"),this.disallowProperty(i,"set","The property descriptor of a field descriptor"),this.disallowProperty(i,"value","The property descriptor of a field descriptor"),o.initializer=e.initializer),o},toElementFinisherExtras:function(e){return{element:this.toElementDescriptor(e),finisher:H(e,"finisher"),extras:this.toElementDescriptors(e.extras)}},fromClassDescriptor:function(e){var t={kind:"class",elements:e.map(this.fromElementDescriptor,this)};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),t},toClassDescriptor:function(e){var t=e.kind+"";if("class"!==t)throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "'+t+'"');this.disallowProperty(e,"key","A class descriptor"),this.disallowProperty(e,"placement","A class descriptor"),this.disallowProperty(e,"descriptor","A class descriptor"),this.disallowProperty(e,"initializer","A class descriptor"),this.disallowProperty(e,"extras","A class descriptor");var n=H(e,"finisher");return{elements:this.toElementDescriptors(e.elements),finisher:n}},runClassFinishers:function(e,t){for(var n=0;n<t.length;n++){var r=(0,t[n])(e);if(void 0!==r){if("function"!=typeof r)throw new TypeError("Finishers must return a constructor.");e=r}}return e},disallowProperty:function(e,t,n){if(void 0!==e[t])throw new TypeError(n+" can't have a ."+t+" property.")}};return e}function q(e){var t,n=J(e.key);"method"===e.kind?t={value:e.value,writable:!0,configurable:!0,enumerable:!1}:"get"===e.kind?t={get:e.value,configurable:!0,enumerable:!1}:"set"===e.kind?t={set:e.value,configurable:!0,enumerable:!1}:"field"===e.kind&&(t={configurable:!0,writable:!0,enumerable:!0});var r={kind:"field"===e.kind?"field":"method",key:n,placement:e.static?"static":"field"===e.kind?"own":"prototype",descriptor:t};return e.decorators&&(r.decorators=e.decorators),"field"===e.kind&&(r.initializer=e.value),r}function I(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function B(e){return e.decorators&&e.decorators.length}function j(e){return void 0!==e&&!(void 0===e.value&&void 0===e.writable)}function H(e,t){var n=e[t];if(void 0!==n&&"function"!=typeof n)throw new TypeError("Expected '"+t+"' to be a function");return n}function z(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function U(e,t,n,r){var i=Z($(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof i?function(e){return i.apply(n,e)}:i}function Z(){return Z="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=$(e)););return e}(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},Z.apply(null,arguments)}function $(e){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},$(e)}function W(e,t,n){return(t=J(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function J(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}const V="BRhighlightStorage";class X{get selectMenuEnabled(){var e,t;return(null===(e=this.br.plugins.experiments)||void 0===e?void 0:e.isEnabled("copyLinkToHighlight"))||(null===(t=this.br.plugins.experiments)||void 0===t?void 0:t.isEnabled("annotateHighlight"))}constructor(e,t,n,r){let i=n.selectionElement;W(this,"options",{maxProtectedWords:200}),W(this,"selectMenu",void 0),W(this,"_onSelectionChange",(e,t)=>{if("started"===e)this.textSelectingMode(t);else if("cleared"===e)this.defaultMode(t);else if("changed"!==e)throw new Error("Unknown type ".concat(e))}),W(this,"_limitSelection",()=>{const e=window.getSelection();if(!e.rangeCount)return;const t=e.getRangeAt(0),n=!!t.startContainer.parentElement.closest(".BRcontainer"),r=!!t.endContainer.parentElement.closest(".BRcontainer");if(!n&&!r)return;if(!n||!r)return void e.removeAllRanges();const i=(0,M.eU)((0,M.nC)(K(t,"element"),e=>e.classList.contains(this.selectionElement[0].replace(".",""))),this.options.maxProtectedWords-1);if(!i||t.endContainer.parentNode==i)return;const o=document.createRange();o.setStart(t.startContainer,t.startOffset),o.setEnd(i.firstChild,i.textContent.length),e.removeAllRanges(),e.addRange(o)}),this.layer=e,this.br=t,this.selectionElement=i,this.selectionObserver=new c(this.layer,this._onSelectionChange),this.options.maxProtectedWords=r||200,this.selectMenu=new Y(t),this.selectMenu.className="br-select-menu__root"}init(){this.attach(),new c(this.layer,e=>{var t,n;"started"==e&&(null===(t=this.br.plugins.archiveAnalytics)||void 0===t||t.sendEvent("BookReader","SelectStart"),this.br.refs.$br.find(".BRpagecontainer--hasSelection").removeClass("BRpagecontainer--hasSelection"),O(window.getSelection().anchorNode).closest(".BRpagecontainer").addClass("BRpagecontainer--hasSelection"),this.mouseIsDown||this.showSelectMenu()),"changed"==e&&!this.mouseIsDown&&null!==(n=window.getSelection())&&void 0!==n&&n.toString()&&this.showSelectMenu(),"cleared"==e&&this.hideSelectMenu()}).attach()}attach(){this.selectionObserver.attach(),this.br.protected&&(document.addEventListener("selectionchange",this._limitSelection),O(document.body).on("contextmenu dragstart copy",e=>{const t=document.getSelection();if(null!=t&&t.toString()&&O(this.layer).toArray().some(e=>t.containsNode(e,!0)))return e.preventDefault(),!1}))}detach(){this.selectionObserver.detach(),this.br.protected&&document.removeEventListener("selectionchange",this._limitSelection)}interceptCopy(e){e[0].addEventListener("copy",e=>{const t=document.getSelection();e.clipboardData.setData("text/plain",t.toString()),e.preventDefault()})}stopPageFlip(e){const t=e.find(this.layer);t.length&&(t.each((e,t)=>this.defaultMode(t)),this.br.protected||this.interceptCopy(e))}defaultMode(e){const t=O(e).closest(".BRpagecontainer");e.style.pointerEvents="none",t.find("img").css("pointer-events","auto"),O(e).off(".textSelectPluginHandler");const n=this.mouseIsDown;let r=this.mouseIsDown;n&&(e.style.pointerEvents="auto"),O(e).on("mousedown.textSelectPluginHandler",e=>{this.mouseIsDown=!0,O(e.target).is(this.selectionElement.join(", "))&&e.stopPropagation()}),O(e).on("mouseup.textSelectPluginHandler",t=>{this.mouseIsDown=!1,e.style.pointerEvents="none",r&&(r=!1,t.stopPropagation())})}textSelectingMode(e){const t=O(e).closest(".BRpagecontainer");e.style.pointerEvents="all",t.find("img").css("pointer-events","none"),O(e).off(".textSelectPluginHandler"),O(e).on("mousedown.textSelectPluginHandler",e=>{1==e.which&&(this.mouseIsDown=!0,e.stopPropagation())}),O(e).on("mouseup.textSelectPluginHandler",e=>{this.mouseIsDown=!1,1==e.which&&(e.stopPropagation(),this.showSelectMenu())})}showSelectMenu(){this.selectMenuEnabled&&(this.selectMenu.copyLinkToHighlightEnabled=this.br.plugins.experiments.isEnabled("copyLinkToHighlight"),this.selectMenu.highlightAnnotationEnabled=this.br.plugins.experiments.isEnabled("annotateHighlight"),this.selectMenu.isConnected||document.body.append(this.selectMenu),this.selectMenu.open?this.selectMenu.repositionToSelection():this.selectMenu.show())}hideSelectMenu(){this.selectMenu.hide()}}function K(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"text+element";return function*(){const n=e.startContainer,r=e.endContainer;let i=!1;const o=e=>"text"===t&&e.nodeType===Node.TEXT_NODE||"element"===t&&e.nodeType===Node.ELEMENT_NODE||"text+element"===t;yield*function e(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.children,s=void 0===a||a,l=n.parents,c=void 0===l||l,d=n.siblings,u=void 0===d||d;return function*(){if(t===r)return i=!0,void(o(t)&&(yield t));if(o(t)&&(yield t),!(s&&t.firstChild&&(yield*e(t.firstChild,{children:!0,parents:!1,siblings:!0}),i))){if(u)for(let n=t.nextSibling;n;n=n.nextSibling)if(yield*e(n,{children:!0,parents:!1,siblings:!1}),i)return;c&&t.parentNode&&(yield*e(t.parentNode,{children:!1,parents:!0,siblings:!0}))}}()}(n)}()}D([(0,R.EM)("br-menu-option")],function(e,t){class n extends t{constructor(){super(...arguments),e(this)}}return{F:n,d:[{kind:"field",decorators:[(0,R.MZ)({type:String})],key:"icon",value:()=>""},{kind:"field",decorators:[(0,R.MZ)({type:String})],key:"label",value:()=>""},{kind:"field",key:"temporaryText",value:()=>null},{kind:"field",decorators:[(0,R.MZ)({type:Number,attribute:"temporary-text-duration"})],key:"temporaryTextDuration",value:()=>1200},{kind:"field",decorators:[(0,R.MZ)({type:String,attribute:"aria-label"})],key:"ariaLabel",value:()=>""},{kind:"field",decorators:[(0,R.MZ)({type:Boolean,attribute:"live-label"})],key:"liveLabel",value:()=>!1},{kind:"field",decorators:[(0,R.MZ)({type:Boolean})],key:"temporaryTextVisible",value:()=>!1},{kind:"field",key:"temporaryTextTimeoutId",value:()=>null},{kind:"method",key:"createRenderRoot",value:function(){return this}},{kind:"method",key:"disconnectedCallback",value:function(){null!=this.temporaryTextTimeoutId&&(window.clearTimeout(this.temporaryTextTimeoutId),this.temporaryTextTimeoutId=null),U(n,"disconnectedCallback",this,3)([])}},{kind:"method",key:"showTemporaryText",value:function(e){null!=e&&e.trim()&&(this.temporaryText=e,this.temporaryTextVisible=!0,null!=this.temporaryTextTimeoutId&&window.clearTimeout(this.temporaryTextTimeoutId),this.temporaryTextTimeoutId=window.setTimeout(()=>{this.temporaryTextVisible=!1,this.temporaryText=null,this.temporaryTextTimeoutId=null},this.temporaryTextDuration))}},{kind:"method",key:"renderIcon",value:function(){return"share"===this.icon?(0,_.qy)(d||(d=N(['<ia-icon-share class="br-select-menu__icon" aria-hidden="true"></ia-icon-share>']))):"edit-pencil"===this.icon?(0,_.qy)(u||(u=N(['<ia-icon-edit-pencil class="br-select-menu__icon" aria-hidden="true"></ia-icon-edit-pencil>']))):"ellipses"===this.icon?(0,_.qy)(h||(h=N(['<ia-icon-ellipses class="br-select-menu__icon" aria-hidden="true"></ia-icon-ellipses>']))):""}},{kind:"method",key:"render",value:function(){var e,t;const n=null!==(e=this.label)&&void 0!==e?e:"",r=!!this.temporaryText,i=r?this.temporaryText:n,o=r&&this.temporaryTextVisible,a=o?i:n,s=null===(t=this.ariaLabel)||void 0===t?void 0:t.trim(),l=s&&s!==a.trim()?s:void 0,c=n.length>=i.length?n:i;return(0,_.qy)(p||(p=N(['\n <button\n type="button"\n class="br-select-menu__option"\n role="menuitem"\n aria-label=',"\n >\n ","\n ","\n </button>\n "])),(0,P.J)(l),this.renderIcon(),r||n?r?(0,_.qy)(g||(g=N(['\n <span class="br-select-menu__label-wrap" style="display: inline-flex; position: relative; align-items: center;">\n <span\n class="br-select-menu__label"\n style="visibility: hidden;"\n aria-hidden="true"\n >','</span>\n <span\n class="br-select-menu__label"\n style="position: absolute; inset: 0; display: inline-flex; align-items: center;"\n aria-live=',"\n >","</span>\n </span>\n "])),c,this.liveLabel?"polite":"off",o?i:n):(0,_.qy)(f||(f=N(['\n <span class="br-select-menu__label" aria-live=',">","</span>\n "])),this.liveLabel?"polite":"off",n):"")}}]}},_.WF);let Y=D([(0,R.EM)("br-select-menu")],function(e,t){class n extends t{constructor(t){super(),e(this),this.br=t}}return{F:n,d:[{kind:"field",key:"br",value:void 0},{kind:"field",decorators:[(0,R.MZ)({type:Boolean,reflect:!0})],key:"showExtended",value:()=>!1},{kind:"field",decorators:[(0,R.P)("#br-select-copy-link-option")],key:"copyLinkOption",value:void 0},{kind:"field",decorators:[(0,R.MZ)({type:Boolean,reflect:!0})],key:"open",value:()=>!1},{kind:"field",decorators:[(0,R.MZ)({type:Boolean})],key:"copyLinkToHighlightEnabled",value:()=>!0},{kind:"field",decorators:[(0,R.MZ)({type:Boolean})],key:"highlightAnnotationEnabled",value:()=>!0},{kind:"method",key:"createRenderRoot",value:function(){return this}},{kind:"field",key:"_scrollTimeoutId",value:()=>null},{kind:"field",key:"_onScroll",value(){return()=>{this.classList.add("br-select-menu__root--scrolling"),null!=this._scrollTimeoutId&&clearTimeout(this._scrollTimeoutId),this._scrollTimeoutId=window.setTimeout(()=>{this._scrollTimeoutId=null,this.repositionToSelection(),this.classList.remove("br-select-menu__root--scrolling")},150)}}},{kind:"method",key:"connectedCallback",value:function(){U(n,"connectedCallback",this,3)([]),this.setAttribute("role","menu"),this.setAttribute("aria-label","Text selection actions"),this.setAttribute("aria-orientation","vertical")}},{kind:"method",key:"disconnectedCallback",value:function(){U(n,"disconnectedCallback",this,3)([]),window.removeEventListener("scroll",this._onScroll,{capture:!0}),null!=this._scrollTimeoutId&&(clearTimeout(this._scrollTimeoutId),this._scrollTimeoutId=null)}},{kind:"method",key:"renderCopyLinkToHighlightOption",value:function(){return(0,_.qy)(m||(m=N(['\n <br-menu-option\n id="br-select-copy-link-option"\n @mousedown=',"\n @click=",'\n icon="share"\n label="Copy Link to Highlight"\n live-label\n ></br-menu-option>\n '])),e=>e.preventDefault(),this.handleCopyLinkToHighlight)}},{kind:"method",key:"renderRemoveOption",value:function(){return(0,_.qy)(y||(y=N(["\n <br-menu-option\n @click=",'\n icon="share"\n label="Delete Highlight and Annotation"\n ></br-menu-option>\n '])),this.handleDeleteHighlight)}},{kind:"method",key:"renderAddAnnotationOption",value:function(){return(0,_.qy)(v||(v=N(["\n <br-menu-option\n @click=",'\n icon="edit-pencil"\n label="Annotate"\n ></br-menu-option>\n '])),this.handleAddAnnotation)}},{kind:"method",key:"renderHighlightOption",value:function(){return(0,_.qy)(b||(b=N(["\n <br-menu-option\n @click=",'\n icon="edit-pencil"\n label="Highlight Selection"\n ></br-menu-option>\n '])),this.handleHighlightSave)}},{kind:"method",key:"renderShowMoreOption",value:function(){return(0,_.qy)(w||(w=N(['\n <br-menu-option\n id="br-select-more"\n @mousedown=',"\n @click=",'\n icon="ellipses"\n aria-label="Show more options"\n ></br-menu-option>\n '])),e=>e.preventDefault(),this.toggleExtendedMenu)}},{kind:"method",key:"renderLocalStorageOptions",value:function(){return(0,_.qy)(k||(k=N(["\n <br-menu-option\n @click=",'\n icon="share"\n label="Load Highlights"\n ></br-menu-option>\n <br-menu-option\n @click=','\n icon="share"\n label="Remove Stored Highlights"\n ></br-menu-option>'])),this.renderSavedHighlights,()=>{window.localStorage.removeItem(V)})}},{kind:"method",key:"renderDefaultOptions",value:function(){return(0,_.qy)(E||(E=N(["\n ","\n ","\n ","\n "])),this.copyLinkToHighlightEnabled?this.renderCopyLinkToHighlightOption():"",this.highlightAnnotationEnabled&&!this.nodesForRemoval?this.renderHighlightOption():"",this.nodesForRemoval?this.renderRemoveOption():"")}},{kind:"method",key:"renderExtendedOptions",value:function(){return(0,_.qy)(x||(x=N(["\n ","\n ","\n "])),this.renderDefaultOptions(),this.renderLocalStorageOptions())}},{kind:"method",key:"render",value:function(){var e;const t=null===(e=this.br.plugins.experiments)||void 0===e?void 0:e.isEnabled("annotateHighlight");return(0,_.qy)(T||(T=N(["\n ","\n ","\n "])),this.showExtended?this.renderExtendedOptions():this.renderDefaultOptions(),!this.showExtended&&t?this.renderShowMoreOption():"")}},{kind:"method",key:"handleCopyLinkToHighlight",value:async function(e){var t;e.preventDefault();const n=window.getSelection(),r=n.getRangeAt(0),i=this.getNodeTextLayer(r.startContainer);if(!i)return void console.warn("No text layer found for selection");const o=ce.fromSelection(n,[i]),a=o.toUrl();await navigator.clipboard.writeText(a),null===(t=this.copyLinkOption)||void 0===t||t.showTemporaryText("Copied!"),this.br.trigger("copyLinkToHighlight",{textFragment:o,link:a})}},{kind:"method",key:"toggleExtendedMenu",value:function(e){e.preventDefault(),this.showExtended=!this.showExtended}},{kind:"method",key:"getNodeTextLayer",value:function(e){var t;if(!e)return null;const n=e instanceof Element?e:e.parentElement;return null!==(t=null==n?void 0:n.closest(".BRtextLayer"))&&void 0!==t?t:null}},{kind:"method",key:"handleHighlightSave",value:function(){const e=window.getSelection(),t="backward"===e.direction?e.focusNode.parentElement:e.anchorNode.parentElement,n=this.getNodeTextLayer(t),r=ce.fromSelection(e,[n.parentElement]);r.uuid="id-".concat(crypto.randomUUID().split("-")[4]);const i=this.loadHighlightsFromLocalStorage();i.push(r),this.saveToLocalStorage(i),this.renderSavedHighlights()}},{kind:"method",key:"handleAddAnnotation",value:function(e){}},{kind:"method",key:"handleDeleteHighlight",value:function(){if(this.nodesForRemoval){const e=le(this.nodesForRemoval[0]);for(const e of this.nodesForRemoval){const t=e.textContent,n=e.parentElement;n.classList.contains("BRwordElement")||n.classList.contains("BRspace")?(e.remove(),n.textContent=t):console.log("This element did not match removal criteria:",n,e)}this.deleteHighlight(e),this.clearNodesForRemoval()}else console.log("there is nothing to remove")}},{kind:"method",key:"deleteHighlight",value:function(e){const t=this.loadHighlightsFromLocalStorage();for(let n=0;n<t.length;n++)if(t[n].uuid===e)return t.splice(n,1),void this.saveToLocalStorage(t)}},{kind:"method",key:"saveToLocalStorage",value:function(e){window.localStorage.setItem(V,JSON.stringify(e.map(e=>e.toJSON())))}},{kind:"method",key:"loadHighlightsFromLocalStorage",value:function(){return JSON.parse(window.localStorage.getItem(V)||"[]").map(e=>ce.fromJSON(e))}},{kind:"method",key:"renderSavedHighlights",value:function(){for(const e of this.loadHighlightsFromLocalStorage()){const t=this.br.$(".pagediv".concat(e.pageIndex," .BRtextLayer"))[0];t&&(ae(t,e),O(t).off("mouseup.BRHighlightClick").on("mouseup.BRHighlightClick",e=>{e.target.classList.contains("BRhighlight")&&(e.stopPropagation(),this.handleHighlightClick(e.target))}))}}},{kind:"method",key:"handleHighlightClick",value:function(e){const t=this.getNodeTextLayer(e),n=le(e),r=t.querySelectorAll(".".concat(n)),i=r[0],o=r[r.length-1],a=document.createRange();a.setStart(i,0),a.setEnd(o,1);const s=window.getSelection();s.removeAllRanges(),s.addRange(a),this.show()}},{kind:"method",key:"repositionToSelection",value:function(){const e=window.getSelection().getRangeAt(0).getBoundingClientRect(),t=(0,A.un)()||(0,A.m0)(),n=(0,A.m0)()?25:(0,A.un)()?15:10,r=t?60:0,i=(e.top<r?e.bottom+r:e.bottom)+n,o=Math.max(10,i)+window.scrollY,a=this.getBoundingClientRect().width,s=document.documentElement.clientWidth,l=a>e.width?e.left+e.width/2-a/2:e.left,c=(0,L.qE)(l,10,s-a-10)+window.scrollX;this.style.top="".concat(o,"px"),this.style.left="".concat(c,"px")}},{kind:"method",key:"show",value:async function(){var e;null!==(e=this.br.plugins.translate)&&void 0!==e&&e.userToggleTranslate||(this.style.zIndex="1",this.style.position="absolute",this.open=!0,this.classList.remove("br-select-menu__root--scrolling"),window.removeEventListener("scroll",this._onScroll,{capture:!0}),window.addEventListener("scroll",this._onScroll,{capture:!0,passive:!0}),await this.updateComplete,this.repositionToSelection(),this.clearNodesForRemoval())}},{kind:"method",key:"hide",value:function(){this.open&&(this.showExtended=!1,this.open=!1,window.removeEventListener("scroll",this._onScroll,{capture:!0}),this.clearNodesForRemoval())}},{kind:"field",key:"clearNodesForRemoval",value(){return()=>{this.nodesForRemoval=null,this.requestUpdate()}}}]}},_.WF);function G(e,t){t=t.trim();const n=new RegExp(String.raw(S||(S=N(["^(S+(s+|$)){1,","}"],["^(\\S+(\\s+|$)){1,","}"])),e)),r=t.match(n);return r?r[0].trim():""}function Q(e,t){t=t.trim();const n=new RegExp(String.raw(C||(C=N(["((^|s+)S+){1,","}s*?$"],["((^|\\s+)\\S+){1,","}\\s*?$"])),e)),r=t.match(n);return r?r[0].trim():""}function ee(e){for(;e.firstChild;)e=e.firstChild;return e}function te(e){for(;e.lastChild;)e=e.lastChild;return e}function ne(e){return e.replace(/(:|-,|,-|,|\n)/g,e=>1===e.length?" ":" ")}function re(e,t,n){let r=(arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}).normalize,i=void 0===r?e=>e:r;if(!n.length)return;const o=n[0]===t.startContainer?t.startOffset:0,a=i(oe(t)),s=i(n[0].textContent.slice(0,o)).length,l=new RegExp(e.source,e.flags.includes("g")?e.flags:"".concat(e.flags,"g")),c=Array.from(a.matchAll(l)).map(e=>{const t=ie(s+e.index,n,!1,{normalize:i}),r=ie(s+e.index+e[0].length,n,!0,{normalize:i});if(!t||!r)return void console.warn("Could not find boundary points for regex match, skipping this match",{match:e,start:t,end:r});const o=new Range;return o.setStart(t.node,t.offset),o.setEnd(r.node,r.offset),o}).filter(e=>!!e);return null!=c&&c.length?c:void 0}function ie(e,t,n){let r=(arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}).normalize,i=void 0===r?e=>e:r;const o=e;let a=0;for(const e of t){const t=e.textContent||"",r=i(t),s=a;if(s+r.length+(n?1:0)>o){const a=o-s;let l=Math.min(a,t.length);const c=n?r.substring(0,a):r.substring(a);let d=i(n?t.substring(0,a):t.substring(a));const u=(n?-1:1)*(c.length>d.length?-1:1);for(;l>=0&&l<=t.length;){if(d.length===c.length)return{node:e,offset:l};l+=u,d=i(n?t.substring(0,l):t.substring(l))}}a+=r.length}}function oe(e){const t=Array.from((0,M.nC)(K(e,"text"),se));let n=t.map(e=>e.textContent).join("");const r=t[0],i=t[t.length-1];return e.startContainer===r&&(n=n.substring(e.startOffset)),e.endContainer===i&&(n=n.substring(0,n.length-(i.textContent.length-e.endOffset))),n}function ae(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const r=ee(e),i=te(e),o=new Range;o.setStart(r,0),o.setEnd(i,i.textContent.length);const a=Array.from((0,M.nC)(K(o,"text"),se)),s=re(t.toRegExp({context:!0}),o,a,{normalize:ne});if(!s)return void console.warn("Could not find quote with context in page");const l=Array.from((0,M.nC)(K(s[0],"text"),se)),c=re(t.toRegExp({context:!1}),s[0],l,{normalize:ne});if(!c)throw new Error("Could not find quote in page");const d=ee(c[0].startContainer),u=ee(c[0].endContainer),h=new Range;return h.setStart(d,0),h.setEnd(u,u.textContent.length),d.parentElement.classList.contains("BRhighlight")||u.parentElement.classList.contains("BRhighlight")?void 0:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:()=>document.createElement("mark");if(e.startContainer.nodeType!=Node.TEXT_NODE||e.endContainer.nodeType!=Node.TEXT_NODE)return[];if(e.startContainer===e.endContainer){const n=t();return e.surroundContents(n),[n]}const n=e.startContainer,r=e.cloneRange();r.setEndAfter(n);const i=e.endContainer,o=e.cloneRange();o.setStartBefore(i);const a=[];e.setStartAfter(n),e.setEndBefore(i);const s=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,{acceptNode:function(t){return e.intersectsNode(t)?t.nodeType===Node.TEXT_NODE?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP:NodeFilter.FILTER_REJECT}});let l=s.nextNode();for(;l;){if(l.nodeType===Node.TEXT_NODE){const e=t();l.parentNode.insertBefore(e,l),e.appendChild(l),a.push(e)}l=s.nextNode()}const c=t();r.surroundContents(c);const d=t();return o.surroundContents(d),[c,...a,d]}(h,()=>{const e=document.createElement("mark");return e.classList.add("BRhighlight"),n&&e.classList.add(n),t.uuid&&e.classList.add(t.uuid),e})}function se(e){var t;return!(null!==(t=e.previousElementSibling)&&void 0!==t&&t.classList.contains("BRspace"))}function le(e){if(!e)return null;const t=Array.from(null==e?void 0:e.classList).filter(e=>{if(e.slice(0,2).includes("id"))return e});return t.length?t[0]:null}class ce{constructor(e){let t=e.prefix,n=e.quote,r=e.quoteStart,i=e.quoteEnd,o=e.suffix,a=e.pageNumber,s=e.pageIndex,l=e.uuid;this.prefix=t,this.quote=null!=n?n:null,this.quoteStart=null!=r?r:null,this.quoteEnd=null!=i?i:null,this.suffix=o,this.pageNumber=a,this.pageIndex=s,this.uuid=null!=l?l:null}static fromString(e,t,n){const r=e.match(/^(?:(.*?):)?(?:(.*?)-,)?(.*?)(?:,-(.*))?$/);if(!r)throw new Error("Invalid text fragment format: ".concat(e));const i=r[1]||null,o=r[2]||null,a=(r[3]||"").split(",");let s=null,l=null,c=null;if(1===a.length)s=a[0];else{if(2!==a.length)throw new Error("Invalid text fragment quote format: ".concat(e));l=a[0],c=a[1]}const d=r[4]||null,u=i?t.getPageIndex(i):n;if("number"!=typeof u)throw new Error("Could not determine page index for text fragment with page number ".concat(i));if(!(s||l&&c))throw new Error("Invalid text fragment quote format: ".concat(e));return new ce({prefix:o,quote:s,quoteStart:l,quoteEnd:c,suffix:d,pageNumber:i,pageIndex:u})}toUrl(){const e=new URLSearchParams(window.location.search);e.set("text",this.toNormalizedString());const t=window.location,n=this.pageNumber||"n".concat(this.pageIndex),r=t.pathname.replace(/((?:^|[#/])page)\/[^/]+/,"$1/".concat(n)),i=t.hash?t.hash.replace(/((?:^|[#/])page)\/[^/]+/,"$1/".concat(n)):"";return"".concat(t.origin).concat(r,"?").concat(e).concat(i)}toNormalizedString(){const e=e=>function(e){return e.replace(/\s+/g," ").trim()}(ne(e).trim());let t=this.pageNumber?this.pageNumber:"n".concat(this.pageIndex);t+=":",this.prefix&&(t+=e(this.prefix),t+="-,");const n=this.quote?e(this.quote):null;let r=null;if(n&&n.length>80&&(n.match(/\S+/g)||[]).length>=6){const e=G(3,n),t=Q(3,n);e&&t&&(r={quoteStart:e,quoteEnd:t})}if(n&&!r)t+=n;else if(r)t+="".concat(r.quoteStart,",").concat(r.quoteEnd);else{if(!this.quoteStart||!this.quoteEnd)throw new Error("Text fragment requires either a quote or quoteStart/quoteEnd");t+="".concat(this.quoteStart,",").concat(this.quoteEnd)}return this.suffix&&(t+=",-",t+=e(this.suffix)),t}toRegExp(){let e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).context,t=void 0!==e&&e;const n=this.quote?[this.quote]:[this.quoteStart,this.quoteEnd];t&&(this.prefix&&(n[0]=this.prefix+" "+n[0]),this.suffix&&(n[n.length-1]=n[n.length-1]+" "+this.suffix));const r=e=>RegExp.escape(ne(e)).replace(/(\\x20)+/g,"\\s+");return 1===n.length?new RegExp(r(n[0]),"gi"):new RegExp(r(n[0])+"[\\s\\S]*?"+r(n[1]),"gi")}toJSON(){return{prefix:this.prefix,quote:this.quote,quoteStart:this.quoteStart,quoteEnd:this.quoteEnd,suffix:this.suffix,pageNumber:this.pageNumber,pageIndex:this.pageIndex,uuid:this.uuid}}static fromJSON(e){return new ce(e)}static fromSelection(e,t){var n,r;const i=e.getRangeAt(0),o=new Range,s=te(i.startContainer),l=ee(i.endContainer);o.setStart(s,0),o.setEnd(l,0==i.endOffset?0:null!==(n=null===(r=l.textContent)||void 0===r?void 0:r.length)&&void 0!==n?n:0);const c=document.createRange();c.setStart(ee(t[0]),0),c.setEnd(s,0);const d=document.createRange();d.setStart(l,o.endOffset);const u=te(t[t.length-1]);d.setEnd(u,Math.max(0,u.textContent.length-1));const h=oe(c);let p=Q(3,h),g=(0,a.rj)(p);const f=oe(d);let m=G(3,f),y=(0,a.rj)(m);g<3&&(m=G(6-g,f),y=(0,a.rj)(m)),y<3&&(p=Q(6-y,h),g=(0,a.rj)(p));const v=oe(o),b=s.parentElement.closest(".BRpagecontainer");return new ce({quote:v,prefix:p,suffix:m,pageNumber:b.getAttribute("data-page-num"),pageIndex:parseFloat(b.getAttribute("data-index"))})}}},5369:(e,t,n)=>{n.d(t,{l:()=>r}),n(3792),n(2953);class r{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10;this.maxSize=e,this.entries=[]}add(e){this.entries.length>=this.maxSize&&this.entries.shift(),this.entries.push(e)}}},4297:(e,t,n)=>{function r(e,t){let n=0;for(const r of e){if(n==t)return r;n++}}function*i(e,t){for(const n of e)t(n)&&(yield n)}function*o(e,t){for(const n of e)yield t(n)}function*a(e){let t,n,r;for(const i of e)void 0!==n&&(r=i,yield[t,n,r]),t=n,n=i,r=void 0;void 0!==n&&(yield[t,n,r])}function*s(e,t){const n=e[Symbol.iterator](),r=t[Symbol.iterator]();for(;;){const e=n.next(),t=r.next();if(e.done&&t.done)return;if(e.done||t.done)throw new Error("zip: one of the iterators is done");yield[e.value,t.value]}}n.d(t,{Px:()=>o,eU:()=>r,nC:()=>i,pp:()=>a,yU:()=>s}),n(3792),n(2953)},8965:(e,t,n)=>{function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function i(e){const t=e.match(/\S+/g);return t?t.length:0}function o(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:a;return null==e?void 0:e.replace(/\{\{([^}]*?)\}\}/g,(e,o)=>{if(!o)return e;const a=function(e){if(Array.isArray(e))return e}(c=o.split("|").map(e=>e.trim()))||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(c)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(c)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),s=a[0],l=r(a).slice(1);var c;if(!(s in n)&&!(s in t))return e;const d=s in n?n[s]:s in t?t[s]:null;return l.map(e=>i[e]).reduce((e,t)=>t(e),d&&d.toString())})}n.d(t,{gT:()=>o,rj:()=>i}),n(9463),n(3792),n(2712),n(7495),n(5440),n(2762),n(2953);const a={urlencode:encodeURIComponent}}};import{__webpack_require__ as n}from"../ia-bookreader.js";n.C({__webpack_esm_ids__,__webpack_esm_modules__});var r=n(271);const i=r.L,o=r.U;export{i as BrTranslatePanel,o as TranslatePlugin};
|
|
1
|
+
import{BatchTranslator as e}from"@internetarchive/bergamot-translator/translator.js";import{default as t}from"iso-language-codes";import"@internetarchive/icon-share";import"@internetarchive/icon-ellipses";export const __webpack_esm_ids__=[444];export const __webpack_esm_modules__={706:(e,t,n)=>{var r=n(350).PROPER,i=n(9039),o=n(7452);e.exports=function(e){return i(function(){return!!o[e]()||"
"!=="
"[e]()||r&&o[e].name!==e})}},3802:(e,t,n)=>{var r=n(9504),i=n(7750),o=n(655),a=n(7452),s=r("".replace),l=RegExp("^["+a+"]+"),c=RegExp("(^|[^"+a+"])["+a+"]+$"),d=function(e){return function(t){var n=o(i(t));return 1&e&&(n=s(n,l,"")),2&e&&(n=s(n,c,"$1")),n}};e.exports={start:d(1),end:d(2),Bq:d(3)}},7452:e=>{e.exports="\t\n\v\f\r \u2028\u2029\ufeff"},2762:(e,t,n)=>{var r=n(6518),i=n(3802).Bq;r({target:"String",proto:!0,forced:n(706)("trim")},{trim:function(){return i(this)}})},6869:(e,t,n)=>{n.d(t,{S:()=>r});class r{constructor(e){this.br=e,this.options}setup(e){this.options=Object.assign({},this.options,e)}init(){}_configurePageContainer(e){}_configureToolbar(e){}_bindNavigationHandlers(){}extendNavBar(e){}}},271:(t,n,r)=>{r.d(n,{L:()=>I,U:()=>F}),r(9463),r(3792),r(3362),r(7495),r(5440),r(2953);var i=r(7597),o=r(6869),a=r(6054),s=r(5369),l=r(9748);function c(e,t,n){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class d{constructor(){c(this,"alreadyTranslated",new s.l(100)),c(this,"modelRegistry",{}),c(this,"currentlyTranslating",{}),c(this,"fromLanguages",[]),c(this,"toLanguages",[]),c(this,"active",!1),c(this,"publicPath",""),c(this,"getTranslation",async(e,t,n,r,i,o)=>{if(this.active=!0,e==t||!e||!t)return;const a="".concat(e).concat(t,"-").concat(n,":").concat(r),s=this.alreadyTranslated.entries.find(e=>e.index==a);if(s)return s.response;if(a in this.currentlyTranslating)return this.currentlyTranslating[a].promise;let l=null,c=null;const d=new Promise((e,t)=>{l=e,c=t});return this.currentlyTranslating[a]={promise:d,resolve:l,reject:c},i?(this.translator.translate({to:t,from:e,text:i,html:!1,priority:o}).then(e=>{const t=e;this.currentlyTranslating[a].resolve(t.target.text),this.alreadyTranslated.add({index:a,response:t.target.text}),delete this.currentlyTranslating[a]}),d):(this.currentlyTranslating[a].reject("No text was provided"),d)}),c(this,"getTranslationModel",async(e,t)=>this.translator.backing.getTranslationModel({from:e,to:t}).catch(n=>{console.error("An error occurred while trying to retreive the ".concat(e,"-").concat(t," model"))}));const e={code:"en",name:"English (en)",type:"prod"};this.fromLanguages.push(e),this.toLanguages.push(e)}async initWorker(){if(this.initPromise)return this.initPromise;this.initPromise=new Promise((e,t)=>{this._initResolve=e,this._initReject=t});const t="https://cors.archive.org/cors/mozilla-translate-models/firefox_models/",n=await fetch(t+"registry.json").then(e=>e.json());for(const e of Object.values(n))for(const n of Object.values(e))n.name=t+n.name;this.translator=new e({registryUrl:"data:application/json,".concat(encodeURIComponent(JSON.stringify(n))),workers:2,batchSize:4,workerUrl:this.publicPath+"/translator-worker.js"});const r=await this.translator.backing.registry,i={};for(const e of Object.values(r)){const t=e.from,n=e.to,r=e.files;if(i["".concat(t).concat(n)]=r,"en"!==t){const e="".concat((0,l._4)(t)," (").concat((0,l.YH)(t),")");this.fromLanguages.push({code:t,name:e,type:"prod"})}if("en"!==n){const e="".concat((0,l._4)(n)," (").concat((0,l.YH)(n),")");this.toLanguages.push({code:n,name:e,type:"prod"})}}return this._initResolve([this.modelRegistry]),this.initPromise}}var u,h,p,g,f,m,y,v,b,w=r(9880),k=r(3991),E=(r(6376),r(1669));function x(){x=function(){return e};var e={elementsDefinitionOrder:[["method"],["field"]],initializeInstanceElements:function(e,t){["method","field"].forEach(function(n){t.forEach(function(t){t.kind===n&&"own"===t.placement&&this.defineClassElement(e,t)},this)},this)},initializeClassElements:function(e,t){var n=e.prototype;["method","field"].forEach(function(r){t.forEach(function(t){var i=t.placement;if(t.kind===r&&("static"===i||"prototype"===i)){var o="static"===i?e:n;this.defineClassElement(o,t)}},this)},this)},defineClassElement:function(e,t){var n=t.descriptor;if("field"===t.kind){var r=t.initializer;n={enumerable:n.enumerable,writable:n.writable,configurable:n.configurable,value:void 0===r?void 0:r.call(e)}}Object.defineProperty(e,t.key,n)},decorateClass:function(e,t){var n=[],r=[],i={static:[],prototype:[],own:[]};if(e.forEach(function(e){this.addElementPlacement(e,i)},this),e.forEach(function(e){if(!C(e))return n.push(e);var t=this.decorateElement(e,i);n.push(t.element),n.push.apply(n,t.extras),r.push.apply(r,t.finishers)},this),!t)return{elements:n,finishers:r};var o=this.decorateConstructor(n,t);return r.push.apply(r,o.finishers),o.finishers=r,o},addElementPlacement:function(e,t,n){var r=t[e.placement];if(!n&&-1!==r.indexOf(e.key))throw new TypeError("Duplicated element ("+e.key+")");r.push(e.key)},decorateElement:function(e,t){for(var n=[],r=[],i=e.decorators,o=i.length-1;o>=0;o--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,i[o])(s)||s);e=l.element,this.addElementPlacement(e,t),l.finisher&&r.push(l.finisher);var c=l.extras;if(c){for(var d=0;d<c.length;d++)this.addElementPlacement(c[d],t);n.push.apply(n,c)}}return{element:e,finishers:r,extras:n}},decorateConstructor:function(e,t){for(var n=[],r=t.length-1;r>=0;r--){var i=this.fromClassDescriptor(e),o=this.toClassDescriptor((0,t[r])(i)||i);if(void 0!==o.finisher&&n.push(o.finisher),void 0!==o.elements){e=o.elements;for(var a=0;a<e.length-1;a++)for(var s=a+1;s<e.length;s++)if(e[a].key===e[s].key&&e[a].placement===e[s].placement)throw new TypeError("Duplicated element ("+e[a].key+")")}}return{elements:e,finishers:n}},fromElementDescriptor:function(e){var t={kind:e.kind,key:e.key,placement:e.placement,descriptor:e.descriptor};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),"field"===e.kind&&(t.initializer=e.initializer),t},toElementDescriptors:function(e){if(void 0!==e)return(t=e,function(e){if(Array.isArray(e))return e}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return R(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?R(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map(function(e){var t=this.toElementDescriptor(e);return this.disallowProperty(e,"finisher","An element descriptor"),this.disallowProperty(e,"extras","An element descriptor"),t},this);var t},toElementDescriptor:function(e){var t=e.kind+"";if("method"!==t&&"field"!==t)throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "'+t+'"');var n=N(e.key),r=e.placement+"";if("static"!==r&&"prototype"!==r&&"own"!==r)throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "'+r+'"');var i=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var o={kind:t,key:n,placement:r,descriptor:Object.assign({},i)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(i,"get","The property descriptor of a field descriptor"),this.disallowProperty(i,"set","The property descriptor of a field descriptor"),this.disallowProperty(i,"value","The property descriptor of a field descriptor"),o.initializer=e.initializer),o},toElementFinisherExtras:function(e){return{element:this.toElementDescriptor(e),finisher:_(e,"finisher"),extras:this.toElementDescriptors(e.extras)}},fromClassDescriptor:function(e){var t={kind:"class",elements:e.map(this.fromElementDescriptor,this)};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),t},toClassDescriptor:function(e){var t=e.kind+"";if("class"!==t)throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "'+t+'"');this.disallowProperty(e,"key","A class descriptor"),this.disallowProperty(e,"placement","A class descriptor"),this.disallowProperty(e,"descriptor","A class descriptor"),this.disallowProperty(e,"initializer","A class descriptor"),this.disallowProperty(e,"extras","A class descriptor");var n=_(e,"finisher");return{elements:this.toElementDescriptors(e.elements),finisher:n}},runClassFinishers:function(e,t){for(var n=0;n<t.length;n++){var r=(0,t[n])(e);if(void 0!==r){if("function"!=typeof r)throw new TypeError("Finishers must return a constructor.");e=r}}return e},disallowProperty:function(e,t,n){if(void 0!==e[t])throw new TypeError(n+" can't have a ."+t+" property.")}};return e}function T(e){var t,n=N(e.key);"method"===e.kind?t={value:e.value,writable:!0,configurable:!0,enumerable:!1}:"get"===e.kind?t={get:e.value,configurable:!0,enumerable:!1}:"set"===e.kind?t={set:e.value,configurable:!0,enumerable:!1}:"field"===e.kind&&(t={configurable:!0,writable:!0,enumerable:!0});var r={kind:"field"===e.kind?"field":"method",key:n,placement:e.static?"static":"field"===e.kind?"own":"prototype",descriptor:t};return e.decorators&&(r.decorators=e.decorators),"field"===e.kind&&(r.initializer=e.value),r}function S(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function C(e){return e.decorators&&e.decorators.length}function L(e){return void 0!==e&&!(void 0===e.value&&void 0===e.writable)}function _(e,t){var n=e[t];if(void 0!==n&&"function"!=typeof n)throw new TypeError("Expected '"+t+"' to be a function");return n}function R(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function P(){return P="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=A(e)););return e}(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},P.apply(null,arguments)}function A(e){return A=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},A(e)}function M(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function O(e,t,n){return(t=N(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}const D=window.BookReader;class F extends o.S{constructor(){super(...arguments),O(this,"options",{enabled:!0,panelDisclaimerText:"Translations are in alpha"}),O(this,"translationManager",new d),O(this,"worker",void 0),O(this,"toLanguages",[]),O(this,"langFromCode",void 0),O(this,"langToCode",void 0),O(this,"_panel",void 0),O(this,"userToggleTranslate",void 0),O(this,"loadingModel",!0),O(this,"textSelectionManager",new k.bg(".BRtranslateLayer",this.br,{selectionElement:[".BRlineElement"]},1)),O(this,"getParagraphsOnPage",e=>e?Array.from(e.querySelectorAll(".BRtextLayer > .BRparagraphElement")):[]),O(this,"handleFromLangChange",async e=>{this.clearAllTranslations();const t=e.detail.value;this.langFromCode=t,this._panel.requestUpdate(),this.translationManager.toLanguages.some(e=>e.code===t)||this.translationManager.toLanguages.push({code:t,name:this.translationManager.fromLanguages.find(e=>e.code==t).name}),this._panel.toLanguages=this.translationManager.toLanguages,console.log(this.langFromCode,this.langToCode),this._render(),this.langFromCode!==this.langToCode&&this.translateActivePageContainerElements()}),O(this,"handleToLangChange",async e=>{this.clearAllTranslations(),this.langToCode=e.detail.value,this._render(),this.translateActivePageContainerElements()}),O(this,"handleToggleTranslation",async()=>{if(!this.userToggleTranslate&&!this.isSourceLanguageSupported())return this.userToggleTranslate=!1,this.translationManager.active=!1,void this._render();this.userToggleTranslate=!this.userToggleTranslate,this.translationManager.active=this.userToggleTranslate,this._render(),this.userToggleTranslate?(this.br.trigger("translationEnabled",{}),this.translateActivePageContainerElements(),this.textSelectionManager.attach()):(this.clearAllTranslations(),this.br.trigger("translationDisabled",{}),this.textSelectionManager.detach())})}async init(){if(!this.options.enabled)return;const e=this.br.options.bookLanguage||"",t=(0,l.YH)(e);this.langFromCode=null!=t?t:"en",this.textSelectionManager.init(),this.translationManager.publicPath=this.br.options.imagesBaseURL.replace(/\/+$/,"")+"/..",this.br.on("textLayerRendered",async(e,t)=>{t.pageIndex;let n=t.pageContainer;if(this.translationManager&&this.translationManager.active){const e=n.$container[0];this.translateRenderedLayer(e)}}),this.br.on("pageVisible",(e,t)=>{let n=t.pageContainerEl;if(this.translationManager.active)for(const e of n.querySelectorAll(".BRtranslateLayer > .BRparagraphElement"))e.textContent&&this.fitVisiblePage(e)}),await this.translationManager.initWorker(),this.langToCode=this.translationManager.toLanguages[0].code,this._render()}translateActivePageContainerElements(){const e=this.br.getActivePageContainerElements(),t=e.filter(e=>e.classList.contains("BRpage-visible")),n=e.filter(e=>!e.classList.contains("BRpage-visible"));for(const e of t)this.translateRenderedLayer(e,0);for(const e of n)this.translateRenderedLayer(e,1e3)}async translateRenderedLayer(e,t){var n;if(this.br.mode==this.br.constModeThumb||!this.userToggleTranslate||this.langFromCode==this.langToCode)return;const r=e.dataset.index;let i;e.querySelector(".BRPageLayer.BRtranslateLayer")?i=e.querySelector(".BRPageLayer.BRtranslateLayer"):(i=document.createElement("div"),i.classList.add("BRPageLayer","BRtranslateLayer","BRtranslateLayerLoading"),i.setAttribute("lang","".concat(this.langToCode)),e.prepend(i));const o=e.querySelector(".BRtextLayer");E(i).css({width:o.style.width,height:o.style.height,transform:o.style.transform,"pointer-events":o.style.pointerEvents,"z-index":3}),o.classList.add("showingTranslation");const a=this.getParagraphsOnPage(e),s=a.map(async(n,o)=>{let s=e.querySelector("[data-translate-index='".concat(r,"-").concat(o,"']"));if(!s){s=document.createElement("p"),s.setAttribute("data-translate-index","".concat(r,"-").concat(o)),s.className="BRparagraphElement";const e=a[o];n.classList.contains("ocr-role-header-footer")&&(s.ariaHidden="true",s.classList.add("ocr-role-header-footer"));const t="".concat(parseInt(E(e).css("font-size")),"px");E(s).css({"margin-left":E(e).css("margin-left"),"margin-top":E(e).css("margin-top"),top:E(e).css("top"),height:E(e).css("height"),width:E(e).css("width"),"font-size":t}),i.append(s)}if(0!==n.textContent.length){var l,c;const i=parseFloat(r)+t+o;this.translationManager.getTranslationModel(this.langFromCode,this.langToCode).then(()=>{this._panel.loadingModel=!1,this.loadingModel=!1});const d=await this.translationManager.getTranslation(this.langFromCode,this.langToCode,r,o,n.textContent,i);null===(l=s.firstElementChild)||void 0===l||l.remove();const u=null===(c=a[o])||void 0===c||null===(c=c.firstChild)||void 0===c?void 0:c.firstChild,h=document.createElement("span");h.className="BRlineElement",h.textContent=d,s.appendChild(h),E(h).css({"text-indent":E(u).css("padding-left")}),e.classList.contains("BRpage-visible")&&this.fitVisiblePage(s)}});null===(n=this.textSelectionManager)||void 0===n||n.stopPageFlip(this.br.refs.$brContainer),await Promise.all(s),this.br.trigger("translateLayerRendered",{leafIndex:r,translateLayer:i})}async getTranslateLayers(e){const t=this.br.getActivePageContainerElementsForIndex(e),n=E(t).filter("[data-index='".concat(e,"']")).find(".BRtranslateLayer");return n.length?n.toArray():new Promise((t,n)=>{const r=async(n,i)=>{i.leafIndex==e&&(this.br.off("translateLayerRendered",r),t([i.translateLayer]))};this.br.on("translateLayerRendered",r)})}clearAllTranslations(){const e=this.br.refs.$br[0];e.querySelectorAll(".BRtranslateLayer").forEach(e=>e.remove()),e.querySelectorAll(".showingTranslation").forEach(e=>e.classList.remove("showingTranslation"))}fitVisiblePage(e){let t=parseInt(E(e).css("font-size"));for(;e.clientHeight<e.scrollHeight&&t>0;)t--,E(e).css({"font-size":"".concat(t,"px")});const n=e.firstElementChild.clientHeight,r=e.scrollHeight;if(n<r){const i=r/(n/t);E(e).css({"line-height":"".concat(i,"px"),overflow:"visible"})}}isSourceLanguageSupported(){return this.translationManager.fromLanguages.some(e=>e.code==this.langFromCode)}_render(){this.br.shell.menuProviders.translate={id:"translate",icon:(0,i.qy)(u||(u=M(["<img src='",'/translate.svg\' width="26"/>'])),this.br.options.imagesBaseURL),label:"Translate",component:(0,i.qy)(h||(h=M(['<br-translate-panel\n @connected="','"\n @langFromChanged="','"\n @langToChanged="','"\n @toggleTranslation="','"\n .fromLanguages="','"\n .toLanguages="','"\n .disclaimerMessage="','"\n .userTranslationActive=',"\n .detectedFromLang=","\n .detectedToLang=","\n .loadingModel=","\n .sourceLanguageSupported=",'\n class="translate-panel"\n />'])),e=>{this._panel=e.target,this._panel.fromLanguages=this.translationManager.fromLanguages,this._panel.toLanguages=this.translationManager.toLanguages,this._panel.userTranslationActive=this.userToggleTranslate,this._panel.detectedToLang=this.langToCode,this._panel.detectedFromLang=this.langFromCode,this._panel.loadingModel=this.loadingModel,this._panel.sourceLanguageSupported=this.isSourceLanguageSupported()},this.handleFromLangChange,this.handleToLangChange,this.handleToggleTranslation,this.translationManager.fromLanguages,this.translationManager.toLanguages,this.options.panelDisclaimerText,this.userToggleTranslate,this.langFromCode,this.langToCode,this.loadingModel,this.isSourceLanguageSupported())},this.br.shell.updateMenuContents()}}null==D||D.registerPlugin("translate",F);let I=(q=[(0,a.EM)("br-translate-panel")],B=i.WF,j=x(),H=function(e,t){class n extends t{constructor(){super(...arguments),e(this)}}return{F:n,d:[{kind:"field",decorators:[(0,a.MZ)({type:Array})],key:"fromLanguages",value:()=>[]},{kind:"field",decorators:[(0,a.MZ)({type:Array})],key:"toLanguages",value:()=>[]},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"prevSelectedLang",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"disclaimerMessage",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:Boolean})],key:"userTranslationActive",value:()=>!1},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"detectedFromLang",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:String})],key:"detectedToLang",value:()=>""},{kind:"field",decorators:[(0,a.MZ)({type:Boolean})],key:"loadingModel",value:void 0},{kind:"field",decorators:[(0,a.MZ)({type:Boolean})],key:"sourceLanguageSupported",value:()=>!0},{kind:"field",decorators:[(0,a.P)("#lang-from")],key:"langFromDropdown",value:void 0},{kind:"field",decorators:[(0,a.P)("#lang-to")],key:"langToDropdown",value:void 0},{kind:"field",static:!0,key:"styles",value:()=>(0,i.AH)(p||(p=M(["\n .disclaimer {\n padding: 10px;\n border-radius: 8px;\n font-size: 12px;\n margin: 0 0 10px;\n background-color: rgba(255, 255, 255, 0.1);\n color: rgba(255, 255, 255, 0.9);\n }\n\n .disclaimer--warning {\n margin: 10px 0;\n background-color: rgba(255, 186, 8, 0.18);\n color: #ffe7a3;\n }\n "])))},{kind:"method",key:"connectedCallback",value:function(){var e,t,r,i,o;(e=n,t="connectedCallback",r=this,o=P(A(1&(i=3)?e.prototype:e),t,r),2&i&&"function"==typeof o?function(e){return o.apply(r,e)}:o)([]),this.dispatchEvent(new CustomEvent("connected"))}},{kind:"method",key:"render",value:function(){const e=this._statusWarning();return(0,i.qy)(g||(g=M(['<div class="app" style="margin-top: 5%;padding-right: 5px;">\n <div\n class="disclaimer"\n id="disclaimerMessage"\n >','</div>\n\n <div class="panel panel--to" style="padding: 0 10px;">\n <label>\n <span style="font-size: 12px;color: #ccc;">Translate To</span>\n <select id="lang-to" name="to" class="lang-select" style="display:block; width:100%;" @change="','">\n ','\n </select>\n </label>\n </div>\n\n <div class="panel panel--start" style="text-align: right;padding: 0 10px;/*! font-size: 18px; */margin-top: 10px;">\n <button class="start-translation-brn" @click="','" ?disabled=',">\n ",'\n </button>\n </div>\n\n <div class="panel panel--from" style="font-size: 12px;color: #ccc;text-align: center;padding: 8px 10px;">\n <details style="display: contents">\n <summary style="text-decoration: underline white; cursor:pointer; display:inline-block"> \n <i>\n Source: '," ",' \n </i> Change \n </summary>\n <select id="lang-from" name="from" class="lang-select" value=',' @change="','" style="width:65%; margin-top: 3%; margin-bottom: 3%">\n ','\n </select>\n </details>\n </div>\n <div class="footer" id="status" style="margin-top:5%">\n ','\n </div>\n\n <div class="lang-models-loading"> \n ',"\n </div>\n </div>"])),this.disclaimerMessage,this._onLangToChange,(0,w.Ul)(this.toLanguages,e=>e.name.toLowerCase()).map(e=>(0,i.qy)(f||(f=M(['<option value="','" \n ?selected=',"\n > "," </option>"])),e.code,e.code==this.detectedToLang,e.name?e.name:e.code)),this._toggleTranslation,!this.sourceLanguageSupported,this.userTranslationActive?"Stop Translating":"Translate",this._getLangName(this.detectedFromLang),this.prevSelectedLang?"":"(detected)",this.detectedFromLang,this._onLangFromChange,(0,w.Ul)(this.fromLanguages,e=>e.name.toLowerCase()).map(e=>(0,i.qy)(m||(m=M(['<option value="','"\n ?selected=',"\n >"," </option>"])),e.code,e.code==this.detectedFromLang,e.name?e.name:e.code)),e?(0,i.qy)(y||(y=M(['\n <div class="disclaimer disclaimer--warning">',"</div>\n "])),e):"",this._languageModelStatus())}},{kind:"method",key:"_onLangFromChange",value:function(e){const t=new CustomEvent("langFromChanged",{detail:{value:e.target.value},bubbles:!0,composed:!0});this.dispatchEvent(t),this._getSelectedLang("to")!==this._getSelectedLang("from")&&(this.prevSelectedLang=this._getSelectedLang("from")),this.loadingModel=!0,this.detectedFromLang=e.target.value}},{kind:"method",key:"_onLangToChange",value:function(e){const t=new CustomEvent("langToChanged",{detail:{value:e.target.value},bubbles:!0,composed:!0});this.dispatchEvent(t),this._getSelectedLang("from")!==e.target.value&&(this.prevSelectedLang=this._getSelectedLang("from")),this.loadingModel=!0,this.detectedToLang=e.target.value}},{kind:"method",key:"_getSelectedLang",value:function(e){const t="from"===e?this.langFromDropdown:this.langToDropdown;return t?t.value:""}},{kind:"method",key:"_getLangName",value:function(e){const t=[...this.fromLanguages,...this.toLanguages].find(t=>t.code===e);return(null==t?void 0:t.name)||(0,l._4)(e)||e}},{kind:"method",key:"_toggleTranslation",value:function(e){if(!this.sourceLanguageSupported)return;const t=new CustomEvent("toggleTranslation",{detail:{value:e.target.value},bubbles:!0,composed:!0});this.userTranslationActive=!this.userTranslationActive,this.dispatchEvent(t)}},{kind:"method",key:"_statusWarning",value:function(){return this.sourceLanguageSupported?this.detectedFromLang==this.detectedToLang?"Translate To language is the same as the Source language":"":"Translating from ".concat(this._getLangName(this.detectedFromLang)," is not supported")}},{kind:"method",key:"_languageModelStatus",value:function(){return this.userTranslationActive?this.loadingModel?(0,i.qy)(v||(v=M(['\n <ia-activity-indicator mode="processing" style="display:block; width: 40px; height: 40px; margin: 0 auto;"></ia-activity-indicator>\n <p>Downloading language model</p>\n ']))):(0,i.qy)(b||(b=M(["<p>Language model loaded</p>"]))):""}}]}}(function(e){j.initializeInstanceElements(e,z.elements)},B),z=j.decorateClass(function(e){for(var t=[],n=function(e){return"method"===e.kind&&e.key===o.key&&e.placement===o.placement},r=0;r<e.length;r++){var i,o=e[r];if("method"===o.kind&&(i=t.find(n)))if(L(o.descriptor)||L(i.descriptor)){if(C(o)||C(i))throw new ReferenceError("Duplicated methods ("+o.key+") can't be decorated.");i.descriptor=o.descriptor}else{if(C(o)){if(C(i))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+o.key+").");i.decorators=o.decorators}S(o,i)}else t.push(o)}return t}(H.d.map(T)),q),j.initializeClassElements(H.F,z.elements),j.runClassFinishers(H.F,z.finishers));var q,B,j,H,z},9748:(e,n,r)=>{r.d(n,{$x:()=>c,ND:()=>l,YH:()=>o,_4:()=>a}),r(4423),r(3792),r(3362),r(2953);const i={"zh-hans":"中文 (Zhōngwén)"};function o(e){if(!e)return null;if(e=e.toLocaleLowerCase(),i[e])return e;const t=s(e,["iso639_1"])||s(e,["iso639_2T"])||s(e,["iso639_2B","name","nativeName"]);return t?t.iso639_1:null}function a(e){if(!e)return null;if(e=e.toLocaleLowerCase(),i[e])return i[e];const t=s(e,["iso639_1"])||s(e,["iso639_2T"])||s(e,["iso639_2B","name","nativeName"]);return null!=t&&t.nativeName?t.nativeName.split(", ")[0]:null}function s(e,n){if(!e)return null;e=e.toLowerCase();for(const i of t)for(const t of n){var r;if(null!==(r=i[t])&&void 0!==r&&r.toLowerCase().split(", ").includes(e))return i}return null}function l(){try{return!!window.localStorage}catch(e){return!1}}const c=-1!=location.toString().indexOf("_debugReadAloud=true")},3991:(e,t,n)=>{n.d(t,{yc:()=>ce,bg:()=>X,lB:()=>ae});var r=n.cw(function(e,t){var r=n(3724),i=n(2106),o=n(5213),a=n(7979);r&&!o.correct&&(i(RegExp.prototype,"flags",{configurable:!0,get:a}),o.correct=!0)}),i=n.cw(function(e,t){var r=n(6518),i=n(9565),o=n(7476),a=n(3994),s=n(2529),l=n(7750),c=n(8014),d=n(655),u=n(8551),h=n(34),p=n(2195),g=n(788),f=n(1034),m=n(5966),y=n(6840),v=n(9039),b=n(8227),w=n(2293),k=n(7829),E=n(6682),x=n(1181),T=n(6395),S=b("matchAll"),C="RegExp String",L=C+" Iterator",_=x.set,R=x.getterFor(L),P=RegExp.prototype,A=TypeError,M=o("".indexOf),O=o("".matchAll),N=!!O&&!v(function(){O("a",/./)}),D=a(function(e,t,n,r){_(this,{type:L,regexp:e,string:t,global:n,unicode:r,done:!1})},C,function(){var e=R(this);if(e.done)return s(void 0,!0);var t=e.regexp,n=e.string,r=E(t,n);return null===r?(e.done=!0,s(void 0,!0)):e.global?(""===d(r[0])&&(t.lastIndex=k(n,c(t.lastIndex),e.unicode)),s(r,!1)):(e.done=!0,s(r,!1))}),F=function(e){var t,n,r,i=u(this),o=d(e),a=w(i,RegExp),s=d(f(i));return t=new a(a===RegExp?i.source:i,s),n=!!~M(s,"g"),r=!!~M(s,"u")||!!~M(s,"v"),t.lastIndex=c(i.lastIndex),new D(t,o,n,r)};r({target:"String",proto:!0,forced:N},{matchAll:function(e){var t,n,r,o,a=l(this);if(h(e)){if(g(e)&&(t=d(l(f(e))),!~M(t,"g")))throw new A("`.matchAll` does not allow non-global regexes");if(N)return O(a,e);if(void 0===(r=m(e,S))&&T&&"RegExp"===p(e)&&(r=F),r)return i(r,e,a)}else if(N)return O(a,e);return n=d(a),o=new RegExp(e,"g"),T?i(F,o,n):o[S](n)}}),T||S in P||y(P,S,F)}),o=n.cw(function(e,t){i()});n(4423),n(9463),n(3792),n(3362),n(4864),n(7495),r(),n(5440),n(2762),o(),n(2953),n(8408);var a=n(8965),s=n(1669);function l(e,t,n){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class c{constructor(e,t){l(this,"selecting",!1),l(this,"startedInSelector",!1),l(this,"target",null),l(this,"lastKnownFocusNode",null),l(this,"_onSelectionChange",()=>{const e=window.getSelection();if(!e)return;const t=function(e){if(!e.isCollapsed)return!1;for(let t=0;t<e.rangeCount;t++)if(!e.getRangeAt(t).collapsed)return!1;return!0}(e);if(!this.selecting&&e.toString()){const t=s(e.anchorNode).closest(this.selector)[0];if(!t)return;this.target=t,this.selecting=!0,this.lastKnownFocusNode=e.focusNode,this.handler("started",this.target)}this.selecting&&this.lastKnownFocusNode!=e.focusNode&&e.toString()&&!t&&(this.lastKnownFocusNode=e.focusNode,this.handler("changed",this.target)),!this.selecting||!t&&e.toString()&&s(e.anchorNode).closest(this.selector)[0]||(this.selecting=!1,this.lastKnownFocusNode=null,this.handler("cleared",this.target))}),this.selector=e,this.handler=t}attach(){document.addEventListener("selectionchange",this._onSelectionChange)}detach(){document.removeEventListener("selectionchange",this._onSelectionChange)}}var d,u,h,p,g,f,m,y,v,b,w,k,E,x,T,S,C,L=n(9880),_=n(7597),R=n(6054),P=n(6248),A=(n(790),n(395)),M=n(4297),O=n(1669);function N(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function D(e,t,n,r){var i=F();if(r)for(var o=0;o<r.length;o++)i=r[o](i);var a=t(function(e){i.initializeInstanceElements(e,s.elements)},n),s=i.decorateClass(function(e){for(var t=[],n=function(e){return"method"===e.kind&&e.key===o.key&&e.placement===o.placement},r=0;r<e.length;r++){var i,o=e[r];if("method"===o.kind&&(i=t.find(n)))if(j(o.descriptor)||j(i.descriptor)){if(B(o)||B(i))throw new ReferenceError("Duplicated methods ("+o.key+") can't be decorated.");i.descriptor=o.descriptor}else{if(B(o)){if(B(i))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+o.key+").");i.decorators=o.decorators}q(o,i)}else t.push(o)}return t}(a.d.map(I)),e);return i.initializeClassElements(a.F,s.elements),i.runClassFinishers(a.F,s.finishers)}function F(){F=function(){return e};var e={elementsDefinitionOrder:[["method"],["field"]],initializeInstanceElements:function(e,t){["method","field"].forEach(function(n){t.forEach(function(t){t.kind===n&&"own"===t.placement&&this.defineClassElement(e,t)},this)},this)},initializeClassElements:function(e,t){var n=e.prototype;["method","field"].forEach(function(r){t.forEach(function(t){var i=t.placement;if(t.kind===r&&("static"===i||"prototype"===i)){var o="static"===i?e:n;this.defineClassElement(o,t)}},this)},this)},defineClassElement:function(e,t){var n=t.descriptor;if("field"===t.kind){var r=t.initializer;n={enumerable:n.enumerable,writable:n.writable,configurable:n.configurable,value:void 0===r?void 0:r.call(e)}}Object.defineProperty(e,t.key,n)},decorateClass:function(e,t){var n=[],r=[],i={static:[],prototype:[],own:[]};if(e.forEach(function(e){this.addElementPlacement(e,i)},this),e.forEach(function(e){if(!B(e))return n.push(e);var t=this.decorateElement(e,i);n.push(t.element),n.push.apply(n,t.extras),r.push.apply(r,t.finishers)},this),!t)return{elements:n,finishers:r};var o=this.decorateConstructor(n,t);return r.push.apply(r,o.finishers),o.finishers=r,o},addElementPlacement:function(e,t,n){var r=t[e.placement];if(!n&&-1!==r.indexOf(e.key))throw new TypeError("Duplicated element ("+e.key+")");r.push(e.key)},decorateElement:function(e,t){for(var n=[],r=[],i=e.decorators,o=i.length-1;o>=0;o--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,i[o])(s)||s);e=l.element,this.addElementPlacement(e,t),l.finisher&&r.push(l.finisher);var c=l.extras;if(c){for(var d=0;d<c.length;d++)this.addElementPlacement(c[d],t);n.push.apply(n,c)}}return{element:e,finishers:r,extras:n}},decorateConstructor:function(e,t){for(var n=[],r=t.length-1;r>=0;r--){var i=this.fromClassDescriptor(e),o=this.toClassDescriptor((0,t[r])(i)||i);if(void 0!==o.finisher&&n.push(o.finisher),void 0!==o.elements){e=o.elements;for(var a=0;a<e.length-1;a++)for(var s=a+1;s<e.length;s++)if(e[a].key===e[s].key&&e[a].placement===e[s].placement)throw new TypeError("Duplicated element ("+e[a].key+")")}}return{elements:e,finishers:n}},fromElementDescriptor:function(e){var t={kind:e.kind,key:e.key,placement:e.placement,descriptor:e.descriptor};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),"field"===e.kind&&(t.initializer=e.initializer),t},toElementDescriptors:function(e){if(void 0!==e)return(t=e,function(e){if(Array.isArray(e))return e}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||function(e,t){if(e){if("string"==typeof e)return z(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?z(e,t):void 0}}(t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).map(function(e){var t=this.toElementDescriptor(e);return this.disallowProperty(e,"finisher","An element descriptor"),this.disallowProperty(e,"extras","An element descriptor"),t},this);var t},toElementDescriptor:function(e){var t=e.kind+"";if("method"!==t&&"field"!==t)throw new TypeError('An element descriptor\'s .kind property must be either "method" or "field", but a decorator created an element descriptor with .kind "'+t+'"');var n=J(e.key),r=e.placement+"";if("static"!==r&&"prototype"!==r&&"own"!==r)throw new TypeError('An element descriptor\'s .placement property must be one of "static", "prototype" or "own", but a decorator created an element descriptor with .placement "'+r+'"');var i=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var o={kind:t,key:n,placement:r,descriptor:Object.assign({},i)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(i,"get","The property descriptor of a field descriptor"),this.disallowProperty(i,"set","The property descriptor of a field descriptor"),this.disallowProperty(i,"value","The property descriptor of a field descriptor"),o.initializer=e.initializer),o},toElementFinisherExtras:function(e){return{element:this.toElementDescriptor(e),finisher:H(e,"finisher"),extras:this.toElementDescriptors(e.extras)}},fromClassDescriptor:function(e){var t={kind:"class",elements:e.map(this.fromElementDescriptor,this)};return Object.defineProperty(t,Symbol.toStringTag,{value:"Descriptor",configurable:!0}),t},toClassDescriptor:function(e){var t=e.kind+"";if("class"!==t)throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator created a class descriptor with .kind "'+t+'"');this.disallowProperty(e,"key","A class descriptor"),this.disallowProperty(e,"placement","A class descriptor"),this.disallowProperty(e,"descriptor","A class descriptor"),this.disallowProperty(e,"initializer","A class descriptor"),this.disallowProperty(e,"extras","A class descriptor");var n=H(e,"finisher");return{elements:this.toElementDescriptors(e.elements),finisher:n}},runClassFinishers:function(e,t){for(var n=0;n<t.length;n++){var r=(0,t[n])(e);if(void 0!==r){if("function"!=typeof r)throw new TypeError("Finishers must return a constructor.");e=r}}return e},disallowProperty:function(e,t,n){if(void 0!==e[t])throw new TypeError(n+" can't have a ."+t+" property.")}};return e}function I(e){var t,n=J(e.key);"method"===e.kind?t={value:e.value,writable:!0,configurable:!0,enumerable:!1}:"get"===e.kind?t={get:e.value,configurable:!0,enumerable:!1}:"set"===e.kind?t={set:e.value,configurable:!0,enumerable:!1}:"field"===e.kind&&(t={configurable:!0,writable:!0,enumerable:!0});var r={kind:"field"===e.kind?"field":"method",key:n,placement:e.static?"static":"field"===e.kind?"own":"prototype",descriptor:t};return e.decorators&&(r.decorators=e.decorators),"field"===e.kind&&(r.initializer=e.value),r}function q(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function B(e){return e.decorators&&e.decorators.length}function j(e){return void 0!==e&&!(void 0===e.value&&void 0===e.writable)}function H(e,t){var n=e[t];if(void 0!==n&&"function"!=typeof n)throw new TypeError("Expected '"+t+"' to be a function");return n}function z(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function U(e,t,n,r){var i=Z($(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof i?function(e){return i.apply(n,e)}:i}function Z(){return Z="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=$(e)););return e}(e,t);if(r){var i=Object.getOwnPropertyDescriptor(r,t);return i.get?i.get.call(arguments.length<3?e:n):i.value}},Z.apply(null,arguments)}function $(e){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},$(e)}function W(e,t,n){return(t=J(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function J(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var n=t.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:t+""}const V="BRhighlightStorage";class X{get selectMenuEnabled(){var e,t;return(null===(e=this.br.plugins.experiments)||void 0===e?void 0:e.isEnabled("copyLinkToHighlight"))||(null===(t=this.br.plugins.experiments)||void 0===t?void 0:t.isEnabled("annotateHighlight"))}constructor(e,t,n,r){let i=n.selectionElement;W(this,"options",{maxProtectedWords:200}),W(this,"selectMenu",void 0),W(this,"_onSelectionChange",(e,t)=>{if("started"===e)this.textSelectingMode(t);else if("cleared"===e)this.defaultMode(t);else if("changed"!==e)throw new Error("Unknown type ".concat(e))}),W(this,"_limitSelection",()=>{const e=window.getSelection();if(!e.rangeCount)return;const t=e.getRangeAt(0),n=!!t.startContainer.parentElement.closest(".BRcontainer"),r=!!t.endContainer.parentElement.closest(".BRcontainer");if(!n&&!r)return;if(!n||!r)return void e.removeAllRanges();const i=(0,M.eU)((0,M.nC)(K(t,"element"),e=>e.classList.contains(this.selectionElement[0].replace(".",""))),this.options.maxProtectedWords-1);if(!i||t.endContainer.parentNode==i)return;const o=document.createRange();o.setStart(t.startContainer,t.startOffset),o.setEnd(i.firstChild,i.textContent.length),e.removeAllRanges(),e.addRange(o)}),this.layer=e,this.br=t,this.selectionElement=i,this.selectionObserver=new c(this.layer,this._onSelectionChange),this.options.maxProtectedWords=r||200,this.selectMenu=new Y(t),this.selectMenu.className="br-select-menu__root"}init(){this.attach(),new c(this.layer,e=>{var t,n;"started"==e&&(null===(t=this.br.plugins.archiveAnalytics)||void 0===t||t.sendEvent("BookReader","SelectStart"),this.br.refs.$br.find(".BRpagecontainer--hasSelection").removeClass("BRpagecontainer--hasSelection"),O(window.getSelection().anchorNode).closest(".BRpagecontainer").addClass("BRpagecontainer--hasSelection"),this.mouseIsDown||this.showSelectMenu()),"changed"==e&&!this.mouseIsDown&&null!==(n=window.getSelection())&&void 0!==n&&n.toString()&&this.showSelectMenu(),"cleared"==e&&this.hideSelectMenu()}).attach()}attach(){this.selectionObserver.attach(),this.br.protected&&(document.addEventListener("selectionchange",this._limitSelection),O(document.body).on("contextmenu dragstart copy",e=>{const t=document.getSelection();if(null!=t&&t.toString()&&O(this.layer).toArray().some(e=>t.containsNode(e,!0)))return e.preventDefault(),!1}))}detach(){this.selectionObserver.detach(),this.br.protected&&document.removeEventListener("selectionchange",this._limitSelection)}interceptCopy(e){e[0].addEventListener("copy",e=>{const t=document.getSelection();e.clipboardData.setData("text/plain",t.toString()),e.preventDefault()})}stopPageFlip(e){const t=e.find(this.layer);t.length&&(t.each((e,t)=>this.defaultMode(t)),this.br.protected||this.interceptCopy(e))}defaultMode(e){const t=O(e).closest(".BRpagecontainer");e.style.pointerEvents="none",t.find("img").css("pointer-events","auto"),O(e).off(".textSelectPluginHandler");const n=this.mouseIsDown;let r=this.mouseIsDown;n&&(e.style.pointerEvents="auto"),O(e).on("mousedown.textSelectPluginHandler",e=>{this.mouseIsDown=!0,O(e.target).is(this.selectionElement.join(", "))&&e.stopPropagation()}),O(e).on("mouseup.textSelectPluginHandler",t=>{this.mouseIsDown=!1,e.style.pointerEvents="none",r&&(r=!1,t.stopPropagation())})}textSelectingMode(e){const t=O(e).closest(".BRpagecontainer");e.style.pointerEvents="all",t.find("img").css("pointer-events","none"),O(e).off(".textSelectPluginHandler"),O(e).on("mousedown.textSelectPluginHandler",e=>{1==e.which&&(this.mouseIsDown=!0,e.stopPropagation())}),O(e).on("mouseup.textSelectPluginHandler",e=>{this.mouseIsDown=!1,1==e.which&&(e.stopPropagation(),this.showSelectMenu())})}showSelectMenu(){this.selectMenuEnabled&&(this.selectMenu.copyLinkToHighlightEnabled=this.br.plugins.experiments.isEnabled("copyLinkToHighlight"),this.selectMenu.highlightAnnotationEnabled=this.br.plugins.experiments.isEnabled("annotateHighlight"),this.selectMenu.isConnected||document.body.append(this.selectMenu),this.selectMenu.open?this.selectMenu.repositionToSelection():this.selectMenu.show())}hideSelectMenu(){this.selectMenu.hide()}}function K(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"text+element";return function*(){const n=e.startContainer,r=e.endContainer;let i=!1;const o=e=>"text"===t&&e.nodeType===Node.TEXT_NODE||"element"===t&&e.nodeType===Node.ELEMENT_NODE||"text+element"===t;yield*function e(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=n.children,s=void 0===a||a,l=n.parents,c=void 0===l||l,d=n.siblings,u=void 0===d||d;return function*(){if(t===r)return i=!0,void(o(t)&&(yield t));if(o(t)&&(yield t),!(s&&t.firstChild&&(yield*e(t.firstChild,{children:!0,parents:!1,siblings:!0}),i))){if(u)for(let n=t.nextSibling;n;n=n.nextSibling)if(yield*e(n,{children:!0,parents:!1,siblings:!1}),i)return;c&&t.parentNode&&(yield*e(t.parentNode,{children:!1,parents:!0,siblings:!0}))}}()}(n)}()}D([(0,R.EM)("br-menu-option")],function(e,t){class n extends t{constructor(){super(...arguments),e(this)}}return{F:n,d:[{kind:"field",decorators:[(0,R.MZ)({type:String})],key:"icon",value:()=>""},{kind:"field",decorators:[(0,R.MZ)({type:String})],key:"label",value:()=>""},{kind:"field",key:"temporaryText",value:()=>null},{kind:"field",decorators:[(0,R.MZ)({type:Number,attribute:"temporary-text-duration"})],key:"temporaryTextDuration",value:()=>1200},{kind:"field",decorators:[(0,R.MZ)({type:String,attribute:"aria-label"})],key:"ariaLabel",value:()=>""},{kind:"field",decorators:[(0,R.MZ)({type:Boolean,attribute:"live-label"})],key:"liveLabel",value:()=>!1},{kind:"field",decorators:[(0,R.MZ)({type:Boolean})],key:"temporaryTextVisible",value:()=>!1},{kind:"field",key:"temporaryTextTimeoutId",value:()=>null},{kind:"method",key:"createRenderRoot",value:function(){return this}},{kind:"method",key:"disconnectedCallback",value:function(){null!=this.temporaryTextTimeoutId&&(window.clearTimeout(this.temporaryTextTimeoutId),this.temporaryTextTimeoutId=null),U(n,"disconnectedCallback",this,3)([])}},{kind:"method",key:"showTemporaryText",value:function(e){null!=e&&e.trim()&&(this.temporaryText=e,this.temporaryTextVisible=!0,null!=this.temporaryTextTimeoutId&&window.clearTimeout(this.temporaryTextTimeoutId),this.temporaryTextTimeoutId=window.setTimeout(()=>{this.temporaryTextVisible=!1,this.temporaryText=null,this.temporaryTextTimeoutId=null},this.temporaryTextDuration))}},{kind:"method",key:"renderIcon",value:function(){return"share"===this.icon?(0,_.qy)(d||(d=N(['<ia-icon-share class="br-select-menu__icon" aria-hidden="true"></ia-icon-share>']))):"edit-pencil"===this.icon?(0,_.qy)(u||(u=N(['<ia-icon-edit-pencil class="br-select-menu__icon" aria-hidden="true"></ia-icon-edit-pencil>']))):"ellipses"===this.icon?(0,_.qy)(h||(h=N(['<ia-icon-ellipses class="br-select-menu__icon" aria-hidden="true"></ia-icon-ellipses>']))):""}},{kind:"method",key:"render",value:function(){var e,t;const n=null!==(e=this.label)&&void 0!==e?e:"",r=!!this.temporaryText,i=r?this.temporaryText:n,o=r&&this.temporaryTextVisible,a=o?i:n,s=null===(t=this.ariaLabel)||void 0===t?void 0:t.trim(),l=s&&s!==a.trim()?s:void 0,c=n.length>=i.length?n:i;return(0,_.qy)(p||(p=N(['\n <button\n type="button"\n class="br-select-menu__option"\n role="menuitem"\n aria-label=',"\n >\n ","\n ","\n </button>\n "])),(0,P.J)(l),this.renderIcon(),r||n?r?(0,_.qy)(g||(g=N(['\n <span class="br-select-menu__label-wrap" style="display: inline-flex; position: relative; align-items: center;">\n <span\n class="br-select-menu__label"\n style="visibility: hidden;"\n aria-hidden="true"\n >','</span>\n <span\n class="br-select-menu__label"\n style="position: absolute; inset: 0; display: inline-flex; align-items: center;"\n aria-live=',"\n >","</span>\n </span>\n "])),c,this.liveLabel?"polite":"off",o?i:n):(0,_.qy)(f||(f=N(['\n <span class="br-select-menu__label" aria-live=',">","</span>\n "])),this.liveLabel?"polite":"off",n):"")}}]}},_.WF);let Y=D([(0,R.EM)("br-select-menu")],function(e,t){class n extends t{constructor(t){super(),e(this),this.br=t}}return{F:n,d:[{kind:"field",key:"br",value:void 0},{kind:"field",decorators:[(0,R.MZ)({type:Boolean,reflect:!0})],key:"showExtended",value:()=>!1},{kind:"field",decorators:[(0,R.P)("#br-select-copy-link-option")],key:"copyLinkOption",value:void 0},{kind:"field",decorators:[(0,R.MZ)({type:Boolean,reflect:!0})],key:"open",value:()=>!1},{kind:"field",decorators:[(0,R.MZ)({type:Boolean})],key:"copyLinkToHighlightEnabled",value:()=>!0},{kind:"field",decorators:[(0,R.MZ)({type:Boolean})],key:"highlightAnnotationEnabled",value:()=>!0},{kind:"method",key:"createRenderRoot",value:function(){return this}},{kind:"field",key:"_scrollTimeoutId",value:()=>null},{kind:"field",key:"_onScroll",value(){return()=>{this.classList.add("br-select-menu__root--scrolling"),null!=this._scrollTimeoutId&&clearTimeout(this._scrollTimeoutId),this._scrollTimeoutId=window.setTimeout(()=>{this._scrollTimeoutId=null,this.repositionToSelection(),this.classList.remove("br-select-menu__root--scrolling")},150)}}},{kind:"method",key:"connectedCallback",value:function(){U(n,"connectedCallback",this,3)([]),this.setAttribute("role","menu"),this.setAttribute("aria-label","Text selection actions"),this.setAttribute("aria-orientation","vertical")}},{kind:"method",key:"disconnectedCallback",value:function(){U(n,"disconnectedCallback",this,3)([]),window.removeEventListener("scroll",this._onScroll,{capture:!0}),null!=this._scrollTimeoutId&&(clearTimeout(this._scrollTimeoutId),this._scrollTimeoutId=null)}},{kind:"method",key:"renderCopyLinkToHighlightOption",value:function(){return(0,_.qy)(m||(m=N(['\n <br-menu-option\n id="br-select-copy-link-option"\n @mousedown=',"\n @click=",'\n icon="share"\n label="Copy Link to Highlight"\n live-label\n ></br-menu-option>\n '])),e=>e.preventDefault(),this.handleCopyLinkToHighlight)}},{kind:"method",key:"renderRemoveOption",value:function(){return(0,_.qy)(y||(y=N(["\n <br-menu-option\n @click=",'\n icon="share"\n label="Delete Highlight and Annotation"\n ></br-menu-option>\n '])),this.handleDeleteHighlight)}},{kind:"method",key:"renderAddAnnotationOption",value:function(){return(0,_.qy)(v||(v=N(["\n <br-menu-option\n @click=",'\n icon="edit-pencil"\n label="Annotate"\n ></br-menu-option>\n '])),this.handleAddAnnotation)}},{kind:"method",key:"renderHighlightOption",value:function(){return(0,_.qy)(b||(b=N(["\n <br-menu-option\n @click=",'\n icon="edit-pencil"\n label="Highlight Selection"\n ></br-menu-option>\n '])),this.handleHighlightSave)}},{kind:"method",key:"renderShowMoreOption",value:function(){return(0,_.qy)(w||(w=N(['\n <br-menu-option\n id="br-select-more"\n @mousedown=',"\n @click=",'\n icon="ellipses"\n aria-label="Show more options"\n ></br-menu-option>\n '])),e=>e.preventDefault(),this.toggleExtendedMenu)}},{kind:"method",key:"renderLocalStorageOptions",value:function(){return(0,_.qy)(k||(k=N(["\n <br-menu-option\n @click=",'\n icon="share"\n label="Load Highlights"\n ></br-menu-option>\n <br-menu-option\n @click=','\n icon="share"\n label="Remove Stored Highlights"\n ></br-menu-option>'])),this.renderSavedHighlights,()=>{window.localStorage.removeItem(V)})}},{kind:"method",key:"renderDefaultOptions",value:function(){return(0,_.qy)(E||(E=N(["\n ","\n ","\n ","\n "])),this.copyLinkToHighlightEnabled?this.renderCopyLinkToHighlightOption():"",this.highlightAnnotationEnabled&&!this.nodesForRemoval?this.renderHighlightOption():"",this.nodesForRemoval?this.renderRemoveOption():"")}},{kind:"method",key:"renderExtendedOptions",value:function(){return(0,_.qy)(x||(x=N(["\n ","\n ","\n "])),this.renderDefaultOptions(),this.renderLocalStorageOptions())}},{kind:"method",key:"render",value:function(){var e;const t=null===(e=this.br.plugins.experiments)||void 0===e?void 0:e.isEnabled("annotateHighlight");return(0,_.qy)(T||(T=N(["\n ","\n ","\n "])),this.showExtended?this.renderExtendedOptions():this.renderDefaultOptions(),!this.showExtended&&t?this.renderShowMoreOption():"")}},{kind:"method",key:"handleCopyLinkToHighlight",value:async function(e){var t;e.preventDefault();const n=window.getSelection(),r=n.getRangeAt(0),i=this.getNodeTextLayer(r.startContainer);if(!i)return void console.warn("No text layer found for selection");const o=ce.fromSelection(n,[i]),a=o.toUrl();await navigator.clipboard.writeText(a),null===(t=this.copyLinkOption)||void 0===t||t.showTemporaryText("Copied!"),this.br.trigger("copyLinkToHighlight",{textFragment:o,link:a})}},{kind:"method",key:"toggleExtendedMenu",value:function(e){e.preventDefault(),this.showExtended=!this.showExtended}},{kind:"method",key:"getNodeTextLayer",value:function(e){var t;if(!e)return null;const n=e instanceof Element?e:e.parentElement;return null!==(t=null==n?void 0:n.closest(".BRtextLayer"))&&void 0!==t?t:null}},{kind:"method",key:"handleHighlightSave",value:function(){const e=window.getSelection(),t="backward"===e.direction?e.focusNode.parentElement:e.anchorNode.parentElement,n=this.getNodeTextLayer(t),r=ce.fromSelection(e,[n.parentElement]);r.uuid="id-".concat(crypto.randomUUID().split("-")[4]);const i=this.loadHighlightsFromLocalStorage();i.push(r),this.saveToLocalStorage(i),this.renderSavedHighlights()}},{kind:"method",key:"handleAddAnnotation",value:function(e){}},{kind:"method",key:"handleDeleteHighlight",value:function(){if(this.nodesForRemoval){const e=le(this.nodesForRemoval[0]);for(const e of this.nodesForRemoval){const t=e.textContent,n=e.parentElement;n.classList.contains("BRwordElement")||n.classList.contains("BRspace")?(e.remove(),n.textContent=t):console.log("This element did not match removal criteria:",n,e)}this.deleteHighlight(e),this.clearNodesForRemoval()}else console.log("there is nothing to remove")}},{kind:"method",key:"deleteHighlight",value:function(e){const t=this.loadHighlightsFromLocalStorage();for(let n=0;n<t.length;n++)if(t[n].uuid===e)return t.splice(n,1),void this.saveToLocalStorage(t)}},{kind:"method",key:"saveToLocalStorage",value:function(e){window.localStorage.setItem(V,JSON.stringify(e.map(e=>e.toJSON())))}},{kind:"method",key:"loadHighlightsFromLocalStorage",value:function(){return JSON.parse(window.localStorage.getItem(V)||"[]").map(e=>ce.fromJSON(e))}},{kind:"method",key:"renderSavedHighlights",value:function(){for(const e of this.loadHighlightsFromLocalStorage()){const t=this.br.$(".pagediv".concat(e.pageIndex," .BRtextLayer"))[0];t&&(ae(t,e),O(t).off("mouseup.BRHighlightClick").on("mouseup.BRHighlightClick",e=>{e.target.classList.contains("BRhighlight")&&(e.stopPropagation(),this.handleHighlightClick(e.target))}))}}},{kind:"method",key:"handleHighlightClick",value:function(e){const t=this.getNodeTextLayer(e),n=le(e),r=t.querySelectorAll(".".concat(n)),i=r[0],o=r[r.length-1],a=document.createRange();a.setStart(i,0),a.setEnd(o,1);const s=window.getSelection();s.removeAllRanges(),s.addRange(a),this.show()}},{kind:"method",key:"repositionToSelection",value:function(){const e=window.getSelection().getRangeAt(0).getBoundingClientRect(),t=(0,A.un)()||(0,A.m0)(),n=(0,A.m0)()?25:(0,A.un)()?15:10,r=t?60:0,i=(e.top<r?e.bottom+r:e.bottom)+n,o=Math.max(10,i)+window.scrollY,a=this.getBoundingClientRect().width,s=document.documentElement.clientWidth,l=a>e.width?e.left+e.width/2-a/2:e.left,c=(0,L.qE)(l,10,s-a-10)+window.scrollX;this.style.top="".concat(o,"px"),this.style.left="".concat(c,"px")}},{kind:"method",key:"show",value:async function(){var e;null!==(e=this.br.plugins.translate)&&void 0!==e&&e.userToggleTranslate||(this.style.zIndex="1",this.style.position="absolute",this.open=!0,this.classList.remove("br-select-menu__root--scrolling"),window.removeEventListener("scroll",this._onScroll,{capture:!0}),window.addEventListener("scroll",this._onScroll,{capture:!0,passive:!0}),await this.updateComplete,this.repositionToSelection(),this.clearNodesForRemoval())}},{kind:"method",key:"hide",value:function(){this.open&&(this.showExtended=!1,this.open=!1,window.removeEventListener("scroll",this._onScroll,{capture:!0}),this.clearNodesForRemoval())}},{kind:"field",key:"clearNodesForRemoval",value(){return()=>{this.nodesForRemoval=null,this.requestUpdate()}}}]}},_.WF);function G(e,t){t=t.trim();const n=new RegExp(String.raw(S||(S=N(["^(S+(s+|$)){1,","}"],["^(\\S+(\\s+|$)){1,","}"])),e)),r=t.match(n);return r?r[0].trim():""}function Q(e,t){t=t.trim();const n=new RegExp(String.raw(C||(C=N(["((^|s+)S+){1,","}s*?$"],["((^|\\s+)\\S+){1,","}\\s*?$"])),e)),r=t.match(n);return r?r[0].trim():""}function ee(e){for(;e.firstChild;)e=e.firstChild;return e}function te(e){for(;e.lastChild;)e=e.lastChild;return e}function ne(e){return e.replace(/(:|-,|,-|,|\n)/g,e=>1===e.length?" ":" ")}function re(e,t,n){let r=(arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}).normalize,i=void 0===r?e=>e:r;if(!n.length)return;const o=n[0]===t.startContainer?t.startOffset:0,a=i(oe(t)),s=i(n[0].textContent.slice(0,o)).length,l=new RegExp(e.source,e.flags.includes("g")?e.flags:"".concat(e.flags,"g")),c=Array.from(a.matchAll(l)).map(e=>{const t=ie(s+e.index,n,!1,{normalize:i}),r=ie(s+e.index+e[0].length,n,!0,{normalize:i});if(!t||!r)return void console.warn("Could not find boundary points for regex match, skipping this match",{match:e,start:t,end:r});const o=new Range;return o.setStart(t.node,t.offset),o.setEnd(r.node,r.offset),o}).filter(e=>!!e);return null!=c&&c.length?c:void 0}function ie(e,t,n){let r=(arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}).normalize,i=void 0===r?e=>e:r;const o=e;let a=0;for(const e of t){const t=e.textContent||"",r=i(t),s=a;if(s+r.length+(n?1:0)>o){const a=o-s;let l=Math.min(a,t.length);const c=n?r.substring(0,a):r.substring(a);let d=i(n?t.substring(0,a):t.substring(a));const u=(n?-1:1)*(c.length>d.length?-1:1);for(;l>=0&&l<=t.length;){if(d.length===c.length)return{node:e,offset:l};l+=u,d=i(n?t.substring(0,l):t.substring(l))}}a+=r.length}}function oe(e){const t=Array.from((0,M.nC)(K(e,"text"),se));let n=t.map(e=>e.textContent).join("");const r=t[0],i=t[t.length-1];return e.startContainer===r&&(n=n.substring(e.startOffset)),e.endContainer===i&&(n=n.substring(0,n.length-(i.textContent.length-e.endOffset))),n}function ae(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;const r=ee(e),i=te(e),o=new Range;o.setStart(r,0),o.setEnd(i,i.textContent.length);const a=Array.from((0,M.nC)(K(o,"text"),se)),s=re(t.toRegExp({context:!0}),o,a,{normalize:ne});if(!s)return void console.warn("Could not find quote with context in page");const l=Array.from((0,M.nC)(K(s[0],"text"),se)),c=re(t.toRegExp({context:!1}),s[0],l,{normalize:ne});if(!c)throw new Error("Could not find quote in page");const d=ee(c[0].startContainer),u=ee(c[0].endContainer),h=new Range;return h.setStart(d,0),h.setEnd(u,u.textContent.length),d.parentElement.classList.contains("BRhighlight")||u.parentElement.classList.contains("BRhighlight")?void 0:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:()=>document.createElement("mark");if(e.startContainer.nodeType!=Node.TEXT_NODE||e.endContainer.nodeType!=Node.TEXT_NODE)return[];if(e.startContainer===e.endContainer){const n=t();return e.surroundContents(n),[n]}const n=e.startContainer,r=e.cloneRange();r.setEndAfter(n);const i=e.endContainer,o=e.cloneRange();o.setStartBefore(i);const a=[];e.setStartAfter(n),e.setEndBefore(i);const s=document.createTreeWalker(e.commonAncestorContainer,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,{acceptNode:function(t){return e.intersectsNode(t)?t.nodeType===Node.TEXT_NODE?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP:NodeFilter.FILTER_REJECT}});let l=s.nextNode();for(;l;){if(l.nodeType===Node.TEXT_NODE){const e=t();l.parentNode.insertBefore(e,l),e.appendChild(l),a.push(e)}l=s.nextNode()}const c=t();r.surroundContents(c);const d=t();return o.surroundContents(d),[c,...a,d]}(h,()=>{const e=document.createElement("mark");return e.classList.add("BRhighlight"),n&&e.classList.add(n),t.uuid&&e.classList.add(t.uuid),e})}function se(e){var t;return!(null!==(t=e.previousElementSibling)&&void 0!==t&&t.classList.contains("BRspace"))}function le(e){if(!e)return null;const t=Array.from(null==e?void 0:e.classList).filter(e=>{if(e.slice(0,2).includes("id"))return e});return t.length?t[0]:null}class ce{constructor(e){let t=e.prefix,n=e.quote,r=e.quoteStart,i=e.quoteEnd,o=e.suffix,a=e.pageNumber,s=e.pageIndex,l=e.uuid;this.prefix=t,this.quote=null!=n?n:null,this.quoteStart=null!=r?r:null,this.quoteEnd=null!=i?i:null,this.suffix=o,this.pageNumber=a,this.pageIndex=s,this.uuid=null!=l?l:null}static fromString(e,t,n){const r=e.match(/^(?:(.*?):)?(?:(.*?)-,)?(.*?)(?:,-(.*))?$/);if(!r)throw new Error("Invalid text fragment format: ".concat(e));const i=r[1]||null,o=r[2]||null,a=(r[3]||"").split(",");let s=null,l=null,c=null;if(1===a.length)s=a[0];else{if(2!==a.length)throw new Error("Invalid text fragment quote format: ".concat(e));l=a[0],c=a[1]}const d=r[4]||null,u=i?t.getPageIndex(i):n;if("number"!=typeof u)throw new Error("Could not determine page index for text fragment with page number ".concat(i));if(!(s||l&&c))throw new Error("Invalid text fragment quote format: ".concat(e));return new ce({prefix:o,quote:s,quoteStart:l,quoteEnd:c,suffix:d,pageNumber:i,pageIndex:u})}toUrl(){const e=new URLSearchParams({text:this.toNormalizedString()}),t=window.location,n=encodeURIComponent(this.pageNumber||"n".concat(this.pageIndex));if(/^#\/?page\//.test(t.hash))return"".concat(t.origin).concat(t.pathname,"?").concat(e,"#page/").concat(n);const r=t.pathname.replace(/\/page\/.*/,"").replace(/\/+$/,"");return"".concat(t.origin).concat(r,"/page/").concat(n,"?").concat(e)}toNormalizedString(){const e=e=>function(e){return e.replace(/\s+/g," ").trim()}(ne(e).trim());let t=this.pageNumber?this.pageNumber:"n".concat(this.pageIndex);t+=":",this.prefix&&(t+=e(this.prefix),t+="-,");const n=this.quote?e(this.quote):null;let r=null;if(n&&n.length>80&&(n.match(/\S+/g)||[]).length>=6){const e=G(3,n),t=Q(3,n);e&&t&&(r={quoteStart:e,quoteEnd:t})}if(n&&!r)t+=n;else if(r)t+="".concat(r.quoteStart,",").concat(r.quoteEnd);else{if(!this.quoteStart||!this.quoteEnd)throw new Error("Text fragment requires either a quote or quoteStart/quoteEnd");t+="".concat(this.quoteStart,",").concat(this.quoteEnd)}return this.suffix&&(t+=",-",t+=e(this.suffix)),t}toRegExp(){let e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}).context,t=void 0!==e&&e;const n=this.quote?[this.quote]:[this.quoteStart,this.quoteEnd];t&&(this.prefix&&(n[0]=this.prefix+" "+n[0]),this.suffix&&(n[n.length-1]=n[n.length-1]+" "+this.suffix));const r=e=>RegExp.escape(ne(e)).replace(/(\\x20)+/g,"\\s+");return 1===n.length?new RegExp(r(n[0]),"gi"):new RegExp(r(n[0])+"[\\s\\S]*?"+r(n[1]),"gi")}toJSON(){return{prefix:this.prefix,quote:this.quote,quoteStart:this.quoteStart,quoteEnd:this.quoteEnd,suffix:this.suffix,pageNumber:this.pageNumber,pageIndex:this.pageIndex,uuid:this.uuid}}static fromJSON(e){return new ce(e)}static fromSelection(e,t){var n,r;const i=e.getRangeAt(0),o=new Range,s=te(i.startContainer),l=ee(i.endContainer);o.setStart(s,0),o.setEnd(l,0==i.endOffset?0:null!==(n=null===(r=l.textContent)||void 0===r?void 0:r.length)&&void 0!==n?n:0);const c=document.createRange();c.setStart(ee(t[0]),0),c.setEnd(s,0);const d=document.createRange();d.setStart(l,o.endOffset);const u=te(t[t.length-1]);d.setEnd(u,Math.max(0,u.textContent.length-1));const h=oe(c);let p=Q(3,h),g=(0,a.rj)(p);const f=oe(d);let m=G(3,f),y=(0,a.rj)(m);g<3&&(m=G(6-g,f),y=(0,a.rj)(m)),y<3&&(p=Q(6-y,h),g=(0,a.rj)(p));const v=oe(o),b=s.parentElement.closest(".BRpagecontainer");return new ce({quote:v,prefix:p,suffix:m,pageNumber:b.getAttribute("data-page-num"),pageIndex:parseFloat(b.getAttribute("data-index"))})}}},5369:(e,t,n)=>{n.d(t,{l:()=>r}),n(3792),n(2953);class r{constructor(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10;this.maxSize=e,this.entries=[]}add(e){this.entries.length>=this.maxSize&&this.entries.shift(),this.entries.push(e)}}},4297:(e,t,n)=>{function r(e,t){let n=0;for(const r of e){if(n==t)return r;n++}}function*i(e,t){for(const n of e)t(n)&&(yield n)}function*o(e,t){for(const n of e)yield t(n)}function*a(e){let t,n,r;for(const i of e)void 0!==n&&(r=i,yield[t,n,r]),t=n,n=i,r=void 0;void 0!==n&&(yield[t,n,r])}function*s(e,t){const n=e[Symbol.iterator](),r=t[Symbol.iterator]();for(;;){const e=n.next(),t=r.next();if(e.done&&t.done)return;if(e.done||t.done)throw new Error("zip: one of the iterators is done");yield[e.value,t.value]}}n.d(t,{Px:()=>o,eU:()=>r,nC:()=>i,pp:()=>a,yU:()=>s}),n(3792),n(2953)},8965:(e,t,n)=>{function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function i(e){const t=e.match(/\S+/g);return t?t.length:0}function o(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:a;return null==e?void 0:e.replace(/\{\{([^}]*?)\}\}/g,(e,o)=>{if(!o)return e;const a=function(e){if(Array.isArray(e))return e}(c=o.split("|").map(e=>e.trim()))||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(c)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(c)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),s=a[0],l=r(a).slice(1);var c;if(!(s in n)&&!(s in t))return e;const d=s in n?n[s]:s in t?t[s]:null;return l.map(e=>i[e]).reduce((e,t)=>t(e),d&&d.toString())})}n.d(t,{gT:()=>o,rj:()=>i}),n(9463),n(3792),n(2712),n(7495),n(5440),n(2762),n(2953);const a={urlencode:encodeURIComponent}}};import{__webpack_require__ as n}from"../ia-bookreader.js";n.C({__webpack_esm_ids__,__webpack_esm_modules__});var r=n(271);const i=r.L,o=r.U;export{i as BrTranslatePanel,o as TranslatePlugin};
|
|
2
2
|
//# sourceMappingURL=plugin.translate.js.map
|