@fluid-topics/ft-reader-feedback 2.0.25 → 2.0.27
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.
|
@@ -2537,7 +2537,7 @@ svg:not(:root).svg-inline--fa, svg:not(:host).svg-inline--fa {
|
|
|
2537
2537
|
.value=${this.icon}
|
|
2538
2538
|
@click=${()=>{var e;return(e=this.input)===null||e===void 0?void 0:e.focus()}}></ft-icon>
|
|
2539
2539
|
`:Me.nothing}update(e){super.update(e),(e.has("value")||e.has("filterSuggestions")||e.has("suggestionsProvider"))&&this.updateSuggestions(),e.has("value")&&e.get("value")!=null&&(this.hideSuggestions=!1),e.has("dispatchedValue")&&e.get("dispatchedValue")!=null&&(this.hideSuggestions=!0)}async updateSuggestions(){this.suggestionsProvider?this.providedSuggestions=await this.suggestionsProvider(this.value):this.filterSuggestionsIfNeeded()}filterSuggestionsIfNeeded(){this.filterSuggestions?(this.slottedSuggestions.forEach(e=>e.hidden=!e.getValue().toLowerCase().includes(this.value.toLowerCase())),this.visibleSuggestions=this.slottedSuggestions.filter(e=>!e.hidden)):this.visibleSuggestions=this.slottedSuggestions,this.newValueSuggestion&&(this.visibleSuggestions=[...this.visibleSuggestions,this.newValueSuggestion]),this.hideSuggestions=this.visibleSuggestions.length<=0}contentAvailableCallback(e){super.contentAvailableCallback(e),e.has("focused")&&!this.hideSuggestions&&this.visibleSuggestions.length>0&&this.setSuggestionPosition(),e.has("value")&&this.suggestionsProvider&&(this.visibleSuggestions=[...this.providedSuggestionsInDom]),e.has("autocomplete")&&this.setupWatchAutofill(),this.suggestionsShouldBeDisplayed()&&this.setSuggestionPosition()}setupWatchAutofill(){var e;this.clearWatchAutofill(),((e=this.autocomplete)!==null&&e!==void 0?e:"off")!=="off"&&(this.watchAutofillInterval=setInterval(()=>{var r,o,a;!((r=this.input)===null||r===void 0)&&r.matches(":autofill")&&this.dispatchedValue!==((o=this.input)===null||o===void 0?void 0:o.value)&&this.setValue((a=this.input)===null||a===void 0?void 0:a.value,!0)},200))}clearWatchAutofill(){this.watchAutofillInterval&&clearInterval(this.watchAutofillInterval)}connectedCallback(){super.connectedCallback(),this.setupWatchAutofill()}disconnectedCallback(){super.disconnectedCallback(),this.clearWatchAutofill()}setValue(e,r=!1){var o,a;this.value!==e&&(this.inputValid=!0,this.setInternalValue(e),this.dispatchEvent(new ri(e))),r&&this.dispatchedValue!==e&&(this.inputValid=(a=(o=this.input)===null||o===void 0?void 0:o.checkValidity())!==null&&a!==void 0?a:!0,this.inputValid?(this.dispatchedValue=e,this.dispatchEvent(new oi(e))):this.dispatchEvent(new ni(this.input.validationMessage)))}handleInput(e){var r;let o=((r=this.input)===null||r===void 0?void 0:r.value)||"";this.setValue(o,e.key=="Escape"||e.key=="Enter")}handleClick(){this.hideSuggestions=!1}handleKeyboardNavigation(e){var r;if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault(),e.stopPropagation(),this.hideSuggestions=!1;let o=this.visibleSuggestions.findIndex(i=>i.matches(":focus-within")),a;e.key==="ArrowDown"?a=o<this.visibleSuggestions.length-1?o+1:0:a=o>0?o-1:this.visibleSuggestions.length-1,(r=this.visibleSuggestions[a])===null||r===void 0||r.focus()}(e.key=="Escape"||e.key=="Enter")&&(this.hideSuggestions=!0)}onSuggestionSelected(e){var r;this.setValue(e.detail,!0),(r=this.input)===null||r===void 0||r.focus(),setTimeout(()=>this.hideSuggestions=!0,0)}onFocus(){this.focused=!0,this.hideSuggestions=!1}onMainPanelBlur(){var e,r;!((e=this.mainPanel)===null||e===void 0)&&e.matches(":focus-within")||(this.focused=!1,this.setValue(((r=this.input)===null||r===void 0?void 0:r.value)||"",!0))}togglePasswordVisibility(){this.hidePassword=!this.hidePassword}isPasswordField(){return this.password||this.type==="password"}setSuggestionPosition(){this.suggestionsContainer.style.width=this.mainPanel.getBoundingClientRect().width+"px";let e=["bottom","top"];(0,Rt.computeOffsetAutoPosition)(this.mainPanel,this.suggestionsContainer,"bottom",e,"fixed","--text-field-internal-suggest-size",0).then(({x:r,y:o})=>{this.suggestionsContainer.style.left=`${r}px`,this.suggestionsContainer.style.top=`${o}px`})}suggestionsShouldBeDisplayed(){return!this.hideSuggestions&&(this.visibleSuggestions.length||this.providedSuggestions.length)}};G.elementDefinitions={"ft-input-label":pt,"ft-ripple":Q,"ft-typography":be,"ft-icon":xe,"ft-text-field-suggestion":Ot};G.styles=[go,Rt.noTextInputDefaultClearButton,wu];q([(0,j.property)()],G.prototype,"label",void 0);q([(0,j.property)({noAccessor:!0})],G.prototype,"value",null);q([(0,j.state)()],G.prototype,"dispatchedValue",void 0);q([(0,j.property)()],G.prototype,"helper",void 0);q([(0,j.property)()],G.prototype,"suggestionsHelper",void 0);q([(0,j.property)({type:Boolean})],G.prototype,"outlined",void 0);q([(0,j.property)({type:Boolean})],G.prototype,"disabled",void 0);q([(0,j.property)({type:Boolean})],G.prototype,"error",void 0);q([(0,j.property)({type:Boolean})],G.prototype,"fixedMenuPosition",void 0);q([(0,j.property)()],G.prototype,"prefix",void 0);q([(0,j.property)()],G.prototype,"icon",void 0);q([(0,j.property)()],G.prototype,"name",void 0);q([(0,j.property)()],G.prototype,"type",void 0);q([(0,j.property)()],G.prototype,"passwordHiddenIcon",void 0);q([(0,j.property)()],G.prototype,"passwordRevealedIcon",void 0);q([(0,j.property)()],G.prototype,"iconVariant",void 0);q([(0,j.property)({type:Boolean})],G.prototype,"filterSuggestions",void 0);q([(0,Rt.numberProperty)()],G.prototype,"maxLength",void 0);q([(0,j.property)({type:Boolean})],G.prototype,"password",void 0);q([(0,j.property)({type:String})],G.prototype,"autocomplete",void 0);q([(0,j.property)({attribute:!1})],G.prototype,"suggestionsProvider",void 0);q([(0,j.state)()],G.prototype,"focused",void 0);q([(0,j.state)()],G.prototype,"inputValid",void 0);q([(0,j.state)()],G.prototype,"hidePassword",void 0);q([(0,j.state)()],G.prototype,"hideSuggestions",void 0);q([(0,j.state)()],G.prototype,"visibleSuggestions",void 0);q([(0,j.state)()],G.prototype,"providedSuggestions",void 0);q([(0,j.query)(".ft-text-field--main-panel")],G.prototype,"mainPanel",void 0);q([(0,j.query)(".ft-text-field--input")],G.prototype,"input",void 0);q([(0,j.query)(".ft-text-field-suggestion--new-value")],G.prototype,"newValueSuggestion",void 0);q([(0,j.query)(".ft-text-field--suggestions")],G.prototype,"suggestionsContainer",void 0);q([(0,j.queryAll)("ft-text-field-suggestion")],G.prototype,"providedSuggestionsInDom",void 0);q([(0,j.queryAssignedElements)({selector:"ft-text-field-suggestion"})],G.prototype,"slottedSuggestions",void 0);q([(0,Rt.ignoreComposingEvents)()],G.prototype,"handleInput",null);var Nc=v(_());(0,Nc.customElement)("ft-text-field")(G);(0,Nc.customElement)("ft-text-field-suggestion")(Ot);var Pu=v(F());var zu=Pu.css`
|
|
2540
|
-
`;var Dn=v(F()),lo=v(X()),Ue=v(_());var it=v(_());var Du=v(_()),E3={setTranslationDestinationLanguage:(t,e)=>{t.translation.destinationLanguage=e.payload},setTranslationSourceLanguage:(t,e)=>{t.translation.sourceLanguage=e.payload},setTranslationProfileId:(t,e)=>{t.translation.profileId=e.payload},setTranslationLoading:(t,e)=>{t.translation.isLoading=e.payload},setTranslationError:(t,e)=>{t.translation.isError=e.payload},setTopicsRating:(t,e)=>{for(let r in e.payload)t.topicsRating[r]=e.payload[r]}},Uu=t=>Du.FtReduxStore.get({name:"ft-reader-"+t,initialState:{mapId:void 0,renderedTopics:[],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,mapRating:void 0,topicsRating:{},translation:{sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1},linkPreviewDialogId:void 0},reducers:E3});var Mc=class{constructor(e,r){this.mapId=e,this.paginatedToc=r,this.nodeByTocId={},this.nodeByUrl={},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,nodeByUrl:this.nodeByUrl,duplicatedPrettyUrls:this.duplicatedPrettyUrls,pages:this.pages,pageByTocId:this.pageByTocId,translationError:this.paginatedToc.translationError}}extractPagesToc(e,r,o){return e.flatMap(a=>{var i;return a.pageConfiguration&&this.registerPage(this.buildPage(a,o)),a.tocId==null?this.extractPagesToc(a.children,r,o):[{tocId:a.tocId,title:(i=a.title)!==null&&i!==void 0?i:"",untranslatedTitle:a.untranslatedTitle,depth:r,children:this.extractPagesToc(a.children,r+1,a.tocId)}]})}convertNodes(e,r,o){return e.flatMap(a=>{var i,s,c;if(a.tocId==null)return[...this.convertSectionNodes((i=a.pageToc)!==null&&i!==void 0?i:[],r,a.tocId),...this.convertNodes(a.children,r,a.tocId)];let u=(s=a.prettyUrl)===null||s===void 0?void 0:s.replace(/^\//,""),f={tocId:a.tocId,contentId:a.contentId,title:a.title,untranslatedTitle:a.untranslatedTitle,hasRating:a.hasRating,origin:a.origin,prettyUrl:u,depth:r,parentTocId:o,children:[]};this.register(f);let h=this.convertSectionNodes((c=a.pageToc)!==null&&c!==void 0?c:[],r+1,a.tocId),g=this.convertNodes(a.children,r+1,f.tocId);return f.children=[...h,...g],[f]})}convertSectionNodes(e,r,o){return e.flatMap(a=>{var i;let s=(i=a.prettyUrl)===null||i===void 0?void 0:i.replace(/^\//,""),c={...a,prettyUrl:s,depth:r,parentTocId:o,children:[]};return this.register(c),c.children=this.convertSectionNodes(a.children,r+1,a.tocId),[c]})}buildPage(e,r){var o,a,i,s,c,u;let f={number:this.pages.length+1,title:(o=e.title)!==null&&o!==void 0?o:"",untranslatedTitle:e.untranslatedTitle,rootTocId:(a=e.tocId)!==null&&a!==void 0?a:"root",toc:((i=e.pageToc)!==null&&i!==void 0?i:[]).map(y=>this.nodeByTocId[y.tocId]),topics:[],hiddenTopics:[],breadcrumb:r?this.buildBreadcrumb(this.nodeByTocId[r]):[]},h=(y,S)=>(S?f.topics:f.hiddenTopics).push(y),g=(c=(s=e.pageConfiguration)===null||s===void 0?void 0:s.parentsVisibility)!==null&&c!==void 0?c:[];return f.breadcrumb.forEach((y,S)=>{h(y,g[S])}),e.tocId&&h(e.tocId,e.pageConfiguration.isVisible),f.topics.push(...this.tocIds((u=e.pageToc)!==null&&u!==void 0?u:[])),f}registerPage(e){for(let r of[...e.topics,...e.hiddenTopics])this.pageByTocId[r]||(this.pageByTocId[r]=e);this.pages.push(e)}tocIds(e){return e.flatMap(r=>[r.tocId,...this.tocIds(r.children)])}buildBreadcrumb(e){let r=[e.tocId];for(;e?.parentTocId;)r.unshift(e.parentTocId),e=this.nodeByTocId[e.parentTocId];return r}register(e){e.prettyUrl&&(this.nodeByUrl[e.prettyUrl]==null?this.nodeByUrl[e.prettyUrl]=e:this.duplicatedPrettyUrls.add(e.prettyUrl)),this.nodeByUrl[`${this.mapId}/${e.tocId}`]=e,this.nodeByTocId[e.tocId]=e}},ii=class{convertPaginatedToc(e,r){return new Mc(e,r).build()}};var si=class extends je{get mapId(){return this._mapId}set mapId(e){e!==this._mapId&&this.clear(),this._mapId=e}constructor(e,r,o){super(!1,r),this.converter=e,this._mapId=o,this.initCache()}async withMapId(e){return this._mapId?e(this._mapId):void 0}initCache(){this.cache.register("configuration",()=>this.api.getReaderConfiguration()),this.cache.register("map",()=>this.withMapId(e=>this.fetchMap(e))),this.cache.register("enrichedToc",()=>this.withMapId(e=>this.fetchPages(e).then(r=>this.converter.convertPaginatedToc(e,r)))),this.cache.register("ratingSummary",()=>{var e,r;return Jt((r=(e=k.getState().session)===null||e===void 0?void 0:e.profile.roles)!==null&&r!==void 0?r:[],"RATING_USER")?this.withMapId(a=>this.fetchMapRating(a)):Promise.resolve()})}clear(){this.cache.clearMatching(e=>e!=="configuration")}makeCacheKey(e,r){return e+(r?"-destinationLanguage-"+r?.destinationLanguage:"")}getMap(e){return this.cache.get(this.makeCacheKey("map",e),()=>this.fetchMap(this.mapId,e))}getMapNow(e){return this.cache.getNow(this.makeCacheKey("map",e))}getConfiguration(){return this.cache.get("configuration")}clearConfiguration(){this.cache.clear("configuration")}getEnrichedToc(e){return this.cache.get(this.makeCacheKey("enrichedToc",e),()=>this.fetchPages(this.mapId,e).then(r=>this.converter.convertPaginatedToc(this.mapId,r)))}getEnrichedTocNow(e){return this.cache.getNow(this.makeCacheKey("enrichedToc",e))}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(e){return(await this.getEnrichedToc(e)).toc}async getPagesToc(e){return(await this.getEnrichedToc(e)).pagesToc}async getTranslationError(e){return(await this.getEnrichedToc(e)).translationError}async getTocNode(e,r){return(await this.getEnrichedToc(r)).nodeByTocId[e]}getTocNodeNow(e,r){var o;return(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.nodeByTocId[e]}getTocNodeNowByUrl(e,r){var o,a;let i=this.getMapNow(r);return i?.prettyUrl==e||`${i?.id}/root`===e?(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.toc[0]:(a=this.getEnrichedTocNow(r))===null||a===void 0?void 0:a.nodeByUrl[e]}async getPage(e,r){let o=await this.getEnrichedToc(r);return o.pages[e-1]||o.pages[0]}async getPageByTocId(e,r){let o=await this.getEnrichedToc(r);return o.pageByTocId[e]||o.pages[0]}getTopicInfo(e){return this.cache.get("topic-"+e.tocId,()=>this.fetchTopicMetadata(e))}getTopicContent(e){return this.cache.get("topic-content-"+e.tocId,()=>this.fetchTopicHTMLContent(e))}getTranslatedTopicContent(e,r){return this.cache.get(this.makeCacheKey("translated-topic-content-"+e.tocId,r),()=>this.fetchTranslatedTopicHTMLContent(e,r))}async getTopicMetadataValue(e,r){let o=this.getTocNodeNow(e);if(!o)return;let a=await this.getTopicInfo(o);return a?.metadata.find(i=>i.key==r)}getAttachments(){return this.cache.get("map-attachments",()=>this.fetchAttachments())}clearMapAttachments(){this.cache.clear("map-attachments")}getRelativesForDocument(e,r){return this.cache.get("document-relatives-"+e+"-"+r.join("-"),()=>this.fetchRelativesForDocument(e,r))}getRelativesForTopicInMap(e,r,o){return this.cache.get("topic-relatives-"+[e,r,...o].join("-"),()=>this.fetchRelativesForTopicInMap(e,r,o))}getAttachmentDownloadLink(e){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(e).content}?download=true&locationValue=reader`)}getLink(e,r,o){let a=this.getNavigationData(e,r,o),i=this.getReaderLinkPrefix()+(a.prettyUrl?a.prettyUrl:`${a.mapId}/${a.tocId}`),s=new URL(i,this.api.tenantBaseUrl);return a.page!=null&&s.searchParams.set("page",`${a.page}`),a.prettyUrlDuplicated&&s.searchParams.set("tocId",a.tocId),a.section!=null&&s.searchParams.set("section",a.section),s.href}getNavigationData(e,r,o,a){var i,s;e=e||"root";let c=this.getEnrichedTocNow(a),u=c?.pageByTocId[e],f=c?.nodeByTocId[e],h=f?.prettyUrl;return{mapId:this.mapId,tocId:e,topicTitle:(i=f?.title)!==null&&i!==void 0?i:"",untranslatedTopicTitle:f?.untranslatedTitle,page:r&&u&&u.number!==r?r:void 0,prettyUrl:h?.replace(/^r\//,""),prettyUrlDuplicated:(s=c?.duplicatedPrettyUrls.has(h??""))!==null&&s!==void 0?s:!1,section:o}}async getAccurateNavigationData(e,r,o,a){return await this.getEnrichedToc(a),this.getNavigationData(e,r,o,a)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then(e=>e?.publication)}getTopicRating(e){return this.getRatingSummary().then(r=>{var o;return r?{type:r.topics.type,rating:(o=r.topics)===null||o===void 0?void 0:o.ratings.find(a=>a.tocId===e)}:void 0})}rateMap(e,r){return this.makeRateMapRequest(e,r).then(()=>this.clearRatingIfNecessary())}unrateMap(){return this.makeUnrateMapRequest().then(()=>this.clearRatingIfNecessary())}sendMapFeedback(e,r){return this.makeMapFeedbackRequest(e,r)}rateTopic(e,r,o){return this.makeRateTopicRequest(e,r,o).then(()=>this.clearRatingIfNecessary())}unrateTopic(e){return this.makeUnrateTopicRequest(e).then(()=>this.clearRatingIfNecessary())}async clearRatingIfNecessary(){let e=k.getState().session;e?.sessionAuthenticated&&this.cache.clear("ratingSummary")}sendTopicFeedback(e,r,o){return this.makeTopicFeedbackRequest(e,r,o)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(e,r){let o=this.getTocNodeNow(e,r),a=[{tocId:o.tocId,title:o.title,untranslatedTitle:o.untranslatedTitle}],i=this.getTocNodeNow(o.parentTocId,r);for(;i;)a.unshift({tocId:i.tocId,title:i.title,untranslatedTitle:i.untranslatedTitle}),i=this.getTocNodeNow(i.parentTocId,r);return a}isFeatureAccessible(e,{session:r}){var o;if(!this.isFeatureAvailable(e))return!1;switch(e){case ht.FEEDBACK:return Jt(r??[],ae.FEEDBACK_USER);case ht.RATING:return Jt(r??[],ae.RATING_USER);case ht.PRINT:return Jt(r??[],ae.PRINT_USER);case ht.BOOKMARK:return!!r?.sessionAuthenticated;case ht.COLLECTIONS:return Jt(r??[],ae.COLLECTION_USER);case ht.PERSONAL_BOOKS:return Jt(r??[],ae.PERSONAL_BOOK_USER)&&!(!((o=this.getMapNow())===null||o===void 0)&&o.pbkConfidential);default:return!1}}makeAbsolute(e){return this.api.makeAbsolute(e)}};var ci=class t extends si{static async build(e){return new t(new ii,void 0,e)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(e,r){let o=await this.api.getMap(e,r);return this.fingerprint=o.fingerprint,o}fetchMapRating(e){return this.api.getMapRating(e)}async fetchPages(e,r){return await this.getMap(r),this.api.getPages(e,this.fingerprint,r)}fetchTopicHTMLContent(e){return this.api.getTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint)}fetchTranslatedTopicHTMLContent(e,r){return this.api.getTranslatedTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint,r)}fetchTopicMetadata(e){return this.api.getTopic(this.mapId,e.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch(()=>[])}fetchRelativesForDocument(e,r){let o={query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",metadataFilters:[{key:e,valueFilter:{negative:!1,values:r}}],sort:[],facets:[]};return this.api.search(o)}fetchRelativesForTopicInMap(e,r,o){let a={query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",metadataFilters:[{key:r,valueFilter:{negative:!1,values:o}},{key:"ft:publicationId",valueFilter:{negative:!1,values:[e]}}],sort:[],facets:[]};return this.api.search(a)}makeMapFeedbackRequest(e,r){return this.api.sendMapFeedback(this.mapId,e,r)}makeRateMapRequest(e,r){return this.api.rateMap(this.mapId,e,r)}makeRateTopicRequest(e,r,o){return this.api.rateTopic(this.mapId,e,r,o)}makeTopicFeedbackRequest(e,r,o){return this.api.sendTopicFeedback(this.mapId,e,r,o)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(e){return this.api.unrateTopic(this.mapId,e)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(e){return!0}};var L3="topicPivot";function Bu(t,e){let r=new URL(t);return e?.values.forEach(o=>{r.searchParams.append(L3,o)}),r.href}var li=class t{static build(e,r){return new t(Uu(e.trim()||"context"),r??ci.build)}loaded(){return(0,it.waitUntil)(()=>this._loaded)}constructor(e,r,o,a){this.store=e,this.clusteringHelperProvider=o,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new it.Debouncer(10),this.analyticsEventsService=a??new La,this.initService(r)}async initService(e){return this.service=await e(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(e){e!==this.store.getState().mapId&&(this.store.actions.mapId(e),this.service&&(this.service.mapId=e),await this.reload())}setRenderedTopics(e){this.store.actions.renderedTopics(e)}setVisibleTopics(e){this.store.actions.visibleTopics(e)}async awaitService(){return(0,it.waitFor)(()=>this.service)}async navigateToTopic(e,r,o){await this.loaded();let a=await this.awaitService(),i=await(o!=null?a.getPage(o,this.getTranslationSettings()):a.getPageByTocId(e??"root",this.getTranslationSettings()));this.store.actions.currentPage(i);let s=this.resolveValidNonRootTocId(e,i);this.store.actions.scrollTarget({tocId:s,section:r}),this.store.getState().visibleTopics[0]!==s&&this.store.actions.visibleTopics([])}resolveValidNonRootTocId(e,r){var o,a,i;let s=(o=e==="root"?void 0:e)!==null&&o!==void 0?o:r.rootTocId;return r.topics.includes(s)?s:(i=(a=r.topics[0])!==null&&a!==void 0?a:r.hiddenTopics[0])!==null&&i!==void 0?i:"root"}async navigateToPage(e){await this.loaded();let o=await(await this.awaitService()).getPage(e,this.getTranslationSettings());this.store.actions.currentPage(o)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var e;!((e=this.service)===null||e===void 0)&&e.mapId&&this.store.getState().map==null&&await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}clear(){var e;this._loaded=!1,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),this.store.actions.renderedTopics([]),this.store.actions.visibleTopics([]),this.store.actions.translation({sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1}),this.store.actions.mapRating(void 0),(e=this.service)===null||e===void 0||e.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(e){var r,o,a,i,s;try{e&&this.setTranslationLoading(!0);let c=u=>{throw e&&this.setTranslationError(!0),u};await Promise.all([this.loadConfiguration(),(r=this.service)===null||r===void 0?void 0:r.getMap(e).then(u=>this.store.actions.map(u)).catch(c),(o=this.service)===null||o===void 0?void 0:o.getToc(e).then(u=>this.store.actions.toc(u)).catch(c),(a=this.service)===null||a===void 0?void 0:a.getPagesToc(e).then(u=>this.store.actions.pagesToc(u)).catch(c),(i=this.service)===null||i===void 0?void 0:i.getPaginationConfiguration().then(u=>this.store.actions.paginationConfiguration(u)).catch(c),(s=this.service)===null||s===void 0?void 0:s.getTranslationError(e).then(u=>this.setTranslationError(u))]),this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives(),this._loaded=!0,e&&this.setTranslationLoading(!1)}catch(c){this.errorHandler&&!(c instanceof it.CanceledPromiseError)&&this.errorHandler(c)}}loadConfiguration(){var e;return(e=this.service)===null||e===void 0?void 0:e.getConfiguration().then(r=>this.store.actions.configuration(r))}reloadConfiguration(){var e;return(e=this.service)===null||e===void 0||e.clearConfiguration(),this.loadConfiguration()}async fetchRelatives(){var e,r;let o=(e=this.store.getState().map)===null||e===void 0?void 0:e.metadata.filter(a=>{var i;return a.key==((i=this.store.getState().configuration)===null||i===void 0?void 0:i.relativePivotMetadata)}).flatMap(a=>a.values);if(o!==void 0&&o.length>0){let a=await((r=this.service)===null||r===void 0?void 0:r.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata,o)),i=a?.results.flatMap(s=>s.entries);this.store.actions.relatives(i)}this.updateClusteringHelper()}updateClusteringHelper(){this.clusteringHelper=this.createClusteringHelper(),this.clusteringHelper&&this.store.dispatchEvent(new Event(Qo.clusteringHelperCreated))}createClusteringHelper(){var e,r;if(this.clusteringHelperProvider)return this.clusteringHelperProvider();let o=this.store.getState().relatives;if(o){let a=o.find(s=>{var c;return((c=s.map)===null||c===void 0?void 0:c.mapId)==this.store.getState().mapId}),i=(r=(e=k.getState().metadataConfiguration)===null||e===void 0?void 0:e.descriptors)!==null&&r!==void 0?r:[];return new it.ClusteringHelper(o,a,this.metadataForSwitchToRelatives,i)}}async navigateToRelativeTopicIfFound(e){var r,o,a;await this.loaded();let i=await(0,it.waitFor)(()=>{var f;return(f=this.store.getState().configuration)===null||f===void 0?void 0:f.relativeTopicPivotMetadata}),s=this.store.getState().mapId,u=await(await this.awaitService()).getRelativesForTopicInMap(s,i,[e]);if(!((a=(o=(r=u?.results)===null||r===void 0?void 0:r[0])===null||o===void 0?void 0:o.entries)===null||a===void 0)&&a[0]){let f=u.results[0].entries[0].topic.tocId;return await this.navigateToTopic(f),!0}else return await this.navigateToTopic("root"),!1}setSearchInDocumentQuery(e){this.store.actions.searchInDocumentQuery(e)}async setTranslationDestinationLanguage(e){this.store.actions.setTranslationDestinationLanguage(e),e&&this.sendDocumentOnDemandTranslateEvent(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationSourceLanguage(e){this.store.actions.setTranslationSourceLanguage(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationProfileId(e){this.store.actions.setTranslationProfileId(e)}async setTranslationLoading(e){this.store.actions.setTranslationLoading(e)}async setTranslationError(e){this.store.actions.setTranslationError(e)}getTranslationSettings(){var e;let r=this.store.getState();return r.translation.profileId&&r.translation.destinationLanguage?{profileId:r.translation.profileId,destinationLanguage:r.translation.destinationLanguage.code,sourceLanguage:(e=r.map)===null||e===void 0?void 0:e.lang}:void 0}setLinkPreviewDialogId(e){this.store.actions.linkPreviewDialogId(e)}async fetchMapRating(){var e;this.store.actions.mapRating(await((e=this.service)===null||e===void 0?void 0:e.getMapRating()))}async fetchTopicRating(e){var r;let o=await((r=this.service)===null||r===void 0?void 0:r.getTopicRating(e));o&&this.store.actions.setTopicsRating({[e]:o})}registerMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.add(e),this.store.getState().relatives==null?this.fetchRelatives():this.updateClusteringHelper()}unregisterMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.delete(e),this.updateClusteringHelper()}getAccurateNavigationData(e,r,o){return this.service.getAccurateNavigationData(e,r?.number,o?.section,this.getTranslationSettings())}buildBreadcrumb(e){var r;return(r=this.service)===null||r===void 0?void 0:r.buildBreadcrumb(e,this.getTranslationSettings())}fetchTopicContent(e){var r,o;let a=this.getTranslationSettings();return a?(this.sendTopicAiTranslateEvent(a.destinationLanguage,e),(r=this.service)===null||r===void 0?void 0:r.getTranslatedTopicContent(e,a).then(i=>(i.isTranslationError&&this.setTranslationError(!0),i.content))):(o=this.service)===null||o===void 0?void 0:o.getTopicContent(e)}getTocNode(e){return this.service.getTocNode(e,this.getTranslationSettings())}getPage(e){return this.service.getPage(e,this.getTranslationSettings())}onMapAttachmentsUpdate(){var e;(e=this.service)===null||e===void 0||e.clearMapAttachments(),this.store.dispatchEvent(new Event(Qo.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(e){var r,o,a;this.store.getState().relatives==null&&await this.fetchRelatives();let i=it.ClusteringHelper.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",e),s=(0,it.accessResultUrl)(i);if(s){let c=this.store.getState().visibleTopics[0],u=(o=this.store.getState().configuration)===null||o===void 0?void 0:o.relativeTopicPivotMetadata;if(u&&c){let f=await((a=this.service)===null||a===void 0?void 0:a.getTopicMetadataValue(c,u));s=Bu(s,f)}}return s}sendDocumentOnDemandTranslateEvent(e){let{editorMode:r,apiIntegrationIdentifier:o,apiIntegrationAppVersion:a}=k.getState(),i=this.store.getState(),s=i.map,c=i.translation.profileId;if(!(r||!s||!o||!a||!c))try{let u=this.analyticsEventsService.convertMapToAnalyticsDocument(s);this.analyticsEventsService.sendDocumentOnDemandTranslateEvent({name:"DOCUMENT__ON_DEMAND_TRANSLATE",offline:!1,appName:o,appVersion:a,sourceLanguage:this.parseLanguageToAnalyticsFormat(s.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e.code),profileId:c,document:u,translationOrigin:Fn.AI})}catch(u){console.warn("Failed to send on-demand document translate event:",u)}}sendTopicAiTranslateEvent(e,r){let{editorMode:o,apiIntegrationIdentifier:a,apiIntegrationAppVersion:i}=k.getState(),s=this.store.getState(),c=s.map,u=s.translation.profileId;if(!(o||!c||!a||!i||!u))try{let f=this.buildBreadcrumb(r.tocId);if(!f){console.warn("Failed to build breadcrumb for topic ai translate event");return}let h=this.analyticsEventsService.convertMapToAnalyticsDocument(c);this.analyticsEventsService.sendTopicAiTranslateEvent({name:"TOPIC__AI_TRANSLATE",offline:!1,appName:a,appVersion:i,sourceLanguage:this.parseLanguageToAnalyticsFormat(c.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e),breadcrumb:f.map(g=>({tocId:g.tocId,title:g.title,mapId:c.id,mapTitle:c.title})),document:h,profileId:u})}catch(f){console.warn("Failed to send topic ai translate event:",f)}}parseLanguageToAnalyticsFormat(e){if(!e)return;let r=e.split("-");return r.length===2?{languageCode:r[0],countryCode:r[1]}:{languageCode:r[0],countryCode:""}}};var di=class extends CustomEvent{constructor(e,r){super("ft-reader-map-loaded",{detail:{map:e,toc:r}})}},ui=class extends CustomEvent{constructor(e,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},fi=class extends CustomEvent{constructor(e){super("ft-reader-navigation-done",{detail:e})}},pi=class extends CustomEvent{constructor(e){super("ft-reader-load-error",{detail:e})}},hi=class extends Event{constructor(){super("ft-reader-map-not-found")}},mi=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},gi=class extends Event{constructor(){super("ft-reader-map-forbidden")}},yi=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var st=function(t,e,r,o){var a=arguments.length,i=a<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,r):o,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,r,o);else for(var c=t.length-1;c>=0;c--)(s=t[c])&&(i=(a<3?s(i):a>3?s(e,r,i):s(e,r))||i);return a>3&&i&&Object.defineProperty(e,r,i),i},Ic=class{constructor(e){this.stateManager=e}searchInDocument(e){this.stateManager.setSearchInDocumentQuery(e??"")}},Ie=class extends Ue.FtLitElementRedux{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new Ue.Debouncer(5),this.navigationDebouncer=new Ue.Debouncer(10),this.mapLoadedEventDebouncer=new Ue.Debouncer(50),this.addStore(k)}render(){return Dn.html`
|
|
2540
|
+
`;var Dn=v(F()),lo=v(X()),Ue=v(_());var it=v(_());var Du=v(_()),E3={setTranslationDestinationLanguage:(t,e)=>{t.translation.destinationLanguage=e.payload},setTranslationSourceLanguage:(t,e)=>{t.translation.sourceLanguage=e.payload},setTranslationProfileId:(t,e)=>{t.translation.profileId=e.payload},setTranslationLoading:(t,e)=>{t.translation.isLoading=e.payload},setTranslationError:(t,e)=>{t.translation.isError=e.payload},setTopicsRating:(t,e)=>{for(let r in e.payload)t.topicsRating[r]=e.payload[r]}},Uu=t=>Du.FtReduxStore.get({name:"ft-reader-"+t,initialState:{mapId:void 0,renderedTopics:[],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,mapRating:void 0,topicsRating:{},translation:{sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1},linkPreviewDialogId:void 0},reducers:E3});var Mc=class{constructor(e,r){this.mapId=e,this.paginatedToc=r,this.nodeByTocId={},this.nodeByUrl={},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,nodeByUrl:this.nodeByUrl,duplicatedPrettyUrls:this.duplicatedPrettyUrls,pages:this.pages,pageByTocId:this.pageByTocId,translationError:this.paginatedToc.translationError}}extractPagesToc(e,r,o){return e.flatMap(a=>{var i;return a.pageConfiguration&&this.registerPage(this.buildPage(a,o)),a.tocId==null?this.extractPagesToc(a.children,r,o):[{tocId:a.tocId,title:(i=a.title)!==null&&i!==void 0?i:"",untranslatedTitle:a.untranslatedTitle,depth:r,children:this.extractPagesToc(a.children,r+1,a.tocId)}]})}convertNodes(e,r,o){return e.flatMap(a=>{var i,s,c;if(a.tocId==null)return[...this.convertSectionNodes((i=a.pageToc)!==null&&i!==void 0?i:[],r,a.tocId),...this.convertNodes(a.children,r,a.tocId)];let u=(s=a.prettyUrl)===null||s===void 0?void 0:s.replace(/^\//,""),f={tocId:a.tocId,contentId:a.contentId,title:a.title,untranslatedTitle:a.untranslatedTitle,hasRating:a.hasRating,origin:a.origin,prettyUrl:u,depth:r,parentTocId:o,children:[]};this.register(f);let h=this.convertSectionNodes((c=a.pageToc)!==null&&c!==void 0?c:[],r+1,a.tocId),g=this.convertNodes(a.children,r+1,f.tocId);return f.children=[...h,...g],[f]})}convertSectionNodes(e,r,o){return e.flatMap(a=>{var i;let s=(i=a.prettyUrl)===null||i===void 0?void 0:i.replace(/^\//,""),c={...a,prettyUrl:s,depth:r,parentTocId:o,children:[]};return this.register(c),c.children=this.convertSectionNodes(a.children,r+1,a.tocId),[c]})}buildPage(e,r){var o,a,i,s,c,u;let f={number:this.pages.length+1,title:(o=e.title)!==null&&o!==void 0?o:"",untranslatedTitle:e.untranslatedTitle,rootTocId:(a=e.tocId)!==null&&a!==void 0?a:"root",toc:((i=e.pageToc)!==null&&i!==void 0?i:[]).map(y=>this.nodeByTocId[y.tocId]),topics:[],hiddenTopics:[],breadcrumb:r?this.buildBreadcrumb(this.nodeByTocId[r]):[]},h=(y,S)=>(S?f.topics:f.hiddenTopics).push(y),g=(c=(s=e.pageConfiguration)===null||s===void 0?void 0:s.parentsVisibility)!==null&&c!==void 0?c:[];return f.breadcrumb.forEach((y,S)=>{h(y,g[S])}),e.tocId&&h(e.tocId,e.pageConfiguration.isVisible),f.topics.push(...this.tocIds((u=e.pageToc)!==null&&u!==void 0?u:[])),f}registerPage(e){for(let r of[...e.topics,...e.hiddenTopics])this.pageByTocId[r]||(this.pageByTocId[r]=e);this.pages.push(e)}tocIds(e){return e.flatMap(r=>[r.tocId,...this.tocIds(r.children)])}buildBreadcrumb(e){let r=[e.tocId];for(;e?.parentTocId;)r.unshift(e.parentTocId),e=this.nodeByTocId[e.parentTocId];return r}register(e){e.prettyUrl&&(this.nodeByUrl[e.prettyUrl]==null?this.nodeByUrl[e.prettyUrl]=e:this.duplicatedPrettyUrls.add(e.prettyUrl)),this.nodeByUrl[`${this.mapId}/${e.tocId}`]=e,this.nodeByTocId[e.tocId]=e}},ii=class{convertPaginatedToc(e,r){return new Mc(e,r).build()}};var si=class extends je{get mapId(){return this._mapId}set mapId(e){e!==this._mapId&&this.clear(),this._mapId=e}constructor(e,r,o){super(!1,r),this.converter=e,this._mapId=o,this.initCache()}async withMapId(e){return this._mapId?e(this._mapId):void 0}initCache(){this.cache.register("configuration",()=>this.api.getReaderConfiguration()),this.cache.register("map",()=>this.withMapId(e=>this.fetchMap(e))),this.cache.register("enrichedToc",()=>this.withMapId(e=>this.fetchPages(e).then(r=>this.converter.convertPaginatedToc(e,r)))),this.cache.register("ratingSummary",()=>{var e,r;return Jt((r=(e=k.getState().session)===null||e===void 0?void 0:e.profile.roles)!==null&&r!==void 0?r:[],"RATING_USER")?this.withMapId(a=>this.fetchMapRating(a)):Promise.resolve()})}clear(){this.cache.clearMatching(e=>e!=="configuration")}makeCacheKey(e,r){return e+(r?"-destinationLanguage-"+r?.destinationLanguage:"")}getMap(e){return this.cache.get(this.makeCacheKey("map",e),()=>this.fetchMap(this.mapId,e))}getMapNow(e){return this.cache.getNow(this.makeCacheKey("map",e))}getConfiguration(){return this.cache.get("configuration")}clearConfiguration(){this.cache.clear("configuration")}getEnrichedToc(e){return this.cache.get(this.makeCacheKey("enrichedToc",e),()=>this.fetchPages(this.mapId,e).then(r=>this.converter.convertPaginatedToc(this.mapId,r)))}getEnrichedTocNow(e){return this.cache.getNow(this.makeCacheKey("enrichedToc",e))}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(e){return(await this.getEnrichedToc(e)).toc}async getPagesToc(e){return(await this.getEnrichedToc(e)).pagesToc}async getTranslationError(e){return(await this.getEnrichedToc(e)).translationError}async getTocNode(e,r){return(await this.getEnrichedToc(r)).nodeByTocId[e]}getTocNodeNow(e,r){var o;return(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.nodeByTocId[e]}getTocNodeNowByUrl(e,r){var o,a;let i=this.getMapNow(r);return i?.prettyUrl==e||`${i?.id}/root`===e?(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.toc[0]:(a=this.getEnrichedTocNow(r))===null||a===void 0?void 0:a.nodeByUrl[e]}async getPage(e,r){let o=await this.getEnrichedToc(r);return o.pages[e-1]||o.pages[0]}async getPageByTocId(e,r){let o=await this.getEnrichedToc(r);return o.pageByTocId[e]||o.pages[0]}getTopicInfo(e){return this.cache.get("topic-"+e.tocId,()=>this.fetchTopicMetadata(e))}getTopicContent(e){return this.cache.get("topic-content-"+e.tocId,()=>this.fetchTopicHTMLContent(e))}getTranslatedTopicContent(e,r){return this.cache.get(this.makeCacheKey("translated-topic-content-"+e.tocId,r),()=>this.fetchTranslatedTopicHTMLContent(e,r))}async getTopicMetadataValue(e,r){let o=this.getTocNodeNow(e);if(!o)return;let a=await this.getTopicInfo(o);return a?.metadata.find(i=>i.key==r)}getAttachments(){return this.cache.get("map-attachments",()=>this.fetchAttachments())}clearMapAttachments(){this.cache.clear("map-attachments")}getRelativesForDocument(e,r){return this.cache.get("document-relatives-"+e+"-"+r.join("-"),()=>this.fetchRelativesForDocument(e,r))}getRelativesForTopicInMap(e,r,o){return this.cache.get("topic-relatives-"+[e,r,...o].join("-"),()=>this.fetchRelativesForTopicInMap(e,r,o))}getAttachmentDownloadLink(e){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(e).content}?download=true&locationValue=reader`)}getLink(e,r,o){let a=this.getNavigationData(e,r,o),i=this.getReaderLinkPrefix()+(a.prettyUrl?a.prettyUrl:`${a.mapId}/${a.tocId}`),s=new URL(i,this.api.tenantBaseUrl);return a.page!=null&&s.searchParams.set("page",`${a.page}`),a.prettyUrlDuplicated&&s.searchParams.set("tocId",a.tocId),a.section!=null&&s.searchParams.set("section",a.section),s.href}getNavigationData(e,r,o,a){var i,s;e=e||"root";let c=this.getEnrichedTocNow(a),u=c?.pageByTocId[e],f=c?.nodeByTocId[e],h=f?.prettyUrl;return{mapId:this.mapId,tocId:e,topicTitle:(i=f?.title)!==null&&i!==void 0?i:"",untranslatedTopicTitle:f?.untranslatedTitle,page:r&&u&&u.number!==r?r:void 0,prettyUrl:h?.replace(/^r\//,""),prettyUrlDuplicated:(s=c?.duplicatedPrettyUrls.has(h??""))!==null&&s!==void 0?s:!1,section:o}}async getAccurateNavigationData(e,r,o,a){return await this.getEnrichedToc(a),this.getNavigationData(e,r,o,a)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then(e=>e?.publication)}getTopicRating(e){return this.getRatingSummary().then(r=>{var o;return r?{type:r.topics.type,rating:(o=r.topics)===null||o===void 0?void 0:o.ratings.find(a=>a.tocId===e)}:void 0})}rateMap(e,r){return this.makeRateMapRequest(e,r).then(()=>this.clearRatingIfNecessary())}unrateMap(){return this.makeUnrateMapRequest().then(()=>this.clearRatingIfNecessary())}sendMapFeedback(e,r){return this.makeMapFeedbackRequest(e,r)}rateTopic(e,r,o){return this.makeRateTopicRequest(e,r,o).then(()=>this.clearRatingIfNecessary())}unrateTopic(e){return this.makeUnrateTopicRequest(e).then(()=>this.clearRatingIfNecessary())}async clearRatingIfNecessary(){let e=k.getState().session;e?.sessionAuthenticated&&this.cache.clear("ratingSummary")}sendTopicFeedback(e,r,o){return this.makeTopicFeedbackRequest(e,r,o)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(e,r){let o=this.getTocNodeNow(e,r),a=[{tocId:o.tocId,title:o.title,untranslatedTitle:o.untranslatedTitle}],i=this.getTocNodeNow(o.parentTocId,r);for(;i;)a.unshift({tocId:i.tocId,title:i.title,untranslatedTitle:i.untranslatedTitle}),i=this.getTocNodeNow(i.parentTocId,r);return a}isFeatureAccessible(e,{session:r}){var o;if(!this.isFeatureAvailable(e))return!1;switch(e){case ht.FEEDBACK:return Jt(r??[],ae.FEEDBACK_USER);case ht.RATING:return Jt(r??[],ae.RATING_USER);case ht.PRINT:return Jt(r??[],ae.PRINT_USER);case ht.BOOKMARK:return!!r?.sessionAuthenticated;case ht.COLLECTIONS:return Jt(r??[],ae.COLLECTION_USER);case ht.PERSONAL_BOOKS:return Jt(r??[],ae.PERSONAL_BOOK_USER)&&!(!((o=this.getMapNow())===null||o===void 0)&&o.pbkConfidential);default:return!1}}makeAbsolute(e){return this.api.makeAbsolute(e)}};var ci=class t extends si{static async build(e){return new t(new ii,void 0,e)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(e,r){let o=await this.api.getMap(e,r);return this.fingerprint=o.fingerprint,o}fetchMapRating(e){return this.api.getMapRating(e)}async fetchPages(e,r){return await this.getMap(r),this.api.getPages(e,this.fingerprint,r)}fetchTopicHTMLContent(e){return this.api.getTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint)}fetchTranslatedTopicHTMLContent(e,r){return this.api.getTranslatedTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint,r)}fetchTopicMetadata(e){return this.api.getTopic(this.mapId,e.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch(()=>[])}fetchRelativesForDocument(e,r){let o={query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",metadataFilters:[{key:e,valueFilter:{negative:!1,values:r}}],sort:[],facets:[]};return this.api.search(o)}fetchRelativesForTopicInMap(e,r,o){let a={query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",metadataFilters:[{key:r,valueFilter:{negative:!1,values:o}},{key:"ft:publicationId",valueFilter:{negative:!1,values:[e]}}],sort:[],facets:[]};return this.api.search(a)}makeMapFeedbackRequest(e,r){return this.api.sendMapFeedback(this.mapId,e,r)}makeRateMapRequest(e,r){return this.api.rateMap(this.mapId,e,r)}makeRateTopicRequest(e,r,o){return this.api.rateTopic(this.mapId,e,r,o)}makeTopicFeedbackRequest(e,r,o){return this.api.sendTopicFeedback(this.mapId,e,r,o)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(e){return this.api.unrateTopic(this.mapId,e)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(e){return!0}};var L3="topicPivot";function Bu(t,e){let r=new URL(t);return e?.values.forEach(o=>{r.searchParams.append(L3,o)}),r.href}var li=class t{static build(e,r){return new t(Uu(e.trim()||"context"),r??ci.build)}loaded(){return(0,it.waitUntil)(()=>this._loaded)}constructor(e,r,o,a){this.store=e,this.clusteringHelperProvider=o,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new it.Debouncer(10),this.analyticsEventsService=a??new La,this.initService(r)}async initService(e){return this.service=await e(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(e){e!==this.store.getState().mapId&&(this.store.actions.mapId(e),this.service&&(this.service.mapId=e),await this.reload())}setRenderedTopics(e){this.store.actions.renderedTopics(e)}setVisibleTopics(e){this.store.actions.visibleTopics(e)}async awaitService(){return(0,it.waitFor)(()=>this.service)}async navigateToTopic(e,r,o){await this.loaded();let a=await this.awaitService(),i=await(o!=null?a.getPage(o,this.getTranslationSettings()):a.getPageByTocId(e??"root",this.getTranslationSettings()));this.store.actions.currentPage(i);let s=this.resolveValidNonRootTocId(e,i);this.store.actions.scrollTarget({tocId:s,section:r}),this.store.getState().visibleTopics[0]!==s&&this.store.actions.visibleTopics([])}resolveValidNonRootTocId(e,r){var o,a,i;let s=(o=e==="root"?void 0:e)!==null&&o!==void 0?o:r.rootTocId;return r.topics.includes(s)?s:(i=(a=r.topics[0])!==null&&a!==void 0?a:r.hiddenTopics[0])!==null&&i!==void 0?i:"root"}async navigateToPage(e){await this.loaded();let o=await(await this.awaitService()).getPage(e,this.getTranslationSettings());this.store.actions.currentPage(o)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var e;!((e=this.service)===null||e===void 0)&&e.mapId&&this.store.getState().map==null&&await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}clear(){var e;this._loaded=!1,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),this.store.actions.renderedTopics([]),this.store.actions.visibleTopics([]),this.store.actions.translation({sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1}),this.store.actions.mapRating(void 0),(e=this.service)===null||e===void 0||e.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(e){var r,o,a,i,s;try{e&&this.setTranslationLoading(!0);let c=u=>{throw e&&this.setTranslationError(!0),u};await Promise.all([this.loadConfiguration(),(r=this.service)===null||r===void 0?void 0:r.getMap(e).then(u=>this.store.actions.map(u)).catch(c),(o=this.service)===null||o===void 0?void 0:o.getToc(e).then(u=>this.store.actions.toc(u)).catch(c),(a=this.service)===null||a===void 0?void 0:a.getPagesToc(e).then(u=>this.store.actions.pagesToc(u)).catch(c),(i=this.service)===null||i===void 0?void 0:i.getPaginationConfiguration().then(u=>this.store.actions.paginationConfiguration(u)).catch(c),(s=this.service)===null||s===void 0?void 0:s.getTranslationError(e).then(u=>this.setTranslationError(u))]),this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives(),this._loaded=!0,e&&this.setTranslationLoading(!1)}catch(c){this.errorHandler&&!(c instanceof it.CanceledPromiseError)&&this.errorHandler(c)}}loadConfiguration(){var e;return(e=this.service)===null||e===void 0?void 0:e.getConfiguration().then(r=>this.store.actions.configuration(r))}reloadConfiguration(){var e;return(e=this.service)===null||e===void 0||e.clearConfiguration(),this.loadConfiguration()}async fetchRelatives(){var e,r;let o=(e=this.store.getState().map)===null||e===void 0?void 0:e.metadata.filter(a=>{var i;return a.key==((i=this.store.getState().configuration)===null||i===void 0?void 0:i.relativePivotMetadata)}).flatMap(a=>a.values);if(o!==void 0&&o.length>0){let a=await((r=this.service)===null||r===void 0?void 0:r.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata,o)),i=a?.results.flatMap(s=>s.entries);this.store.actions.relatives(i)}this.updateClusteringHelper()}updateClusteringHelper(){this.clusteringHelper=this.createClusteringHelper(),this.clusteringHelper&&this.store.dispatchEvent(new Event(Qo.clusteringHelperCreated))}createClusteringHelper(){var e,r;if(this.clusteringHelperProvider)return this.clusteringHelperProvider();let o=this.store.getState().relatives;if(o){let a=o.find(s=>{var c;return((c=s.map)===null||c===void 0?void 0:c.mapId)==this.store.getState().mapId}),i=(r=(e=k.getState().metadataConfiguration)===null||e===void 0?void 0:e.descriptors)!==null&&r!==void 0?r:[];return new it.ClusteringHelper(o,a,this.metadataForSwitchToRelatives,i)}}async navigateToRelativeTopicIfFound(e){var r,o,a;await this.loaded();let i=await(0,it.waitFor)(()=>{var f;return(f=this.store.getState().configuration)===null||f===void 0?void 0:f.relativeTopicPivotMetadata}),s=this.store.getState().mapId,u=await(await this.awaitService()).getRelativesForTopicInMap(s,i,[e]);if(!((a=(o=(r=u?.results)===null||r===void 0?void 0:r[0])===null||o===void 0?void 0:o.entries)===null||a===void 0)&&a[0]){let f=u.results[0].entries[0].topic.tocId;return await this.navigateToTopic(f),!0}else return await this.navigateToTopic("root"),!1}setSearchInDocumentQuery(e){this.store.actions.searchInDocumentQuery(e)}async setTranslationDestinationLanguage(e){this.store.actions.setTranslationDestinationLanguage(e),e&&this.sendDocumentOnDemandTranslateEvent(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationSourceLanguage(e){this.store.actions.setTranslationSourceLanguage(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationProfileId(e){this.store.actions.setTranslationProfileId(e)}async setTranslationLoading(e){this.store.actions.setTranslationLoading(e)}async setTranslationError(e){this.store.actions.setTranslationError(e)}getTranslationSettings(){var e;let r=this.store.getState();return r.translation.profileId&&r.translation.destinationLanguage?{profileId:r.translation.profileId,destinationLanguage:r.translation.destinationLanguage.code,sourceLanguage:(e=r.map)===null||e===void 0?void 0:e.lang}:void 0}setLinkPreviewDialogId(e){this.store.actions.linkPreviewDialogId(e)}async fetchMapRating(){var e;this.store.actions.mapRating(await((e=this.service)===null||e===void 0?void 0:e.getMapRating()))}async fetchTopicRating(e){var r;let o=await((r=this.service)===null||r===void 0?void 0:r.getTopicRating(e));o&&this.store.actions.setTopicsRating({[e]:o})}registerMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.add(e),this.store.getState().relatives==null?this.fetchRelatives():this.updateClusteringHelper()}unregisterMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.delete(e),this.updateClusteringHelper()}getAccurateNavigationData(e,r,o){return this.service.getAccurateNavigationData(e,r?.number,o?.section,this.getTranslationSettings())}buildBreadcrumb(e){var r;return(r=this.service)===null||r===void 0?void 0:r.buildBreadcrumb(e,this.getTranslationSettings())}fetchTopicContent(e){var r,o;let a=this.getTranslationSettings();return a?(this.sendTopicAiTranslateEvent(a.destinationLanguage,e),(r=this.service)===null||r===void 0?void 0:r.getTranslatedTopicContent(e,a).then(i=>(i.isTranslationError&&this.setTranslationError(!0),i.content))):(o=this.service)===null||o===void 0?void 0:o.getTopicContent(e)}getTocNode(e){return this.service.getTocNode(e,this.getTranslationSettings())}getPage(e){return this.service.getPage(e,this.getTranslationSettings())}onMapAttachmentsUpdate(){var e;(e=this.service)===null||e===void 0||e.clearMapAttachments(),this.store.dispatchEvent(new Event(Qo.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(e){var r,o,a;this.store.getState().relatives==null&&await this.fetchRelatives();let i=it.ClusteringHelper.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",e),s=(0,it.accessResultUrl)(i);if(s){let c=this.store.getState().visibleTopics[0],u=(o=this.store.getState().configuration)===null||o===void 0?void 0:o.relativeTopicPivotMetadata;if(u&&c){let f=await((a=this.service)===null||a===void 0?void 0:a.getTopicMetadataValue(c,u));s=Bu(s,f)}}return s}sendDocumentOnDemandTranslateEvent(e){let{editorMode:r,apiIntegrationIdentifier:o,apiIntegrationAppVersion:a}=k.getState(),i=this.store.getState(),s=i.map,c=i.translation.profileId;if(!(r||!s||!o||!a||!c))try{let u=this.analyticsEventsService.convertMapToAnalyticsDocument(s);this.analyticsEventsService.sendDocumentOnDemandTranslateEvent({name:"DOCUMENT__ON_DEMAND_TRANSLATE",offline:!1,appName:o,appVersion:a,sourceLanguage:this.parseLanguageToAnalyticsFormat(s.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e.code),profileId:c,document:u,translationOrigin:Fn.AI})}catch(u){console.warn("Failed to send on-demand document translate event:",u)}}sendTopicAiTranslateEvent(e,r){let{editorMode:o,apiIntegrationIdentifier:a,apiIntegrationAppVersion:i}=k.getState(),s=this.store.getState(),c=s.map,u=s.translation.profileId;if(!(o||!c||!a||!i||!u))try{let f=this.buildBreadcrumb(r.tocId);if(!f){console.warn("Failed to build breadcrumb for topic ai translate event");return}let h=this.analyticsEventsService.convertMapToAnalyticsDocument(c);this.analyticsEventsService.sendTopicAiTranslateEvent({name:"TOPIC__AI_TRANSLATE",offline:!1,appName:a,appVersion:i,sourceLanguage:this.parseLanguageToAnalyticsFormat(c.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e),breadcrumb:f.map(g=>({tocId:g.tocId,title:g.title})),document:h,profileId:u})}catch(f){console.warn("Failed to send topic ai translate event:",f)}}parseLanguageToAnalyticsFormat(e){if(!e)return;let r=e.split("-");return r.length===2?{languageCode:r[0],countryCode:r[1]}:{languageCode:r[0],countryCode:""}}};var di=class extends CustomEvent{constructor(e,r){super("ft-reader-map-loaded",{detail:{map:e,toc:r}})}},ui=class extends CustomEvent{constructor(e,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},fi=class extends CustomEvent{constructor(e){super("ft-reader-navigation-done",{detail:e})}},pi=class extends CustomEvent{constructor(e){super("ft-reader-load-error",{detail:e})}},hi=class extends Event{constructor(){super("ft-reader-map-not-found")}},mi=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},gi=class extends Event{constructor(){super("ft-reader-map-forbidden")}},yi=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var st=function(t,e,r,o){var a=arguments.length,i=a<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,r):o,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(t,e,r,o);else for(var c=t.length-1;c>=0;c--)(s=t[c])&&(i=(a<3?s(i):a>3?s(e,r,i):s(e,r))||i);return a>3&&i&&Object.defineProperty(e,r,i),i},Ic=class{constructor(e){this.stateManager=e}searchInDocument(e){this.stateManager.setSearchInDocumentQuery(e??"")}},Ie=class extends Ue.FtLitElementRedux{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new Ue.Debouncer(5),this.navigationDebouncer=new Ue.Debouncer(10),this.mapLoadedEventDebouncer=new Ue.Debouncer(50),this.addStore(k)}render(){return Dn.html`
|
|
2541
2541
|
${this.importStyleIfNeeded()}
|
|
2542
2542
|
<slot @register-ft-reader-component=${this.registerComponent}></slot>
|
|
2543
2543
|
`}importStyleIfNeeded(){var e,r;let o=(e=this.stateManager.service)===null||e===void 0?void 0:e.themeStylesheet();return!o||window.location.href.startsWith((r=this.baseUrl)!==null&&r!==void 0?r:"")?Dn.nothing:Dn.html`
|
|
@@ -2617,7 +2617,7 @@ svg:not(:root).svg-inline--fa, svg:not(:host).svg-inline--fa {
|
|
|
2617
2617
|
.value=${this.icon}
|
|
2618
2618
|
@click=${()=>{var e;return(e=this.input)===null||e===void 0?void 0:e.focus()}}></ft-icon>
|
|
2619
2619
|
`:G}update(e){super.update(e),(e.has("value")||e.has("filterSuggestions")||e.has("suggestionsProvider"))&&this.updateSuggestions(),e.has("value")&&e.get("value")!=null&&(this.hideSuggestions=!1),e.has("dispatchedValue")&&e.get("dispatchedValue")!=null&&(this.hideSuggestions=!0)}async updateSuggestions(){this.suggestionsProvider?this.providedSuggestions=await this.suggestionsProvider(this.value):this.filterSuggestionsIfNeeded()}filterSuggestionsIfNeeded(){this.filterSuggestions?(this.slottedSuggestions.forEach(e=>e.hidden=!e.getValue().toLowerCase().includes(this.value.toLowerCase())),this.visibleSuggestions=this.slottedSuggestions.filter(e=>!e.hidden)):this.visibleSuggestions=this.slottedSuggestions,this.newValueSuggestion&&(this.visibleSuggestions=[...this.visibleSuggestions,this.newValueSuggestion]),this.hideSuggestions=this.visibleSuggestions.length<=0}contentAvailableCallback(e){super.contentAvailableCallback(e),e.has("focused")&&!this.hideSuggestions&&this.visibleSuggestions.length>0&&this.setSuggestionPosition(),e.has("value")&&this.suggestionsProvider&&(this.visibleSuggestions=[...this.providedSuggestionsInDom]),e.has("autocomplete")&&this.setupWatchAutofill(),this.suggestionsShouldBeDisplayed()&&this.setSuggestionPosition()}setupWatchAutofill(){var e;this.clearWatchAutofill(),((e=this.autocomplete)!==null&&e!==void 0?e:"off")!=="off"&&(this.watchAutofillInterval=setInterval(()=>{var r,o,i;!((r=this.input)===null||r===void 0)&&r.matches(":autofill")&&this.dispatchedValue!==((o=this.input)===null||o===void 0?void 0:o.value)&&this.setValue((i=this.input)===null||i===void 0?void 0:i.value,!0)},200))}clearWatchAutofill(){this.watchAutofillInterval&&clearInterval(this.watchAutofillInterval)}connectedCallback(){super.connectedCallback(),this.setupWatchAutofill()}disconnectedCallback(){super.disconnectedCallback(),this.clearWatchAutofill()}setValue(e,r=!1){var o,i;this.value!==e&&(this.inputValid=!0,this.setInternalValue(e),this.dispatchEvent(new ia(e))),r&&this.dispatchedValue!==e&&(this.inputValid=(i=(o=this.input)===null||o===void 0?void 0:o.checkValidity())!==null&&i!==void 0?i:!0,this.inputValid?(this.dispatchedValue=e,this.dispatchEvent(new aa(e))):this.dispatchEvent(new sa(this.input.validationMessage)))}handleInput(e){var r;let o=((r=this.input)===null||r===void 0?void 0:r.value)||"";this.setValue(o,e.key=="Escape"||e.key=="Enter")}handleClick(){this.hideSuggestions=!1}handleKeyboardNavigation(e){var r;if(e.key==="ArrowDown"||e.key==="ArrowUp"){e.preventDefault(),e.stopPropagation(),this.hideSuggestions=!1;let o=this.visibleSuggestions.findIndex(a=>a.matches(":focus-within")),i;e.key==="ArrowDown"?i=o<this.visibleSuggestions.length-1?o+1:0:i=o>0?o-1:this.visibleSuggestions.length-1,(r=this.visibleSuggestions[i])===null||r===void 0||r.focus()}(e.key=="Escape"||e.key=="Enter")&&(this.hideSuggestions=!0)}onSuggestionSelected(e){var r;this.setValue(e.detail,!0),(r=this.input)===null||r===void 0||r.focus(),setTimeout(()=>this.hideSuggestions=!0,0)}onFocus(){this.focused=!0,this.hideSuggestions=!1}onMainPanelBlur(){var e,r;!((e=this.mainPanel)===null||e===void 0)&&e.matches(":focus-within")||(this.focused=!1,this.setValue(((r=this.input)===null||r===void 0?void 0:r.value)||"",!0))}togglePasswordVisibility(){this.hidePassword=!this.hidePassword}isPasswordField(){return this.password||this.type==="password"}setSuggestionPosition(){this.suggestionsContainer.style.width=this.mainPanel.getBoundingClientRect().width+"px";let e=["bottom","top"];js(this.mainPanel,this.suggestionsContainer,"bottom",e,"fixed","--text-field-internal-suggest-size",0).then(({x:r,y:o})=>{this.suggestionsContainer.style.left=`${r}px`,this.suggestionsContainer.style.top=`${o}px`})}suggestionsShouldBeDisplayed(){return!this.hideSuggestions&&(this.visibleSuggestions.length||this.providedSuggestions.length)}};q.elementDefinitions={"ft-input-label":st,"ft-ripple":se,"ft-typography":Le,"ft-icon":Ae,"ft-text-field-suggestion":vt};q.styles=[Fo,nc,Hf];ne([b()],q.prototype,"label",void 0);ne([b({noAccessor:!0})],q.prototype,"value",null);ne([V()],q.prototype,"dispatchedValue",void 0);ne([b()],q.prototype,"helper",void 0);ne([b()],q.prototype,"suggestionsHelper",void 0);ne([b({type:Boolean})],q.prototype,"outlined",void 0);ne([b({type:Boolean})],q.prototype,"disabled",void 0);ne([b({type:Boolean})],q.prototype,"error",void 0);ne([b({type:Boolean})],q.prototype,"fixedMenuPosition",void 0);ne([b()],q.prototype,"prefix",void 0);ne([b()],q.prototype,"icon",void 0);ne([b()],q.prototype,"name",void 0);ne([b()],q.prototype,"type",void 0);ne([b()],q.prototype,"passwordHiddenIcon",void 0);ne([b()],q.prototype,"passwordRevealedIcon",void 0);ne([b()],q.prototype,"iconVariant",void 0);ne([b({type:Boolean})],q.prototype,"filterSuggestions",void 0);ne([St()],q.prototype,"maxLength",void 0);ne([b({type:Boolean})],q.prototype,"password",void 0);ne([b({type:String})],q.prototype,"autocomplete",void 0);ne([b({attribute:!1})],q.prototype,"suggestionsProvider",void 0);ne([V()],q.prototype,"focused",void 0);ne([V()],q.prototype,"inputValid",void 0);ne([V()],q.prototype,"hidePassword",void 0);ne([V()],q.prototype,"hideSuggestions",void 0);ne([V()],q.prototype,"visibleSuggestions",void 0);ne([V()],q.prototype,"providedSuggestions",void 0);ne([ee(".ft-text-field--main-panel")],q.prototype,"mainPanel",void 0);ne([ee(".ft-text-field--input")],q.prototype,"input",void 0);ne([ee(".ft-text-field-suggestion--new-value")],q.prototype,"newValueSuggestion",void 0);ne([ee(".ft-text-field--suggestions")],q.prototype,"suggestionsContainer",void 0);ne([Ga("ft-text-field-suggestion")],q.prototype,"providedSuggestionsInDom",void 0);ne([Wa({selector:"ft-text-field-suggestion"})],q.prototype,"slottedSuggestions",void 0);ne([rs()],q.prototype,"handleInput",null);X("ft-text-field")(q);X("ft-text-field-suggestion")(vt);var Wf=D`
|
|
2620
|
-
`;var K3={setTranslationDestinationLanguage:(t,e)=>{t.translation.destinationLanguage=e.payload},setTranslationSourceLanguage:(t,e)=>{t.translation.sourceLanguage=e.payload},setTranslationProfileId:(t,e)=>{t.translation.profileId=e.payload},setTranslationLoading:(t,e)=>{t.translation.isLoading=e.payload},setTranslationError:(t,e)=>{t.translation.isError=e.payload},setTopicsRating:(t,e)=>{for(let r in e.payload)t.topicsRating[r]=e.payload[r]}},Vf=t=>Qt.get({name:"ft-reader-"+t,initialState:{mapId:void 0,renderedTopics:[],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,mapRating:void 0,topicsRating:{},translation:{sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1},linkPreviewDialogId:void 0},reducers:K3});var Xl=class{constructor(e,r){this.mapId=e,this.paginatedToc=r,this.nodeByTocId={},this.nodeByUrl={},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,nodeByUrl:this.nodeByUrl,duplicatedPrettyUrls:this.duplicatedPrettyUrls,pages:this.pages,pageByTocId:this.pageByTocId,translationError:this.paginatedToc.translationError}}extractPagesToc(e,r,o){return e.flatMap(i=>{var a;return i.pageConfiguration&&this.registerPage(this.buildPage(i,o)),i.tocId==null?this.extractPagesToc(i.children,r,o):[{tocId:i.tocId,title:(a=i.title)!==null&&a!==void 0?a:"",untranslatedTitle:i.untranslatedTitle,depth:r,children:this.extractPagesToc(i.children,r+1,i.tocId)}]})}convertNodes(e,r,o){return e.flatMap(i=>{var a,s,c;if(i.tocId==null)return[...this.convertSectionNodes((a=i.pageToc)!==null&&a!==void 0?a:[],r,i.tocId),...this.convertNodes(i.children,r,i.tocId)];let d=(s=i.prettyUrl)===null||s===void 0?void 0:s.replace(/^\//,""),u={tocId:i.tocId,contentId:i.contentId,title:i.title,untranslatedTitle:i.untranslatedTitle,hasRating:i.hasRating,origin:i.origin,prettyUrl:d,depth:r,parentTocId:o,children:[]};this.register(u);let p=this.convertSectionNodes((c=i.pageToc)!==null&&c!==void 0?c:[],r+1,i.tocId),h=this.convertNodes(i.children,r+1,u.tocId);return u.children=[...p,...h],[u]})}convertSectionNodes(e,r,o){return e.flatMap(i=>{var a;let s=(a=i.prettyUrl)===null||a===void 0?void 0:a.replace(/^\//,""),c={...i,prettyUrl:s,depth:r,parentTocId:o,children:[]};return this.register(c),c.children=this.convertSectionNodes(i.children,r+1,i.tocId),[c]})}buildPage(e,r){var o,i,a,s,c,d;let u={number:this.pages.length+1,title:(o=e.title)!==null&&o!==void 0?o:"",untranslatedTitle:e.untranslatedTitle,rootTocId:(i=e.tocId)!==null&&i!==void 0?i:"root",toc:((a=e.pageToc)!==null&&a!==void 0?a:[]).map(g=>this.nodeByTocId[g.tocId]),topics:[],hiddenTopics:[],breadcrumb:r?this.buildBreadcrumb(this.nodeByTocId[r]):[]},p=(g,S)=>(S?u.topics:u.hiddenTopics).push(g),h=(c=(s=e.pageConfiguration)===null||s===void 0?void 0:s.parentsVisibility)!==null&&c!==void 0?c:[];return u.breadcrumb.forEach((g,S)=>{p(g,h[S])}),e.tocId&&p(e.tocId,e.pageConfiguration.isVisible),u.topics.push(...this.tocIds((d=e.pageToc)!==null&&d!==void 0?d:[])),u}registerPage(e){for(let r of[...e.topics,...e.hiddenTopics])this.pageByTocId[r]||(this.pageByTocId[r]=e);this.pages.push(e)}tocIds(e){return e.flatMap(r=>[r.tocId,...this.tocIds(r.children)])}buildBreadcrumb(e){let r=[e.tocId];for(;e?.parentTocId;)r.unshift(e.parentTocId),e=this.nodeByTocId[e.parentTocId];return r}register(e){e.prettyUrl&&(this.nodeByUrl[e.prettyUrl]==null?this.nodeByUrl[e.prettyUrl]=e:this.duplicatedPrettyUrls.add(e.prettyUrl)),this.nodeByUrl[`${this.mapId}/${e.tocId}`]=e,this.nodeByTocId[e.tocId]=e}},la=class{convertPaginatedToc(e,r){return new Xl(e,r).build()}};var da=class extends Ve{get mapId(){return this._mapId}set mapId(e){e!==this._mapId&&this.clear(),this._mapId=e}constructor(e,r,o){super(!1,r),this.converter=e,this._mapId=o,this.initCache()}async withMapId(e){return this._mapId?e(this._mapId):void 0}initCache(){this.cache.register("configuration",()=>this.api.getReaderConfiguration()),this.cache.register("map",()=>this.withMapId(e=>this.fetchMap(e))),this.cache.register("enrichedToc",()=>this.withMapId(e=>this.fetchPages(e).then(r=>this.converter.convertPaginatedToc(e,r)))),this.cache.register("ratingSummary",()=>{var e,r;return Jt((r=(e=$.getState().session)===null||e===void 0?void 0:e.profile.roles)!==null&&r!==void 0?r:[],"RATING_USER")?this.withMapId(i=>this.fetchMapRating(i)):Promise.resolve()})}clear(){this.cache.clearMatching(e=>e!=="configuration")}makeCacheKey(e,r){return e+(r?"-destinationLanguage-"+r?.destinationLanguage:"")}getMap(e){return this.cache.get(this.makeCacheKey("map",e),()=>this.fetchMap(this.mapId,e))}getMapNow(e){return this.cache.getNow(this.makeCacheKey("map",e))}getConfiguration(){return this.cache.get("configuration")}clearConfiguration(){this.cache.clear("configuration")}getEnrichedToc(e){return this.cache.get(this.makeCacheKey("enrichedToc",e),()=>this.fetchPages(this.mapId,e).then(r=>this.converter.convertPaginatedToc(this.mapId,r)))}getEnrichedTocNow(e){return this.cache.getNow(this.makeCacheKey("enrichedToc",e))}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(e){return(await this.getEnrichedToc(e)).toc}async getPagesToc(e){return(await this.getEnrichedToc(e)).pagesToc}async getTranslationError(e){return(await this.getEnrichedToc(e)).translationError}async getTocNode(e,r){return(await this.getEnrichedToc(r)).nodeByTocId[e]}getTocNodeNow(e,r){var o;return(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.nodeByTocId[e]}getTocNodeNowByUrl(e,r){var o,i;let a=this.getMapNow(r);return a?.prettyUrl==e||`${a?.id}/root`===e?(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.toc[0]:(i=this.getEnrichedTocNow(r))===null||i===void 0?void 0:i.nodeByUrl[e]}async getPage(e,r){let o=await this.getEnrichedToc(r);return o.pages[e-1]||o.pages[0]}async getPageByTocId(e,r){let o=await this.getEnrichedToc(r);return o.pageByTocId[e]||o.pages[0]}getTopicInfo(e){return this.cache.get("topic-"+e.tocId,()=>this.fetchTopicMetadata(e))}getTopicContent(e){return this.cache.get("topic-content-"+e.tocId,()=>this.fetchTopicHTMLContent(e))}getTranslatedTopicContent(e,r){return this.cache.get(this.makeCacheKey("translated-topic-content-"+e.tocId,r),()=>this.fetchTranslatedTopicHTMLContent(e,r))}async getTopicMetadataValue(e,r){let o=this.getTocNodeNow(e);if(!o)return;let i=await this.getTopicInfo(o);return i?.metadata.find(a=>a.key==r)}getAttachments(){return this.cache.get("map-attachments",()=>this.fetchAttachments())}clearMapAttachments(){this.cache.clear("map-attachments")}getRelativesForDocument(e,r){return this.cache.get("document-relatives-"+e+"-"+r.join("-"),()=>this.fetchRelativesForDocument(e,r))}getRelativesForTopicInMap(e,r,o){return this.cache.get("topic-relatives-"+[e,r,...o].join("-"),()=>this.fetchRelativesForTopicInMap(e,r,o))}getAttachmentDownloadLink(e){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(e).content}?download=true&locationValue=reader`)}getLink(e,r,o){let i=this.getNavigationData(e,r,o),a=this.getReaderLinkPrefix()+(i.prettyUrl?i.prettyUrl:`${i.mapId}/${i.tocId}`),s=new URL(a,this.api.tenantBaseUrl);return i.page!=null&&s.searchParams.set("page",`${i.page}`),i.prettyUrlDuplicated&&s.searchParams.set("tocId",i.tocId),i.section!=null&&s.searchParams.set("section",i.section),s.href}getNavigationData(e,r,o,i){var a,s;e=e||"root";let c=this.getEnrichedTocNow(i),d=c?.pageByTocId[e],u=c?.nodeByTocId[e],p=u?.prettyUrl;return{mapId:this.mapId,tocId:e,topicTitle:(a=u?.title)!==null&&a!==void 0?a:"",untranslatedTopicTitle:u?.untranslatedTitle,page:r&&d&&d.number!==r?r:void 0,prettyUrl:p?.replace(/^r\//,""),prettyUrlDuplicated:(s=c?.duplicatedPrettyUrls.has(p??""))!==null&&s!==void 0?s:!1,section:o}}async getAccurateNavigationData(e,r,o,i){return await this.getEnrichedToc(i),this.getNavigationData(e,r,o,i)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then(e=>e?.publication)}getTopicRating(e){return this.getRatingSummary().then(r=>{var o;return r?{type:r.topics.type,rating:(o=r.topics)===null||o===void 0?void 0:o.ratings.find(i=>i.tocId===e)}:void 0})}rateMap(e,r){return this.makeRateMapRequest(e,r).then(()=>this.clearRatingIfNecessary())}unrateMap(){return this.makeUnrateMapRequest().then(()=>this.clearRatingIfNecessary())}sendMapFeedback(e,r){return this.makeMapFeedbackRequest(e,r)}rateTopic(e,r,o){return this.makeRateTopicRequest(e,r,o).then(()=>this.clearRatingIfNecessary())}unrateTopic(e){return this.makeUnrateTopicRequest(e).then(()=>this.clearRatingIfNecessary())}async clearRatingIfNecessary(){let e=$.getState().session;e?.sessionAuthenticated&&this.cache.clear("ratingSummary")}sendTopicFeedback(e,r,o){return this.makeTopicFeedbackRequest(e,r,o)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(e,r){let o=this.getTocNodeNow(e,r),i=[{tocId:o.tocId,title:o.title,untranslatedTitle:o.untranslatedTitle}],a=this.getTocNodeNow(o.parentTocId,r);for(;a;)i.unshift({tocId:a.tocId,title:a.title,untranslatedTitle:a.untranslatedTitle}),a=this.getTocNodeNow(a.parentTocId,r);return i}isFeatureAccessible(e,{session:r}){var o;if(!this.isFeatureAvailable(e))return!1;switch(e){case mt.FEEDBACK:return Jt(r??[],pe.FEEDBACK_USER);case mt.RATING:return Jt(r??[],pe.RATING_USER);case mt.PRINT:return Jt(r??[],pe.PRINT_USER);case mt.BOOKMARK:return!!r?.sessionAuthenticated;case mt.COLLECTIONS:return Jt(r??[],pe.COLLECTION_USER);case mt.PERSONAL_BOOKS:return Jt(r??[],pe.PERSONAL_BOOK_USER)&&!(!((o=this.getMapNow())===null||o===void 0)&&o.pbkConfidential);default:return!1}}makeAbsolute(e){return this.api.makeAbsolute(e)}};var ua=class t extends da{static async build(e){return new t(new la,void 0,e)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(e,r){let o=await this.api.getMap(e,r);return this.fingerprint=o.fingerprint,o}fetchMapRating(e){return this.api.getMapRating(e)}async fetchPages(e,r){return await this.getMap(r),this.api.getPages(e,this.fingerprint,r)}fetchTopicHTMLContent(e){return this.api.getTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint)}fetchTranslatedTopicHTMLContent(e,r){return this.api.getTranslatedTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint,r)}fetchTopicMetadata(e){return this.api.getTopic(this.mapId,e.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch(()=>[])}fetchRelativesForDocument(e,r){let o={query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",metadataFilters:[{key:e,valueFilter:{negative:!1,values:r}}],sort:[],facets:[]};return this.api.search(o)}fetchRelativesForTopicInMap(e,r,o){let i={query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",metadataFilters:[{key:r,valueFilter:{negative:!1,values:o}},{key:"ft:publicationId",valueFilter:{negative:!1,values:[e]}}],sort:[],facets:[]};return this.api.search(i)}makeMapFeedbackRequest(e,r){return this.api.sendMapFeedback(this.mapId,e,r)}makeRateMapRequest(e,r){return this.api.rateMap(this.mapId,e,r)}makeRateTopicRequest(e,r,o){return this.api.rateTopic(this.mapId,e,r,o)}makeTopicFeedbackRequest(e,r,o){return this.api.sendTopicFeedback(this.mapId,e,r,o)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(e){return this.api.unrateTopic(this.mapId,e)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(e){return!0}};var Z3="topicPivot";function jf(t,e){let r=new URL(t);return e?.values.forEach(o=>{r.searchParams.append(Z3,o)}),r.href}var fa=class t{static build(e,r){return new t(Vf(e.trim()||"context"),r??ua.build)}loaded(){return Qa(()=>this._loaded)}constructor(e,r,o,i){this.store=e,this.clusteringHelperProvider=o,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new ge(10),this.analyticsEventsService=i??new Di,this.initService(r)}async initService(e){return this.service=await e(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(e){e!==this.store.getState().mapId&&(this.store.actions.mapId(e),this.service&&(this.service.mapId=e),await this.reload())}setRenderedTopics(e){this.store.actions.renderedTopics(e)}setVisibleTopics(e){this.store.actions.visibleTopics(e)}async awaitService(){return pn(()=>this.service)}async navigateToTopic(e,r,o){await this.loaded();let i=await this.awaitService(),a=await(o!=null?i.getPage(o,this.getTranslationSettings()):i.getPageByTocId(e??"root",this.getTranslationSettings()));this.store.actions.currentPage(a);let s=this.resolveValidNonRootTocId(e,a);this.store.actions.scrollTarget({tocId:s,section:r}),this.store.getState().visibleTopics[0]!==s&&this.store.actions.visibleTopics([])}resolveValidNonRootTocId(e,r){var o,i,a;let s=(o=e==="root"?void 0:e)!==null&&o!==void 0?o:r.rootTocId;return r.topics.includes(s)?s:(a=(i=r.topics[0])!==null&&i!==void 0?i:r.hiddenTopics[0])!==null&&a!==void 0?a:"root"}async navigateToPage(e){await this.loaded();let o=await(await this.awaitService()).getPage(e,this.getTranslationSettings());this.store.actions.currentPage(o)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var e;!((e=this.service)===null||e===void 0)&&e.mapId&&this.store.getState().map==null&&await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}clear(){var e;this._loaded=!1,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),this.store.actions.renderedTopics([]),this.store.actions.visibleTopics([]),this.store.actions.translation({sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1}),this.store.actions.mapRating(void 0),(e=this.service)===null||e===void 0||e.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(e){var r,o,i,a,s;try{e&&this.setTranslationLoading(!0);let c=d=>{throw e&&this.setTranslationError(!0),d};await Promise.all([this.loadConfiguration(),(r=this.service)===null||r===void 0?void 0:r.getMap(e).then(d=>this.store.actions.map(d)).catch(c),(o=this.service)===null||o===void 0?void 0:o.getToc(e).then(d=>this.store.actions.toc(d)).catch(c),(i=this.service)===null||i===void 0?void 0:i.getPagesToc(e).then(d=>this.store.actions.pagesToc(d)).catch(c),(a=this.service)===null||a===void 0?void 0:a.getPaginationConfiguration().then(d=>this.store.actions.paginationConfiguration(d)).catch(c),(s=this.service)===null||s===void 0?void 0:s.getTranslationError(e).then(d=>this.setTranslationError(d))]),this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives(),this._loaded=!0,e&&this.setTranslationLoading(!1)}catch(c){this.errorHandler&&!(c instanceof jt)&&this.errorHandler(c)}}loadConfiguration(){var e;return(e=this.service)===null||e===void 0?void 0:e.getConfiguration().then(r=>this.store.actions.configuration(r))}reloadConfiguration(){var e;return(e=this.service)===null||e===void 0||e.clearConfiguration(),this.loadConfiguration()}async fetchRelatives(){var e,r;let o=(e=this.store.getState().map)===null||e===void 0?void 0:e.metadata.filter(i=>{var a;return i.key==((a=this.store.getState().configuration)===null||a===void 0?void 0:a.relativePivotMetadata)}).flatMap(i=>i.values);if(o!==void 0&&o.length>0){let i=await((r=this.service)===null||r===void 0?void 0:r.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata,o)),a=i?.results.flatMap(s=>s.entries);this.store.actions.relatives(a)}this.updateClusteringHelper()}updateClusteringHelper(){this.clusteringHelper=this.createClusteringHelper(),this.clusteringHelper&&this.store.dispatchEvent(new Event(Nn.clusteringHelperCreated))}createClusteringHelper(){var e,r;if(this.clusteringHelperProvider)return this.clusteringHelperProvider();let o=this.store.getState().relatives;if(o){let i=o.find(s=>{var c;return((c=s.map)===null||c===void 0?void 0:c.mapId)==this.store.getState().mapId}),a=(r=(e=$.getState().metadataConfiguration)===null||e===void 0?void 0:e.descriptors)!==null&&r!==void 0?r:[];return new mo(o,i,this.metadataForSwitchToRelatives,a)}}async navigateToRelativeTopicIfFound(e){var r,o,i;await this.loaded();let a=await pn(()=>{var u;return(u=this.store.getState().configuration)===null||u===void 0?void 0:u.relativeTopicPivotMetadata}),s=this.store.getState().mapId,d=await(await this.awaitService()).getRelativesForTopicInMap(s,a,[e]);if(!((i=(o=(r=d?.results)===null||r===void 0?void 0:r[0])===null||o===void 0?void 0:o.entries)===null||i===void 0)&&i[0]){let u=d.results[0].entries[0].topic.tocId;return await this.navigateToTopic(u),!0}else return await this.navigateToTopic("root"),!1}setSearchInDocumentQuery(e){this.store.actions.searchInDocumentQuery(e)}async setTranslationDestinationLanguage(e){this.store.actions.setTranslationDestinationLanguage(e),e&&this.sendDocumentOnDemandTranslateEvent(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationSourceLanguage(e){this.store.actions.setTranslationSourceLanguage(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationProfileId(e){this.store.actions.setTranslationProfileId(e)}async setTranslationLoading(e){this.store.actions.setTranslationLoading(e)}async setTranslationError(e){this.store.actions.setTranslationError(e)}getTranslationSettings(){var e;let r=this.store.getState();return r.translation.profileId&&r.translation.destinationLanguage?{profileId:r.translation.profileId,destinationLanguage:r.translation.destinationLanguage.code,sourceLanguage:(e=r.map)===null||e===void 0?void 0:e.lang}:void 0}setLinkPreviewDialogId(e){this.store.actions.linkPreviewDialogId(e)}async fetchMapRating(){var e;this.store.actions.mapRating(await((e=this.service)===null||e===void 0?void 0:e.getMapRating()))}async fetchTopicRating(e){var r;let o=await((r=this.service)===null||r===void 0?void 0:r.getTopicRating(e));o&&this.store.actions.setTopicsRating({[e]:o})}registerMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.add(e),this.store.getState().relatives==null?this.fetchRelatives():this.updateClusteringHelper()}unregisterMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.delete(e),this.updateClusteringHelper()}getAccurateNavigationData(e,r,o){return this.service.getAccurateNavigationData(e,r?.number,o?.section,this.getTranslationSettings())}buildBreadcrumb(e){var r;return(r=this.service)===null||r===void 0?void 0:r.buildBreadcrumb(e,this.getTranslationSettings())}fetchTopicContent(e){var r,o;let i=this.getTranslationSettings();return i?(this.sendTopicAiTranslateEvent(i.destinationLanguage,e),(r=this.service)===null||r===void 0?void 0:r.getTranslatedTopicContent(e,i).then(a=>(a.isTranslationError&&this.setTranslationError(!0),a.content))):(o=this.service)===null||o===void 0?void 0:o.getTopicContent(e)}getTocNode(e){return this.service.getTocNode(e,this.getTranslationSettings())}getPage(e){return this.service.getPage(e,this.getTranslationSettings())}onMapAttachmentsUpdate(){var e;(e=this.service)===null||e===void 0||e.clearMapAttachments(),this.store.dispatchEvent(new Event(Nn.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(e){var r,o,i;this.store.getState().relatives==null&&await this.fetchRelatives();let a=mo.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",e),s=ls(a);if(s){let c=this.store.getState().visibleTopics[0],d=(o=this.store.getState().configuration)===null||o===void 0?void 0:o.relativeTopicPivotMetadata;if(d&&c){let u=await((i=this.service)===null||i===void 0?void 0:i.getTopicMetadataValue(c,d));s=jf(s,u)}}return s}sendDocumentOnDemandTranslateEvent(e){let{editorMode:r,apiIntegrationIdentifier:o,apiIntegrationAppVersion:i}=$.getState(),a=this.store.getState(),s=a.map,c=a.translation.profileId;if(!(r||!s||!o||!i||!c))try{let d=this.analyticsEventsService.convertMapToAnalyticsDocument(s);this.analyticsEventsService.sendDocumentOnDemandTranslateEvent({name:"DOCUMENT__ON_DEMAND_TRANSLATE",offline:!1,appName:o,appVersion:i,sourceLanguage:this.parseLanguageToAnalyticsFormat(s.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e.code),profileId:c,document:d,translationOrigin:Ri.AI})}catch(d){console.warn("Failed to send on-demand document translate event:",d)}}sendTopicAiTranslateEvent(e,r){let{editorMode:o,apiIntegrationIdentifier:i,apiIntegrationAppVersion:a}=$.getState(),s=this.store.getState(),c=s.map,d=s.translation.profileId;if(!(o||!c||!i||!a||!d))try{let u=this.buildBreadcrumb(r.tocId);if(!u){console.warn("Failed to build breadcrumb for topic ai translate event");return}let p=this.analyticsEventsService.convertMapToAnalyticsDocument(c);this.analyticsEventsService.sendTopicAiTranslateEvent({name:"TOPIC__AI_TRANSLATE",offline:!1,appName:i,appVersion:a,sourceLanguage:this.parseLanguageToAnalyticsFormat(c.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e),breadcrumb:u.map(h=>({tocId:h.tocId,title:h.title,mapId:c.id,mapTitle:c.title})),document:p,profileId:d})}catch(u){console.warn("Failed to send topic ai translate event:",u)}}parseLanguageToAnalyticsFormat(e){if(!e)return;let r=e.split("-");return r.length===2?{languageCode:r[0],countryCode:r[1]}:{languageCode:r[0],countryCode:""}}};var pa=class extends CustomEvent{constructor(e,r){super("ft-reader-map-loaded",{detail:{map:e,toc:r}})}},ha=class extends CustomEvent{constructor(e,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},ma=class extends CustomEvent{constructor(e){super("ft-reader-navigation-done",{detail:e})}},ga=class extends CustomEvent{constructor(e){super("ft-reader-load-error",{detail:e})}},ya=class extends Event{constructor(){super("ft-reader-map-not-found")}},ba=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},va=class extends Event{constructor(){super("ft-reader-map-forbidden")}},xa=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var tt=function(t,e,r,o){var i=arguments.length,a=i<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,r):o,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,o);else for(var c=t.length-1;c>=0;c--)(s=t[c])&&(a=(i<3?s(a):i>3?s(e,r,a):s(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},Ql=class{constructor(e){this.stateManager=e}searchInDocument(e){this.stateManager.setSearchInDocumentQuery(e??"")}},ke=class extends Lt{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new ge(5),this.navigationDebouncer=new ge(10),this.mapLoadedEventDebouncer=new ge(50),this.addStore($)}render(){return k`
|
|
2620
|
+
`;var K3={setTranslationDestinationLanguage:(t,e)=>{t.translation.destinationLanguage=e.payload},setTranslationSourceLanguage:(t,e)=>{t.translation.sourceLanguage=e.payload},setTranslationProfileId:(t,e)=>{t.translation.profileId=e.payload},setTranslationLoading:(t,e)=>{t.translation.isLoading=e.payload},setTranslationError:(t,e)=>{t.translation.isError=e.payload},setTopicsRating:(t,e)=>{for(let r in e.payload)t.topicsRating[r]=e.payload[r]}},Vf=t=>Qt.get({name:"ft-reader-"+t,initialState:{mapId:void 0,renderedTopics:[],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,mapRating:void 0,topicsRating:{},translation:{sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1},linkPreviewDialogId:void 0},reducers:K3});var Xl=class{constructor(e,r){this.mapId=e,this.paginatedToc=r,this.nodeByTocId={},this.nodeByUrl={},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,nodeByUrl:this.nodeByUrl,duplicatedPrettyUrls:this.duplicatedPrettyUrls,pages:this.pages,pageByTocId:this.pageByTocId,translationError:this.paginatedToc.translationError}}extractPagesToc(e,r,o){return e.flatMap(i=>{var a;return i.pageConfiguration&&this.registerPage(this.buildPage(i,o)),i.tocId==null?this.extractPagesToc(i.children,r,o):[{tocId:i.tocId,title:(a=i.title)!==null&&a!==void 0?a:"",untranslatedTitle:i.untranslatedTitle,depth:r,children:this.extractPagesToc(i.children,r+1,i.tocId)}]})}convertNodes(e,r,o){return e.flatMap(i=>{var a,s,c;if(i.tocId==null)return[...this.convertSectionNodes((a=i.pageToc)!==null&&a!==void 0?a:[],r,i.tocId),...this.convertNodes(i.children,r,i.tocId)];let d=(s=i.prettyUrl)===null||s===void 0?void 0:s.replace(/^\//,""),u={tocId:i.tocId,contentId:i.contentId,title:i.title,untranslatedTitle:i.untranslatedTitle,hasRating:i.hasRating,origin:i.origin,prettyUrl:d,depth:r,parentTocId:o,children:[]};this.register(u);let p=this.convertSectionNodes((c=i.pageToc)!==null&&c!==void 0?c:[],r+1,i.tocId),h=this.convertNodes(i.children,r+1,u.tocId);return u.children=[...p,...h],[u]})}convertSectionNodes(e,r,o){return e.flatMap(i=>{var a;let s=(a=i.prettyUrl)===null||a===void 0?void 0:a.replace(/^\//,""),c={...i,prettyUrl:s,depth:r,parentTocId:o,children:[]};return this.register(c),c.children=this.convertSectionNodes(i.children,r+1,i.tocId),[c]})}buildPage(e,r){var o,i,a,s,c,d;let u={number:this.pages.length+1,title:(o=e.title)!==null&&o!==void 0?o:"",untranslatedTitle:e.untranslatedTitle,rootTocId:(i=e.tocId)!==null&&i!==void 0?i:"root",toc:((a=e.pageToc)!==null&&a!==void 0?a:[]).map(g=>this.nodeByTocId[g.tocId]),topics:[],hiddenTopics:[],breadcrumb:r?this.buildBreadcrumb(this.nodeByTocId[r]):[]},p=(g,S)=>(S?u.topics:u.hiddenTopics).push(g),h=(c=(s=e.pageConfiguration)===null||s===void 0?void 0:s.parentsVisibility)!==null&&c!==void 0?c:[];return u.breadcrumb.forEach((g,S)=>{p(g,h[S])}),e.tocId&&p(e.tocId,e.pageConfiguration.isVisible),u.topics.push(...this.tocIds((d=e.pageToc)!==null&&d!==void 0?d:[])),u}registerPage(e){for(let r of[...e.topics,...e.hiddenTopics])this.pageByTocId[r]||(this.pageByTocId[r]=e);this.pages.push(e)}tocIds(e){return e.flatMap(r=>[r.tocId,...this.tocIds(r.children)])}buildBreadcrumb(e){let r=[e.tocId];for(;e?.parentTocId;)r.unshift(e.parentTocId),e=this.nodeByTocId[e.parentTocId];return r}register(e){e.prettyUrl&&(this.nodeByUrl[e.prettyUrl]==null?this.nodeByUrl[e.prettyUrl]=e:this.duplicatedPrettyUrls.add(e.prettyUrl)),this.nodeByUrl[`${this.mapId}/${e.tocId}`]=e,this.nodeByTocId[e.tocId]=e}},la=class{convertPaginatedToc(e,r){return new Xl(e,r).build()}};var da=class extends Ve{get mapId(){return this._mapId}set mapId(e){e!==this._mapId&&this.clear(),this._mapId=e}constructor(e,r,o){super(!1,r),this.converter=e,this._mapId=o,this.initCache()}async withMapId(e){return this._mapId?e(this._mapId):void 0}initCache(){this.cache.register("configuration",()=>this.api.getReaderConfiguration()),this.cache.register("map",()=>this.withMapId(e=>this.fetchMap(e))),this.cache.register("enrichedToc",()=>this.withMapId(e=>this.fetchPages(e).then(r=>this.converter.convertPaginatedToc(e,r)))),this.cache.register("ratingSummary",()=>{var e,r;return Jt((r=(e=$.getState().session)===null||e===void 0?void 0:e.profile.roles)!==null&&r!==void 0?r:[],"RATING_USER")?this.withMapId(i=>this.fetchMapRating(i)):Promise.resolve()})}clear(){this.cache.clearMatching(e=>e!=="configuration")}makeCacheKey(e,r){return e+(r?"-destinationLanguage-"+r?.destinationLanguage:"")}getMap(e){return this.cache.get(this.makeCacheKey("map",e),()=>this.fetchMap(this.mapId,e))}getMapNow(e){return this.cache.getNow(this.makeCacheKey("map",e))}getConfiguration(){return this.cache.get("configuration")}clearConfiguration(){this.cache.clear("configuration")}getEnrichedToc(e){return this.cache.get(this.makeCacheKey("enrichedToc",e),()=>this.fetchPages(this.mapId,e).then(r=>this.converter.convertPaginatedToc(this.mapId,r)))}getEnrichedTocNow(e){return this.cache.getNow(this.makeCacheKey("enrichedToc",e))}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(e){return(await this.getEnrichedToc(e)).toc}async getPagesToc(e){return(await this.getEnrichedToc(e)).pagesToc}async getTranslationError(e){return(await this.getEnrichedToc(e)).translationError}async getTocNode(e,r){return(await this.getEnrichedToc(r)).nodeByTocId[e]}getTocNodeNow(e,r){var o;return(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.nodeByTocId[e]}getTocNodeNowByUrl(e,r){var o,i;let a=this.getMapNow(r);return a?.prettyUrl==e||`${a?.id}/root`===e?(o=this.getEnrichedTocNow(r))===null||o===void 0?void 0:o.toc[0]:(i=this.getEnrichedTocNow(r))===null||i===void 0?void 0:i.nodeByUrl[e]}async getPage(e,r){let o=await this.getEnrichedToc(r);return o.pages[e-1]||o.pages[0]}async getPageByTocId(e,r){let o=await this.getEnrichedToc(r);return o.pageByTocId[e]||o.pages[0]}getTopicInfo(e){return this.cache.get("topic-"+e.tocId,()=>this.fetchTopicMetadata(e))}getTopicContent(e){return this.cache.get("topic-content-"+e.tocId,()=>this.fetchTopicHTMLContent(e))}getTranslatedTopicContent(e,r){return this.cache.get(this.makeCacheKey("translated-topic-content-"+e.tocId,r),()=>this.fetchTranslatedTopicHTMLContent(e,r))}async getTopicMetadataValue(e,r){let o=this.getTocNodeNow(e);if(!o)return;let i=await this.getTopicInfo(o);return i?.metadata.find(a=>a.key==r)}getAttachments(){return this.cache.get("map-attachments",()=>this.fetchAttachments())}clearMapAttachments(){this.cache.clear("map-attachments")}getRelativesForDocument(e,r){return this.cache.get("document-relatives-"+e+"-"+r.join("-"),()=>this.fetchRelativesForDocument(e,r))}getRelativesForTopicInMap(e,r,o){return this.cache.get("topic-relatives-"+[e,r,...o].join("-"),()=>this.fetchRelativesForTopicInMap(e,r,o))}getAttachmentDownloadLink(e){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(e).content}?download=true&locationValue=reader`)}getLink(e,r,o){let i=this.getNavigationData(e,r,o),a=this.getReaderLinkPrefix()+(i.prettyUrl?i.prettyUrl:`${i.mapId}/${i.tocId}`),s=new URL(a,this.api.tenantBaseUrl);return i.page!=null&&s.searchParams.set("page",`${i.page}`),i.prettyUrlDuplicated&&s.searchParams.set("tocId",i.tocId),i.section!=null&&s.searchParams.set("section",i.section),s.href}getNavigationData(e,r,o,i){var a,s;e=e||"root";let c=this.getEnrichedTocNow(i),d=c?.pageByTocId[e],u=c?.nodeByTocId[e],p=u?.prettyUrl;return{mapId:this.mapId,tocId:e,topicTitle:(a=u?.title)!==null&&a!==void 0?a:"",untranslatedTopicTitle:u?.untranslatedTitle,page:r&&d&&d.number!==r?r:void 0,prettyUrl:p?.replace(/^r\//,""),prettyUrlDuplicated:(s=c?.duplicatedPrettyUrls.has(p??""))!==null&&s!==void 0?s:!1,section:o}}async getAccurateNavigationData(e,r,o,i){return await this.getEnrichedToc(i),this.getNavigationData(e,r,o,i)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then(e=>e?.publication)}getTopicRating(e){return this.getRatingSummary().then(r=>{var o;return r?{type:r.topics.type,rating:(o=r.topics)===null||o===void 0?void 0:o.ratings.find(i=>i.tocId===e)}:void 0})}rateMap(e,r){return this.makeRateMapRequest(e,r).then(()=>this.clearRatingIfNecessary())}unrateMap(){return this.makeUnrateMapRequest().then(()=>this.clearRatingIfNecessary())}sendMapFeedback(e,r){return this.makeMapFeedbackRequest(e,r)}rateTopic(e,r,o){return this.makeRateTopicRequest(e,r,o).then(()=>this.clearRatingIfNecessary())}unrateTopic(e){return this.makeUnrateTopicRequest(e).then(()=>this.clearRatingIfNecessary())}async clearRatingIfNecessary(){let e=$.getState().session;e?.sessionAuthenticated&&this.cache.clear("ratingSummary")}sendTopicFeedback(e,r,o){return this.makeTopicFeedbackRequest(e,r,o)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(e,r){let o=this.getTocNodeNow(e,r),i=[{tocId:o.tocId,title:o.title,untranslatedTitle:o.untranslatedTitle}],a=this.getTocNodeNow(o.parentTocId,r);for(;a;)i.unshift({tocId:a.tocId,title:a.title,untranslatedTitle:a.untranslatedTitle}),a=this.getTocNodeNow(a.parentTocId,r);return i}isFeatureAccessible(e,{session:r}){var o;if(!this.isFeatureAvailable(e))return!1;switch(e){case mt.FEEDBACK:return Jt(r??[],pe.FEEDBACK_USER);case mt.RATING:return Jt(r??[],pe.RATING_USER);case mt.PRINT:return Jt(r??[],pe.PRINT_USER);case mt.BOOKMARK:return!!r?.sessionAuthenticated;case mt.COLLECTIONS:return Jt(r??[],pe.COLLECTION_USER);case mt.PERSONAL_BOOKS:return Jt(r??[],pe.PERSONAL_BOOK_USER)&&!(!((o=this.getMapNow())===null||o===void 0)&&o.pbkConfidential);default:return!1}}makeAbsolute(e){return this.api.makeAbsolute(e)}};var ua=class t extends da{static async build(e){return new t(new la,void 0,e)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(e,r){let o=await this.api.getMap(e,r);return this.fingerprint=o.fingerprint,o}fetchMapRating(e){return this.api.getMapRating(e)}async fetchPages(e,r){return await this.getMap(r),this.api.getPages(e,this.fingerprint,r)}fetchTopicHTMLContent(e){return this.api.getTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint)}fetchTranslatedTopicHTMLContent(e,r){return this.api.getTranslatedTopicHTMLContent(this.mapId,e.contentId,"DESIGNED_READER",this.fingerprint,r)}fetchTopicMetadata(e){return this.api.getTopic(this.mapId,e.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch(()=>[])}fetchRelativesForDocument(e,r){let o={query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",metadataFilters:[{key:e,valueFilter:{negative:!1,values:r}}],sort:[],facets:[]};return this.api.search(o)}fetchRelativesForTopicInMap(e,r,o){let i={query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",metadataFilters:[{key:r,valueFilter:{negative:!1,values:o}},{key:"ft:publicationId",valueFilter:{negative:!1,values:[e]}}],sort:[],facets:[]};return this.api.search(i)}makeMapFeedbackRequest(e,r){return this.api.sendMapFeedback(this.mapId,e,r)}makeRateMapRequest(e,r){return this.api.rateMap(this.mapId,e,r)}makeRateTopicRequest(e,r,o){return this.api.rateTopic(this.mapId,e,r,o)}makeTopicFeedbackRequest(e,r,o){return this.api.sendTopicFeedback(this.mapId,e,r,o)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(e){return this.api.unrateTopic(this.mapId,e)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(e){return!0}};var Z3="topicPivot";function jf(t,e){let r=new URL(t);return e?.values.forEach(o=>{r.searchParams.append(Z3,o)}),r.href}var fa=class t{static build(e,r){return new t(Vf(e.trim()||"context"),r??ua.build)}loaded(){return Qa(()=>this._loaded)}constructor(e,r,o,i){this.store=e,this.clusteringHelperProvider=o,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new ge(10),this.analyticsEventsService=i??new Di,this.initService(r)}async initService(e){return this.service=await e(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(e){e!==this.store.getState().mapId&&(this.store.actions.mapId(e),this.service&&(this.service.mapId=e),await this.reload())}setRenderedTopics(e){this.store.actions.renderedTopics(e)}setVisibleTopics(e){this.store.actions.visibleTopics(e)}async awaitService(){return pn(()=>this.service)}async navigateToTopic(e,r,o){await this.loaded();let i=await this.awaitService(),a=await(o!=null?i.getPage(o,this.getTranslationSettings()):i.getPageByTocId(e??"root",this.getTranslationSettings()));this.store.actions.currentPage(a);let s=this.resolveValidNonRootTocId(e,a);this.store.actions.scrollTarget({tocId:s,section:r}),this.store.getState().visibleTopics[0]!==s&&this.store.actions.visibleTopics([])}resolveValidNonRootTocId(e,r){var o,i,a;let s=(o=e==="root"?void 0:e)!==null&&o!==void 0?o:r.rootTocId;return r.topics.includes(s)?s:(a=(i=r.topics[0])!==null&&i!==void 0?i:r.hiddenTopics[0])!==null&&a!==void 0?a:"root"}async navigateToPage(e){await this.loaded();let o=await(await this.awaitService()).getPage(e,this.getTranslationSettings());this.store.actions.currentPage(o)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var e;!((e=this.service)===null||e===void 0)&&e.mapId&&this.store.getState().map==null&&await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}clear(){var e;this._loaded=!1,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),this.store.actions.renderedTopics([]),this.store.actions.visibleTopics([]),this.store.actions.translation({sourceLanguage:void 0,destinationLanguage:void 0,profileId:void 0,isLoading:!1,isError:!1}),this.store.actions.mapRating(void 0),(e=this.service)===null||e===void 0||e.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(e){var r,o,i,a,s;try{e&&this.setTranslationLoading(!0);let c=d=>{throw e&&this.setTranslationError(!0),d};await Promise.all([this.loadConfiguration(),(r=this.service)===null||r===void 0?void 0:r.getMap(e).then(d=>this.store.actions.map(d)).catch(c),(o=this.service)===null||o===void 0?void 0:o.getToc(e).then(d=>this.store.actions.toc(d)).catch(c),(i=this.service)===null||i===void 0?void 0:i.getPagesToc(e).then(d=>this.store.actions.pagesToc(d)).catch(c),(a=this.service)===null||a===void 0?void 0:a.getPaginationConfiguration().then(d=>this.store.actions.paginationConfiguration(d)).catch(c),(s=this.service)===null||s===void 0?void 0:s.getTranslationError(e).then(d=>this.setTranslationError(d))]),this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives(),this._loaded=!0,e&&this.setTranslationLoading(!1)}catch(c){this.errorHandler&&!(c instanceof jt)&&this.errorHandler(c)}}loadConfiguration(){var e;return(e=this.service)===null||e===void 0?void 0:e.getConfiguration().then(r=>this.store.actions.configuration(r))}reloadConfiguration(){var e;return(e=this.service)===null||e===void 0||e.clearConfiguration(),this.loadConfiguration()}async fetchRelatives(){var e,r;let o=(e=this.store.getState().map)===null||e===void 0?void 0:e.metadata.filter(i=>{var a;return i.key==((a=this.store.getState().configuration)===null||a===void 0?void 0:a.relativePivotMetadata)}).flatMap(i=>i.values);if(o!==void 0&&o.length>0){let i=await((r=this.service)===null||r===void 0?void 0:r.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata,o)),a=i?.results.flatMap(s=>s.entries);this.store.actions.relatives(a)}this.updateClusteringHelper()}updateClusteringHelper(){this.clusteringHelper=this.createClusteringHelper(),this.clusteringHelper&&this.store.dispatchEvent(new Event(Nn.clusteringHelperCreated))}createClusteringHelper(){var e,r;if(this.clusteringHelperProvider)return this.clusteringHelperProvider();let o=this.store.getState().relatives;if(o){let i=o.find(s=>{var c;return((c=s.map)===null||c===void 0?void 0:c.mapId)==this.store.getState().mapId}),a=(r=(e=$.getState().metadataConfiguration)===null||e===void 0?void 0:e.descriptors)!==null&&r!==void 0?r:[];return new mo(o,i,this.metadataForSwitchToRelatives,a)}}async navigateToRelativeTopicIfFound(e){var r,o,i;await this.loaded();let a=await pn(()=>{var u;return(u=this.store.getState().configuration)===null||u===void 0?void 0:u.relativeTopicPivotMetadata}),s=this.store.getState().mapId,d=await(await this.awaitService()).getRelativesForTopicInMap(s,a,[e]);if(!((i=(o=(r=d?.results)===null||r===void 0?void 0:r[0])===null||o===void 0?void 0:o.entries)===null||i===void 0)&&i[0]){let u=d.results[0].entries[0].topic.tocId;return await this.navigateToTopic(u),!0}else return await this.navigateToTopic("root"),!1}setSearchInDocumentQuery(e){this.store.actions.searchInDocumentQuery(e)}async setTranslationDestinationLanguage(e){this.store.actions.setTranslationDestinationLanguage(e),e&&this.sendDocumentOnDemandTranslateEvent(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationSourceLanguage(e){this.store.actions.setTranslationSourceLanguage(e),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationProfileId(e){this.store.actions.setTranslationProfileId(e)}async setTranslationLoading(e){this.store.actions.setTranslationLoading(e)}async setTranslationError(e){this.store.actions.setTranslationError(e)}getTranslationSettings(){var e;let r=this.store.getState();return r.translation.profileId&&r.translation.destinationLanguage?{profileId:r.translation.profileId,destinationLanguage:r.translation.destinationLanguage.code,sourceLanguage:(e=r.map)===null||e===void 0?void 0:e.lang}:void 0}setLinkPreviewDialogId(e){this.store.actions.linkPreviewDialogId(e)}async fetchMapRating(){var e;this.store.actions.mapRating(await((e=this.service)===null||e===void 0?void 0:e.getMapRating()))}async fetchTopicRating(e){var r;let o=await((r=this.service)===null||r===void 0?void 0:r.getTopicRating(e));o&&this.store.actions.setTopicsRating({[e]:o})}registerMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.add(e),this.store.getState().relatives==null?this.fetchRelatives():this.updateClusteringHelper()}unregisterMetadataForSwitchToRelatives(e){this.metadataForSwitchToRelatives.delete(e),this.updateClusteringHelper()}getAccurateNavigationData(e,r,o){return this.service.getAccurateNavigationData(e,r?.number,o?.section,this.getTranslationSettings())}buildBreadcrumb(e){var r;return(r=this.service)===null||r===void 0?void 0:r.buildBreadcrumb(e,this.getTranslationSettings())}fetchTopicContent(e){var r,o;let i=this.getTranslationSettings();return i?(this.sendTopicAiTranslateEvent(i.destinationLanguage,e),(r=this.service)===null||r===void 0?void 0:r.getTranslatedTopicContent(e,i).then(a=>(a.isTranslationError&&this.setTranslationError(!0),a.content))):(o=this.service)===null||o===void 0?void 0:o.getTopicContent(e)}getTocNode(e){return this.service.getTocNode(e,this.getTranslationSettings())}getPage(e){return this.service.getPage(e,this.getTranslationSettings())}onMapAttachmentsUpdate(){var e;(e=this.service)===null||e===void 0||e.clearMapAttachments(),this.store.dispatchEvent(new Event(Nn.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(e){var r,o,i;this.store.getState().relatives==null&&await this.fetchRelatives();let a=mo.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",e),s=ls(a);if(s){let c=this.store.getState().visibleTopics[0],d=(o=this.store.getState().configuration)===null||o===void 0?void 0:o.relativeTopicPivotMetadata;if(d&&c){let u=await((i=this.service)===null||i===void 0?void 0:i.getTopicMetadataValue(c,d));s=jf(s,u)}}return s}sendDocumentOnDemandTranslateEvent(e){let{editorMode:r,apiIntegrationIdentifier:o,apiIntegrationAppVersion:i}=$.getState(),a=this.store.getState(),s=a.map,c=a.translation.profileId;if(!(r||!s||!o||!i||!c))try{let d=this.analyticsEventsService.convertMapToAnalyticsDocument(s);this.analyticsEventsService.sendDocumentOnDemandTranslateEvent({name:"DOCUMENT__ON_DEMAND_TRANSLATE",offline:!1,appName:o,appVersion:i,sourceLanguage:this.parseLanguageToAnalyticsFormat(s.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e.code),profileId:c,document:d,translationOrigin:Ri.AI})}catch(d){console.warn("Failed to send on-demand document translate event:",d)}}sendTopicAiTranslateEvent(e,r){let{editorMode:o,apiIntegrationIdentifier:i,apiIntegrationAppVersion:a}=$.getState(),s=this.store.getState(),c=s.map,d=s.translation.profileId;if(!(o||!c||!i||!a||!d))try{let u=this.buildBreadcrumb(r.tocId);if(!u){console.warn("Failed to build breadcrumb for topic ai translate event");return}let p=this.analyticsEventsService.convertMapToAnalyticsDocument(c);this.analyticsEventsService.sendTopicAiTranslateEvent({name:"TOPIC__AI_TRANSLATE",offline:!1,appName:i,appVersion:a,sourceLanguage:this.parseLanguageToAnalyticsFormat(c.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(e),breadcrumb:u.map(h=>({tocId:h.tocId,title:h.title})),document:p,profileId:d})}catch(u){console.warn("Failed to send topic ai translate event:",u)}}parseLanguageToAnalyticsFormat(e){if(!e)return;let r=e.split("-");return r.length===2?{languageCode:r[0],countryCode:r[1]}:{languageCode:r[0],countryCode:""}}};var pa=class extends CustomEvent{constructor(e,r){super("ft-reader-map-loaded",{detail:{map:e,toc:r}})}},ha=class extends CustomEvent{constructor(e,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},ma=class extends CustomEvent{constructor(e){super("ft-reader-navigation-done",{detail:e})}},ga=class extends CustomEvent{constructor(e){super("ft-reader-load-error",{detail:e})}},ya=class extends Event{constructor(){super("ft-reader-map-not-found")}},ba=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},va=class extends Event{constructor(){super("ft-reader-map-forbidden")}},xa=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var tt=function(t,e,r,o){var i=arguments.length,a=i<3?e:o===null?o=Object.getOwnPropertyDescriptor(e,r):o,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(t,e,r,o);else for(var c=t.length-1;c>=0;c--)(s=t[c])&&(a=(i<3?s(a):i>3?s(e,r,a):s(e,r))||a);return i>3&&a&&Object.defineProperty(e,r,a),a},Ql=class{constructor(e){this.stateManager=e}searchInDocument(e){this.stateManager.setSearchInDocumentQuery(e??"")}},ke=class extends Lt{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new ge(5),this.navigationDebouncer=new ge(10),this.mapLoadedEventDebouncer=new ge(50),this.addStore($)}render(){return k`
|
|
2621
2621
|
${this.importStyleIfNeeded()}
|
|
2622
2622
|
<slot @register-ft-reader-component=${this.registerComponent}></slot>
|
|
2623
2623
|
`}importStyleIfNeeded(){var e,r;let o=(e=this.stateManager.service)===null||e===void 0?void 0:e.themeStylesheet();return!o||window.location.href.startsWith((r=this.baseUrl)!==null&&r!==void 0?r:"")?G:k`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-reader-feedback",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.27",
|
|
4
4
|
"description": "Feedback forms for a map and its topics in an integrated reader",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lit"
|
|
@@ -19,13 +19,13 @@
|
|
|
19
19
|
"url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fluid-topics/ft-app-context": "2.0.
|
|
23
|
-
"@fluid-topics/ft-reader-context": "2.0.
|
|
24
|
-
"@fluid-topics/ft-wc-utils": "2.0.
|
|
22
|
+
"@fluid-topics/ft-app-context": "2.0.27",
|
|
23
|
+
"@fluid-topics/ft-reader-context": "2.0.27",
|
|
24
|
+
"@fluid-topics/ft-wc-utils": "2.0.27",
|
|
25
25
|
"lit": "3.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@fluid-topics/public-api": "1.0.122"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "b4f188d0ab565bdf8a3fab98c358d0b533e8f611"
|
|
31
31
|
}
|