@fluid-topics/ft-infinite-scroll 1.1.70 → 1.1.71

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,6 +1,6 @@
1
- !function(t,i,s,e,h,l){const n={padding:i.FtCssVariableFactory.create("--ft-infinite-scroll-padding","","SIZE","0"),itemsGap:i.FtCssVariableFactory.create("--ft-infinite-scroll-items-gap","","SIZE","4px"),itemContainerMinHeight:i.FtCssVariableFactory.create("--ft-infinite-scroll-item-container-min-height","","SIZE",".1px")},r=s.css`
1
+ "use strict";(()=>{var F=Object.create;var y=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var u=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var q=(r,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of L(e))!j.call(r,i)&&i!==t&&y(r,i,{get:()=>e[i],enumerable:!(s=M(e,i))||s.enumerable});return r};var f=(r,e,t)=>(t=r!=null?F(P(r)):{},q(e||!r||!r.__esModule?y(t,"default",{value:r,enumerable:!0}):t,r));var p=u((B,O)=>{O.exports=ftGlobals.wcUtils});var g=u((U,R)=>{R.exports=ftGlobals.lit});var x=u((K,w)=>{w.exports=ftGlobals.litDecorators});var C=u((Z,_)=>{_.exports=ftGlobals.litRepeat});var E=u((W,A)=>{A.exports=ftGlobals.litUnsafeHTML});var $=f(p());var m=f(g()),a=f(x()),H=f(C()),c=f(p()),N=f(E());var V=f(g()),v=f(p()),I={padding:v.FtCssVariableFactory.create("--ft-infinite-scroll-padding","","SIZE","0"),itemsGap:v.FtCssVariableFactory.create("--ft-infinite-scroll-items-gap","","SIZE","4px"),itemContainerMinHeight:v.FtCssVariableFactory.create("--ft-infinite-scroll-item-container-min-height","","SIZE",".1px")},D=V.css`
2
2
  .items-container {
3
- padding: ${n.padding};
3
+ padding: ${I.padding};
4
4
  outline: none;
5
5
  }
6
6
 
@@ -17,7 +17,7 @@
17
17
  By adding this gap we ensure that the previous item will be fully hidden
18
18
  and even if its size changes, it will not impact the scroll offset
19
19
  */
20
- margin-top: ${n.itemsGap};
20
+ margin-top: ${I.itemsGap};
21
21
  }
22
22
 
