@fluid-topics/ft-infinite-scroll 1.1.69 → 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.
- package/build/ft-infinite-scroll.light.js +12 -12
- package/build/ft-infinite-scroll.min.js +193 -135
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
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: ${
|
|
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: ${
|
|
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: ${
|
|
29
|
+
min-height: ${I.itemContainerMinHeight};
|
|
30
30
|
}
|
|
31
|
-
`;var
|
|
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
|
-
${
|
|
35
|
+
${(0,H.repeat)(this.items,(e,t)=>this.getItemKey(e,t),(e,t)=>this.renderItemContainer(e,t))}
|
|
36
36
|
</div>
|
|
37
|
-
`}renderItemContainer(t
|
|
38
|
-
<div id="item-${
|
|
39
|
-
class="item-container ${
|
|
40
|
-
data-item-index="${
|
|
41
|
-
${
|
|
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(
|
|
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);})();
|