@fluid-topics/ft-reader-context 1.0.53 → 1.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,46 +1,10 @@
1
1
  import { PropertyValues } from "lit";
2
2
  import { FtLitElementRedux } from "@fluid-topics/ft-wc-utils";
3
3
  import { FtReaderComponentInterface } from "./registration";
4
- import { FtReaderNavigationData, FtReaderPage, FtReaderScrollTarget, FtReaderTocNode } from "./store/model";
4
+ import { FtReaderPage, FtReaderScrollTarget, FtReaderTocNode } from "./store/model";
5
5
  import type { FtMap } from "@fluid-topics/public-api";
6
6
  import { FtReaderContextProperties } from "./ft-reader-context.properties";
7
- type MapLoadedEventDetail = {
8
- map: FtMap;
9
- toc: Array<FtReaderTocNode>;
10
- };
11
- export declare class MapLoadedEvent extends CustomEvent<MapLoadedEventDetail> {
12
- constructor(map: FtMap, toc: Array<FtReaderTocNode>);
13
- }
14
- export interface FtReaderBreadcrumb {
15
- tocId: string;
16
- title: string;
17
- }
18
- export interface FtReaderVisibleTopic {
19
- tocId: string;
20
- title: string;
21
- page?: number;
22
- prettyUrl?: string;
23
- prettyUrlDuplicated: boolean;
24
- breadcrumb?: Array<FtReaderBreadcrumb>;
25
- }
26
- export interface VisibleTopicsChangeData {
27
- visibleTopics: FtReaderVisibleTopic[];
28
- }
29
- export declare class VisibleTopicsChangeEvent extends CustomEvent<VisibleTopicsChangeData> {
30
- constructor(map: FtMap, visibleTopics: FtReaderVisibleTopic[]);
31
- }
32
- export declare class NavigationDoneEvent extends CustomEvent<FtReaderNavigationData> {
33
- constructor(data: FtReaderNavigationData);
34
- }
35
- export declare class LoadErrorEvent extends CustomEvent<Error> {
36
- constructor(e: Error);
37
- }
38
- export declare class NotFoundErrorEvent extends Event {
39
- constructor();
40
- }
41
- export declare class UnauthorizedErrorEvent extends Event {
42
- constructor();
43
- }
7
+ import type { FtReaderService } from "./store/utils/FtReaderService";
44
8
  export declare class FtReaderContext extends FtLitElementRedux implements FtReaderContextProperties {
45
9
  static styles: import("lit").CSSResult;
46
10
  baseUrl?: string;
@@ -53,6 +17,7 @@ export declare class FtReaderContext extends FtLitElementRedux implements FtRead
53
17
  visibleTopics: string[];
54
18
  currentPage?: FtReaderPage;
55
19
  scrollTarget?: FtReaderScrollTarget;
20
+ readerServiceProvider?: () => Promise<FtReaderService>;
56
21
  constructor();
57
22
  protected render(): import("lit-html").TemplateResult<1>;
58
23
  private importStyleIfNeeded;
@@ -62,12 +27,11 @@ export declare class FtReaderContext extends FtLitElementRedux implements FtRead
62
27
  protected updated(props: PropertyValues): void;
63
28
  private scrollToTargetDebouncer;
64
29
  protected contentAvailableCallback(props: PropertyValues): void;
65
- private buildBreadcrumb;
66
30
  reload(): Promise<void>;
67
31
  private navigationDebouncer;
68
32
  navigateToTarget(): void;
69
33
  private registerComponent;
70
34
  register(component: FtReaderComponentInterface): void;
71
35
  private handleLoadError;
36
+ reloadBookmarks(): void;
72
37
  }
73
- export {};
@@ -9,37 +9,8 @@ import { property } from "lit/decorators.js";
9
9
  import { Debouncer, FtLitElementRedux, redux } from "@fluid-topics/ft-wc-utils";
10
10
  import { FtReaderStateManager } from "./store/FtReaderStateManager";
11
11
  import { styles } from "./ft-reader-context.css";
12
- import { ftAppInfoStore } from "@fluid-topics/ft-app-context";
13
- export class MapLoadedEvent extends CustomEvent {
14
- constructor(map, toc) {
15
- super("ft-reader-map-loaded", { detail: { map, toc } });
16
- }
17
- }
18
- export class VisibleTopicsChangeEvent extends CustomEvent {
19
- constructor(map, visibleTopics) {
20
- super("ft-reader-visible-topics-change", { detail: { visibleTopics } });
21
- }
22
- }
23
- export class NavigationDoneEvent extends CustomEvent {
24
- constructor(data) {
25
- super("ft-reader-navigation-done", { detail: data });
26
- }
27
- }
28
- export class LoadErrorEvent extends CustomEvent {
29
- constructor(e) {
30
- super("ft-reader-load-error", { detail: e });
31
- }
32
- }
33
- export class NotFoundErrorEvent extends Event {
34
- constructor() {
35
- super("ft-reader-map-not-found");
36
- }
37
- }
38
- export class UnauthorizedErrorEvent extends Event {
39
- constructor() {
40
- super("ft-reader-map-unauthorized");
41
- }
42
- }
12
+ import { ftAppInfoStore, userAssetsActions } from "@fluid-topics/ft-app-context";
13
+ import { LoadErrorEvent, MapLoadedEvent, NavigationDoneEvent, NotFoundErrorEvent, UnauthorizedErrorEvent, VisibleTopicsChangeEvent } from "./models";
43
14
  const fromNumberAttribute = (defaultValue) => (value) => +(value !== null && value !== void 0 ? value : "NaN") > 0 ? +value : defaultValue;
