@fluid-topics/ft-reader-content 1.1.46 → 1.1.47

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.
@@ -2,6 +2,7 @@ import { TemplateResult } from "lit";
2
2
  import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
3
3
  import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registration";
4
4
  import { FtReaderPage, FtReaderScrollTarget } from "@fluid-topics/ft-reader-context/build/store/model";
5
+ import { FtInfiniteScroll } from "@fluid-topics/ft-infinite-scroll";
5
6
  import { FtReaderContentProperties } from "./ft-reader-content.properties";
6
7
  import "@fluid-topics/ft-reader-topic-context";
7
8
  export declare class FtReaderContent extends FtReaderComponent implements FtReaderContentProperties {
@@ -15,7 +16,7 @@ export declare class FtReaderContent extends FtReaderComponent implements FtRead
15
16
  renderBeforeFirst: number;
16
17
  renderAfterLast: number;
17
18
  mapId?: string;
18
- container: HTMLDivElement;
19
+ container?: FtInfiniteScroll<any>;
19
20
  protected render(): TemplateResult<1>;
20
21
  private renderTopicInContext;
21
22
  private getScrollTarget;
@@ -11,6 +11,7 @@ import { FtReaderComponent } from "@fluid-topics/ft-reader-context/build/registr
11
11
  import { FtInfiniteScroll } from "@fluid-topics/ft-infinite-scroll";
12
12
  import { styles } from "./ft-reader-content.styles";
13
13
  import "@fluid-topics/ft-reader-topic-context";
14
+ import { FtReaderWatermark } from "./watermark/ft-reader-watermark";
14
15
  class FtReaderContent extends FtReaderComponent {
15
16
  constructor() {
16
17
  super(...arguments);
@@ -24,7 +25,7 @@ class FtReaderContent extends FtReaderComponent {
24
25
  this.visibleTopicsDebouncer = new Debouncer(50);
25
26
  }
26
27
  render() {
27
- var _a, _b;
28
+ var _a, _b, _c;
28
29
  const topics = ((_a = this.currentPage) === null || _a === void 0 ? void 0 : _a.topics) || [];
29
30
  return html `
30
31
  <ft-infinite-scroll class="ft-reader-content"
@@ -39,6 +40,7 @@ class FtReaderContent extends FtReaderComponent {
39
40
  @visible-items-change=${this.visibleTopicChange}
40
41
  @scrolled-to-target=${this.onScrollDone}>
41
42
  </ft-infinite-scroll>
43
+ <ft-reader-watermark height="${(_c = this.container) === null || _c === void 0 ? void 0 : _c.scrollable.clientHeight}px"></ft-reader-watermark>
42
44
  `;
43
45
  }
44
46
  renderTopicInContext(tocId, index) {
@@ -73,7 +75,8 @@ class FtReaderContent extends FtReaderComponent {
73
75
  }
74
76
  }
75
77
  FtReaderContent.elementDefinitions = {
76
- "ft-infinite-scroll": FtInfiniteScroll
78
+ "ft-infinite-scroll": FtInfiniteScroll,
79
+ "ft-reader-watermark": FtReaderWatermark
77
80
  };
78
81
  FtReaderContent.styles = styles;
79
82
  __decorate([
@@ -1,4 +1,4 @@
1
- !function(t,i,e,s,r,n){var o;!function(t){t.FEEDBACK="FEEDBACK",t.RATING="RATING",t.PRINT="PRINT",t.BOOKMARK="BOOKMARK",t.COLLECTIONS="COLLECTIONS",t.PERSONAL_BOOKS="PERSONAL_BOOKS"}(o||(o={}));var l=function(t,i,e,s){for(var r,n=arguments.length,o=n<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(i,e,o):r(i,e))||o);return n>3&&o&&Object.defineProperty(i,e,o),o};class h extends Event{constructor(){super("register-ft-reader-component",{bubbles:!0,composed:!0})}}const d=Symbol("registerInterval");class a extends(function(t){var i;class e extends t{constructor(){super(...arguments),this[i]=0}setReaderStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"reader")}clearStateManager(){this.stateManager&&(this.removeStore("reader"),this.stateManager=void 0)}get service(){var t;return null===(t=this.stateManager)||void 0===t?void 0:t.service}connectedCallback(){super.connectedCallback(),this[d]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[d]):this.dispatchEvent(new h)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return i=d,l([s.state()],e.prototype,"stateManager",void 0),e}(i.FtLitElementRedux)){}const c=i.FtCssVariableFactory.create("--ft-infinite-scroll-padding","","SIZE","0"),v=i.FtCssVariableFactory.create("--ft-infinite-scroll-items-gap","","SIZE","4px"),u=i.FtCssVariableFactory.create("--ft-infinite-scroll-item-container-min-height","","SIZE",".1px"),f=e.css`
1
+ !function(t,e,i,s,r,n){var o;!function(t){t.FEEDBACK="FEEDBACK",t.RATING="RATING",t.PRINT="PRINT",t.BOOKMARK="BOOKMARK",t.COLLECTIONS="COLLECTIONS",t.PERSONAL_BOOKS="PERSONAL_BOOKS"}(o||(o={}));var l=function(t,e,i,s){for(var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class h extends Event{constructor(){super("register-ft-reader-component",{bubbles:!0,composed:!0})}}const a=Symbol("registerInterval");class d extends(function(t){var e;class i extends t{constructor(){super(...arguments),this[e]=0}setReaderStateManager(t){this.clearStateManager(),this.stateManager=t,this.addStore(t.store,"reader")}clearStateManager(){this.stateManager&&(this.removeStore("reader"),this.stateManager=void 0)}get service(){var t;return null===(t=this.stateManager)||void 0===t?void 0:t.service}connectedCallback(){super.connectedCallback(),this[a]=window.setInterval((()=>this.tryToRegisterToContext()),50)}tryToRegisterToContext(){null!=this.stateManager?window.clearInterval(this[a]):this.dispatchEvent(new h)}disconnectedCallback(){super.disconnectedCallback(),this.clearStateManager()}}return e=a,l([s.state()],i.prototype,"stateManager",void 0),i}(e.FtLitElementRedux)){}const c=e.FtCssVariableFactory.create("--ft-infinite-scroll-padding","","SIZE","0"),v=e.FtCssVariableFactory.create("--ft-infinite-scroll-items-gap","","SIZE","4px"),u=e.FtCssVariableFactory.create("--ft-infinite-scroll-item-container-min-height","","SIZE",".1px"),f=i.css`
2
2
  .items-container {
3
3
  padding: ${c};
4
4
  outline: none;
@@ -28,42 +28,76 @@
28
28
  display: flow-root;
29
29
  min-height: ${u};
30
30
  }
31
- `;var p=function(t,i,e,s){for(var r,n=arguments.length,o=n<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(i,e,o):r(i,e))||o);return n>3&&o&&Object.defineProperty(i,e,o),o};class b extends CustomEvent{constructor(t,i){super("visible-items-change",{detail:{visibleIndexes:t,visibleItems:i}})}}class m extends Event{constructor(){super("scrolled-to-target")}}class g extends i.FtLitElement{constructor(){super(...arguments),this.items=[],this.renderItem=()=>e.html``,this.getItemKey=(t,i)=>`${i} - ${JSON.stringify(t)}`,this.internalScroll=!1,this.renderBeforeFirst=1,this.renderAfterLast=1,this.ensureScrollToTarget=!1,this.visibleItems=[],this.scrolledToTarget=!1,this.scrolling=!1,this.renderApprovalTimeouts=[],this.renderedIndexes=new Set,this.scrollDebouncer=new i.Debouncer(5),this.scrollDoneDebouncer=new i.Debouncer(10),this.onVisibilityChange=t=>{let i=new Set(this.visibleItems),e=new Set;for(let s of t){let t=+s.target.attributes.getNamedItem("data-item-index").value;s.intersectionRect.height>0?(i.add(t),e.add(t)):e.has(t)||i.delete(t)}this.visibleItems=[...i].sort(((t,i)=>t-i))},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.scrollingDebouncer=new i.Debouncer(50),this.ignoreNextScrollEvent=!1,this.scrollListener=()=>{if(this.ignoreNextScrollEvent||(this.scrolling=!0,this.scrollingDebouncer.run((()=>this.scrolling=!1))),this.ignoreNextScrollEvent=!1,this.scrolledToTarget){const t=this.searchFirstVisibleItem(this.itemsContainer.children);this.scrollRestorationItem=t?+t.getAttribute("data-item-index"):void 0,this.scrollRestorationOffset=this.scrollable.scrollTop-this.getOffset(t)}},this.onItemsResize=t=>{for(const i of t)i.contentRect.height>0&&i.target.setAttribute("data-last-known-height",""+i.contentRect.height);this.restoreScroll()},this.restoreScroll=()=>{if(null!=this.scrollRestorationItem&&null!=this.scrollRestorationOffset&&this.scrolledToTarget){const t=this.getItem(this.scrollRestorationItem),e=this.getOffset(t),s=i.minmax(0===this.scrollRestorationItem?-e:0,this.scrollRestorationOffset,this.getLastKnownHeight(t)+1);this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop=e+s}},this.itemsResizeObserver=new ResizeObserver(this.onItemsResize),this.scrollableResizeObserver=new ResizeObserver(this.restoreScroll),this.onMutation=()=>{[...this.itemsContainer.children].forEach((t=>{this.intersectionObserver.observe(t),this.itemsResizeObserver.observe(t)})),this.scrollableResizeObserver.observe(this.scrollable)},this.mutationObserver=new MutationObserver(this.onMutation),this.resetVisibleItemsDebouncer=new i.Debouncer(10)}get scrollable(){var t;return null!==(t=this.internalScroll?this.internalScrollable:this.firstScrollableParent)&&void 0!==t?t:document.body}render(){return e.html`
31
+ `;var p=function(t,e,i,s){for(var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class m extends CustomEvent{constructor(t,e){super("visible-items-change",{detail:{visibleIndexes:t,visibleItems:e}})}}class b extends Event{constructor(){super("scrolled-to-target")}}class g extends e.FtLitElement{constructor(){super(...arguments),this.items=[],this.renderItem=()=>i.html``,this.getItemKey=(t,e)=>`${e} - ${JSON.stringify(t)}`,this.internalScroll=!1,this.renderBeforeFirst=1,this.renderAfterLast=1,this.ensureScrollToTarget=!1,this.visibleItems=[],this.scrolledToTarget=!1,this.scrolling=!1,this.renderApprovalTimeouts=[],this.renderedIndexes=new Set,this.scrollDebouncer=new e.Debouncer(5),this.scrollDoneDebouncer=new e.Debouncer(10),this.onVisibilityChange=t=>{let e=new Set(this.visibleItems),i=new Set;for(let s of t){let t=+s.target.attributes.getNamedItem("data-item-index").value;s.intersectionRect.height>0?(e.add(t),i.add(t)):i.has(t)||e.delete(t)}this.visibleItems=[...e].sort(((t,e)=>t-e))},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.scrollingDebouncer=new e.Debouncer(50),this.ignoreNextScrollEvent=!1,this.scrollListener=()=>{if(this.ignoreNextScrollEvent||(this.scrolling=!0,this.scrollingDebouncer.run((()=>this.scrolling=!1))),this.ignoreNextScrollEvent=!1,this.scrolledToTarget){const t=this.searchFirstVisibleItem(this.itemsContainer.children);this.scrollRestorationItem=t?+t.getAttribute("data-item-index"):void 0,this.scrollRestorationOffset=this.scrollable.scrollTop-this.getOffset(t)}},this.onItemsResize=t=>{for(const e of t)e.contentRect.height>0&&e.target.setAttribute("data-last-known-height",""+e.contentRect.height);this.restoreScroll()},this.restoreScroll=()=>{if(null!=this.scrollRestorationItem&&null!=this.scrollRestorationOffset&&this.scrolledToTarget){const t=this.getItem(this.scrollRestorationItem),i=this.getOffset(t),s=e.minmax(0===this.scrollRestorationItem?-i:0,this.scrollRestorationOffset,this.getLastKnownHeight(t)+1);this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop=i+s}},this.itemsResizeObserver=new ResizeObserver(this.onItemsResize),this.scrollableResizeObserver=new ResizeObserver(this.restoreScroll),this.onMutation=()=>{[...this.itemsContainer.children].forEach((t=>{this.intersectionObserver.observe(t),this.itemsResizeObserver.observe(t)})),this.scrollableResizeObserver.observe(this.scrollable)},this.mutationObserver=new MutationObserver(this.onMutation),this.resetVisibleItemsDebouncer=new e.Debouncer(10)}get scrollable(){var t;return null!==(t=this.internalScroll?this.internalScrollable:this.firstScrollableParent)&&void 0!==t?t:document.body}render(){return i.html`
32
32
  <div class="items-container ${this.internalScroll?"scrollable":""}"
33
33
  tabindex="-1"
34
34
  @find-scrollable-parent=${this.findScrollableParent}>
35
- ${r.repeat(this.items,((t,i)=>this.getItemKey(t,i)),((t,i)=>this.renderItemContainer(t,i)))}
35
+ ${r.repeat(this.items,((t,e)=>this.getItemKey(t,e)),((t,e)=>this.renderItemContainer(t,e)))}
36
36
  </div>
37
- `}renderItemContainer(t,i){this.prepareRenderIfNeeded(i);const s=this.scrolledToTarget&&this.visibleItems.includes(i),r=this.renderedIndexes.has(i);return e.html`
38
- <div id="item-${i}"
37
+ `}renderItemContainer(t,e){this.prepareRenderIfNeeded(e);const s=this.scrolledToTarget&&this.visibleItems.includes(e),r=this.renderedIndexes.has(e);return i.html`
38
+ <div id="item-${e}"
39
39
  class="item-container ${r?"rendered":""} ${s?"visible":""}"
40
- data-item-index="${i}">
41
- ${r?(()=>{const e=this.renderItem(t,i);return"string"==typeof e?n.unsafeHTML(e):e})():e.nothing}
40
+ data-item-index="${e}">
41
+ ${r?(()=>{const i=this.renderItem(t,e);return"string"==typeof i?n.unsafeHTML(i):i})():i.nothing}
42
42
  </div>
43
- `}prepareRenderIfNeeded(t){const i=null!=this.renderApprovalTimeouts[t];this.inRenderRange(t)&&!i&&(this.renderApprovalTimeouts[t]=setTimeout((()=>{this.inRenderRange(t)?this.renderedIndexes.add(t):this.renderApprovalTimeouts[t]=void 0,this.requestUpdate()}),300))}inRenderRange(t){return t>=this.visibleItems[0]-this.renderBeforeFirst&&t<=(null!=(i=this.visibleItems)?i:[])[(null!=i?i:[]).length-1]+this.renderAfterLast;var i}resetScroll(){this.triggerFindScrollableParent(),this.intersectionObserver.disconnect(),this.itemsResizeObserver.disconnect(),this.scrollableResizeObserver.disconnect(),this.visibleItems=[];const t=this.resolveScrollToIndex();this.renderedIndexes.add(t),this.scrolledToTarget=!1,this.scrollToTarget(t),this.onMutation(),this.scrollDoneDebouncer.run((()=>{this.ensureScrollToTarget&&t>=0&&this.scrollDebouncer.run((()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(t))>5&&this.scrollToTarget(t)}),500),this.scrolledToTarget=!0}))}resolveScrollToIndex(){var t;let i=null!==(t=this.scrollToIndex)&&void 0!==t?t:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;return i>=this.items.length?-1:i}getItem(t){var i,e,s;return null!==(e=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelector(`#item-${t}`))&&void 0!==e?e:null===(s=this.shadowRoot)||void 0===s?void 0:s.querySelector("#item-0")}scrollToTarget(t){t<=0?(this.scrollable.scrollTop=0,this.scrollRestorationOffset=-this.getOffset(t)):(this.scrollable.scrollTop=this.getOffset(t),this.scrollRestorationOffset=0),this.scrollRestorationItem=t>=0?t:void 0}getOffset(t){var i;let e=0,s="number"==typeof t?this.getItem(t):t;for(;s&&s.offsetParent!==this.scrollable.offsetParent;)e+=s.offsetTop,s=s.offsetParent;return e+(null!==(i=null==s?void 0:s.offsetTop)&&void 0!==i?i:0)-this.scrollable.offsetTop}getLastKnownHeight(t){var i;return+(null!==(i=null==t?void 0:t.getAttribute("data-last-known-height"))&&void 0!==i?i:1e3)}appendItems(...t){this.items=[...this.items,...t]}prependItems(...t){this.items=[...t,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout((()=>{this.triggerFindScrollableParent(),this.initIntersectionObserver(),this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()}),0)}initIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]})}triggerFindScrollableParent(){var t;null===(t=this.itemsContainer)||void 0===t||t.dispatchEvent(new Event("find-scrollable-parent",{composed:!0}))}findScrollableParent(t){var i;let e,s;t.stopPropagation();for(let i of t.composedPath()){const t=i,r=this.elementCanScroll(t);if(r&&t.clientHeight&&t.clientHeight<t.scrollHeight){e=t;break}r&&(s=t)}let r=e||s;r!==this.firstScrollableParent&&(null===(i=this.firstScrollableParent)||void 0===i||i.removeEventListener("scroll",this.scrollListener),null==r||r.addEventListener("scroll",this.scrollListener),this.firstScrollableParent=r,this.initIntersectionObserver(),this.resetScroll())}elementCanScroll(t){try{return["auto","scroll"].includes(getComputedStyle(t).overflowY)}catch(t){return!1}}searchFirstVisibleItem(t,i,e){if(i=null!=i?i:0,(e=null!=e?e:t.length-1)<=i)return t[i];const s=Math.floor((e-i)/2)+i,r=t[s];return this.getOffset(r)>this.scrollable.scrollTop?this.searchFirstVisibleItem(t,i,s-1):this.getOffset(r)+this.getLastKnownHeight(r)<this.scrollable.scrollTop?this.searchFirstVisibleItem(t,s+1,e):r}disconnectedCallback(){super.disconnectedCallback(),this.intersectionObserver.disconnect(),this.itemsResizeObserver.disconnect(),this.scrollableResizeObserver.disconnect(),this.mutationObserver.disconnect()}update(t){super.update(t),t.has("items")&&(this.renderedIndexes=new Set,this.renderApprovalTimeouts=[]),!t.has("scrollToItem")&&!t.has("scrollToIndex")||null==this.scrollToItem&&null==this.scrollToIndex||this.resetScroll()}updated(t){super.updated(t),(t.has("visibleItems")||t.has("items"))&&this.onVisibleItemsChange(),t.has("scrolledToTarget")&&this.scrolledToTarget&&(null!=this.scrollToItem||null!=this.scrollToIndex)&&this.dispatchEvent(new m)}onVisibleItemsChange(){this.visibleItems.every(((t,i)=>null==this.visibleItems[i+1]||t+1===this.visibleItems[i+1]))||i.deepEqual(this.visibleItems,this.lastNotOkVisibleItems)?(this.resetVisibleItemsDebouncer.cancel(),this.dispatchVisibleItemsEvent()):this.resetVisibleItemsDebouncer.run((()=>{this.lastNotOkVisibleItems=[...this.visibleItems],this.visibleItems=[],this.initIntersectionObserver(),this.onMutation()}))}dispatchVisibleItemsEvent(){var t;null===(t=this.cancelableDispatchEvent)||void 0===t||t.cancel(),this.cancelableDispatchEvent=i.cancelable(i.waitUntil((()=>!this.scrolling))),this.cancelableDispatchEvent.then((()=>this.dispatchEvent(new b(this.visibleItems,this.visibleItems.map((t=>this.items[t])))))).catch((()=>null))}}g.styles=f,p([s.property({type:Array})],g.prototype,"items",void 0),p([s.property({attribute:!1})],g.prototype,"renderItem",void 0),p([s.property({attribute:!1})],g.prototype,"getItemKey",void 0),p([s.property({type:Object})],g.prototype,"scrollToItem",void 0),p([s.property({type:Number})],g.prototype,"scrollToIndex",void 0),p([s.property({type:Boolean})],g.prototype,"internalScroll",void 0),p([s.property({type:Number})],g.prototype,"renderBeforeFirst",void 0),p([s.property({type:Number})],g.prototype,"renderAfterLast",void 0),p([s.property({type:Boolean})],g.prototype,"ensureScrollToTarget",void 0),p([s.state({hasChanged:(t,i)=>null!=t&&null==i||t.length!==i.length||t[0]!==i[0]})],g.prototype,"visibleItems",void 0),p([s.query(".scrollable")],g.prototype,"internalScrollable",void 0),p([s.query(".items-container")],g.prototype,"itemsContainer",void 0),p([s.state()],g.prototype,"scrolledToTarget",void 0),p([s.state()],g.prototype,"scrolling",void 0),p([s.state({hasChanged:(t,e)=>!i.deepEqual(t,e)})],g.prototype,"renderedIndexes",void 0),i.customElement("ft-infinite-scroll")(g);const I=e.css`
44
- `,w=e.css`
45
- `;var x=function(t,i,e,s){for(var r,n=arguments.length,o=n<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(i,e,o):r(i,e))||o);return n>3&&o&&Object.defineProperty(i,e,o),o};class T extends a{constructor(){super(...arguments),this.disableContextInteractions=!1,this.registeredComponents=[]}render(){return e.html`
43
+ `}prepareRenderIfNeeded(t){const e=null!=this.renderApprovalTimeouts[t];this.inRenderRange(t)&&!e&&(this.renderApprovalTimeouts[t]=setTimeout((()=>{this.inRenderRange(t)?this.renderedIndexes.add(t):this.renderApprovalTimeouts[t]=void 0,this.requestUpdate()}),300))}inRenderRange(t){return t>=this.visibleItems[0]-this.renderBeforeFirst&&t<=(null!=(e=this.visibleItems)?e:[])[(null!=e?e:[]).length-1]+this.renderAfterLast;var e}resetScroll(){this.triggerFindScrollableParent(),this.intersectionObserver.disconnect(),this.itemsResizeObserver.disconnect(),this.scrollableResizeObserver.disconnect(),this.visibleItems=[];const t=this.resolveScrollToIndex();this.renderedIndexes.add(t),this.scrolledToTarget=!1,this.scrollToTarget(t),this.onMutation(),this.scrollDoneDebouncer.run((()=>{this.ensureScrollToTarget&&t>=0&&this.scrollDebouncer.run((()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(t))>5&&this.scrollToTarget(t)}),500),this.scrolledToTarget=!0}))}resolveScrollToIndex(){var t;let e=null!==(t=this.scrollToIndex)&&void 0!==t?t:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;return e>=this.items.length?-1:e}getItem(t){var e,i,s;return null!==(i=null===(e=this.shadowRoot)||void 0===e?void 0:e.querySelector(`#item-${t}`))&&void 0!==i?i:null===(s=this.shadowRoot)||void 0===s?void 0:s.querySelector("#item-0")}scrollToTarget(t){t<=0?(this.scrollable.scrollTop=0,this.scrollRestorationOffset=-this.getOffset(t)):(this.scrollable.scrollTop=this.getOffset(t),this.scrollRestorationOffset=0),this.scrollRestorationItem=t>=0?t:void 0}getOffset(t){var e;let i=0,s="number"==typeof t?this.getItem(t):t;for(;s&&s.offsetParent!==this.scrollable.offsetParent;)i+=s.offsetTop,s=s.offsetParent;return i+(null!==(e=null==s?void 0:s.offsetTop)&&void 0!==e?e:0)-this.scrollable.offsetTop}getLastKnownHeight(t){var e;return+(null!==(e=null==t?void 0:t.getAttribute("data-last-known-height"))&&void 0!==e?e:1e3)}appendItems(...t){this.items=[...this.items,...t]}prependItems(...t){this.items=[...t,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout((()=>{this.triggerFindScrollableParent(),this.initIntersectionObserver(),this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()}),0)}initIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]})}triggerFindScrollableParent(){var t;null===(t=this.itemsContainer)||void 0===t||t.dispatchEvent(new Event("find-scrollable-parent",{composed:!0}))}findScrollableParent(t){var e;let i,s;t.stopPropagation();for(let e of t.composedPath()){const t=e,r=this.elementCanScroll(t);if(r&&t.clientHeight&&t.clientHeight<t.scrollHeight){i=t;break}r&&(s=t)}let r=i||s;r!==this.firstScrollableParent&&(null===(e=this.firstScrollableParent)||void 0===e||e.removeEventListener("scroll",this.scrollListener),null==r||r.addEventListener("scroll",this.scrollListener),this.firstScrollableParent=r,this.initIntersectionObserver(),this.resetScroll())}elementCanScroll(t){try{return["auto","scroll"].includes(getComputedStyle(t).overflowY)}catch(t){return!1}}searchFirstVisibleItem(t,e,i){if(e=null!=e?e:0,(i=null!=i?i:t.length-1)<=e)return t[e];const s=Math.floor((i-e)/2)+e,r=t[s];return this.getOffset(r)>this.scrollable.scrollTop?this.searchFirstVisibleItem(t,e,s-1):this.getOffset(r)+this.getLastKnownHeight(r)<this.scrollable.scrollTop?this.searchFirstVisibleItem(t,s+1,i):r}disconnectedCallback(){super.disconnectedCallback(),this.intersectionObserver.disconnect(),this.itemsResizeObserver.disconnect(),this.scrollableResizeObserver.disconnect(),this.mutationObserver.disconnect()}update(t){super.update(t),t.has("items")&&(this.renderedIndexes=new Set,this.renderApprovalTimeouts=[]),!t.has("scrollToItem")&&!t.has("scrollToIndex")||null==this.scrollToItem&&null==this.scrollToIndex||this.resetScroll()}updated(t){super.updated(t),(t.has("visibleItems")||t.has("items"))&&this.onVisibleItemsChange(),t.has("scrolledToTarget")&&this.scrolledToTarget&&(null!=this.scrollToItem||null!=this.scrollToIndex)&&this.dispatchEvent(new b)}onVisibleItemsChange(){this.visibleItems.every(((t,e)=>null==this.visibleItems[e+1]||t+1===this.visibleItems[e+1]))||e.deepEqual(this.visibleItems,this.lastNotOkVisibleItems)?(this.resetVisibleItemsDebouncer.cancel(),this.dispatchVisibleItemsEvent()):this.resetVisibleItemsDebouncer.run((()=>{this.lastNotOkVisibleItems=[...this.visibleItems],this.visibleItems=[],this.initIntersectionObserver(),this.onMutation()}))}dispatchVisibleItemsEvent(){var t;null===(t=this.cancelableDispatchEvent)||void 0===t||t.cancel(),this.cancelableDispatchEvent=e.cancelable(e.waitUntil((()=>!this.scrolling))),this.cancelableDispatchEvent.then((()=>this.dispatchEvent(new m(this.visibleItems,this.visibleItems.map((t=>this.items[t])))))).catch((()=>null))}}g.styles=f,p([s.property({type:Array})],g.prototype,"items",void 0),p([s.property({attribute:!1})],g.prototype,"renderItem",void 0),p([s.property({attribute:!1})],g.prototype,"getItemKey",void 0),p([s.property({type:Object})],g.prototype,"scrollToItem",void 0),p([s.property({type:Number})],g.prototype,"scrollToIndex",void 0),p([s.property({type:Boolean})],g.prototype,"internalScroll",void 0),p([s.property({type:Number})],g.prototype,"renderBeforeFirst",void 0),p([s.property({type:Number})],g.prototype,"renderAfterLast",void 0),p([s.property({type:Boolean})],g.prototype,"ensureScrollToTarget",void 0),p([s.state({hasChanged:(t,e)=>null!=t&&null==e||t.length!==e.length||t[0]!==e[0]})],g.prototype,"visibleItems",void 0),p([s.query(".scrollable")],g.prototype,"internalScrollable",void 0),p([s.query(".items-container")],g.prototype,"itemsContainer",void 0),p([s.state()],g.prototype,"scrolledToTarget",void 0),p([s.state()],g.prototype,"scrolling",void 0),p([s.state({hasChanged:(t,i)=>!e.deepEqual(t,i)})],g.prototype,"renderedIndexes",void 0),e.customElement("ft-infinite-scroll")(g);const w=i.css`
44
+ `,x=i.css`
45
+ `;var I=function(t,e,i,s){for(var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class $ extends d{constructor(){super(...arguments),this.disableContextInteractions=!1,this.registeredComponents=[]}render(){return i.html`
46
46
  <article id=${this.tocId}>
47
47
  <slot @register-ft-reader-topic-component=${this.registerComponent}></slot>
48
48
  </article>
49
- `}registerComponent(t){t.stopPropagation();const i=t.composedPath()[0];this.register(i)}register(t){this.registeredComponents.push(t),t.tocNode=this.tocNode,t.disableContextInteractions=this.disableContextInteractions}update(t){super.update(t),["mapId","tocId","stateManager"].some((i=>t.has(i)))&&this.setTocNode(),t.has("tocNode")&&this.registeredComponents.forEach((t=>t.tocNode=this.tocNode))}async setTocNode(){var t;this.tocNode=void 0,this.tocNode=this.mapId&&this.tocId?await(null===(t=this.service)||void 0===t?void 0:t.getTocNode(this.tocId)):void 0}disconnectedCallback(){super.disconnectedCallback(),this.registeredComponents=[]}}T.styles=w,x([i.redux({selector:t=>{var i;return null===(i=t.map)||void 0===i?void 0:i.id}})],T.prototype,"mapId",void 0),x([s.property()],T.prototype,"tocId",void 0),x([s.property({type:Boolean})],T.prototype,"disableContextInteractions",void 0),x([s.state()],T.prototype,"tocNode",void 0),i.customElement("ft-reader-topic-context")(T);var $=function(t,i,e,s){for(var r,n=arguments.length,o=n<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,e):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(i,e,o):r(i,e))||o);return n>3&&o&&Object.defineProperty(i,e,o),o};class S extends a{constructor(){super(...arguments),this.renderTopic=()=>e.html`
49
+ `}registerComponent(t){t.stopPropagation();const e=t.composedPath()[0];this.register(e)}register(t){this.registeredComponents.push(t),t.tocNode=this.tocNode,t.disableContextInteractions=this.disableContextInteractions}update(t){super.update(t),["mapId","tocId","stateManager"].some((e=>t.has(e)))&&this.setTocNode(),t.has("tocNode")&&this.registeredComponents.forEach((t=>t.tocNode=this.tocNode))}async setTocNode(){var t;this.tocNode=void 0,this.tocNode=this.mapId&&this.tocId?await(null===(t=this.service)||void 0===t?void 0:t.getTocNode(this.tocId)):void 0}disconnectedCallback(){super.disconnectedCallback(),this.registeredComponents=[]}}$.styles=x,I([e.redux({selector:t=>{var e;return null===(e=t.map)||void 0===e?void 0:e.id}})],$.prototype,"mapId",void 0),I([s.property()],$.prototype,"tocId",void 0),I([s.property({type:Boolean})],$.prototype,"disableContextInteractions",void 0),I([s.state()],$.prototype,"tocNode",void 0),e.customElement("ft-reader-topic-context")($);const y=i.css`
50
+ :host {
51
+ position: absolute;
52
+ top: 0;
53
+ right: 0;
54
+ bottom: 0;
55
+ left: 0;
56
+ pointer-events: none;
57
+ }
58
+
59
+ .ft-watermark-container {
60
+ position: sticky;
61
+ top: 0;
62
+ text-align: center;
63
+ }
64
+
65
+ .ft-watermark {
66
+ z-index: 79;
67
+ }
68
+ `;var T=function(t,e,i,s){for(var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class O extends d{constructor(){super(...arguments),this.height="0"}render(){var t,e,s;return this.watermark?i.html`
69
+ <style>
70
+ .ft-watermark {
71
+ height: ${this.height};
72
+ }
73
+ </style>
74
+ <div class="ft-watermark-container">
75
+ <svg xmlns="http://www.w3.org/2000/svg" class="ft-watermark">
76
+ <text x="0" y="0" text-anchor="middle" transform="rotate(-45)" fill="${null===(t=this.watermark)||void 0===t?void 0:t.color}"
77
+ fill-opacity="${null===(e=this.watermark)||void 0===e?void 0:e.opacity}%">
78
+ ${r.repeat((null===(s=this.watermark)||void 0===s?void 0:s.text)||[],(t=>i.svg`<tspan x="0" dy="1.2em">${t}</tspan>`))}
79
+ </text>
80
+ </svg>
81
+ </div>
82
+ `:i.nothing}updated(t){if(super.updated(t),t.has("watermark")&&this.watermark){const t=this.svg.getBBox();this.svg.setAttribute("viewBox",t.x+" "+t.y+" "+t.width+" "+t.height)}}}O.styles=y,T([e.redux({selector:t=>{var e;return null===(e=t.map)||void 0===e?void 0:e.watermark}})],O.prototype,"watermark",void 0),T([s.query(".ft-watermark")],O.prototype,"svg",void 0),T([s.property()],O.prototype,"height",void 0);var S=function(t,e,i,s){for(var r,n=arguments.length,o=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s,l=t.length-1;l>=0;l--)(r=t[l])&&(o=(n<3?r(o):n>3?r(e,i,o):r(e,i))||o);return n>3&&o&&Object.defineProperty(e,i,o),o};class C extends d{constructor(){super(...arguments),this.renderTopic=()=>i.html`
50
83
  <ft-reader-topic-title></ft-reader-topic-title>
51
84
  <ft-reader-topic-content></ft-reader-topic-content>
52
- `,this.disableContextInteractions=!1,this.renderBeforeFirst=5,this.renderAfterLast=10,this.visibleTopicsDebouncer=new i.Debouncer(50)}render(){var t,i;const s=(null===(t=this.currentPage)||void 0===t?void 0:t.topics)||[];return e.html`
85
+ `,this.disableContextInteractions=!1,this.renderBeforeFirst=5,this.renderAfterLast=10,this.visibleTopicsDebouncer=new e.Debouncer(50)}render(){var t,e,s;const r=(null===(t=this.currentPage)||void 0===t?void 0:t.topics)||[];return i.html`
53
86
  <ft-infinite-scroll class="ft-reader-content"
54
- .items=${s}
55
- .renderItem=${(t,i)=>this.renderTopicInContext(t,i)}
87
+ .items=${r}
88
+ .renderItem=${(t,e)=>this.renderTopicInContext(t,e)}
56
89
  .getItemKey=${t=>this.mapId+t}
57
90
  .scrollToItem=${this.getScrollTarget()}
58
- ?ensureScrollToTarget=${null==(null===(i=this.scrollTarget)||void 0===i?void 0:i.section)&&!window.location.hash}
91
+ ?ensureScrollToTarget=${null==(null===(e=this.scrollTarget)||void 0===e?void 0:e.section)&&!window.location.hash}
59
92
  .renderBeforeFirst=${this.renderBeforeFirst}
60
93
  .renderAfterLast=${this.renderAfterLast}
61
94
  exportpartsPrefix="scroller"
62
95
  @visible-items-change=${this.visibleTopicChange}
63
96
  @scrolled-to-target=${this.onScrollDone}>
64
97
  </ft-infinite-scroll>
65
- `}renderTopicInContext(t,i){return e.html`
98
+ <ft-reader-watermark height="${null===(s=this.container)||void 0===s?void 0:s.scrollable.clientHeight}px"></ft-reader-watermark>
99
+ `}renderTopicInContext(t,e){return i.html`
66
100
  <ft-reader-topic-context tocId="${t}" ?disableContextInteractions=${this.disableContextInteractions}>
67
- ${this.renderTopic(t,i)}
101
+ ${this.renderTopic(t,e)}
68
102
  </ft-reader-topic-context>
69
- `}getScrollTarget(){var t,i,e,s,r;if(this.disableContextInteractions)return null;const n=null!==(s=null===(t=this.visibleTopics)||void 0===t?void 0:t.includes(null!==(e=null===(i=this.scrollTarget)||void 0===i?void 0:i.tocId)&&void 0!==e?e:""))&&void 0!==s&&s;return!(null===(r=this.scrollTarget)||void 0===r?void 0:r.tocId)||n&&null!=this.scrollTarget.section?null:this.scrollTarget.tocId}visibleTopicChange(t){this.disableContextInteractions||this.visibleTopicsDebouncer.run((()=>{var i;return null===(i=this.stateManager)||void 0===i?void 0:i.setVisibleTopics(t.detail.visibleItems)}))}onScrollDone(){var t,i;this.disableContextInteractions||(null===(t=this.scrollTarget)||void 0===t?void 0:t.section)||null===(i=this.stateManager)||void 0===i||i.scrollDone()}}S.elementDefinitions={"ft-infinite-scroll":g},S.styles=I,$([s.property()],S.prototype,"renderTopic",void 0),$([s.property({type:Boolean})],S.prototype,"disableContextInteractions",void 0),$([i.redux()],S.prototype,"currentPage",void 0),$([i.redux()],S.prototype,"scrollTarget",void 0),$([i.redux()],S.prototype,"visibleTopics",void 0),$([i.redux({selector:t=>{var i,e;return null!==(e=null===(i=t.configuration)||void 0===i?void 0:i.loadBeforeFirstVisibleTopic)&&void 0!==e?e:5}})],S.prototype,"renderBeforeFirst",void 0),$([i.redux({selector:t=>{var i,e;return null!==(e=null===(i=t.configuration)||void 0===i?void 0:i.loadAfterLastVisibleTopic)&&void 0!==e?e:5}})],S.prototype,"renderAfterLast",void 0),$([i.redux()],S.prototype,"mapId",void 0),$([s.query(".ft-reader-content")],S.prototype,"container",void 0),i.customElement("ft-reader-content")(S),t.FtReaderContent=S,t.FtReaderContentCssVariables={},t.styles=I}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators,ftGlobals.litRepeat,ftGlobals.litUnsafeHTML);
103
+ `}getScrollTarget(){var t,e,i,s,r;if(this.disableContextInteractions)return null;const n=null!==(s=null===(t=this.visibleTopics)||void 0===t?void 0:t.includes(null!==(i=null===(e=this.scrollTarget)||void 0===e?void 0:e.tocId)&&void 0!==i?i:""))&&void 0!==s&&s;return!(null===(r=this.scrollTarget)||void 0===r?void 0:r.tocId)||n&&null!=this.scrollTarget.section?null:this.scrollTarget.tocId}visibleTopicChange(t){this.disableContextInteractions||this.visibleTopicsDebouncer.run((()=>{var e;return null===(e=this.stateManager)||void 0===e?void 0:e.setVisibleTopics(t.detail.visibleItems)}))}onScrollDone(){var t,e;this.disableContextInteractions||(null===(t=this.scrollTarget)||void 0===t?void 0:t.section)||null===(e=this.stateManager)||void 0===e||e.scrollDone()}}C.elementDefinitions={"ft-infinite-scroll":g,"ft-reader-watermark":O},C.styles=w,S([s.property()],C.prototype,"renderTopic",void 0),S([s.property({type:Boolean})],C.prototype,"disableContextInteractions",void 0),S([e.redux()],C.prototype,"currentPage",void 0),S([e.redux()],C.prototype,"scrollTarget",void 0),S([e.redux()],C.prototype,"visibleTopics",void 0),S([e.redux({selector:t=>{var e,i;return null!==(i=null===(e=t.configuration)||void 0===e?void 0:e.loadBeforeFirstVisibleTopic)&&void 0!==i?i:5}})],C.prototype,"renderBeforeFirst",void 0),S([e.redux({selector:t=>{var e,i;return null!==(i=null===(e=t.configuration)||void 0===e?void 0:e.loadAfterLastVisibleTopic)&&void 0!==i?i:5}})],C.prototype,"renderAfterLast",void 0),S([e.redux()],C.prototype,"mapId",void 0),S([s.query(".ft-reader-content")],C.prototype,"container",void 0),e.customElement("ft-reader-content")(C),t.FtReaderContent=C,t.FtReaderContentCssVariables={},t.styles=w}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators,ftGlobals.litRepeat,ftGlobals.litUnsafeHTML);