@fluid-topics/ft-reader-metadata 2.0.25 → 2.0.26
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.
|
@@ -2173,7 +2173,7 @@ svg:not(:root).svg-inline--fa, svg:not(:host).svg-inline--fa {
|
|
|
2173
2173
|
</ft-typography>
|
|
2174
2174
|
</div>
|
|
2175
2175
|
`}};or.elementDefinitions={"ft-typography":Se};or.styles=P0;var Qo=x(I());(0,Qo.customElement)("ft-floating-menu")(rr);(0,Qo.customElement)("ftds-floating-menu")(po);(0,Qo.customElement)("ft-floating-menu-item")(_e);(0,Qo.customElement)("ft-floating-menu-label")(or);var Jo=x(I());function Ap(e){var t;return((t=(0,Jo.accessResult)(e))===null||t===void 0?void 0:t.openMode)===Un.EXTERNAL}function $s(e){return Ap(e)?(0,Jo.accessResult)(e).originUrl:(0,Jo.accessResultUrl)(e)}var W0=x(U0());var Gs=Jn.build("designedReaderMapMetadata");var B0=x(F());var H0=B0.css`
|
|
2176
|
-
`;var en=x(F()),Or=x(J()),ye=x(I());var Ue=x(I());var $0=x(I()),Op={setTranslationDestinationLanguage:(e,t)=>{e.translation.destinationLanguage=t.payload},setTranslationSourceLanguage:(e,t)=>{e.translation.sourceLanguage=t.payload},setTranslationProfileId:(e,t)=>{e.translation.profileId=t.payload},setTranslationLoading:(e,t)=>{e.translation.isLoading=t.payload},setTranslationError:(e,t)=>{e.translation.isError=t.payload},setTopicsRating:(e,t)=>{for(let r in t.payload)e.topicsRating[r]=t.payload[r]}},G0=e=>$0.FtReduxStore.get({name:"ft-reader-"+e,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:Op});var Fs=class{constructor(t,r){this.mapId=t,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(t,r,n){return t.flatMap(a=>{var i;return a.pageConfiguration&&this.registerPage(this.buildPage(a,n)),a.tocId==null?this.extractPagesToc(a.children,r,n):[{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(t,r,n){return t.flatMap(a=>{var i,s,l;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:n,children:[]};this.register(f);let h=this.convertSectionNodes((l=a.pageToc)!==null&&l!==void 0?l:[],r+1,a.tocId),g=this.convertNodes(a.children,r+1,f.tocId);return f.children=[...h,...g],[f]})}convertSectionNodes(t,r,n){return t.flatMap(a=>{var i;let s=(i=a.prettyUrl)===null||i===void 0?void 0:i.replace(/^\//,""),l={...a,prettyUrl:s,depth:r,parentTocId:n,children:[]};return this.register(l),l.children=this.convertSectionNodes(a.children,r+1,a.tocId),[l]})}buildPage(t,r){var n,a,i,s,l,u;let f={number:this.pages.length+1,title:(n=t.title)!==null&&n!==void 0?n:"",untranslatedTitle:t.untranslatedTitle,rootTocId:(a=t.tocId)!==null&&a!==void 0?a:"root",toc:((i=t.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=(l=(s=t.pageConfiguration)===null||s===void 0?void 0:s.parentsVisibility)!==null&&l!==void 0?l:[];return f.breadcrumb.forEach((y,S)=>{h(y,g[S])}),t.tocId&&h(t.tocId,t.pageConfiguration.isVisible),f.topics.push(...this.tocIds((u=t.pageToc)!==null&&u!==void 0?u:[])),f}registerPage(t){for(let r of[...t.topics,...t.hiddenTopics])this.pageByTocId[r]||(this.pageByTocId[r]=t);this.pages.push(t)}tocIds(t){return t.flatMap(r=>[r.tocId,...this.tocIds(r.children)])}buildBreadcrumb(t){let r=[t.tocId];for(;t?.parentTocId;)r.unshift(t.parentTocId),t=this.nodeByTocId[t.parentTocId];return r}register(t){t.prettyUrl&&(this.nodeByUrl[t.prettyUrl]==null?this.nodeByUrl[t.prettyUrl]=t:this.duplicatedPrettyUrls.add(t.prettyUrl)),this.nodeByUrl[`${this.mapId}/${t.tocId}`]=t,this.nodeByTocId[t.tocId]=t}},_a=class{convertPaginatedToc(t,r){return new Fs(t,r).build()}};var Na=class extends Ae{get mapId(){return this._mapId}set mapId(t){t!==this._mapId&&this.clear(),this._mapId=t}constructor(t,r,n){super(!1,r),this.converter=t,this._mapId=n,this.initCache()}async withMapId(t){return this._mapId?t(this._mapId):void 0}initCache(){this.cache.register("configuration",()=>this.api.getReaderConfiguration()),this.cache.register("map",()=>this.withMapId(t=>this.fetchMap(t))),this.cache.register("enrichedToc",()=>this.withMapId(t=>this.fetchPages(t).then(r=>this.converter.convertPaginatedToc(t,r)))),this.cache.register("ratingSummary",()=>{var t,r;return wt((r=(t=z.getState().session)===null||t===void 0?void 0:t.profile.roles)!==null&&r!==void 0?r:[],"RATING_USER")?this.withMapId(a=>this.fetchMapRating(a)):Promise.resolve()})}clear(){this.cache.clearMatching(t=>t!=="configuration")}makeCacheKey(t,r){return t+(r?"-destinationLanguage-"+r?.destinationLanguage:"")}getMap(t){return this.cache.get(this.makeCacheKey("map",t),()=>this.fetchMap(this.mapId,t))}getMapNow(t){return this.cache.getNow(this.makeCacheKey("map",t))}getConfiguration(){return this.cache.get("configuration")}clearConfiguration(){this.cache.clear("configuration")}getEnrichedToc(t){return this.cache.get(this.makeCacheKey("enrichedToc",t),()=>this.fetchPages(this.mapId,t).then(r=>this.converter.convertPaginatedToc(this.mapId,r)))}getEnrichedTocNow(t){return this.cache.getNow(this.makeCacheKey("enrichedToc",t))}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(t){return(await this.getEnrichedToc(t)).toc}async getPagesToc(t){return(await this.getEnrichedToc(t)).pagesToc}async getTranslationError(t){return(await this.getEnrichedToc(t)).translationError}async getTocNode(t,r){return(await this.getEnrichedToc(r)).nodeByTocId[t]}getTocNodeNow(t,r){var n;return(n=this.getEnrichedTocNow(r))===null||n===void 0?void 0:n.nodeByTocId[t]}getTocNodeNowByUrl(t,r){var n,a;let i=this.getMapNow(r);return i?.prettyUrl==t||`${i?.id}/root`===t?(n=this.getEnrichedTocNow(r))===null||n===void 0?void 0:n.toc[0]:(a=this.getEnrichedTocNow(r))===null||a===void 0?void 0:a.nodeByUrl[t]}async getPage(t,r){let n=await this.getEnrichedToc(r);return n.pages[t-1]||n.pages[0]}async getPageByTocId(t,r){let n=await this.getEnrichedToc(r);return n.pageByTocId[t]||n.pages[0]}getTopicInfo(t){return this.cache.get("topic-"+t.tocId,()=>this.fetchTopicMetadata(t))}getTopicContent(t){return this.cache.get("topic-content-"+t.tocId,()=>this.fetchTopicHTMLContent(t))}getTranslatedTopicContent(t,r){return this.cache.get(this.makeCacheKey("translated-topic-content-"+t.tocId,r),()=>this.fetchTranslatedTopicHTMLContent(t,r))}async getTopicMetadataValue(t,r){let n=this.getTocNodeNow(t);if(!n)return;let a=await this.getTopicInfo(n);return a?.metadata.find(i=>i.key==r)}getAttachments(){return this.cache.get("map-attachments",()=>this.fetchAttachments())}clearMapAttachments(){this.cache.clear("map-attachments")}getRelativesForDocument(t,r){return this.cache.get("document-relatives-"+t+"-"+r.join("-"),()=>this.fetchRelativesForDocument(t,r))}getRelativesForTopicInMap(t,r,n){return this.cache.get("topic-relatives-"+[t,r,...n].join("-"),()=>this.fetchRelativesForTopicInMap(t,r,n))}getAttachmentDownloadLink(t){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(t).content}?download=true&locationValue=reader`)}getLink(t,r,n){let a=this.getNavigationData(t,r,n),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(t,r,n,a){var i,s;t=t||"root";let l=this.getEnrichedTocNow(a),u=l?.pageByTocId[t],f=l?.nodeByTocId[t],h=f?.prettyUrl;return{mapId:this.mapId,tocId:t,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=l?.duplicatedPrettyUrls.has(h??""))!==null&&s!==void 0?s:!1,section:n}}async getAccurateNavigationData(t,r,n,a){return await this.getEnrichedToc(a),this.getNavigationData(t,r,n,a)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then(t=>t?.publication)}getTopicRating(t){return this.getRatingSummary().then(r=>{var n;return r?{type:r.topics.type,rating:(n=r.topics)===null||n===void 0?void 0:n.ratings.find(a=>a.tocId===t)}:void 0})}rateMap(t,r){return this.makeRateMapRequest(t,r).then(()=>this.clearRatingIfNecessary())}unrateMap(){return this.makeUnrateMapRequest().then(()=>this.clearRatingIfNecessary())}sendMapFeedback(t,r){return this.makeMapFeedbackRequest(t,r)}rateTopic(t,r,n){return this.makeRateTopicRequest(t,r,n).then(()=>this.clearRatingIfNecessary())}unrateTopic(t){return this.makeUnrateTopicRequest(t).then(()=>this.clearRatingIfNecessary())}async clearRatingIfNecessary(){let t=z.getState().session;t?.sessionAuthenticated&&this.cache.clear("ratingSummary")}sendTopicFeedback(t,r,n){return this.makeTopicFeedbackRequest(t,r,n)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(t,r){let n=this.getTocNodeNow(t,r),a=[{tocId:n.tocId,title:n.title,untranslatedTitle:n.untranslatedTitle}],i=this.getTocNodeNow(n.parentTocId,r);for(;i;)a.unshift({tocId:i.tocId,title:i.title,untranslatedTitle:i.untranslatedTitle}),i=this.getTocNodeNow(i.parentTocId,r);return a}isFeatureAccessible(t,{session:r}){var n;if(!this.isFeatureAvailable(t))return!1;switch(t){case Ct.FEEDBACK:return wt(r??[],Y.FEEDBACK_USER);case Ct.RATING:return wt(r??[],Y.RATING_USER);case Ct.PRINT:return wt(r??[],Y.PRINT_USER);case Ct.BOOKMARK:return!!r?.sessionAuthenticated;case Ct.COLLECTIONS:return wt(r??[],Y.COLLECTION_USER);case Ct.PERSONAL_BOOKS:return wt(r??[],Y.PERSONAL_BOOK_USER)&&!(!((n=this.getMapNow())===null||n===void 0)&&n.pbkConfidential);default:return!1}}makeAbsolute(t){return this.api.makeAbsolute(t)}};var Ma=class e extends Na{static async build(t){return new e(new _a,void 0,t)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(t,r){let n=await this.api.getMap(t,r);return this.fingerprint=n.fingerprint,n}fetchMapRating(t){return this.api.getMapRating(t)}async fetchPages(t,r){return await this.getMap(r),this.api.getPages(t,this.fingerprint,r)}fetchTopicHTMLContent(t){return this.api.getTopicHTMLContent(this.mapId,t.contentId,"DESIGNED_READER",this.fingerprint)}fetchTranslatedTopicHTMLContent(t,r){return this.api.getTranslatedTopicHTMLContent(this.mapId,t.contentId,"DESIGNED_READER",this.fingerprint,r)}fetchTopicMetadata(t){return this.api.getTopic(this.mapId,t.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch(()=>[])}fetchRelativesForDocument(t,r){let n={query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",metadataFilters:[{key:t,valueFilter:{negative:!1,values:r}}],sort:[],facets:[]};return this.api.search(n)}fetchRelativesForTopicInMap(t,r,n){let a={query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",metadataFilters:[{key:r,valueFilter:{negative:!1,values:n}},{key:"ft:publicationId",valueFilter:{negative:!1,values:[t]}}],sort:[],facets:[]};return this.api.search(a)}makeMapFeedbackRequest(t,r){return this.api.sendMapFeedback(this.mapId,t,r)}makeRateMapRequest(t,r){return this.api.rateMap(this.mapId,t,r)}makeRateTopicRequest(t,r,n){return this.api.rateTopic(this.mapId,t,r,n)}makeTopicFeedbackRequest(t,r,n){return this.api.sendTopicFeedback(this.mapId,t,r,n)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(t){return this.api.unrateTopic(this.mapId,t)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(t){return!0}};var Rp="topicPivot";function Ia(e,t){let r=new URL(e);return t?.values.forEach(n=>{r.searchParams.append(Rp,n)}),r.href}var Pa=class e{static build(t,r){return new e(G0(t.trim()||"context"),r??Ma.build)}loaded(){return(0,Ue.waitUntil)(()=>this._loaded)}constructor(t,r,n,a){this.store=t,this.clusteringHelperProvider=n,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new Ue.Debouncer(10),this.analyticsEventsService=a??new jn,this.initService(r)}async initService(t){return this.service=await t(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(t){t!==this.store.getState().mapId&&(this.store.actions.mapId(t),this.service&&(this.service.mapId=t),await this.reload())}setRenderedTopics(t){this.store.actions.renderedTopics(t)}setVisibleTopics(t){this.store.actions.visibleTopics(t)}async awaitService(){return(0,Ue.waitFor)(()=>this.service)}async navigateToTopic(t,r,n){await this.loaded();let a=await this.awaitService(),i=await(n!=null?a.getPage(n,this.getTranslationSettings()):a.getPageByTocId(t??"root",this.getTranslationSettings()));this.store.actions.currentPage(i);let s=this.resolveValidNonRootTocId(t,i);this.store.actions.scrollTarget({tocId:s,section:r}),this.store.getState().visibleTopics[0]!==s&&this.store.actions.visibleTopics([])}resolveValidNonRootTocId(t,r){var n,a,i;let s=(n=t==="root"?void 0:t)!==null&&n!==void 0?n: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(t){await this.loaded();let n=await(await this.awaitService()).getPage(t,this.getTranslationSettings());this.store.actions.currentPage(n)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var t;!((t=this.service)===null||t===void 0)&&t.mapId&&this.store.getState().map==null&&await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}clear(){var t;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),(t=this.service)===null||t===void 0||t.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(t){var r,n,a,i,s;try{t&&this.setTranslationLoading(!0);let l=u=>{throw t&&this.setTranslationError(!0),u};await Promise.all([this.loadConfiguration(),(r=this.service)===null||r===void 0?void 0:r.getMap(t).then(u=>this.store.actions.map(u)).catch(l),(n=this.service)===null||n===void 0?void 0:n.getToc(t).then(u=>this.store.actions.toc(u)).catch(l),(a=this.service)===null||a===void 0?void 0:a.getPagesToc(t).then(u=>this.store.actions.pagesToc(u)).catch(l),(i=this.service)===null||i===void 0?void 0:i.getPaginationConfiguration().then(u=>this.store.actions.paginationConfiguration(u)).catch(l),(s=this.service)===null||s===void 0?void 0:s.getTranslationError(t).then(u=>this.setTranslationError(u))]),this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives(),this._loaded=!0,t&&this.setTranslationLoading(!1)}catch(l){this.errorHandler&&!(l instanceof Ue.CanceledPromiseError)&&this.errorHandler(l)}}loadConfiguration(){var t;return(t=this.service)===null||t===void 0?void 0:t.getConfiguration().then(r=>this.store.actions.configuration(r))}reloadConfiguration(){var t;return(t=this.service)===null||t===void 0||t.clearConfiguration(),this.loadConfiguration()}async fetchRelatives(){var t,r;let n=(t=this.store.getState().map)===null||t===void 0?void 0:t.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(n!==void 0&&n.length>0){let a=await((r=this.service)===null||r===void 0?void 0:r.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata,n)),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(ir.clusteringHelperCreated))}createClusteringHelper(){var t,r;if(this.clusteringHelperProvider)return this.clusteringHelperProvider();let n=this.store.getState().relatives;if(n){let a=n.find(s=>{var l;return((l=s.map)===null||l===void 0?void 0:l.mapId)==this.store.getState().mapId}),i=(r=(t=z.getState().metadataConfiguration)===null||t===void 0?void 0:t.descriptors)!==null&&r!==void 0?r:[];return new Ue.ClusteringHelper(n,a,this.metadataForSwitchToRelatives,i)}}async navigateToRelativeTopicIfFound(t){var r,n,a;await this.loaded();let i=await(0,Ue.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,[t]);if(!((a=(n=(r=u?.results)===null||r===void 0?void 0:r[0])===null||n===void 0?void 0:n.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(t){this.store.actions.searchInDocumentQuery(t)}async setTranslationDestinationLanguage(t){this.store.actions.setTranslationDestinationLanguage(t),t&&this.sendDocumentOnDemandTranslateEvent(t),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationSourceLanguage(t){this.store.actions.setTranslationSourceLanguage(t),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationProfileId(t){this.store.actions.setTranslationProfileId(t)}async setTranslationLoading(t){this.store.actions.setTranslationLoading(t)}async setTranslationError(t){this.store.actions.setTranslationError(t)}getTranslationSettings(){var t;let r=this.store.getState();return r.translation.profileId&&r.translation.destinationLanguage?{profileId:r.translation.profileId,destinationLanguage:r.translation.destinationLanguage.code,sourceLanguage:(t=r.map)===null||t===void 0?void 0:t.lang}:void 0}setLinkPreviewDialogId(t){this.store.actions.linkPreviewDialogId(t)}async fetchMapRating(){var t;this.store.actions.mapRating(await((t=this.service)===null||t===void 0?void 0:t.getMapRating()))}async fetchTopicRating(t){var r;let n=await((r=this.service)===null||r===void 0?void 0:r.getTopicRating(t));n&&this.store.actions.setTopicsRating({[t]:n})}registerMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.add(t),this.store.getState().relatives==null?this.fetchRelatives():this.updateClusteringHelper()}unregisterMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.delete(t),this.updateClusteringHelper()}getAccurateNavigationData(t,r,n){return this.service.getAccurateNavigationData(t,r?.number,n?.section,this.getTranslationSettings())}buildBreadcrumb(t){var r;return(r=this.service)===null||r===void 0?void 0:r.buildBreadcrumb(t,this.getTranslationSettings())}fetchTopicContent(t){var r,n;let a=this.getTranslationSettings();return a?(this.sendTopicAiTranslateEvent(a.destinationLanguage,t),(r=this.service)===null||r===void 0?void 0:r.getTranslatedTopicContent(t,a).then(i=>(i.isTranslationError&&this.setTranslationError(!0),i.content))):(n=this.service)===null||n===void 0?void 0:n.getTopicContent(t)}getTocNode(t){return this.service.getTocNode(t,this.getTranslationSettings())}getPage(t){return this.service.getPage(t,this.getTranslationSettings())}onMapAttachmentsUpdate(){var t;(t=this.service)===null||t===void 0||t.clearMapAttachments(),this.store.dispatchEvent(new Event(ir.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(t){var r,n,a;this.store.getState().relatives==null&&await this.fetchRelatives();let i=Ue.ClusteringHelper.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",t),s=(0,Ue.accessResultUrl)(i);if(s){let l=this.store.getState().visibleTopics[0],u=(n=this.store.getState().configuration)===null||n===void 0?void 0:n.relativeTopicPivotMetadata;if(u&&l){let f=await((a=this.service)===null||a===void 0?void 0:a.getTopicMetadataValue(l,u));s=Ia(s,f)}}return s}sendDocumentOnDemandTranslateEvent(t){let{editorMode:r,apiIntegrationIdentifier:n,apiIntegrationAppVersion:a}=z.getState(),i=this.store.getState(),s=i.map,l=i.translation.profileId;if(!(r||!s||!n||!a||!l))try{let u=this.analyticsEventsService.convertMapToAnalyticsDocument(s);this.analyticsEventsService.sendDocumentOnDemandTranslateEvent({name:"DOCUMENT__ON_DEMAND_TRANSLATE",offline:!1,appName:n,appVersion:a,sourceLanguage:this.parseLanguageToAnalyticsFormat(s.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(t.code),profileId:l,document:u,translationOrigin:Dn.AI})}catch(u){console.warn("Failed to send on-demand document translate event:",u)}}sendTopicAiTranslateEvent(t,r){let{editorMode:n,apiIntegrationIdentifier:a,apiIntegrationAppVersion:i}=z.getState(),s=this.store.getState(),l=s.map,u=s.translation.profileId;if(!(n||!l||!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(l);this.analyticsEventsService.sendTopicAiTranslateEvent({name:"TOPIC__AI_TRANSLATE",offline:!1,appName:a,appVersion:i,sourceLanguage:this.parseLanguageToAnalyticsFormat(l.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(t),breadcrumb:f.map(g=>({tocId:g.tocId,title:g.title,mapId:l.id,mapTitle:l.title})),document:h,profileId:u})}catch(f){console.warn("Failed to send topic ai translate event:",f)}}parseLanguageToAnalyticsFormat(t){if(!t)return;let r=t.split("-");return r.length===2?{languageCode:r[0],countryCode:r[1]}:{languageCode:r[0],countryCode:""}}};var ka=class extends CustomEvent{constructor(t,r){super("ft-reader-map-loaded",{detail:{map:t,toc:r}})}},za=class extends CustomEvent{constructor(t,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},Da=class extends CustomEvent{constructor(t){super("ft-reader-navigation-done",{detail:t})}},Ua=class extends CustomEvent{constructor(t){super("ft-reader-load-error",{detail:t})}},Ba=class extends Event{constructor(){super("ft-reader-map-not-found")}},Ha=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},$a=class extends Event{constructor(){super("ft-reader-map-forbidden")}},Ga=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var Be=function(e,t,r,n){var a=arguments.length,i=a<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,r):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(e,t,r,n);else for(var l=e.length-1;l>=0;l--)(s=e[l])&&(i=(a<3?s(i):a>3?s(t,r,i):s(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i},Ws=class{constructor(t){this.stateManager=t}searchInDocument(t){this.stateManager.setSearchInDocumentQuery(t??"")}},ge=class extends ye.FtLitElementRedux{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new ye.Debouncer(5),this.navigationDebouncer=new ye.Debouncer(10),this.mapLoadedEventDebouncer=new ye.Debouncer(50),this.addStore(z)}render(){return en.html`
|
|
2176
|
+
`;var en=x(F()),Or=x(J()),ye=x(I());var Ue=x(I());var $0=x(I()),Op={setTranslationDestinationLanguage:(e,t)=>{e.translation.destinationLanguage=t.payload},setTranslationSourceLanguage:(e,t)=>{e.translation.sourceLanguage=t.payload},setTranslationProfileId:(e,t)=>{e.translation.profileId=t.payload},setTranslationLoading:(e,t)=>{e.translation.isLoading=t.payload},setTranslationError:(e,t)=>{e.translation.isError=t.payload},setTopicsRating:(e,t)=>{for(let r in t.payload)e.topicsRating[r]=t.payload[r]}},G0=e=>$0.FtReduxStore.get({name:"ft-reader-"+e,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:Op});var Fs=class{constructor(t,r){this.mapId=t,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(t,r,n){return t.flatMap(a=>{var i;return a.pageConfiguration&&this.registerPage(this.buildPage(a,n)),a.tocId==null?this.extractPagesToc(a.children,r,n):[{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(t,r,n){return t.flatMap(a=>{var i,s,l;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:n,children:[]};this.register(f);let h=this.convertSectionNodes((l=a.pageToc)!==null&&l!==void 0?l:[],r+1,a.tocId),g=this.convertNodes(a.children,r+1,f.tocId);return f.children=[...h,...g],[f]})}convertSectionNodes(t,r,n){return t.flatMap(a=>{var i;let s=(i=a.prettyUrl)===null||i===void 0?void 0:i.replace(/^\//,""),l={...a,prettyUrl:s,depth:r,parentTocId:n,children:[]};return this.register(l),l.children=this.convertSectionNodes(a.children,r+1,a.tocId),[l]})}buildPage(t,r){var n,a,i,s,l,u;let f={number:this.pages.length+1,title:(n=t.title)!==null&&n!==void 0?n:"",untranslatedTitle:t.untranslatedTitle,rootTocId:(a=t.tocId)!==null&&a!==void 0?a:"root",toc:((i=t.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=(l=(s=t.pageConfiguration)===null||s===void 0?void 0:s.parentsVisibility)!==null&&l!==void 0?l:[];return f.breadcrumb.forEach((y,S)=>{h(y,g[S])}),t.tocId&&h(t.tocId,t.pageConfiguration.isVisible),f.topics.push(...this.tocIds((u=t.pageToc)!==null&&u!==void 0?u:[])),f}registerPage(t){for(let r of[...t.topics,...t.hiddenTopics])this.pageByTocId[r]||(this.pageByTocId[r]=t);this.pages.push(t)}tocIds(t){return t.flatMap(r=>[r.tocId,...this.tocIds(r.children)])}buildBreadcrumb(t){let r=[t.tocId];for(;t?.parentTocId;)r.unshift(t.parentTocId),t=this.nodeByTocId[t.parentTocId];return r}register(t){t.prettyUrl&&(this.nodeByUrl[t.prettyUrl]==null?this.nodeByUrl[t.prettyUrl]=t:this.duplicatedPrettyUrls.add(t.prettyUrl)),this.nodeByUrl[`${this.mapId}/${t.tocId}`]=t,this.nodeByTocId[t.tocId]=t}},_a=class{convertPaginatedToc(t,r){return new Fs(t,r).build()}};var Na=class extends Ae{get mapId(){return this._mapId}set mapId(t){t!==this._mapId&&this.clear(),this._mapId=t}constructor(t,r,n){super(!1,r),this.converter=t,this._mapId=n,this.initCache()}async withMapId(t){return this._mapId?t(this._mapId):void 0}initCache(){this.cache.register("configuration",()=>this.api.getReaderConfiguration()),this.cache.register("map",()=>this.withMapId(t=>this.fetchMap(t))),this.cache.register("enrichedToc",()=>this.withMapId(t=>this.fetchPages(t).then(r=>this.converter.convertPaginatedToc(t,r)))),this.cache.register("ratingSummary",()=>{var t,r;return wt((r=(t=z.getState().session)===null||t===void 0?void 0:t.profile.roles)!==null&&r!==void 0?r:[],"RATING_USER")?this.withMapId(a=>this.fetchMapRating(a)):Promise.resolve()})}clear(){this.cache.clearMatching(t=>t!=="configuration")}makeCacheKey(t,r){return t+(r?"-destinationLanguage-"+r?.destinationLanguage:"")}getMap(t){return this.cache.get(this.makeCacheKey("map",t),()=>this.fetchMap(this.mapId,t))}getMapNow(t){return this.cache.getNow(this.makeCacheKey("map",t))}getConfiguration(){return this.cache.get("configuration")}clearConfiguration(){this.cache.clear("configuration")}getEnrichedToc(t){return this.cache.get(this.makeCacheKey("enrichedToc",t),()=>this.fetchPages(this.mapId,t).then(r=>this.converter.convertPaginatedToc(this.mapId,r)))}getEnrichedTocNow(t){return this.cache.getNow(this.makeCacheKey("enrichedToc",t))}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(t){return(await this.getEnrichedToc(t)).toc}async getPagesToc(t){return(await this.getEnrichedToc(t)).pagesToc}async getTranslationError(t){return(await this.getEnrichedToc(t)).translationError}async getTocNode(t,r){return(await this.getEnrichedToc(r)).nodeByTocId[t]}getTocNodeNow(t,r){var n;return(n=this.getEnrichedTocNow(r))===null||n===void 0?void 0:n.nodeByTocId[t]}getTocNodeNowByUrl(t,r){var n,a;let i=this.getMapNow(r);return i?.prettyUrl==t||`${i?.id}/root`===t?(n=this.getEnrichedTocNow(r))===null||n===void 0?void 0:n.toc[0]:(a=this.getEnrichedTocNow(r))===null||a===void 0?void 0:a.nodeByUrl[t]}async getPage(t,r){let n=await this.getEnrichedToc(r);return n.pages[t-1]||n.pages[0]}async getPageByTocId(t,r){let n=await this.getEnrichedToc(r);return n.pageByTocId[t]||n.pages[0]}getTopicInfo(t){return this.cache.get("topic-"+t.tocId,()=>this.fetchTopicMetadata(t))}getTopicContent(t){return this.cache.get("topic-content-"+t.tocId,()=>this.fetchTopicHTMLContent(t))}getTranslatedTopicContent(t,r){return this.cache.get(this.makeCacheKey("translated-topic-content-"+t.tocId,r),()=>this.fetchTranslatedTopicHTMLContent(t,r))}async getTopicMetadataValue(t,r){let n=this.getTocNodeNow(t);if(!n)return;let a=await this.getTopicInfo(n);return a?.metadata.find(i=>i.key==r)}getAttachments(){return this.cache.get("map-attachments",()=>this.fetchAttachments())}clearMapAttachments(){this.cache.clear("map-attachments")}getRelativesForDocument(t,r){return this.cache.get("document-relatives-"+t+"-"+r.join("-"),()=>this.fetchRelativesForDocument(t,r))}getRelativesForTopicInMap(t,r,n){return this.cache.get("topic-relatives-"+[t,r,...n].join("-"),()=>this.fetchRelativesForTopicInMap(t,r,n))}getAttachmentDownloadLink(t){return this.makeAbsolute(`${this.api.endpoints.khub.maps.mapId(this.mapId).attachments.attachmentId(t).content}?download=true&locationValue=reader`)}getLink(t,r,n){let a=this.getNavigationData(t,r,n),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(t,r,n,a){var i,s;t=t||"root";let l=this.getEnrichedTocNow(a),u=l?.pageByTocId[t],f=l?.nodeByTocId[t],h=f?.prettyUrl;return{mapId:this.mapId,tocId:t,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=l?.duplicatedPrettyUrls.has(h??""))!==null&&s!==void 0?s:!1,section:n}}async getAccurateNavigationData(t,r,n,a){return await this.getEnrichedToc(a),this.getNavigationData(t,r,n,a)}getRatingSummary(){return this.cache.get("ratingSummary")}reloadRating(){return this.cache.clear("ratingSummary"),this.getRatingSummary()}getMapRating(){return this.getRatingSummary().then(t=>t?.publication)}getTopicRating(t){return this.getRatingSummary().then(r=>{var n;return r?{type:r.topics.type,rating:(n=r.topics)===null||n===void 0?void 0:n.ratings.find(a=>a.tocId===t)}:void 0})}rateMap(t,r){return this.makeRateMapRequest(t,r).then(()=>this.clearRatingIfNecessary())}unrateMap(){return this.makeUnrateMapRequest().then(()=>this.clearRatingIfNecessary())}sendMapFeedback(t,r){return this.makeMapFeedbackRequest(t,r)}rateTopic(t,r,n){return this.makeRateTopicRequest(t,r,n).then(()=>this.clearRatingIfNecessary())}unrateTopic(t){return this.makeUnrateTopicRequest(t).then(()=>this.clearRatingIfNecessary())}async clearRatingIfNecessary(){let t=z.getState().session;t?.sessionAuthenticated&&this.cache.clear("ratingSummary")}sendTopicFeedback(t,r,n){return this.makeTopicFeedbackRequest(t,r,n)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(t,r){let n=this.getTocNodeNow(t,r),a=[{tocId:n.tocId,title:n.title,untranslatedTitle:n.untranslatedTitle}],i=this.getTocNodeNow(n.parentTocId,r);for(;i;)a.unshift({tocId:i.tocId,title:i.title,untranslatedTitle:i.untranslatedTitle}),i=this.getTocNodeNow(i.parentTocId,r);return a}isFeatureAccessible(t,{session:r}){var n;if(!this.isFeatureAvailable(t))return!1;switch(t){case Ct.FEEDBACK:return wt(r??[],Y.FEEDBACK_USER);case Ct.RATING:return wt(r??[],Y.RATING_USER);case Ct.PRINT:return wt(r??[],Y.PRINT_USER);case Ct.BOOKMARK:return!!r?.sessionAuthenticated;case Ct.COLLECTIONS:return wt(r??[],Y.COLLECTION_USER);case Ct.PERSONAL_BOOKS:return wt(r??[],Y.PERSONAL_BOOK_USER)&&!(!((n=this.getMapNow())===null||n===void 0)&&n.pbkConfidential);default:return!1}}makeAbsolute(t){return this.api.makeAbsolute(t)}};var Ma=class e extends Na{static async build(t){return new e(new _a,void 0,t)}clear(){super.clear(),this.fingerprint=void 0}async fetchMap(t,r){let n=await this.api.getMap(t,r);return this.fingerprint=n.fingerprint,n}fetchMapRating(t){return this.api.getMapRating(t)}async fetchPages(t,r){return await this.getMap(r),this.api.getPages(t,this.fingerprint,r)}fetchTopicHTMLContent(t){return this.api.getTopicHTMLContent(this.mapId,t.contentId,"DESIGNED_READER",this.fingerprint)}fetchTranslatedTopicHTMLContent(t,r){return this.api.getTranslatedTopicHTMLContent(this.mapId,t.contentId,"DESIGNED_READER",this.fingerprint,r)}fetchTopicMetadata(t){return this.api.getTopic(this.mapId,t.contentId,this.fingerprint)}fetchAttachments(){return this.api.getMapAttachments(this.mapId).catch(()=>[])}fetchRelativesForDocument(t,r){let n={query:"",paging:{page:1,perPage:-1},scope:"DOCUMENTS",metadataFilters:[{key:t,valueFilter:{negative:!1,values:r}}],sort:[],facets:[]};return this.api.search(n)}fetchRelativesForTopicInMap(t,r,n){let a={query:"",paging:{page:1,perPage:1},scope:"ALL_TOPICS",metadataFilters:[{key:r,valueFilter:{negative:!1,values:n}},{key:"ft:publicationId",valueFilter:{negative:!1,values:[t]}}],sort:[],facets:[]};return this.api.search(a)}makeMapFeedbackRequest(t,r){return this.api.sendMapFeedback(this.mapId,t,r)}makeRateMapRequest(t,r){return this.api.rateMap(this.mapId,t,r)}makeRateTopicRequest(t,r,n){return this.api.rateTopic(this.mapId,t,r,n)}makeTopicFeedbackRequest(t,r,n){return this.api.sendTopicFeedback(this.mapId,t,r,n)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(t){return this.api.unrateTopic(this.mapId,t)}getReaderLinkPrefix(){return"r/"}isFeatureAvailable(t){return!0}};var Rp="topicPivot";function Ia(e,t){let r=new URL(e);return t?.values.forEach(n=>{r.searchParams.append(Rp,n)}),r.href}var Pa=class e{static build(t,r){return new e(G0(t.trim()||"context"),r??Ma.build)}loaded(){return(0,Ue.waitUntil)(()=>this._loaded)}constructor(t,r,n,a){this.store=t,this.clusteringHelperProvider=n,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new Ue.Debouncer(10),this.analyticsEventsService=a??new jn,this.initService(r)}async initService(t){return this.service=await t(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(t){t!==this.store.getState().mapId&&(this.store.actions.mapId(t),this.service&&(this.service.mapId=t),await this.reload())}setRenderedTopics(t){this.store.actions.renderedTopics(t)}setVisibleTopics(t){this.store.actions.visibleTopics(t)}async awaitService(){return(0,Ue.waitFor)(()=>this.service)}async navigateToTopic(t,r,n){await this.loaded();let a=await this.awaitService(),i=await(n!=null?a.getPage(n,this.getTranslationSettings()):a.getPageByTocId(t??"root",this.getTranslationSettings()));this.store.actions.currentPage(i);let s=this.resolveValidNonRootTocId(t,i);this.store.actions.scrollTarget({tocId:s,section:r}),this.store.getState().visibleTopics[0]!==s&&this.store.actions.visibleTopics([])}resolveValidNonRootTocId(t,r){var n,a,i;let s=(n=t==="root"?void 0:t)!==null&&n!==void 0?n: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(t){await this.loaded();let n=await(await this.awaitService()).getPage(t,this.getTranslationSettings());this.store.actions.currentPage(n)}scrollDone(){this.store.actions.scrollTarget({})}async load(){var t;!((t=this.service)===null||t===void 0)&&t.mapId&&this.store.getState().map==null&&await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}clear(){var t;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),(t=this.service)===null||t===void 0||t.clear(),this.clusteringHelper=void 0}reload(){return this.clear(),this.load()}async fetchData(t){var r,n,a,i,s;try{t&&this.setTranslationLoading(!0);let l=u=>{throw t&&this.setTranslationError(!0),u};await Promise.all([this.loadConfiguration(),(r=this.service)===null||r===void 0?void 0:r.getMap(t).then(u=>this.store.actions.map(u)).catch(l),(n=this.service)===null||n===void 0?void 0:n.getToc(t).then(u=>this.store.actions.toc(u)).catch(l),(a=this.service)===null||a===void 0?void 0:a.getPagesToc(t).then(u=>this.store.actions.pagesToc(u)).catch(l),(i=this.service)===null||i===void 0?void 0:i.getPaginationConfiguration().then(u=>this.store.actions.paginationConfiguration(u)).catch(l),(s=this.service)===null||s===void 0?void 0:s.getTranslationError(t).then(u=>this.setTranslationError(u))]),this.metadataForSwitchToRelatives.size>0&&this.fetchRelatives(),this._loaded=!0,t&&this.setTranslationLoading(!1)}catch(l){this.errorHandler&&!(l instanceof Ue.CanceledPromiseError)&&this.errorHandler(l)}}loadConfiguration(){var t;return(t=this.service)===null||t===void 0?void 0:t.getConfiguration().then(r=>this.store.actions.configuration(r))}reloadConfiguration(){var t;return(t=this.service)===null||t===void 0||t.clearConfiguration(),this.loadConfiguration()}async fetchRelatives(){var t,r;let n=(t=this.store.getState().map)===null||t===void 0?void 0:t.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(n!==void 0&&n.length>0){let a=await((r=this.service)===null||r===void 0?void 0:r.getRelativesForDocument(this.store.getState().configuration.relativePivotMetadata,n)),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(ir.clusteringHelperCreated))}createClusteringHelper(){var t,r;if(this.clusteringHelperProvider)return this.clusteringHelperProvider();let n=this.store.getState().relatives;if(n){let a=n.find(s=>{var l;return((l=s.map)===null||l===void 0?void 0:l.mapId)==this.store.getState().mapId}),i=(r=(t=z.getState().metadataConfiguration)===null||t===void 0?void 0:t.descriptors)!==null&&r!==void 0?r:[];return new Ue.ClusteringHelper(n,a,this.metadataForSwitchToRelatives,i)}}async navigateToRelativeTopicIfFound(t){var r,n,a;await this.loaded();let i=await(0,Ue.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,[t]);if(!((a=(n=(r=u?.results)===null||r===void 0?void 0:r[0])===null||n===void 0?void 0:n.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(t){this.store.actions.searchInDocumentQuery(t)}async setTranslationDestinationLanguage(t){this.store.actions.setTranslationDestinationLanguage(t),t&&this.sendDocumentOnDemandTranslateEvent(t),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationSourceLanguage(t){this.store.actions.setTranslationSourceLanguage(t),await this.loadDebouncer.run(()=>this.fetchData(this.getTranslationSettings()))}async setTranslationProfileId(t){this.store.actions.setTranslationProfileId(t)}async setTranslationLoading(t){this.store.actions.setTranslationLoading(t)}async setTranslationError(t){this.store.actions.setTranslationError(t)}getTranslationSettings(){var t;let r=this.store.getState();return r.translation.profileId&&r.translation.destinationLanguage?{profileId:r.translation.profileId,destinationLanguage:r.translation.destinationLanguage.code,sourceLanguage:(t=r.map)===null||t===void 0?void 0:t.lang}:void 0}setLinkPreviewDialogId(t){this.store.actions.linkPreviewDialogId(t)}async fetchMapRating(){var t;this.store.actions.mapRating(await((t=this.service)===null||t===void 0?void 0:t.getMapRating()))}async fetchTopicRating(t){var r;let n=await((r=this.service)===null||r===void 0?void 0:r.getTopicRating(t));n&&this.store.actions.setTopicsRating({[t]:n})}registerMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.add(t),this.store.getState().relatives==null?this.fetchRelatives():this.updateClusteringHelper()}unregisterMetadataForSwitchToRelatives(t){this.metadataForSwitchToRelatives.delete(t),this.updateClusteringHelper()}getAccurateNavigationData(t,r,n){return this.service.getAccurateNavigationData(t,r?.number,n?.section,this.getTranslationSettings())}buildBreadcrumb(t){var r;return(r=this.service)===null||r===void 0?void 0:r.buildBreadcrumb(t,this.getTranslationSettings())}fetchTopicContent(t){var r,n;let a=this.getTranslationSettings();return a?(this.sendTopicAiTranslateEvent(a.destinationLanguage,t),(r=this.service)===null||r===void 0?void 0:r.getTranslatedTopicContent(t,a).then(i=>(i.isTranslationError&&this.setTranslationError(!0),i.content))):(n=this.service)===null||n===void 0?void 0:n.getTopicContent(t)}getTocNode(t){return this.service.getTocNode(t,this.getTranslationSettings())}getPage(t){return this.service.getPage(t,this.getTranslationSettings())}onMapAttachmentsUpdate(){var t;(t=this.service)===null||t===void 0||t.clearMapAttachments(),this.store.dispatchEvent(new Event(ir.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(t){var r,n,a;this.store.getState().relatives==null&&await this.fetchRelatives();let i=Ue.ClusteringHelper.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",t),s=(0,Ue.accessResultUrl)(i);if(s){let l=this.store.getState().visibleTopics[0],u=(n=this.store.getState().configuration)===null||n===void 0?void 0:n.relativeTopicPivotMetadata;if(u&&l){let f=await((a=this.service)===null||a===void 0?void 0:a.getTopicMetadataValue(l,u));s=Ia(s,f)}}return s}sendDocumentOnDemandTranslateEvent(t){let{editorMode:r,apiIntegrationIdentifier:n,apiIntegrationAppVersion:a}=z.getState(),i=this.store.getState(),s=i.map,l=i.translation.profileId;if(!(r||!s||!n||!a||!l))try{let u=this.analyticsEventsService.convertMapToAnalyticsDocument(s);this.analyticsEventsService.sendDocumentOnDemandTranslateEvent({name:"DOCUMENT__ON_DEMAND_TRANSLATE",offline:!1,appName:n,appVersion:a,sourceLanguage:this.parseLanguageToAnalyticsFormat(s.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(t.code),profileId:l,document:u,translationOrigin:Dn.AI})}catch(u){console.warn("Failed to send on-demand document translate event:",u)}}sendTopicAiTranslateEvent(t,r){let{editorMode:n,apiIntegrationIdentifier:a,apiIntegrationAppVersion:i}=z.getState(),s=this.store.getState(),l=s.map,u=s.translation.profileId;if(!(n||!l||!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(l);this.analyticsEventsService.sendTopicAiTranslateEvent({name:"TOPIC__AI_TRANSLATE",offline:!1,appName:a,appVersion:i,sourceLanguage:this.parseLanguageToAnalyticsFormat(l.lang),destinationLanguage:this.parseLanguageToAnalyticsFormat(t),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(t){if(!t)return;let r=t.split("-");return r.length===2?{languageCode:r[0],countryCode:r[1]}:{languageCode:r[0],countryCode:""}}};var ka=class extends CustomEvent{constructor(t,r){super("ft-reader-map-loaded",{detail:{map:t,toc:r}})}},za=class extends CustomEvent{constructor(t,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},Da=class extends CustomEvent{constructor(t){super("ft-reader-navigation-done",{detail:t})}},Ua=class extends CustomEvent{constructor(t){super("ft-reader-load-error",{detail:t})}},Ba=class extends Event{constructor(){super("ft-reader-map-not-found")}},Ha=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},$a=class extends Event{constructor(){super("ft-reader-map-forbidden")}},Ga=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var Be=function(e,t,r,n){var a=arguments.length,i=a<3?t:n===null?n=Object.getOwnPropertyDescriptor(t,r):n,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(e,t,r,n);else for(var l=e.length-1;l>=0;l--)(s=e[l])&&(i=(a<3?s(i):a>3?s(t,r,i):s(t,r))||i);return a>3&&i&&Object.defineProperty(t,r,i),i},Ws=class{constructor(t){this.stateManager=t}searchInDocument(t){this.stateManager.setSearchInDocumentQuery(t??"")}},ge=class extends ye.FtLitElementRedux{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new ye.Debouncer(5),this.navigationDebouncer=new ye.Debouncer(10),this.mapLoadedEventDebouncer=new ye.Debouncer(50),this.addStore(z)}render(){return en.html`
|
|
2177
2177
|
${this.importStyleIfNeeded()}
|
|
2178
2178
|
<slot @register-ft-reader-component=${this.registerComponent}></slot>
|
|
2179
2179
|
`}importStyleIfNeeded(){var t,r;let n=(t=this.stateManager.service)===null||t===void 0?void 0:t.themeStylesheet();return!n||window.location.href.startsWith((r=this.baseUrl)!==null&&r!==void 0?r:"")?en.nothing:en.html`
|
|
@@ -2253,7 +2253,7 @@ svg:not(:root).svg-inline--fa, svg:not(:host).svg-inline--fa {
|
|
|
2253
2253
|
</ft-typography>
|
|
2254
2254
|
</div>
|
|
2255
2255
|
`}};ir.elementDefinitions={"ft-typography":Re};ir.styles=pu;J("ft-floating-menu")(ar);J("ftds-floating-menu")(_o);J("ft-floating-menu-item")(ke);J("ft-floating-menu-label")(ir);function Sh(t){var e;return((e=Fr(t))===null||e===void 0?void 0:e.openMode)===na.EXTERNAL}function vl(t){return Sh(t)?Fr(t).originUrl:Go(t)}var xl=Sa.build("designedReaderMapMetadata");var hu=k`
|
|
2256
|
-
`;var Ch={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]}},mu=t=>Pt.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:Ch});var Sl=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 d=(s=a.prettyUrl)===null||s===void 0?void 0:s.replace(/^\//,""),u={tocId:a.tocId,contentId:a.contentId,title:a.title,untranslatedTitle:a.untranslatedTitle,hasRating:a.hasRating,origin:a.origin,prettyUrl:d,depth:r,parentTocId:o,children:[]};this.register(u);let p=this.convertSectionNodes((c=a.pageToc)!==null&&c!==void 0?c:[],r+1,a.tocId),h=this.convertNodes(a.children,r+1,u.tocId);return u.children=[...p,...h],[u]})}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,d;let u={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(g=>this.nodeByTocId[g.tocId]),topics:[],hiddenTopics:[],breadcrumb:r?this.buildBreadcrumb(this.nodeByTocId[r]):[]},p=(g,x)=>(x?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,x)=>{p(g,h[x])}),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}},Fa=class{convertPaginatedToc(e,r){return new Sl(e,r).build()}};var Ga=class extends Te{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 kt((r=(e=H.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),d=c?.pageByTocId[e],u=c?.nodeByTocId[e],p=u?.prettyUrl;return{mapId:this.mapId,tocId:e,topicTitle:(i=u?.title)!==null&&i!==void 0?i:"",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,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=H.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 zt.FEEDBACK:return kt(r??[],ie.FEEDBACK_USER);case zt.RATING:return kt(r??[],ie.RATING_USER);case zt.PRINT:return kt(r??[],ie.PRINT_USER);case zt.BOOKMARK:return!!r?.sessionAuthenticated;case zt.COLLECTIONS:return kt(r??[],ie.COLLECTION_USER);case zt.PERSONAL_BOOKS:return kt(r??[],ie.PERSONAL_BOOK_USER)&&!(!((o=this.getMapNow())===null||o===void 0)&&o.pbkConfidential);default:return!1}}makeAbsolute(e){return this.api.makeAbsolute(e)}};var Wa=class t extends Ga{static async build(e){return new t(new Fa,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 Eh="topicPivot";function Va(t,e){let r=new URL(t);return e?.values.forEach(o=>{r.searchParams.append(Eh,o)}),r.href}var ja=class t{static build(e,r){return new t(mu(e.trim()||"context"),r??Wa.build)}loaded(){return Ai(()=>this._loaded)}constructor(e,r,o,a){this.store=e,this.clusteringHelperProvider=o,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new ye(10),this.analyticsEventsService=a??new ha,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 Bo(()=>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=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),(a=this.service)===null||a===void 0?void 0:a.getPagesToc(e).then(d=>this.store.actions.pagesToc(d)).catch(c),(i=this.service)===null||i===void 0?void 0:i.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 wt)&&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(wr.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=H.getState().metadataConfiguration)===null||e===void 0?void 0:e.descriptors)!==null&&r!==void 0?r:[];return new Gt(o,a,this.metadataForSwitchToRelatives,i)}}async navigateToRelativeTopicIfFound(e){var r,o,a;await this.loaded();let i=await Bo(()=>{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,i,[e]);if(!((a=(o=(r=d?.results)===null||r===void 0?void 0:r[0])===null||o===void 0?void 0:o.entries)===null||a===void 0)&&a[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 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(wr.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(e){var r,o,a;this.store.getState().relatives==null&&await this.fetchRelatives();let i=Gt.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",e),s=Go(i);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((a=this.service)===null||a===void 0?void 0:a.getTopicMetadataValue(c,d));s=Va(s,u)}}return s}sendDocumentOnDemandTranslateEvent(e){let{editorMode:r,apiIntegrationIdentifier:o,apiIntegrationAppVersion:a}=H.getState(),i=this.store.getState(),s=i.map,c=i.translation.profileId;if(!(r||!s||!o||!a||!c))try{let d=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:d,translationOrigin:oa.AI})}catch(d){console.warn("Failed to send on-demand document translate event:",d)}}sendTopicAiTranslateEvent(e,r){let{editorMode:o,apiIntegrationIdentifier:a,apiIntegrationAppVersion:i}=H.getState(),s=this.store.getState(),c=s.map,d=s.translation.profileId;if(!(o||!c||!a||!i||!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:a,appVersion:i,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 Ka=class extends CustomEvent{constructor(e,r){super("ft-reader-map-loaded",{detail:{map:e,toc:r}})}},Za=class extends CustomEvent{constructor(e,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},qa=class extends CustomEvent{constructor(e){super("ft-reader-navigation-done",{detail:e})}},Ya=class extends CustomEvent{constructor(e){super("ft-reader-load-error",{detail:e})}},Xa=class extends Event{constructor(){super("ft-reader-map-not-found")}},Qa=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},Ja=class extends Event{constructor(){super("ft-reader-map-forbidden")}},ei=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var Ve=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},Cl=class{constructor(e){this.stateManager=e}searchInDocument(e){this.stateManager.setSearchInDocumentQuery(e??"")}},Le=class extends ct{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new ye(5),this.navigationDebouncer=new ye(10),this.mapLoadedEventDebouncer=new ye(50),this.addStore(H)}render(){return D`
|
|
2256
|
+
`;var Ch={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]}},mu=t=>Pt.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:Ch});var Sl=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 d=(s=a.prettyUrl)===null||s===void 0?void 0:s.replace(/^\//,""),u={tocId:a.tocId,contentId:a.contentId,title:a.title,untranslatedTitle:a.untranslatedTitle,hasRating:a.hasRating,origin:a.origin,prettyUrl:d,depth:r,parentTocId:o,children:[]};this.register(u);let p=this.convertSectionNodes((c=a.pageToc)!==null&&c!==void 0?c:[],r+1,a.tocId),h=this.convertNodes(a.children,r+1,u.tocId);return u.children=[...p,...h],[u]})}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,d;let u={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(g=>this.nodeByTocId[g.tocId]),topics:[],hiddenTopics:[],breadcrumb:r?this.buildBreadcrumb(this.nodeByTocId[r]):[]},p=(g,x)=>(x?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,x)=>{p(g,h[x])}),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}},Fa=class{convertPaginatedToc(e,r){return new Sl(e,r).build()}};var Ga=class extends Te{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 kt((r=(e=H.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),d=c?.pageByTocId[e],u=c?.nodeByTocId[e],p=u?.prettyUrl;return{mapId:this.mapId,tocId:e,topicTitle:(i=u?.title)!==null&&i!==void 0?i:"",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,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=H.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 zt.FEEDBACK:return kt(r??[],ie.FEEDBACK_USER);case zt.RATING:return kt(r??[],ie.RATING_USER);case zt.PRINT:return kt(r??[],ie.PRINT_USER);case zt.BOOKMARK:return!!r?.sessionAuthenticated;case zt.COLLECTIONS:return kt(r??[],ie.COLLECTION_USER);case zt.PERSONAL_BOOKS:return kt(r??[],ie.PERSONAL_BOOK_USER)&&!(!((o=this.getMapNow())===null||o===void 0)&&o.pbkConfidential);default:return!1}}makeAbsolute(e){return this.api.makeAbsolute(e)}};var Wa=class t extends Ga{static async build(e){return new t(new Fa,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 Eh="topicPivot";function Va(t,e){let r=new URL(t);return e?.values.forEach(o=>{r.searchParams.append(Eh,o)}),r.href}var ja=class t{static build(e,r){return new t(mu(e.trim()||"context"),r??Wa.build)}loaded(){return Ai(()=>this._loaded)}constructor(e,r,o,a){this.store=e,this.clusteringHelperProvider=o,this.metadataForSwitchToRelatives=new Set,this._loaded=!1,this.loadDebouncer=new ye(10),this.analyticsEventsService=a??new ha,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 Bo(()=>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=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),(a=this.service)===null||a===void 0?void 0:a.getPagesToc(e).then(d=>this.store.actions.pagesToc(d)).catch(c),(i=this.service)===null||i===void 0?void 0:i.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 wt)&&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(wr.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=H.getState().metadataConfiguration)===null||e===void 0?void 0:e.descriptors)!==null&&r!==void 0?r:[];return new Gt(o,a,this.metadataForSwitchToRelatives,i)}}async navigateToRelativeTopicIfFound(e){var r,o,a;await this.loaded();let i=await Bo(()=>{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,i,[e]);if(!((a=(o=(r=d?.results)===null||r===void 0?void 0:r[0])===null||o===void 0?void 0:o.entries)===null||a===void 0)&&a[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 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(wr.mapAttachmentsUpdate))}async getRelativeDocumentUrlForLocale(e){var r,o,a;this.store.getState().relatives==null&&await this.fetchRelatives();let i=Gt.findResultWithMetadataValue((r=this.store.getState().relatives)!==null&&r!==void 0?r:[],"ft:locale",e),s=Go(i);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((a=this.service)===null||a===void 0?void 0:a.getTopicMetadataValue(c,d));s=Va(s,u)}}return s}sendDocumentOnDemandTranslateEvent(e){let{editorMode:r,apiIntegrationIdentifier:o,apiIntegrationAppVersion:a}=H.getState(),i=this.store.getState(),s=i.map,c=i.translation.profileId;if(!(r||!s||!o||!a||!c))try{let d=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:d,translationOrigin:oa.AI})}catch(d){console.warn("Failed to send on-demand document translate event:",d)}}sendTopicAiTranslateEvent(e,r){let{editorMode:o,apiIntegrationIdentifier:a,apiIntegrationAppVersion:i}=H.getState(),s=this.store.getState(),c=s.map,d=s.translation.profileId;if(!(o||!c||!a||!i||!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:a,appVersion:i,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 Ka=class extends CustomEvent{constructor(e,r){super("ft-reader-map-loaded",{detail:{map:e,toc:r}})}},Za=class extends CustomEvent{constructor(e,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}},qa=class extends CustomEvent{constructor(e){super("ft-reader-navigation-done",{detail:e})}},Ya=class extends CustomEvent{constructor(e){super("ft-reader-load-error",{detail:e})}},Xa=class extends Event{constructor(){super("ft-reader-map-not-found")}},Qa=class extends Event{constructor(){super("ft-reader-map-unauthorized")}},Ja=class extends Event{constructor(){super("ft-reader-map-forbidden")}},ei=class extends Event{constructor(){super("ft-reader-topic-relative-not-found",{bubbles:!0,composed:!0})}};var Ve=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},Cl=class{constructor(e){this.stateManager=e}searchInDocument(e){this.stateManager.setSearchInDocumentQuery(e??"")}},Le=class extends ct{constructor(){super(),this.visibleTopics=[],this.updateConfiguration=()=>{this.stateManager.reloadConfiguration()},this.scrollToTargetDebouncer=new ye(5),this.navigationDebouncer=new ye(10),this.mapLoadedEventDebouncer=new ye(50),this.addStore(H)}render(){return D`
|
|
2257
2257
|
${this.importStyleIfNeeded()}
|
|
2258
2258
|
<slot @register-ft-reader-component=${this.registerComponent}></slot>
|
|
2259
2259
|
`}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:"")?j:D`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-topics/ft-reader-metadata",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.26",
|
|
4
4
|
"description": "Metadata for integrated reader",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lit"
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fluid-topics/ft-chip": "2.0.
|
|
23
|
-
"@fluid-topics/ft-floating-menu": "2.0.
|
|
24
|
-
"@fluid-topics/ft-reader-context": "2.0.
|
|
25
|
-
"@fluid-topics/ft-ripple": "2.0.
|
|
26
|
-
"@fluid-topics/ft-tooltip": "2.0.
|
|
27
|
-
"@fluid-topics/ft-wc-utils": "2.0.
|
|
22
|
+
"@fluid-topics/ft-chip": "2.0.26",
|
|
23
|
+
"@fluid-topics/ft-floating-menu": "2.0.26",
|
|
24
|
+
"@fluid-topics/ft-reader-context": "2.0.26",
|
|
25
|
+
"@fluid-topics/ft-ripple": "2.0.26",
|
|
26
|
+
"@fluid-topics/ft-tooltip": "2.0.26",
|
|
27
|
+
"@fluid-topics/ft-wc-utils": "2.0.26",
|
|
28
28
|
"lit": "3.1.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@fluid-topics/ft-wc-test-utils": "2.0.
|
|
31
|
+
"@fluid-topics/ft-wc-test-utils": "2.0.26"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "4ffd88b4d84ec81428bd1ac1c82423c58428afe9"
|
|
34
34
|
}
|