@fluid-topics/ft-reader-context 1.1.44 → 1.1.46

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.
@@ -1,7 +1,7 @@
1
1
  !function(t,i,e,s){class n{constructor(t){this.paginatedToc=t,this.nodeByTocId={},this.knownPrettyUrls=new Set,this.duplicatedPrettyUrls=new Set,this.pages=[],this.pageByTocId={}}build(){return{paginationConfiguration:this.paginatedToc.configuration,toc:this.convertNodes(this.paginatedToc.paginatedToc,1),pagesToc:this.extractPagesToc(this.paginatedToc.paginatedToc,1),nodeByTocId:this.nodeByTocId,duplicatedPrettyUrls:this.duplicatedPrettyUrls,pages:this.pages,pageByTocId:this.pageByTocId}}extractPagesToc(t,i,e){return t.flatMap((t=>(t.pageConfiguration&&this.registerPage(this.buildPage(t,e)),null==t.tocId?this.extractPagesToc(t.children,i,e):[{tocId:t.tocId,title:t.title,depth:i,children:this.extractPagesToc(t.children,i+1,t.tocId)}])))}convertNodes(t,i,e){return t.flatMap((t=>{var s,n,r;if(null==t.tocId)return[...this.convertSectionNodes(null!==(s=t.pageToc)&&void 0!==s?s:[],i,t.tocId),...this.convertNodes(t.children,i,t.tocId)];let o=null===(n=t.prettyUrl)||void 0===n?void 0:n.replace(/^\//,"");const a={tocId:t.tocId,contentId:t.contentId,title:t.title,hasRating:t.hasRating,origin:t.origin,prettyUrl:o,depth:i,parentTocId:e,children:[]};this.register(a);const h=this.convertSectionNodes(null!==(r=t.pageToc)&&void 0!==r?r:[],i+1,t.tocId),u=this.convertNodes(t.children,i+1,a.tocId);return a.children=[...h,...u],[a]}))}convertSectionNodes(t,i,e){return t.flatMap((t=>{var s;let n=null===(s=t.prettyUrl)||void 0===s?void 0:s.replace(/^\//,"");const r={...t,prettyUrl:n,depth:i,parentTocId:e,children:[]};return this.register(r),r.children=this.convertSectionNodes(t.children,i+1,t.tocId),[r]}))}buildPage(t,i){var e,s,n,r,o,a;const h={number:this.pages.length+1,title:null!==(e=t.title)&&void 0!==e?e:"",rootTocId:null!==(s=t.tocId)&&void 0!==s?s:"root",toc:(null!==(n=t.pageToc)&&void 0!==n?n:[]).map((t=>this.nodeByTocId[t.tocId])),topics:[],hiddenTopics:[],breadcrumb:i?this.buildBreadcrumb(this.nodeByTocId[i]):[]},u=(t,i)=>(i?h.topics:h.hiddenTopics).push(t),l=null!==(o=null===(r=t.pageConfiguration)||void 0===r?void 0:r.parentsVisibility)&&void 0!==o?o:[];return h.breadcrumb.forEach(((t,i)=>{u(t,l[i])})),t.tocId&&u(t.tocId,t.pageConfiguration.isVisible),h.topics.push(...this.tocIds(null!==(a=t.pageToc)&&void 0!==a?a:[])),h}registerPage(t){for(let i of[...t.topics,...t.hiddenTopics])this.pageByTocId[i]||(this.pageByTocId[i]=t);this.pages.push(t)}tocIds(t){return t.flatMap((t=>[t.tocId,...this.tocIds(t.children)]))}buildBreadcrumb(t){const i=[t.tocId];for(;null==t?void 0:t.parentTocId;)i.unshift(t.parentTocId),t=this.nodeByTocId[t.parentTocId];return i}register(t){t.prettyUrl&&(this.knownPrettyUrls.has(t.prettyUrl)&&this.duplicatedPrettyUrls.add(t.prettyUrl),this.knownPrettyUrls.add(t.prettyUrl)),this.nodeByTocId[t.tocId]=t}}class r{convertPaginatedToc(t){return new n(t).build()}}var o,a,h,u,l,c,d,v,f,p,w,y,g,m,T,E,b,A;!function(t){!function(i){var e={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(e.arrayBuffer)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&s.indexOf(Object.prototype.toString.call(t))>-1};function r(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var i={next:function(){var i=t.shift();return{done:void 0===i,value:i}}};return e.iterable&&(i[Symbol.iterator]=function(){return i}),i}function h(t){this.map={},t instanceof h?t.forEach((function(t,i){this.append(i,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(i){this.append(i,t[i])}),this)}function u(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise((function(i,e){t.onload=function(){i(t.result)},t.onerror=function(){e(t.error)}}))}function c(t){var i=new FileReader,e=l(i);return i.readAsArrayBuffer(t),e}function d(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var i;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:e.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:e.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():e.arrayBuffer&&e.blob&&((i=t)&&DataView.prototype.isPrototypeOf(i))?(this._bodyArrayBuffer=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):e.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=d(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e.blob&&(this.blob=function(){var t=u(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(c)}),this.text=function(){var t,i,e,s=u(this);if(s)return s;if(this._bodyBlob)return t=this._bodyBlob,i=new FileReader,e=l(i),i.readAsText(t),e;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var i=new Uint8Array(t),e=new Array(i.length),s=0;s<i.length;s++)e[s]=String.fromCharCode(i[s]);return e.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},e.formData&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,i){t=r(t),i=o(i);var e=this.map[t];this.map[t]=e?e+", "+i:i},h.prototype.delete=function(t){delete this.map[r(t)]},h.prototype.get=function(t){return t=r(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(r(t))},h.prototype.set=function(t,i){this.map[r(t)]=o(i)},h.prototype.forEach=function(t,i){for(var e in this.map)this.map.hasOwnProperty(e)&&t.call(i,this.map[e],e,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(i,e){t.push(e)})),a(t)},h.prototype.values=function(){var t=[];return this.forEach((function(i){t.push(i)})),a(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(i,e){t.push([e,i])})),a(t)},e.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var f=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function p(t,i){var e,s,n=(i=i||{}).body;if(t instanceof p){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,i.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=i.credentials||this.credentials||"same-origin",!i.headers&&this.headers||(this.headers=new h(i.headers)),this.method=(e=i.method||this.method||"GET",s=e.toUpperCase(),f.indexOf(s)>-1?s:e),this.mode=i.mode||this.mode||null,this.signal=i.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function w(t){var i=new FormData;return t.trim().split("&").forEach((function(t){if(t){var e=t.split("="),s=e.shift().replace(/\+/g," "),n=e.join("=").replace(/\+/g," ");i.append(decodeURIComponent(s),decodeURIComponent(n))}})),i}function y(t,i){i||(i={}),this.type="default",this.status=void 0===i.status?200:i.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in i?i.statusText:"OK",this.headers=new h(i.headers),this.url=i.url||"",this._initBody(t)}p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},v.call(p.prototype),v.call(y.prototype),y.prototype.clone=function(){return new y(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},y.error=function(){var t=new y(null,{status:0,statusText:""});return t.type="error",t};var g=[301,302,303,307,308];y.redirect=function(t,i){if(-1===g.indexOf(i))throw new RangeError("Invalid status code");return new y(null,{status:i,headers:{location:t}})},i.DOMException=t.DOMException;try{new i.DOMException}catch(t){i.DOMException=function(t,i){this.message=t,this.name=i;var e=Error(t);this.stack=e.stack},i.DOMException.prototype=Object.create(Error.prototype),i.DOMException.prototype.constructor=i.DOMException}function m(t,s){return new Promise((function(n,r){var o=new p(t,s);if(o.signal&&o.signal.aborted)return r(new i.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,i,e={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",i=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var e=t.split(":"),s=e.shift().trim();if(s){var n=e.join(":").trim();i.append(s,n)}})),i)};e.url="responseURL"in a?a.responseURL:e.headers.get("X-Request-URL");var s="response"in a?a.response:a.responseText;n(new y(s,e))},a.onerror=function(){r(new TypeError("Network request failed"))},a.ontimeout=function(){r(new TypeError("Network request failed"))},a.onabort=function(){r(new i.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&e.blob&&(a.responseType="blob"),o.headers.forEach((function(t,i){a.setRequestHeader(i,t)})),o.signal&&(o.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",u)}),a.send(void 0===o._bodyInit?null:o._bodyInit)}))}m.polyfill=!0,t.fetch||(t.fetch=m,t.Headers=h,t.Request=p,t.Response=y),i.Headers=h,i.Request=p,i.Response=y,i.fetch=m,Object.defineProperty(i,"t",{value:!0})}({})}("undefined"!=typeof self?self:void 0),function(t){t.black="black",t.green="green",t.blue="blue",t.purple="purple",t.red="red",t.orange="orange",t.yellow="yellow"}(o||(o={})),function(t){t.OFFICIAL="OFFICIAL",t.PERSONAL="PERSONAL",t.SHARED="SHARED"}(a||(a={})),function(t){t.THIRD_PARTY="THIRD_PARTY",t.OFF_THE_GRID="OFF_THE_GRID",t.CONTENT_PACKAGER="CONTENT_PACKAGER",t.PAGES="PAGES",t.DESIGNED_READER="DESIGNED_READER"}(h||(h={})),function(t){t.CLASSIC="CLASSIC",t.CUSTOM="CUSTOM",t.DESIGNER="DESIGNER"}(u||(u={})),function(t){t.AND="AND",t.OR="OR",t.MONOVALUED="MONOVALUED"}(l||(l={})),function(t){t.NONE="NONE",t.ALPHABET="ALPHABET",t.VERSION="VERSION"}(c||(c={})),function(t){t.STARS="STARS",t.LIKE="LIKE",t.DICHOTOMOUS="DICHOTOMOUS",t.NO_RATING="NO_RATING"}(d||(d={})),function(t){t.LAST_WEEK="LAST_WEEK",t.LAST_MONTH="LAST_MONTH",t.LAST_YEAR="LAST_YEAR",t.CUSTOM="CUSTOM"}(v||(v={})),function(t){t.ASC="ASC",t.DESC="DESC"}(f||(f={})),function(t){t.ALPHA="ALPHA",t.NATURAL="NATURAL"}(p||(p={})),function(t){t.EVERYWHERE="EVERYWHERE",t.TITLE_ONLY="TITLE_ONLY",t.NONE="NONE"}(w||(w={})),function(t){t.ARTICLE="ARTICLE",t.BOOK="BOOK",t.SHARED_BOOK="SHARED_BOOK"}(y||(y={})),function(t){t.FLUIDTOPICS="FLUIDTOPICS",t.EXTERNAL="EXTERNAL"}(g||(g={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC",t.PERSONAL_BOOK="PERSONAL_BOOK",t.SHARED_BOOK="SHARED_BOOK"}(m||(m={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC"}(T||(T={})),function(t){t.DEFAULT="DEFAULT",t.DOCUMENTS="DOCUMENTS",t.ALL_TOPICS="ALL_TOPICS"}(E||(E={})),function(t){t.PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",t.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",t.HTML_EXPORT_USER="HTML_EXPORT_USER",t.PDF_EXPORT_USER="PDF_EXPORT_USER",t.SAVED_SEARCH_USER="SAVED_SEARCH_USER",t.COLLECTION_USER="COLLECTION_USER",t.OFFLINE_USER="OFFLINE_USER",t.ANALYTICS_USER="ANALYTICS_USER",t.BETA_USER="BETA_USER",t.DEBUG_USER="DEBUG_USER",t.PRINT_USER="PRINT_USER",t.RATING_USER="RATING_USER",t.FEEDBACK_USER="FEEDBACK_USER",t.GENERATIVE_AI_USER="GENERATIVE_AI_USER",t.CONTENT_PUBLISHER="CONTENT_PUBLISHER",t.KHUB_ADMIN="KHUB_ADMIN",t.USERS_ADMIN="USERS_ADMIN",t.PORTAL_ADMIN="PORTAL_ADMIN",t.ADMIN="ADMIN",t.DEVELOPER="DEVELOPER"}(b||(b={})),function(t){t.VALID="VALID",t.INVALID="INVALID"}(A||(A={}));const I={[b.PERSONAL_BOOK_SHARE_USER]:[b.PERSONAL_BOOK_USER],[b.HTML_EXPORT_USER]:[b.PERSONAL_BOOK_USER],[b.PDF_EXPORT_USER]:[b.PERSONAL_BOOK_USER],[b.KHUB_ADMIN]:[b.CONTENT_PUBLISHER],[b.ADMIN]:[b.KHUB_ADMIN,b.USERS_ADMIN,b.PORTAL_ADMIN],[b.DEVELOPER]:[b.BETA_USER,b.DEBUG_USER]};function S(t,i){return t===i||(I[t]??[]).some((t=>S(t,i)))}function R(t,i){if(null==t)return!1;return(Array.isArray(t)?t:Array.isArray(t.roles)?t.roles:Array.isArray(t.profile?.roles)?t.profile.roles:[]).some((t=>S(t,i)))}var O;t.FtReaderFeatures=void 0,(O=t.FtReaderFeatures||(t.FtReaderFeatures={})).FEEDBACK="FEEDBACK",O.RATING="RATING",O.PRINT="PRINT",O.BOOKMARK="BOOKMARK",O.COLLECTIONS="COLLECTIONS",O.PERSONAL_BOOKS="PERSONAL_BOOKS";const C=e.css`
2
2
  `,U=i.FtReduxStore.get({name:"ft-app-info",reducers:{},initialState:{baseUrl:void 0,apiIntegrationIdentifier:void 0,uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],metadataConfiguration:void 0,editorMode:!1,noCustom:!1,noCustomComponent:!1,session:void 0,openExternalDocumentInNewTab:!1}});class P{static build(t){const{baseUrl:i,apiIntegrationIdentifier:e}=U.getState(),s=null!=t?t:e;if(i&&s&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(i,s,!0)}static get(t){var i;return null!=t?P.build(t):null!==(i=P.API)&&void 0!==i?i:P.API=P.build()}static await(t){return new Promise((i=>{let e=P.get(t);if(e)i(e);else{const s=U.subscribe((()=>{e=P.get(t),e&&(s(),i(e))}))}}))}}class N{constructor(t=!0,e){var s;this.overrideApi=e;let n=this.constructor;n.commonCache=null!==(s=n.commonCache)&&void 0!==s?s:new i.CacheRegistry,this.cache=t?n.commonCache:new i.CacheRegistry}get api(){var t;return null!==(t=this.overrideApi)&&void 0!==t?t:P.get()}get awaitApi(){var t;return null!==(t=this.overrideApi)&&void 0!==t?t:P.await()}clearCache(){this.cache.clearAll()}}var L;const D=Symbol("clearAfterUnitTest");class M extends N{constructor(t){super(),this.messageContextProvider=t,this.defaultMessages={},this.listeners={},this.currentUiLocale="",this[L]=()=>{this.defaultMessages={},this.cache=new i.CacheRegistry,this.listeners={}},this.currentUiLocale=U.getState().uiLocale,U.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=U.getState();this.currentUiLocale!==t&&(this.currentUiLocale=t,this.cache.clearAll(),this.notifyAll())}addContext(t){const i=t.name.toLowerCase();this.cache.setFinal(i,t),this.notify(i)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(t,e){var s;if(t=t.toLowerCase(),Object.keys(e).length>0){const n={...null!==(s=this.defaultMessages[t])&&void 0!==s?s:{},...e};i.deepEqual(this.defaultMessages[t],n)||(this.defaultMessages[t]=n,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,e,...s){var n,r,o;t=t.toLowerCase(),this.fetchContext(t);const a=null!==(r=null===(n=this.cache.getNow(t))||void 0===n?void 0:n.messages)&&void 0!==r?r:{};return new i.ParametrizedLabelResolver(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},a).resolve(e,...s)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,i){var e;return t=t.toLowerCase(),this.listeners[t]=null!==(e=this.listeners[t])&&void 0!==e?e:new Set,this.listeners[t].add(i),()=>{var e;return null===(e=this.listeners[t])||void 0===e?void 0:e.delete(i)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>i.delay(0).then((()=>t())).catch((()=>null)))))}}L=D,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new class extends M{constructor(){super((async(t,i)=>(await this.awaitApi).getFluidTopicsMessageContext(t,i)))}}),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new class extends M{constructor(){super((async(t,i)=>(await this.awaitApi).getCustomMessageContext(t,i)))}});const _=window.FluidTopicsI18nService;var B=function(t,i,e,s){for(var n,r=arguments.length,o=r<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(i,e,o):n(i,e))||o);return r>3&&o&&Object.defineProperty(i,e,o),o};class k extends i.FtLitElement{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.editorMode=!1,this.noCustom=!1,this.openExternalDocumentInNewTab=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>P.get(),this.cache=new i.CacheRegistry,this.cleanSessionDebouncer=new i.Debouncer}render(){return e.html`
3
3
  <slot></slot>
4
- `}update(t){super.update(t),t.has("baseUrl")&&(U.actions.baseUrl(this.baseUrl),window.fluidTopicsBaseUrl=this.baseUrl),t.has("apiIntegrationIdentifier")&&U.actions.apiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&U.actions.uiLocale(this.uiLocale),t.has("metadataConfiguration")&&U.actions.metadataConfiguration(this.metadataConfiguration),t.has("noCustom")&&U.actions.noCustom(this.noCustom),t.has("editorMode")&&U.actions.editorMode(this.editorMode),t.has("noCustomComponent")&&U.actions.noCustomComponent(this.noCustomComponent),t.has("session")&&U.actions.session(this.session),t.has("availableUiLocales")&&U.actions.availableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>_.addContext(t))),t.has("openExternalDocumentInNewTab")&&U.actions.openExternalDocumentInNewTab(this.openExternalDocumentInNewTab),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){!this.withManualResources&&this.apiProvider()&&(null==this.session&&this.updateSession(),null==this.availableUiLocales&&this.updateUiLocales(),null==this.metadataConfiguration&&this.updateMetadataConfiguration())}async updateSession(){this.session=await this.cache.get("session",(async()=>{const t=await this.apiProvider().getCurrentSession();return t.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),t.idleTimeoutInMillis),t}))}async updateUiLocales(){this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>this.apiProvider().getAvailableUiLocales()))}async updateMetadataConfiguration(){this.metadataConfiguration=await this.cache.get("metadataConfiguration",(()=>this.apiProvider().getMetadataConfiguration()))}}k.elementDefinitions={},k.styles=C,B([s.property()],k.prototype,"baseUrl",void 0),B([s.property()],k.prototype,"apiIntegrationIdentifier",void 0),B([s.property()],k.prototype,"uiLocale",void 0),B([i.jsonProperty(null)],k.prototype,"availableUiLocales",void 0),B([i.jsonProperty(null)],k.prototype,"metadataConfiguration",void 0),B([s.property({type:Boolean})],k.prototype,"editorMode",void 0),B([s.property({type:Boolean})],k.prototype,"noCustom",void 0),B([s.property({type:Boolean})],k.prototype,"openExternalDocumentInNewTab",void 0),B([s.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],k.prototype,"noCustomComponent",void 0),B([s.property({type:Boolean})],k.prototype,"withManualResources",void 0),B([i.jsonProperty([])],k.prototype,"messageContexts",void 0),B([i.jsonProperty(void 0)],k.prototype,"session",void 0),B([s.property({type:Object})],k.prototype,"apiProvider",void 0);class x extends N{async listMySearches(){let t=U.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-searches",(async()=>(await this.awaitApi).listMySearches(t.profile.userId)),3e5):[]}}class F extends N{async listMyBookmarks(){let t=U.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-bookmarks",(async()=>(await this.awaitApi).listMyBookmarks(t.profile.userId)),3e5):[]}}const j=i.FtReduxStore.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const H=new class{constructor(){this.currentSession=U.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new F,this.savedSearchesService=new x,U.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:e}=U.getState();i.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==e?void 0:e.profile)||(this.currentSession=e,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){this.savedSearchesService.clearCache(),j.actions.savedSearches(void 0)}clearMyBookmarks(){this.bookmarksService.clearCache(),j.actions.bookmarks(void 0)}async reloadMySearches(){this.savedSearchesService.clearCache();const t=await this.savedSearchesService.listMySearches();j.actions.savedSearches(t)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const i=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;j.actions.bookmarks(i)}}};i.customElement("ft-app-context")(k);class G extends N{get mapId(){return this._mapId}set mapId(t){t!==this._mapId&&this.clear(),this._mapId=t}constructor(t,i,e){super(!1,i),this.converter=t,this._mapId=e,this.initCache()}async withMapId(t){return this._mapId?t(this._mapId):void 0}initCache(){this.cache.registerFinal("configuration",(()=>this.api.getReaderConfiguration())),this.cache.register("map",(()=>this.withMapId((t=>this.fetchMap(t))))),this.cache.register("enrichedToc",(()=>this.withMapId((t=>this.fetchPages(t).then((t=>this.converter.convertPaginatedToc(t))))))),this.cache.register("ratingSummary",(()=>{var t,i;return R(null!==(i=null===(t=U.getState().session)||void 0===t?void 0:t.profile.roles)&&void 0!==i?i:[],"RATING_USER")?this.withMapId((t=>this.fetchMapRating(t))):Promise.resolve()}))}clear(){this.cache.clearAll()}getMap(){return this.cache.get("map")}getConfiguration(){return this.cache.get("configuration")}getEnrichedToc(){return this.cache.get("enrichedToc")}get enrichedToc(){return this.cache.getNow("enrichedToc")}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(){return(await this.getEnrichedToc()).toc}async getPagesToc(){return(await this.getEnrichedToc()).pagesToc}async getTocNode(t){return(await this.getEnrichedToc()).nodeByTocId[t]}getTocNodeNow(t){var i;return null===(i=this.enrichedToc)||void 0===i?void 0:i.nodeByTocId[t]}async getPage(t){const i=await this.getEnrichedToc();return i.pages[t-1]||i.pages[0]}async getPageByTocId(t){const i=await this.getEnrichedToc();return i.pageByTocId[t]||i.pages[0]}getTopicInfo(t){return this.cache.get("topic-"+t.tocId,(()=>this.fetchTopicMetadata(t)))}getTopicContent(t){return this.cache.get("topic-content-"+t.tocId,(()=>this.fetchTopicHTMLContent(t)))}getAttachments(){return this.cache.get("map-attachments",(()=>this.fetchAttachments()))}getRelativesForDocument(t,i){return this.cache.get("document-relatives-"+t+"-"+i.join("-"),(()=>this.fetchRelativesForDocument(t,i)))}getRelativesForTopicInMap(t,i,e){return this.cache.get("topic-relatives-"+[t,i,...e].join("-"),(()=>this.fetchRelativesForTopicInMap(t,i,e)))}getAttachmentDownloadLink(t){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(t).content}?download=true`)}getLink(t,i,e){const s=this.getNavigationData(t,i,e),n=this.getReaderLinkPrefix()+(s.prettyUrl?s.prettyUrl:`${s.mapId}/${s.tocId}`),r=new URL(n,this.api.tenantBaseUrl);return null!=s.page&&r.searchParams.set("page",`${s.page}`),s.prettyUrlDuplicated&&r.searchParams.set("tocId",s.tocId),null!=s.section&&r.searchParams.set("section",s.section),r.href}getNavigationData(t,i,e){var s,n;t=t||"root";const r=this.enrichedToc,o=null==r?void 0:r.pageByTocId[t],a=null==r?void 0:r.nodeByTocId[t],h=null==a?void 0:a.prettyUrl;return{mapId:this.mapId,tocId:t,topicTitle:null!==(s=null==a?void 0:a.title)&&void 0!==s?s:"",page:i&&o&&o.number!==i?i:void 0,prettyUrl:null!=h?h.replace(/^r\//,""):void 0,prettyUrlDuplicated:null!==(n=null==r?void 0:r.duplicatedPrettyUrls.has(null!=h?h:""))&&void 0!==n&&n,section:e}}async getAccurateNavigationData(t,i,e){return await this.getEnrichedToc(),this.getNavigationData(t,i,e)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then((t=>null==t?void 0:t.publication))}getTopicRating(t){return this.getRatingSummary().then((i=>{var e;return i?{type:i.topics.type,rating:null===(e=i.topics)||void 0===e?void 0:e.ratings.find((i=>i.tocId===t))}:void 0}))}rateMap(t,i){return this.makeRateMapRequest(t,i).then((()=>this.clearRatingIfNecessary()))}unrateMap(){return this.makeUnrateMapRequest().then((()=>this.clearRatingIfNecessary()))}sendMapFeedback(t,i){return this.makeMapFeedbackRequest(t,i)}rateTopic(t,i,e){return this.makeRateTopicRequest(t,i,e).then((()=>this.clearRatingIfNecessary()))}unrateTopic(t){return this.makeUnrateTopicRequest(t).then((()=>this.clearRatingIfNecessary()))}async clearRatingIfNecessary(){const t=U.getState().session;(null==t?void 0:t.sessionAuthenticated)&&this.cache.clear("ratingSummary")}sendTopicFeedback(t,i,e){return this.makeTopicFeedbackRequest(t,i,e)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(t){let i=this.getTocNodeNow(t),e=[{tocId:i.tocId,title:i.title}],s=this.getTocNodeNow(i.parentTocId);for(;s;)e.unshift({tocId:s.tocId,title:s.title}),s=this.getTocNodeNow(s.parentTocId);return e}isFeatureAccessible(i,{session:e,ratingType:s}){if(!this.isFeatureAvailable(i))return!1;switch(i){case t.FtReaderFeatures.FEEDBACK:return R(null!=e?e:[],b.FEEDBACK_USER);case t.FtReaderFeatures.RATING:return R(null!=e?e:[],b.RATING_USER)&&null!=s&&s!==d.NO_RATING;case t.FtReaderFeatures.PRINT:return R(null!=e?e:[],b.PRINT_USER);case t.FtReaderFeatures.BOOKMARK:return!!(null==e?void 0:e.sessionAuthenticated);case t.FtReaderFeatures.COLLECTIONS:return R(null!=e?e:[],b.COLLECTION_USER);case t.FtReaderFeatures.PERSONAL_BOOKS:return R(null!=e?e:[],b.PERSONAL_BOOK_USER);default:return!1}}makeAbsolute(t){return this.api.makeAbsolute(t)}}class K extends G{static async build(t){return new K(new r,void 0,t)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(t){const i=await this.api.getMap(t);return this.fingerprint=i.fingerprint,i}fetchMapRating(t){return this.api.getMapRating(t)}async fetchPages(t){return await this.getMap(),this.api.getPages(t,this.fingerprint)}fetchTopicHTMLContent(t){return this.api.getTopicHTMLContent(this.mapId,t.contentId,"DESIGNED_READER",this.fingerprint)}fetchTopicMetadata(t){return this.api.getTopic(this.mapId,t.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch((()=>[]))}fetchRelativesForDocument(t,i){return this.api.search({query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",filters:[{negative:!1,values:i,key:t}],sort:[],facets:[]})}fetchRelativesForTopicInMap(t,i,e){return this.api.search({query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",filters:[{negative:!1,values:e,key:i},{negative:!1,values:[t],key:"ft:publicationId"}],sort:[],facets:[]})}makeMapFeedbackRequest(t,i){return this.api.sendMapFeedback(this.mapId,t,i)}makeRateMapRequest(t,i){return this.api.rateMap(this.mapId,t,i)}makeRateTopicRequest(t,i,e){return this.api.rateTopic(this.mapId,t,i,e)}makeTopicFeedbackRequest(t,i,e){return this.api.sendTopicFeedback(this.mapId,t,i,e)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(t){return this.api.unrateTopic(this.mapId,t)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(t){return!0}}class q{static build(t,e){return new q((t=>i.FtReduxStore.get({name:"ft-reader-"+t,initialState:{mapId:void 0,visibleTopics:[],map:void 0,toc:void 0,pagesToc:void 0,paginationConfiguration:void 0,currentPage:void 0,scrollTarget:void 0,configuration:void 0,searchInDocumentQuery:void 0,relatives:void 0}}))(t.trim()||"context"),null!=e?e:K.build)}constructor(t,e){this.store=t,this.metadataForSwitchToRelatives=new Set,this.loadDebouncer=new i.Debouncer(10),this.initService(e)}async initService(t){return this.service=await t(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(t){t!==this.store.getState().mapId&&(this.store.actions.mapId(t),this.service&&(this.service.mapId=t),await this.reload())}setVisibleTopics(t){this.store.actions.visibleTopics(t)}async awaitService(){return i.waitFor((()=>this.service))}async navigateToTopic(t,i,e){const s=await this.awaitService(),n=await(null!=e?s.getPage(e):s.getPageByTocId(null!=t?t:"root"));this.store.actions.currentPage(n),this.store.actions.scrollTarget({tocId:this.resolveValidNonRootTocId(t,n),section:i})}resolveValidNonRootTocId(t,i){var e,s,n;let r=null!==(e="root"===t?void 0:t)&&void 0!==e?e:i.rootTocId;return i.topics.includes(r)?r:null!==(n=null!==(s=i.topics[0])&&void 0!==s?s:i.hiddenTopics[0])&&void 0!==n?n:"root"}async navigateToPage(t){const i=await this.awaitService();let e=await i.getPage(t);this.store.actions.currentPage(e)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var t;(null===(t=this.service)||void 0===t?void 0:t.mapId)&&null==this.store.getState().map&&await this.loadDebouncer.run((()=>this.fetchData()))}clear(){var t;this.store.actions.configuration(void 0),this.store.actions.map(void 0),this.store.actions.toc(void 0),this.store.actions.pagesToc(void 0),this.store.actions.currentPage(void 0),this.store.actions.searchInDocumentQuery(""),this.store.actions.relatives(void 0),null===(t=this.service)||void 0===t||t.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(){var t,e,s,n,r;try{await Promise.all([null===(t=this.service)||void 0===t?void 0:t.getConfiguration().then((t=>this.store.actions.configuration(t))),null===(e=this.service)||void 0===e?void 0:e.getMap().then((t=>this.store.actions.map(t))),null===(s=this.service)||void 0===s?void 0:s.getToc().then((t=>this.store.actions.toc(t))),null===(n=this.service)||void 0===n?void 0:n.getPagesToc().then((t=>this.store.actions.pagesToc(t))),null===(r=this.service)||void 0===r?void 0:r.getPaginationConfiguration().then((t=>this.store.actions.paginationConfiguration(t)))]).then((()=>{this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives()}))}catch(t){!this.errorHandler||t instanceof i.CanceledPromiseError||this.errorHandler(t)}}fetchRelatives(){var t,i,e;const s=null===(t=this.store.getState().map)||void 0===t?void 0:t.metadata.filter((t=>{var i;return t.key==(null===(i=this.store.getState().configuration)||void 0===i?void 0:i.relativePivotMetadata)})).flatMap((t=>t.values));void 0!==s&&s.length>0&&(null===(i=this.service)||void 0===i||i.getRelativesForDocument(null===(e=this.store.getState().configuration)||void 0===e?void 0:e.relativePivotMetadata,s).then((t=>{const i=t.results.flatMap((t=>t.entries));this.store.actions.relatives(i),this.createClusteringHelper()})))}createClusteringHelper(){var t,e;this.store.getState().relatives&&(this.clusteringHelper=new i.ClusteringHelper(this.store.getState().relatives,this.store.getState().relatives.find((t=>{var i;return(null===(i=t.map)||void 0===i?void 0:i.mapId)==this.store.getState().mapId})),this.metadataForSwitchToRelatives,null!==(e=null===(t=U.getState().metadataConfiguration)||void 0===t?void 0:t.descriptors)&&void 0!==e?e:[]),this.store.eventBus.dispatchEvent(new CustomEvent("clustering-helper-created")))}async navigateToRelativeTopicIfFound(t){var e,s,n;const r=await i.waitFor((()=>{var t;return null===(t=this.store.getState().configuration)||void 0===t?void 0:t.relativeTopicPivotMetadata})),o=this.store.getState().mapId,a=await this.awaitService(),h=await a.getRelativesForTopicInMap(o,r,[t]);if(null===(n=null===(s=null===(e=null==h?void 0:h.results)||void 0===e?void 0:e[0])||void 0===s?void 0:s.entries)||void 0===n?void 0:n[0]){const t=h.results[0].entries[0].topic.tocId;return await this.navigateToTopic(t),!0}return await this.navigateToTopic("root"),!1}setSearchInDocumentQuery(t){this.store.actions.searchInDocumentQuery(t)}registerMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.add(t),null==this.store.getState().relatives?this.fetchRelatives():this.createClusteringHelper()}unregisterMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.delete(t),this.createClusteringHelper()}}const V=e.css`
4
+ `}update(t){super.update(t),t.has("baseUrl")&&(U.actions.baseUrl(this.baseUrl),window.fluidTopicsBaseUrl=this.baseUrl),t.has("apiIntegrationIdentifier")&&U.actions.apiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&U.actions.uiLocale(this.uiLocale),t.has("metadataConfiguration")&&U.actions.metadataConfiguration(this.metadataConfiguration),t.has("noCustom")&&U.actions.noCustom(this.noCustom),t.has("editorMode")&&U.actions.editorMode(this.editorMode),t.has("noCustomComponent")&&U.actions.noCustomComponent(this.noCustomComponent),t.has("session")&&U.actions.session(this.session),t.has("availableUiLocales")&&U.actions.availableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>_.addContext(t))),t.has("openExternalDocumentInNewTab")&&U.actions.openExternalDocumentInNewTab(this.openExternalDocumentInNewTab),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){!this.withManualResources&&this.apiProvider()&&(null==this.session&&this.updateSession(),null==this.availableUiLocales&&this.updateUiLocales(),null==this.metadataConfiguration&&this.updateMetadataConfiguration())}async updateSession(){this.session=await this.cache.get("session",(async()=>{const t=await this.apiProvider().getCurrentSession();return t.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),t.idleTimeoutInMillis),t}))}async updateUiLocales(){this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>this.apiProvider().getAvailableUiLocales()))}async updateMetadataConfiguration(){this.metadataConfiguration=await this.cache.get("metadataConfiguration",(()=>this.apiProvider().getMetadataConfiguration()))}}k.elementDefinitions={},k.styles=C,B([s.property()],k.prototype,"baseUrl",void 0),B([s.property()],k.prototype,"apiIntegrationIdentifier",void 0),B([s.property()],k.prototype,"uiLocale",void 0),B([i.jsonProperty(null)],k.prototype,"availableUiLocales",void 0),B([i.jsonProperty(null)],k.prototype,"metadataConfiguration",void 0),B([s.property({type:Boolean})],k.prototype,"editorMode",void 0),B([s.property({type:Boolean})],k.prototype,"noCustom",void 0),B([s.property({type:Boolean})],k.prototype,"openExternalDocumentInNewTab",void 0),B([s.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],k.prototype,"noCustomComponent",void 0),B([s.property({type:Boolean})],k.prototype,"withManualResources",void 0),B([i.jsonProperty([])],k.prototype,"messageContexts",void 0),B([i.jsonProperty(void 0)],k.prototype,"session",void 0),B([s.property({type:Object})],k.prototype,"apiProvider",void 0);class x extends N{async listMySearches(){let t=U.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-searches",(async()=>(await this.awaitApi).listMySearches(t.profile.userId)),3e5):[]}}class F extends N{async listMyBookmarks(){let t=U.getState().session;return(null==t?void 0:t.sessionAuthenticated)?this.cache.get("my-bookmarks",(async()=>(await this.awaitApi).listMyBookmarks(t.profile.userId)),3e5):[]}}const j=i.FtReduxStore.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const H=new class{constructor(){this.currentSession=U.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new F,this.savedSearchesService=new x,U.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:e}=U.getState();i.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==e?void 0:e.profile)||(this.currentSession=e,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){this.savedSearchesService.clearCache(),j.actions.savedSearches(void 0)}clearMyBookmarks(){this.bookmarksService.clearCache(),j.actions.bookmarks(void 0)}async reloadMySearches(){this.savedSearchesService.clearCache();const t=await this.savedSearchesService.listMySearches();j.actions.savedSearches(t)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const i=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;j.actions.bookmarks(i)}}};i.customElement("ft-app-context")(k);class G extends N{get mapId(){return this._mapId}set mapId(t){t!==this._mapId&&this.clear(),this._mapId=t}constructor(t,i,e){super(!1,i),this.converter=t,this._mapId=e,this.initCache()}async withMapId(t){return this._mapId?t(this._mapId):void 0}initCache(){this.cache.registerFinal("configuration",(()=>this.api.getReaderConfiguration())),this.cache.register("map",(()=>this.withMapId((t=>this.fetchMap(t))))),this.cache.register("enrichedToc",(()=>this.withMapId((t=>this.fetchPages(t).then((t=>this.converter.convertPaginatedToc(t))))))),this.cache.register("ratingSummary",(()=>{var t,i;return R(null!==(i=null===(t=U.getState().session)||void 0===t?void 0:t.profile.roles)&&void 0!==i?i:[],"RATING_USER")?this.withMapId((t=>this.fetchMapRating(t))):Promise.resolve()}))}clear(){this.cache.clearAll()}getMap(){return this.cache.get("map")}getMapNow(){return this.cache.getNow("map")}getConfiguration(){return this.cache.get("configuration")}getEnrichedToc(){return this.cache.get("enrichedToc")}get enrichedToc(){return this.cache.getNow("enrichedToc")}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(){return(await this.getEnrichedToc()).toc}async getPagesToc(){return(await this.getEnrichedToc()).pagesToc}async getTocNode(t){return(await this.getEnrichedToc()).nodeByTocId[t]}getTocNodeNow(t){var i;return null===(i=this.enrichedToc)||void 0===i?void 0:i.nodeByTocId[t]}async getPage(t){const i=await this.getEnrichedToc();return i.pages[t-1]||i.pages[0]}async getPageByTocId(t){const i=await this.getEnrichedToc();return i.pageByTocId[t]||i.pages[0]}getTopicInfo(t){return this.cache.get("topic-"+t.tocId,(()=>this.fetchTopicMetadata(t)))}getTopicContent(t){return this.cache.get("topic-content-"+t.tocId,(()=>this.fetchTopicHTMLContent(t)))}getAttachments(){return this.cache.get("map-attachments",(()=>this.fetchAttachments()))}getRelativesForDocument(t,i){return this.cache.get("document-relatives-"+t+"-"+i.join("-"),(()=>this.fetchRelativesForDocument(t,i)))}getRelativesForTopicInMap(t,i,e){return this.cache.get("topic-relatives-"+[t,i,...e].join("-"),(()=>this.fetchRelativesForTopicInMap(t,i,e)))}getAttachmentDownloadLink(t){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(t).content}?download=true`)}getLink(t,i,e){const s=this.getNavigationData(t,i,e),n=this.getReaderLinkPrefix()+(s.prettyUrl?s.prettyUrl:`${s.mapId}/${s.tocId}`),r=new URL(n,this.api.tenantBaseUrl);return null!=s.page&&r.searchParams.set("page",`${s.page}`),s.prettyUrlDuplicated&&r.searchParams.set("tocId",s.tocId),null!=s.section&&r.searchParams.set("section",s.section),r.href}getNavigationData(t,i,e){var s,n;t=t||"root";const r=this.enrichedToc,o=null==r?void 0:r.pageByTocId[t],a=null==r?void 0:r.nodeByTocId[t],h=null==a?void 0:a.prettyUrl;return{mapId:this.mapId,tocId:t,topicTitle:null!==(s=null==a?void 0:a.title)&&void 0!==s?s:"",page:i&&o&&o.number!==i?i:void 0,prettyUrl:null!=h?h.replace(/^r\//,""):void 0,prettyUrlDuplicated:null!==(n=null==r?void 0:r.duplicatedPrettyUrls.has(null!=h?h:""))&&void 0!==n&&n,section:e}}async getAccurateNavigationData(t,i,e){return await this.getEnrichedToc(),this.getNavigationData(t,i,e)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then((t=>null==t?void 0:t.publication))}getTopicRating(t){return this.getRatingSummary().then((i=>{var e;return i?{type:i.topics.type,rating:null===(e=i.topics)||void 0===e?void 0:e.ratings.find((i=>i.tocId===t))}:void 0}))}rateMap(t,i){return this.makeRateMapRequest(t,i).then((()=>this.clearRatingIfNecessary()))}unrateMap(){return this.makeUnrateMapRequest().then((()=>this.clearRatingIfNecessary()))}sendMapFeedback(t,i){return this.makeMapFeedbackRequest(t,i)}rateTopic(t,i,e){return this.makeRateTopicRequest(t,i,e).then((()=>this.clearRatingIfNecessary()))}unrateTopic(t){return this.makeUnrateTopicRequest(t).then((()=>this.clearRatingIfNecessary()))}async clearRatingIfNecessary(){const t=U.getState().session;(null==t?void 0:t.sessionAuthenticated)&&this.cache.clear("ratingSummary")}sendTopicFeedback(t,i,e){return this.makeTopicFeedbackRequest(t,i,e)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(t){let i=this.getTocNodeNow(t),e=[{tocId:i.tocId,title:i.title}],s=this.getTocNodeNow(i.parentTocId);for(;s;)e.unshift({tocId:s.tocId,title:s.title}),s=this.getTocNodeNow(s.parentTocId);return e}isFeatureAccessible(i,{session:e,ratingType:s}){var n;if(!this.isFeatureAvailable(i))return!1;switch(i){case t.FtReaderFeatures.FEEDBACK:return R(null!=e?e:[],b.FEEDBACK_USER);case t.FtReaderFeatures.RATING:return R(null!=e?e:[],b.RATING_USER)&&null!=s&&s!==d.NO_RATING;case t.FtReaderFeatures.PRINT:return R(null!=e?e:[],b.PRINT_USER);case t.FtReaderFeatures.BOOKMARK:return!!(null==e?void 0:e.sessionAuthenticated);case t.FtReaderFeatures.COLLECTIONS:return R(null!=e?e:[],b.COLLECTION_USER);case t.FtReaderFeatures.PERSONAL_BOOKS:return R(null!=e?e:[],b.PERSONAL_BOOK_USER)&&!(null===(n=this.getMapNow())||void 0===n?void 0:n.pbkConfidential);default:return!1}}makeAbsolute(t){return this.api.makeAbsolute(t)}}class K extends G{static async build(t){return new K(new r,void 0,t)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(t){const i=await this.api.getMap(t);return this.fingerprint=i.fingerprint,i}fetchMapRating(t){return this.api.getMapRating(t)}async fetchPages(t){return await this.getMap(),this.api.getPages(t,this.fingerprint)}fetchTopicHTMLContent(t){return this.api.getTopicHTMLContent(this.mapId,t.contentId,"DESIGNED_READER",this.fingerprint)}fetchTopicMetadata(t){return this.api.getTopic(this.mapId,t.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch((()=>[]))}fetchRelativesForDocument(t,i){return this.api.search({query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",filters:[{negative:!1,values:i,key:t}],sort:[],facets:[]})}fetchRelativesForTopicInMap(t,i,e){return this.api.search({query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",filters:[{negative:!1,values:e,key:i},{negative:!1,values:[t],key:"ft:publicationId"}],sort:[],facets:[]})}makeMapFeedbackRequest(t,i){return this.api.sendMapFeedback(this.mapId,t,i)}makeRateMapRequest(t,i){return this.api.rateMap(this.mapId,t,i)}makeRateTopicRequest(t,i,e){return this.api.rateTopic(this.mapId,t,i,e)}makeTopicFeedbackRequest(t,i,e){return this.api.sendTopicFeedback(this.mapId,t,i,e)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(t){return this.api.unrateTopic(this.mapId,t)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(t){return!0}}class q{static build(t,e){return new q((t=>i.FtReduxStore.get({name:"ft-reader-"+t,initialState:{mapId:void 0,visibleTopics:[],map:void 0,toc:void 0,pagesToc:void 0,paginationConfiguration:void 0,currentPage:void 0,scrollTarget:void 0,configuration:void 0,searchInDocumentQuery:void 0,relatives:void 0}}))(t.trim()||"context"),null!=e?e:K.build)}constructor(t,e){this.store=t,this.metadataForSwitchToRelatives=new Set,this.loadDebouncer=new i.Debouncer(10),this.initService(e)}async initService(t){return this.service=await t(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(t){t!==this.store.getState().mapId&&(this.store.actions.mapId(t),this.service&&(this.service.mapId=t),await this.reload())}setVisibleTopics(t){this.store.actions.visibleTopics(t)}async awaitService(){return i.waitFor((()=>this.service))}async navigateToTopic(t,i,e){const s=await this.awaitService(),n=await(null!=e?s.getPage(e):s.getPageByTocId(null!=t?t:"root"));this.store.actions.currentPage(n),this.store.actions.scrollTarget({tocId:this.resolveValidNonRootTocId(t,n),section:i})}resolveValidNonRootTocId(t,i){var e,s,n;let r=null!==(e="root"===t?void 0:t)&&void 0!==e?e:i.rootTocId;return i.topics.includes(r)?r:null!==(n=null!==(s=i.topics[0])&&void 0!==s?s:i.hiddenTopics[0])&&void 0!==n?n:"root"}async navigateToPage(t){const i=await this.awaitService();let e=await i.getPage(t);this.store.actions.currentPage(e)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var t;(null===(t=this.service)||void 0===t?void 0:t.mapId)&&null==this.store.getState().map&&await this.loadDebouncer.run((()=>this.fetchData()))}clear(){var t;this.store.actions.configuration(void 0),this.store.actions.map(void 0),this.store.actions.toc(void 0),this.store.actions.pagesToc(void 0),this.store.actions.currentPage(void 0),this.store.actions.searchInDocumentQuery(""),this.store.actions.relatives(void 0),null===(t=this.service)||void 0===t||t.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(){var t,e,s,n,r;try{await Promise.all([null===(t=this.service)||void 0===t?void 0:t.getConfiguration().then((t=>this.store.actions.configuration(t))),null===(e=this.service)||void 0===e?void 0:e.getMap().then((t=>this.store.actions.map(t))),null===(s=this.service)||void 0===s?void 0:s.getToc().then((t=>this.store.actions.toc(t))),null===(n=this.service)||void 0===n?void 0:n.getPagesToc().then((t=>this.store.actions.pagesToc(t))),null===(r=this.service)||void 0===r?void 0:r.getPaginationConfiguration().then((t=>this.store.actions.paginationConfiguration(t)))]).then((()=>{this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives()}))}catch(t){!this.errorHandler||t instanceof i.CanceledPromiseError||this.errorHandler(t)}}fetchRelatives(){var t,i,e;const s=null===(t=this.store.getState().map)||void 0===t?void 0:t.metadata.filter((t=>{var i;return t.key==(null===(i=this.store.getState().configuration)||void 0===i?void 0:i.relativePivotMetadata)})).flatMap((t=>t.values));void 0!==s&&s.length>0&&(null===(i=this.service)||void 0===i||i.getRelativesForDocument(null===(e=this.store.getState().configuration)||void 0===e?void 0:e.relativePivotMetadata,s).then((t=>{const i=t.results.flatMap((t=>t.entries));this.store.actions.relatives(i),this.createClusteringHelper()})))}createClusteringHelper(){var t,e;this.store.getState().relatives&&(this.clusteringHelper=new i.ClusteringHelper(this.store.getState().relatives,this.store.getState().relatives.find((t=>{var i;return(null===(i=t.map)||void 0===i?void 0:i.mapId)==this.store.getState().mapId})),this.metadataForSwitchToRelatives,null!==(e=null===(t=U.getState().metadataConfiguration)||void 0===t?void 0:t.descriptors)&&void 0!==e?e:[]),this.store.eventBus.dispatchEvent(new CustomEvent("clustering-helper-created")))}async navigateToRelativeTopicIfFound(t){var e,s,n;const r=await i.waitFor((()=>{var t;return null===(t=this.store.getState().configuration)||void 0===t?void 0:t.relativeTopicPivotMetadata})),o=this.store.getState().mapId,a=await this.awaitService(),h=await a.getRelativesForTopicInMap(o,r,[t]);if(null===(n=null===(s=null===(e=null==h?void 0:h.results)||void 0===e?void 0:e[0])||void 0===s?void 0:s.entries)||void 0===n?void 0:n[0]){const t=h.results[0].entries[0].topic.tocId;return await this.navigateToTopic(t),!0}return await this.navigateToTopic("root"),!1}setSearchInDocumentQuery(t){this.store.actions.searchInDocumentQuery(t)}registerMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.add(t),null==this.store.getState().relatives?this.fetchRelatives():this.createClusteringHelper()}unregisterMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.delete(t),this.createClusteringHelper()}}const V=e.css`
5
5
  `;class $ extends CustomEvent{constructor(t,i){super("ft-reader-map-loaded",{detail:{map:t,toc:i}})}}class X extends CustomEvent{constructor(t,i){super("ft-reader-visible-topics-change",{detail:{visibleTopics:i}})}}class Y extends CustomEvent{constructor(t){super("ft-reader-navigation-done",{detail:t})}}class Q extends CustomEvent{constructor(t){super("ft-reader-load-error",{detail:t})}}class W extends Event{constructor(){super("ft-reader-map-not-found")}}class z extends Event{constructor(){super("ft-reader-map-unauthorized")}}class J extends Event{constructor(){super("ft-reader-map-forbidden")}}class Z extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}}var tt=function(t,i,e,s){for(var n,r=arguments.length,o=r<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(i,e,o):n(i,e))||o);return r>3&&o&&Object.defineProperty(i,e,o),o};class it extends i.FtLitElementRedux{constructor(){super(),this.visibleTopics=[],this.scrollToTargetDebouncer=new i.Debouncer(5),this.navigationDebouncer=new i.Debouncer(10),this.mapLoadedEventDebouncer=new i.Debouncer(50),this.addStore(U)}render(){return e.html`
6
6
  ${this.importStyleIfNeeded()}
7
7
  <slot @register-ft-reader-component=${this.registerComponent}></slot>