@fluid-topics/ft-reader-context 0.3.18 → 0.3.19

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,8 +1,9 @@
1
1
  import { PropertyValues } from "lit";
2
2
  import { FtLitElementRedux } from "@fluid-topics/ft-wc-utils";
3
- import { FtReaderNavigationData, FtReaderTocNode } from "./store/model";
3
+ import { FtReaderNavigationData, FtReaderScrollTarget, FtReaderTocNode } from "./store/model";
4
4
  import { FtMap } from "@fluid-topics/public-api";
5
5
  import { FtReaderContextProperties } from "./ft-reader-context.properties";
6
+ import { FtReaderPage } from "./store/model";
6
7
  declare type MapLoadedEventDetail = {
7
8
  map: FtMap;
8
9
  toc: Array<FtReaderTocNode>;
@@ -40,11 +41,11 @@ export declare class FtReaderContext extends FtLitElementRedux implements FtRead
40
41
  page?: number;
41
42
  renderBeforeFirst: number;
42
43
  renderAfterLast: number;
43
- private map?;
44
- private toc?;
45
- private visibleTopics;
46
- private currentPageNumber?;
47
- private scrollTarget?;
44
+ map?: FtMap;
45
+ toc?: FtReaderTocNode[];
46
+ visibleTopics: string[];
47
+ currentPage?: FtReaderPage;
48
+ scrollTarget?: FtReaderScrollTarget;
48
49
  protected render(): import("lit-html").TemplateResult<1>;
49
50
  private _stateManager?;
50
51
  private get stateManager();
@@ -80,12 +80,15 @@ export class FtReaderContext extends FtLitElementRedux {
80
80
  if (props.has("scrollTarget") && ((_a = this.scrollTarget) === null || _a === void 0 ? void 0 : _a.tocId) == null) {
81
81
  const oldScrollTarget = props.get("scrollTarget");
82
82
  if ((oldScrollTarget === null || oldScrollTarget === void 0 ? void 0 : oldScrollTarget.tocId) != null) {
83
- this.navigationDebouncer.run(() => this.stateManager.service.getAccurateNavigationData(oldScrollTarget.tocId, this.currentPageNumber, oldScrollTarget.section)
84
- .then(data => this.dispatchEvent(new NavigationDoneEvent(data))));
83
+ this.navigationDebouncer.run(() => {
84
+ var _a;
85
+ return this.stateManager.service.getAccurateNavigationData(oldScrollTarget.tocId, (_a = this.currentPage) === null || _a === void 0 ? void 0 : _a.number, oldScrollTarget.section)
86
+ .then(data => this.dispatchEvent(new NavigationDoneEvent(data)));
87
+ });
85
88
  }
86
89
  }
87
90
  if (props.has("visibleTopics")) {
88
- Promise.all(this.visibleTopics.map(tocId => this.stateManager.service.getAccurateNavigationData(tocId, this.currentPageNumber)))
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); }))
89
92
  .then(navigationData => {
90
93
  let visibleTopics = navigationData.filter(data => data != null && data.topicTitle !== "")
91
94
  .map(data => ({
@@ -150,8 +153,8 @@ __decorate([
150
153
  redux()
151
154
  ], FtReaderContext.prototype, "visibleTopics", void 0);
152
155
  __decorate([
153
- redux((state) => { var _a; return (_a = state.currentPage) === null || _a === void 0 ? void 0 : _a.number; })
154
- ], FtReaderContext.prototype, "currentPageNumber", void 0);
156
+ redux()
157
+ ], FtReaderContext.prototype, "currentPage", void 0);
155
158
  __decorate([
156
159
  redux()
157
160
  ], FtReaderContext.prototype, "scrollTarget", void 0);
@@ -1,4 +1,4 @@
1
- !function(t,r,n,e){function i(t){for(var r=arguments.length,n=Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];throw Error("[Immer] minified error nr: "+t+(n.length?" "+n.map((function(t){return"'"+t+"'"})).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function o(t){return!!t&&!!t[V]}function u(t){return!!t&&(function(t){if(!t||"object"!=typeof t)return!1;var r=Object.getPrototypeOf(t);if(null===r)return!0;var n=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return n===Object||"function"==typeof n&&Function.toString.call(n)===J}(t)||Array.isArray(t)||!!t[q]||!!t.constructor[q]||d(t)||v(t))}function s(t,r,n){void 0===n&&(n=!1),0===a(t)?(n?Object.keys:W)(t).forEach((function(e){n&&"symbol"==typeof e||r(e,t[e],t)})):t.forEach((function(n,e){return r(e,n,t)}))}function a(t){var r=t[V];return r?r.i>3?r.i-4:r.i:Array.isArray(t)?1:d(t)?2:v(t)?3:0}function c(t,r){return 2===a(t)?t.has(r):Object.prototype.hasOwnProperty.call(t,r)}function f(t,r,n){var e=a(t);2===e?t.set(r,n):3===e?(t.delete(r),t.add(n)):t[r]=n}function l(t,r){return t===r?0!==t||1/t==1/r:t!=t&&r!=r}function d(t){return L&&t instanceof Map}function v(t){return $&&t instanceof Set}function h(t){return t.o||t.t}function p(t){if(Array.isArray(t))return Array.prototype.slice.call(t);var r=X(t);delete r[V];for(var n=W(r),e=0;e<n.length;e++){var i=n[e],o=r[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(r[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:t[i]})}return Object.create(Object.getPrototypeOf(t),r)}function b(t,r){return void 0===r&&(r=!1),m(t)||o(t)||!u(t)||(a(t)>1&&(t.set=t.add=t.clear=t.delete=y),Object.freeze(t),r&&s(t,(function(t,r){return b(r,!0)}),!0)),t}function y(){i(2)}function m(t){return null==t||"object"!=typeof t||Object.isFrozen(t)}function w(t){var r=Y[t];return r||i(18,t),r}function g(){return F}function j(t,r){r&&(w("Patches"),t.u=[],t.s=[],t.v=r)}function I(t){O(t),t.p.forEach(A),t.p=null}function O(t){t===F&&(F=t.l)}function T(t){return F={p:[],l:F,h:t,m:!0,_:0}}function A(t){var r=t[V];0===r.i||1===r.i?r.j():r.O=!0}function P(t,r){r._=r.p.length;var n=r.p[0],e=void 0!==t&&t!==n;return r.h.g||w("ES5").S(r,t,e),e?(n[V].P&&(I(r),i(4)),u(t)&&(t=S(r,t),r.l||M(r,t)),r.u&&w("Patches").M(n[V].t,t,r.u,r.s)):t=S(r,n,[]),I(r),r.u&&r.v(r.u,r.s),t!==K?t:void 0}function S(t,r,n){if(m(r))return r;var e=r[V];if(!e)return s(r,(function(i,o){return E(t,e,r,i,o,n)}),!0),r;if(e.A!==t)return r;if(!e.P)return M(t,e.t,!0),e.t;if(!e.I){e.I=!0,e.A._--;var i=4===e.i||5===e.i?e.o=p(e.k):e.o;s(3===e.i?new Set(i):i,(function(r,o){return E(t,e,i,r,o,n)})),M(t,i,!1),n&&t.u&&w("Patches").R(e,n,t.u,t.s)}return e.o}function E(t,r,n,e,i,s){if(o(i)){var a=S(t,i,s&&r&&3!==r.i&&!c(r.D,e)?s.concat(e):void 0);if(f(n,e,a),!o(a))return;t.m=!1}if(u(i)&&!m(i)){if(!t.h.F&&t._<1)return;S(t,i),r&&r.A.l||M(t,i)}}function M(t,r,n){void 0===n&&(n=!1),t.h.F&&t.m&&b(r,n)}function R(t,r){var n=t[V];return(n?h(n):t)[r]}function C(t,r){if(r in t)for(var n=Object.getPrototypeOf(t);n;){var e=Object.getOwnPropertyDescriptor(n,r);if(e)return e;n=Object.getPrototypeOf(n)}}function U(t){t.P||(t.P=!0,t.l&&U(t.l))}function _(t){t.o||(t.o=p(t.t))}function N(t,r,n){var e=d(r)?w("MapSet").N(r,n):v(r)?w("MapSet").T(r,n):t.g?function(t,r){var n=Array.isArray(t),e={i:n?1:0,A:r?r.A:g(),P:!1,I:!1,D:{},l:r,t,k:null,o:null,j:null,C:!1},i=e,o=z;n&&(i=[e],o=H);var u=Proxy.revocable(i,o),s=u.revoke,a=u.proxy;return e.k=a,e.j=s,a}(r,n):w("ES5").J(r,n);return(n?n.A:g()).p.push(e),e}function x(t){return o(t)||i(22,t),function t(r){if(!u(r))return r;var n,e=r[V],i=a(r);if(e){if(!e.P&&(e.i<4||!w("ES5").K(e)))return e.t;e.I=!0,n=B(r,i),e.I=!1}else n=B(r,i);return s(n,(function(r,i){e&&function(t,r){return 2===a(t)?t.get(r):t[r]}(e.t,r)===i||f(n,r,t(i))})),3===i?new Set(n):n}(t)}function B(t,r){switch(r){case 2:return new Map(t);case 3:return Array.from(t)}return p(t)}var D,F,k="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),L="undefined"!=typeof Map,$="undefined"!=typeof Set,G="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,K=k?Symbol.for("immer-nothing"):((D={})["immer-nothing"]=!0,D),q=k?Symbol.for("immer-draftable"):"__$immer_draftable",V=k?Symbol.for("immer-state"):"__$immer_state",J=""+Object.prototype.constructor,W="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Object.getOwnPropertyNames,X=Object.getOwnPropertyDescriptors||function(t){var r={};return W(t).forEach((function(n){r[n]=Object.getOwnPropertyDescriptor(t,n)})),r},Y={},z={get:function(t,r){if(r===V)return t;var n=h(t);if(!c(n,r))return function(t,r,n){var e,i=C(r,n);return i?"value"in i?i.value:null===(e=i.get)||void 0===e?void 0:e.call(t.k):void 0}(t,n,r);var e=n[r];return t.I||!u(e)?e:e===R(t.t,r)?(_(t),t.o[r]=N(t.A.h,e,t)):e},has:function(t,r){return r in h(t)},ownKeys:function(t){return Reflect.ownKeys(h(t))},set:function(t,r,n){var e=C(h(t),r);if(null==e?void 0:e.set)return e.set.call(t.k,n),!0;if(!t.P){var i=R(h(t),r),o=null==i?void 0:i[V];if(o&&o.t===n)return t.o[r]=n,t.D[r]=!1,!0;if(l(n,i)&&(void 0!==n||c(t.t,r)))return!0;_(t),U(t)}return t.o[r]===n&&"number"!=typeof n&&(void 0!==n||r in t.o)||(t.o[r]=n,t.D[r]=!0,!0)},deleteProperty:function(t,r){return void 0!==R(t.t,r)||r in t.t?(t.D[r]=!1,_(t),U(t)):delete t.D[r],t.o&&delete t.o[r],!0},getOwnPropertyDescriptor:function(t,r){var n=h(t),e=Reflect.getOwnPropertyDescriptor(n,r);return e?{writable:!0,configurable:1!==t.i||"length"!==r,enumerable:e.enumerable,value:n[r]}:e},defineProperty:function(){i(11)},getPrototypeOf:function(t){return Object.getPrototypeOf(t.t)},setPrototypeOf:function(){i(12)}},H={};s(z,(function(t,r){H[t]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}})),H.deleteProperty=function(t,r){return H.set.call(this,t,r,void 0)},H.set=function(t,r,n){return z.set.call(this,t[0],r,n,t[0])};var Q=function(){function t(t){var r=this;this.g=G,this.F=!0,this.produce=function(t,n,e){if("function"==typeof t&&"function"!=typeof n){var o=n;n=t;var s=r;return function(t){var r=this;void 0===t&&(t=o);for(var e=arguments.length,i=Array(e>1?e-1:0),u=1;u<e;u++)i[u-1]=arguments[u];return s.produce(t,(function(t){var e;return(e=n).call.apply(e,[r,t].concat(i))}))}}var a;if("function"!=typeof n&&i(6),void 0!==e&&"function"!=typeof e&&i(7),u(t)){var c=T(r),f=N(r,t,void 0),l=!0;try{a=n(f),l=!1}finally{l?I(c):O(c)}return"undefined"!=typeof Promise&&a instanceof Promise?a.then((function(t){return j(c,e),P(t,c)}),(function(t){throw I(c),t})):(j(c,e),P(a,c))}if(!t||"object"!=typeof t){if(void 0===(a=n(t))&&(a=t),a===K&&(a=void 0),r.F&&b(a,!0),e){var d=[],v=[];w("Patches").M(t,a,d,v),e(d,v)}return a}i(21,t)},this.produceWithPatches=function(t,n){if("function"==typeof t)return function(n){for(var e=arguments.length,i=Array(e>1?e-1:0),o=1;o<e;o++)i[o-1]=arguments[o];return r.produceWithPatches(n,(function(r){return t.apply(void 0,[r].concat(i))}))};var e,i,o=r.produce(t,n,(function(t,r){e=t,i=r}));return"undefined"!=typeof Promise&&o instanceof Promise?o.then((function(t){return[t,e,i]})):[o,e,i]},"boolean"==typeof(null==t?void 0:t.useProxies)&&this.setUseProxies(t.useProxies),"boolean"==typeof(null==t?void 0:t.autoFreeze)&&this.setAutoFreeze(t.autoFreeze)}var r=t.prototype;return r.createDraft=function(t){u(t)||i(8),o(t)&&(t=x(t));var r=T(this),n=N(this,t,void 0);return n[V].C=!0,O(r),n},r.finishDraft=function(t,r){var n=(t&&t[V]).A;return j(n,r),P(void 0,n)},r.setAutoFreeze=function(t){this.F=t},r.setUseProxies=function(t){t&&!G&&i(20),this.g=t},r.applyPatches=function(t,r){var n;for(n=r.length-1;n>=0;n--){var e=r[n];if(0===e.path.length&&"replace"===e.op){t=e.value;break}}n>-1&&(r=r.slice(n+1));var i=w("Patches").$;return o(t)?i(t,r):this.produce(t,(function(t){return i(t,r)}))},t}(),Z=new Q,tt=Z.produce;Z.produceWithPatches.bind(Z),Z.setAutoFreeze.bind(Z),Z.setUseProxies.bind(Z),Z.applyPatches.bind(Z),Z.createDraft.bind(Z),Z.finishDraft.bind(Z);var rt,nt=tt,et=(rt=function(t,r){return rt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])},rt(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}rt(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}),it=function(t,r){for(var n=0,e=r.length,i=t.length;n<e;n++,i++)t[i]=r[n];return t},ot=Object.defineProperty,ut=Object.getOwnPropertySymbols,st=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,ct=function(t,r,n){return r in t?ot(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n},ft=function(t,r){for(var n in r||(r={}))st.call(r,n)&&ct(t,n,r[n]);if(ut)for(var e=0,i=ut(r);e<i.length;e++){n=i[e];at.call(r,n)&&ct(t,n,r[n])}return t};function lt(t){return u(t)?nt(t,(function(){})):t}function dt(t,r){function n(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];if(r){var i=r.apply(void 0,n);if(!i)throw new Error("prepareAction did not return an object");return ft(ft({type:t,payload:i.payload},"meta"in i&&{meta:i.meta}),"error"in i&&{error:i.error})}return{type:t,payload:n[0]}}return n.toString=function(){return""+t},n.type=t,n.match=function(r){return r.type===t},n}function vt(t){var r,n={},e=[],i={addCase:function(t,r){var e="string"==typeof t?t:t.type;if(e in n)throw new Error("addCase cannot be called with two reducers for the same action type");return n[e]=r,i},addMatcher:function(t,r){return e.push({matcher:t,reducer:r}),i},addDefaultCase:function(t){return r=t,i}};return t(i),[n,e,r]}function ht(t){var r=t.name;if(!r)throw new Error("`name` is a required option for createSlice");var n,e="function"==typeof t.initialState?t.initialState:lt(t.initialState),i=t.reducers||{},s=Object.keys(i),a={},c={},f={};function l(){var r="function"==typeof t.extraReducers?vt(t.extraReducers):[t.extraReducers],n=r[0],i=void 0===n?{}:n,s=r[1],a=void 0===s?[]:s,f=r[2],l=void 0===f?void 0:f,d=ft(ft({},i),c);return function(t,r,n,e){void 0===n&&(n=[]);var i,s="function"==typeof r?vt(r):[r,n,e],a=s[0],c=s[1],f=s[2];if(function(t){return"function"==typeof t}(t))i=function(){return lt(t())};else{var l=lt(t);i=function(){return l}}function d(t,r){void 0===t&&(t=i());var n=it([a[r.type]],c.filter((function(t){return(0,t.matcher)(r)})).map((function(t){return t.reducer})));return 0===n.filter((function(t){return!!t})).length&&(n=[f]),n.reduce((function(t,n){if(n){var e;if(o(t))return void 0===(e=n(t,r))?t:e;if(u(t))return nt(t,(function(t){return n(t,r)}));if(void 0===(e=n(t,r))){if(null===t)return t;throw Error("A case reducer on a non-draftable value must not return undefined")}return e}return t}),t)}return d.getInitialState=i,d}(e,d,a,l)}return s.forEach((function(t){var n,e,o=i[t],u=r+"/"+t;"reducer"in o?(n=o.reducer,e=o.prepare):n=o,a[t]=n,c[u]=n,f[t]=e?dt(u,e):dt(u)})),{name:r,reducer:function(t,r){return n||(n=l()),n(t,r)},actions:f,caseReducers:a,getInitialState:function(){return n||(n=l()),n.getInitialState()}}}!function(t){function r(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var i=t.apply(this,n)||this;return Object.setPrototypeOf(i,r.prototype),i}et(r,t),Object.defineProperty(r,Symbol.species,{get:function(){return r},enumerable:!1,configurable:!0}),r.prototype.concat=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return t.prototype.concat.apply(this,r)},r.prototype.prepend=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length&&Array.isArray(t[0])?new(r.bind.apply(r,it([void 0],t[0].concat(this)))):new(r.bind.apply(r,it([void 0],t.concat(this))))}}(Array);var pt="listenerMiddleware";dt(pt+"/add"),dt(pt+"/removeAll"),dt(pt+"/remove"),function(){function t(t,r){var n=i[t];return n?n.enumerable=r:i[t]=n={configurable:!0,enumerable:r,get:function(){var r=this[V];return z.get(r,t)},set:function(r){var n=this[V];z.set(n,t,r)}},n}function r(t){for(var r=t.length-1;r>=0;r--){var i=t[r][V];if(!i.P)switch(i.i){case 5:e(i)&&U(i);break;case 4:n(i)&&U(i)}}}function n(t){for(var r=t.t,n=t.k,e=W(n),i=e.length-1;i>=0;i--){var o=e[i];if(o!==V){var u=r[o];if(void 0===u&&!c(r,o))return!0;var s=n[o],a=s&&s[V];if(a?a.t!==u:!l(s,u))return!0}}var f=!!r[V];return e.length!==W(r).length+(f?0:1)}function e(t){var r=t.k;if(r.length!==t.t.length)return!0;var n=Object.getOwnPropertyDescriptor(r,r.length-1);if(n&&!n.get)return!0;for(var e=0;e<r.length;e++)if(!r.hasOwnProperty(e))return!0;return!1}var i={};!function(t,r){Y[t]||(Y[t]=r)}("ES5",{J:function(r,n){var e=Array.isArray(r),i=function(r,n){if(r){for(var e=Array(n.length),i=0;i<n.length;i++)Object.defineProperty(e,""+i,t(i,!0));return e}var o=X(n);delete o[V];for(var u=W(o),s=0;s<u.length;s++){var a=u[s];o[a]=t(a,r||!!o[a].enumerable)}return Object.create(Object.getPrototypeOf(n),o)}(e,r),o={i:e?5:4,A:n?n.A:g(),P:!1,I:!1,D:{},l:n,t:r,k:i,o:null,O:!1,C:!1};return Object.defineProperty(i,V,{value:o,writable:!0}),i},S:function(t,n,i){i?o(n)&&n[V].A===t&&r(t.p):(t.u&&function t(r){if(r&&"object"==typeof r){var n=r[V];if(n){var i=n.t,o=n.k,u=n.D,a=n.i;if(4===a)s(o,(function(r){r!==V&&(void 0!==i[r]||c(i,r)?u[r]||t(o[r]):(u[r]=!0,U(n)))})),s(i,(function(t){void 0!==o[t]||c(o,t)||(u[t]=!1,U(n))}));else if(5===a){if(e(n)&&(U(n),u.length=!0),o.length<i.length)for(var f=o.length;f<i.length;f++)u[f]=!1;else for(var l=i.length;l<o.length;l++)u[l]=!0;for(var d=Math.min(o.length,i.length),v=0;v<d;v++)o.hasOwnProperty(v)||(u[v]=!0),void 0===u[v]&&t(o[v])}}}}(t.p[0]),r(t.p))},K:function(t){return 4===t.i?n(t):e(t)}})}();const bt={setBaseUrl:(t,r)=>{t.baseUrl=r.payload},setApiIntegrationIdentifier:(t,r)=>{t.apiIntegrationIdentifier=r.payload},setMapId:(t,r)=>{t.mapId=r.payload},setTocId:(t,r)=>{t.tocId=r.payload},setMap:(t,r)=>{t.map=r.payload},setToc:(t,r)=>{t.toc=r.payload},setCurrentPage:(t,r)=>{t.currentPage=r.payload},setScrollTarget:(t,r)=>{t.scrollTarget=r.payload},setVisibleTopics:(t,r)=>{t.visibleTopics=r.payload},setRenderBeforeFirst:(t,r)=>{t.renderBeforeFirst=r.payload},setRenderAfterLast:(t,r)=>{t.renderAfterLast=r.payload}};class yt{convertNodes(t){var r,n,e,i;const o={},u=new Set,s=new Set,a=[],c=(t,r,n)=>t.map((t=>{var e;t.page&&a.push(t.tocId);let i=null===(e=t.prettyUrl)||void 0===e?void 0:e.replace(/^\//,"");const f={...t,prettyUrl:i,depth:r,parentTocId:n,children:c(t.children,r+1,t.tocId)};return i&&(u.has(i)&&s.add(i),u.add(i)),o[t.tocId]=f,f})),f=c(null!=t?t:[],1),l=this.buildPages(a,o);let d={};return 0===l.length?l.push({number:1,title:null!==(n=null===(r=f[0])||void 0===r?void 0:r.title)&&void 0!==n?n:"",rootTocId:null!==(i=null===(e=f[0])||void 0===e?void 0:e.tocId)&&void 0!==i?i:"root",toc:[],topics:this.tocIds(f),hiddenTopics:[],breadcrumb:[]}):d=this.indexPages(l),{toc:f,nodeByTocId:o,duplicatedPrettyUrls:s,pages:l,pageByTocId:d}}tocIds(t){return t.flatMap((t=>[t.tocId,...this.tocIds(t.children)]))}buildPages(t,r){return t.map((t=>r[t])).map(((t,n)=>{var e,i,o,u,s;const a={number:n+1,title:t.title,rootTocId:t.tocId,toc:(null===(e=t.page)||void 0===e?void 0:e.onItsOwn)?[]:t.children,topics:[],hiddenTopics:[],breadcrumb:this.buildBreadcrumb(t,r)},c=(t,r)=>(r?a.topics:a.hiddenTopics).push(t),f=null!==(o=null===(i=t.page)||void 0===i?void 0:i.parentsVisibility)&&void 0!==o?o:[];return a.breadcrumb.forEach(((t,r)=>{c(t,f[r])})),c(t.tocId,null===(u=t.page)||void 0===u?void 0:u.visible),(null===(s=t.page)||void 0===s?void 0:s.onItsOwn)||a.topics.push(...this.tocIds(t.children)),a}))}buildBreadcrumb(t,r){const n=[];for(;null==t?void 0:t.parentTocId;)n.unshift(t.parentTocId),t=r[t.parentTocId];return n}indexPages(t){const r={};for(let n of t)for(let t of[...n.topics,...n.hiddenTopics])r[t]||(r[t]=n);return r}}class mt{constructor(t,r,n,e){this.converter=t,this.api=r,this.baseUrl=n,this.mapId=e,this.topics={},this.topicContents={},n.endsWith("/")||(this.baseUrl=n+"/")}static build(t,r,n){if(null==window.fluidtopics)throw console.error("Fluid Topics public API was not found. You can find it here: https://www.npmjs.com/package/@fluid-topics/public-api"),new Error("Fluid Topics public API not found");return new mt(new yt,new window.fluidtopics.FluidTopicsApi(t,r,!0),t,n)}clear(){this.map=void 0,this.enrichedToc=void 0,this.topics={},this.topicContents={}}getMap(){return this.loadIfNeeded((()=>this.map),(t=>this.map=t),(()=>this.api.getMap(this.mapId)))}getEnrichedToc(){return this.loadIfNeeded((()=>this.enrichedToc),(t=>this.enrichedToc=t),(()=>this.api.getTableOfContent(this.mapId).then((t=>this.converter.convertNodes(t)))))}async getToc(){return(await this.getEnrichedToc()).toc}async getTocNode(t){return(await this.getEnrichedToc()).nodeByTocId[t]}getTocNodeOrThrow(t){if("boolean"==typeof this.enrichedToc)throw new Error((this.enrichedToc," still loading"));return this.enrichedToc.nodeByTocId[t]}async getPage(t){const r=await this.getEnrichedToc();return r.pages[t-1]||r.pages[0]}async getPageByTocId(t){const r=await this.getEnrichedToc();return r.pageByTocId[t]||r.pages[0]}getTopicInfo(t){return this.loadIfNeeded((()=>this.topics[t]),(r=>this.topics[t]=r),(()=>this.api.getTopic(this.mapId,t)))}getTopicContent(t){return this.loadIfNeeded((()=>this.topicContents[t]),(r=>this.topicContents[t]=r),(()=>this.api.getTopicHTMLContent(this.mapId,t,"DESIGNED_READER")))}getLink(t,r,n){const e=this.getNavigationData(t,r,n),i="r/"+(e.prettyUrl?e.prettyUrl:`${e.mapId}/${e.tocId}`),o=new URL(i,this.baseUrl);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,r,n){var e,i;t=t||"root";const o="object"==typeof this.enrichedToc?this.enrichedToc:void 0,u=null==o?void 0:o.pageByTocId[t],s=null==o?void 0:o.nodeByTocId[t],a=null==s?void 0:s.prettyUrl;return{mapId:this.mapId,tocId:t,topicTitle:null!==(e=null==s?void 0:s.title)&&void 0!==e?e:"",page:r&&u&&u.number!==r?r:void 0,prettyUrl:null!=a?a.replace(/^r\//,""):void 0,prettyUrlDuplicated:null!==(i=null==o?void 0:o.duplicatedPrettyUrls.has(null!=a?a:""))&&void 0!==i&&i,section:n}}async getAccurateNavigationData(t,r,n){return await this.getEnrichedToc(),this.getNavigationData(t,r,n)}async loadIfNeeded(t,n,e){for(void 0===t()&&(n(!0),n(await e().catch((t=>(console.error(t),!1)))));!0===t();)await r.delay(10);const i=t();if(!1===i)throw new Error("Could not load data");return i}}class wt{constructor(t,n){this.store=t,this.slice=n,this.reloadDebouncer=new r.Debouncer(10)}static build(t){const n=(t=>ht({name:"ft-reader-"+t,initialState:{baseUrl:"",apiIntegrationIdentifier:"ft-reader",visibleTopics:[],renderBeforeFirst:2,renderAfterLast:3},reducers:bt}))(t.trim()||"context");return new wt(r.getStore(n),n)}setBaseUrl(t){this.setRequiredStateField("baseUrl","setBaseUrl",t)}setApiIntegrationIdentifier(t){this.setRequiredStateField("apiIntegrationIdentifier","setApiIntegrationIdentifier",t)}setMapId(t){this.setRequiredStateField("mapId","setMapId",t)}setRenderBeforeFirst(t){this.dispatch(this.slice.actions.setRenderBeforeFirst(t))}setRenderAfterLast(t){this.dispatch(this.slice.actions.setRenderAfterLast(t))}setVisibleTopics(t){this.dispatch(this.slice.actions.setVisibleTopics(t))}async navigateToTopic(t,n,e){for(;null==this.service;)await r.delay(5);let i=null!=e?await this.service.getPage(e):await this.service.getPageByTocId(t);this.dispatch(this.slice.actions.setCurrentPage(i),this.slice.actions.setScrollTarget({tocId:t,section:n}))}async navigateToPage(t){for(;null==this.service;)await r.delay(5);let n=await this.service.getPage(t);this.dispatch(this.slice.actions.setCurrentPage(n))}scrollDone(){this.dispatch(this.slice.actions.setScrollTarget({}))}setRequiredStateField(t,r,n){this.store.getState()[t]!==n&&(this.dispatch(this.slice.actions[r](n)),this.clearAll(),this.reload())}clearAll(){this.dispatch(this.slice.actions.setMap(void 0),this.slice.actions.setToc(void 0),this.slice.actions.setCurrentPage(void 0))}reload(){const t=this.store.getState();t.baseUrl&&t.apiIntegrationIdentifier&&t.mapId?this.service=mt.build(t.baseUrl,t.apiIntegrationIdentifier,t.mapId):this.service=void 0,this.reloadDebouncer.run((async()=>{this.reloadMap(),this.reloadToc()}))}async reloadMap(){var t;const r=await(null===(t=this.service)||void 0===t?void 0:t.getMap());this.dispatch(this.slice.actions.setMap(r))}async reloadToc(){var t;const r=await(null===(t=this.service)||void 0===t?void 0:t.getToc());this.dispatch(this.slice.actions.setToc(r))}dispatch(...t){for(let r of t)this.store.dispatch(r)}}const gt=n.css`
1
+ !function(t,r,n,e){function i(t){for(var r=arguments.length,n=Array(r>1?r-1:0),e=1;e<r;e++)n[e-1]=arguments[e];throw Error("[Immer] minified error nr: "+t+(n.length?" "+n.map((function(t){return"'"+t+"'"})).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function o(t){return!!t&&!!t[V]}function u(t){return!!t&&(function(t){if(!t||"object"!=typeof t)return!1;var r=Object.getPrototypeOf(t);if(null===r)return!0;var n=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return n===Object||"function"==typeof n&&Function.toString.call(n)===J}(t)||Array.isArray(t)||!!t[q]||!!t.constructor[q]||d(t)||v(t))}function s(t,r,n){void 0===n&&(n=!1),0===a(t)?(n?Object.keys:W)(t).forEach((function(e){n&&"symbol"==typeof e||r(e,t[e],t)})):t.forEach((function(n,e){return r(e,n,t)}))}function a(t){var r=t[V];return r?r.i>3?r.i-4:r.i:Array.isArray(t)?1:d(t)?2:v(t)?3:0}function c(t,r){return 2===a(t)?t.has(r):Object.prototype.hasOwnProperty.call(t,r)}function f(t,r,n){var e=a(t);2===e?t.set(r,n):3===e?(t.delete(r),t.add(n)):t[r]=n}function l(t,r){return t===r?0!==t||1/t==1/r:t!=t&&r!=r}function d(t){return L&&t instanceof Map}function v(t){return $&&t instanceof Set}function h(t){return t.o||t.t}function p(t){if(Array.isArray(t))return Array.prototype.slice.call(t);var r=X(t);delete r[V];for(var n=W(r),e=0;e<n.length;e++){var i=n[e],o=r[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(r[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:t[i]})}return Object.create(Object.getPrototypeOf(t),r)}function b(t,r){return void 0===r&&(r=!1),w(t)||o(t)||!u(t)||(a(t)>1&&(t.set=t.add=t.clear=t.delete=y),Object.freeze(t),r&&s(t,(function(t,r){return b(r,!0)}),!0)),t}function y(){i(2)}function w(t){return null==t||"object"!=typeof t||Object.isFrozen(t)}function m(t){var r=Y[t];return r||i(18,t),r}function g(){return F}function j(t,r){r&&(m("Patches"),t.u=[],t.s=[],t.v=r)}function I(t){O(t),t.p.forEach(A),t.p=null}function O(t){t===F&&(F=t.l)}function T(t){return F={p:[],l:F,h:t,m:!0,_:0}}function A(t){var r=t[V];0===r.i||1===r.i?r.j():r.O=!0}function P(t,r){r._=r.p.length;var n=r.p[0],e=void 0!==t&&t!==n;return r.h.g||m("ES5").S(r,t,e),e?(n[V].P&&(I(r),i(4)),u(t)&&(t=S(r,t),r.l||M(r,t)),r.u&&m("Patches").M(n[V].t,t,r.u,r.s)):t=S(r,n,[]),I(r),r.u&&r.v(r.u,r.s),t!==K?t:void 0}function S(t,r,n){if(w(r))return r;var e=r[V];if(!e)return s(r,(function(i,o){return E(t,e,r,i,o,n)}),!0),r;if(e.A!==t)return r;if(!e.P)return M(t,e.t,!0),e.t;if(!e.I){e.I=!0,e.A._--;var i=4===e.i||5===e.i?e.o=p(e.k):e.o;s(3===e.i?new Set(i):i,(function(r,o){return E(t,e,i,r,o,n)})),M(t,i,!1),n&&t.u&&m("Patches").R(e,n,t.u,t.s)}return e.o}function E(t,r,n,e,i,s){if(o(i)){var a=S(t,i,s&&r&&3!==r.i&&!c(r.D,e)?s.concat(e):void 0);if(f(n,e,a),!o(a))return;t.m=!1}if(u(i)&&!w(i)){if(!t.h.F&&t._<1)return;S(t,i),r&&r.A.l||M(t,i)}}function M(t,r,n){void 0===n&&(n=!1),t.h.F&&t.m&&b(r,n)}function R(t,r){var n=t[V];return(n?h(n):t)[r]}function C(t,r){if(r in t)for(var n=Object.getPrototypeOf(t);n;){var e=Object.getOwnPropertyDescriptor(n,r);if(e)return e;n=Object.getPrototypeOf(n)}}function U(t){t.P||(t.P=!0,t.l&&U(t.l))}function _(t){t.o||(t.o=p(t.t))}function x(t,r,n){var e=d(r)?m("MapSet").N(r,n):v(r)?m("MapSet").T(r,n):t.g?function(t,r){var n=Array.isArray(t),e={i:n?1:0,A:r?r.A:g(),P:!1,I:!1,D:{},l:r,t,k:null,o:null,j:null,C:!1},i=e,o=z;n&&(i=[e],o=H);var u=Proxy.revocable(i,o),s=u.revoke,a=u.proxy;return e.k=a,e.j=s,a}(r,n):m("ES5").J(r,n);return(n?n.A:g()).p.push(e),e}function B(t){return o(t)||i(22,t),function t(r){if(!u(r))return r;var n,e=r[V],i=a(r);if(e){if(!e.P&&(e.i<4||!m("ES5").K(e)))return e.t;e.I=!0,n=D(r,i),e.I=!1}else n=D(r,i);return s(n,(function(r,i){e&&function(t,r){return 2===a(t)?t.get(r):t[r]}(e.t,r)===i||f(n,r,t(i))})),3===i?new Set(n):n}(t)}function D(t,r){switch(r){case 2:return new Map(t);case 3:return Array.from(t)}return p(t)}var N,F,k="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),L="undefined"!=typeof Map,$="undefined"!=typeof Set,G="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,K=k?Symbol.for("immer-nothing"):((N={})["immer-nothing"]=!0,N),q=k?Symbol.for("immer-draftable"):"__$immer_draftable",V=k?Symbol.for("immer-state"):"__$immer_state",J=""+Object.prototype.constructor,W="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Object.getOwnPropertyNames,X=Object.getOwnPropertyDescriptors||function(t){var r={};return W(t).forEach((function(n){r[n]=Object.getOwnPropertyDescriptor(t,n)})),r},Y={},z={get:function(t,r){if(r===V)return t;var n=h(t);if(!c(n,r))return function(t,r,n){var e,i=C(r,n);return i?"value"in i?i.value:null===(e=i.get)||void 0===e?void 0:e.call(t.k):void 0}(t,n,r);var e=n[r];return t.I||!u(e)?e:e===R(t.t,r)?(_(t),t.o[r]=x(t.A.h,e,t)):e},has:function(t,r){return r in h(t)},ownKeys:function(t){return Reflect.ownKeys(h(t))},set:function(t,r,n){var e=C(h(t),r);if(null==e?void 0:e.set)return e.set.call(t.k,n),!0;if(!t.P){var i=R(h(t),r),o=null==i?void 0:i[V];if(o&&o.t===n)return t.o[r]=n,t.D[r]=!1,!0;if(l(n,i)&&(void 0!==n||c(t.t,r)))return!0;_(t),U(t)}return t.o[r]===n&&"number"!=typeof n&&(void 0!==n||r in t.o)||(t.o[r]=n,t.D[r]=!0,!0)},deleteProperty:function(t,r){return void 0!==R(t.t,r)||r in t.t?(t.D[r]=!1,_(t),U(t)):delete t.D[r],t.o&&delete t.o[r],!0},getOwnPropertyDescriptor:function(t,r){var n=h(t),e=Reflect.getOwnPropertyDescriptor(n,r);return e?{writable:!0,configurable:1!==t.i||"length"!==r,enumerable:e.enumerable,value:n[r]}:e},defineProperty:function(){i(11)},getPrototypeOf:function(t){return Object.getPrototypeOf(t.t)},setPrototypeOf:function(){i(12)}},H={};s(z,(function(t,r){H[t]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}})),H.deleteProperty=function(t,r){return H.set.call(this,t,r,void 0)},H.set=function(t,r,n){return z.set.call(this,t[0],r,n,t[0])};var Q=function(){function t(t){var r=this;this.g=G,this.F=!0,this.produce=function(t,n,e){if("function"==typeof t&&"function"!=typeof n){var o=n;n=t;var s=r;return function(t){var r=this;void 0===t&&(t=o);for(var e=arguments.length,i=Array(e>1?e-1:0),u=1;u<e;u++)i[u-1]=arguments[u];return s.produce(t,(function(t){var e;return(e=n).call.apply(e,[r,t].concat(i))}))}}var a;if("function"!=typeof n&&i(6),void 0!==e&&"function"!=typeof e&&i(7),u(t)){var c=T(r),f=x(r,t,void 0),l=!0;try{a=n(f),l=!1}finally{l?I(c):O(c)}return"undefined"!=typeof Promise&&a instanceof Promise?a.then((function(t){return j(c,e),P(t,c)}),(function(t){throw I(c),t})):(j(c,e),P(a,c))}if(!t||"object"!=typeof t){if(void 0===(a=n(t))&&(a=t),a===K&&(a=void 0),r.F&&b(a,!0),e){var d=[],v=[];m("Patches").M(t,a,d,v),e(d,v)}return a}i(21,t)},this.produceWithPatches=function(t,n){if("function"==typeof t)return function(n){for(var e=arguments.length,i=Array(e>1?e-1:0),o=1;o<e;o++)i[o-1]=arguments[o];return r.produceWithPatches(n,(function(r){return t.apply(void 0,[r].concat(i))}))};var e,i,o=r.produce(t,n,(function(t,r){e=t,i=r}));return"undefined"!=typeof Promise&&o instanceof Promise?o.then((function(t){return[t,e,i]})):[o,e,i]},"boolean"==typeof(null==t?void 0:t.useProxies)&&this.setUseProxies(t.useProxies),"boolean"==typeof(null==t?void 0:t.autoFreeze)&&this.setAutoFreeze(t.autoFreeze)}var r=t.prototype;return r.createDraft=function(t){u(t)||i(8),o(t)&&(t=B(t));var r=T(this),n=x(this,t,void 0);return n[V].C=!0,O(r),n},r.finishDraft=function(t,r){var n=(t&&t[V]).A;return j(n,r),P(void 0,n)},r.setAutoFreeze=function(t){this.F=t},r.setUseProxies=function(t){t&&!G&&i(20),this.g=t},r.applyPatches=function(t,r){var n;for(n=r.length-1;n>=0;n--){var e=r[n];if(0===e.path.length&&"replace"===e.op){t=e.value;break}}n>-1&&(r=r.slice(n+1));var i=m("Patches").$;return o(t)?i(t,r):this.produce(t,(function(t){return i(t,r)}))},t}(),Z=new Q,tt=Z.produce;Z.produceWithPatches.bind(Z),Z.setAutoFreeze.bind(Z),Z.setUseProxies.bind(Z),Z.applyPatches.bind(Z),Z.createDraft.bind(Z),Z.finishDraft.bind(Z);var rt,nt=tt,et=(rt=function(t,r){return rt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])},rt(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}rt(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}),it=function(t,r){for(var n=0,e=r.length,i=t.length;n<e;n++,i++)t[i]=r[n];return t},ot=Object.defineProperty,ut=Object.getOwnPropertySymbols,st=Object.prototype.hasOwnProperty,at=Object.prototype.propertyIsEnumerable,ct=function(t,r,n){return r in t?ot(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n},ft=function(t,r){for(var n in r||(r={}))st.call(r,n)&&ct(t,n,r[n]);if(ut)for(var e=0,i=ut(r);e<i.length;e++){n=i[e];at.call(r,n)&&ct(t,n,r[n])}return t};function lt(t){return u(t)?nt(t,(function(){})):t}function dt(t,r){function n(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];if(r){var i=r.apply(void 0,n);if(!i)throw new Error("prepareAction did not return an object");return ft(ft({type:t,payload:i.payload},"meta"in i&&{meta:i.meta}),"error"in i&&{error:i.error})}return{type:t,payload:n[0]}}return n.toString=function(){return""+t},n.type=t,n.match=function(r){return r.type===t},n}function vt(t){var r,n={},e=[],i={addCase:function(t,r){var e="string"==typeof t?t:t.type;if(e in n)throw new Error("addCase cannot be called with two reducers for the same action type");return n[e]=r,i},addMatcher:function(t,r){return e.push({matcher:t,reducer:r}),i},addDefaultCase:function(t){return r=t,i}};return t(i),[n,e,r]}function ht(t){var r=t.name;if(!r)throw new Error("`name` is a required option for createSlice");var n,e="function"==typeof t.initialState?t.initialState:lt(t.initialState),i=t.reducers||{},s=Object.keys(i),a={},c={},f={};function l(){var r="function"==typeof t.extraReducers?vt(t.extraReducers):[t.extraReducers],n=r[0],i=void 0===n?{}:n,s=r[1],a=void 0===s?[]:s,f=r[2],l=void 0===f?void 0:f,d=ft(ft({},i),c);return function(t,r,n,e){void 0===n&&(n=[]);var i,s="function"==typeof r?vt(r):[r,n,e],a=s[0],c=s[1],f=s[2];if(function(t){return"function"==typeof t}(t))i=function(){return lt(t())};else{var l=lt(t);i=function(){return l}}function d(t,r){void 0===t&&(t=i());var n=it([a[r.type]],c.filter((function(t){return(0,t.matcher)(r)})).map((function(t){return t.reducer})));return 0===n.filter((function(t){return!!t})).length&&(n=[f]),n.reduce((function(t,n){if(n){var e;if(o(t))return void 0===(e=n(t,r))?t:e;if(u(t))return nt(t,(function(t){return n(t,r)}));if(void 0===(e=n(t,r))){if(null===t)return t;throw Error("A case reducer on a non-draftable value must not return undefined")}return e}return t}),t)}return d.getInitialState=i,d}(e,d,a,l)}return s.forEach((function(t){var n,e,o=i[t],u=r+"/"+t;"reducer"in o?(n=o.reducer,e=o.prepare):n=o,a[t]=n,c[u]=n,f[t]=e?dt(u,e):dt(u)})),{name:r,reducer:function(t,r){return n||(n=l()),n(t,r)},actions:f,caseReducers:a,getInitialState:function(){return n||(n=l()),n.getInitialState()}}}!function(t){function r(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];var i=t.apply(this,n)||this;return Object.setPrototypeOf(i,r.prototype),i}et(r,t),Object.defineProperty(r,Symbol.species,{get:function(){return r},enumerable:!1,configurable:!0}),r.prototype.concat=function(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];return t.prototype.concat.apply(this,r)},r.prototype.prepend=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return 1===t.length&&Array.isArray(t[0])?new(r.bind.apply(r,it([void 0],t[0].concat(this)))):new(r.bind.apply(r,it([void 0],t.concat(this))))}}(Array);var pt="listenerMiddleware";dt(pt+"/add"),dt(pt+"/removeAll"),dt(pt+"/remove"),function(){function t(t,r){var n=i[t];return n?n.enumerable=r:i[t]=n={configurable:!0,enumerable:r,get:function(){var r=this[V];return z.get(r,t)},set:function(r){var n=this[V];z.set(n,t,r)}},n}function r(t){for(var r=t.length-1;r>=0;r--){var i=t[r][V];if(!i.P)switch(i.i){case 5:e(i)&&U(i);break;case 4:n(i)&&U(i)}}}function n(t){for(var r=t.t,n=t.k,e=W(n),i=e.length-1;i>=0;i--){var o=e[i];if(o!==V){var u=r[o];if(void 0===u&&!c(r,o))return!0;var s=n[o],a=s&&s[V];if(a?a.t!==u:!l(s,u))return!0}}var f=!!r[V];return e.length!==W(r).length+(f?0:1)}function e(t){var r=t.k;if(r.length!==t.t.length)return!0;var n=Object.getOwnPropertyDescriptor(r,r.length-1);if(n&&!n.get)return!0;for(var e=0;e<r.length;e++)if(!r.hasOwnProperty(e))return!0;return!1}var i={};!function(t,r){Y[t]||(Y[t]=r)}("ES5",{J:function(r,n){var e=Array.isArray(r),i=function(r,n){if(r){for(var e=Array(n.length),i=0;i<n.length;i++)Object.defineProperty(e,""+i,t(i,!0));return e}var o=X(n);delete o[V];for(var u=W(o),s=0;s<u.length;s++){var a=u[s];o[a]=t(a,r||!!o[a].enumerable)}return Object.create(Object.getPrototypeOf(n),o)}(e,r),o={i:e?5:4,A:n?n.A:g(),P:!1,I:!1,D:{},l:n,t:r,k:i,o:null,O:!1,C:!1};return Object.defineProperty(i,V,{value:o,writable:!0}),i},S:function(t,n,i){i?o(n)&&n[V].A===t&&r(t.p):(t.u&&function t(r){if(r&&"object"==typeof r){var n=r[V];if(n){var i=n.t,o=n.k,u=n.D,a=n.i;if(4===a)s(o,(function(r){r!==V&&(void 0!==i[r]||c(i,r)?u[r]||t(o[r]):(u[r]=!0,U(n)))})),s(i,(function(t){void 0!==o[t]||c(o,t)||(u[t]=!1,U(n))}));else if(5===a){if(e(n)&&(U(n),u.length=!0),o.length<i.length)for(var f=o.length;f<i.length;f++)u[f]=!1;else for(var l=i.length;l<o.length;l++)u[l]=!0;for(var d=Math.min(o.length,i.length),v=0;v<d;v++)o.hasOwnProperty(v)||(u[v]=!0),void 0===u[v]&&t(o[v])}}}}(t.p[0]),r(t.p))},K:function(t){return 4===t.i?n(t):e(t)}})}();const bt={setBaseUrl:(t,r)=>{t.baseUrl=r.payload},setApiIntegrationIdentifier:(t,r)=>{t.apiIntegrationIdentifier=r.payload},setMapId:(t,r)=>{t.mapId=r.payload},setTocId:(t,r)=>{t.tocId=r.payload},setMap:(t,r)=>{t.map=r.payload},setToc:(t,r)=>{t.toc=r.payload},setCurrentPage:(t,r)=>{t.currentPage=r.payload},setScrollTarget:(t,r)=>{t.scrollTarget=r.payload},setVisibleTopics:(t,r)=>{t.visibleTopics=r.payload},setRenderBeforeFirst:(t,r)=>{t.renderBeforeFirst=r.payload},setRenderAfterLast:(t,r)=>{t.renderAfterLast=r.payload}};class yt{convertNodes(t){var r,n,e,i;const o={},u=new Set,s=new Set,a=[],c=(t,r,n)=>t.map((t=>{var e;t.page&&a.push(t.tocId);let i=null===(e=t.prettyUrl)||void 0===e?void 0:e.replace(/^\//,"");const f={...t,prettyUrl:i,depth:r,parentTocId:n,children:c(t.children,r+1,t.tocId)};return i&&(u.has(i)&&s.add(i),u.add(i)),o[t.tocId]=f,f})),f=c(null!=t?t:[],1),l=this.buildPages(a,o);let d={};return 0===l.length?l.push({number:1,title:null!==(n=null===(r=f[0])||void 0===r?void 0:r.title)&&void 0!==n?n:"",rootTocId:null!==(i=null===(e=f[0])||void 0===e?void 0:e.tocId)&&void 0!==i?i:"root",toc:[],topics:this.tocIds(f),hiddenTopics:[],breadcrumb:[]}):d=this.indexPages(l),{toc:f,nodeByTocId:o,duplicatedPrettyUrls:s,pages:l,pageByTocId:d}}tocIds(t){return t.flatMap((t=>[t.tocId,...this.tocIds(t.children)]))}buildPages(t,r){return t.map((t=>r[t])).map(((t,n)=>{var e,i,o,u,s;const a={number:n+1,title:t.title,rootTocId:t.tocId,toc:(null===(e=t.page)||void 0===e?void 0:e.onItsOwn)?[]:t.children,topics:[],hiddenTopics:[],breadcrumb:this.buildBreadcrumb(t,r)},c=(t,r)=>(r?a.topics:a.hiddenTopics).push(t),f=null!==(o=null===(i=t.page)||void 0===i?void 0:i.parentsVisibility)&&void 0!==o?o:[];return a.breadcrumb.forEach(((t,r)=>{c(t,f[r])})),c(t.tocId,null===(u=t.page)||void 0===u?void 0:u.visible),(null===(s=t.page)||void 0===s?void 0:s.onItsOwn)||a.topics.push(...this.tocIds(t.children)),a}))}buildBreadcrumb(t,r){const n=[];for(;null==t?void 0:t.parentTocId;)n.unshift(t.parentTocId),t=r[t.parentTocId];return n}indexPages(t){const r={};for(let n of t)for(let t of[...n.topics,...n.hiddenTopics])r[t]||(r[t]=n);return r}}class wt{constructor(t,r,n,e){this.converter=t,this.api=r,this.baseUrl=n,this.mapId=e,this.topics={},this.topicContents={},n.endsWith("/")||(this.baseUrl=n+"/")}static build(t,r,n){if(null==window.fluidtopics)throw console.error("Fluid Topics public API was not found. You can find it here: https://www.npmjs.com/package/@fluid-topics/public-api"),new Error("Fluid Topics public API not found");return new wt(new yt,new window.fluidtopics.FluidTopicsApi(t,r,!0),t,n)}clear(){this.map=void 0,this.enrichedToc=void 0,this.topics={},this.topicContents={}}getMap(){return this.loadIfNeeded((()=>this.map),(t=>this.map=t),(()=>this.api.getMap(this.mapId)))}getEnrichedToc(){return this.loadIfNeeded((()=>this.enrichedToc),(t=>this.enrichedToc=t),(()=>this.api.getTableOfContent(this.mapId).then((t=>this.converter.convertNodes(t)))))}async getToc(){return(await this.getEnrichedToc()).toc}async getTocNode(t){return(await this.getEnrichedToc()).nodeByTocId[t]}getTocNodeOrThrow(t){if("boolean"==typeof this.enrichedToc)throw new Error((this.enrichedToc," still loading"));return this.enrichedToc.nodeByTocId[t]}async getPage(t){const r=await this.getEnrichedToc();return r.pages[t-1]||r.pages[0]}async getPageByTocId(t){const r=await this.getEnrichedToc();return r.pageByTocId[t]||r.pages[0]}getTopicInfo(t){return this.loadIfNeeded((()=>this.topics[t]),(r=>this.topics[t]=r),(()=>this.api.getTopic(this.mapId,t)))}getTopicContent(t){return this.loadIfNeeded((()=>this.topicContents[t]),(r=>this.topicContents[t]=r),(()=>this.api.getTopicHTMLContent(this.mapId,t,"DESIGNED_READER")))}getLink(t,r,n){const e=this.getNavigationData(t,r,n),i="r/"+(e.prettyUrl?e.prettyUrl:`${e.mapId}/${e.tocId}`),o=new URL(i,this.baseUrl);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,r,n){var e,i;t=t||"root";const o="object"==typeof this.enrichedToc?this.enrichedToc:void 0,u=null==o?void 0:o.pageByTocId[t],s=null==o?void 0:o.nodeByTocId[t],a=null==s?void 0:s.prettyUrl;return{mapId:this.mapId,tocId:t,topicTitle:null!==(e=null==s?void 0:s.title)&&void 0!==e?e:"",page:r&&u&&u.number!==r?r:void 0,prettyUrl:null!=a?a.replace(/^r\//,""):void 0,prettyUrlDuplicated:null!==(i=null==o?void 0:o.duplicatedPrettyUrls.has(null!=a?a:""))&&void 0!==i&&i,section:n}}async getAccurateNavigationData(t,r,n){return await this.getEnrichedToc(),this.getNavigationData(t,r,n)}async loadIfNeeded(t,n,e){for(void 0===t()&&(n(!0),n(await e().catch((t=>(console.error(t),!1)))));!0===t();)await r.delay(10);const i=t();if(!1===i)throw new Error("Could not load data");return i}}class mt{constructor(t,n){this.store=t,this.slice=n,this.reloadDebouncer=new r.Debouncer(10)}static build(t){const n=(t=>ht({name:"ft-reader-"+t,initialState:{baseUrl:"",apiIntegrationIdentifier:"ft-reader",visibleTopics:[],renderBeforeFirst:2,renderAfterLast:3},reducers:bt}))(t.trim()||"context");return new mt(r.getStore(n),n)}setBaseUrl(t){this.setRequiredStateField("baseUrl","setBaseUrl",t)}setApiIntegrationIdentifier(t){this.setRequiredStateField("apiIntegrationIdentifier","setApiIntegrationIdentifier",t)}setMapId(t){this.setRequiredStateField("mapId","setMapId",t)}setRenderBeforeFirst(t){this.dispatch(this.slice.actions.setRenderBeforeFirst(t))}setRenderAfterLast(t){this.dispatch(this.slice.actions.setRenderAfterLast(t))}setVisibleTopics(t){this.dispatch(this.slice.actions.setVisibleTopics(t))}async navigateToTopic(t,n,e){for(;null==this.service;)await r.delay(5);let i=null!=e?await this.service.getPage(e):await this.service.getPageByTocId(t);this.dispatch(this.slice.actions.setCurrentPage(i),this.slice.actions.setScrollTarget({tocId:t,section:n}))}async navigateToPage(t){for(;null==this.service;)await r.delay(5);let n=await this.service.getPage(t);this.dispatch(this.slice.actions.setCurrentPage(n))}scrollDone(){this.dispatch(this.slice.actions.setScrollTarget({}))}setRequiredStateField(t,r,n){this.store.getState()[t]!==n&&(this.dispatch(this.slice.actions[r](n)),this.clearAll(),this.reload())}clearAll(){this.dispatch(this.slice.actions.setMap(void 0),this.slice.actions.setToc(void 0),this.slice.actions.setCurrentPage(void 0))}reload(){const t=this.store.getState();t.baseUrl&&t.apiIntegrationIdentifier&&t.mapId?this.service=wt.build(t.baseUrl,t.apiIntegrationIdentifier,t.mapId):this.service=void 0,this.reloadDebouncer.run((async()=>{this.reloadMap(),this.reloadToc()}))}async reloadMap(){var t;const r=await(null===(t=this.service)||void 0===t?void 0:t.getMap());this.dispatch(this.slice.actions.setMap(r))}async reloadToc(){var t;const r=await(null===(t=this.service)||void 0===t?void 0:t.getToc());this.dispatch(this.slice.actions.setToc(r))}dispatch(...t){for(let r of t)this.store.dispatch(r)}}const gt=n.css`
2
2
  `;var jt=function(t,r,n,e){for(var i,o=arguments.length,u=o<3?r:null===e?e=Object.getOwnPropertyDescriptor(r,n):e,s=t.length-1;s>=0;s--)(i=t[s])&&(u=(o<3?i(u):o>3?i(r,n,u):i(r,n))||u);return o>3&&u&&Object.defineProperty(r,n,u),u};class It extends CustomEvent{constructor(t,r){super("ft-reader-map-loaded",{detail:{map:t,toc:r}})}}class Ot extends CustomEvent{constructor(t,r){super("ft-reader-visible-topics-change",{detail:{visibleTopics:r}})}}class Tt extends CustomEvent{constructor(t){super("ft-reader-navigation-done",{detail:t})}}const At=t=>r=>+(null!=r?r:"NaN")>0?+r:t;class Pt extends r.FtLitElementRedux{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-reader",this.renderBeforeFirst=2,this.renderAfterLast=3,this.visibleTopics=[],this.navigationDebouncer=new r.Debouncer(5)}render(){return n.html`
3
3
  <slot @register-ft-reader-component=${this.registerComponent}></slot>
4
- `}get stateManager(){return null==this._stateManager&&(this._stateManager=wt.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this.store=this.stateManager.store),this._stateManager}updated(t){super.updated(t),t.has("baseUrl")&&this.baseUrl&&this.stateManager.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&this.stateManager.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("mapId")&&this.mapId&&(this.stateManager.setMapId(this.mapId),this.stateManager.navigateToTopic("root")),t.has("page")&&!this.tocId&&null!=this.page&&this.stateManager.navigateToPage(this.page),(t.has("tocId")||t.has("section")||t.has("page"))&&this.tocId&&this.stateManager.navigateToTopic(this.tocId,this.section,this.page),t.has("renderBeforeFirst")&&this.stateManager.setRenderBeforeFirst(this.renderBeforeFirst),t.has("renderAfterLast")&&this.stateManager.setRenderAfterLast(this.renderAfterLast)}contentAvailableCallback(t){var r;if(super.contentAvailableCallback(t),(t.has("map")||t.has("toc"))&&this.map&&this.toc&&this.dispatchEvent(new It(this.map,this.toc)),t.has("scrollTarget")&&null==(null===(r=this.scrollTarget)||void 0===r?void 0:r.tocId)){const r=t.get("scrollTarget");null!=(null==r?void 0:r.tocId)&&this.navigationDebouncer.run((()=>this.stateManager.service.getAccurateNavigationData(r.tocId,this.currentPageNumber,r.section).then((t=>this.dispatchEvent(new Tt(t))))))}t.has("visibleTopics")&&Promise.all(this.visibleTopics.map((t=>this.stateManager.service.getAccurateNavigationData(t,this.currentPageNumber)))).then((t=>{let r=t.filter((t=>null!=t&&""!==t.topicTitle)).map((t=>({tocId:t.tocId,title:t.topicTitle,page:t.page,prettyUrl:t.prettyUrl,prettyUrlDuplicated:t.prettyUrlDuplicated})));this.dispatchEvent(new Ot(this.map,r))}))}navigateToTarget(){null!=this.tocId?this.stateManager.navigateToTopic(this.tocId,this.section,this.page):null!=this.page&&this.stateManager.navigateToPage(this.page)}registerComponent(t){t.stopPropagation();t.composedPath()[0].setReaderStateManager(this.stateManager)}}Pt.styles=gt,jt([e.property()],Pt.prototype,"baseUrl",void 0),jt([e.property()],Pt.prototype,"apiIntegrationIdentifier",void 0),jt([e.property()],Pt.prototype,"mapId",void 0),jt([e.property()],Pt.prototype,"tocId",void 0),jt([e.property()],Pt.prototype,"section",void 0),jt([e.property({type:Number,converter:{fromAttribute:At()}})],Pt.prototype,"page",void 0),jt([e.property({type:Number,converter:{fromAttribute:At(2)}})],Pt.prototype,"renderBeforeFirst",void 0),jt([e.property({type:Number,converter:{fromAttribute:At(3)}})],Pt.prototype,"renderAfterLast",void 0),jt([r.redux()],Pt.prototype,"map",void 0),jt([r.redux()],Pt.prototype,"toc",void 0),jt([r.redux()],Pt.prototype,"visibleTopics",void 0),jt([r.redux((t=>{var r;return null===(r=t.currentPage)||void 0===r?void 0:r.number}))],Pt.prototype,"currentPageNumber",void 0),jt([r.redux()],Pt.prototype,"scrollTarget",void 0),r.customElement("ft-reader-context")(Pt),t.FtReaderContext=Pt,t.FtReaderContextCssVariables={},t.MapLoadedEvent=It,t.NavigationDoneEvent=Tt,t.VisibleTopicsChangeEvent=Ot,t.styles=gt,Object.defineProperty(t,"U",{value:!0})}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);
4
+ `}get stateManager(){return null==this._stateManager&&(this._stateManager=mt.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this.store=this.stateManager.store),this._stateManager}updated(t){super.updated(t),t.has("baseUrl")&&this.baseUrl&&this.stateManager.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&this.stateManager.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("mapId")&&this.mapId&&(this.stateManager.setMapId(this.mapId),this.stateManager.navigateToTopic("root")),t.has("page")&&!this.tocId&&null!=this.page&&this.stateManager.navigateToPage(this.page),(t.has("tocId")||t.has("section")||t.has("page"))&&this.tocId&&this.stateManager.navigateToTopic(this.tocId,this.section,this.page),t.has("renderBeforeFirst")&&this.stateManager.setRenderBeforeFirst(this.renderBeforeFirst),t.has("renderAfterLast")&&this.stateManager.setRenderAfterLast(this.renderAfterLast)}contentAvailableCallback(t){var r;if(super.contentAvailableCallback(t),(t.has("map")||t.has("toc"))&&this.map&&this.toc&&this.dispatchEvent(new It(this.map,this.toc)),t.has("scrollTarget")&&null==(null===(r=this.scrollTarget)||void 0===r?void 0:r.tocId)){const r=t.get("scrollTarget");null!=(null==r?void 0:r.tocId)&&this.navigationDebouncer.run((()=>{var t;return this.stateManager.service.getAccurateNavigationData(r.tocId,null===(t=this.currentPage)||void 0===t?void 0:t.number,r.section).then((t=>this.dispatchEvent(new Tt(t))))}))}t.has("visibleTopics")&&Promise.all(this.visibleTopics.map((t=>{var r;return this.stateManager.service.getAccurateNavigationData(t,null===(r=this.currentPage)||void 0===r?void 0:r.number)}))).then((t=>{let r=t.filter((t=>null!=t&&""!==t.topicTitle)).map((t=>({tocId:t.tocId,title:t.topicTitle,page:t.page,prettyUrl:t.prettyUrl,prettyUrlDuplicated:t.prettyUrlDuplicated})));this.dispatchEvent(new Ot(this.map,r))}))}navigateToTarget(){null!=this.tocId?this.stateManager.navigateToTopic(this.tocId,this.section,this.page):null!=this.page&&this.stateManager.navigateToPage(this.page)}registerComponent(t){t.stopPropagation();t.composedPath()[0].setReaderStateManager(this.stateManager)}}Pt.styles=gt,jt([e.property()],Pt.prototype,"baseUrl",void 0),jt([e.property()],Pt.prototype,"apiIntegrationIdentifier",void 0),jt([e.property()],Pt.prototype,"mapId",void 0),jt([e.property()],Pt.prototype,"tocId",void 0),jt([e.property()],Pt.prototype,"section",void 0),jt([e.property({type:Number,converter:{fromAttribute:At()}})],Pt.prototype,"page",void 0),jt([e.property({type:Number,converter:{fromAttribute:At(2)}})],Pt.prototype,"renderBeforeFirst",void 0),jt([e.property({type:Number,converter:{fromAttribute:At(3)}})],Pt.prototype,"renderAfterLast",void 0),jt([r.redux()],Pt.prototype,"map",void 0),jt([r.redux()],Pt.prototype,"toc",void 0),jt([r.redux()],Pt.prototype,"visibleTopics",void 0),jt([r.redux()],Pt.prototype,"currentPage",void 0),jt([r.redux()],Pt.prototype,"scrollTarget",void 0),r.customElement("ft-reader-context")(Pt),t.FtReaderContext=Pt,t.FtReaderContextCssVariables={},t.MapLoadedEvent=It,t.NavigationDoneEvent=Tt,t.VisibleTopicsChangeEvent=Ot,t.styles=gt,Object.defineProperty(t,"U",{value:!0})}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators);
@@ -81,4 +81,4 @@ function(t){return class extends t{createRenderRoot(){const t=this.constructor,{
81
81
  `;var Dt,Kt,Ht="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),zt="undefined"!=typeof Map,Jt="undefined"!=typeof Set,Vt="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,Zt=Ht?Symbol.for("immer-nothing"):((Dt={})["immer-nothing"]=!0,Dt),qt=Ht?Symbol.for("immer-draftable"):"__$immer_draftable",Xt=Ht?Symbol.for("immer-state"):"__$immer_state",Gt=""+Object.prototype.constructor,Yt="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Object.getOwnPropertyNames,Qt=Object.getOwnPropertyDescriptors||function(t){var e={};return Yt(t).forEach((function(i){e[i]=Object.getOwnPropertyDescriptor(t,i)})),e},te={},ee={get:function(t,e){if(e===Xt)return t;var i=mt(t);if(!vt(i,e))return function(t,e,i){var n,r=Ft(e,i);return r?"value"in r?r.value:null===(n=r.get)||void 0===n?void 0:n.call(t.k):void 0}(t,i,e);var n=i[e];return t.I||!ft(n)?n:n===kt(t.t,e)?(Lt(t),t.o[e]=_t(t.A.h,n,t)):n},has:function(t,e){return e in mt(t)},ownKeys:function(t){return Reflect.ownKeys(mt(t))},set:function(t,e,i){var n=Ft(mt(t),e);if(null==n?void 0:n.set)return n.set.call(t.k,i),!0;if(!t.P){var r=kt(mt(t),e),o=null==r?void 0:r[Xt];if(o&&o.t===i)return t.o[e]=i,t.D[e]=!1,!0;if(bt(i,r)&&(void 0!==i||vt(t.t,e)))return!0;Lt(t),Pt(t)}return t.o[e]===i&&"number"!=typeof i&&(void 0!==i||e in t.o)||(t.o[e]=i,t.D[e]=!0,!0)},deleteProperty:function(t,e){return void 0!==kt(t.t,e)||e in t.t?(t.D[e]=!1,Lt(t),Pt(t)):delete t.D[e],t.o&&delete t.o[e],!0},getOwnPropertyDescriptor:function(t,e){var i=mt(t),n=Reflect.getOwnPropertyDescriptor(i,e);return n?{writable:!0,configurable:1!==t.i||"length"!==e,enumerable:n.enumerable,value:i[e]}:n},defineProperty:function(){ct(11)},getPrototypeOf:function(t){return Object.getPrototypeOf(t.t)},setPrototypeOf:function(){ct(12)}},ie={};ht(ee,(function(t,e){ie[t]=function(){return arguments[0]=arguments[0][0],e.apply(this,arguments)}})),ie.deleteProperty=function(t,e){return ie.set.call(this,t,e,void 0)},ie.set=function(t,e,i){return ee.set.call(this,t[0],e,i,t[0])};var ne=function(){function t(t){var e=this;this.g=Vt,this.F=!0,this.produce=function(t,i,n){if("function"==typeof t&&"function"!=typeof i){var r=i;i=t;var o=e;return function(t){var e=this;void 0===t&&(t=r);for(var n=arguments.length,s=Array(n>1?n-1:0),u=1;u<n;u++)s[u-1]=arguments[u];return o.produce(t,(function(t){var n;return(n=i).call.apply(n,[e,t].concat(s))}))}}var s;if("function"!=typeof i&&ct(6),void 0!==n&&"function"!=typeof n&&ct(7),ft(t)){var u=Mt(e),a=_t(e,t,void 0),c=!0;try{s=i(a),c=!1}finally{c?St(u):Ct(u)}return"undefined"!=typeof Promise&&s instanceof Promise?s.then((function(t){return Rt(u,n),Tt(t,u)}),(function(t){throw St(u),t})):(Rt(u,n),Tt(s,u))}if(!t||"object"!=typeof t){if(void 0===(s=i(t))&&(s=t),s===Zt&&(s=void 0),e.F&&xt(s,!0),n){var l=[],f=[];jt("Patches").M(t,s,l,f),n(l,f)}return s}ct(21,t)},this.produceWithPatches=function(t,i){if("function"==typeof t)return function(i){for(var n=arguments.length,r=Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return e.produceWithPatches(i,(function(e){return t.apply(void 0,[e].concat(r))}))};var n,r,o=e.produce(t,i,(function(t,e){n=t,r=e}));return"undefined"!=typeof Promise&&o instanceof Promise?o.then((function(t){return[t,n,r]})):[o,n,r]},"boolean"==typeof(null==t?void 0:t.useProxies)&&this.setUseProxies(t.useProxies),"boolean"==typeof(null==t?void 0:t.autoFreeze)&&this.setAutoFreeze(t.autoFreeze)}var e=t.prototype;return e.createDraft=function(t){ft(t)||ct(8),lt(t)&&(t=Bt(t));var e=Mt(this),i=_t(this,t,void 0);return i[Xt].C=!0,Ct(e),i},e.finishDraft=function(t,e){var i=(t&&t[Xt]).A;return Rt(i,e),Tt(void 0,i)},e.setAutoFreeze=function(t){this.F=t},e.setUseProxies=function(t){t&&!Vt&&ct(20),this.g=t},e.applyPatches=function(t,e){var i;for(i=e.length-1;i>=0;i--){var n=e[i];if(0===n.path.length&&"replace"===n.op){t=n.value;break}}i>-1&&(e=e.slice(i+1));var r=jt("Patches").$;return lt(t)?r(t,e):this.produce(t,(function(t){return r(t,e)}))},t}(),re=new ne,oe=re.produce;re.produceWithPatches.bind(re),re.setAutoFreeze.bind(re),re.setUseProxies.bind(re),re.applyPatches.bind(re),re.createDraft.bind(re),re.finishDraft.bind(re);var se=oe;function ue(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function ae(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function ce(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?ae(Object(i),!0).forEach((function(e){ue(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):ae(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function le(t){return"Minified Redux error #"+t+"; visit https://redux.js.org/Errors?code="+t+" for the full message or use the non-minified dev environment for full errors. "}var fe="function"==typeof Symbol&&Symbol.observable||"@@observable",he=function(){return Math.random().toString(36).substring(7).split("").join(".")},de={INIT:"@@redux/INIT"+he(),REPLACE:"@@redux/REPLACE"+he(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+he()}};function ve(t){if("object"!=typeof t||null===t)return!1;for(var e=t;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}function pe(t,e,i){var n;if("function"==typeof e&&"function"==typeof i||"function"==typeof i&&"function"==typeof arguments[3])throw new Error(le(0));if("function"==typeof e&&void 0===i&&(i=e,e=void 0),void 0!==i){if("function"!=typeof i)throw new Error(le(1));return i(pe)(t,e)}if("function"!=typeof t)throw new Error(le(2));var r=t,o=e,s=[],u=s,a=!1;function c(){u===s&&(u=s.slice())}function l(){if(a)throw new Error(le(3));return o}function f(t){if("function"!=typeof t)throw new Error(le(4));if(a)throw new Error(le(5));var e=!0;return c(),u.push(t),function(){if(e){if(a)throw new Error(le(6));e=!1,c();var i=u.indexOf(t);u.splice(i,1),s=null}}}function h(t){if(!ve(t))throw new Error(le(7));if(void 0===t.type)throw new Error(le(8));if(a)throw new Error(le(9));try{a=!0,o=r(o,t)}finally{a=!1}for(var e=s=u,i=0;i<e.length;i++){(0,e[i])()}return t}function d(t){if("function"!=typeof t)throw new Error(le(10));r=t,h({type:de.REPLACE})}function v(){var t,e=f;return(t={subscribe:function(t){if("object"!=typeof t||null===t)throw new Error(le(11));function i(){t.next&&t.next(l())}return i(),{unsubscribe:e(i)}}})[fe]=function(){return this},t}return h({type:de.INIT}),(n={dispatch:h,subscribe:f,getState:l,replaceReducer:d})[fe]=v,n}function be(t){for(var e=Object.keys(t),i={},n=0;n<e.length;n++){var r=e[n];"function"==typeof t[r]&&(i[r]=t[r])}var o,s=Object.keys(i);try{!function(t){Object.keys(t).forEach((function(e){var i=t[e];if(void 0===i(void 0,{type:de.INIT}))throw new Error(le(12));if(void 0===i(void 0,{type:de.PROBE_UNKNOWN_ACTION()}))throw new Error(le(13))}))}(i)}catch(t){o=t}return function(t,e){if(void 0===t&&(t={}),o)throw o;for(var n=!1,r={},u=0;u<s.length;u++){var a=s[u],c=i[a],l=t[a],f=c(l,e);if(void 0===f)throw e&&e.type,new Error(le(14));r[a]=f,n=n||f!==l}return(n=n||s.length!==Object.keys(t).length)?r:t}}function we(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return 0===e.length?function(t){return t}:1===e.length?e[0]:e.reduce((function(t,e){return function(){return t(e.apply(void 0,arguments))}}))}function ye(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return function(t){return function(){var i=t.apply(void 0,arguments),n=function(){throw new Error(le(15))},r={getState:i.getState,dispatch:function(){return n.apply(void 0,arguments)}},o=e.map((function(t){return t(r)}));return n=we.apply(void 0,o)(i.dispatch),ce(ce({},i),{},{dispatch:n})}}}function me(t){return function(e){var i=e.dispatch,n=e.getState;return function(e){return function(r){return"function"==typeof r?r(i,n,t):e(r)}}}}var ge=me();ge.withExtraArgument=me;var xe,Oe=ge,Ee=(xe=function(t,e){return xe=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},xe(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}xe(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}),je=function(t,e){for(var i=0,n=e.length,r=t.length;i<n;i++,r++)t[r]=e[i];return t},Ne=Object.defineProperty,Re=Object.getOwnPropertySymbols,Se=Object.prototype.hasOwnProperty,Ce=Object.prototype.propertyIsEnumerable,Me=function(t,e,i){return e in t?Ne(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i},Ae=function(t,e){for(var i in e||(e={}))Se.call(e,i)&&Me(t,i,e[i]);if(Re)for(var n=0,r=Re(e);n<r.length;n++){i=r[n];Ce.call(e,i)&&Me(t,i,e[i])}return t},Te="undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__?window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__:function(){if(0!==arguments.length)return"object"==typeof arguments[0]?we:we.apply(null,arguments)};var Ue=function(t){function e(){for(var i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];var r=t.apply(this,i)||this;return Object.setPrototypeOf(r,e.prototype),r}return Ee(e,t),Object.defineProperty(e,Symbol.species,{get:function(){return e},enumerable:!1,configurable:!0}),e.prototype.concat=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];return t.prototype.concat.apply(this,e)},e.prototype.prepend=function(){for(var t=[],i=0;i<arguments.length;i++)t[i]=arguments[i];return 1===t.length&&Array.isArray(t[0])?new(e.bind.apply(e,je([void 0],t[0].concat(this)))):new(e.bind.apply(e,je([void 0],t.concat(this))))},e}(Array);function $e(t){return ft(t)?se(t,(function(){})):t}function Ie(){return function(t){return function(t){void 0===t&&(t={});var e=t.thunk,i=void 0===e||e;t.immutableCheck,t.serializableCheck;var n=new Ue;i&&(!function(t){return"boolean"==typeof t}(i)?n.push(Oe.withExtraArgument(i.extraArgument)):n.push(Oe));return n}(t)}}function ke(t){var e,i=Ie(),n=t||{},r=n.reducer,o=void 0===r?void 0:r,s=n.middleware,u=void 0===s?i():s,a=n.devTools,c=void 0===a||a,l=n.preloadedState,f=void 0===l?void 0:l,h=n.enhancers,d=void 0===h?void 0:h;if("function"==typeof o)e=o;else{if(!function(t){if("object"!=typeof t||null===t)return!1;var e=Object.getPrototypeOf(t);if(null===e)return!0;for(var i=e;null!==Object.getPrototypeOf(i);)i=Object.getPrototypeOf(i);return e===i}(o))throw new Error('"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers');e=be(o)}var v=u;"function"==typeof v&&(v=v(i));var p=ye.apply(void 0,v),b=we;c&&(b=Te(Ae({trace:!1},"object"==typeof c&&c)));var w=[p];return Array.isArray(d)?w=je([p],d):"function"==typeof d&&(w=d(w)),pe(e,f,b.apply(void 0,w))}function Fe(t,e){function i(){for(var i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];if(e){var r=e.apply(void 0,i);if(!r)throw new Error("prepareAction did not return an object");return Ae(Ae({type:t,payload:r.payload},"meta"in r&&{meta:r.meta}),"error"in r&&{error:r.error})}return{type:t,payload:i[0]}}return i.toString=function(){return""+t},i.type=t,i.match=function(e){return e.type===t},i}function Pe(t){var e,i={},n=[],r={addCase:function(t,e){var n="string"==typeof t?t:t.type;if(n in i)throw new Error("addCase cannot be called with two reducers for the same action type");return i[n]=e,r},addMatcher:function(t,e){return n.push({matcher:t,reducer:e}),r},addDefaultCase:function(t){return e=t,r}};return t(r),[i,n,e]}function Le(t){var e=t.name;if(!e)throw new Error("`name` is a required option for createSlice");var i,n="function"==typeof t.initialState?t.initialState:$e(t.initialState),r=t.reducers||{},o=Object.keys(r),s={},u={},a={};function c(){var e="function"==typeof t.extraReducers?Pe(t.extraReducers):[t.extraReducers],i=e[0],r=void 0===i?{}:i,o=e[1],s=void 0===o?[]:o,a=e[2],c=void 0===a?void 0:a,l=Ae(Ae({},r),u);return function(t,e,i,n){void 0===i&&(i=[]);var r,o="function"==typeof e?Pe(e):[e,i,n],s=o[0],u=o[1],a=o[2];if(function(t){return"function"==typeof t}(t))r=function(){return $e(t())};else{var c=$e(t);r=function(){return c}}function l(t,e){void 0===t&&(t=r());var i=je([s[e.type]],u.filter((function(t){return(0,t.matcher)(e)})).map((function(t){return t.reducer})));return 0===i.filter((function(t){return!!t})).length&&(i=[a]),i.reduce((function(t,i){if(i){var n;if(lt(t))return void 0===(n=i(t,e))?t:n;if(ft(t))return se(t,(function(t){return i(t,e)}));if(void 0===(n=i(t,e))){if(null===t)return t;throw Error("A case reducer on a non-draftable value must not return undefined")}return n}return t}),t)}return l.getInitialState=r,l}(n,l,s,c)}return o.forEach((function(t){var i,n,o=r[t],c=e+"/"+t;"reducer"in o?(i=o.reducer,n=o.prepare):i=o,s[t]=i,u[c]=i,a[t]=n?Fe(c,n):Fe(c)})),{name:e,reducer:function(t,e){return i||(i=c()),i(t,e)},actions:a,caseReducers:s,getInitialState:function(){return i||(i=c()),i.getInitialState()}}}var _e="listenerMiddleware";Fe(_e+"/add"),Fe(_e+"/removeAll"),Fe(_e+"/remove"),function(){function t(t,e){var i=r[t];return i?i.enumerable=e:r[t]=i={configurable:!0,enumerable:e,get:function(){var e=this[Xt];return ee.get(e,t)},set:function(e){var i=this[Xt];ee.set(i,t,e)}},i}function e(t){for(var e=t.length-1;e>=0;e--){var r=t[e][Xt];if(!r.P)switch(r.i){case 5:n(r)&&Pt(r);break;case 4:i(r)&&Pt(r)}}}function i(t){for(var e=t.t,i=t.k,n=Yt(i),r=n.length-1;r>=0;r--){var o=n[r];if(o!==Xt){var s=e[o];if(void 0===s&&!vt(e,o))return!0;var u=i[o],a=u&&u[Xt];if(a?a.t!==s:!bt(u,s))return!0}}var c=!!e[Xt];return n.length!==Yt(e).length+(c?0:1)}function n(t){var e=t.k;if(e.length!==t.t.length)return!0;var i=Object.getOwnPropertyDescriptor(e,e.length-1);if(i&&!i.get)return!0;for(var n=0;n<e.length;n++)if(!e.hasOwnProperty(n))return!0;return!1}var r={};!function(t,e){te[t]||(te[t]=e)}("ES5",{J:function(e,i){var n=Array.isArray(e),r=function(e,i){if(e){for(var n=Array(i.length),r=0;r<i.length;r++)Object.defineProperty(n,""+r,t(r,!0));return n}var o=Qt(i);delete o[Xt];for(var s=Yt(o),u=0;u<s.length;u++){var a=s[u];o[a]=t(a,e||!!o[a].enumerable)}return Object.create(Object.getPrototypeOf(i),o)}(n,e),o={i:n?5:4,A:i?i.A:Nt(),P:!1,I:!1,D:{},l:i,t:e,k:r,o:null,O:!1,C:!1};return Object.defineProperty(r,Xt,{value:o,writable:!0}),r},S:function(t,i,r){r?lt(i)&&i[Xt].A===t&&e(t.p):(t.u&&function t(e){if(e&&"object"==typeof e){var i=e[Xt];if(i){var r=i.t,o=i.k,s=i.D,u=i.i;if(4===u)ht(o,(function(e){e!==Xt&&(void 0!==r[e]||vt(r,e)?s[e]||t(o[e]):(s[e]=!0,Pt(i)))})),ht(r,(function(t){void 0!==o[t]||vt(o,t)||(s[t]=!1,Pt(i))}));else if(5===u){if(n(i)&&(Pt(i),s.length=!0),o.length<r.length)for(var a=o.length;a<r.length;a++)s[a]=!1;else for(var c=r.length;c<o.length;c++)s[c]=!0;for(var l=Math.min(o.length,r.length),f=0;f<l;f++)o.hasOwnProperty(f)||(s[f]=!0),void 0===s[f]&&t(o[f])}}}}(t.p[0]),e(t.p))},K:function(t){return 4===t.i?i(t):n(t)}})}();const Be=(t,e)=>(i,n)=>{i.constructor.createProperty(n,{attribute:!1,hasChanged:null!=e?e:(t,e)=>!o(t,e)});const r=i;r.reduxProperties=r.reduxProperties||new Map,r.reduxProperties.set(n,null!=t?t:t=>t[n])};class We extends at{get store(){return this.internalStore}set store(t){this.internalStore=t,this.store&&this.setupStore()}updateFromStore(){const t=this.store.getState();this.reduxProperties&&this.reduxProperties.forEach(((e,i)=>{this[i]=e(t,this)}))}setupStore(){this.unsubscribeFromStore&&this.unsubscribeFromStore(),this.updateFromStore(),this.unsubscribeFromStore=this.store.subscribe((()=>{this.updateFromStore()})),this.onStoreAvailable(),this.requestUpdate()}onStoreAvailable(){}connectedCallback(){super.connectedCallback(),this.store&&this.setupStore()}disconnectedCallback(){this.unsubscribeFromStore&&this.unsubscribeFromStore(),super.disconnectedCallback()}}var De,Ke;navigator.vendor&&navigator.vendor.match(/apple/i)||(null===(Ke=null===(De=window.safari)||void 0===De?void 0:De.pushNotification)||void 0===Ke||Ke.toString());const He={setBaseUrl:(t,e)=>{t.baseUrl=e.payload},setApiIntegrationIdentifier:(t,e)=>{t.apiIntegrationIdentifier=e.payload},setMapId:(t,e)=>{t.mapId=e.payload},setTocId:(t,e)=>{t.tocId=e.payload},setMap:(t,e)=>{t.map=e.payload},setToc:(t,e)=>{t.toc=e.payload},setCurrentPage:(t,e)=>{t.currentPage=e.payload},setScrollTarget:(t,e)=>{t.scrollTarget=e.payload},setVisibleTopics:(t,e)=>{t.visibleTopics=e.payload},setRenderBeforeFirst:(t,e)=>{t.renderBeforeFirst=e.payload},setRenderAfterLast:(t,e)=>{t.renderAfterLast=e.payload}};class ze{convertNodes(t){var e,i,n,r;const o={},s=new Set,u=new Set,a=[],c=(t,e,i)=>t.map((t=>{var n;t.page&&a.push(t.tocId);let r=null===(n=t.prettyUrl)||void 0===n?void 0:n.replace(/^\//,"");const l={...t,prettyUrl:r,depth:e,parentTocId:i,children:c(t.children,e+1,t.tocId)};return r&&(s.has(r)&&u.add(r),s.add(r)),o[t.tocId]=l,l})),l=c(null!=t?t:[],1),f=this.buildPages(a,o);let h={};return 0===f.length?f.push({number:1,title:null!==(i=null===(e=l[0])||void 0===e?void 0:e.title)&&void 0!==i?i:"",rootTocId:null!==(r=null===(n=l[0])||void 0===n?void 0:n.tocId)&&void 0!==r?r:"root",toc:[],topics:this.tocIds(l),hiddenTopics:[],breadcrumb:[]}):h=this.indexPages(f),{toc:l,nodeByTocId:o,duplicatedPrettyUrls:u,pages:f,pageByTocId:h}}tocIds(t){return t.flatMap((t=>[t.tocId,...this.tocIds(t.children)]))}buildPages(t,e){return t.map((t=>e[t])).map(((t,i)=>{var n,r,o,s,u;const a={number:i+1,title:t.title,rootTocId:t.tocId,toc:(null===(n=t.page)||void 0===n?void 0:n.onItsOwn)?[]:t.children,topics:[],hiddenTopics:[],breadcrumb:this.buildBreadcrumb(t,e)},c=(t,e)=>(e?a.topics:a.hiddenTopics).push(t),l=null!==(o=null===(r=t.page)||void 0===r?void 0:r.parentsVisibility)&&void 0!==o?o:[];return a.breadcrumb.forEach(((t,e)=>{c(t,l[e])})),c(t.tocId,null===(s=t.page)||void 0===s?void 0:s.visible),(null===(u=t.page)||void 0===u?void 0:u.onItsOwn)||a.topics.push(...this.tocIds(t.children)),a}))}buildBreadcrumb(t,e){const i=[];for(;null==t?void 0:t.parentTocId;)i.unshift(t.parentTocId),t=e[t.parentTocId];return i}indexPages(t){const e={};for(let i of t)for(let t of[...i.topics,...i.hiddenTopics])e[t]||(e[t]=i);return e}}class Je{constructor(t,e,i,n){this.converter=t,this.api=e,this.baseUrl=i,this.mapId=n,this.topics={},this.topicContents={},i.endsWith("/")||(this.baseUrl=i+"/")}static build(t,e,i){if(null==window.fluidtopics)throw console.error("Fluid Topics public API was not found. You can find it here: https://www.npmjs.com/package/@fluid-topics/public-api"),new Error("Fluid Topics public API not found");return new Je(new ze,new window.fluidtopics.FluidTopicsApi(t,e,!0),t,i)}clear(){this.map=void 0,this.enrichedToc=void 0,this.topics={},this.topicContents={}}getMap(){return this.loadIfNeeded((()=>this.map),(t=>this.map=t),(()=>this.api.getMap(this.mapId)))}getEnrichedToc(){return this.loadIfNeeded((()=>this.enrichedToc),(t=>this.enrichedToc=t),(()=>this.api.getTableOfContent(this.mapId).then((t=>this.converter.convertNodes(t)))))}async getToc(){return(await this.getEnrichedToc()).toc}async getTocNode(t){return(await this.getEnrichedToc()).nodeByTocId[t]}getTocNodeOrThrow(t){if("boolean"==typeof this.enrichedToc)throw new Error((this.enrichedToc," still loading"));return this.enrichedToc.nodeByTocId[t]}async getPage(t){const e=await this.getEnrichedToc();return e.pages[t-1]||e.pages[0]}async getPageByTocId(t){const e=await this.getEnrichedToc();return e.pageByTocId[t]||e.pages[0]}getTopicInfo(t){return this.loadIfNeeded((()=>this.topics[t]),(e=>this.topics[t]=e),(()=>this.api.getTopic(this.mapId,t)))}getTopicContent(t){return this.loadIfNeeded((()=>this.topicContents[t]),(e=>this.topicContents[t]=e),(()=>this.api.getTopicHTMLContent(this.mapId,t,"DESIGNED_READER")))}getLink(t,e,i){const n=this.getNavigationData(t,e,i),r="r/"+(n.prettyUrl?n.prettyUrl:`${n.mapId}/${n.tocId}`),o=new URL(r,this.baseUrl);return null!=n.page&&o.searchParams.set("page",`${n.page}`),n.prettyUrlDuplicated&&o.searchParams.set("tocId",n.tocId),null!=n.section&&o.searchParams.set("section",n.section),o.href}getNavigationData(t,e,i){var n,r;t=t||"root";const o="object"==typeof this.enrichedToc?this.enrichedToc:void 0,s=null==o?void 0:o.pageByTocId[t],u=null==o?void 0:o.nodeByTocId[t],a=null==u?void 0:u.prettyUrl;return{mapId:this.mapId,tocId:t,topicTitle:null!==(n=null==u?void 0:u.title)&&void 0!==n?n:"",page:e&&s&&s.number!==e?e:void 0,prettyUrl:null!=a?a.replace(/^r\//,""):void 0,prettyUrlDuplicated:null!==(r=null==o?void 0:o.duplicatedPrettyUrls.has(null!=a?a:""))&&void 0!==r&&r,section:i}}async getAccurateNavigationData(t,e,i){return await this.getEnrichedToc(),this.getNavigationData(t,e,i)}async loadIfNeeded(t,e,i){for(void 0===t()&&(e(!0),e(await i().catch((t=>(console.error(t),!1)))));!0===t();)await s(10);const n=t();if(!1===n)throw new Error("Could not load data");return n}}class Ve{constructor(t,i){this.store=t,this.slice=i,this.reloadDebouncer=new e(10)}static build(t){const e=(t=>Le({name:"ft-reader-"+t,initialState:{baseUrl:"",apiIntegrationIdentifier:"ft-reader",visibleTopics:[],renderBeforeFirst:2,renderAfterLast:3},reducers:He}))(t.trim()||"context");return new Ve(function(t,e,i){window.ftReduxStores||(window.ftReduxStores={});const n=e||t.name;return window.ftReduxStores[n]||(window.ftReduxStores[n]=ke({reducer:t.reducer})),window.ftReduxStores[n]}(e),e)}setBaseUrl(t){this.setRequiredStateField("baseUrl","setBaseUrl",t)}setApiIntegrationIdentifier(t){this.setRequiredStateField("apiIntegrationIdentifier","setApiIntegrationIdentifier",t)}setMapId(t){this.setRequiredStateField("mapId","setMapId",t)}setRenderBeforeFirst(t){this.dispatch(this.slice.actions.setRenderBeforeFirst(t))}setRenderAfterLast(t){this.dispatch(this.slice.actions.setRenderAfterLast(t))}setVisibleTopics(t){this.dispatch(this.slice.actions.setVisibleTopics(t))}async navigateToTopic(t,e,i){for(;null==this.service;)await s(5);let n=null!=i?await this.service.getPage(i):await this.service.getPageByTocId(t);this.dispatch(this.slice.actions.setCurrentPage(n),this.slice.actions.setScrollTarget({tocId:t,section:e}))}async navigateToPage(t){for(;null==this.service;)await s(5);let e=await this.service.getPage(t);this.dispatch(this.slice.actions.setCurrentPage(e))}scrollDone(){this.dispatch(this.slice.actions.setScrollTarget({}))}setRequiredStateField(t,e,i){this.store.getState()[t]!==i&&(this.dispatch(this.slice.actions[e](i)),this.clearAll(),this.reload())}clearAll(){this.dispatch(this.slice.actions.setMap(void 0),this.slice.actions.setToc(void 0),this.slice.actions.setCurrentPage(void 0))}reload(){const t=this.store.getState();t.baseUrl&&t.apiIntegrationIdentifier&&t.mapId?this.service=Je.build(t.baseUrl,t.apiIntegrationIdentifier,t.mapId):this.service=void 0,this.reloadDebouncer.run((async()=>{this.reloadMap(),this.reloadToc()}))}async reloadMap(){var t;const e=await(null===(t=this.service)||void 0===t?void 0:t.getMap());this.dispatch(this.slice.actions.setMap(e))}async reloadToc(){var t;const e=await(null===(t=this.service)||void 0===t?void 0:t.getToc());this.dispatch(this.slice.actions.setToc(e))}dispatch(...t){for(let e of t)this.store.dispatch(e)}}const Ze=h`
82
82
  `;var qe=function(t,e,i,n){for(var r,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n,u=t.length-1;u>=0;u--)(r=t[u])&&(s=(o<3?r(s):o>3?r(e,i,s):r(e,i))||s);return o>3&&s&&Object.defineProperty(e,i,s),s};class Xe extends CustomEvent{constructor(t,e){super("ft-reader-map-loaded",{detail:{map:t,toc:e}})}}class Ge extends CustomEvent{constructor(t,e){super("ft-reader-visible-topics-change",{detail:{visibleTopics:e}})}}class Ye extends CustomEvent{constructor(t){super("ft-reader-navigation-done",{detail:t})}}const Qe=t=>e=>+(null!=e?e:"NaN")>0?+e:t;class ti extends We{constructor(){super(...arguments),this.apiIntegrationIdentifier="ft-reader",this.renderBeforeFirst=2,this.renderAfterLast=3,this.visibleTopics=[],this.navigationDebouncer=new e(5)}render(){return B`
83
83
  <slot @register-ft-reader-component=${this.registerComponent}></slot>
84
- `}get stateManager(){return null==this._stateManager&&(this._stateManager=Ve.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this.store=this.stateManager.store),this._stateManager}updated(t){super.updated(t),t.has("baseUrl")&&this.baseUrl&&this.stateManager.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&this.stateManager.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("mapId")&&this.mapId&&(this.stateManager.setMapId(this.mapId),this.stateManager.navigateToTopic("root")),t.has("page")&&!this.tocId&&null!=this.page&&this.stateManager.navigateToPage(this.page),(t.has("tocId")||t.has("section")||t.has("page"))&&this.tocId&&this.stateManager.navigateToTopic(this.tocId,this.section,this.page),t.has("renderBeforeFirst")&&this.stateManager.setRenderBeforeFirst(this.renderBeforeFirst),t.has("renderAfterLast")&&this.stateManager.setRenderAfterLast(this.renderAfterLast)}contentAvailableCallback(t){var e;if(super.contentAvailableCallback(t),(t.has("map")||t.has("toc"))&&this.map&&this.toc&&this.dispatchEvent(new Xe(this.map,this.toc)),t.has("scrollTarget")&&null==(null===(e=this.scrollTarget)||void 0===e?void 0:e.tocId)){const e=t.get("scrollTarget");null!=(null==e?void 0:e.tocId)&&this.navigationDebouncer.run((()=>this.stateManager.service.getAccurateNavigationData(e.tocId,this.currentPageNumber,e.section).then((t=>this.dispatchEvent(new Ye(t))))))}t.has("visibleTopics")&&Promise.all(this.visibleTopics.map((t=>this.stateManager.service.getAccurateNavigationData(t,this.currentPageNumber)))).then((t=>{let e=t.filter((t=>null!=t&&""!==t.topicTitle)).map((t=>({tocId:t.tocId,title:t.topicTitle,page:t.page,prettyUrl:t.prettyUrl,prettyUrlDuplicated:t.prettyUrlDuplicated})));this.dispatchEvent(new Ge(this.map,e))}))}navigateToTarget(){null!=this.tocId?this.stateManager.navigateToTopic(this.tocId,this.section,this.page):null!=this.page&&this.stateManager.navigateToPage(this.page)}registerComponent(t){t.stopPropagation();t.composedPath()[0].setReaderStateManager(this.stateManager)}}var ei;ti.styles=Ze,qe([n()],ti.prototype,"baseUrl",void 0),qe([n()],ti.prototype,"apiIntegrationIdentifier",void 0),qe([n()],ti.prototype,"mapId",void 0),qe([n()],ti.prototype,"tocId",void 0),qe([n()],ti.prototype,"section",void 0),qe([n({type:Number,converter:{fromAttribute:Qe()}})],ti.prototype,"page",void 0),qe([n({type:Number,converter:{fromAttribute:Qe(2)}})],ti.prototype,"renderBeforeFirst",void 0),qe([n({type:Number,converter:{fromAttribute:Qe(3)}})],ti.prototype,"renderAfterLast",void 0),qe([Be()],ti.prototype,"map",void 0),qe([Be()],ti.prototype,"toc",void 0),qe([Be()],ti.prototype,"visibleTopics",void 0),qe([Be((t=>{var e;return null===(e=t.currentPage)||void 0===e?void 0:e.number}))],ti.prototype,"currentPageNumber",void 0),qe([Be()],ti.prototype,"scrollTarget",void 0),(ei="ft-reader-context",t=>{window.customElements.get(ei)||window.customElements.define(ei,t)})(ti),t.FtReaderContext=ti,t.FtReaderContextCssVariables={},t.MapLoadedEvent=Xe,t.NavigationDoneEvent=Ye,t.VisibleTopicsChangeEvent=Ge,t.styles=Ze,Object.defineProperty(t,"U",{value:!0})}({});
84
+ `}get stateManager(){return null==this._stateManager&&(this._stateManager=Ve.build(this.id||(""+Math.round(999e3*Math.random())).padStart(6,"0")),this.store=this.stateManager.store),this._stateManager}updated(t){super.updated(t),t.has("baseUrl")&&this.baseUrl&&this.stateManager.setBaseUrl(this.baseUrl),t.has("apiIntegrationIdentifier")&&this.stateManager.setApiIntegrationIdentifier(this.apiIntegrationIdentifier),t.has("mapId")&&this.mapId&&(this.stateManager.setMapId(this.mapId),this.stateManager.navigateToTopic("root")),t.has("page")&&!this.tocId&&null!=this.page&&this.stateManager.navigateToPage(this.page),(t.has("tocId")||t.has("section")||t.has("page"))&&this.tocId&&this.stateManager.navigateToTopic(this.tocId,this.section,this.page),t.has("renderBeforeFirst")&&this.stateManager.setRenderBeforeFirst(this.renderBeforeFirst),t.has("renderAfterLast")&&this.stateManager.setRenderAfterLast(this.renderAfterLast)}contentAvailableCallback(t){var e;if(super.contentAvailableCallback(t),(t.has("map")||t.has("toc"))&&this.map&&this.toc&&this.dispatchEvent(new Xe(this.map,this.toc)),t.has("scrollTarget")&&null==(null===(e=this.scrollTarget)||void 0===e?void 0:e.tocId)){const e=t.get("scrollTarget");null!=(null==e?void 0:e.tocId)&&this.navigationDebouncer.run((()=>{var t;return this.stateManager.service.getAccurateNavigationData(e.tocId,null===(t=this.currentPage)||void 0===t?void 0:t.number,e.section).then((t=>this.dispatchEvent(new Ye(t))))}))}t.has("visibleTopics")&&Promise.all(this.visibleTopics.map((t=>{var e;return this.stateManager.service.getAccurateNavigationData(t,null===(e=this.currentPage)||void 0===e?void 0:e.number)}))).then((t=>{let e=t.filter((t=>null!=t&&""!==t.topicTitle)).map((t=>({tocId:t.tocId,title:t.topicTitle,page:t.page,prettyUrl:t.prettyUrl,prettyUrlDuplicated:t.prettyUrlDuplicated})));this.dispatchEvent(new Ge(this.map,e))}))}navigateToTarget(){null!=this.tocId?this.stateManager.navigateToTopic(this.tocId,this.section,this.page):null!=this.page&&this.stateManager.navigateToPage(this.page)}registerComponent(t){t.stopPropagation();t.composedPath()[0].setReaderStateManager(this.stateManager)}}var ei;ti.styles=Ze,qe([n()],ti.prototype,"baseUrl",void 0),qe([n()],ti.prototype,"apiIntegrationIdentifier",void 0),qe([n()],ti.prototype,"mapId",void 0),qe([n()],ti.prototype,"tocId",void 0),qe([n()],ti.prototype,"section",void 0),qe([n({type:Number,converter:{fromAttribute:Qe()}})],ti.prototype,"page",void 0),qe([n({type:Number,converter:{fromAttribute:Qe(2)}})],ti.prototype,"renderBeforeFirst",void 0),qe([n({type:Number,converter:{fromAttribute:Qe(3)}})],ti.prototype,"renderAfterLast",void 0),qe([Be()],ti.prototype,"map",void 0),qe([Be()],ti.prototype,"toc",void 0),qe([Be()],ti.prototype,"visibleTopics",void 0),qe([Be()],ti.prototype,"currentPage",void 0),qe([Be()],ti.prototype,"scrollTarget",void 0),(ei="ft-reader-context",t=>{window.customElements.get(ei)||window.customElements.define(ei,t)})(ti),t.FtReaderContext=ti,t.FtReaderContextCssVariables={},t.MapLoadedEvent=Xe,t.NavigationDoneEvent=Ye,t.VisibleTopicsChangeEvent=Ge,t.styles=Ze,Object.defineProperty(t,"U",{value:!0})}({});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-reader-context",
3
- "version": "0.3.18",
3
+ "version": "0.3.19",
4
4
  "description": "Context block for integrated reader components",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,7 +19,7 @@
19
19
  "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
20
  },
21
21
  "dependencies": {
22
- "@fluid-topics/ft-wc-utils": "0.3.18",
22
+ "@fluid-topics/ft-wc-utils": "0.3.19",
23
23
  "@reduxjs/toolkit": "^1.6.2",
24
24
  "lit": "2.2.8"
25
25
  },
@@ -29,5 +29,5 @@
29
29
  "peerDependencies": {
30
30
  "@fluid-topics/public-api": "1.0.22"
31
31
  },
32
- "gitHead": "33fac246cb4042276b1804479304a2c8fe0f8e3f"
32
+ "gitHead": "675c2ceb687246109347352e64772e8ebad2cc17"
33
33
  }