@kedem/okdb 2.1.0 → 2.1.2

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 +1 @@
1
- function t(t,e){let i=0,s=t.length-1;for(;i<=s;){const r=Math.floor((i+s)/2);t[r]<e?i=r+1:s=r-1}return i}var e={tag:"virtualized",attr:{items:{alias:[""],default:[]}},context(e){const i=[],s=[];let r=0,a=0,l=new Set,o=0,h=!1,n=!1,c=null,d=0,u=null,g=1/0;return{get firstLoad(){return e.$attr.firstLoad||10},get overscan(){return Math.max(e.$attr.overscan||2,1)},get defaultHeight(){return Number.parseInt(e.$attr.defaultHeight??50)},get averageHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:a>0?r/a:50},holeHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:c??(c=this.averageHeight)},get items(){return e.$attr.items||[]},get itemClass(){return e.$attr.itemClass||"virtualized-item"},get pinBottom(){return"bottom"===e.$attr.pin},atTop:!0,atBottom:!1,scrollTop:0,windowTop:0,gapBottom:0,contentHeight:0,start:0,startVisible:0,endVisible:0,end:0,view:[],scroller:null,rebuildAcc(){this.rebuildAccFrom(0)},rebuildAccFrom(t){const e=this.holeHeight();s.length=i.length;for(let r=t;r<i.length;r++)s[r]=(s[r-1]||0)+(i[r]??e);g=1/0},syncHeights(){i.length=this.items.length,this.rebuildAcc()},handleUnshift(t){i.unshift(...Array(t)),this.rebuildAcc()},handlePush(t){const e=this.holeHeight();for(let r=0;r<t;r++){const t=s.length>0?s[s.length-1]:0;i.push(void 0),s.push(t+e)}},handlePop(){i.pop(),s.pop()},handleShift(){i.shift(),this.rebuildAcc()},handleSplice(t,e,s){i.splice(t,e,...Array(s)),this.rebuildAcc()},handleReplace(){i.length=0,i.length=this.items.length,this.rebuildAcc()},scheduleUpdate(t=!1){h||=t,n||(n=!0,setTimeout(()=>{n=!1,this.update(h),h=!1},100))},update(i){if(!(this.scroller&&e.$el instanceof Element&&e.$el.isConnected))return;if(Date.now()-d>200){let t=g;if(null==e.$attr.defaultHeight&&a>0){const e=this.averageHeight;(null==c||Math.abs(e-c)>.5)&&(c=e,t=0)}t!==1/0&&this.rebuildAccFrom(t)}const r=s[this.items.length-1]||0,l=this.pinBottom&&this.atBottom;let h=null!=o?o:this.scrollTop;if((l||h>=r)&&(h=Math.max(0,r-this.scroller.clientHeight)),!i&&h===this.scrollTop&&this.view.length>0)return;const n=t(s,h),u=t(s,h+this.scroller.clientHeight),p=Math.max(n-this.overscan,0),m=Math.min(u+this.overscan,this.items.length-1);if(p===this.start&&m===this.end&&!i)return;this.scrollTop=h,this.start=p,this.end=m,this.startVisible=Math.max(p,n),this.endVisible=Math.min(m,u),this.windowTop=s[this.start-1]||0,this.gapBottom=r-(s[this.end]||0),this.view=this.items.slice(this.start,this.end+1),this.contentHeight=r;const v=getComputedStyle(e.$el),f=parseFloat(v.minHeight)||0,b=parseFloat(v.maxHeight)||1/0,x=Math.max(f,Math.min(r,b));this.scroller.style.height=x+1+"px",this.atTop=this.scrollTop<=5,this.atBottom=this.scrollTop+this.scroller.clientHeight>=this.scroller.scrollHeight-24,l&&e.$ok.nextFrame(()=>{this.scroller&&e.$el.isConnected&&(this.scroller.scrollTop=this.scroller.scrollHeight,this.atBottom=!0)})},updateItemSize(t){const e=t.$vars.index+this.start;if(e>=this.items.length)return;const s=t.$el.offsetHeight,l=i[e];l!==s?(r+=s-(l||0),l||a++,i[e]=s,g=Math.min(g,e),this.scheduleUpdate(!0)):this.scheduleUpdate()},itemMounted(t){l.add(t),e.$ok.nextFrame(()=>{l.delete(t),this.updateItemSize(t);const i=t.$el;e.$cache.virtualized.resizeMap.set(i,t),e.$cache.virtualized.resizeObserver.observe(i)})},itemUnmounted(t){const i=e.$cache.virtualized;t?.$el&&i.resizeObserver&&(i.resizeObserver.unobserve(t.$el),i.resizeMap.delete(t.$el))},onScroll(t){o=t.target.scrollTop,d=Date.now(),this.update(!1),clearTimeout(u),u=setTimeout(()=>this.update(!0),250)}}},mount(t){const e=t.$cache.virtualized={resizeMap:new WeakMap,resizeObserver:null};e.resizeObserver=new ResizeObserver(i=>{t.$ok.nextFrame(()=>{for(const t of i){const i=e.resizeMap.get(t.target);i&&this.updateItemSize(i)}})});const i=t=>{if(Array.isArray(t.target))if("length"===t.property){switch(t.mode){case"splice":const[e,i,...s]=t.args;this.handleSplice(e,i,s.length);break;case"push":this.handlePush(t.args.length);break;case"pop":this.handlePop();break;case"shift":this.handleShift();break;case"unshift":this.handleUnshift(t.args.length);break;default:this.handleReplace()}this.scheduleUpdate(!0)}else"set"===t.mode&&this.scheduleUpdate(!0)};t.$watch(()=>this.items,()=>{this.syncHeights(),this.scheduleUpdate(!0),t.$observe(this.items,null,i)}).run()},template:'<slot name="before"/><div :ref="scroller=$el" style="min-height:100%;overflow:auto;margin:0;position:relative;overflow-anchor:none" @scroll="onScroll"><div class="virtual-body" style="position:relative;overflow:hidden;width:100%" :style="{ \'height\': contentHeight + \'px\', \'--virt-avg\': averageHeight + \'px\', \'--virt-gap-top\': windowTop + \'px\', \'--virt-gap-bottom\': gapBottom + \'px\' }"><div class="virtual-window" style="position:absolute;left:0;right:0;z-index:1" :style="{ \'top\': windowTop + \'px\' }"><slot name="top"/><each :of="view" let:item let:index><div @mounted="itemMounted" @unmounted="itemUnmounted" :class="{[itemClass]: true, \'--visible\': index + start >= startVisible && index + start <= endVisible }"><slot :var:item="item" :var:index="index + start"/></div></each><slot name="bottom"/></div></div></div><slot name="after"/>',style:"[tag]{position:relative;overflow:hidden;flex-grow:1;max-height:100%}[tag] .virtual-body::after,[tag] .virtual-body::before{content:'';position:absolute;left:0;right:0;background:var(--ok_virtualized-skeleton, repeating-linear-gradient(\n to bottom,\n color-mix(in srgb, currentColor 7%, transparent) 0\n calc(max(var(--virt-avg, 50px) - 8px, 8px)),\n transparent calc(max(var(--virt-avg, 50px) - 8px, 8px))\n max(var(--virt-avg, 50px), 16px)\n ))}[tag] .virtual-body::before{top:0;height:var(--virt-gap-top, 0px)}[tag] .virtual-body::after{bottom:0;height:var(--virt-gap-bottom, 0px)}"};export{e as default};
1
+ function t(t,e){let s=0,i=t.length-1;for(;s<=i;){const l=Math.floor((s+i)/2);t[l]<e?s=l+1:i=l-1}return s}var e={tag:"virtualized",attr:{items:{alias:[""],default:[]}},context(e){const s=[],i=[];let l=0,o=0,r=new Set,h=0,n=!1,a=!1,c=null,d=0,g=null,p=1/0,u=!1,m=null,f=!1,v=0,b=0;return{get firstLoad(){return e.$attr.firstLoad||10},get overscan(){return Math.max(e.$attr.overscan||2,1)},get defaultHeight(){return Number.parseInt(e.$attr.defaultHeight??50)},get averageHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:o>0?l/o:50},holeHeight(){return null!=e.$attr.defaultHeight?this.defaultHeight:c??(c=this.averageHeight)},get items(){return e.$attr.items||[]},get itemClass(){return e.$attr.itemClass||"virtualized-item"},get pinBottom(){return"bottom"===e.$attr.pin||"bottom"===e.$attr.start},get pinTop(){return"top"===e.$attr.pin},atTop:!0,atBottom:!1,following:!1,scrollTop:0,windowTop:0,gapBottom:0,contentHeight:0,start:0,startVisible:0,endVisible:0,end:0,view:[],scroller:null,rebuildAcc(){this.rebuildAccFrom(0)},rebuildAccFrom(t){const e=this.holeHeight();i.length=s.length;for(let l=t;l<s.length;l++)i[l]=(i[l-1]||0)+(s[l]??e);p=1/0},syncHeights(){s.length=this.items.length,this.rebuildAcc()},syncView(t){const e=this.view;if(0===e.length)return void(t.length&&e.push(...t));const s=e.length,i=new Map;for(let t=0;t<s;t++)i.has(e[t])||i.set(e[t],t);let l=0,o=0;for(let s=0;s<t.length;s++){const r=t[s],h=i.get(r);if(void 0===h||h<l)e.splice(o,0,r);else{const t=h-l;t>0&&e.splice(o,t),l=h+1}o++}const r=s-l;r>0&&e.splice(o,r)},handleUnshift(t){const e=t>0&&this.pinTop&&this.scroller;if(s.unshift(...Array(t)),this.rebuildAcc(),e){const e=t*this.holeHeight();this.update(!0),this.scroller.scrollTop+=e,m=v=this.scroller.scrollTop,b=this.endOffset(i[this.items.length-1]||0),this.onScroll({target:this.scroller})}},handlePush(t){const e=this.holeHeight();for(let l=0;l<t;l++){const t=i.length>0?i[i.length-1]:0;s.push(void 0),i.push(t+e)}},handlePop(){s.pop(),i.pop()},handleShift(){s.shift(),this.rebuildAcc()},handleSplice(t,e,i){s.splice(t,e,...Array(i)),this.rebuildAcc()},handleReplace(){s.length=0,s.length=this.items.length,this.rebuildAcc()},scheduleUpdate(t=!1){n||=t,a||(a=!0,setTimeout(()=>{a=!1,this.update(n),n=!1},100))},update(s){if(!(this.scroller&&e.$el instanceof Element&&e.$el.isConnected))return;if(Date.now()-d>200){let t=p;if(null==e.$attr.defaultHeight&&o>0){const e=this.averageHeight;(null==c||Math.abs(e-c)>.5)&&(c=e,t=0)}t!==1/0&&this.rebuildAccFrom(t)}const l=i[this.items.length-1]||0;!u&&"bottom"===e.$attr.start&&this.items.length>0&&(u=!0,this.following=!0);const r=this.pinBottom&&this.following;let n=null!=h?h:this.scrollTop;if((r||n>=l)&&(n=Math.max(0,l-this.scroller.clientHeight)),h=n,r&&this.snapToEnd(l),!s&&n===this.scrollTop&&this.view.length>0)return;const a=t(i,n),g=t(i,n+this.scroller.clientHeight),m=Math.max(a-this.overscan,0),f=Math.min(g+this.overscan,this.items.length-1);if(m===this.start&&f===this.end&&!s)return;this.scrollTop=n,this.start=m,this.end=f,this.startVisible=Math.max(m,a),this.endVisible=Math.min(f,g),this.windowTop=i[this.start-1]||0,this.gapBottom=l-(i[this.end]||0),this.syncView(this.items.slice(this.start,this.end+1)),this.contentHeight=l;const v=getComputedStyle(e.$el),b=parseFloat(v.minHeight)||0,x=parseFloat(v.maxHeight)||1/0,T=Math.max(b,Math.min(l,x));this.scroller.style.height=T+1+"px",this.atTop=this.scrollTop<=5,this.atBottom=this.isAtEnd(this.scrollTop,l)},get bottomSlack(){return Math.max(24,this.holeHeight())},distanceToEnd(t,e){return e-(t+this.scroller.clientHeight)},isAtEnd(t,e,s=this.bottomSlack){return this.distanceToEnd(t,e)<=s},endOffset(t){return Math.max(0,t-this.scroller.clientHeight)},snapToEnd(t){f||(f=!0,e.$ok.nextFrame(()=>{if(f=!1,!this.scroller||!e.$el.isConnected||!this.following)return;const s=Math.max(this.scroller.scrollHeight,t);this.scroller.scrollTop=s,m=this.scroller.scrollTop,v=m,b=this.endOffset(t),this.isAtEnd(m,t)||this.scheduleUpdate(!0)}))},updateItemSize(t){const e=t.$vars.index+this.start;if(e>=this.items.length)return;const i=t.$el.offsetHeight,r=s[e];r!==i?(l+=i-(r||0),r||o++,s[e]=i,p=Math.min(p,e),this.scheduleUpdate(!0)):this.scheduleUpdate()},itemMounted(t){r.add(t),e.$ok.nextFrame(()=>{r.delete(t),this.updateItemSize(t);const s=t.$el;e.$cache.virtualized.resizeMap.set(s,t),e.$cache.virtualized.resizeObserver.observe(s)})},itemUnmounted(t){const s=e.$cache.virtualized;t?.$el&&s.resizeObserver&&(s.resizeObserver.unobserve(t.$el),s.resizeMap.delete(t.$el))},onScroll(t){h=t.target.scrollTop;const e=null!==m&&Math.abs(h-m)<=.5;if(m=null,e||(d=Date.now()),this.pinBottom&&!e){const t=i[this.items.length-1]||0,e=this.endOffset(t),s=Math.max(0,b-e),l=v-h;this.following?l>s+.5&&(this.following=!1):h>v+.5&&this.isAtEnd(h,t)&&(this.following=!0),b=e,this.atBottom=this.isAtEnd(h,t)}v=h,this.update(!1),clearTimeout(g),g=setTimeout(()=>this.update(!0),250)},scrollTo(t,{smooth:e=!1}={}){if(!this.scroller)return;const s=Math.max(0,t);e&&"function"==typeof this.scroller.scrollTo?this.scroller.scrollTo({top:s,behavior:"smooth"}):(this.scroller.scrollTop=s,this.onScroll({target:this.scroller}))},scrollToTop(t){this.scrollTo(0,t)},scrollToEnd(t){this.scroller&&this.scrollTo(this.scroller.scrollHeight,t)},scrollToIndex(t,{align:e="start",smooth:s=!1}={}){if(!this.scroller||!this.items.length)return;const l=Math.max(0,Math.min(t,this.items.length-1)),o=i[l-1]||0,r=i[l]??o;let h=o;"center"===e?h=o-(this.scroller.clientHeight-(r-o))/2:"end"===e&&(h=r-this.scroller.clientHeight),this.scrollTo(h,{smooth:s})},scrollToItem(t,e){const s="function"==typeof t?this.items.findIndex(t):this.items.indexOf(t);-1!==s&&this.scrollToIndex(s,e)}}},mount(t){t.$el.scrollTo=(t,e)=>this.scrollTo(t,e),t.$el.scrollToTop=t=>this.scrollToTop(t),t.$el.scrollToEnd=t=>this.scrollToEnd(t),t.$el.scrollToIndex=(t,e)=>this.scrollToIndex(t,e),t.$el.scrollToItem=(t,e)=>this.scrollToItem(t,e);const e=t.$cache.virtualized={resizeMap:new WeakMap,resizeObserver:null};e.resizeObserver=new ResizeObserver(s=>{t.$ok.nextFrame(()=>{for(const t of s){const s=e.resizeMap.get(t.target);s&&this.updateItemSize(s)}})});const s=t=>{if(Array.isArray(t.target))if("length"===t.property){switch(t.mode){case"splice":const[e,s,...i]=t.args;this.handleSplice(e,s,i.length);break;case"push":this.handlePush(t.args.length);break;case"pop":this.handlePop();break;case"shift":this.handleShift();break;case"unshift":this.handleUnshift(t.args.length);break;default:this.handleReplace()}this.scheduleUpdate(!0)}else"set"===t.mode&&this.scheduleUpdate(!0)};t.$watch(()=>this.items,()=>{this.syncHeights(),this.scheduleUpdate(!0),t.$observe(this.items,null,s)}).run()},template:'<slot name="before"/><div :ref="scroller=$el" style="min-height:100%;overflow:auto;margin:0;position:relative;overflow-anchor:none" @scroll="onScroll"><div class="virtual-body" style="position:relative;overflow:hidden;width:100%" :style="{ \'height\': contentHeight + \'px\', \'--virt-avg\': averageHeight + \'px\', \'--virt-gap-top\': windowTop + \'px\', \'--virt-gap-bottom\': gapBottom + \'px\' }"><div class="virtual-window" style="position:absolute;left:0;right:0;z-index:1" :style="{ \'top\': windowTop + \'px\' }"><slot name="top"/><each :of="view" let:item let:index><div @mounted="itemMounted" @unmounted="itemUnmounted" :class="{[itemClass]: true, \'--visible\': index + start >= startVisible && index + start <= endVisible }"><slot :var:item="item" :var:index="index + start"/></div></each><slot name="bottom"/></div></div></div><slot name="after"/>',style:"[tag]{position:relative;overflow:hidden;flex-grow:1;max-height:100%}[tag] .virtual-body::after,[tag] .virtual-body::before{content:'';position:absolute;left:0;right:0;background:var(--ok_virtualized-skeleton, repeating-linear-gradient(\n to bottom,\n color-mix(in srgb, currentColor 7%, transparent) 0\n calc(max(var(--virt-avg, 50px) - 8px, 8px)),\n transparent calc(max(var(--virt-avg, 50px) - 8px, 8px))\n max(var(--virt-avg, 50px), 16px)\n ))}[tag] .virtual-body::before{top:0;height:var(--virt-gap-top, 0px)}[tag] .virtual-body::after{bottom:0;height:var(--virt-gap-bottom, 0px)}"};export{e as default};