23
23
  .item-container:not(.rendered) {
@@ -26,18 +26,18 @@
26
26
 
27
27
  .item-container.rendered {
28
28
  display: flow-root;
29
- min-height: ${n.itemContainerMinHeight};
29
+ min-height: ${I.itemContainerMinHeight};
30
30
  }
31
- `;var o=function(t,i,s,e){for(var h,l=arguments.length,n=l<3?i:null===e?e=Object.getOwnPropertyDescriptor(i,s):e,r=t.length-1;r>=0;r--)(h=t[r])&&(n=(l<3?h(n):l>3?h(i,s,n):h(i,s))||n);return l>3&&n&&Object.defineProperty(i,s,n),n};class a extends CustomEvent{constructor(t,i){super("visible-items-change",{detail:{visibleIndexes:t,visibleItems:i}})}}class d extends Event{constructor(){super("scrolled-to-target")}}class c extends i.FtLitElement{constructor(){super(...arguments),this.items=[],this.renderItem=()=>s.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),s=new Set;for(let e of t){let t=+e.target.getAttribute("data-item-index");e.intersectionRect.height>0?(i.add(t),s.add(t)):s.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=()=>{var t;const i=this.ignoreNextScrollEvent;this.ignoreNextScrollEvent=!1,i||(this.scrolling=!0,this.scrollingDebouncer.run((()=>this.scrolling=!1)));const s=this.scrollable.scrollTop,e=s-(null!==(t=this.lastScrollTop)&&void 0!==t?t:0);if(this.lastScrollTop=s,this.scrolledToTarget){this.restoreScrollIfNeeded(i?0:e);const t=this.searchFirstVisibleItem(s,this.itemsContainer.children);this.scrollRestorationItem=t?+t.getAttribute("data-item-index"):void 0,this.scrollRestorationOffset=s-this.getOffset(t)}},this.restoreScrollIfNeeded=(t=0)=>{var s;const e=this.scrollable.scrollHeight,h=e-(null!==(s=this.lastScrollHeight)&&void 0!==s?s:e);if(this.lastScrollHeight=e,0!==h&&null!=this.scrollRestorationItem&&null!=this.scrollRestorationOffset&&this.scrolledToTarget){const s=this.getItem(this.scrollRestorationItem),e=this.getOffset(s),l=e+i.minmax(0===this.scrollRestorationItem?-e:1,this.scrollRestorationOffset,s.clientHeight-1)+t-this.scrollable.scrollTop;(Math.abs(h-l)<4||Math.abs(l)>5)&&(this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop+=l)}},this._shouldRestoreScroll=!1,this.scrollAdjustment=()=>{this.restoreScrollIfNeeded(),this.shouldRestoreScroll&&requestAnimationFrame(this.scrollAdjustment)},this.onMutation=()=>{for(let t of this.itemsContainer.children)this.intersectionObserver.observe(t)},this.mutationObserver=new MutationObserver(this.onMutation),this.resetVisibleItemsDebouncer=new i.Debouncer(10)}get scrollable(){var t;return null!==(t=this._scrollable)&&void 0!==t?t:document.body}set scrollable(t){var i,s,e,h;this._scrollable!==t&&(null===(i=this._scrollable)||void 0===i||i.removeEventListener("scroll",this.scrollListener),this._scrollable&&this.initialOverflowAnchorValue&&(this.scrollable.style.overflowAnchor=this.initialOverflowAnchorValue),this._scrollable=t,null===(s=this._scrollable)||void 0===s||s.addEventListener("scroll",this.scrollListener),this.lastScrollTop=null===(e=this._scrollable)||void 0===e?void 0:e.scrollTop,this.lastScrollHeight=null===(h=this._scrollable)||void 0===h?void 0:h.scrollHeight,this._scrollable&&(this.initialOverflowAnchorValue=getComputedStyle(this._scrollable).overflowAnchor,this._scrollable.style.overflowAnchor="none"))}render(){return s.html`
31
+ `;var h=function(r,e,t,s){var i=arguments.length,l=i<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")l=Reflect.decorate(r,e,t,s);else for(var d=r.length-1;d>=0;d--)(o=r[d])&&(l=(i<3?o(l):i>3?o(e,t,l):o(e,t))||l);return i>3&&l&&Object.defineProperty(e,t,l),l},T=class extends CustomEvent{constructor(e,t){super("visible-items-change",{detail:{visibleIndexes:e,visibleItems:t}})}},S=class extends Event{constructor(){super("scrolled-to-target")}},G=r=>(r??[])[(r??[]).length-1],n=class extends c.FtLitElement{constructor(){super(...arguments),this.items=[],this.renderItem=()=>m.html``,this.getItemKey=(e,t)=>`${t} - ${JSON.stringify(e)}`,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 c.Debouncer(5),this.scrollDoneDebouncer=new c.Debouncer(10),this.onVisibilityChange=e=>{let t=new Set(this.visibleItems),s=new Set;for(let i of e){let l=+i.target.getAttribute("data-item-index");i.intersectionRect.height>0?(t.add(l),s.add(l)):s.has(l)||t.delete(l)}this.visibleItems=[...t].sort((i,l)=>i-l)},this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange),this.scrollingDebouncer=new c.Debouncer(50),this.ignoreNextScrollEvent=!1,this.scrollListener=()=>{var e;let t=this.ignoreNextScrollEvent;this.ignoreNextScrollEvent=!1,t||(this.scrolling=!0,this.scrollingDebouncer.run(()=>this.scrolling=!1));let s=this.scrollable.scrollTop,i=s-((e=this.lastScrollTop)!==null&&e!==void 0?e:0);if(this.lastScrollTop=s,this.scrolledToTarget){this.restoreScrollIfNeeded(t?0:i);let l=this.searchFirstVisibleItem(s,this.itemsContainer.children);this.scrollRestorationItem=l?+l.getAttribute("data-item-index"):void 0,this.scrollRestorationOffset=s-this.getOffset(l)}},this.restoreScrollIfNeeded=(e=0)=>{var t;let s=this.scrollable.scrollHeight,i=s-((t=this.lastScrollHeight)!==null&&t!==void 0?t:s);if(this.lastScrollHeight=s,i!==0&&this.scrollRestorationItem!=null&&this.scrollRestorationOffset!=null&&this.scrolledToTarget){let l=this.getItem(this.scrollRestorationItem),o=this.getOffset(l),d=(0,c.minmax)(this.scrollRestorationItem===0?-o:1,this.scrollRestorationOffset,l.clientHeight-1),b=o+d+e-this.scrollable.scrollTop;(Math.abs(i-b)<4||Math.abs(b)>5)&&(this.ignoreNextScrollEvent=!0,this.scrollable.scrollTop+=b)}},this._shouldRestoreScroll=!1,this.scrollAdjustment=()=>{this.restoreScrollIfNeeded(),this.shouldRestoreScroll&&requestAnimationFrame(this.scrollAdjustment)},this.onMutation=()=>{for(let e of this.itemsContainer.children)this.intersectionObserver.observe(e)},this.mutationObserver=new MutationObserver(this.onMutation),this.resetVisibleItemsDebouncer=new c.Debouncer(10)}get scrollable(){var e;return(e=this._scrollable)!==null&&e!==void 0?e:document.body}set scrollable(e){var t,s,i,l;this._scrollable!==e&&((t=this._scrollable)===null||t===void 0||t.removeEventListener("scroll",this.scrollListener),this._scrollable&&this.initialOverflowAnchorValue&&(this.scrollable.style.overflowAnchor=this.initialOverflowAnchorValue),this._scrollable=e,(s=this._scrollable)===null||s===void 0||s.addEventListener("scroll",this.scrollListener),this.lastScrollTop=(i=this._scrollable)===null||i===void 0?void 0:i.scrollTop,this.lastScrollHeight=(l=this._scrollable)===null||l===void 0?void 0:l.scrollHeight,this._scrollable&&(this.initialOverflowAnchorValue=getComputedStyle(this._scrollable).overflowAnchor,this._scrollable.style.overflowAnchor="none"))}render(){return m.html`
32
32
  <div class="items-container ${this.internalScroll?"scrollable":""}"
33
33
  tabindex="-1"
34
34
  @find-scrollable-parent=${this.findScrollableParent}>
35
- ${h.repeat(this.items,((t,i)=>this.getItemKey(t,i)),((t,i)=>this.renderItemContainer(t,i)))}
35
+ ${(0,H.repeat)(this.items,(e,t)=>this.getItemKey(e,t),(e,t)=>this.renderItemContainer(e,t))}
36
36
  </div>
37
- `}renderItemContainer(t,i){this.prepareRenderIfNeeded(i);const e=this.scrolledToTarget&&this.visibleItems.includes(i),h=this.renderedIndexes.has(i);return s.html`
38
- <div id="item-${i}"
39
- class="item-container ${h?"rendered":""} ${e?"visible":""}"
40
- data-item-index="${i}">
41
- ${h?(()=>{const s=this.renderItem(t,i);return"string"==typeof s?l.unsafeHTML(s):s})():s.nothing}
37
+ `}renderItemContainer(e,t){this.prepareRenderIfNeeded(t);let s=this.scrolledToTarget&&this.visibleItems.includes(t),i=this.renderedIndexes.has(t);return m.html`
38
+ <div id="item-${t}"
39
+ class="item-container ${i?"rendered":""} ${s?"visible":""}"
40
+ data-item-index="${t}">
41
+ ${i?(()=>{let o=this.renderItem(e,t);return typeof o=="string"?(0,N.unsafeHTML)(o):o})():m.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(t=!0){var i;if(this.shouldRestoreScroll=!1,this.intersectionObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.internalScroll&&this.scrollable!==this.internalScrollable)this.scrollable=this.internalScrollable;else if(!this.internalScroll&&t)return void(null===(i=this.itemsContainer)||void 0===i||i.dispatchEvent(new Event("find-scrollable-parent",{composed:!0})));const s=this.resolveScrollToIndex();this.renderedIndexes.add(s),this.scrollToTarget(s),this.scrollDoneDebouncer.run((()=>{this.ensureScrollToTarget&&s>=0&&this.scrollDebouncer.run((()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(s))>5&&this.scrollToTarget(s)}),500),this.scrollToTarget(s),this.scrolledToTarget=!0,this.shouldRestoreScroll=!0,this.resetIntersectionObserver()}))}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,s,e;return null!==(s=null===(i=this.shadowRoot)||void 0===i?void 0:i.querySelector(`#item-${t}`))&&void 0!==s?s:null===(e=this.shadowRoot)||void 0===e?void 0:e.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 s=0,e="number"==typeof t?this.getItem(t):t;for(;e&&e.offsetParent!==this.scrollable.offsetParent;)s+=e.offsetTop,e=e.offsetParent;return s+(null!==(i=null==e?void 0:e.offsetTop)&&void 0!==i?i:0)-this.scrollable.offsetTop}appendItems(...t){this.items=[...this.items,...t]}prependItems(...t){this.items=[...t,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout((()=>{this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()}),0)}disconnectedCallback(){super.disconnectedCallback(),this.scrollable=void 0,this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.shouldRestoreScroll=!1}findScrollableParent(t){var i;let s,e;t.stopPropagation();for(let i of t.composedPath()){const t=i,h=this.elementCanScroll(t);if(h&&t.clientHeight&&t.clientHeight<t.scrollHeight){s=t;break}h&&null==e&&(e=t)}this.scrollable=null!==(i=null!=s?s:e)&&void 0!==i?i:document.body,this.resetScroll(!1)}elementCanScroll(t){try{return["auto","scroll"].includes(getComputedStyle(t).overflowY)}catch(t){return!1}}resetIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]}),this.onMutation()}searchFirstVisibleItem(t,i,s,e){if(s=null!=s?s:0,(e=null!=e?e:i.length-1)<=s)return i[s];const h=Math.floor((e-s)/2)+s,l=i[h];let n=this.getOffset(l);return n>t?this.searchFirstVisibleItem(t,i,s,h-1):n+l.clientHeight<t?this.searchFirstVisibleItem(t,i,h+1,e):l}get shouldRestoreScroll(){return this._shouldRestoreScroll}set shouldRestoreScroll(t){let i=t&&!this._shouldRestoreScroll;this._shouldRestoreScroll=t,i&&requestAnimationFrame(this.scrollAdjustment)}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)||t.has("internalScroll"))&&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 d)}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.resetIntersectionObserver()}))}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 a(this.visibleItems,this.visibleItems.map((t=>this.items[t])))))).catch((()=>null))}}c.styles=r,o([e.property({type:Array})],c.prototype,"items",void 0),o([e.property({attribute:!1})],c.prototype,"renderItem",void 0),o([e.property({attribute:!1})],c.prototype,"getItemKey",void 0),o([e.property({type:Object})],c.prototype,"scrollToItem",void 0),o([e.property({type:Number})],c.prototype,"scrollToIndex",void 0),o([e.property({type:Boolean})],c.prototype,"internalScroll",void 0),o([e.property({type:Number})],c.prototype,"renderBeforeFirst",void 0),o([e.property({type:Number})],c.prototype,"renderAfterLast",void 0),o([e.property({type:Boolean})],c.prototype,"ensureScrollToTarget",void 0),o([e.state({hasChanged:(t,i)=>null!=t&&null==i||t.length!==i.length||t[0]!==i[0]})],c.prototype,"visibleItems",void 0),o([e.query(".scrollable")],c.prototype,"internalScrollable",void 0),o([e.query(".items-container")],c.prototype,"itemsContainer",void 0),o([e.state()],c.prototype,"scrolledToTarget",void 0),o([e.state()],c.prototype,"scrolling",void 0),o([e.state({hasChanged:(t,s)=>!i.deepEqual(t,s)})],c.prototype,"renderedIndexes",void 0),i.customElement("ft-infinite-scroll")(c),t.FtInfiniteScroll=c,t.FtInfiniteScrollCssVariables=n,t.ScrolledToTargetEvent=d,t.VisibleItemsChangeEvent=a,t.styles=r}({},ftGlobals.wcUtils,ftGlobals.lit,ftGlobals.litDecorators,ftGlobals.litRepeat,ftGlobals.litUnsafeHTML);
43
+ `}prepareRenderIfNeeded(e){let t=this.renderApprovalTimeouts[e]!=null;this.inRenderRange(e)&&!t&&(this.renderApprovalTimeouts[e]=setTimeout(()=>{this.inRenderRange(e)?this.renderedIndexes.add(e):this.renderApprovalTimeouts[e]=void 0,this.requestUpdate()},300))}inRenderRange(e){return e>=this.visibleItems[0]-this.renderBeforeFirst&&e<=G(this.visibleItems)+this.renderAfterLast}resetScroll(e=!0){var t;if(this.shouldRestoreScroll=!1,this.intersectionObserver.disconnect(),this.visibleItems=[],this.scrolledToTarget=!1,this.internalScroll&&this.scrollable!==this.internalScrollable)this.scrollable=this.internalScrollable;else if(!this.internalScroll&&e){(t=this.itemsContainer)===null||t===void 0||t.dispatchEvent(new Event("find-scrollable-parent",{composed:!0}));return}let s=this.resolveScrollToIndex();this.renderedIndexes.add(s),this.scrollToTarget(s),this.scrollDoneDebouncer.run(()=>{this.ensureScrollToTarget&&s>=0&&this.scrollDebouncer.run(()=>{Math.abs(this.scrollable.scrollTop-this.getOffset(s))>5&&this.scrollToTarget(s)},500),this.scrollToTarget(s),this.scrolledToTarget=!0,this.shouldRestoreScroll=!0,this.resetIntersectionObserver()})}resolveScrollToIndex(){var e;let t=(e=this.scrollToIndex)!==null&&e!==void 0?e:this.scrollToItem?this.items.indexOf(this.scrollToItem):-1;return t>=this.items.length?-1:t}getItem(e){var t,s,i;return(s=(t=this.shadowRoot)===null||t===void 0?void 0:t.querySelector(`#item-${e}`))!==null&&s!==void 0?s:(i=this.shadowRoot)===null||i===void 0?void 0:i.querySelector("#item-0")}scrollToTarget(e){e<=0?(this.scrollable.scrollTop=0,this.scrollRestorationOffset=-this.getOffset(e)):(this.scrollable.scrollTop=this.getOffset(e),this.scrollRestorationOffset=0),this.scrollRestorationItem=e>=0?e:void 0}getOffset(e){var t;let s=0,i=typeof e=="number"?this.getItem(e):e;for(;i&&i.offsetParent!==this.scrollable.offsetParent;)s+=i.offsetTop,i=i.offsetParent;return s+((t=i?.offsetTop)!==null&&t!==void 0?t:0)-this.scrollable.offsetTop}appendItems(...e){this.items=[...this.items,...e]}prependItems(...e){this.items=[...e,...this.items]}connectedCallback(){super.connectedCallback(),setTimeout(()=>{this.mutationObserver.disconnect(),this.mutationObserver.observe(this.itemsContainer,{childList:!0}),this.resetScroll()},0)}disconnectedCallback(){super.disconnectedCallback(),this.scrollable=void 0,this.intersectionObserver.disconnect(),this.mutationObserver.disconnect(),this.shouldRestoreScroll=!1}findScrollableParent(e){var t;e.stopPropagation();let s,i;for(let l of e.composedPath()){let o=l,d=this.elementCanScroll(o);if(d&&o.clientHeight&&o.clientHeight<o.scrollHeight){s=o;break}else d&&i==null&&(i=o)}this.scrollable=(t=s??i)!==null&&t!==void 0?t:document.body,this.resetScroll(!1)}elementCanScroll(e){try{return["auto","scroll"].includes(getComputedStyle(e).overflowY)}catch{return!1}}resetIntersectionObserver(){this.intersectionObserver.disconnect(),this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange,{root:this.scrollable,rootMargin:"-8px",threshold:[0,.01,.1,1]}),this.onMutation()}searchFirstVisibleItem(e,t,s,i){if(s=s??0,i=i??t.length-1,i<=s)return t[s];let l=Math.floor((i-s)/2)+s,o=t[l],d=this.getOffset(o);return d>e?this.searchFirstVisibleItem(e,t,s,l-1):d+o.clientHeight<e?this.searchFirstVisibleItem(e,t,l+1,i):o}get shouldRestoreScroll(){return this._shouldRestoreScroll}set shouldRestoreScroll(e){let t=e&&!this._shouldRestoreScroll;this._shouldRestoreScroll=e,t&&requestAnimationFrame(this.scrollAdjustment)}update(e){super.update(e),e.has("items")&&(this.renderedIndexes=new Set,this.renderApprovalTimeouts=[]),((e.has("scrollToItem")||e.has("scrollToIndex"))&&(this.scrollToItem!=null||this.scrollToIndex!=null)||e.has("internalScroll"))&&this.resetScroll()}updated(e){super.updated(e),(e.has("visibleItems")||e.has("items"))&&this.onVisibleItemsChange(),e.has("scrolledToTarget")&&this.scrolledToTarget&&(this.scrollToItem!=null||this.scrollToIndex!=null)&&this.dispatchEvent(new S)}onVisibleItemsChange(){this.visibleItems.every((t,s)=>this.visibleItems[s+1]==null||t+1===this.visibleItems[s+1])||(0,c.deepEqual)(this.visibleItems,this.lastNotOkVisibleItems)?(this.resetVisibleItemsDebouncer.cancel(),this.dispatchVisibleItemsEvent()):this.resetVisibleItemsDebouncer.run(()=>{this.lastNotOkVisibleItems=[...this.visibleItems],this.visibleItems=[],this.resetIntersectionObserver()})}dispatchVisibleItemsEvent(){var e;(e=this.cancelableDispatchEvent)===null||e===void 0||e.cancel(),this.cancelableDispatchEvent=(0,c.cancelable)((0,c.waitUntil)(()=>!this.scrolling)),this.cancelableDispatchEvent.then(()=>this.dispatchEvent(new T(this.visibleItems,this.visibleItems.map(t=>this.items[t])))).catch(()=>null)}};n.styles=D;h([(0,a.property)({type:Array})],n.prototype,"items",void 0);h([(0,a.property)({attribute:!1})],n.prototype,"renderItem",void 0);h([(0,a.property)({attribute:!1})],n.prototype,"getItemKey",void 0);h([(0,a.property)({type:Object})],n.prototype,"scrollToItem",void 0);h([(0,a.property)({type:Number})],n.prototype,"scrollToIndex",void 0);h([(0,a.property)({type:Boolean})],n.prototype,"internalScroll",void 0);h([(0,a.property)({type:Number})],n.prototype,"renderBeforeFirst",void 0);h([(0,a.property)({type:Number})],n.prototype,"renderAfterLast",void 0);h([(0,a.property)({type:Boolean})],n.prototype,"ensureScrollToTarget",void 0);h([(0,a.state)({hasChanged(r,e){return r!=null&&e==null||r.length!==e.length||r[0]!==e[0]}})],n.prototype,"visibleItems",void 0);h([(0,a.query)(".scrollable")],n.prototype,"internalScrollable",void 0);h([(0,a.query)(".items-container")],n.prototype,"itemsContainer",void 0);h([(0,a.state)()],n.prototype,"scrolledToTarget",void 0);h([(0,a.state)()],n.prototype,"scrolling",void 0);h([(0,a.state)({hasChanged:(r,e)=>!(0,c.deepEqual)(r,e)})],n.prototype,"renderedIndexes",void 0);(0,$.customElement)("ft-infinite-scroll")(n);})();