@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{default as e}from"iso-language-codes";import"@internetarchive/icon-share";import"@internetarchive/icon-ellipses";export const __webpack_esm_ids__=[326];export const __webpack_esm_modules__={5703:(e,t,n)=>{var r=n(1354),o=n.n(r),i=n(6314),a=n.n(i)()(o());a.push([e.id,'.BRtextLayer,.BRtranslateLayer{z-index:2;position:absolute;top:0;left:0;color:rgba(0,0,0,0);transform-origin:0 0;pointer-events:none;cursor:text}.BRtextLayer{mix-blend-mode:multiply}.BRtranslateLayer{hyphens:auto}.BRparagraphElement{margin:0;cursor:text;font-family:Georgia,serif;line-height:0}.BRlineElement{pointer-events:all;white-space:nowrap;display:inline-block}.BRtextLayer[dir=ltr] .BRlineElement{margin-right:100%}.BRtextLayer[dir=rtl] .BRlineElement{margin-left:100%}.BRwordElement::selection,.BRspace::selection,.BRparagraphElement::selection,.BRparagraphElement br::selection{background:hsla(210,74%,62%,.4)}.BRwordElement::-moz-selection,.BRspace::-moz-selection,.BRparagraphElement::-moz-selection,.BRparagraphElement br::-moz-selection{background:hsla(210,74%,62%,.4);color:rgba(0,0,0,0)}.BRtranslateLayer ::selection{background:hsla(210,74%,62%,.4)}.BRtranslateLayer ::-moz-selection{background:hsla(210,74%,62%,.4)}.BRparagraphElement br{visibility:hidden}.BRwordElement--hyphen::after{content:"-"}.BRsmooth-zooming .BRpagecontainer:not(.BRpagecontainer--hasSelection):not(:has(hypothesis-highlight)):not(:has(.BRhighlight)) .BRtextLayer,.BRscrolling-active .BRpagecontainer:not(.BRpagecontainer--hasSelection):not(:has(hypothesis-highlight)):not(:has(.BRhighlight)) .BRtextLayer{display:none}.BRmode1up .BRpagecontainer:not(.BRpage-visible) .BRtextLayer{display:none}.BRpagecontainer img{-webkit-user-select:none;-moz-user-select:none;user-select:none}.BRtextLayer:has([_istranslated="1"],msreadoutspan){mix-blend-mode:normal}.BRwordElement[_istranslated="1"],.BRwordElement[_msttexthash],.BRspace[_istranslated="1"],.BRspace[_msttexthash]{color:#000;letter-spacing:unset !important}.BRlineElement:has([_istranslated="1"],[_msttexthash]){background:rgba(248,237,192,.8);backdrop-filter:blur(8px);color:#000;text-align:justify;width:inherit}.BRlineElement:has([_istranslated="1"],[_msttexthash]):not(:nth-last-child(2)){text-align-last:justify}.BRlineElement[_msttexthash]{word-spacing:unset !important}.BRtranslateLayer .BRparagraphElement{pointer-events:auto;overflow-y:auto;background:rgba(248,237,192,.8);backdrop-filter:blur(8px);color:#000;line-height:1em;text-align:justify}.BRtranslateLayer .BRparagraphElement .BRlineElement{white-space:break-spaces;display:inline-block}.BRtextLayer.showingTranslation{display:none}.BRtranslateLayer .BRparagraphElement.BRtranslateHidden{display:none}.br-select-menu__root{display:none;color:#fff;color-scheme:dark;padding:2px;overflow:hidden;opacity:1;transition:opacity .2s;gap:5px}.br-select-menu__root[open]{display:flex}.br-select-menu__root[showextended]{display:block;gap:0px;background-color:#333;border-radius:10px}@starting-style{.br-select-menu__root{opacity:0}}.br-select-menu__root--scrolling{opacity:0;pointer-events:none}.br-select-menu__option{--iconWidth: 15px;--iconHeight: 15px;--iconFillColor: currentColor;background:rgba(0,0,0,0);display:flex;align-items:center;border-radius:25px;font-family:inherit;color:inherit;border:0;cursor:pointer;text-wrap:nowrap;background-color:#333;position:relative}@media(pointer: coarse)and (hover: none){.br-select-menu__option{padding:4px 8px}#br-select-more .br-select-menu__option{padding:4px}}.br-select-menu__option:hover:after{position:absolute;left:2px;right:2px;top:2px;bottom:2px;content:"";pointer-events:none;background-color:rgba(255,255,255,.1);border-radius:23px}.br-select-menu__root[showextended] .br-select-menu__option{width:100%}.br-select-menu__root[showextended] .br-select-menu__option:hover:after{border-radius:8px}.br-select-menu__icon{display:block;flex-shrink:0;width:17px;height:17px;padding:2px}.br-select-menu__label{margin-left:4px;font-size:12px;margin-right:4px}@media(hover: hover){.br-select-menu__option{padding:4px}.br-select-menu__label{width:0px;margin:0;opacity:0;interpolate-size:allow-keywords;transition:width .2s}.br-select-menu__root:hover .br-select-menu__label{width:auto;margin:0 4px;opacity:1}}.BRtextLayer .BRhighlight{background-color:#ff0;pointer-events:all;color:rgba(0,0,0,0)}@keyframes highlightTargetFlash{to{background-color:hsl(45,80%,66%)}}.BRtextLayer .BRhighlight--target-text,.BRtextLayer ::target-text{background-color:hsla(45,80%,66%,.6);color:rgba(0,0,0,0);animation:highlightTargetFlash 600ms 1 reverse}',"",{version:3,sources:["webpack://./src/css/_TextSelection.scss"],names:[],mappings:"AAAA,+BACI,SAAA,CACA,iBAAA,CACA,KAAA,CACA,MAAA,CACA,mBAAA,CACA,oBAAA,CAEA,mBAAA,CACA,WAAA,CAGJ,aACI,uBAAA,CAGJ,kBACI,YAAA,CAGJ,oBACI,QAAA,CACA,WAAA,CACA,yBAAA,CACA,aAAA,CAGJ,eACI,kBAAA,CACA,kBAAA,CACA,oBAAA,CASA,qCAAA,iBAAA,CACA,qCAAA,gBAAA,CAMA,+GACI,+BAAA,CAGJ,mIACI,+BAAA,CACA,mBAAA,CAIR,8BACI,+BAAA,CAGJ,mCACI,+BAAA,CAGJ,uBACI,iBAAA,CAKJ,8BACI,WAAA,CAMA,0RACI,YAAA,CAKR,8DACI,YAAA,CAIJ,qBACI,wBAAA,CACA,qBAAA,CACA,gBAAA,CAOJ,oDACI,qBAAA,CAIA,kHACI,UAAA,CACA,+BAAA,CAIR,uDACI,+BAAA,CACA,yBAAA,CACA,UAAA,CACA,kBAAA,CACA,aAAA,CACA,+EACI,uBAAA,CAIR,6BACI,6BAAA,CAGJ,sCACI,mBAAA,CACA,eAAA,CACA,+BAAA,CACA,yBAAA,CACA,UAAA,CACA,eAAA,CACA,kBAAA,CAGJ,qDACI,wBAAA,CACA,oBAAA,CAGJ,gCACI,YAAA,CAGJ,wDACI,YAAA,CAMJ,sBACE,YAAA,CACA,UAAA,CACA,iBAAA,CACA,WAAA,CACA,eAAA,CACA,SAAA,CACA,sBAAA,CACA,OAAA,CAEA,4BACE,YAAA,CAGF,oCACE,aAAA,CACA,OAAA,CACA,qBAAA,CACA,kBAnB0B,CAsB5B,gBArBF,sBAsBI,SAAA,CAAA,CAGJ,iCACE,SAAA,CACA,mBAAA,CAGF,wBACE,iBAAA,CACA,kBAAA,CACA,6BAAA,CACA,wBAAA,CACA,YAAA,CACA,kBAAA,CACA,kBAvCmB,CAwCnB,mBAAA,CACA,aAAA,CACA,QAAA,CACA,cAAA,CACA,gBAAA,CACA,qBAAA,CACA,iBAAA,CAEA,yCAhBF,wBAiBI,eAAA,CACA,wCACI,WAAA,CAAA,CAIN,oCACE,iBAAA,CACA,QAAA,CACA,SAAA,CACA,OAAA,CACA,UAAA,CACA,UAAA,CACA,mBAAA,CACA,qCAAA,CACA,kBAAA,CAGF,4DACI,UAAA,CACA,wEACE,iBAAA,CAKR,sBACE,aAAA,CACA,aAAA,CACA,UAAA,CACA,WAAA,CACA,WAAA,CAGF,uBACE,eAAA,CACA,cAAA,CACA,gBAAA,CAGF,qBACI,wBACI,WAAA,CAEJ,uBACI,SAAA,CACA,QAAA,CACA,SAAA,CACA,+BAAA,CACA,oBAAA,CAEJ,mDACI,UAAA,CACA,YAAA,CACA,SAAA,CAAA,CAIR,0BACI,qBAAA,CACA,kBAAA,CACA,mBAAA,CAGJ,gCACE,GAAA,gCAAA,CAAA,CAIF,kEAEI,oCAAA,CACA,mBAAA,CACA,8CAAA",sourcesContent:['.BRtextLayer, .BRtranslateLayer {\n z-index: 2;\n position: absolute;\n top: 0;\n left: 0;\n color: transparent;\n transform-origin: 0 0;\n // Make it so right-clicking on "blank" part of text layer sends events to the image (for saving)\n pointer-events: none;\n cursor: text;\n}\n\n.BRtextLayer {\n mix-blend-mode: multiply;\n}\n\n.BRtranslateLayer {\n hyphens: auto;\n}\n\n.BRparagraphElement {\n margin: 0;\n cursor: text;\n font-family: Georgia, serif;\n line-height: 0;\n}\n\n.BRlineElement {\n pointer-events: all;\n white-space: nowrap;\n display: inline-block;\n\n // We use display: inline-block, otherwise this causes every line\n // to have newlines at the end in safari. BUT, since they\'re inline,\n // if the OCR has to short line in the same paragraph, they can wrap\n // and one can go onto the other. This adds an arbitrary margin to\n // the right of each line, forcing things to wrap.\n // See eg https://www-drini.archive.org/details/countofmontecris00duma_7/page/261/mode/2up\n // Page 261, second last line on the page.\n .BRtextLayer[dir=ltr] & { margin-right: 100%; }\n .BRtextLayer[dir=rtl] & { margin-left: 100%; }\n}\n\n// Highlight colors for text selection layer\n.BRwordElement, .BRspace, .BRparagraphElement, .BRparagraphElement br {\n // these 2 properties do not work if joined\n &::selection {\n background: hsla(210, 74%, 62%, 0.4);\n }\n\n &::-moz-selection {\n background: hsla(210, 74%, 62%, 0.4);\n color:transparent;\n }\n}\n\n.BRtranslateLayer ::selection {\n background: hsla(210, 74%, 62%, 0.4);\n}\n\n.BRtranslateLayer ::-moz-selection {\n background: hsla(210, 74%, 62%, 0.4);\n}\n\n.BRparagraphElement br {\n visibility: hidden;\n}\n\n// Use CSS pseudo-elements to render the hyphens. This makes them\n// not selectable, so copy/pasting text doesn\'t include them.\n.BRwordElement--hyphen::after {\n content: "-";\n}\n\n// Hide text layer for performance during zooming & scrolling\n.BRsmooth-zooming, .BRscrolling-active {\n // If the text layer has an annotation, don\'t hide it\n .BRpagecontainer:not(.BRpagecontainer--hasSelection):not(:has(hypothesis-highlight)):not(:has(.BRhighlight)) .BRtextLayer {\n display: none;\n }\n}\n\n// Hide text selection layers of off-screen pages\n.BRmode1up .BRpagecontainer:not(.BRpage-visible) .BRtextLayer {\n display: none;\n}\n\n// Makes page image unselectable\n.BRpagecontainer img {\n -webkit-user-select: none;\n -moz-user-select: none;\n user-select: none;\n}\n\n\n// These are Microsoft Edge specific fixed to make some of the\n// browsers features work well. These are for the in-place\n// translation.\n.BRtextLayer:has([_istranslated="1"], msreadoutspan) {\n mix-blend-mode: normal;\n}\n\n.BRwordElement, .BRspace {\n &[_istranslated="1"], &[_msttexthash] {\n color: black;\n letter-spacing: unset !important;\n }\n}\n\n.BRlineElement:has([_istranslated="1"], [_msttexthash]) {\n background: rgba(248, 237, 192, 0.8);\n backdrop-filter: blur(8px);\n color: black;\n text-align: justify;\n width: inherit;\n &:not(:nth-last-child(2)) {\n text-align-last: justify;\n }\n}\n\n.BRlineElement[_msttexthash] {\n word-spacing: unset !important;\n}\n\n.BRtranslateLayer .BRparagraphElement {\n pointer-events: auto;\n overflow-y: auto;\n background: rgba(248, 237, 192, 0.8);\n backdrop-filter: blur(8px);\n color:black;\n line-height: 1em;\n text-align: justify;\n}\n\n.BRtranslateLayer .BRparagraphElement .BRlineElement {\n white-space: break-spaces;\n display: inline-block;\n}\n\n.BRtextLayer.showingTranslation {\n display: none;\n}\n\n.BRtranslateLayer .BRparagraphElement.BRtranslateHidden {\n display: none;\n}\n\n\n$select-menu-radius: 25px;\n$select-menu-extended-radius: 10px;\n.br-select-menu__root {\n display: none;\n color: white;\n color-scheme: dark;\n padding: 2px;\n overflow: hidden;\n opacity: 1;\n transition: opacity 0.2s;\n gap: 5px;\n\n &[open] {\n display: flex;\n }\n\n &[showextended] {\n display: block;\n gap: 0px;\n background-color: #333;\n border-radius: $select-menu-extended-radius;\n }\n\n @starting-style {\n opacity: 0;\n }\n}\n.br-select-menu__root--scrolling {\n opacity: 0;\n pointer-events: none;\n}\n\n.br-select-menu__option {\n --iconWidth: 15px;\n --iconHeight: 15px;\n --iconFillColor: currentColor;\n background: transparent;\n display: flex;\n align-items: center;\n border-radius: $select-menu-radius;\n font-family: inherit;\n color: inherit;\n border: 0;\n cursor: pointer;\n text-wrap: nowrap;\n background-color: #333;\n position: relative;\n\n @media (pointer: coarse) and (hover: none) {\n padding: 4px 8px;\n #br-select-more & {\n padding: 4px;\n }\n }\n\n &:hover:after {\n position: absolute;\n left: 2px;\n right: 2px;\n top: 2px;\n bottom: 2px;\n content: "";\n pointer-events: none;\n background-color: rgba(255, 255, 255, 0.1);\n border-radius: calc($select-menu-radius - 2px);\n }\n\n .br-select-menu__root[showextended] & {\n width:100%;\n &:hover:after {\n border-radius: calc($select-menu-extended-radius - 2px);\n }\n }\n}\n\n.br-select-menu__icon {\n display: block;\n flex-shrink: 0;\n width: 17px;\n height: 17px;\n padding: 2px;\n}\n\n.br-select-menu__label {\n margin-left: 4px;\n font-size: 12px;\n margin-right: 4px;\n}\n\n@media (hover: hover) {\n .br-select-menu__option {\n padding: 4px;\n }\n .br-select-menu__label {\n width: 0px;\n margin: 0;\n opacity: 0;\n interpolate-size: allow-keywords;\n transition: width 0.2s;\n }\n .br-select-menu__root:hover .br-select-menu__label {\n width: auto;\n margin: 0 4px;\n opacity: 1;\n }\n}\n\n.BRtextLayer .BRhighlight {\n background-color: yellow;\n pointer-events: all;\n color: transparent;\n}\n\n@keyframes highlightTargetFlash {\n to { background-color: hsla(45, 80%, 66%, 1); }\n}\n\n// Style URI TextFragments, eg ?text=example\n.BRtextLayer .BRhighlight--target-text, .BRtextLayer ::target-text {\n // Similar colour to the default one used in Safari, Firefox. Note Chrome uses a purple colour\n background-color: hsla(45, 80%, 66%, 0.6);\n color: transparent;\n animation: highlightTargetFlash 600ms 1 reverse;\n}\n'],sourceRoot:""}]);const s=a.toString();n.d(t,["A",0,s])},6314:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n="",r=void 0!==t[5];return t[4]&&(n+="@supports (".concat(t[4],") {")),t[2]&&(n+="@media ".concat(t[2]," {")),r&&(n+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),n+=e(t),r&&(n+="}"),t[2]&&(n+="}"),t[4]&&(n+="}"),n}).join("")},t.i=function(e,n,r,o,i){"string"==typeof e&&(e=[[null,e,void 0]]);var a={};if(r)for(var s=0;s<this.length;s++){var l=this[s][0];null!=l&&(a[l]=!0)}for(var c=0;c<e.length;c++){var d=[].concat(e[c]);r&&a[d[0]]||(void 0!==i&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=i),n&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=n):d[2]=n),o&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=o):d[4]="".concat(o)),t.push(d))}},t}},1354:e=>{e.exports=function(e){var t=e[1],n=e[3];if(!n)return t;if("function"==typeof btoa){var r=btoa(unescape(encodeURIComponent(JSON.stringify(n)))),o="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(r),i="/*# ".concat(o," */");return[t].concat([i]).join("\n")}return[t].join("\n")}},706:(e,t,n)=>{var r=n(350).PROPER,o=n(9039),i=n(7452);e.exports=function(e){return o(function(){return!!i[e]()||"
"!=="
"[e]()||r&&i[e].name!==e})}},3802:(e,t,n)=>{var r=n(9504),o=n(7750),i=n(655),a=n(7452),s=r("".replace),l=RegExp("^["+a+"]+"),c=RegExp("(^|[^"+a+"])["+a+"]+$"),d=function(e){return function(t){var n=i(o(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),o=n(3802).Bq;r({target:"String",proto:!0,forced:n(706)("trim")},{trim:function(){return o(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){}}},6364:(e,t,n)=>{n.d(t,{r:()=>f}),n(9463),n(3792),n(6910),n(3362),n(7495),n(2762),n(2953),n(8408);var r=n(1391),o=n(6869),i=n(8965),a=n(5369),s=n(9748),l=n(3991),c=n(4297),d=n(5703),h=n(1669);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,s=[],l=!0,c=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=i.call(n)).done)&&(s.push(r.value),s.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return p(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)?p(e,t):void 0}}(e,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.")}()}function p(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 g(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}const m=window.BookReader;class f extends o.S{constructor(e){super(e),g(this,"options",{enabled:!0,fullDjvuXmlUrl:null,singlePageDjvuXmlUrl:null,jsonp:!1,maxProtectedWords:200}),g(this,"djvuPagesPromise",null),g(this,"pageTextCache",new a.l),g(this,"maxWordRendered",2500),g(this,"_jumpedToHighlight",!1),g(this,"_measurementDocument",void 0),this.rtl="rl"===this.br.pageProgression,this.textSelectionManager=new l.bg(".BRtextLayer",this.br,{selectionElement:[".BRwordElement",".BRspace","mark"]},this.options.maxProtectedWords)}init(){if(!this.options.enabled)return;const e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.style.cssText="position:fixed; top:-99999px; left:-99999px; width:2000px; height:4000px; border:0; visibility:hidden;",document.body.appendChild(e),this._measurementDocument=e.contentDocument;const t=this._measurementDocument.createElement("style");t.textContent=d.A,this._measurementDocument.head.appendChild(t),this.br.on("pageVisible",(e,t)=>{let n=t.pageContainerEl;const r=n.querySelector(".BRtextLayer");r&&this.br.trigger("textLayerVisible",{pageContainerEl:n,textLayer:r})}),this.loadData(),this.textSelectionManager.init();const n=new URLSearchParams(location.search).get("text");n&&(this.br.targetTextFragment=l.yc.fromString(n,this.br.book,this.br.firstIndex),this.initTextFragment())}async initTextFragment(){if(this.br.options.verifyTextFragment&&!await this.br.options.verifyTextFragment(this.br.targetTextFragment))return;const e=this.br.targetTextFragment;this.br.on("textLayerVisible",async(t,n)=>{let r=n.pageContainerEl,o=n.textLayer;if(e.pageIndex===parseFloat(r.getAttribute("data-index"))){const t=(0,l.lB)(o,e,"BRhighlight--target-text");this._jumpedToHighlight||(this.br.scrollIntoView(t[0],{behavior:"smooth",block:"center"}),this._jumpedToHighlight=!0)}});const t=this.br.book.getPage(this.br.targetTextFragment.pageIndex);t.isViewable||(await this.br.requestPage(t),this.br.jumpToIndex(t.index,{ariaLive:!0,allowUnviewable:!0}))}_configurePageContainer(e){var t;return this.options.enabled&&this.br.mode!==this.br.constModeThumb&&null!==(t=e.page)&&void 0!==t&&t.isViewable&&this.createTextLayer(e),e}loadData(){this.options.singlePageDjvuXmlUrl||(this.djvuPagesPromise=h.ajax({type:"GET",url:(0,i.gT)(this.options.fullDjvuXmlUrl,this.br.options.vars),dataType:this.options.jsonp?"jsonp":"html",cache:!0,xhrFields:{withCredentials:this.br.protected},error:e=>{}}).then(e=>{try{const t=h.parseXML(e);return t&&h(t).find("OBJECT")}catch(e){return}}))}async getPageText(e){if(this.options.singlePageDjvuXmlUrl){const t=this.pageTextCache.entries.find(t=>t.index==e);if(t)return t.response;const n=await h.ajax({type:"GET",url:(0,i.gT)(this.options.singlePageDjvuXmlUrl,this.br.options.vars,{pageIndex:e}),dataType:this.options.jsonp?"jsonp":"html",cache:!0,xhrFields:{withCredentials:this.br.protected},error:e=>{}});try{const t=h.parseXML(n),r=t&&h(t).find("OBJECT")[0];return this.pageTextCache.add({index:e,response:r}),r}catch(e){return}}else{const t=await this.djvuPagesPromise;if(t)return t[e]}}async createTextLayer(e){const t=e.page.index,n=e.$container;if(n.find(".BRtextLayer").length)return;const o=await this.getPageText(t);if(!o)return;h(o).find("WORD").filter((e,t)=>{const n=u(t.getAttribute("coords").split(",").map(parseFloat),4),r=n[0],o=n[3];if(0==r&&0==o)return console.error("Found invalid ocr word coordinates"),!0}).remove(),b(o);const i=h(o).find("WORD").length;if(i>this.maxWordRendered)return void console.log("Page ".concat(t," has too many words (").concat(i," > ").concat(this.maxWordRendered,"). Not rendering text layer."));const a=(0,r.Ql)(e.page,"BRtextLayer");await Promise.resolve();const l=parseFloat(e.$container[0].style.width)/e.page.width,d=parseFloat(e.$container[0].style.height)/e.page.height;a.style.transform="scale(".concat(l,", ").concat(d,")");const p=(0,s.YH)(this.br.options.bookLanguage);p&&a.setAttribute("lang",p),a.setAttribute("dir",this.rtl?"rtl":"ltr");const g=h(o).find("PARAGRAPH[coords]").toArray(),m=g.map(e=>{const t=this.renderParagraph(e);return a.appendChild(t),t}),f=A(a,".BRparagraphElement",this._measurementDocument);let y=0;for(const e of(0,c.yU)(g,m)){var v=u(e,2);const t=v[0],n=v[1],r=h(t).attr("coords").split(",").map(parseFloat),o=f.get(n),i=u(r,4),s=i[0],l=i[2],c=i[3],d=this.rtl?o.right-l:s-o.left,p=c-(o.top+y);n.style[this.rtl?"marginRight":"marginLeft"]="".concat(d,"px"),n.style.marginTop="".concat(p,"px"),y+=p,a.appendChild(n),a.appendChild(document.createTextNode("\n"))}n.append(a),this.textSelectionManager.stopPageFlip(n),this.br.trigger("textLayerRendered",{pageIndex:t,pageContainer:e}),n.hasClass("BRpage-visible")&&this.br.trigger("textLayerVisible",{pageContainerEl:n[0],textLayer:a})}renderParagraph(e){const t=document.createElement("p");t.classList.add("BRparagraphElement"),e.getAttribute("x-role")&&(t.classList.add("ocr-role-header-footer"),t.ariaHidden="true");const n=u(h(e).attr("coords").split(",").map(parseFloat),4),r=n[0],o=n[1],i=n[2],a=n[3],s=[],l=h(e).find("LINE[coords]").toArray();if(!l.length)return t;for(const e of(0,c.pp)((0,c.Px)(l,y))){var d=u(e,3);const n=d[0],r=d[1],o=d[2],i=r.ocrElement==l[l.length-1],a=document.createElement("span");a.classList.add("BRlineElement");for(const e of r.words.entries()){var p=u(e,2);const t=p[0],r=p[1],i=u(h(r).attr("coords").split(",").map(parseFloat),4),l=i[1],c=i[2],d=i[3],g=l-d;if(s.push(g),0==t&&null!=n&&n.lastWord.textContent.trim().endsWith("-")){const e=u(h((o||n).firstWord).attr("coords").split(",").map(parseFloat),3)[0];h(r).attr("coords","".concat(e,",").concat(l,",").concat(c,",").concat(d))}const m=document.createElement("span");if(m.setAttribute("class","BRwordElement"),m.textContent=r.textContent.trim(),t>0){const e=document.createElement("span");e.classList.add("BRspace"),e.textContent=" ",e.setAttribute("aria-label"," "),a.append(e),a.appendChild(document.createTextNode(" "))}a.appendChild(m)}const c=r.lastWord.textContent.trim().endsWith("-"),g=a.children[a.children.length-1];c&&!i&&(g.textContent=g.textContent.trim().slice(0,-1),g.classList.add("BRwordElement--hyphen")),t.appendChild(a),i||c||t.appendChild(document.createTextNode(" "))}s.sort((e,t)=>e-t);const g=s[Math.floor(.85*s.length)]+4;t.style.left="".concat(r,"px"),t.style.top="".concat(a,"px"),t.style.width="".concat(i-r,"px"),t.style.height="".concat(o-a,"px"),t.style.fontSize="".concat(g,"px");let m=A(t,".BRwordElement",this._measurementDocument);const f=h(e).find("WORD").toArray(),b=t.querySelectorAll(".BRwordElement");for(const e of(0,c.yU)(f,b)){var v=u(e,2);const t=v[0],n=v[1],r=m.get(n),o=u(h(t).attr("coords").split(",").map(parseFloat),3),i=o[0];let a=o[2]-i;t.textContent.endsWith(" ")&&(a=a*(t.textContent.length-1)/t.textContent.length);const s=a-r.width;n.style.letterSpacing="".concat(s/(t.textContent.length-1),"px")}m=A(t,".BRwordElement",this._measurementDocument);const x=A(t,".BRspace",this._measurementDocument),C=h(e).find("LINE[coords]").toArray(),w=Array.from(t.querySelectorAll(".BRlineElement"));let E=a;for(const e of(0,c.yU)(C,w)){var k=u(e,2);const t=k[0],n=k[1],o=h(t).find("WORD").toArray();let a=this.rtl?i:r;for(const e of(0,c.yU)(o,n.querySelectorAll(".BRwordElement"))){var B=u(e,2);const t=B[0],n=B[1];{const e=m.get(n),r=u(h(t).attr("coords").split(",").map(parseFloat),3),o=r[0],i=r[2],s=this.rtl?-(i-a):o-a;if(n.previousElementSibling){const e=n.previousElementSibling;e.style.letterSpacing="".concat(s-x.get(e).width,"px")}else n.style[this.rtl?"paddingRight":"paddingLeft"]="".concat(s,"px");this.rtl?a-=s+e.width:a+=s+e.width}}const s=Math.min(...o.map(e=>parseFloat(h(e).attr("coords").split(",")[3])))-E;n.previousElementSibling&&(n.previousElementSibling.style.lineHeight="".concat(s,"px"),E+=s)}return w[w.length-1].style.lineHeight="".concat(o-E,"px"),t.appendChild(document.createElement("br")),t}}function A(e,t,n){const r={position:e.style.position,visibility:e.style.visibility,top:e.style.top,left:e.style.left,transform:e.style.transform};e.style.position="absolute",e.style.visibility="hidden",e.style.top="0",e.style.left="0",e.style.transform="none",n.body.appendChild(e);const o=new Map(Array.from(e.querySelectorAll(t)).map(e=>{const t=e.getBoundingClientRect();return[e,new v(t.left+n.defaultView.scrollX,t.top+n.defaultView.scrollY,t.width,t.height)]}));return n.body.removeChild(e),Object.assign(e.style,r),document.adoptNode(e),o}function y(e){const t=h(e).find("WORD").toArray();return{ocrElement:e,words:t,firstWord:t[0],lastWord:t[t.length-1]}}function b(e){if(h(e).attr("coords")||!e.children)return;const t=h(e).children().toArray();if(0===t.length)return;for(const e of t)b(e);const n=[];for(const e of t)h(e).attr("coords")&&n.push(h(e).attr("coords").split(",").map(parseFloat));const r=function(e){let t=1/0,n=-1/0,r=-1/0,o=1/0;for(const a of e){var i=u(a,4);const e=i[0],s=i[1],l=i[2],c=i[3];t=Math.min(t,e),n=Math.max(n,s),r=Math.max(r,l),o=Math.min(o,c)}return[t,n,r,o]}(n);Math.abs(r[0])!=1/0&&h(e).attr("coords",r.join(","))}null==m||m.registerPlugin("textSelection",f);class v{constructor(e,t,n,r){this.x=e,this.y=t,this.width=n,this.height=r}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get top(){return this.y}get left(){return this.x}}},9748:(t,n,r)=>{r.d(n,{$x:()=>c,ND:()=>l,YH:()=>i,_4:()=>a}),r(4423),r(3792),r(3362),r(2953);const o={"zh-hans":"中文 (Zhōngwén)"};function i(e){if(!e)return null;if(e=e.toLocaleLowerCase(),o[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(),o[e])return o[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(t,n){if(!t)return null;t=t.toLowerCase();for(const o of e)for(const e of n){var r;if(null!==(r=o[e])&&void 0!==r&&r.toLowerCase().split(", ").includes(t))return o}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:()=>V,lB:()=>ae});var r=n.cw(function(e,t){var r=n(3724),o=n(2106),i=n(5213),a=n(7979);r&&!i.correct&&(o(RegExp.prototype,"flags",{configurable:!0,get:a}),i.correct=!0)}),o=n.cw(function(e,t){var r=n(6518),o=n(9565),i=n(7476),a=n(3994),s=n(2529),l=n(7750),c=n(8014),d=n(655),h=n(8551),u=n(34),p=n(2195),g=n(788),m=n(1034),f=n(5966),A=n(6840),y=n(9039),b=n(8227),v=n(2293),x=n(7829),C=n(6682),w=n(1181),E=n(6395),k=b("matchAll"),B="RegExp String",R=B+" Iterator",S=w.set,_=w.getterFor(R),T=RegExp.prototype,L=TypeError,I=i("".indexOf),P=i("".matchAll),N=!!P&&!y(function(){P("a",/./)}),O=a(function(e,t,n,r){S(this,{type:R,regexp:e,string:t,global:n,unicode:r,done:!1})},B,function(){var e=_(this);if(e.done)return s(void 0,!0);var t=e.regexp,n=e.string,r=C(t,n);return null===r?(e.done=!0,s(void 0,!0)):e.global?(""===d(r[0])&&(t.lastIndex=x(n,c(t.lastIndex),e.unicode)),s(r,!1)):(e.done=!0,s(r,!1))}),D=function(e){var t,n,r,o=h(this),i=d(e),a=v(o,RegExp),s=d(m(o));return t=new a(a===RegExp?o.source:o,s),n=!!~I(s,"g"),r=!!~I(s,"u")||!!~I(s,"v"),t.lastIndex=c(o.lastIndex),new O(t,i,n,r)};r({target:"String",proto:!0,forced:N},{matchAll:function(e){var t,n,r,i,a=l(this);if(u(e)){if(g(e)&&(t=d(l(m(e))),!~I(t,"g")))throw new L("`.matchAll` does not allow non-global regexes");if(N)return P(a,e);if(void 0===(r=f(e,k))&&E&&"RegExp"===p(e)&&(r=D),r)return o(r,e,a)}else if(N)return P(a,e);return n=d(a),i=new RegExp(e,"g"),E?o(D,i,n):i[k](n)}}),E||k in T||A(T,k,D)}),i=n.cw(function(e,t){o()});n(4423),n(9463),n(3792),n(3362),n(4864),n(7495),r(),n(5440),n(2762),i(),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,h,u,p,g,m,f,A,y,b,v,x,C,w,E,k,B,R=n(9880),S=n(7597),_=n(6054),T=n(6248),L=(n(790),n(395)),I=n(4297),P=n(1669);function N(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function O(e,t,n,r){var o=D();if(r)for(var i=0;i<r.length;i++)o=r[i](o);var a=t(function(e){o.initializeInstanceElements(e,s.elements)},n),s=o.decorateClass(function(e){for(var t=[],n=function(e){return"method"===e.kind&&e.key===i.key&&e.placement===i.placement},r=0;r<e.length;r++){var o,i=e[r];if("method"===i.kind&&(o=t.find(n)))if(M(i.descriptor)||M(o.descriptor)){if(j(i)||j(o))throw new ReferenceError("Duplicated methods ("+i.key+") can't be decorated.");o.descriptor=i.descriptor}else{if(j(i)){if(j(o))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+i.key+").");o.decorators=i.decorators}q(i,o)}else t.push(i)}return t}(a.d.map(F)),e);return o.initializeClassElements(a.F,s.elements),o.runClassFinishers(a.F,s.finishers)}function D(){D=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 o=t.placement;if(t.kind===r&&("static"===o||"prototype"===o)){var i="static"===o?e:n;this.defineClassElement(i,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=[],o={static:[],prototype:[],own:[]};if(e.forEach(function(e){this.addElementPlacement(e,o)},this),e.forEach(function(e){if(!j(e))return n.push(e);var t=this.decorateElement(e,o);n.push(t.element),n.push.apply(n,t.extras),r.push.apply(r,t.finishers)},this),!t)return{elements:n,finishers:r};var i=this.decorateConstructor(n,t);return r.push.apply(r,i.finishers),i.finishers=r,i},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=[],o=e.decorators,i=o.length-1;i>=0;i--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,o[i])(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 o=this.fromClassDescriptor(e),i=this.toClassDescriptor((0,t[r])(o)||o);if(void 0!==i.finisher&&n.push(i.finisher),void 0!==i.elements){e=i.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=$(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 o=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var i={kind:t,key:n,placement:r,descriptor:Object.assign({},o)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(o,"get","The property descriptor of a field descriptor"),this.disallowProperty(o,"set","The property descriptor of a field descriptor"),this.disallowProperty(o,"value","The property descriptor of a field descriptor"),i.initializer=e.initializer),i},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 F(e){var t,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 q(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function j(e){return e.decorators&&e.decorators.length}function M(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 o=W(J(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof o?function(e){return o.apply(n,e)}:o}function W(){return W="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=J(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(arguments.length<3?e:n):o.value}},W.apply(null,arguments)}function J(e){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},J(e)}function G(e,t,n){return(t=$(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}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+""}const X="BRhighlightStorage";class V{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 o=n.selectionElement;G(this,"options",{maxProtectedWords:200}),G(this,"selectMenu",void 0),G(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))}),G(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 o=(0,I.eU)((0,I.nC)(Y(t,"element"),e=>e.classList.contains(this.selectionElement[0].replace(".",""))),this.options.maxProtectedWords-1);if(!o||t.endContainer.parentNode==o)return;const i=document.createRange();i.setStart(t.startContainer,t.startOffset),i.setEnd(o.firstChild,o.textContent.length),e.removeAllRanges(),e.addRange(i)}),this.layer=e,this.br=t,this.selectionElement=o,this.selectionObserver=new c(this.layer,this._onSelectionChange),this.options.maxProtectedWords=r||200,this.selectMenu=new Z(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"),P(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),P(document.body).on("contextmenu dragstart copy",e=>{const t=document.getSelection();if(null!=t&&t.toString()&&P(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=P(e).closest(".BRpagecontainer");e.style.pointerEvents="none",t.find("img").css("pointer-events","auto"),P(e).off(".textSelectPluginHandler");const n=this.mouseIsDown;let r=this.mouseIsDown;n&&(e.style.pointerEvents="auto"),P(e).on("mousedown.textSelectPluginHandler",e=>{this.mouseIsDown=!0,P(e.target).is(this.selectionElement.join(", "))&&e.stopPropagation()}),P(e).on("mouseup.textSelectPluginHandler",t=>{this.mouseIsDown=!1,e.style.pointerEvents="none",r&&(r=!1,t.stopPropagation())})}textSelectingMode(e){const t=P(e).closest(".BRpagecontainer");e.style.pointerEvents="all",t.find("img").css("pointer-events","none"),P(e).off(".textSelectPluginHandler"),P(e).on("mousedown.textSelectPluginHandler",e=>{1==e.which&&(this.mouseIsDown=!0,e.stopPropagation())}),P(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 Y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"text+element";return function*(){const n=e.startContainer,r=e.endContainer;let o=!1;const i=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,h=void 0===d||d;return function*(){if(t===r)return o=!0,void(i(t)&&(yield t));if(i(t)&&(yield t),!(s&&t.firstChild&&(yield*e(t.firstChild,{children:!0,parents:!1,siblings:!0}),o))){if(h)for(let n=t.nextSibling;n;n=n.nextSibling)if(yield*e(n,{children:!0,parents:!1,siblings:!1}),o)return;c&&t.parentNode&&(yield*e(t.parentNode,{children:!1,parents:!0,siblings:!0}))}}()}(n)}()}O([(0,_.EM)("br-menu-option")],function(e,t){class n extends t{constructor(){super(...arguments),e(this)}}return{F:n,d:[{kind:"field",decorators:[(0,_.MZ)({type:String})],key:"icon",value:()=>""},{kind:"field",decorators:[(0,_.MZ)({type:String})],key:"label",value:()=>""},{kind:"field",key:"temporaryText",value:()=>null},{kind:"field",decorators:[(0,_.MZ)({type:Number,attribute:"temporary-text-duration"})],key:"temporaryTextDuration",value:()=>1200},{kind:"field",decorators:[(0,_.MZ)({type:String,attribute:"aria-label"})],key:"ariaLabel",value:()=>""},{kind:"field",decorators:[(0,_.MZ)({type:Boolean,attribute:"live-label"})],key:"liveLabel",value:()=>!1},{kind:"field",decorators:[(0,_.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,S.qy)(d||(d=N(['<ia-icon-share class="br-select-menu__icon" aria-hidden="true"></ia-icon-share>']))):"edit-pencil"===this.icon?(0,S.qy)(h||(h=N(['<ia-icon-edit-pencil class="br-select-menu__icon" aria-hidden="true"></ia-icon-edit-pencil>']))):"ellipses"===this.icon?(0,S.qy)(u||(u=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,o=r?this.temporaryText:n,i=r&&this.temporaryTextVisible,a=i?o:n,s=null===(t=this.ariaLabel)||void 0===t?void 0:t.trim(),l=s&&s!==a.trim()?s:void 0,c=n.length>=o.length?n:o;return(0,S.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,T.J)(l),this.renderIcon(),r||n?r?(0,S.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",i?o:n):(0,S.qy)(m||(m=N(['\n <span class="br-select-menu__label" aria-live=',">","</span>\n "])),this.liveLabel?"polite":"off",n):"")}}]}},S.WF);let Z=O([(0,_.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,_.MZ)({type:Boolean,reflect:!0})],key:"showExtended",value:()=>!1},{kind:"field",decorators:[(0,_.P)("#br-select-copy-link-option")],key:"copyLinkOption",value:void 0},{kind:"field",decorators:[(0,_.MZ)({type:Boolean,reflect:!0})],key:"open",value:()=>!1},{kind:"field",decorators:[(0,_.MZ)({type:Boolean})],key:"copyLinkToHighlightEnabled",value:()=>!0},{kind:"field",decorators:[(0,_.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,S.qy)(f||(f=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,S.qy)(A||(A=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,S.qy)(y||(y=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,S.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,S.qy)(v||(v=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,S.qy)(x||(x=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(X)})}},{kind:"method",key:"renderDefaultOptions",value:function(){return(0,S.qy)(C||(C=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,S.qy)(w||(w=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,S.qy)(E||(E=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),o=this.getNodeTextLayer(r.startContainer);if(!o)return void console.warn("No text layer found for selection");const i=ce.fromSelection(n,[o]),a=i.toUrl();await navigator.clipboard.writeText(a),null===(t=this.copyLinkOption)||void 0===t||t.showTemporaryText("Copied!"),this.br.trigger("copyLinkToHighlight",{textFragment:i,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 o=this.loadHighlightsFromLocalStorage();o.push(r),this.saveToLocalStorage(o),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(X,JSON.stringify(e.map(e=>e.toJSON())))}},{kind:"method",key:"loadHighlightsFromLocalStorage",value:function(){return JSON.parse(window.localStorage.getItem(X)||"[]").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),P(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)),o=r[0],i=r[r.length-1],a=document.createRange();a.setStart(o,0),a.setEnd(i,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,L.un)()||(0,L.m0)(),n=(0,L.m0)()?25:(0,L.un)()?15:10,r=t?60:0,o=(e.top<r?e.bottom+r:e.bottom)+n,i=Math.max(10,o)+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,R.qE)(l,10,s-a-10)+window.scrollX;this.style.top="".concat(i,"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()}}}]}},S.WF);function K(e,t){t=t.trim();const n=new RegExp(String.raw(k||(k=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(B||(B=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,o=void 0===r?e=>e:r;if(!n.length)return;const i=n[0]===t.startContainer?t.startOffset:0,a=o(ie(t)),s=o(n[0].textContent.slice(0,i)).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=oe(s+e.index,n,!1,{normalize:o}),r=oe(s+e.index+e[0].length,n,!0,{normalize:o});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 i=new Range;return i.setStart(t.node,t.offset),i.setEnd(r.node,r.offset),i}).filter(e=>!!e);return null!=c&&c.length?c:void 0}function oe(e,t,n){let r=(arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}).normalize,o=void 0===r?e=>e:r;const i=e;let a=0;for(const e of t){const t=e.textContent||"",r=o(t),s=a;if(s+r.length+(n?1:0)>i){const a=i-s;let l=Math.min(a,t.length);const c=n?r.substring(0,a):r.substring(a);let d=o(n?t.substring(0,a):t.substring(a));const h=(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+=h,d=o(n?t.substring(0,l):t.substring(l))}}a+=r.length}}function ie(e){const t=Array.from((0,I.nC)(Y(e,"text"),se));let n=t.map(e=>e.textContent).join("");const r=t[0],o=t[t.length-1];return e.startContainer===r&&(n=n.substring(e.startOffset)),e.endContainer===o&&(n=n.substring(0,n.length-(o.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),o=te(e),i=new Range;i.setStart(r,0),i.setEnd(o,o.textContent.length);const a=Array.from((0,I.nC)(Y(i,"text"),se)),s=re(t.toRegExp({context:!0}),i,a,{normalize:ne});if(!s)return void console.warn("Could not find quote with context in page");const l=Array.from((0,I.nC)(Y(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),h=ee(c[0].endContainer),u=new Range;return u.setStart(d,0),u.setEnd(h,h.textContent.length),d.parentElement.classList.contains("BRhighlight")||h.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 o=e.endContainer,i=e.cloneRange();i.setStartBefore(o);const a=[];e.setStartAfter(n),e.setEndBefore(o);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 i.surroundContents(d),[c,...a,d]}(u,()=>{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,o=e.quoteEnd,i=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!=o?o:null,this.suffix=i,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 o=r[1]||null,i=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,h=o?t.getPageIndex(o):n;if("number"!=typeof h)throw new Error("Could not determine page index for text fragment with page number ".concat(o));if(!(s||l&&c))throw new Error("Invalid text fragment quote format: ".concat(e));return new ce({prefix:i,quote:s,quoteStart:l,quoteEnd:c,suffix:d,pageNumber:o,pageIndex:h})}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)),o=t.hash?t.hash.replace(/((?:^|[#/])page)\/[^/]+/,"$1/".concat(n)):"";return"".concat(t.origin).concat(r,"?").concat(e).concat(o)}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=K(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 o=e.getRangeAt(0),i=new Range,s=te(o.startContainer),l=ee(o.endContainer);i.setStart(s,0),i.setEnd(l,0==o.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,i.endOffset);const h=te(t[t.length-1]);d.setEnd(h,Math.max(0,h.textContent.length-1));const u=ie(c);let p=Q(3,u),g=(0,a.rj)(p);const m=ie(d);let f=K(3,m),A=(0,a.rj)(f);g<3&&(f=K(6-g,m),A=(0,a.rj)(f)),A<3&&(p=Q(6-A,u),g=(0,a.rj)(p));const y=ie(i),b=s.parentElement.closest(".BRpagecontainer");return new ce({quote:y,prefix:p,suffix:f,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*o(e,t){for(const n of e)t(n)&&(yield n)}function*i(e,t){for(const n of e)yield t(n)}function*a(e){let t,n,r;for(const o of e)void 0!==n&&(r=o,yield[t,n,r]),t=n,n=o,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:()=>i,eU:()=>r,nC:()=>o,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 o(e){const t=e.match(/\S+/g);return t?t.length:0}function i(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:a;return null==e?void 0:e.replace(/\{\{([^}]*?)\}\}/g,(e,i)=>{if(!i)return e;const a=function(e){if(Array.isArray(e))return e}(c=i.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=>o[e]).reduce((e,t)=>t(e),d&&d.toString())})}n.d(t,{gT:()=>i,rj:()=>o}),n(9463),n(3792),n(2712),n(7495),n(5440),n(2762),n(2953);const a={urlencode:encodeURIComponent}}};import{__webpack_require__ as t}from"../ia-bookreader.js";t.C({__webpack_esm_ids__,__webpack_esm_modules__});const n=t(6364).r;export{n as TextSelectionPlugin};
|
|
1
|
+
import{default as e}from"iso-language-codes";import"@internetarchive/icon-share";import"@internetarchive/icon-ellipses";export const __webpack_esm_ids__=[326];export const __webpack_esm_modules__={5703:(e,t,n)=>{var r=n(1354),o=n.n(r),i=n(6314),a=n.n(i)()(o());a.push([e.id,'.BRtextLayer,.BRtranslateLayer{z-index:2;position:absolute;top:0;left:0;color:rgba(0,0,0,0);transform-origin:0 0;pointer-events:none;cursor:text}.BRtextLayer{mix-blend-mode:multiply}.BRtranslateLayer{hyphens:auto}.BRparagraphElement{margin:0;cursor:text;font-family:Georgia,serif;line-height:0}.BRlineElement{pointer-events:all;white-space:nowrap;display:inline-block}.BRtextLayer[dir=ltr] .BRlineElement{margin-right:100%}.BRtextLayer[dir=rtl] .BRlineElement{margin-left:100%}.BRwordElement::selection,.BRspace::selection,.BRparagraphElement::selection,.BRparagraphElement br::selection{background:hsla(210,74%,62%,.4)}.BRwordElement::-moz-selection,.BRspace::-moz-selection,.BRparagraphElement::-moz-selection,.BRparagraphElement br::-moz-selection{background:hsla(210,74%,62%,.4);color:rgba(0,0,0,0)}.BRtranslateLayer ::selection{background:hsla(210,74%,62%,.4)}.BRtranslateLayer ::-moz-selection{background:hsla(210,74%,62%,.4)}.BRparagraphElement br{visibility:hidden}.BRwordElement--hyphen::after{content:"-"}.BRsmooth-zooming .BRpagecontainer:not(.BRpagecontainer--hasSelection):not(:has(hypothesis-highlight)):not(:has(.BRhighlight)) .BRtextLayer,.BRscrolling-active .BRpagecontainer:not(.BRpagecontainer--hasSelection):not(:has(hypothesis-highlight)):not(:has(.BRhighlight)) .BRtextLayer{display:none}.BRmode1up .BRpagecontainer:not(.BRpage-visible) .BRtextLayer{display:none}.BRpagecontainer img{-webkit-user-select:none;-moz-user-select:none;user-select:none}.BRtextLayer:has([_istranslated="1"],msreadoutspan){mix-blend-mode:normal}.BRwordElement[_istranslated="1"],.BRwordElement[_msttexthash],.BRspace[_istranslated="1"],.BRspace[_msttexthash]{color:#000;letter-spacing:unset !important}.BRlineElement:has([_istranslated="1"],[_msttexthash]){background:rgba(248,237,192,.8);backdrop-filter:blur(8px);color:#000;text-align:justify;width:inherit}.BRlineElement:has([_istranslated="1"],[_msttexthash]):not(:nth-last-child(2)){text-align-last:justify}.BRlineElement[_msttexthash]{word-spacing:unset !important}.BRtranslateLayer .BRparagraphElement{pointer-events:auto;overflow-y:auto;background:rgba(248,237,192,.8);backdrop-filter:blur(8px);color:#000;line-height:1em;text-align:justify}.BRtranslateLayer .BRparagraphElement .BRlineElement{white-space:break-spaces;display:inline-block}.BRtextLayer.showingTranslation{display:none}.BRtranslateLayer .BRparagraphElement.BRtranslateHidden{display:none}.br-select-menu__root{display:none;color:#fff;color-scheme:dark;padding:2px;overflow:hidden;opacity:1;transition:opacity .2s;gap:5px}.br-select-menu__root[open]{display:flex}.br-select-menu__root[showextended]{display:block;gap:0px;background-color:#333;border-radius:10px}@starting-style{.br-select-menu__root{opacity:0}}.br-select-menu__root--scrolling{opacity:0;pointer-events:none}.br-select-menu__option{--iconWidth: 15px;--iconHeight: 15px;--iconFillColor: currentColor;background:rgba(0,0,0,0);display:flex;align-items:center;border-radius:25px;font-family:inherit;color:inherit;border:0;cursor:pointer;text-wrap:nowrap;background-color:#333;position:relative}@media(pointer: coarse)and (hover: none){.br-select-menu__option{padding:4px 8px}#br-select-more .br-select-menu__option{padding:4px}}.br-select-menu__option:hover:after{position:absolute;left:2px;right:2px;top:2px;bottom:2px;content:"";pointer-events:none;background-color:rgba(255,255,255,.1);border-radius:23px}.br-select-menu__root[showextended] .br-select-menu__option{width:100%}.br-select-menu__root[showextended] .br-select-menu__option:hover:after{border-radius:8px}.br-select-menu__icon{display:block;flex-shrink:0;width:17px;height:17px;padding:2px}.br-select-menu__label{margin-left:4px;font-size:12px;margin-right:4px}@media(hover: hover){.br-select-menu__option{padding:4px}.br-select-menu__label{width:0px;margin:0;opacity:0;interpolate-size:allow-keywords;transition:width .2s}.br-select-menu__root:hover .br-select-menu__label{width:auto;margin:0 4px;opacity:1}}.BRtextLayer .BRhighlight{background-color:#ff0;pointer-events:all;color:rgba(0,0,0,0)}@keyframes highlightTargetFlash{to{background-color:hsl(45,80%,66%)}}.BRtextLayer .BRhighlight--target-text,.BRtextLayer ::target-text{background-color:hsla(45,80%,66%,.6);color:rgba(0,0,0,0);animation:highlightTargetFlash 600ms 1 reverse}',"",{version:3,sources:["webpack://./src/css/_TextSelection.scss"],names:[],mappings:"AAAA,+BACI,SAAA,CACA,iBAAA,CACA,KAAA,CACA,MAAA,CACA,mBAAA,CACA,oBAAA,CAEA,mBAAA,CACA,WAAA,CAGJ,aACI,uBAAA,CAGJ,kBACI,YAAA,CAGJ,oBACI,QAAA,CACA,WAAA,CACA,yBAAA,CACA,aAAA,CAGJ,eACI,kBAAA,CACA,kBAAA,CACA,oBAAA,CASA,qCAAA,iBAAA,CACA,qCAAA,gBAAA,CAMA,+GACI,+BAAA,CAGJ,mIACI,+BAAA,CACA,mBAAA,CAIR,8BACI,+BAAA,CAGJ,mCACI,+BAAA,CAGJ,uBACI,iBAAA,CAKJ,8BACI,WAAA,CAMA,0RACI,YAAA,CAKR,8DACI,YAAA,CAIJ,qBACI,wBAAA,CACA,qBAAA,CACA,gBAAA,CAOJ,oDACI,qBAAA,CAIA,kHACI,UAAA,CACA,+BAAA,CAIR,uDACI,+BAAA,CACA,yBAAA,CACA,UAAA,CACA,kBAAA,CACA,aAAA,CACA,+EACI,uBAAA,CAIR,6BACI,6BAAA,CAGJ,sCACI,mBAAA,CACA,eAAA,CACA,+BAAA,CACA,yBAAA,CACA,UAAA,CACA,eAAA,CACA,kBAAA,CAGJ,qDACI,wBAAA,CACA,oBAAA,CAGJ,gCACI,YAAA,CAGJ,wDACI,YAAA,CAMJ,sBACE,YAAA,CACA,UAAA,CACA,iBAAA,CACA,WAAA,CACA,eAAA,CACA,SAAA,CACA,sBAAA,CACA,OAAA,CAEA,4BACE,YAAA,CAGF,oCACE,aAAA,CACA,OAAA,CACA,qBAAA,CACA,kBAnB0B,CAsB5B,gBArBF,sBAsBI,SAAA,CAAA,CAGJ,iCACE,SAAA,CACA,mBAAA,CAGF,wBACE,iBAAA,CACA,kBAAA,CACA,6BAAA,CACA,wBAAA,CACA,YAAA,CACA,kBAAA,CACA,kBAvCmB,CAwCnB,mBAAA,CACA,aAAA,CACA,QAAA,CACA,cAAA,CACA,gBAAA,CACA,qBAAA,CACA,iBAAA,CAEA,yCAhBF,wBAiBI,eAAA,CACA,wCACI,WAAA,CAAA,CAIN,oCACE,iBAAA,CACA,QAAA,CACA,SAAA,CACA,OAAA,CACA,UAAA,CACA,UAAA,CACA,mBAAA,CACA,qCAAA,CACA,kBAAA,CAGF,4DACI,UAAA,CACA,wEACE,iBAAA,CAKR,sBACE,aAAA,CACA,aAAA,CACA,UAAA,CACA,WAAA,CACA,WAAA,CAGF,uBACE,eAAA,CACA,cAAA,CACA,gBAAA,CAGF,qBACI,wBACI,WAAA,CAEJ,uBACI,SAAA,CACA,QAAA,CACA,SAAA,CACA,+BAAA,CACA,oBAAA,CAEJ,mDACI,UAAA,CACA,YAAA,CACA,SAAA,CAAA,CAIR,0BACI,qBAAA,CACA,kBAAA,CACA,mBAAA,CAGJ,gCACE,GAAA,gCAAA,CAAA,CAIF,kEAEI,oCAAA,CACA,mBAAA,CACA,8CAAA",sourcesContent:['.BRtextLayer, .BRtranslateLayer {\n z-index: 2;\n position: absolute;\n top: 0;\n left: 0;\n color: transparent;\n transform-origin: 0 0;\n // Make it so right-clicking on "blank" part of text layer sends events to the image (for saving)\n pointer-events: none;\n cursor: text;\n}\n\n.BRtextLayer {\n mix-blend-mode: multiply;\n}\n\n.BRtranslateLayer {\n hyphens: auto;\n}\n\n.BRparagraphElement {\n margin: 0;\n cursor: text;\n font-family: Georgia, serif;\n line-height: 0;\n}\n\n.BRlineElement {\n pointer-events: all;\n white-space: nowrap;\n display: inline-block;\n\n // We use display: inline-block, otherwise this causes every line\n // to have newlines at the end in safari. BUT, since they\'re inline,\n // if the OCR has to short line in the same paragraph, they can wrap\n // and one can go onto the other. This adds an arbitrary margin to\n // the right of each line, forcing things to wrap.\n // See eg https://www-drini.archive.org/details/countofmontecris00duma_7/page/261/mode/2up\n // Page 261, second last line on the page.\n .BRtextLayer[dir=ltr] & { margin-right: 100%; }\n .BRtextLayer[dir=rtl] & { margin-left: 100%; }\n}\n\n// Highlight colors for text selection layer\n.BRwordElement, .BRspace, .BRparagraphElement, .BRparagraphElement br {\n // these 2 properties do not work if joined\n &::selection {\n background: hsla(210, 74%, 62%, 0.4);\n }\n\n &::-moz-selection {\n background: hsla(210, 74%, 62%, 0.4);\n color:transparent;\n }\n}\n\n.BRtranslateLayer ::selection {\n background: hsla(210, 74%, 62%, 0.4);\n}\n\n.BRtranslateLayer ::-moz-selection {\n background: hsla(210, 74%, 62%, 0.4);\n}\n\n.BRparagraphElement br {\n visibility: hidden;\n}\n\n// Use CSS pseudo-elements to render the hyphens. This makes them\n// not selectable, so copy/pasting text doesn\'t include them.\n.BRwordElement--hyphen::after {\n content: "-";\n}\n\n// Hide text layer for performance during zooming & scrolling\n.BRsmooth-zooming, .BRscrolling-active {\n // If the text layer has an annotation, don\'t hide it\n .BRpagecontainer:not(.BRpagecontainer--hasSelection):not(:has(hypothesis-highlight)):not(:has(.BRhighlight)) .BRtextLayer {\n display: none;\n }\n}\n\n// Hide text selection layers of off-screen pages\n.BRmode1up .BRpagecontainer:not(.BRpage-visible) .BRtextLayer {\n display: none;\n}\n\n// Makes page image unselectable\n.BRpagecontainer img {\n -webkit-user-select: none;\n -moz-user-select: none;\n user-select: none;\n}\n\n\n// These are Microsoft Edge specific fixed to make some of the\n// browsers features work well. These are for the in-place\n// translation.\n.BRtextLayer:has([_istranslated="1"], msreadoutspan) {\n mix-blend-mode: normal;\n}\n\n.BRwordElement, .BRspace {\n &[_istranslated="1"], &[_msttexthash] {\n color: black;\n letter-spacing: unset !important;\n }\n}\n\n.BRlineElement:has([_istranslated="1"], [_msttexthash]) {\n background: rgba(248, 237, 192, 0.8);\n backdrop-filter: blur(8px);\n color: black;\n text-align: justify;\n width: inherit;\n &:not(:nth-last-child(2)) {\n text-align-last: justify;\n }\n}\n\n.BRlineElement[_msttexthash] {\n word-spacing: unset !important;\n}\n\n.BRtranslateLayer .BRparagraphElement {\n pointer-events: auto;\n overflow-y: auto;\n background: rgba(248, 237, 192, 0.8);\n backdrop-filter: blur(8px);\n color:black;\n line-height: 1em;\n text-align: justify;\n}\n\n.BRtranslateLayer .BRparagraphElement .BRlineElement {\n white-space: break-spaces;\n display: inline-block;\n}\n\n.BRtextLayer.showingTranslation {\n display: none;\n}\n\n.BRtranslateLayer .BRparagraphElement.BRtranslateHidden {\n display: none;\n}\n\n\n$select-menu-radius: 25px;\n$select-menu-extended-radius: 10px;\n.br-select-menu__root {\n display: none;\n color: white;\n color-scheme: dark;\n padding: 2px;\n overflow: hidden;\n opacity: 1;\n transition: opacity 0.2s;\n gap: 5px;\n\n &[open] {\n display: flex;\n }\n\n &[showextended] {\n display: block;\n gap: 0px;\n background-color: #333;\n border-radius: $select-menu-extended-radius;\n }\n\n @starting-style {\n opacity: 0;\n }\n}\n.br-select-menu__root--scrolling {\n opacity: 0;\n pointer-events: none;\n}\n\n.br-select-menu__option {\n --iconWidth: 15px;\n --iconHeight: 15px;\n --iconFillColor: currentColor;\n background: transparent;\n display: flex;\n align-items: center;\n border-radius: $select-menu-radius;\n font-family: inherit;\n color: inherit;\n border: 0;\n cursor: pointer;\n text-wrap: nowrap;\n background-color: #333;\n position: relative;\n\n @media (pointer: coarse) and (hover: none) {\n padding: 4px 8px;\n #br-select-more & {\n padding: 4px;\n }\n }\n\n &:hover:after {\n position: absolute;\n left: 2px;\n right: 2px;\n top: 2px;\n bottom: 2px;\n content: "";\n pointer-events: none;\n background-color: rgba(255, 255, 255, 0.1);\n border-radius: calc($select-menu-radius - 2px);\n }\n\n .br-select-menu__root[showextended] & {\n width:100%;\n &:hover:after {\n border-radius: calc($select-menu-extended-radius - 2px);\n }\n }\n}\n\n.br-select-menu__icon {\n display: block;\n flex-shrink: 0;\n width: 17px;\n height: 17px;\n padding: 2px;\n}\n\n.br-select-menu__label {\n margin-left: 4px;\n font-size: 12px;\n margin-right: 4px;\n}\n\n@media (hover: hover) {\n .br-select-menu__option {\n padding: 4px;\n }\n .br-select-menu__label {\n width: 0px;\n margin: 0;\n opacity: 0;\n interpolate-size: allow-keywords;\n transition: width 0.2s;\n }\n .br-select-menu__root:hover .br-select-menu__label {\n width: auto;\n margin: 0 4px;\n opacity: 1;\n }\n}\n\n.BRtextLayer .BRhighlight {\n background-color: yellow;\n pointer-events: all;\n color: transparent;\n}\n\n@keyframes highlightTargetFlash {\n to { background-color: hsla(45, 80%, 66%, 1); }\n}\n\n// Style URI TextFragments, eg ?text=example\n.BRtextLayer .BRhighlight--target-text, .BRtextLayer ::target-text {\n // Similar colour to the default one used in Safari, Firefox. Note Chrome uses a purple colour\n background-color: hsla(45, 80%, 66%, 0.6);\n color: transparent;\n animation: highlightTargetFlash 600ms 1 reverse;\n}\n'],sourceRoot:""}]);const s=a.toString();n.d(t,["A",0,s])},6314:e=>{e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var n="",r=void 0!==t[5];return t[4]&&(n+="@supports (".concat(t[4],") {")),t[2]&&(n+="@media ".concat(t[2]," {")),r&&(n+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),n+=e(t),r&&(n+="}"),t[2]&&(n+="}"),t[4]&&(n+="}"),n}).join("")},t.i=function(e,n,r,o,i){"string"==typeof e&&(e=[[null,e,void 0]]);var a={};if(r)for(var s=0;s<this.length;s++){var l=this[s][0];null!=l&&(a[l]=!0)}for(var c=0;c<e.length;c++){var d=[].concat(e[c]);r&&a[d[0]]||(void 0!==i&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=i),n&&(d[2]?(d[1]="@media ".concat(d[2]," {").concat(d[1],"}"),d[2]=n):d[2]=n),o&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=o):d[4]="".concat(o)),t.push(d))}},t}},1354:e=>{e.exports=function(e){var t=e[1],n=e[3];if(!n)return t;if("function"==typeof btoa){var r=btoa(unescape(encodeURIComponent(JSON.stringify(n)))),o="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(r),i="/*# ".concat(o," */");return[t].concat([i]).join("\n")}return[t].join("\n")}},706:(e,t,n)=>{var r=n(350).PROPER,o=n(9039),i=n(7452);e.exports=function(e){return o(function(){return!!i[e]()||"
"!=="
"[e]()||r&&i[e].name!==e})}},3802:(e,t,n)=>{var r=n(9504),o=n(7750),i=n(655),a=n(7452),s=r("".replace),l=RegExp("^["+a+"]+"),c=RegExp("(^|[^"+a+"])["+a+"]+$"),d=function(e){return function(t){var n=i(o(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),o=n(3802).Bq;r({target:"String",proto:!0,forced:n(706)("trim")},{trim:function(){return o(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){}}},6364:(e,t,n)=>{n.d(t,{r:()=>f}),n(9463),n(3792),n(6910),n(3362),n(7495),n(2762),n(2953),n(8408);var r=n(1391),o=n(6869),i=n(8965),a=n(5369),s=n(9748),l=n(3991),c=n(4297),d=n(5703),h=n(1669);function u(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,s=[],l=!0,c=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=i.call(n)).done)&&(s.push(r.value),s.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return s}}(e,t)||function(e,t){if(e){if("string"==typeof e)return p(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)?p(e,t):void 0}}(e,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.")}()}function p(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 g(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}const m=window.BookReader;class f extends o.S{constructor(e){super(e),g(this,"options",{enabled:!0,fullDjvuXmlUrl:null,singlePageDjvuXmlUrl:null,jsonp:!1,maxProtectedWords:200}),g(this,"djvuPagesPromise",null),g(this,"pageTextCache",new a.l),g(this,"maxWordRendered",2500),g(this,"_jumpedToHighlight",!1),g(this,"_measurementDocument",void 0),this.rtl="rl"===this.br.pageProgression,this.textSelectionManager=new l.bg(".BRtextLayer",this.br,{selectionElement:[".BRwordElement",".BRspace","mark"]},this.options.maxProtectedWords)}init(){if(!this.options.enabled)return;const e=document.createElement("iframe");e.setAttribute("aria-hidden","true"),e.tabIndex=-1,e.style.cssText="position:fixed; top:-99999px; left:-99999px; width:2000px; height:4000px; border:0; visibility:hidden;",document.body.appendChild(e),this._measurementDocument=e.contentDocument;const t=this._measurementDocument.createElement("style");t.textContent=d.A,this._measurementDocument.head.appendChild(t),this.br.on("pageVisible",(e,t)=>{let n=t.pageContainerEl;const r=n.querySelector(".BRtextLayer");r&&this.br.trigger("textLayerVisible",{pageContainerEl:n,textLayer:r})}),this.loadData(),this.textSelectionManager.init();const n=new URLSearchParams(location.search).get("text");n&&(this.br.targetTextFragment=l.yc.fromString(n,this.br.book,this.br.firstIndex),this.initTextFragment())}async initTextFragment(){if(this.br.options.verifyTextFragment&&!await this.br.options.verifyTextFragment.call(this,this.br.targetTextFragment))return;const e=this.br.targetTextFragment;this.br.on("textLayerVisible",async(t,n)=>{let r=n.pageContainerEl,o=n.textLayer;if(e.pageIndex===parseFloat(r.getAttribute("data-index"))){const t=(0,l.lB)(o,e,"BRhighlight--target-text");this._jumpedToHighlight||(this.br.scrollIntoView(t[0],{behavior:"smooth",block:"center"}),this._jumpedToHighlight=!0)}});const t=this.br.book.getPage(this.br.targetTextFragment.pageIndex);t.isViewable||(await this.br.requestPage(t),this.br.jumpToIndex(t.index,{ariaLive:!0,allowUnviewable:!0}))}_configurePageContainer(e){var t;return this.options.enabled&&this.br.mode!==this.br.constModeThumb&&null!==(t=e.page)&&void 0!==t&&t.isViewable&&this.createTextLayer(e),e}loadData(){this.options.singlePageDjvuXmlUrl||(this.djvuPagesPromise=h.ajax({type:"GET",url:(0,i.gT)(this.options.fullDjvuXmlUrl,this.br.options.vars),dataType:this.options.jsonp?"jsonp":"html",cache:!0,xhrFields:{withCredentials:this.br.protected},error:e=>{}}).then(e=>{try{const t=h.parseXML(e);return t&&h(t).find("OBJECT")}catch(e){return}}))}async getPageText(e){if(this.options.singlePageDjvuXmlUrl){const t=this.pageTextCache.entries.find(t=>t.index==e);if(t)return t.response;const n=await h.ajax({type:"GET",url:(0,i.gT)(this.options.singlePageDjvuXmlUrl,this.br.options.vars,{pageIndex:e}),dataType:this.options.jsonp?"jsonp":"html",cache:!0,xhrFields:{withCredentials:this.br.protected},error:e=>{}});try{const t=h.parseXML(n),r=t&&h(t).find("OBJECT")[0];return this.pageTextCache.add({index:e,response:r}),r}catch(e){return}}else{const t=await this.djvuPagesPromise;if(t)return t[e]}}async createTextLayer(e){const t=e.page.index,n=e.$container;if(n.find(".BRtextLayer").length)return;const o=await this.getPageText(t);if(!o)return;h(o).find("WORD").filter((e,t)=>{const n=u(t.getAttribute("coords").split(",").map(parseFloat),4),r=n[0],o=n[3];if(0==r&&0==o)return console.error("Found invalid ocr word coordinates"),!0}).remove(),b(o);const i=h(o).find("WORD").length;if(i>this.maxWordRendered)return void console.log("Page ".concat(t," has too many words (").concat(i," > ").concat(this.maxWordRendered,"). Not rendering text layer."));const a=(0,r.Ql)(e.page,"BRtextLayer");await Promise.resolve();const l=parseFloat(e.$container[0].style.width)/e.page.width,d=parseFloat(e.$container[0].style.height)/e.page.height;a.style.transform="scale(".concat(l,", ").concat(d,")");const p=(0,s.YH)(this.br.options.bookLanguage);p&&a.setAttribute("lang",p),a.setAttribute("dir",this.rtl?"rtl":"ltr");const g=h(o).find("PARAGRAPH[coords]").toArray(),m=g.map(e=>{const t=this.renderParagraph(e);return a.appendChild(t),t}),f=A(a,".BRparagraphElement",this._measurementDocument);let y=0;for(const e of(0,c.yU)(g,m)){var v=u(e,2);const t=v[0],n=v[1],r=h(t).attr("coords").split(",").map(parseFloat),o=f.get(n),i=u(r,4),s=i[0],l=i[2],c=i[3],d=this.rtl?o.right-l:s-o.left,p=c-(o.top+y);n.style[this.rtl?"marginRight":"marginLeft"]="".concat(d,"px"),n.style.marginTop="".concat(p,"px"),y+=p,a.appendChild(n),a.appendChild(document.createTextNode("\n"))}n.append(a),this.textSelectionManager.stopPageFlip(n),this.br.trigger("textLayerRendered",{pageIndex:t,pageContainer:e}),n.hasClass("BRpage-visible")&&this.br.trigger("textLayerVisible",{pageContainerEl:n[0],textLayer:a})}renderParagraph(e){const t=document.createElement("p");t.classList.add("BRparagraphElement"),e.getAttribute("x-role")&&(t.classList.add("ocr-role-header-footer"),t.ariaHidden="true");const n=u(h(e).attr("coords").split(",").map(parseFloat),4),r=n[0],o=n[1],i=n[2],a=n[3],s=[],l=h(e).find("LINE[coords]").toArray();if(!l.length)return t;for(const e of(0,c.pp)((0,c.Px)(l,y))){var d=u(e,3);const n=d[0],r=d[1],o=d[2],i=r.ocrElement==l[l.length-1],a=document.createElement("span");a.classList.add("BRlineElement");for(const e of r.words.entries()){var p=u(e,2);const t=p[0],r=p[1],i=u(h(r).attr("coords").split(",").map(parseFloat),4),l=i[1],c=i[2],d=i[3],g=l-d;if(s.push(g),0==t&&null!=n&&n.lastWord.textContent.trim().endsWith("-")){const e=u(h((o||n).firstWord).attr("coords").split(",").map(parseFloat),3)[0];h(r).attr("coords","".concat(e,",").concat(l,",").concat(c,",").concat(d))}const m=document.createElement("span");if(m.setAttribute("class","BRwordElement"),m.textContent=r.textContent.trim(),t>0){const e=document.createElement("span");e.classList.add("BRspace"),e.textContent=" ",e.setAttribute("aria-label"," "),a.append(e),a.appendChild(document.createTextNode(" "))}a.appendChild(m)}const c=r.lastWord.textContent.trim().endsWith("-"),g=a.children[a.children.length-1];c&&!i&&(g.textContent=g.textContent.trim().slice(0,-1),g.classList.add("BRwordElement--hyphen")),t.appendChild(a),i||c||t.appendChild(document.createTextNode(" "))}s.sort((e,t)=>e-t);const g=s[Math.floor(.85*s.length)]+4;t.style.left="".concat(r,"px"),t.style.top="".concat(a,"px"),t.style.width="".concat(i-r,"px"),t.style.height="".concat(o-a,"px"),t.style.fontSize="".concat(g,"px");let m=A(t,".BRwordElement",this._measurementDocument);const f=h(e).find("WORD").toArray(),b=t.querySelectorAll(".BRwordElement");for(const e of(0,c.yU)(f,b)){var v=u(e,2);const t=v[0],n=v[1],r=m.get(n),o=u(h(t).attr("coords").split(",").map(parseFloat),3),i=o[0];let a=o[2]-i;t.textContent.endsWith(" ")&&(a=a*(t.textContent.length-1)/t.textContent.length);const s=a-r.width;n.style.letterSpacing="".concat(s/(t.textContent.length-1),"px")}m=A(t,".BRwordElement",this._measurementDocument);const x=A(t,".BRspace",this._measurementDocument),C=h(e).find("LINE[coords]").toArray(),w=Array.from(t.querySelectorAll(".BRlineElement"));let E=a;for(const e of(0,c.yU)(C,w)){var k=u(e,2);const t=k[0],n=k[1],o=h(t).find("WORD").toArray();let a=this.rtl?i:r;for(const e of(0,c.yU)(o,n.querySelectorAll(".BRwordElement"))){var B=u(e,2);const t=B[0],n=B[1];{const e=m.get(n),r=u(h(t).attr("coords").split(",").map(parseFloat),3),o=r[0],i=r[2],s=this.rtl?-(i-a):o-a;if(n.previousElementSibling){const e=n.previousElementSibling;e.style.letterSpacing="".concat(s-x.get(e).width,"px")}else n.style[this.rtl?"paddingRight":"paddingLeft"]="".concat(s,"px");this.rtl?a-=s+e.width:a+=s+e.width}}const s=Math.min(...o.map(e=>parseFloat(h(e).attr("coords").split(",")[3])))-E;n.previousElementSibling&&(n.previousElementSibling.style.lineHeight="".concat(s,"px"),E+=s)}return w[w.length-1].style.lineHeight="".concat(o-E,"px"),t.appendChild(document.createElement("br")),t}}function A(e,t,n){const r={position:e.style.position,visibility:e.style.visibility,top:e.style.top,left:e.style.left,transform:e.style.transform};e.style.position="absolute",e.style.visibility="hidden",e.style.top="0",e.style.left="0",e.style.transform="none",n.body.appendChild(e);const o=new Map(Array.from(e.querySelectorAll(t)).map(e=>{const t=e.getBoundingClientRect();return[e,new v(t.left+n.defaultView.scrollX,t.top+n.defaultView.scrollY,t.width,t.height)]}));return n.body.removeChild(e),Object.assign(e.style,r),document.adoptNode(e),o}function y(e){const t=h(e).find("WORD").toArray();return{ocrElement:e,words:t,firstWord:t[0],lastWord:t[t.length-1]}}function b(e){if(h(e).attr("coords")||!e.children)return;const t=h(e).children().toArray();if(0===t.length)return;for(const e of t)b(e);const n=[];for(const e of t)h(e).attr("coords")&&n.push(h(e).attr("coords").split(",").map(parseFloat));const r=function(e){let t=1/0,n=-1/0,r=-1/0,o=1/0;for(const a of e){var i=u(a,4);const e=i[0],s=i[1],l=i[2],c=i[3];t=Math.min(t,e),n=Math.max(n,s),r=Math.max(r,l),o=Math.min(o,c)}return[t,n,r,o]}(n);Math.abs(r[0])!=1/0&&h(e).attr("coords",r.join(","))}null==m||m.registerPlugin("textSelection",f);class v{constructor(e,t,n,r){this.x=e,this.y=t,this.width=n,this.height=r}get right(){return this.x+this.width}get bottom(){return this.y+this.height}get top(){return this.y}get left(){return this.x}}},9748:(t,n,r)=>{r.d(n,{$x:()=>c,ND:()=>l,YH:()=>i,_4:()=>a}),r(4423),r(3792),r(3362),r(2953);const o={"zh-hans":"中文 (Zhōngwén)"};function i(e){if(!e)return null;if(e=e.toLocaleLowerCase(),o[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(),o[e])return o[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(t,n){if(!t)return null;t=t.toLowerCase();for(const o of e)for(const e of n){var r;if(null!==(r=o[e])&&void 0!==r&&r.toLowerCase().split(", ").includes(t))return o}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:()=>V,lB:()=>ae});var r=n.cw(function(e,t){var r=n(3724),o=n(2106),i=n(5213),a=n(7979);r&&!i.correct&&(o(RegExp.prototype,"flags",{configurable:!0,get:a}),i.correct=!0)}),o=n.cw(function(e,t){var r=n(6518),o=n(9565),i=n(7476),a=n(3994),s=n(2529),l=n(7750),c=n(8014),d=n(655),h=n(8551),u=n(34),p=n(2195),g=n(788),m=n(1034),f=n(5966),A=n(6840),y=n(9039),b=n(8227),v=n(2293),x=n(7829),C=n(6682),w=n(1181),E=n(6395),k=b("matchAll"),B="RegExp String",R=B+" Iterator",S=w.set,_=w.getterFor(R),T=RegExp.prototype,L=TypeError,I=i("".indexOf),P=i("".matchAll),N=!!P&&!y(function(){P("a",/./)}),O=a(function(e,t,n,r){S(this,{type:R,regexp:e,string:t,global:n,unicode:r,done:!1})},B,function(){var e=_(this);if(e.done)return s(void 0,!0);var t=e.regexp,n=e.string,r=C(t,n);return null===r?(e.done=!0,s(void 0,!0)):e.global?(""===d(r[0])&&(t.lastIndex=x(n,c(t.lastIndex),e.unicode)),s(r,!1)):(e.done=!0,s(r,!1))}),D=function(e){var t,n,r,o=h(this),i=d(e),a=v(o,RegExp),s=d(m(o));return t=new a(a===RegExp?o.source:o,s),n=!!~I(s,"g"),r=!!~I(s,"u")||!!~I(s,"v"),t.lastIndex=c(o.lastIndex),new O(t,i,n,r)};r({target:"String",proto:!0,forced:N},{matchAll:function(e){var t,n,r,i,a=l(this);if(u(e)){if(g(e)&&(t=d(l(m(e))),!~I(t,"g")))throw new L("`.matchAll` does not allow non-global regexes");if(N)return P(a,e);if(void 0===(r=f(e,k))&&E&&"RegExp"===p(e)&&(r=D),r)return o(r,e,a)}else if(N)return P(a,e);return n=d(a),i=new RegExp(e,"g"),E?o(D,i,n):i[k](n)}}),E||k in T||A(T,k,D)}),i=n.cw(function(e,t){o()});n(4423),n(9463),n(3792),n(3362),n(4864),n(7495),r(),n(5440),n(2762),i(),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,h,u,p,g,m,f,A,y,b,v,x,C,w,E,k,B,R=n(9880),S=n(7597),_=n(6054),T=n(6248),L=(n(790),n(395)),I=n(4297),P=n(1669);function N(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}function O(e,t,n,r){var o=D();if(r)for(var i=0;i<r.length;i++)o=r[i](o);var a=t(function(e){o.initializeInstanceElements(e,s.elements)},n),s=o.decorateClass(function(e){for(var t=[],n=function(e){return"method"===e.kind&&e.key===i.key&&e.placement===i.placement},r=0;r<e.length;r++){var o,i=e[r];if("method"===i.kind&&(o=t.find(n)))if(M(i.descriptor)||M(o.descriptor)){if(j(i)||j(o))throw new ReferenceError("Duplicated methods ("+i.key+") can't be decorated.");o.descriptor=i.descriptor}else{if(j(i)){if(j(o))throw new ReferenceError("Decorators can't be placed on different accessors with for the same property ("+i.key+").");o.decorators=i.decorators}q(i,o)}else t.push(i)}return t}(a.d.map(F)),e);return o.initializeClassElements(a.F,s.elements),o.runClassFinishers(a.F,s.finishers)}function D(){D=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 o=t.placement;if(t.kind===r&&("static"===o||"prototype"===o)){var i="static"===o?e:n;this.defineClassElement(i,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=[],o={static:[],prototype:[],own:[]};if(e.forEach(function(e){this.addElementPlacement(e,o)},this),e.forEach(function(e){if(!j(e))return n.push(e);var t=this.decorateElement(e,o);n.push(t.element),n.push.apply(n,t.extras),r.push.apply(r,t.finishers)},this),!t)return{elements:n,finishers:r};var i=this.decorateConstructor(n,t);return r.push.apply(r,i.finishers),i.finishers=r,i},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=[],o=e.decorators,i=o.length-1;i>=0;i--){var a=t[e.placement];a.splice(a.indexOf(e.key),1);var s=this.fromElementDescriptor(e),l=this.toElementFinisherExtras((0,o[i])(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 o=this.fromClassDescriptor(e),i=this.toClassDescriptor((0,t[r])(o)||o);if(void 0!==i.finisher&&n.push(i.finisher),void 0!==i.elements){e=i.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=$(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 o=e.descriptor;this.disallowProperty(e,"elements","An element descriptor");var i={kind:t,key:n,placement:r,descriptor:Object.assign({},o)};return"field"!==t?this.disallowProperty(e,"initializer","A method descriptor"):(this.disallowProperty(o,"get","The property descriptor of a field descriptor"),this.disallowProperty(o,"set","The property descriptor of a field descriptor"),this.disallowProperty(o,"value","The property descriptor of a field descriptor"),i.initializer=e.initializer),i},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 F(e){var t,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 q(e,t){void 0!==e.descriptor.get?t.descriptor.get=e.descriptor.get:t.descriptor.set=e.descriptor.set}function j(e){return e.decorators&&e.decorators.length}function M(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 o=W(J(1&r?e.prototype:e),t,n);return 2&r&&"function"==typeof o?function(e){return o.apply(n,e)}:o}function W(){return W="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,n){var r=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=J(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(arguments.length<3?e:n):o.value}},W.apply(null,arguments)}function J(e){return J=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},J(e)}function G(e,t,n){return(t=$(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}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+""}const X="BRhighlightStorage";class V{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 o=n.selectionElement;G(this,"options",{maxProtectedWords:200}),G(this,"selectMenu",void 0),G(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))}),G(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 o=(0,I.eU)((0,I.nC)(Y(t,"element"),e=>e.classList.contains(this.selectionElement[0].replace(".",""))),this.options.maxProtectedWords-1);if(!o||t.endContainer.parentNode==o)return;const i=document.createRange();i.setStart(t.startContainer,t.startOffset),i.setEnd(o.firstChild,o.textContent.length),e.removeAllRanges(),e.addRange(i)}),this.layer=e,this.br=t,this.selectionElement=o,this.selectionObserver=new c(this.layer,this._onSelectionChange),this.options.maxProtectedWords=r||200,this.selectMenu=new Z(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"),P(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),P(document.body).on("contextmenu dragstart copy",e=>{const t=document.getSelection();if(null!=t&&t.toString()&&P(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=P(e).closest(".BRpagecontainer");e.style.pointerEvents="none",t.find("img").css("pointer-events","auto"),P(e).off(".textSelectPluginHandler");const n=this.mouseIsDown;let r=this.mouseIsDown;n&&(e.style.pointerEvents="auto"),P(e).on("mousedown.textSelectPluginHandler",e=>{this.mouseIsDown=!0,P(e.target).is(this.selectionElement.join(", "))&&e.stopPropagation()}),P(e).on("mouseup.textSelectPluginHandler",t=>{this.mouseIsDown=!1,e.style.pointerEvents="none",r&&(r=!1,t.stopPropagation())})}textSelectingMode(e){const t=P(e).closest(".BRpagecontainer");e.style.pointerEvents="all",t.find("img").css("pointer-events","none"),P(e).off(".textSelectPluginHandler"),P(e).on("mousedown.textSelectPluginHandler",e=>{1==e.which&&(this.mouseIsDown=!0,e.stopPropagation())}),P(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 Y(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"text+element";return function*(){const n=e.startContainer,r=e.endContainer;let o=!1;const i=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,h=void 0===d||d;return function*(){if(t===r)return o=!0,void(i(t)&&(yield t));if(i(t)&&(yield t),!(s&&t.firstChild&&(yield*e(t.firstChild,{children:!0,parents:!1,siblings:!0}),o))){if(h)for(let n=t.nextSibling;n;n=n.nextSibling)if(yield*e(n,{children:!0,parents:!1,siblings:!1}),o)return;c&&t.parentNode&&(yield*e(t.parentNode,{children:!1,parents:!0,siblings:!0}))}}()}(n)}()}O([(0,_.EM)("br-menu-option")],function(e,t){class n extends t{constructor(){super(...arguments),e(this)}}return{F:n,d:[{kind:"field",decorators:[(0,_.MZ)({type:String})],key:"icon",value:()=>""},{kind:"field",decorators:[(0,_.MZ)({type:String})],key:"label",value:()=>""},{kind:"field",key:"temporaryText",value:()=>null},{kind:"field",decorators:[(0,_.MZ)({type:Number,attribute:"temporary-text-duration"})],key:"temporaryTextDuration",value:()=>1200},{kind:"field",decorators:[(0,_.MZ)({type:String,attribute:"aria-label"})],key:"ariaLabel",value:()=>""},{kind:"field",decorators:[(0,_.MZ)({type:Boolean,attribute:"live-label"})],key:"liveLabel",value:()=>!1},{kind:"field",decorators:[(0,_.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,S.qy)(d||(d=N(['<ia-icon-share class="br-select-menu__icon" aria-hidden="true"></ia-icon-share>']))):"edit-pencil"===this.icon?(0,S.qy)(h||(h=N(['<ia-icon-edit-pencil class="br-select-menu__icon" aria-hidden="true"></ia-icon-edit-pencil>']))):"ellipses"===this.icon?(0,S.qy)(u||(u=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,o=r?this.temporaryText:n,i=r&&this.temporaryTextVisible,a=i?o:n,s=null===(t=this.ariaLabel)||void 0===t?void 0:t.trim(),l=s&&s!==a.trim()?s:void 0,c=n.length>=o.length?n:o;return(0,S.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,T.J)(l),this.renderIcon(),r||n?r?(0,S.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",i?o:n):(0,S.qy)(m||(m=N(['\n <span class="br-select-menu__label" aria-live=',">","</span>\n "])),this.liveLabel?"polite":"off",n):"")}}]}},S.WF);let Z=O([(0,_.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,_.MZ)({type:Boolean,reflect:!0})],key:"showExtended",value:()=>!1},{kind:"field",decorators:[(0,_.P)("#br-select-copy-link-option")],key:"copyLinkOption",value:void 0},{kind:"field",decorators:[(0,_.MZ)({type:Boolean,reflect:!0})],key:"open",value:()=>!1},{kind:"field",decorators:[(0,_.MZ)({type:Boolean})],key:"copyLinkToHighlightEnabled",value:()=>!0},{kind:"field",decorators:[(0,_.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,S.qy)(f||(f=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,S.qy)(A||(A=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,S.qy)(y||(y=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,S.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,S.qy)(v||(v=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,S.qy)(x||(x=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(X)})}},{kind:"method",key:"renderDefaultOptions",value:function(){return(0,S.qy)(C||(C=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,S.qy)(w||(w=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,S.qy)(E||(E=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),o=this.getNodeTextLayer(r.startContainer);if(!o)return void console.warn("No text layer found for selection");const i=ce.fromSelection(n,[o]),a=i.toUrl();await navigator.clipboard.writeText(a),null===(t=this.copyLinkOption)||void 0===t||t.showTemporaryText("Copied!"),this.br.trigger("copyLinkToHighlight",{textFragment:i,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 o=this.loadHighlightsFromLocalStorage();o.push(r),this.saveToLocalStorage(o),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(X,JSON.stringify(e.map(e=>e.toJSON())))}},{kind:"method",key:"loadHighlightsFromLocalStorage",value:function(){return JSON.parse(window.localStorage.getItem(X)||"[]").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),P(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)),o=r[0],i=r[r.length-1],a=document.createRange();a.setStart(o,0),a.setEnd(i,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,L.un)()||(0,L.m0)(),n=(0,L.m0)()?25:(0,L.un)()?15:10,r=t?60:0,o=(e.top<r?e.bottom+r:e.bottom)+n,i=Math.max(10,o)+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,R.qE)(l,10,s-a-10)+window.scrollX;this.style.top="".concat(i,"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()}}}]}},S.WF);function K(e,t){t=t.trim();const n=new RegExp(String.raw(k||(k=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(B||(B=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,o=void 0===r?e=>e:r;if(!n.length)return;const i=n[0]===t.startContainer?t.startOffset:0,a=o(ie(t)),s=o(n[0].textContent.slice(0,i)).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=oe(s+e.index,n,!1,{normalize:o}),r=oe(s+e.index+e[0].length,n,!0,{normalize:o});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 i=new Range;return i.setStart(t.node,t.offset),i.setEnd(r.node,r.offset),i}).filter(e=>!!e);return null!=c&&c.length?c:void 0}function oe(e,t,n){let r=(arguments.length>3&&void 0!==arguments[3]?arguments[3]:{}).normalize,o=void 0===r?e=>e:r;const i=e;let a=0;for(const e of t){const t=e.textContent||"",r=o(t),s=a;if(s+r.length+(n?1:0)>i){const a=i-s;let l=Math.min(a,t.length);const c=n?r.substring(0,a):r.substring(a);let d=o(n?t.substring(0,a):t.substring(a));const h=(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+=h,d=o(n?t.substring(0,l):t.substring(l))}}a+=r.length}}function ie(e){const t=Array.from((0,I.nC)(Y(e,"text"),se));let n=t.map(e=>e.textContent).join("");const r=t[0],o=t[t.length-1];return e.startContainer===r&&(n=n.substring(e.startOffset)),e.endContainer===o&&(n=n.substring(0,n.length-(o.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),o=te(e),i=new Range;i.setStart(r,0),i.setEnd(o,o.textContent.length);const a=Array.from((0,I.nC)(Y(i,"text"),se)),s=re(t.toRegExp({context:!0}),i,a,{normalize:ne});if(!s)return void console.warn("Could not find quote with context in page");const l=Array.from((0,I.nC)(Y(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),h=ee(c[0].endContainer),u=new Range;return u.setStart(d,0),u.setEnd(h,h.textContent.length),d.parentElement.classList.contains("BRhighlight")||h.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 o=e.endContainer,i=e.cloneRange();i.setStartBefore(o);const a=[];e.setStartAfter(n),e.setEndBefore(o);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 i.surroundContents(d),[c,...a,d]}(u,()=>{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,o=e.quoteEnd,i=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!=o?o:null,this.suffix=i,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 o=r[1]||null,i=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,h=o?t.getPageIndex(o):n;if("number"!=typeof h)throw new Error("Could not determine page index for text fragment with page number ".concat(o));if(!(s||l&&c))throw new Error("Invalid text fragment quote format: ".concat(e));return new ce({prefix:i,quote:s,quoteStart:l,quoteEnd:c,suffix:d,pageNumber:o,pageIndex:h})}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=K(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 o=e.getRangeAt(0),i=new Range,s=te(o.startContainer),l=ee(o.endContainer);i.setStart(s,0),i.setEnd(l,0==o.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,i.endOffset);const h=te(t[t.length-1]);d.setEnd(h,Math.max(0,h.textContent.length-1));const u=ie(c);let p=Q(3,u),g=(0,a.rj)(p);const m=ie(d);let f=K(3,m),A=(0,a.rj)(f);g<3&&(f=K(6-g,m),A=(0,a.rj)(f)),A<3&&(p=Q(6-A,u),g=(0,a.rj)(p));const y=ie(i),b=s.parentElement.closest(".BRpagecontainer");return new ce({quote:y,prefix:p,suffix:f,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*o(e,t){for(const n of e)t(n)&&(yield n)}function*i(e,t){for(const n of e)yield t(n)}function*a(e){let t,n,r;for(const o of e)void 0!==n&&(r=o,yield[t,n,r]),t=n,n=o,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:()=>i,eU:()=>r,nC:()=>o,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 o(e){const t=e.match(/\S+/g);return t?t.length:0}function i(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:a;return null==e?void 0:e.replace(/\{\{([^}]*?)\}\}/g,(e,i)=>{if(!i)return e;const a=function(e){if(Array.isArray(e))return e}(c=i.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=>o[e]).reduce((e,t)=>t(e),d&&d.toString())})}n.d(t,{gT:()=>i,rj:()=>o}),n(9463),n(3792),n(2712),n(7495),n(5440),n(2762),n(2953);const a={urlencode:encodeURIComponent}}};import{__webpack_require__ as t}from"../ia-bookreader.js";t.C({__webpack_esm_ids__,__webpack_esm_modules__});const n=t(6364).r;export{n as TextSelectionPlugin};
|
|
2
2
|
//# sourceMappingURL=plugin.text_selection.js.map
|