char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
8144f3192
char/aliceai-t5-moe
1export function useScrollCarousel () { 2let canScrollLeft = $state ( false ); 3let canScrollRight = $state ( false ); 4let scrollContainer = $state < HTMLDivElement | undefined >(); 5let contentContainer = $state < HTMLDivElement | undefined >(); 6 7function scrollToCenter ( element :HTMLElement ) { 8if ( ! scrollContainer ) return ; 9 10const containerRect = scrollContainer . getBoundingClientRect (); 11const elementRect = element . getBoundingClientRect (); 12const elementCenter = elementRect . left + elementRect . width / 2 ; 13const containerCenter = containerRect . left + containerRect . width / 2 ; 14const scrollOffset = elementCenter - containerCenter ; 15 16scrollContainer . scrollBy ({ behavior :'smooth' , left :scrollOffset }); 17} 18 19function updateScrollButtons () { 20if ( ! scrollContainer ) return ; 21 22const { clientWidth, scrollLeft :sl , scrollWidth} = scrollContainer ; 23 24canScrollLeft = sl > 0 ; 25canScrollRight = sl < scrollWidth - clientWidth - 1 ; 26} 27 28// Re-evaluate arrow visibility whenever the container or its content resizes, 29// otherwise the arrows may not appear when overflowing items are added (e.g. new 30// tabs/attachments) and the user has not scrolled yet. 31$effect (() => { 32if ( ! scrollContainer ) return ; 33 34updateScrollButtons (); 35 36const observer = new ResizeObserver (() => updateScrollButtons ()); 37 38observer . observe ( scrollContainer ); 39 40if ( contentContainer ) observer . observe ( contentContainer ); 41 42return () => observer . disconnect (); 43}); 44 45return { 46get canScrollLeft () { 47return canScrollLeft ; 48}, 49get canScrollRight () { 50return canScrollRight ; 51}, 52get contentContainer () { 53return contentContainer ; 54}, 55set contentContainer ( el :HTMLDivElement | undefined ) { 56contentContainer = el ; 57}, 58get scrollContainer () { 59return scrollContainer ; 60}, 61set scrollContainer ( el :HTMLDivElement | undefined ) { 62scrollContainer = el ; 63}, 64 scrollToCenter, 65 updateScrollButtons 66}; 67}