44
15
  class FtReaderContext extends FtLitElementRedux {
45
16
  constructor() {
@@ -69,7 +40,7 @@ class FtReaderContext extends FtLitElementRedux {
69
40
  }
70
41
  get stateManager() {
71
42
  if (this._stateManager == null) {
72
- this._stateManager = FtReaderStateManager.build(this.id || ("" + Math.round(Math.random() * 999000)).padStart(6, "0"));
43
+ this._stateManager = FtReaderStateManager.build(this.id || ("" + Math.round(Math.random() * 999000)).padStart(6, "0"), this.readerServiceProvider);
73
44
  this._stateManager.errorHandler = (e) => this.handleLoadError(e);
74
45
  this.addStore(this.stateManager.store, "reader");
75
46
  }
@@ -90,6 +61,9 @@ class FtReaderContext extends FtLitElementRedux {
90
61
  }
91
62
  updated(props) {
92
63
  super.updated(props);
64
+ if (props.has("readerServiceProvider") && this.readerServiceProvider) {
65
+ this.stateManager.initService(this.readerServiceProvider);
66
+ }
93
67
  if (props.has("mapId")) {
94
68
  this.stateManager.setMapId(this.mapId);
95
69
  }
@@ -117,29 +91,21 @@ class FtReaderContext extends FtLitElementRedux {
117
91
  Promise.all(this.visibleTopics.map(tocId => { var _a; return this.stateManager.service.getAccurateNavigationData(tocId, (_a = this.currentPage) === null || _a === void 0 ? void 0 : _a.number); }))
118
92
  .then(navigationData => {
119
93
  let visibleTopics = navigationData.filter(data => data != null && data.topicTitle !== "")
120
- .map(data => ({
121
- tocId: data.tocId,
122
- title: data.topicTitle,
123
- page: data.page,
124
- prettyUrl: data.prettyUrl,
125
- prettyUrlDuplicated: data.prettyUrlDuplicated,
126
- breadcrumb: this.buildBreadcrumb(data.tocId)
127
- }));
94
+ .map(data => {
95
+ var _a;
96
+ return ({
97
+ tocId: data.tocId,
98
+ title: data.topicTitle,
99
+ page: data.page,
100
+ prettyUrl: data.prettyUrl,
101
+ prettyUrlDuplicated: data.prettyUrlDuplicated,
102
+ breadcrumb: (_a = this.stateManager.service) === null || _a === void 0 ? void 0 : _a.buildBreadcrumb(data.tocId)
103
+ });
104
+ });
128
105
  this.dispatchEvent(new VisibleTopicsChangeEvent(this.map, visibleTopics));
129
106
  });
130
107
  }
131
108
  }
132
- buildBreadcrumb(tocId) {
133
- var _a, _b, _c, _d;
134
- let breadcrumb = [];
135
- let parentTocIc = (_b = (_a = this.stateManager.service) === null || _a === void 0 ? void 0 : _a.getTocNodeNow(tocId)) === null || _b === void 0 ? void 0 : _b.parentTocId;
136
- let parent = (_c = this.stateManager.service) === null || _c === void 0 ? void 0 : _c.getTocNodeNow(parentTocIc);
137
- while (parent) {
138
- breadcrumb.unshift({ tocId: parent.tocId, title: parent.title });
139
- parent = (_d = this.stateManager.service) === null || _d === void 0 ? void 0 : _d.getTocNodeNow(parent.parentTocId);
140
- }
141
- return breadcrumb;
142
- }
143
109
  async reload() {
144
110
  await this.stateManager.reload();
145
111
  this.navigateToTarget();
@@ -174,6 +140,10 @@ class FtReaderContext extends FtLitElementRedux {
174
140
  this.dispatchEvent(new LoadErrorEvent(e));
175
141
  }
176
142
  }
143
+ // Used in GWT
144
+ reloadBookmarks() {
145
+ userAssetsActions.reloadBookmarks();
146
+ }
177
147
  }
178
148
  // language=CSS
179
149
  FtReaderContext.styles = styles;
@@ -207,4 +177,7 @@ __decorate([
207
177
  __decorate([
208
178
  redux({ store: "reader" })
209
179
  ], FtReaderContext.prototype, "scrollTarget", void 0);
180
+ __decorate([
181
+ property({ attribute: false })
182
+ ], FtReaderContext.prototype, "readerServiceProvider", void 0);
210
183
  export { FtReaderContext };
@@ -1,12 +1,12 @@
1
- !function(t,i,s,e){const n={setMapId:(t,i)=>{t.mapId=i.payload},setTocId:(t,i)=>{t.tocId=i.payload},setMap:(t,i)=>{t.map=i.payload},setToc:(t,i)=>{t.toc=i.payload},setPagesToc:(t,i)=>{t.pagesToc=i.payload},setPaginationConfiguration:(t,i)=>{t.paginationConfiguration=i.payload},setCurrentPage:(t,i)=>{t.currentPage=i.payload},setScrollTarget:(t,i)=>{t.scrollTarget=i.payload},setVisibleTopics:(t,i)=>{t.visibleTopics=i.payload},setConfiguration:(t,i)=>{t.configuration=i.payload}};class o{constructor(t){this.paginatedToc=t,this.nodeByTocId={},this.knownPrettyUrls=new Set,this.duplicatedPrettyUrls=new Set,this.pages=[],this.pageByTocId={}}build(){return{paginationConfiguration:this.paginatedToc.configuration,toc:this.convertNodes(this.paginatedToc.paginatedToc,1),pagesToc:this.extractPagesToc(this.paginatedToc.paginatedToc,1),nodeByTocId:this.nodeByTocId,duplicatedPrettyUrls:this.duplicatedPrettyUrls,pages:this.pages,pageByTocId:this.pageByTocId}}extractPagesToc(t,i,s){return t.flatMap((t=>(t.pageConfiguration&&this.registerPage(this.buildPage(t,s)),null==t.tocId?this.extractPagesToc(t.children,i,s):[{tocId:t.tocId,title:t.title,depth:i,children:this.extractPagesToc(t.children,i+1,t.tocId)}])))}convertNodes(t,i,s){return t.flatMap((t=>{var e,n,o;if(null==t.tocId)return[...this.convertSectionNodes(null!==(e=t.pageToc)&&void 0!==e?e:[],i,t.tocId),...this.convertNodes(t.children,i,t.tocId)];let r=null===(n=t.prettyUrl)||void 0===n?void 0:n.replace(/^\//,"");const a={tocId:t.tocId,contentId:t.contentId,title:t.title,hasRating:t.hasRating,prettyUrl:r,depth:i,parentTocId:s,children:[]};this.register(a);const h=this.convertSectionNodes(null!==(o=t.pageToc)&&void 0!==o?o:[],i+1,t.tocId),l=this.convertNodes(t.children,i+1,a.tocId);return a.children=[...h,...l],[a]}))}convertSectionNodes(t,i,s){return t.flatMap((t=>{var e;let n=null===(e=t.prettyUrl)||void 0===e?void 0:e.replace(/^\//,"");const o={...t,prettyUrl:n,depth:i,parentTocId:s,children:[]};return this.register(o),o.children=this.convertSectionNodes(t.children,i+1,t.tocId),[o]}))}buildPage(t,i){var s,e,n,o,r,a;const h={number:this.pages.length+1,title:null!==(s=t.title)&&void 0!==s?s:"",rootTocId:null!==(e=t.tocId)&&void 0!==e?e:"root",toc:(null!==(n=t.pageToc)&&void 0!==n?n:[]).map((t=>this.nodeByTocId[t.tocId])),topics:[],hiddenTopics:[],breadcrumb:i?this.buildBreadcrumb(this.nodeByTocId[i]):[]},l=(t,i)=>(i?h.topics:h.hiddenTopics).push(t),d=null!==(r=null===(o=t.pageConfiguration)||void 0===o?void 0:o.parentsVisibility)&&void 0!==r?r:[];return h.breadcrumb.forEach(((t,i)=>{l(t,d[i])})),t.tocId&&l(t.tocId,t.pageConfiguration.isVisible),h.topics.push(...this.tocIds(null!==(a=t.pageToc)&&void 0!==a?a:[])),h}registerPage(t){for(let i of[...t.topics,...t.hiddenTopics])this.pageByTocId[i]||(this.pageByTocId[i]=t);this.pages.push(t)}tocIds(t){return t.flatMap((t=>[t.tocId,...this.tocIds(t.children)]))}buildBreadcrumb(t){const i=[t.tocId];for(;null==t?void 0:t.parentTocId;)i.unshift(t.parentTocId),t=this.nodeByTocId[t.parentTocId];return i}register(t){t.prettyUrl&&(this.knownPrettyUrls.has(t.prettyUrl)&&this.duplicatedPrettyUrls.add(t.prettyUrl),this.knownPrettyUrls.add(t.prettyUrl)),this.nodeByTocId[t.tocId]=t}}class r{convertPaginatedToc(t){return new o(t).build()}}const a=s.css`
2
- `,h=i.FtReduxStore.get({name:"ft-app-info",reducers:{setBaseUrl:(t,i)=>{t.baseUrl=i.payload},setApiIntegrationIdentifier:(t,i)=>{t.apiIntegrationIdentifier=i.payload},setUiLocale:(t,i)=>{t.uiLocale=i.payload},setAvailableUiLocales:(t,i)=>{t.availableUiLocales=i.payload},setEditorMode:(t,i)=>{t.editorMode=i.payload},setNoCustom:(t,i)=>{t.noCustom=i.payload},setNoCustomComponent:(t,i)=>{t.noCustomComponent=i.payload},setSession:(t,i)=>{t.session=i.payload}},initialState:{uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],editorMode:!1,noCustom:!1,noCustomComponent:!1}});class l{static build(t){const{baseUrl:i,apiIntegrationIdentifier:s}=h.getState(),e=null!=t?t:s;if(i&&e&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(i,e,!0)}static get(t){var i;return null!=t?l.build(t):null!==(i=l.API)&&void 0!==i?i:l.API=l.build()}static await(t){return new Promise((i=>{let s=l.get(t);if(s)i(s);else{const e=h.subscribe((()=>{s=l.get(t),s&&(e(),i(s))}))}}))}}var d;const c=Symbol("clearAfterUnitTest");class u{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new i.CacheRegistry,this.listeners={},this.currentUiLocale="",this[d]=()=>{this.defaultMessages={},this.cache=new i.CacheRegistry,this.listeners={}},this.currentUiLocale=h.getState().uiLocale,h.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=h.getState();this.currentUiLocale!==t&&(this.currentUiLocale=t,this.cache.clearAll(),this.notifyAll())}addContext(t){const i=t.name.toLowerCase();this.cache.setFinal(i,t),this.notify(i)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(t,s){var e;if(t=t.toLowerCase(),Object.keys(s).length>0){const n={...null!==(e=this.defaultMessages[t])&&void 0!==e?e:{},...s};i.deepEqual(this.defaultMessages[t],n)||(this.defaultMessages[t]=n,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,s,...e){var n,o,r;t=t.toLowerCase(),this.fetchContext(t);const a=null!==(o=null===(n=this.cache.getNow(t))||void 0===n?void 0:n.messages)&&void 0!==o?o:{};return new i.ParametrizedLabelResolver(null!==(r=this.defaultMessages[t])&&void 0!==r?r:{},a).resolve(s,...e)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,i){var s;return t=t.toLowerCase(),this.listeners[t]=null!==(s=this.listeners[t])&&void 0!==s?s:new Set,this.listeners[t].add(i),()=>{var s;return null===(s=this.listeners[t])||void 0===s?void 0:s.delete(i)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>i.delay(0).then((()=>t())).catch((()=>null)))))}}d=c,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new u((async(t,i)=>(await l.await()).getFluidTopicsMessageContext(t,i)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new u((async(t,i)=>(await l.await()).getCustomMessageContext(t,i))));const v=window.FluidTopicsI18nService;var p=function(t,i,s,e){for(var n,o=arguments.length,r=o<3?i:null===e?e=Object.getOwnPropertyDescriptor(i,s):e,a=t.length-1;a>=0;a--)(n=t[a])&&(r=(o<3?n(r):o>3?n(i,s,r):n(i,s))||r);return o>3&&r&&Object.defineProperty(i,s,r),r};class g extends i.FtLitElement{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.availableUiLocales=[],this.editorMode=!1,this.noCustom=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>l.get(),this.cache=new i.CacheRegistry,this.cleanSessionDebouncer=new i.Debouncer}render(){return s.html`
1
+ !function(t,i,e,s){const n={setMapId:(t,i)=>{t.mapId=i.payload},setTocId:(t,i)=>{t.tocId=i.payload},setMap:(t,i)=>{t.map=i.payload},setToc:(t,i)=>{t.toc=i.payload},setPagesToc:(t,i)=>{t.pagesToc=i.payload},setPaginationConfiguration:(t,i)=>{t.paginationConfiguration=i.payload},setCurrentPage:(t,i)=>{t.currentPage=i.payload},setScrollTarget:(t,i)=>{t.scrollTarget=i.payload},setVisibleTopics:(t,i)=>{t.visibleTopics=i.payload},setConfiguration:(t,i)=>{t.configuration=i.payload}};class r{constructor(t){this.paginatedToc=t,this.nodeByTocId={},this.knownPrettyUrls=new Set,this.duplicatedPrettyUrls=new Set,this.pages=[],this.pageByTocId={}}build(){return{paginationConfiguration:this.paginatedToc.configuration,toc:this.convertNodes(this.paginatedToc.paginatedToc,1),pagesToc:this.extractPagesToc(this.paginatedToc.paginatedToc,1),nodeByTocId:this.nodeByTocId,duplicatedPrettyUrls:this.duplicatedPrettyUrls,pages:this.pages,pageByTocId:this.pageByTocId}}extractPagesToc(t,i,e){return t.flatMap((t=>(t.pageConfiguration&&this.registerPage(this.buildPage(t,e)),null==t.tocId?this.extractPagesToc(t.children,i,e):[{tocId:t.tocId,title:t.title,depth:i,children:this.extractPagesToc(t.children,i+1,t.tocId)}])))}convertNodes(t,i,e){return t.flatMap((t=>{var s,n,r;if(null==t.tocId)return[...this.convertSectionNodes(null!==(s=t.pageToc)&&void 0!==s?s:[],i,t.tocId),...this.convertNodes(t.children,i,t.tocId)];let o=null===(n=t.prettyUrl)||void 0===n?void 0:n.replace(/^\//,"");const a={tocId:t.tocId,contentId:t.contentId,title:t.title,hasRating:t.hasRating,origin:t.origin,prettyUrl:o,depth:i,parentTocId:e,children:[]};this.register(a);const h=this.convertSectionNodes(null!==(r=t.pageToc)&&void 0!==r?r:[],i+1,t.tocId),u=this.convertNodes(t.children,i+1,a.tocId);return a.children=[...h,...u],[a]}))}convertSectionNodes(t,i,e){return t.flatMap((t=>{var s;let n=null===(s=t.prettyUrl)||void 0===s?void 0:s.replace(/^\//,"");const r={...t,prettyUrl:n,depth:i,parentTocId:e,children:[]};return this.register(r),r.children=this.convertSectionNodes(t.children,i+1,t.tocId),[r]}))}buildPage(t,i){var e,s,n,r,o,a;const h={number:this.pages.length+1,title:null!==(e=t.title)&&void 0!==e?e:"",rootTocId:null!==(s=t.tocId)&&void 0!==s?s:"root",toc:(null!==(n=t.pageToc)&&void 0!==n?n:[]).map((t=>this.nodeByTocId[t.tocId])),topics:[],hiddenTopics:[],breadcrumb:i?this.buildBreadcrumb(this.nodeByTocId[i]):[]},u=(t,i)=>(i?h.topics:h.hiddenTopics).push(t),c=null!==(o=null===(r=t.pageConfiguration)||void 0===r?void 0:r.parentsVisibility)&&void 0!==o?o:[];return h.breadcrumb.forEach(((t,i)=>{u(t,c[i])})),t.tocId&&u(t.tocId,t.pageConfiguration.isVisible),h.topics.push(...this.tocIds(null!==(a=t.pageToc)&&void 0!==a?a:[])),h}registerPage(t){for(let i of[...t.topics,...t.hiddenTopics])this.pageByTocId[i]||(this.pageByTocId[i]=t);this.pages.push(t)}tocIds(t){return t.flatMap((t=>[t.tocId,...this.tocIds(t.children)]))}buildBreadcrumb(t){const i=[t.tocId];for(;null==t?void 0:t.parentTocId;)i.unshift(t.parentTocId),t=this.nodeByTocId[t.parentTocId];return i}register(t){t.prettyUrl&&(this.knownPrettyUrls.has(t.prettyUrl)&&this.duplicatedPrettyUrls.add(t.prettyUrl),this.knownPrettyUrls.add(t.prettyUrl)),this.nodeByTocId[t.tocId]=t}}class o{convertPaginatedToc(t){return new r(t).build()}}!function(t){!function(i){var e={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(e.arrayBuffer)var s=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=ArrayBuffer.isView||function(t){return t&&s.indexOf(Object.prototype.toString.call(t))>-1};function r(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function o(t){return"string"!=typeof t&&(t=String(t)),t}function a(t){var i={next:function(){var i=t.shift();return{done:void 0===i,value:i}}};return e.iterable&&(i[Symbol.iterator]=function(){return i}),i}function h(t){this.map={},t instanceof h?t.forEach((function(t,i){this.append(i,t)}),this):Array.isArray(t)?t.forEach((function(t){this.append(t[0],t[1])}),this):t&&Object.getOwnPropertyNames(t).forEach((function(i){this.append(i,t[i])}),this)}function u(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function c(t){return new Promise((function(i,e){t.onload=function(){i(t.result)},t.onerror=function(){e(t.error)}}))}function l(t){var i=new FileReader,e=c(i);return i.readAsArrayBuffer(t),e}function d(t){if(t.slice)return t.slice(0);var i=new Uint8Array(t.byteLength);return i.set(new Uint8Array(t)),i.buffer}function v(){return this.bodyUsed=!1,this._initBody=function(t){var i;this._bodyInit=t,t?"string"==typeof t?this._bodyText=t:e.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:e.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():e.arrayBuffer&&e.blob&&((i=t)&&DataView.prototype.isPrototypeOf(i))?(this._bodyArrayBuffer=d(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):e.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||n(t))?this._bodyArrayBuffer=d(t):this._bodyText=t=Object.prototype.toString.call(t):this._bodyText="",this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e.blob&&(this.blob=function(){var t=u(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?u(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(l)}),this.text=function(){var t,i,e,s=u(this);if(s)return s;if(this._bodyBlob)return t=this._bodyBlob,i=new FileReader,e=c(i),i.readAsText(t),e;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var i=new Uint8Array(t),e=new Array(i.length),s=0;s<i.length;s++)e[s]=String.fromCharCode(i[s]);return e.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},e.formData&&(this.formData=function(){return this.text().then(w)}),this.json=function(){return this.text().then(JSON.parse)},this}h.prototype.append=function(t,i){t=r(t),i=o(i);var e=this.map[t];this.map[t]=e?e+", "+i:i},h.prototype.delete=function(t){delete this.map[r(t)]},h.prototype.get=function(t){return t=r(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(r(t))},h.prototype.set=function(t,i){this.map[r(t)]=o(i)},h.prototype.forEach=function(t,i){for(var e in this.map)this.map.hasOwnProperty(e)&&t.call(i,this.map[e],e,this)},h.prototype.keys=function(){var t=[];return this.forEach((function(i,e){t.push(e)})),a(t)},h.prototype.values=function(){var t=[];return this.forEach((function(i){t.push(i)})),a(t)},h.prototype.entries=function(){var t=[];return this.forEach((function(i,e){t.push([e,i])})),a(t)},e.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var f=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];function p(t,i){var e,s,n=(i=i||{}).body;if(t instanceof p){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,i.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,n||null==t._bodyInit||(n=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=i.credentials||this.credentials||"same-origin",!i.headers&&this.headers||(this.headers=new h(i.headers)),this.method=(e=i.method||this.method||"GET",s=e.toUpperCase(),f.indexOf(s)>-1?s:e),this.mode=i.mode||this.mode||null,this.signal=i.signal||this.signal,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&n)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(n)}function w(t){var i=new FormData;return t.trim().split("&").forEach((function(t){if(t){var e=t.split("="),s=e.shift().replace(/\+/g," "),n=e.join("=").replace(/\+/g," ");i.append(decodeURIComponent(s),decodeURIComponent(n))}})),i}function E(t,i){i||(i={}),this.type="default",this.status=void 0===i.status?200:i.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in i?i.statusText:"OK",this.headers=new h(i.headers),this.url=i.url||"",this._initBody(t)}p.prototype.clone=function(){return new p(this,{body:this._bodyInit})},v.call(p.prototype),v.call(E.prototype),E.prototype.clone=function(){return new E(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},E.error=function(){var t=new E(null,{status:0,statusText:""});return t.type="error",t};var y=[301,302,303,307,308];E.redirect=function(t,i){if(-1===y.indexOf(i))throw new RangeError("Invalid status code");return new E(null,{status:i,headers:{location:t}})},i.DOMException=t.DOMException;try{new i.DOMException}catch(t){i.DOMException=function(t,i){this.message=t,this.name=i;var e=Error(t);this.stack=e.stack},i.DOMException.prototype=Object.create(Error.prototype),i.DOMException.prototype.constructor=i.DOMException}function T(t,s){return new Promise((function(n,r){var o=new p(t,s);if(o.signal&&o.signal.aborted)return r(new i.DOMException("Aborted","AbortError"));var a=new XMLHttpRequest;function u(){a.abort()}a.onload=function(){var t,i,e={status:a.status,statusText:a.statusText,headers:(t=a.getAllResponseHeaders()||"",i=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach((function(t){var e=t.split(":"),s=e.shift().trim();if(s){var n=e.join(":").trim();i.append(s,n)}})),i)};e.url="responseURL"in a?a.responseURL:e.headers.get("X-Request-URL");var s="response"in a?a.response:a.responseText;n(new E(s,e))},a.onerror=function(){r(new TypeError("Network request failed"))},a.ontimeout=function(){r(new TypeError("Network request failed"))},a.onabort=function(){r(new i.DOMException("Aborted","AbortError"))},a.open(o.method,o.url,!0),"include"===o.credentials?a.withCredentials=!0:"omit"===o.credentials&&(a.withCredentials=!1),"responseType"in a&&e.blob&&(a.responseType="blob"),o.headers.forEach((function(t,i){a.setRequestHeader(i,t)})),o.signal&&(o.signal.addEventListener("abort",u),a.onreadystatechange=function(){4===a.readyState&&o.signal.removeEventListener("abort",u)}),a.send(void 0===o._bodyInit?null:o._bodyInit)}))}T.polyfill=!0,t.fetch||(t.fetch=T,t.Headers=h,t.Request=p,t.Response=E),i.Headers=h,i.Request=p,i.Response=E,i.fetch=T,Object.defineProperty(i,"t",{value:!0})}({})}("undefined"!=typeof self?self:void 0);const a=t=>"object"==typeof t&&null!=t,h=t=>"string"==typeof t;var u,c,l,d,v,f,p,w,E,y,T,m;!function(t){t.black="black",t.green="green",t.blue="blue",t.purple="purple",t.red="red",t.orange="orange",t.yellow="yellow"}(u||(u={})),function(t){t.OFFICIAL="OFFICIAL",t.PERSONAL="PERSONAL",t.SHARED="SHARED"}(c||(c={})),function(t){t.THIRD_PARTY="THIRD_PARTY",t.OFF_THE_GRID="OFF_THE_GRID",t.CONTENT_PACKAGER="CONTENT_PACKAGER",t.PAGES="PAGES",t.DESIGNED_READER="DESIGNED_READER"}(l||(l={})),function(t){t.STARS="STARS",t.LIKE="LIKE",t.DICHOTOMOUS="DICHOTOMOUS",t.NO_RATING="NO_RATING"}(d||(d={})),function(t){t.LAST_WEEK="LAST_WEEK",t.LAST_MONTH="LAST_MONTH",t.LAST_YEAR="LAST_YEAR",t.CUSTOM="CUSTOM"}(v||(v={})),function(t){t.ASC="ASC",t.DESC="DESC"}(f||(f={})),function(t){t.ALPHA="ALPHA",t.NATURAL="NATURAL"}(p||(p={})),function(t){t.ARTICLE="ARTICLE",t.BOOK="BOOK"}(w||(w={})),function(t){t.FLUIDTOPICS="FLUIDTOPICS",t.EXTERNAL="EXTERNAL"}(E||(E={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC",t.PERSONAL_BOOK="PERSONAL_BOOK",t.SHARED_BOOK="SHARED_BOOK"}(y||(y={})),function(t){t.MAP="MAP",t.DOCUMENT="DOCUMENT",t.TOPIC="TOPIC"}(T||(T={})),function(t){t.PERSONAL_BOOK_USER="PERSONAL_BOOK_USER",t.PERSONAL_BOOK_SHARE_USER="PERSONAL_BOOK_SHARE_USER",t.HTML_EXPORT_USER="HTML_EXPORT_USER",t.PDF_EXPORT_USER="PDF_EXPORT_USER",t.SAVED_SEARCH_USER="SAVED_SEARCH_USER",t.COLLECTION_USER="COLLECTION_USER",t.OFFLINE_USER="OFFLINE_USER",t.ANALYTICS_USER="ANALYTICS_USER",t.BETA_USER="BETA_USER",t.DEBUG_USER="DEBUG_USER",t.PRINT_USER="PRINT_USER",t.RATING_USER="RATING_USER",t.FEEDBACK_USER="FEEDBACK_USER",t.CONTENT_PUBLISHER="CONTENT_PUBLISHER",t.KHUB_ADMIN="KHUB_ADMIN",t.USERS_ADMIN="USERS_ADMIN",t.PORTAL_ADMIN="PORTAL_ADMIN",t.ADMIN="ADMIN",t.DEVELOPER="DEVELOPER"}(m||(m={}));const g=t=>a(t)&&(null==t.authenticationIdentifier||(t=>a(t)&&h(t.identifier)&&h(t.realm))(t.authenticationIdentifier))&&(t=>"number"==typeof t)(t.idleTimeoutInMillis)&&S(t.profile)&&(t=>"boolean"==typeof t)(t.sessionAuthenticated),S=t=>a(t)&&(null==t.emailAddress||h(t.emailAddress))&&(null==t.displayName||h(t.displayName))&&Array.isArray(t.roles)&&t.roles.every((t=>(t=>["PERSONAL_BOOK_USER","PERSONAL_BOOK_SHARE_USER","HTML_EXPORT_USER","PDF_EXPORT_USER","SAVED_SEARCH_USER","COLLECTION_USER","OFFLINE_USER","ANALYTICS_USER","BETA_USER","DEBUG_USER","PRINT_USER","RATING_USER","FEEDBACK_USER","CONTENT_PUBLISHER","KHUB_ADMIN","USERS_ADMIN","PORTAL_ADMIN","ADMIN","DEVELOPER"].includes(t))(t)))&&(null==t.userId||h(t.userId)),R={[m.PERSONAL_BOOK_SHARE_USER]:[m.PERSONAL_BOOK_USER],[m.HTML_EXPORT_USER]:[m.PERSONAL_BOOK_USER],[m.PDF_EXPORT_USER]:[m.PERSONAL_BOOK_USER],[m.KHUB_ADMIN]:[m.CONTENT_PUBLISHER],[m.ADMIN]:[m.KHUB_ADMIN,m.USERS_ADMIN,m.PORTAL_ADMIN],[m.DEVELOPER]:[m.BETA_USER,m.DEBUG_USER]};function b(t,i){return t===i||(R[t]??[]).some((t=>b(t,i)))}function A(t,i){return(g(t)?t.profile.roles:S(t)?t.roles:t).some((t=>b(t,i)))}const I=e.css`
2
+ `,U=i.FtReduxStore.get({name:"ft-app-info",reducers:{setBaseUrl:(t,i)=>{t.baseUrl=i.payload},setApiIntegrationIdentifier:(t,i)=>{t.apiIntegrationIdentifier=i.payload},setUiLocale:(t,i)=>{t.uiLocale=i.payload},setAvailableUiLocales:(t,i)=>{t.availableUiLocales=i.payload},setEditorMode:(t,i)=>{t.editorMode=i.payload},setNoCustom:(t,i)=>{t.noCustom=i.payload},setNoCustomComponent:(t,i)=>{t.noCustomComponent=i.payload},setSession:(t,i)=>{t.session=i.payload}},initialState:{uiLocale:document.documentElement.lang||"en-US",availableUiLocales:[],editorMode:!1,noCustom:!1,noCustomComponent:!1}});class O{static build(t){const{baseUrl:i,apiIntegrationIdentifier:e}=U.getState(),s=null!=t?t:e;if(i&&s&&window.fluidtopics)return new window.fluidtopics.FluidTopicsApi(i,s,!0)}static get(t){var i;return null!=t?O.build(t):null!==(i=O.API)&&void 0!==i?i:O.API=O.build()}static await(t){return new Promise((i=>{let e=O.get(t);if(e)i(e);else{const s=U.subscribe((()=>{e=O.get(t),e&&(s(),i(e))}))}}))}}var P;const C=Symbol("clearAfterUnitTest");class N{constructor(t){this.messageContextProvider=t,this.defaultMessages={},this.cache=new i.CacheRegistry,this.listeners={},this.currentUiLocale="",this[P]=()=>{this.defaultMessages={},this.cache=new i.CacheRegistry,this.listeners={}},this.currentUiLocale=U.getState().uiLocale,U.subscribe((()=>this.clearWhenUiLocaleChanges()))}clearWhenUiLocaleChanges(){const{uiLocale:t}=U.getState();this.currentUiLocale!==t&&(this.currentUiLocale=t,this.cache.clearAll(),this.notifyAll())}addContext(t){const i=t.name.toLowerCase();this.cache.setFinal(i,t),this.notify(i)}getAllContexts(){return this.cache.resolvedValues()}async prepareContext(t,e){var s;if(t=t.toLowerCase(),Object.keys(e).length>0){const n={...null!==(s=this.defaultMessages[t])&&void 0!==s?s:{},...e};i.deepEqual(this.defaultMessages[t],n)||(this.defaultMessages[t]=n,await this.notify(t))}await this.fetchContext(t)}resolveMessage(t,e,...s){var n,r,o;t=t.toLowerCase(),this.fetchContext(t);const a=null!==(r=null===(n=this.cache.getNow(t))||void 0===n?void 0:n.messages)&&void 0!==r?r:{};return new i.ParametrizedLabelResolver(null!==(o=this.defaultMessages[t])&&void 0!==o?o:{},a).resolve(e,...s)}async fetchContext(t){if(!this.cache.has(t))try{await this.cache.get(t,(()=>this.messageContextProvider(this.currentUiLocale,t))),await this.notify(t)}catch(t){console.error(t)}}subscribe(t,i){var e;return t=t.toLowerCase(),this.listeners[t]=null!==(e=this.listeners[t])&&void 0!==e?e:new Set,this.listeners[t].add(i),()=>{var e;return null===(e=this.listeners[t])||void 0===e?void 0:e.delete(i)}}async notifyAll(){await Promise.all(Object.keys(this.listeners).map((t=>this.notify(t))))}async notify(t){null!=this.listeners[t]&&await Promise.all([...this.listeners[t].values()].map((t=>i.delay(0).then((()=>t())).catch((()=>null)))))}}P=C,null==window.FluidTopicsI18nService&&(window.FluidTopicsI18nService=new N((async(t,i)=>(await O.await()).getFluidTopicsMessageContext(t,i)))),null==window.FluidTopicsCustomI18nService&&(window.FluidTopicsCustomI18nService=new N((async(t,i)=>(await O.await()).getCustomMessageContext(t,i))));const _=window.FluidTopicsI18nService;var L=function(t,i,e,s){for(var n,r=arguments.length,o=r<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(i,e,o):n(i,e))||o);return r>3&&o&&Object.defineProperty(i,e,o),o};class D extends i.FtLitElement{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-integration",this.uiLocale="en-US",this.availableUiLocales=[],this.editorMode=!1,this.noCustom=!1,this.noCustomComponent=!1,this.withManualResources=!1,this.messageContexts=[],this.apiProvider=()=>O.get(),this.cache=new i.CacheRegistry,this.cleanSessionDebouncer=new i.Debouncer}render(){return e.html`
3
3
  <slot></slot>
4
- `}updated(t){super.updated(t),t.has("baseUrl")&&h.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&h.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&h.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&h.actions.setNoCustom(this.noCustom),t.has("editorMode")&&h.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&h.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&h.actions.setSession(this.session),t.has("availableUiLocales")&&h.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>v.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const i=await t.getCurrentSession();return i.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),i.idleTimeoutInMillis),i}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}g.elementDefinitions={},g.styles=a,p([e.property()],g.prototype,"baseUrl",void 0),p([e.property()],g.prototype,"apiIntegrationIdentifier",void 0),p([e.property()],g.prototype,"uiLocale",void 0),p([i.jsonProperty([])],g.prototype,"availableUiLocales",void 0),p([e.property({type:Boolean})],g.prototype,"editorMode",void 0),p([e.property({type:Boolean})],g.prototype,"noCustom",void 0),p([e.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],g.prototype,"noCustomComponent",void 0),p([e.property({type:Boolean})],g.prototype,"withManualResources",void 0),p([i.jsonProperty([])],g.prototype,"messageContexts",void 0),p([i.jsonProperty(void 0)],g.prototype,"session",void 0),p([e.property({type:Object})],g.prototype,"apiProvider",void 0),i.customElement("ft-app-context")(g);class w{static async build(t){return new w(new r,await l.await(),new i.CacheRegistry,t)}get mapId(){return this._mapId}set mapId(t){t!==this._mapId&&this.clear(),this._mapId=t}constructor(t,i,s,e){this.converter=t,this.api=i,this.cache=s,this._mapId=e,this.initCache()}async withMapId(t){return this._mapId?t(this._mapId):void 0}initCache(){this.cache.registerFinal("configuration",(()=>this.api.getReaderConfiguration())),this.cache.register("map",(()=>this.withMapId((t=>this.api.getMap(t))))),this.cache.register("enrichedToc",(()=>this.withMapId((t=>this.api.getPages(t).then((t=>this.converter.convertPaginatedToc(t))))))),this.cache.register("ratingSummary",(()=>{var t;return(null===(t=h.getState().session)||void 0===t?void 0:t.profile.roles.includes("RATING_USER"))?this.withMapId((t=>this.api.getMapRating(t))):Promise.resolve()}))}clear(){this.cache.clearAll()}getMap(){return this.cache.get("map")}getConfiguration(){return this.cache.get("configuration")}getEnrichedToc(){return this.cache.get("enrichedToc")}get enrichedToc(){return this.cache.getNow("enrichedToc")}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(){return(await this.getEnrichedToc()).toc}async getPagesToc(){return(await this.getEnrichedToc()).pagesToc}async getTocNode(t){return(await this.getEnrichedToc()).nodeByTocId[t]}getTocNodeNow(t){var i;return null===(i=this.enrichedToc)||void 0===i?void 0:i.nodeByTocId[t]}async getPage(t){const i=await this.getEnrichedToc();return i.pages[t-1]||i.pages[0]}async getPageByTocId(t){const i=await this.getEnrichedToc();return i.pageByTocId[t]||i.pages[0]}getTopicInfo(t){return this.cache.get("topic-"+t,(()=>this.api.getTopic(this.mapId,t)))}getTopicContent(t){return this.cache.get("topic-content-"+t,(()=>this.api.getTopicHTMLContent(this.mapId,t,"DESIGNED_READER")))}getLink(t,i,s){const e=this.getNavigationData(t,i,s),n="r/"+(e.prettyUrl?e.prettyUrl:`${e.mapId}/${e.tocId}`),o=new URL(n,this.api.tenantBaseUrl);return null!=e.page&&o.searchParams.set("page",`${e.page}`),e.prettyUrlDuplicated&&o.searchParams.set("tocId",e.tocId),null!=e.section&&o.searchParams.set("section",e.section),o.href}getNavigationData(t,i,s){var e,n;t=t||"root";const o=this.enrichedToc,r=null==o?void 0:o.pageByTocId[t],a=null==o?void 0:o.nodeByTocId[t],h=null==a?void 0:a.prettyUrl;return{mapId:this.mapId,tocId:t,topicTitle:null!==(e=null==a?void 0:a.title)&&void 0!==e?e:"",page:i&&r&&r.number!==i?i:void 0,prettyUrl:null!=h?h.replace(/^r\//,""):void 0,prettyUrlDuplicated:null!==(n=null==o?void 0:o.duplicatedPrettyUrls.has(null!=h?h:""))&&void 0!==n&&n,section:s}}async getAccurateNavigationData(t,i,s){return await this.getEnrichedToc(),this.getNavigationData(t,i,s)}getRatingSummary(){return this.cache.get("ratingSummary")}getMapRating(){return this.getRatingSummary().then((t=>null==t?void 0:t.publication))}getTopicRating(t){return this.getRatingSummary().then((i=>{var s;return i?{type:i.topics.type,rating:null===(s=i.topics)||void 0===s?void 0:s.ratings.find((i=>i.tocId===t))}:void 0}))}rateMap(t,i){return this.api.rateMap(this.mapId,t,i).then((()=>this.clearRatingIfNecessary()))}unrateMap(){return this.api.unrateMap(this.mapId).then((()=>this.clearRatingIfNecessary()))}sendMapFeedback(t,i){return this.api.sendMapFeedback(this.mapId,t,i)}rateTopic(t,i,s){return this.api.rateTopic(this.mapId,t,i,s).then((()=>this.clearRatingIfNecessary()))}unrateTopic(t){return this.api.unrateTopic(this.mapId,t).then((()=>this.clearRatingIfNecessary()))}async clearRatingIfNecessary(){const t=h.getState().session;(null==t?void 0:t.sessionAuthenticated)&&this.cache.clear("ratingSummary")}sendTopicFeedback(t,i,s){return this.api.sendTopicFeedback(this.mapId,t,i,s)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}}class m{static build(t){return new m((t=>i.FtReduxStore.get({name:"ft-reader-"+t,initialState:{mapId:void 0,visibleTopics:[]},reducers:n}))(t.trim()||"context"),w.build)}constructor(t,s){this.store=t,this.reloadDebouncer=new i.Debouncer(10),this.initService(s)}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.setMapId(t),this.service&&(this.service.mapId=t),await this.reload())}setVisibleTopics(t){this.store.actions.setVisibleTopics(t)}async awaitService(){for(;null==this.service;)await i.delay(5);return this.service}async navigateToTopic(t,i,s){const e=await this.awaitService(),n=await(null!=s?e.getPage(s):e.getPageByTocId(null!=t?t:"root"));this.store.actions.setCurrentPage(n),this.store.actions.setScrollTarget({tocId:this.resolveValidNonRootTocId(t,n),section:i})}resolveValidNonRootTocId(t,i){var s,e,n;let o=null!==(s="root"===t?void 0:t)&&void 0!==s?s:i.rootTocId;return i.topics.includes(o)?o:null!==(n=null!==(e=i.topics[0])&&void 0!==e?e:i.hiddenTopics[0])&&void 0!==n?n:"root"}async navigateToPage(t){const i=await this.awaitService();let s=await i.getPage(t);this.store.actions.setCurrentPage(s)}scrollDone(){this.store.actions.setScrollTarget({})}async reload(){var t,i;this.store.actions.setConfiguration(void 0),this.store.actions.setMap(void 0),this.store.actions.setToc(void 0),this.store.actions.setPagesToc(void 0),this.store.actions.setCurrentPage(void 0),null===(t=this.service)||void 0===t||t.clear(),(null===(i=this.service)||void 0===i?void 0:i.mapId)&&await this.reloadDebouncer.run((()=>this.fetchData()))}async fetchData(){var t,s,e,n,o;try{await Promise.all([null===(t=this.service)||void 0===t?void 0:t.getConfiguration().then((t=>this.store.actions.setConfiguration(t))),null===(s=this.service)||void 0===s?void 0:s.getMap().then((t=>this.store.actions.setMap(t))),null===(e=this.service)||void 0===e?void 0:e.getToc().then((t=>this.store.actions.setToc(t))),null===(n=this.service)||void 0===n?void 0:n.getPagesToc().then((t=>this.store.actions.setPagesToc(t))),null===(o=this.service)||void 0===o?void 0:o.getPaginationConfiguration().then((t=>this.store.actions.setPaginationConfiguration(t)))])}catch(t){!this.errorHandler||t instanceof i.CanceledPromiseError||this.errorHandler(t)}}}const f=s.css`
5
- `;var y=function(t,i,s,e){for(var n,o=arguments.length,r=o<3?i:null===e?e=Object.getOwnPropertyDescriptor(i,s):e,a=t.length-1;a>=0;a--)(n=t[a])&&(r=(o<3?n(r):o>3?n(i,s,r):n(i,s))||r);return o>3&&r&&Object.defineProperty(i,s,r),r};class b extends CustomEvent{constructor(t,i){super("ft-reader-map-loaded",{detail:{map:t,toc:i}})}}class T extends CustomEvent{constructor(t,i){super("ft-reader-visible-topics-change",{detail:{visibleTopics:i}})}}class I extends CustomEvent{constructor(t){super("ft-reader-navigation-done",{detail:t})}}class C extends CustomEvent{constructor(t){super("ft-reader-load-error",{detail:t})}}class U extends Event{constructor(){super("ft-reader-map-not-found")}}class S extends Event{constructor(){super("ft-reader-map-unauthorized")}}class P extends i.FtLitElementRedux{constructor(){super(),this.visibleTopics=[],this.scrollToTargetDebouncer=new i.Debouncer(5),this.navigationDebouncer=new i.Debouncer(50),this.addStore(h)}render(){return s.html`
4
+ `}updated(t){super.updated(t),t.has("baseUrl")&&U.actions.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&U.actions.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("uiLocale")&&U.actions.setUiLocale(this.uiLocale),t.has("noCustom")&&U.actions.setNoCustom(this.noCustom),t.has("editorMode")&&U.actions.setEditorMode(this.editorMode),t.has("noCustomComponent")&&U.actions.setNoCustomComponent(this.noCustomComponent),t.has("session")&&U.actions.setSession(this.session),t.has("availableUiLocales")&&U.actions.setAvailableUiLocales(Array.isArray(this.availableUiLocales)?this.availableUiLocales:[]),t.has("messageContexts")&&null!=this.messageContexts&&this.messageContexts.forEach((t=>_.addContext(t))),setTimeout((()=>this.updateIfNeeded()))}async updateIfNeeded(){const t=this.apiProvider();!this.withManualResources&&t&&(null==this.session&&(this.session=await this.cache.get("session",(async()=>{const i=await t.getCurrentSession();return i.idleTimeoutInMillis>0&&this.cleanSessionDebouncer.run((()=>{this.cache.clear("session"),this.session=void 0}),i.idleTimeoutInMillis),i}))),null==this.availableUiLocales&&(this.availableUiLocales=await this.cache.get("availableUiLocales",(()=>t.getAvailableUiLocales()))))}}D.elementDefinitions={},D.styles=I,L([s.property()],D.prototype,"baseUrl",void 0),L([s.property()],D.prototype,"apiIntegrationIdentifier",void 0),L([s.property()],D.prototype,"uiLocale",void 0),L([i.jsonProperty([])],D.prototype,"availableUiLocales",void 0),L([s.property({type:Boolean})],D.prototype,"editorMode",void 0),L([s.property({type:Boolean})],D.prototype,"noCustom",void 0),L([s.property({converter:{fromAttribute:t=>"false"!==t&&("true"===t||null!=t&&t)}})],D.prototype,"noCustomComponent",void 0),L([s.property({type:Boolean})],D.prototype,"withManualResources",void 0),L([i.jsonProperty([])],D.prototype,"messageContexts",void 0),L([i.jsonProperty(void 0)],D.prototype,"session",void 0),L([s.property({type:Object})],D.prototype,"apiProvider",void 0);class M{async listMySearches(){var t;return(null===(t=U.getState().session)||void 0===t?void 0:t.sessionAuthenticated)?(await O.await()).listMySearches(U.getState().session.profile.userId):[]}}const B=new i.CacheRegistry;class k{async listMyBookmarks(){return B.get("bookmarks",(async()=>(await O.await()).listMyBookmarks(U.getState().session.profile.userId)))}clearCache(){B.clear("bookmarks")}}const F=i.FtReduxStore.get({name:"ft-user-assets",initialState:{savedSearches:void 0,bookmarks:void 0}});const x=new class{constructor(){this.currentSession=U.getState().session,this.bookmarksAreUsed=!1,this.bookmarksService=new k,U.subscribe((()=>this.reloadWhenUserSessionChanges()))}reloadWhenUserSessionChanges(){var t;const{session:e}=U.getState();i.deepEqual(null===(t=this.currentSession)||void 0===t?void 0:t.profile,null==e?void 0:e.profile)||(this.currentSession=e,this.clearMySearches(),this.reloadBookmarks())}clear(){this.clearMySearches(),this.clearMyBookmarks()}clearMySearches(){F.actions.savedSearches(void 0)}clearMyBookmarks(){F.actions.bookmarks(void 0)}async reloadMySearches(){const t=new M,i=await t.listMySearches();F.actions.savedSearches(i)}async reloadBookmarks(){this.bookmarksService.clearCache(),await this.updateBookmarksIfUsed()}async registerBookmarkComponent(){this.bookmarksAreUsed=!0,await this.updateBookmarksIfUsed()}async updateBookmarksIfUsed(){var t;if(this.bookmarksAreUsed){const i=(null===(t=this.currentSession)||void 0===t?void 0:t.sessionAuthenticated)?await this.bookmarksService.listMyBookmarks():void 0;F.actions.bookmarks(i)}}};var j;i.customElement("ft-app-context")(D),t.FtReaderFeatures=void 0,(j=t.FtReaderFeatures||(t.FtReaderFeatures={})).FEEDBACK="FEEDBACK",j.RATING="RATING",j.PRINT="PRINT",j.BOOKMARK="BOOKMARK",j.COLLECTIONS="COLLECTIONS";class H{get mapId(){return this._mapId}set mapId(t){t!==this._mapId&&this.clear(),this._mapId=t}constructor(t,i,e,s){this.converter=t,this.api=i,this.cache=e,this._mapId=s,this.initCache()}async withMapId(t){return this._mapId?t(this._mapId):void 0}initCache(){this.cache.registerFinal("configuration",(()=>this.api.getReaderConfiguration())),this.cache.register("map",(()=>this.withMapId((t=>this.fetchMap(t))))),this.cache.register("enrichedToc",(()=>this.withMapId((t=>this.fetchPages(t).then((t=>this.converter.convertPaginatedToc(t))))))),this.cache.register("ratingSummary",(()=>{var t,i;return A(null!==(i=null===(t=U.getState().session)||void 0===t?void 0:t.profile.roles)&&void 0!==i?i:[],"RATING_USER")?this.withMapId((t=>this.fetchMapRating(t))):Promise.resolve()}))}clear(){this.cache.clearAll()}getMap(){return this.cache.get("map")}getConfiguration(){return this.cache.get("configuration")}getEnrichedToc(){return this.cache.get("enrichedToc")}get enrichedToc(){return this.cache.getNow("enrichedToc")}async getPaginationConfiguration(){return(await this.getEnrichedToc()).paginationConfiguration}async getToc(){return(await this.getEnrichedToc()).toc}async getPagesToc(){return(await this.getEnrichedToc()).pagesToc}async getTocNode(t){return(await this.getEnrichedToc()).nodeByTocId[t]}getTocNodeNow(t){var i;return null===(i=this.enrichedToc)||void 0===i?void 0:i.nodeByTocId[t]}async getPage(t){const i=await this.getEnrichedToc();return i.pages[t-1]||i.pages[0]}async getPageByTocId(t){const i=await this.getEnrichedToc();return i.pageByTocId[t]||i.pages[0]}getTopicInfo(t){return this.cache.get("topic-"+t.tocId,(()=>this.fetchTopicMetadata(t)))}getTopicContent(t){return this.cache.get("topic-content-"+t.tocId,(()=>this.fetchTopicHTMLContent(t)))}getLink(t,i,e){const s=this.getNavigationData(t,i,e),n=this.getReaderLinkPrefix()+(s.prettyUrl?s.prettyUrl:`${s.mapId}/${s.tocId}`),r=new URL(n,this.api.tenantBaseUrl);return null!=s.page&&r.searchParams.set("page",`${s.page}`),s.prettyUrlDuplicated&&r.searchParams.set("tocId",s.tocId),null!=s.section&&r.searchParams.set("section",s.section),r.href}getNavigationData(t,i,e){var s,n;t=t||"root";const r=this.enrichedToc,o=null==r?void 0:r.pageByTocId[t],a=null==r?void 0:r.nodeByTocId[t],h=null==a?void 0:a.prettyUrl;return{mapId:this.mapId,tocId:t,topicTitle:null!==(s=null==a?void 0:a.title)&&void 0!==s?s:"",page:i&&o&&o.number!==i?i:void 0,prettyUrl:null!=h?h.replace(/^r\//,""):void 0,prettyUrlDuplicated:null!==(n=null==r?void 0:r.duplicatedPrettyUrls.has(null!=h?h:""))&&void 0!==n&&n,section:e}}async getAccurateNavigationData(t,i,e){return await this.getEnrichedToc(),this.getNavigationData(t,i,e)}getRatingSummary(){return this.cache.get("ratingSummary")}getMapRating(){return this.getRatingSummary().then((t=>null==t?void 0:t.publication))}getTopicRating(t){return this.getRatingSummary().then((i=>{var e;return i?{type:i.topics.type,rating:null===(e=i.topics)||void 0===e?void 0:e.ratings.find((i=>i.tocId===t))}:void 0}))}rateMap(t,i){return this.makeRateMapRequest(t,i).then((()=>this.clearRatingIfNecessary()))}unrateMap(){return this.makeUnrateMapRequest().then((()=>this.clearRatingIfNecessary()))}sendMapFeedback(t,i){return this.makeMapFeedbackRequest(t,i)}rateTopic(t,i,e){return this.makeRateTopicRequest(t,i,e).then((()=>this.clearRatingIfNecessary()))}unrateTopic(t){return this.makeUnrateTopicRequest(t).then((()=>this.clearRatingIfNecessary()))}async clearRatingIfNecessary(){const t=U.getState().session;(null==t?void 0:t.sessionAuthenticated)&&this.cache.clear("ratingSummary")}sendTopicFeedback(t,i,e){return this.makeTopicFeedbackRequest(t,i,e)}fontsStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.fonts)}themeStylesheet(){return this.api.makeAbsolute(this.api.endpoints.stylesheets.theme)}buildBreadcrumb(t){let i=this.getTocNodeNow(t),e=[{tocId:i.tocId,title:i.title}],s=this.getTocNodeNow(i.parentTocId);for(;s;)e.unshift({tocId:s.tocId,title:s.title}),s=this.getTocNodeNow(s.parentTocId);return e}}class G extends H{static async build(t){return new G(new o,await O.await(),new i.CacheRegistry,t)}fetchMap(t){return this.api.getMap(t)}fetchMapRating(t){return this.api.getMapRating(t)}fetchPages(t){return this.api.getPages(t)}fetchTopicHTMLContent(t){return this.api.getTopicHTMLContent(this.mapId,t.contentId,"DESIGNED_READER")}fetchTopicMetadata(t){return this.api.getTopic(this.mapId,t.contentId)}makeMapFeedbackRequest(t,i){return this.api.sendMapFeedback(this.mapId,t,i)}makeRateMapRequest(t,i){return this.api.rateMap(this.mapId,t,i)}makeRateTopicRequest(t,i,e){return this.api.rateTopic(this.mapId,t,i,e)}makeTopicFeedbackRequest(t,i,e){return this.api.sendTopicFeedback(this.mapId,t,i,e)}makeUnrateMapRequest(){return this.api.unrateMap(this.mapId)}makeUnrateTopicRequest(t){return this.api.unrateTopic(this.mapId,t)}getReaderLinkPrefix(){return"r/"}isFeatureAccessible(t){return!0}}class K{static build(t,e){return new K((t=>i.FtReduxStore.get({name:"ft-reader-"+t,initialState:{mapId:void 0,visibleTopics:[]},reducers:n}))(t.trim()||"context"),null!=e?e:G.build)}constructor(t,e){this.store=t,this.reloadDebouncer=new i.Debouncer(10),this.initService(e)}async initService(t){return this.service=await t(),this.service.mapId=this.store.getState().mapId,this.reload()}async setMapId(t){t!==this.store.getState().mapId&&(this.store.actions.setMapId(t),this.service&&(this.service.mapId=t),await this.reload())}setVisibleTopics(t){this.store.actions.setVisibleTopics(t)}async awaitService(){for(;null==this.service;)await i.delay(5);return this.service}async navigateToTopic(t,i,e){const s=await this.awaitService(),n=await(null!=e?s.getPage(e):s.getPageByTocId(null!=t?t:"root"));this.store.actions.setCurrentPage(n),this.store.actions.setScrollTarget({tocId:this.resolveValidNonRootTocId(t,n),section:i})}resolveValidNonRootTocId(t,i){var e,s,n;let r=null!==(e="root"===t?void 0:t)&&void 0!==e?e:i.rootTocId;return i.topics.includes(r)?r:null!==(n=null!==(s=i.topics[0])&&void 0!==s?s:i.hiddenTopics[0])&&void 0!==n?n:"root"}async navigateToPage(t){const i=await this.awaitService();let e=await i.getPage(t);this.store.actions.setCurrentPage(e)}scrollDone(){this.store.actions.setScrollTarget({})}async reload(){var t,i;this.store.actions.setConfiguration(void 0),this.store.actions.setMap(void 0),this.store.actions.setToc(void 0),this.store.actions.setPagesToc(void 0),this.store.actions.setCurrentPage(void 0),null===(t=this.service)||void 0===t||t.clear(),(null===(i=this.service)||void 0===i?void 0:i.mapId)&&await this.reloadDebouncer.run((()=>this.fetchData()))}async fetchData(){var t,e,s,n,r;try{await Promise.all([null===(t=this.service)||void 0===t?void 0:t.getConfiguration().then((t=>this.store.actions.setConfiguration(t))),null===(e=this.service)||void 0===e?void 0:e.getMap().then((t=>this.store.actions.setMap(t))),null===(s=this.service)||void 0===s?void 0:s.getToc().then((t=>this.store.actions.setToc(t))),null===(n=this.service)||void 0===n?void 0:n.getPagesToc().then((t=>this.store.actions.setPagesToc(t))),null===(r=this.service)||void 0===r?void 0:r.getPaginationConfiguration().then((t=>this.store.actions.setPaginationConfiguration(t)))])}catch(t){!this.errorHandler||t instanceof i.CanceledPromiseError||this.errorHandler(t)}}}const q=e.css`
5
+ `;class V extends CustomEvent{constructor(t,i){super("ft-reader-map-loaded",{detail:{map:t,toc:i}})}}class $ extends CustomEvent{constructor(t,i){super("ft-reader-visible-topics-change",{detail:{visibleTopics:i}})}}class X extends CustomEvent{constructor(t){super("ft-reader-navigation-done",{detail:t})}}class Y extends CustomEvent{constructor(t){super("ft-reader-load-error",{detail:t})}}class W extends Event{constructor(){super("ft-reader-map-not-found")}}class z extends Event{constructor(){super("ft-reader-map-unauthorized")}}var J=function(t,i,e,s){for(var n,r=arguments.length,o=r<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,a=t.length-1;a>=0;a--)(n=t[a])&&(o=(r<3?n(o):r>3?n(i,e,o):n(i,e))||o);return r>3&&o&&Object.defineProperty(i,e,o),o};class Q extends i.FtLitElementRedux{constructor(){super(),this.visibleTopics=[],this.scrollToTargetDebouncer=new i.Debouncer(5),this.navigationDebouncer=new i.Debouncer(50),this.addStore(U)}render(){return e.html`
6
6
  ${this.importStyleIfNeeded()}
7
7
  <slot @register-ft-reader-component=${this.registerComponent}></slot>
8
- `}importStyleIfNeeded(){var t,i;const e=null===(t=this.stateManager.service)||void 0===t?void 0:t.themeStylesheet();return!e||window.location.href.startsWith(null!==(i=this.baseUrl)&&void 0!==i?i:"")?s.nothing:s.html`
8
+ `}importStyleIfNeeded(){var t,i;const s=null===(t=this.stateManager.service)||void 0===t?void 0:t.themeStylesheet();return!s||window.location.href.startsWith(null!==(i=this.baseUrl)&&void 0!==i?i:"")?e.nothing:e.html`
9
9
  <style>
10
- @import "${e}"
10
+ @import "${s}"
11
11
  </style>
12
- `}get stateManager(){return null==this._stateManager&&(this._stateManager=m.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"reader")),this._stateManager}connectedCallback(){super.connectedCallback(),this.stateManager.setMapId(this.mapId),this.stateManager.awaitService().then((t=>{const i=t.fontsStylesheet();if(i&&!window.location.href.startsWith(this.baseUrl)&&!document.querySelector(`head link[href="${i}"]`)){const t=document.createElement("link");t.setAttribute("rel","stylesheet"),t.setAttribute("href",i),document.head.append(t)}}))}updated(t){super.updated(t),t.has("mapId")&&this.stateManager.setMapId(this.mapId),["tocId","section","page","mapId"].some((i=>t.has(i)))&&this.mapId&&this.navigateToTarget()}contentAvailableCallback(t){var i;if(super.contentAvailableCallback(t),(t.has("map")||t.has("toc"))&&this.map&&this.toc&&this.dispatchEvent(new b(this.map,this.toc)),t.has("scrollTarget")&&null==(null===(i=this.scrollTarget)||void 0===i?void 0:i.tocId)){const i=t.get("scrollTarget");null!=(null==i?void 0:i.tocId)&&this.scrollToTargetDebouncer.run((()=>{var t;return this.stateManager.service.getAccurateNavigationData(i.tocId,null===(t=this.currentPage)||void 0===t?void 0:t.number,i.section).then((t=>this.dispatchEvent(new I(t))))}))}t.has("visibleTopics")&&Promise.all(this.visibleTopics.map((t=>{var i;return this.stateManager.service.getAccurateNavigationData(t,null===(i=this.currentPage)||void 0===i?void 0:i.number)}))).then((t=>{let i=t.filter((t=>null!=t&&""!==t.topicTitle)).map((t=>({tocId:t.tocId,title:t.topicTitle,page:t.page,prettyUrl:t.prettyUrl,prettyUrlDuplicated:t.prettyUrlDuplicated,breadcrumb:this.buildBreadcrumb(t.tocId)})));this.dispatchEvent(new T(this.map,i))}))}buildBreadcrumb(t){var i,s,e,n;let o=[],r=null===(s=null===(i=this.stateManager.service)||void 0===i?void 0:i.getTocNodeNow(t))||void 0===s?void 0:s.parentTocId,a=null===(e=this.stateManager.service)||void 0===e?void 0:e.getTocNodeNow(r);for(;a;)o.unshift({tocId:a.tocId,title:a.title}),a=null===(n=this.stateManager.service)||void 0===n?void 0:n.getTocNodeNow(a.parentTocId);return o}async reload(){await this.stateManager.reload(),this.navigateToTarget()}navigateToTarget(){this.navigationDebouncer.run((()=>{null!=this.tocId?this.stateManager.navigateToTopic(this.tocId,this.section,this.page):null!=this.page&&this.stateManager.navigateToPage(this.page)}))}registerComponent(t){t.stopPropagation();const i=t.composedPath()[0];this.register(i)}register(t){t.setReaderStateManager(this.stateManager)}handleLoadError(t){const i=t;404===i.status?this.dispatchEvent(new U):401===i.status?this.dispatchEvent(new S):this.dispatchEvent(new C(t))}}var x;P.styles=f,y([i.redux({store:h.name})],P.prototype,"baseUrl",void 0),y([e.property()],P.prototype,"mapId",void 0),y([e.property()],P.prototype,"tocId",void 0),y([e.property()],P.prototype,"section",void 0),y([e.property({type:Number,converter:{fromAttribute:t=>+(null!=t?t:"NaN")>0?+t:x}})],P.prototype,"page",void 0),y([i.redux({store:"reader"})],P.prototype,"map",void 0),y([i.redux({store:"reader"})],P.prototype,"toc",void 0),y([i.redux({store:"reader"})],P.prototype,"visibleTopics",void 0),y([i.redux({store:"reader"})],P.prototype,"currentPage",void 0),y([i.redux({store:"reader"})],P.prototype,"scrollTarget",void 0),i.customElement("ft-reader-context")(P),t.FtReaderContext=P,t.FtReaderContextCssVariables={},t.LoadErrorEvent=C,t.MapLoadedEvent=b,t.NavigationDoneEvent=I,t.NotFoundErrorEvent=U,t.UnauthorizedErrorEvent=S,t.VisibleTopicsChangeEvent=T,t.styles=f}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);
12
+ `}get stateManager(){return null==this._stateManager&&(this._stateManager=K.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0"),this.readerServiceProvider),this._stateManager.errorHandler=t=>this.handleLoadError(t),this.addStore(this.stateManager.store,"reader")),this._stateManager}connectedCallback(){super.connectedCallback(),this.stateManager.setMapId(this.mapId),this.stateManager.awaitService().then((t=>{const i=t.fontsStylesheet();if(i&&!window.location.href.startsWith(this.baseUrl)&&!document.querySelector(`head link[href="${i}"]`)){const t=document.createElement("link");t.setAttribute("rel","stylesheet"),t.setAttribute("href",i),document.head.append(t)}}))}updated(t){super.updated(t),t.has("readerServiceProvider")&&this.readerServiceProvider&&this.stateManager.initService(this.readerServiceProvider),t.has("mapId")&&this.stateManager.setMapId(this.mapId),["tocId","section","page","mapId"].some((i=>t.has(i)))&&this.mapId&&this.navigateToTarget()}contentAvailableCallback(t){var i;if(super.contentAvailableCallback(t),(t.has("map")||t.has("toc"))&&this.map&&this.toc&&this.dispatchEvent(new V(this.map,this.toc)),t.has("scrollTarget")&&null==(null===(i=this.scrollTarget)||void 0===i?void 0:i.tocId)){const i=t.get("scrollTarget");null!=(null==i?void 0:i.tocId)&&this.scrollToTargetDebouncer.run((()=>{var t;return this.stateManager.service.getAccurateNavigationData(i.tocId,null===(t=this.currentPage)||void 0===t?void 0:t.number,i.section).then((t=>this.dispatchEvent(new X(t))))}))}t.has("visibleTopics")&&Promise.all(this.visibleTopics.map((t=>{var i;return this.stateManager.service.getAccurateNavigationData(t,null===(i=this.currentPage)||void 0===i?void 0:i.number)}))).then((t=>{let i=t.filter((t=>null!=t&&""!==t.topicTitle)).map((t=>{var i;return{tocId:t.tocId,title:t.topicTitle,page:t.page,prettyUrl:t.prettyUrl,prettyUrlDuplicated:t.prettyUrlDuplicated,breadcrumb:null===(i=this.stateManager.service)||void 0===i?void 0:i.buildBreadcrumb(t.tocId)}}));this.dispatchEvent(new $(this.map,i))}))}async reload(){await this.stateManager.reload(),this.navigateToTarget()}navigateToTarget(){this.navigationDebouncer.run((()=>{null!=this.tocId?this.stateManager.navigateToTopic(this.tocId,this.section,this.page):null!=this.page&&this.stateManager.navigateToPage(this.page)}))}registerComponent(t){t.stopPropagation();const i=t.composedPath()[0];this.register(i)}register(t){t.setReaderStateManager(this.stateManager)}handleLoadError(t){const i=t;404===i.status?this.dispatchEvent(new W):401===i.status?this.dispatchEvent(new z):this.dispatchEvent(new Y(t))}reloadBookmarks(){x.reloadBookmarks()}}var Z;Q.styles=q,J([i.redux({store:U.name})],Q.prototype,"baseUrl",void 0),J([s.property()],Q.prototype,"mapId",void 0),J([s.property()],Q.prototype,"tocId",void 0),J([s.property()],Q.prototype,"section",void 0),J([s.property({type:Number,converter:{fromAttribute:t=>+(null!=t?t:"NaN")>0?+t:Z}})],Q.prototype,"page",void 0),J([i.redux({store:"reader"})],Q.prototype,"map",void 0),J([i.redux({store:"reader"})],Q.prototype,"toc",void 0),J([i.redux({store:"reader"})],Q.prototype,"visibleTopics",void 0),J([i.redux({store:"reader"})],Q.prototype,"currentPage",void 0),J([i.redux({store:"reader"})],Q.prototype,"scrollTarget",void 0),J([s.property({attribute:!1})],Q.prototype,"readerServiceProvider",void 0),i.customElement("ft-reader-context")(Q),t.FtOfficialReaderService=G,t.FtReaderContext=Q,t.FtReaderContextCssVariables={},t.FtReaderConverter=o,t.FtReaderService=H,t.LoadErrorEvent=Y,t.MapLoadedEvent=V,t.NavigationDoneEvent=X,t.NotFoundErrorEvent=W,t.UnauthorizedErrorEvent=z,t.VisibleTopicsChangeEvent=$,t.styles=q}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);