@wyxos/vibe 5.6.0 → 5.7.1

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/lib/index.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`);function t(e){return[e,...e.items]}function n(e,t){return Math.min(e.items.length,Math.max(0,t))}function r(e,r){return t(e)[n(e,r)]??e}function i(e,t){return`${String(e)}:${t}`}function a(t){return(0,e.computed)(()=>Object.freeze([...t.items]))}function o(e,t=[...e.items]){return{activeReelPostId:e.activeReelPostId,autoScroll:{...e.autoScroll},autofill:{...e.autofill},current:e.current,error:e.error,fill:{...e.fill,target:e.fill.target?{...e.fill.target}:null},infiniteScroll:e.infiniteScroll,isLoading:e.isLoading,isLoadingMore:e.isLoadingMore,items:t,layout:e.layout,lifecycle:e.isLoading||e.isLoadingMore?`loading`:e.error||e.nextPageError?`error`:`loaded`,loadMoreLocked:e.loadMoreLocked,next:e.next,nextPageError:e.nextPageError,phoneMode:e.phoneMode,reelAutoAdvance:{...e.reelAutoAdvance},reelForward:{...e.reelForward},reelInfoSheet:{...e.reelInfoSheet},reelOrigin:e.reelOrigin,total:e.total}}var s={key:0,class:`gallery-footer`},c={key:0,class:`load-more-status`,role:`status`},l=[`disabled`],u={key:2,class:`end-feed`},d=[`disabled`],f=(0,e.defineComponent)({__name:`GalleryFooter`,props:{canRetryEnd:{type:Boolean},hasError:{type:Boolean},hasNext:{type:Boolean},isLoading:{type:Boolean},loadMoreLocked:{type:Boolean},showLoadMore:{type:Boolean}},emits:[`loadMore`,`retryEnd`],setup(t,{emit:n}){let r=t,i=n;function a(){r.loadMoreLocked||(r.hasNext?i(`loadMore`):i(`retryEnd`))}return(n,r)=>t.isLoading||t.hasError||t.hasNext&&t.showLoadMore||!t.hasNext&&t.canRetryEnd?((0,e.openBlock)(),(0,e.createElementBlock)(`footer`,s,[t.isLoading?((0,e.openBlock)(),(0,e.createElementBlock)(`p`,c,` Loading more… `)):t.hasError||t.hasNext&&t.showLoadMore?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:1,"data-test":`load-more`,class:`load-more-button`,type:`button`,disabled:t.loadMoreLocked,onClick:a},(0,e.toDisplayString)(t.hasError?`Try again`:t.loadMoreLocked?`Loading paused`:`Load more`),9,l)):((0,e.openBlock)(),(0,e.createElementBlock)(`div`,u,[r[1]||=(0,e.createElementVNode)(`p`,{class:`end-feed-message`,role:`status`},` You've reached the end. `,-1),(0,e.createElementVNode)(`button`,{"data-test":`retry-end`,class:`load-more-button`,type:`button`,disabled:t.loadMoreLocked,onClick:r[0]||=e=>n.$emit(`retryEnd`)},` Check for more `,8,d)]))])):(0,e.createCommentVNode)(``,!0)}}),p=(0,e.defineComponent)({__name:`FeedFooter`,props:{actions:{},canRetryEnd:{type:Boolean},feedFooter:{},hasError:{type:Boolean},hasNext:{type:Boolean},isLoading:{type:Boolean},loadMoreLocked:{type:Boolean},showLoadMore:{type:Boolean},state:{}},emits:[`loadMore`,`retryEnd`],setup(t,{emit:n}){let r=t,i=n;function a(){r.actions?.cancelAutofill()}function o(){r.actions?.retry()}return(n,r)=>t.feedFooter&&t.actions&&t.state?((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.feedFooter.component),{key:0,actions:t.actions,"can-retry-end":t.canRetryEnd,"show-load-more":t.showLoadMore,state:t.state,onAutofillCancel:a,onLoadMore:r[0]||=e=>i(`loadMore`),onRetry:o,onRetryEnd:r[1]||=e=>i(`retryEnd`)},null,40,[`actions`,`can-retry-end`,`show-load-more`,`state`])):((0,e.openBlock)(),(0,e.createBlock)(f,{key:1,"can-retry-end":t.canRetryEnd,"has-error":t.hasError,"has-next":t.hasNext,"is-loading":t.isLoading,"load-more-locked":t.loadMoreLocked,"show-load-more":t.showLoadMore,onLoadMore:r[2]||=e=>i(`loadMore`),onRetryEnd:r[3]||=e=>i(`retryEnd`)},null,8,[`can-retry-end`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`show-load-more`]))}}),m=[`role`],h={class:`gallery-status`},g=(0,e.defineComponent)({__name:`FeedStatus`,props:{actions:{},canRetryEnd:{type:Boolean},feedFooter:{},state:{}},emits:[`loadMore`,`retryEnd`],setup(t,{emit:n}){let r=t,i=n;return(n,a)=>((0,e.openBlock)(),(0,e.createElementBlock)(`main`,{class:`gallery-shell`,role:r.state.error?`alert`:r.state.isLoading?`status`:void 0},[(0,e.createElementVNode)(`p`,h,[r.state.error?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:0},[(0,e.createTextVNode)(` Unable to load media. `)],64)):r.state.isLoading?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:1},[(0,e.createTextVNode)(` Loading media… `)],64)):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:2},[(0,e.createTextVNode)(` No media found. `)],64))]),t.feedFooter?((0,e.openBlock)(),(0,e.createBlock)(p,{key:0,actions:t.actions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,"has-error":!!t.state.nextPageError,"has-next":t.state.next!==null,"is-loading":t.state.isLoadingMore,"load-more-locked":t.state.loadMoreLocked,"show-load-more":``,state:t.state,onLoadMore:a[0]||=e=>i(`loadMore`),onRetryEnd:a[1]||=e=>i(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`state`])):(0,e.createCommentVNode)(``,!0)],8,m))}});function _(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=240}function v(e){let t=e.preview.width??e.width,n=e.preview.height??e.height;return!t||!n||t<=0||n<=0?1:n/t}function y(e){return e.reduce((t,n,r)=>n<e[t]?r:t,0)}function b(e){return Math.max(0,e.containerHeight)+Math.max(0,e.gap)}function x(e,t,n){if(t<=0||e.length===0)return{columns:0,height:0,items:[]};let r=Math.max(0,n.gap),i=Number.isFinite(n.additionalHeight)?Math.max(0,n.additionalHeight??0):0,a=Math.max(1,n.minColumnWidth),o=Math.max(1,Math.floor((t+r)/(a+r))),s=(t-r*(o-1))/o,c=Array.from({length:o},()=>0),l=e.map(e=>{let t=y(c),n=s*v(e)+i,a={x:t*(s+r),y:c[t],width:s,height:n};return c[t]+=n+r,a});return{columns:o,height:Math.max(...c)-r,items:l}}function S(e,t){let n=new Map;return e.forEach((e,r)=>{let i=n.get(e.x)??[];i.push({bottom:e.y+e.height,index:t?.[r]??r,top:e.y}),n.set(e.x,i)}),{columns:[...n.entries()].sort(([e],[t])=>e-t).map(([,e])=>e.sort((e,t)=>e.top-t.top||e.index-t.index))}}function C(e,t){let n=0,r=0,i=e.length;for(;r<i;){let a=Math.floor((r+i)/2);n+=1,e[a].bottom<t?r=a+1:i=a}return{index:r,inspected:n}}function w(e,t){let n=Math.max(0,t.overscan),r=t.scrollTop-n,i=t.scrollTop+Math.max(0,t.viewportHeight)+n,a=[],o=0;return e.columns.forEach(e=>{let t=C(e,r);o+=t.inspected;for(let n=t.index;n<e.length;n+=1){let t=e[n];if(o+=1,t.top>i)break;a.push(t.index)}}),{indices:a.sort((e,t)=>e-t),inspected:o}}function T(e){return e?.minColumnWidth??240}function E(e,t){let n=e?.overscan?.minimumPx??800,r=e?.overscan?.viewportMultiplier??1.5,i=Math.max(n,t*r),a=e?.overscan?.maximumPx;return a===void 0?i:Math.min(i,a)}function D(e){if(e?.minColumnWidth!==void 0&&(!Number.isFinite(e.minColumnWidth)||e.minColumnWidth<=0))throw TypeError(`Vibe masonry minColumnWidth must be a positive number.`);let t=e?.overscan;if(t){for(let[e,n]of[[`maximumPx`,t.maximumPx],[`minimumPx`,t.minimumPx],[`viewportMultiplier`,t.viewportMultiplier]])if(n!==void 0&&(!Number.isFinite(n)||n<0))throw TypeError(`Vibe masonry overscan ${e} must be a non-negative number.`);if(t.maximumPx!==void 0&&t.minimumPx!==void 0&&t.maximumPx<t.minimumPx)throw TypeError(`Vibe masonry overscan maximumPx must be greater than or equal to minimumPx.`)}}function O(e,t,n){return Math.min(n,Math.max(t,e))}function k({contentSize:e,minimumThumbSize:t,scrollPosition:n,trackSize:r,viewportSize:i}){let a=Math.max(0,e),o=Math.max(0,r),s=Math.max(0,i),c=Math.max(0,a-s);if(!(c>0&&o>0))return{maximumScrollPosition:c,scrollable:!1,thumbOffset:0,thumbSize:o,thumbTravel:0};let l=O(s/a*o,Math.min(Math.max(0,t),o),o),u=Math.max(0,o-l);return{maximumScrollPosition:c,scrollable:!0,thumbOffset:u*(O(n,0,c)/c),thumbSize:l,thumbTravel:u}}var A=[`aria-hidden`],j=[`aria-controls`,`aria-valuemax`,`aria-valuenow`,`tabindex`],M=32,N=40,P=120,F=(0,e.defineComponent)({__name:`GalleryScrollbar`,props:{contentSize:{},controlsId:{},scrollElement:{},suspended:{type:Boolean}},setup(t){let n=t,r={maximumScrollPosition:0,scrollable:!1,thumbOffset:0,thumbSize:0,thumbTravel:0},i=(0,e.shallowRef)(null),a=(0,e.shallowRef)(r),o=(0,e.shallowRef)(!1),s=(0,e.shallowRef)(!1),c=(0,e.shallowRef)(!1),l=null,u=0,d=0,f=null,p=null,m=null,h=null,g=!1,_=null,v=(0,e.computed)(()=>a.value.scrollable&&!n.suspended),y=(0,e.computed)(()=>({height:`${a.value.thumbSize}px`,transform:`translate3d(0, ${a.value.thumbOffset}px, 0)`}));function b(){f!==null&&clearTimeout(f),f=setTimeout(()=>{f=null,o.value||(s.value=!1)},P)}function x(){s.value=!0,b()}function S(){let e=n.scrollElement,t=i.value;return!e||!t?r:k({contentSize:e.scrollHeight,minimumThumbSize:M,scrollPosition:e.scrollTop,trackSize:t.clientHeight,viewportSize:e.clientHeight})}function C(e){if(o.value&&e!==`scroll`){g=!0;return}if(o.value){let e=n.scrollElement;if(!e||a.value.maximumScrollPosition<=0)return;let t=Math.min(1,Math.max(0,e.scrollTop/a.value.maximumScrollPosition));a.value={...a.value,thumbOffset:a.value.thumbTravel*t};return}a.value=S(),!(c.value||p!==null)&&(p=requestAnimationFrame(()=>{p=null,c.value=!0}))}function w(){x(),C(`scroll`)}function T(e){let t=n.scrollElement;t&&(t.scrollTop=Math.min(a.value.maximumScrollPosition,Math.max(0,e)),C(`scroll`))}function E(e){if(!v.value||e.target!==e.currentTarget)return;let t=i.value;if(!t||a.value.thumbTravel<=0)return;e.preventDefault(),x();let n=e.clientY-t.getBoundingClientRect().top-a.value.thumbSize/2;T(Math.min(1,Math.max(0,n/a.value.thumbTravel))*a.value.maximumScrollPosition)}function D(e){v.value&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture?.(e.pointerId),l=e.pointerId,u=e.clientY,d=n.scrollElement?.scrollTop??0,o.value=!0,s.value=!0,f!==null&&clearTimeout(f),f=null)}function O(e){if(!o.value||e.pointerId!==l||(e.preventDefault(),a.value.thumbTravel<=0))return;let t=(e.clientY-u)/a.value.thumbTravel*a.value.maximumScrollPosition;T(d+t)}function F(e){!o.value||e.pointerId!==l||(e.currentTarget.releasePointerCapture?.(e.pointerId),l=null,o.value=!1,g&&(g=!1,C(`content`)),b())}function I(e){if(!v.value)return;let t=n.scrollElement?.clientHeight??0,r=n.scrollElement?.scrollTop??0,i=e.key===`ArrowUp`?r-N:e.key===`ArrowDown`?r+N:e.key===`PageUp`?r-t:e.key===`PageDown`?r+t:e.key===`Home`?0:e.key===`End`?a.value.maximumScrollPosition:null;i!==null&&(e.preventDefault(),x(),T(i))}function L(e){if(h?.disconnect(),!(typeof ResizeObserver>`u`)){h=new ResizeObserver(()=>C(`content`));for(let t of e.children)h.observe(t)}}return(0,e.watch)(()=>n.scrollElement,(t,n)=>{n?.removeEventListener(`scroll`,w),m?.disconnect(),m=null,h?.disconnect(),h=null,_?.disconnect(),_=null,t?.addEventListener(`scroll`,w,{passive:!0}),t&&typeof ResizeObserver<`u`&&(_=new ResizeObserver(()=>{x(),C(`resize`)}),_.observe(t),L(t)),t&&typeof MutationObserver<`u`&&(m=new MutationObserver(()=>{L(t),C(`content`)}),m.observe(t,{childList:!0})),(0,e.nextTick)(()=>C(`resize`))},{immediate:!0}),(0,e.watch)(()=>n.contentSize,()=>{(0,e.nextTick)(()=>C(`content`))}),(0,e.onBeforeUnmount)(()=>{n.scrollElement?.removeEventListener(`scroll`,w),m?.disconnect(),h?.disconnect(),_?.disconnect(),f!==null&&clearTimeout(f),p!==null&&cancelAnimationFrame(p)}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{ref_key:`trackElement`,ref:i,class:(0,e.normalizeClass)([`gallery-scrollbar`,{"gallery-scrollbar--dragging":o.value,"gallery-scrollbar--interacting":s.value,"gallery-scrollbar--ready":c.value,"gallery-scrollbar--visible":v.value}]),"aria-hidden":!v.value||void 0,onPointerdown:E},[(0,e.createElementVNode)(`div`,{class:`gallery-scrollbar-thumb`,"aria-controls":t.controlsId,"aria-label":`Media gallery scroll position`,"aria-orientation":`vertical`,"aria-valuemax":Math.round(a.value.maximumScrollPosition),"aria-valuemin":`0`,"aria-valuenow":Math.round(t.scrollElement?.scrollTop??0),role:`scrollbar`,style:(0,e.normalizeStyle)(y.value),tabindex:v.value?0:-1,onKeydown:I,onPointercancel:F,onPointerdown:D,onPointermove:O,onPointerup:F},null,44,j)],42,A))}}),I=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},L=e=>e===``,R=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),z=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),B=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),V=e=>{let t=B(e);return t.charAt(0).toUpperCase()+t.slice(1)},H={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`},U=({name:t,iconNode:n,absoluteStrokeWidth:r,"absolute-stroke-width":i,strokeWidth:a,"stroke-width":o,size:s=H.width,color:c=H.stroke,...l},{slots:u})=>(0,e.h)(`svg`,{...H,...l,width:s,height:s,stroke:c,"stroke-width":L(r)||L(i)||r===!0||i===!0?Number(a||o||H[`stroke-width`])*24/Number(s):a||o||H[`stroke-width`],class:R(`lucide`,l.class,...t?[`lucide-${z(V(t))}-icon`,`lucide-${z(t)}`]:[`lucide-icon`]),...!u.default&&!I(l)&&{"aria-hidden":`true`}},[...n.map(t=>(0,e.h)(...t)),...u.default?[u.default()]:[]]),W=(t,n)=>(r,{slots:i,attrs:a})=>(0,e.h)(U,{...a,...r,iconNode:n,name:t},i),G=W(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),ee=W(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),K=W(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),q=W(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),J=W(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]),te=W(`volume-x`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`line`,{x1:`22`,x2:`16`,y1:`9`,y2:`15`,key:`1ewh16`}],[`line`,{x1:`16`,x2:`22`,y1:`9`,y2:`15`,key:`5ykzw1`}]]),Y={401:`Authentication required`,403:`Access forbidden`,404:`Preview not found`,419:`Session expired`,500:`Server error`};function ne(e){return e.match(/\/demo-errors\/(401|403|404|419|500)\//)?.[1]??`Error`}function re(e){return Y[ne(e)]??`Preview unavailable`}var ie=(0,e.defineComponent)({__name:`CardRegion`,props:{index:{},item:{},layout:{},loadedCount:{},mediaIndex:{},mediaSource:{},placement:{},region:{},style:{},total:{}},setup(i){let a=i,o=(0,e.computed)(()=>n(a.item,a.mediaIndex)),s=(0,e.computed)(()=>t(a.item)),c=(0,e.computed)(()=>r(a.item,o.value)),l=(0,e.computed)(()=>({height:`${a.region.height}px`,paddingBlock:a.style?.paddingY===void 0?void 0:`${a.style.paddingY}px`,paddingInline:a.style?.paddingX===void 0?void 0:`${a.style.paddingX}px`})),u=(0,e.computed)(()=>a.style?.background??a.region.background);return(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:(0,e.normalizeClass)([`media-card-region`,[`media-card-${i.placement}`,{"media-card-region--transparent":u.value===`transparent`}]]),style:(0,e.normalizeStyle)(l.value),onClick:n[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:n[1]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(i.region.component),{index:i.index,item:i.item,layout:i.layout,"loaded-count":i.loadedCount,"media-count":s.value.length,"media-index":o.value,"media-item":c.value,"media-source":i.mediaSource??`preview`,total:i.total},null,8,[`index`,`item`,`layout`,`loaded-count`,`media-count`,`media-index`,`media-item`,`media-source`,`total`]))],38))}}),ae=[`max`,`value`,`aria-valuetext`,`disabled`],oe={key:0,class:`media-controls-row`},se=[`aria-label`,`title`],ce={class:`media-controls-audio`},le=[`aria-label`,`title`],ue=[`value`,`aria-valuetext`],de={class:`media-control-time`,"aria-live":`off`},fe=(0,e.defineComponent)({__name:`MediaControls`,props:{currentTime:{},duration:{},layout:{},muted:{type:Boolean},playing:{type:Boolean},volume:{}},emits:[`seek`,`toggleMute`,`togglePlayback`,`volumeChange`],setup(t,{emit:n}){let r=t,i=n;function a(e,t=1){return Number.isFinite(e)?Math.min(t,Math.max(0,e)):0}function o(e){let t=Math.floor(a(e,2**53-1)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}function s(e){return Number(e.target.value)}let c=(0,e.computed)(()=>Math.max(0,r.duration)),l=(0,e.computed)(()=>a(r.currentTime,c.value)),u=(0,e.computed)(()=>({"--media-range-progress":`${c.value>0?l.value/c.value*100:0}%`})),d=(0,e.computed)(()=>({"--media-range-progress":`${a(r.volume)*100}%`}));return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:(0,e.normalizeClass)([`media-controls`,`media-controls--${t.layout}`]),"aria-label":`Video controls`,onClick:r[4]||=(0,e.withModifiers)(()=>{},[`stop`]),onDblclick:r[5]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:r[6]||=(0,e.withModifiers)(()=>{},[`stop`]),onWheel:r[7]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`input`,{class:`media-control-range media-control-seek`,type:`range`,min:`0`,max:c.value||0,step:`0.1`,value:l.value,style:(0,e.normalizeStyle)(u.value),"aria-label":`Seek video`,"aria-valuetext":`${o(l.value)} of ${o(c.value)}`,disabled:c.value<=0,onInput:r[0]||=e=>i(`seek`,s(e))},null,44,ae),t.layout===`reel`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,oe,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button media-control-playback`,"aria-label":t.playing?`Pause video`:`Play video`,title:t.playing?`Pause`:`Play`,onClick:r[1]||=e=>i(`togglePlayback`)},[t.playing?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(K),{key:0,size:18,fill:`currentColor`})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(q),{key:1,size:18,fill:`currentColor`}))],8,se),(0,e.createElementVNode)(`div`,ce,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button`,"aria-label":t.muted?`Unmute video`:`Mute video`,title:t.muted?`Unmute`:`Mute`,onClick:r[2]||=e=>i(`toggleMute`)},[t.muted||t.volume===0?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(te),{key:0,size:18})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(J),{key:1,size:18}))],8,le),(0,e.createElementVNode)(`input`,{class:`media-control-range media-control-volume`,type:`range`,min:`0`,max:`1`,step:`0.05`,value:t.volume,style:(0,e.normalizeStyle)(d.value),"aria-label":`Video volume`,"aria-valuetext":`${Math.round(t.volume*100)} percent`,onInput:r[3]||=e=>i(`volumeChange`,s(e))},null,44,ue)]),(0,e.createElementVNode)(`output`,de,(0,e.toDisplayString)(o(l.value))+` / `+(0,e.toDisplayString)(o(c.value)),1)])):(0,e.createCommentVNode)(``,!0)],34))}});function pe(t){let n=(0,e.computed)(()=>t.layout()!==`reel`||t.active()===!0),r=(0,e.computed)(()=>n.value?t.videoIsMuted.value:!0);function i(){if(!n.value){t.videoElement.value?.pause(),t.videoIsPlaying.value=!1;return}t.videoIsPlaying.value=!0}return(0,e.watch)(n,r=>{let i=t.videoElement.value;if(!r){i?.pause(),i&&(i.muted=!0),t.videoIsPlaying.value=!1;return}(0,e.nextTick)().then(async()=>{let e=t.videoElement.value;if(!(!e||!n.value)){e.muted=t.videoIsMuted.value;try{await e.play()}catch{t.videoIsPlaying.value=!1}}})}),{effectiveMuted:r,onPlaying:i,playbackAllowed:n}}var X=/\.(aac|flac|m4a|mp3|mp4|mov|ogg|opus|wav|webm)$/i;function me(e){try{return X.test(new URL(e).pathname)}catch{return X.test(e.split(`?`)[0]??e)}}function he(e,t){return e===void 0?me(t):e===`video`}function ge(t){let n=(0,e.computed)(()=>he(t.mediaType(),t.mediaSource())),r=(0,e.computed)(()=>t.layout()===`masonry`&&t.fetchPriority()===`low`?`lazy`:`eager`),i=(0,e.computed)(()=>t.layout()===`reel`&&!t.active()?`none`:t.fetchPriority()===`high`?`auto`:t.layout()===`masonry`?`none`:`metadata`);return(0,e.watch)(i,(n,r)=>{r!==`none`||n===`none`||(0,e.nextTick)(()=>t.videoElement.value?.load())}),{imageLoading:r,mediaIsTimed:n,videoPreload:i}}function _e(t){let n=(0,e.shallowRef)(null),r=(0,e.shallowRef)(null),i=(0,e.shallowRef)(0),a=(0,e.shallowRef)(0),o=(0,e.shallowRef)(!0),s=(0,e.shallowRef)(!1),c=null,l=!1,u=(0,e.computed)(()=>s.value?`error`:o.value?`loading`:t.previewState());function d(){c!==null&&clearTimeout(c),c=null}function f(e){return Number(e.currentTarget.dataset.sourceGeneration)===i.value}function p(){d(),c=setTimeout(()=>g(),15e3)}function m(e){e&&!f(e)||(d(),o.value=!1,s.value=!1,t.onReady(t.mediaIndex()))}function h(){let e=n.value;if(e?.complete){e.naturalWidth>0?m():g();return}let t=r.value;if(t&&t.readyState>=HTMLMediaElement.HAVE_METADATA){m();return}p()}function g(n){if(!(n&&!f(n))){if(d(),!n&&a.value===0){a.value=1,i.value+=1,o.value=!0,(0,e.nextTick)(h);return}o.value=!1,s.value=!0,t.onError(t.mediaIndex())}}function _(){a.value=0,s.value=!1,o.value=!0,i.value+=1,(0,e.nextTick)(h)}function v(e){f(e)&&o.value&&p()}return(0,e.watch)(t.identity,()=>{d(),i.value+=1,a.value=0,o.value=l||t.previewState()===`loading`,s.value=!1,l=!0,(0,e.nextTick)(h)},{immediate:!0}),(0,e.onBeforeUnmount)(d),{effectivePreviewState:u,failSourceAttempt:g,imageElement:n,markSourceReady:m,noteSourceActivity:v,retrySource:_,sourceGeneration:i,videoElement:r}}var ve=[`data-post-id`,`data-media-index`,`aria-hidden`,`aria-busy`,`inert`,`role`,`tabindex`],ye={class:`media-card-content`},be=[`data-media-direction`],xe=[`data-media-index`],Se={key:0,"data-test":`media-loading`,class:`media-loading`,"aria-hidden":`true`},Ce=[`aria-label`],we={class:`media-error-code`},Te=[`data-source-generation`,`src`,`width`,`height`,`autoplay`,`loop`,`muted`,`preload`],Ee=[`data-source-generation`,`src`,`width`,`height`,`fetchpriority`,`loading`],De=[`aria-label`],Oe=[`aria-label`],ke=[`aria-label`],Ae=40,je=160,Me=24,Ne=(0,e.defineComponent)({__name:`MediaCard`,props:{active:{type:Boolean},advanceOnMediaEnd:{type:Boolean},cardFooter:{},cardHeader:{},entering:{type:Boolean},fetchPriority:{},index:{},item:{},itemStyle:{},interactive:{type:Boolean},leaving:{type:Boolean},layout:{},loadedCount:{},mediaIndex:{},mediaCard:{},mediaSource:{},previewState:{},reelControlsTarget:{},stationaryReelControls:{type:Boolean},total:{}},emits:[`activate`,`ended`,`error`,`mediaChange`,`ready`],setup(i,{emit:a}){let o=i,s=null,c=0,l=!1,u=null,d=null,f=(0,e.shallowRef)(`next`),p=a;function m(e=!1,t=`pointer`){e&&p(`activate`,t)}let h=(0,e.computed)(()=>t(o.item)),g=(0,e.computed)(()=>n(o.item,o.mediaIndex)),_=(0,e.computed)(()=>r(o.item,g.value)),v=(0,e.computed)(()=>o.mediaSource===`original`?_.value.src:_.value.preview.src),y=(0,e.computed)(()=>o.mediaSource===`original`?_.value.type:_.value.preview.type??_.value.type),b=(0,e.computed)(()=>o.mediaSource===`original`?_.value.width:_.value.preview.width),x=(0,e.computed)(()=>o.mediaSource===`original`?_.value.height:_.value.preview.height),{effectivePreviewState:S,failSourceAttempt:C,imageElement:w,markSourceReady:T,noteSourceActivity:E,retrySource:D,sourceGeneration:O,videoElement:k}=_e({identity:()=>`${o.item.postId}:${g.value}:${o.mediaSource??`preview`}:${v.value}:${y.value??``}`,mediaIndex:()=>g.value,onError:e=>p(`error`,e),onReady:e=>p(`ready`,e),previewState:()=>o.previewState}),A=(0,e.shallowRef)(0),j=(0,e.shallowRef)(0),M=(0,e.shallowRef)(o.mediaCard?.videoMuted??o.layout===`masonry`),N=(0,e.shallowRef)(!1),P=(0,e.shallowRef)(1),F=1,{effectiveMuted:I,onPlaying:L,playbackAllowed:R}=pe({active:()=>o.active,layout:()=>o.layout,videoElement:k,videoIsMuted:M,videoIsPlaying:N}),z=(0,e.computed)(()=>o.interactive&&!!(o.cardHeader||o.cardFooter));function B(e){return e.detail===0?`keyboard`:`pointer`}function V(e,t){let n=h.value.length,r=(e+n)%n;r!==g.value&&(f.value=e<g.value?`previous`:`next`,p(`mediaChange`,r),t&&t.detail>0&&t.currentTarget?.blur())}function H(e,t,n){return t===1?e*16:t===2?e*n:e}function U(){c=0,l=!1,s!==null&&clearTimeout(s),s=null}function W(){s!==null&&clearTimeout(s),s=setTimeout(U,je)}function K(e){if(h.value.length<=1)return;let t=e.currentTarget?.clientWidth||1,n=H(e.deltaX,e.deltaMode,t);if(n===0||(e.preventDefault(),W(),l)||(c+=n,Math.abs(c)<Me))return;let r=Math.sign(c);c=0,l=!0,V(g.value+r)}function q(e){let t=e.touches[0];o.layout!==`reel`||!t||(u=t.clientX,d=t.clientY)}function J(e){let t=e.changedTouches[0];if(u===null||d===null||!t)return;let n=u-t.clientX,r=d-t.clientY;u=null,d=null,!(Math.abs(n)<=Math.abs(r))&&(Math.abs(n)<Ae||V(g.value+Math.sign(n)))}let{imageLoading:te,mediaIsTimed:Y,videoPreload:ae}=ge({active:()=>o.active,fetchPriority:()=>o.fetchPriority,layout:()=>o.layout,mediaSource:()=>v.value,mediaType:()=>y.value,videoElement:k}),oe=(0,e.computed)(()=>o.layout===`reel`&&o.stationaryReelControls===!0),se=(0,e.computed)(()=>Y.value&&S.value===`ready`&&(!oe.value||!!(o.active&&o.reelControlsTarget))),ce=(0,e.computed)(()=>`${o.item.postId}:${g.value}:${v.value}`);function le(e){o.layout===`reel`&&(e.stopPropagation(),ue())}async function ue(){if(!(!k.value||!R.value)){if(N.value){k.value.pause();return}try{await k.value.play()}catch{N.value=!1}}}function de(e){return Number.isFinite(e)?Math.max(0,e):0}function X(e){let t=e?.currentTarget??k.value;t&&(A.value=de(t.currentTime),j.value=de(t.duration),R.value&&(M.value=t.muted),P.value=t.volume,t.volume>0&&(F=t.volume))}function me(e){X(e),T(e)}function he(){N.value=!1,p(`ended`,g.value)}function Ne(e){let t=k.value;!t||!Number.isFinite(e)||(t.currentTime=Math.min(de(t.duration),Math.max(0,e)),A.value=t.currentTime)}function Pe(e){let t=k.value;if(!t||!Number.isFinite(e))return;let n=Math.min(1,Math.max(0,e));t.volume=n,t.muted=n===0,n>0&&(F=n),X()}function Fe(){let e=k.value;e&&(e.muted&&e.volume===0&&(e.volume=F),e.muted=!e.muted,X())}return(0,e.onBeforeUnmount)(()=>{U()}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`article`,{"data-post-id":i.item.postId,"data-media-index":g.value,class:(0,e.normalizeClass)([`media-card`,{"media-card--entering":i.entering,"media-card--leaving":i.leaving,"media-card--error":(0,e.unref)(S)===`error`,"media-card--transparent-chrome":i.mediaCard?.header?.background===`transparent`||i.mediaCard?.footer?.background===`transparent`||i.cardHeader?.background===`transparent`||i.cardFooter?.background===`transparent`}]),style:(0,e.normalizeStyle)(i.itemStyle),"aria-hidden":i.leaving||void 0,"aria-busy":(0,e.unref)(S)===`loading`,inert:i.leaving||void 0,role:i.interactive&&!i.leaving&&!z.value?`button`:void 0,tabindex:i.interactive&&!i.leaving&&!z.value?0:void 0,onClick:n[15]||=e=>m(i.interactive&&!z.value,B(e)),onKeydown:[n[16]||=(0,e.withKeys)(e=>m(i.interactive&&!z.value,`keyboard`),[`enter`]),n[17]||=(0,e.withKeys)((0,e.withModifiers)(e=>m(i.interactive&&!z.value,`keyboard`),[`prevent`]),[`space`])]},[(0,e.createElementVNode)(`div`,ye,[i.cardHeader?((0,e.openBlock)(),(0,e.createBlock)(ie,{key:0,index:i.index,item:i.item,layout:i.layout,"loaded-count":i.loadedCount,"media-index":g.value,"media-source":i.mediaSource,placement:`header`,region:i.cardHeader,style:(0,e.normalizeStyle)(i.mediaCard?.header),total:i.total},null,8,[`index`,`item`,`layout`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,{class:(0,e.normalizeClass)([`media-card-media`,{"media-card-media--carousel":i.layout===`reel`&&h.value.length>1}]),"data-media-direction":f.value,onWheel:K,onTouchstartPassive:q,onTouchendPassive:J},[(0,e.createVNode)(e.Transition,{name:`media-slide-${f.value}`},{default:(0,e.withCtx)(()=>[((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:`${i.item.postId}:${_.value.src}:${i.mediaSource??`preview`}:${(0,e.unref)(O)}`,class:`media-card-frame`,"data-media-index":g.value},[(0,e.unref)(S)===`loading`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Se,[...n[18]||=[(0,e.createElementVNode)(`span`,{class:`media-loading-shimmer`},null,-1)]])):(0,e.unref)(S)===`error`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:1,"data-test":`media-error`,class:`media-error`,role:`img`,"aria-label":`${(0,e.unref)(ne)(v.value)} ${(0,e.unref)(re)(v.value)}`},[(0,e.createElementVNode)(`strong`,we,(0,e.toDisplayString)((0,e.unref)(ne)(v.value)),1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(re)(v.value)),1),(0,e.createElementVNode)(`button`,{type:`button`,"data-test":`media-retry`,onClick:n[0]||=(0,e.withModifiers)((...t)=>(0,e.unref)(D)&&(0,e.unref)(D)(...t),[`stop`])},`Retry`)],8,Ce)):(0,e.createCommentVNode)(``,!0),(0,e.unref)(Y)?((0,e.openBlock)(),(0,e.createElementBlock)(`video`,{key:2,ref_key:`videoElement`,ref:k,"data-source-generation":(0,e.unref)(O),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(S)===`ready`,"media-preview--reel-video":i.layout===`reel`}]),src:v.value,width:b.value??void 0,height:x.value??void 0,autoplay:(0,e.unref)(R),loop:!i.advanceOnMediaEnd,muted:(0,e.unref)(I),playsinline:``,preload:(0,e.unref)(ae),onLoadedmetadata:me,onProgress:n[1]||=(...t)=>(0,e.unref)(E)&&(0,e.unref)(E)(...t),onLoadeddata:n[2]||=(...t)=>(0,e.unref)(E)&&(0,e.unref)(E)(...t),onCanplay:n[3]||=(...t)=>(0,e.unref)(E)&&(0,e.unref)(E)(...t),onDurationchange:X,onTimeupdate:X,onVolumechange:X,onPlaying:n[4]||=(...t)=>(0,e.unref)(L)&&(0,e.unref)(L)(...t),onPause:n[5]||=e=>N.value=!1,onEnded:he,onClick:le,onError:n[6]||=(...t)=>(0,e.unref)(C)&&(0,e.unref)(C)(...t)},null,42,Te)):((0,e.openBlock)(),(0,e.createElementBlock)(`img`,{key:3,ref_key:`imageElement`,ref:w,"data-source-generation":(0,e.unref)(O),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(S)===`ready`}]),src:v.value,width:b.value??void 0,height:x.value??void 0,fetchpriority:i.fetchPriority,alt:``,decoding:`async`,loading:(0,e.unref)(te),onLoad:n[7]||=(...t)=>(0,e.unref)(T)&&(0,e.unref)(T)(...t),onError:n[8]||=(...t)=>(0,e.unref)(C)&&(0,e.unref)(C)(...t)},null,42,Ee))],8,xe))]),_:1},8,[`name`]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{disabled:!oe.value||!i.reelControlsTarget,to:i.reelControlsTarget??`body`},[(0,e.createVNode)(e.Transition,{name:`vibe-reel-media-controls`,css:oe.value},{default:(0,e.withCtx)(()=>[se.value?((0,e.openBlock)(),(0,e.createBlock)(fe,{key:ce.value,"current-time":A.value,"data-control-post-id":oe.value?i.item.postId:void 0,duration:j.value,layout:i.layout,muted:M.value,playing:N.value,volume:P.value,onSeek:Ne,onToggleMute:Fe,onTogglePlayback:ue,onVolumeChange:Pe},null,8,[`current-time`,`data-control-post-id`,`duration`,`layout`,`muted`,`playing`,`volume`])):(0,e.createCommentVNode)(``,!0)]),_:1},8,[`css`])],8,[`disabled`,`to`])),h.value.length>1?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:(0,e.normalizeClass)([`media-carousel-controls`,{"media-carousel-controls--persistent":i.layout===`reel`}]),"aria-label":`Media navigation`},[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-carousel-control media-carousel-control--previous`,"aria-label":`Previous media for post ${i.item.postId}`,onClick:n[9]||=(0,e.withModifiers)(e=>V(g.value-1,e),[`stop`]),onKeydown:n[10]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(G),{size:20})],40,De),(0,e.createElementVNode)(`button`,{type:`button`,class:`media-carousel-control media-carousel-control--next`,"aria-label":`Next media for post ${i.item.postId}`,onClick:n[11]||=(0,e.withModifiers)(e=>V(g.value+1,e),[`stop`]),onKeydown:n[12]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(ee),{size:20})],40,Oe)],2)):(0,e.createCommentVNode)(``,!0),z.value?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:1,class:`media-card-activator`,type:`button`,"aria-label":`Open post ${i.item.postId}`,onClick:n[13]||=(0,e.withModifiers)(e=>t.$emit(`activate`,B(e)),[`stop`]),onKeydown:n[14]||=(0,e.withModifiers)(()=>{},[`stop`])},null,40,ke)):(0,e.createCommentVNode)(``,!0)],42,be),i.cardFooter?((0,e.openBlock)(),(0,e.createBlock)(ie,{key:1,index:i.index,item:i.item,layout:i.layout,"loaded-count":i.loadedCount,"media-index":g.value,"media-source":i.mediaSource,placement:`footer`,region:i.cardFooter,style:(0,e.normalizeStyle)(i.mediaCard?.footer),total:i.total},null,8,[`index`,`item`,`layout`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0)])],46,ve))}}),Pe={class:`masonry-feed-shell`},Fe=[`aria-hidden`,`inert`],Ie={key:0,class:`masonry-feed-status-overlay`},Le=6,Re=12,ze=250,Be=(0,e.defineComponent)({__name:`MasonryFeed`,props:{enteringPostIds:{},entryDelays:{},leavingPostIds:{default:()=>new Set},removalDelays:{default:()=>new Map},masonry:{},suspended:{type:Boolean},canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},hasNext:{type:Boolean},infiniteScroll:{type:Boolean},isLoadingMore:{type:Boolean},items:{},loadMoreLocked:{type:Boolean},mediaCard:{},mediaIndices:{},nextPageError:{type:Boolean},previewStates:{},state:{},total:{}},emits:[`activate`,`error`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`visible`],setup(t,{expose:n,emit:r}){let a=0,o=t,s=r,c=(0,e.shallowRef)(null),l=`vibe-masonry-${(0,e.useId)()}`,u=(0,e.shallowRef)(null),d=(0,e.shallowRef)(0),f=(0,e.shallowRef)(Le),m=(0,e.shallowRef)(0),h=(0,e.shallowRef)(0),g=(0,e.shallowRef)(0),v=(0,e.shallowRef)([]),y=(0,e.shallowRef)([]),C=0,D=null,O=null,k=null,A=null,j=(0,e.computed)(()=>x(o.items,d.value,{additionalHeight:(o.cardHeader?.height??0)+(o.cardFooter?.height??0),gap:f.value,minColumnWidth:T(o.masonry)})),M=(0,e.computed)(()=>{if(o.leavingPostIds.size===0)return null;let e=o.items.flatMap((e,t)=>o.leavingPostIds.has(e.postId)?[]:[{index:t,item:e}]),t=x(e.map(({item:e})=>e),d.value,{additionalHeight:(o.cardHeader?.height??0)+(o.cardFooter?.height??0),gap:f.value,minColumnWidth:T(o.masonry)});return{indices:e.map(({index:e})=>e),layout:t,positions:new Map(e.map(({item:e},n)=>[e.postId,t.items[n]]))}}),N=(0,e.computed)(()=>{let e=j.value,t=M.value;return t?{...t.layout,items:o.items.map((n,r)=>o.leavingPostIds.has(n.postId)?e.items[r]:t.positions.get(n.postId)??e.items[r])}:e}),P=(0,e.computed)(()=>S(j.value.items)),I=(0,e.computed)(()=>{let e=M.value;return e?S(e.layout.items,e.indices):null}),L=(0,e.computed)(()=>Math.max(h.value,o.leavingPostIds.size===0?N.value.height:j.value.height)),R=(0,e.computed)(()=>({height:`${L.value}px`})),z=(0,e.computed)(()=>!o.infiniteScroll||m.value>0&&g.value+N.value.height<=m.value+1),B=(0,e.computed)(()=>new Set(v.value)),V=(0,e.computed)(()=>y.value.flatMap(e=>{let t=o.items[e];return t?[{fetchPriority:B.value.has(e)?`high`:`low`,index:e,item:t}]:[]}));function H(e,t){return[...new Set([...e,...t])].sort((e,t)=>e-t)}function U(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function W(e){let t={scrollTop:C-g.value,viewportHeight:m.value},n=I.value,r=w(n??P.value,{...t,overscan:e}).indices;return H(r,o.leavingPostIds.size===0?[]:w(P.value,{...t,overscan:e}).indices)}function G(){let e=o.suspended?[]:W(0),t=W(E(o.masonry,m.value));U(v.value,e)||(v.value=e),U(y.value,t)||(y.value=t)}function ee(){if(A!==null)return;A=-1;let e=requestAnimationFrame(()=>{A=null,G()});A!==null&&(A=e)}let K=new Set;(0,e.watch)(()=>[...B.value].flatMap(e=>{let t=o.items[e];if(!t)return[];let n=o.mediaIndices.get(t.postId)??0,r=i(t.postId,n);return o.previewStates.get(r)===`ready`?[{key:r,mediaIndex:n,postId:t.postId}]:[]}),e=>{let t=new Set(e.map(({key:e})=>e));e.forEach(({key:e,mediaIndex:t,postId:n})=>{K.has(e)||s(`visible`,n,t)}),K=t},{immediate:!0,flush:`post`});function q(e){let t=N.value.items[e],n=o.items[e]?.postId;if(!t)return{};let r=n!==void 0&&o.enteringPostIds.has(n),i=n!==void 0&&o.leavingPostIds.has(n),a=r||i?b({containerHeight:Math.max(h.value,j.value.height),gap:f.value}):0,s=n===void 0?0:i?o.removalDelays.get(n)??0:r?o.entryDelays.get(n)??0:0;return{"--masonry-entry-delay":`${s}ms`,width:`${t.width}px`,height:`${t.height}px`,transform:`translate3d(${t.x}px, ${t.y+a}px, 0)`}}function J(){let e=c.value;if(!e)return;C=e.scrollTop,m.value=e.clientHeight;let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(Number.parseFloat(t?.paddingTop??``)||0)+(Number.parseFloat(t?.paddingBottom??``)||0);h.value=Math.max(0,e.clientHeight-n);let r=u.value;r&&(g.value=r.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,G())}function te(e){let t=e.ownerDocument.documentElement.clientWidth;d.value=e.clientWidth,f.value=Math.min(Re,Math.max(Le,t*.0075)),J()}function Y(e){let t=e.currentTarget;t&&(C=t.scrollTop,ee(),Date.now()>=a&&!o.loadMoreLocked&&o.infiniteScroll&&_(t)&&s(`loadMore`))}function ne(){let e=c.value;Date.now()>=a&&!o.loadMoreLocked&&e&&_(e)&&s(`loadMore`)}(0,e.watch)(()=>o.items.length,(e,t)=>{e>0&&e<t&&(a=Date.now()+ze)});function re(){return c.value}return(0,e.watch)(u,e=>{D?.disconnect(),D=null,k!==null&&cancelAnimationFrame(k),e&&(te(e),!(typeof ResizeObserver>`u`)&&(D=new ResizeObserver(([t])=>{let n=t?.contentRect.width??e.clientWidth;Math.abs(n-d.value)<.5||(k=requestAnimationFrame(()=>{k=null,te(e)}))}),D.observe(e)))}),(0,e.watch)(c,e=>{O?.disconnect(),O=null,e&&(J(),!(typeof ResizeObserver>`u`)&&(O=new ResizeObserver(J),O.observe(e)))}),(0,e.watch)([j,N,()=>o.suspended,()=>o.masonry],G,{flush:`post`}),(0,e.onBeforeUnmount)(()=>{D?.disconnect(),O?.disconnect(),k!==null&&cancelAnimationFrame(k),A!==null&&cancelAnimationFrame(A)}),n({getScrollElement:re,loadIfNearBottom:ne}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Pe,[(0,e.createElementVNode)(`main`,{id:l,ref_key:`galleryElement`,ref:c,class:(0,e.normalizeClass)([`gallery-shell masonry-feed`,{"masonry-feed--suspended":t.suspended}]),"data-layout-mode":`masonry`,"aria-hidden":t.suspended||void 0,inert:t.suspended||void 0,onScrollPassive:Y},[(0,e.createElementVNode)(`section`,{ref_key:`masonryElement`,ref:u,class:(0,e.normalizeClass)([`masonry`,{"masonry--ready":d.value>0}]),style:(0,e.normalizeStyle)(R.value),"aria-label":`Media gallery`},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(V.value,({fetchPriority:n,item:r,index:a})=>((0,e.openBlock)(),(0,e.createBlock)(Ne,{key:r.postId,class:`masonry-item`,entering:t.enteringPostIds.has(r.postId),leaving:t.leavingPostIds.has(r.postId),"fetch-priority":n,"card-footer":t.cardFooter,"card-header":t.cardHeader,"media-card":t.mediaCard,index:a,item:r,"item-style":q(a),interactive:``,layout:`masonry`,"loaded-count":t.items.length,"media-index":t.mediaIndices.get(r.postId)??0,"preview-state":t.previewStates.get((0,e.unref)(i)(r.postId,t.mediaIndices.get(r.postId)??0))??`loading`,total:t.total,onActivate:e=>s(`activate`,r.postId,e),onMediaChange:e=>s(`mediaChange`,r.postId,e),onReady:e=>s(`ready`,r.postId,e),onError:e=>s(`error`,r.postId,e)},null,8,[`entering`,`leaving`,`fetch-priority`,`card-footer`,`card-header`,`media-card`,`index`,`item`,`item-style`,`loaded-count`,`media-index`,`preview-state`,`total`,`onActivate`,`onMediaChange`,`onReady`,`onError`]))),128))],6)],42,Fe),t.feedFooter||t.isLoadingMore||t.nextPageError||t.hasNext&&z.value||!t.hasNext&&t.canRetryEnd?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Ie,[(0,e.createVNode)(p,{actions:t.feedFooterActions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,"has-error":t.nextPageError,"has-next":t.hasNext,"is-loading":t.isLoadingMore,"load-more-locked":t.loadMoreLocked,"show-load-more":z.value,state:t.state,onLoadMore:r[0]||=e=>s(`loadMore`),onRetryEnd:r[1]||=e=>s(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`show-load-more`,`state`])])):(0,e.createCommentVNode)(``,!0),(0,e.createVNode)(F,{"content-size":N.value.height,"controls-id":l,"scroll-element":c.value,suspended:t.suspended},null,8,[`content-size`,`scroll-element`,`suspended`])]))}}),Ve=300;function He(e,t,n){let r=e.scrollTop;if(n||Math.abs(r-t)<=1)return e.scrollTop=t,Promise.resolve();e.setAttribute(`data-transitioning`,``);let i=performance.now(),a=0;return new Promise(n=>{let o=s=>{a+=1;let c=Math.max(s-i,1e3/60*a),l=Math.min(1,c/Ve),u=1-(1-l)**3;if(e.scrollTop=r+(t-r)*u,l<1){requestAnimationFrame(o);return}e.removeAttribute(`data-transitioning`),e.scrollTop=t,n()};requestAnimationFrame(o)})}var Ue=[`aria-label`],We=(0,e.defineComponent)({__name:`ReelAutoAdvanceProgress`,props:{durationMs:{},label:{}},emits:[`complete`],setup(t,{emit:n}){let r=t,i=n,a=(0,e.computed)(()=>({"--vibe-reel-auto-advance-duration":`${r.durationMs}ms`}));return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:`reel-auto-advance`,"data-test":`reel-auto-advance`,role:`timer`,"aria-label":t.label},[(0,e.createElementVNode)(`span`,{class:`reel-auto-advance-progress`,style:(0,e.normalizeStyle)(a.value),onAnimationend:r[0]||=e=>i(`complete`)},null,36)],8,Ue))}}),Ge={class:`reel-viewport`},Ke=[`data-active-post-id`,`data-active-media-index`],qe=[`role`,`data-status`],Je=2,Ye=300,Xe=250,Ze=(0,e.defineComponent)({__name:`ReelFeed`,props:{initialPostId:{},mediaSource:{},reelAutoAdvance:{},reelForward:{default:()=>({error:null,status:`idle`})},canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},hasNext:{type:Boolean},infiniteScroll:{type:Boolean},isLoadingMore:{type:Boolean},items:{},loadMoreLocked:{type:Boolean},mediaCard:{},mediaIndices:{},nextPageError:{type:Boolean},previewStates:{},state:{},total:{}},emits:[`activeChange`,`error`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`retryForward`],setup(n,{expose:a,emit:o}){let s=0,c=n,l=o,u=(0,e.shallowRef)(null),d=(0,e.shallowRef)(null),f=c.initialPostId===null||c.initialPostId===void 0?-1:c.items.findIndex(e=>e.postId===c.initialPostId),m=(0,e.shallowRef)(Math.max(0,f)),h=(0,e.shallowRef)(!1),g=(0,e.shallowRef)(!1),v=0,y=null,b=null,x=null,S=(0,e.computed)(()=>({gridTemplateRows:`repeat(${c.items.length}, 100cqh)`})),C=(0,e.computed)(()=>{let e=Math.max(0,m.value-Je),t=Math.min(c.items.length-1,m.value+Je);return c.items.slice(e,t+1).map((t,n)=>({fetchPriority:e+n===m.value?`high`:`low`,index:e+n,item:t}))}),w=(0,e.computed)(()=>c.items[m.value]?.postId),T=(0,e.computed)(()=>c.items[m.value]),E=(0,e.computed)(()=>{let e=w.value;return e===void 0?0:c.mediaIndices.get(e)??0}),D=(0,e.computed)(()=>{let e=w.value;return e===void 0?`loading`:c.previewStates.get(i(e,E.value))??`loading`}),O=(0,e.computed)(()=>T.value?r(T.value,E.value):null),k=(0,e.computed)(()=>D.value===`ready`&&!!(O.value&&he(c.mediaSource===`original`?O.value.type:O.value.preview.type??O.value.type,c.mediaSource===`original`?O.value.src:O.value.preview.src))),A=(0,e.computed)(()=>[w.value,E.value,c.items.length,c.loadMoreLocked,c.reelAutoAdvance.enabled,c.reelAutoAdvance.includePostItems,c.reelAutoAdvance.intervalMs].join(`:`)),j=(0,e.computed)(()=>{let e=T.value,n=!!(e&&c.reelAutoAdvance.includePostItems&&E.value<t(e).length-1),r=c.reelAutoAdvance.intervalMs/1e3;return`Auto advance to the next ${n?`post item`:`post`} in ${r}s`}),M=(0,e.computed)(()=>c.reelAutoAdvance.enabled&&c.reelForward.status===`idle`&&T.value!==void 0&&D.value!==`loading`&&!k.value),N=(0,e.computed)(()=>!c.infiniteScroll||c.items.length<=1),P=(0,e.computed)(()=>c.reelForward.status===`loading`?`Loading the next media…`:c.reelForward.status===`error`?`Unable to load the next media.`:`You reached the end of this feed.`);function F(e){return{gridRow:`${e+1}`}}function I(e){let t=v||e.clientHeight;return t<=0||c.items.length===0?0:Math.min(c.items.length-1,Math.max(0,Math.round(e.scrollTop/t)))}function L(e){let t=e.currentTarget;if(!t)return;let n=v||t.clientHeight,r=Math.max(0,c.items.length-1)*n;h.value=c.items.length>0&&t.scrollTop>r+1,g.value||(m.value=I(t)),Date.now()>=s&&!c.loadMoreLocked&&c.infiniteScroll&&_(t)&&l(`loadMore`)}function R(){let e=u.value;e&&(h.value=!1,V(!0),v=e.clientHeight,e.scrollTop=m.value*v,b!==null&&cancelAnimationFrame(b),b=requestAnimationFrame(()=>{e.scrollTop=m.value*e.clientHeight,v=e.clientHeight,b=null}),z())}function z(){x!==null&&clearTimeout(x),x=setTimeout(()=>{x=null;let e=u.value;e&&(v=e.clientHeight,e.scrollTop=m.value*v),V(!1)},120)}function B(){V(!0);let e=u.value;e&&(v=e.clientHeight,e.scrollTop=m.value*v),z()}function V(e){g.value=e,u.value?.toggleAttribute(`data-resizing`,e)}function H(){let e=u.value;Date.now()>=s&&!c.loadMoreLocked&&e&&_(e)&&l(`loadMore`)}(0,e.watch)(()=>c.items.length,(e,t)=>{e>0&&e<t&&(s=Date.now()+Xe)});function U(e){let n=T.value;if(!n)return!1;let r=t(n).length;if(r<=1)return!1;let i=(E.value+e+r)%r;return l(`mediaChange`,n.postId,i),!0}function W(e){let t=m.value+e;return!u.value||t<0||t>=c.items.length?!1:(q(t),!0)}function G(e,t){let n=c.items.findIndex(t=>t.postId===e),r=c.items[n];return!u.value||!r||t<0||t>r.items.length?!1:((c.mediaIndices.get(e)??0)!==t&&l(`mediaChange`,e,t),n!==m.value&&q(n),!0)}function ee(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function K(e){let t=u.value;if(!t)return Promise.resolve();let n=e*(v||t.clientHeight);return m.value=e,He(t,n,ee())}function q(e){K(e)}async function J(e){let t=c.items.findIndex(t=>t.postId===e);return t<0||t===m.value?!1:(await K(t),!0)}async function te(e){return U(e)?(ee()||await new Promise(e=>setTimeout(e,Ye)),!0):!1}function Y(){if(!c.reelAutoAdvance.enabled)return;let e=T.value;if(!e)return;if(c.reelAutoAdvance.includePostItems&&E.value<t(e).length-1){l(`mediaChange`,e.postId,E.value+1);return}let n=m.value+1,r=c.items[n];if(!r){c.hasNext&&!c.loadMoreLocked&&l(`loadMore`);return}c.reelAutoAdvance.includePostItems&&(c.mediaIndices.get(r.postId)??0)!==0&&l(`mediaChange`,r.postId,0),q(n)}function ne(e,t){!c.reelAutoAdvance.enabled||e!==w.value||t!==E.value||!k.value||Y()}return(0,e.watch)(u,e=>{y?.disconnect(),y=null,e&&(v=e.clientHeight,!(typeof ResizeObserver>`u`)&&(y=new ResizeObserver(R),y.observe(e)))}),(0,e.watch)(()=>c.items.length,async t=>{let n=c.initialPostId,r=n==null?-1:c.items.findIndex(({postId:e})=>e===n);m.value=r>=0?r:Math.min(m.value,Math.max(0,t-1)),await(0,e.nextTick)(),R()}),(0,e.watch)(w,e=>{e!==void 0&&l(`activeChange`,e)},{immediate:!0}),(0,e.onMounted)(()=>{window.addEventListener(`resize`,B),window.addEventListener(`orientationchange`,B),f>=0&&(0,e.nextTick)(R)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`resize`,B),window.removeEventListener(`orientationchange`,B),y?.disconnect(),b!==null&&cancelAnimationFrame(b),x!==null&&clearTimeout(x)}),a({activeIndex:m,activePostId:w,changeActiveMedia:U,loadIfNearBottom:H,moveActivePost:W,navigateToItem:G,transitionActiveMedia:te,transitionActivePost:J}),(t,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`main`,{class:(0,e.normalizeClass)([`reel-shell`,{"reel-shell--has-footer":!!n.cardFooter,"reel-shell--has-header":!!n.cardHeader}]),"data-layout-mode":`reel`},[n.cardHeader&&T.value&&n.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(ie,{key:0,index:m.value,item:T.value,layout:`reel`,"loaded-count":n.items.length,"media-index":E.value,"media-source":n.mediaSource,placement:`header`,region:n.cardHeader,style:(0,e.normalizeStyle)(n.mediaCard?.header),total:n.total},null,8,[`index`,`item`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,Ge,[(0,e.createElementVNode)(`div`,{ref_key:`galleryElement`,ref:u,class:`gallery-shell reel-feed`,"data-active-post-id":w.value,"data-active-media-index":E.value,onScrollPassive:L},[n.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{key:1,class:`reel-track`,style:(0,e.normalizeStyle)(S.value),"aria-label":`Media gallery`},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(C.value,({fetchPriority:t,item:r,index:a})=>((0,e.openBlock)(),(0,e.createBlock)(Ne,{key:r.postId,active:a===m.value&&!h.value,"advance-on-media-end":c.reelAutoAdvance.enabled&&a===m.value,class:`reel-item`,entering:!1,"fetch-priority":t,index:a,item:r,"item-style":F(a),"media-card":n.mediaCard,layout:`reel`,"loaded-count":n.items.length,"media-index":n.mediaIndices.get(r.postId)??0,"media-source":n.mediaSource,"preview-state":n.previewStates.get((0,e.unref)(i)(r.postId,n.mediaIndices.get(r.postId)??0))??`loading`,"reel-controls-target":d.value,"stationary-reel-controls":``,total:n.total,onMediaChange:e=>l(`mediaChange`,r.postId,e),onEnded:e=>ne(r.postId,e),onReady:e=>l(`ready`,r.postId,e),onError:e=>l(`error`,r.postId,e)},null,8,[`active`,`advance-on-media-end`,`fetch-priority`,`index`,`item`,`item-style`,`media-card`,`loaded-count`,`media-index`,`media-source`,`preview-state`,`reel-controls-target`,`total`,`onMediaChange`,`onEnded`,`onReady`,`onError`]))),128))],4)):((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`reel-forward-status`,role:n.reelForward.status===`error`?`alert`:`status`,"data-status":n.reelForward.status},[(0,e.createElementVNode)(`p`,null,(0,e.toDisplayString)(P.value),1),n.reelForward.status===`error`||n.reelForward.status===`end`?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:0,class:`reel-forward-retry`,type:`button`,onClick:r[0]||=e=>l(`retryForward`)},` Retry `)):(0,e.createCommentVNode)(``,!0)],8,qe)),n.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(p,{key:2,actions:n.feedFooterActions,"can-retry-end":n.canRetryEnd,"feed-footer":n.feedFooter,"has-error":n.nextPageError,"has-next":n.hasNext,"is-loading":n.isLoadingMore,"load-more-locked":n.loadMoreLocked,"show-load-more":N.value,state:n.state,onLoadMore:r[1]||=e=>l(`loadMore`),onRetryEnd:r[2]||=e=>l(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`show-load-more`,`state`])):(0,e.createCommentVNode)(``,!0)],40,Ke),(0,e.createElementVNode)(`div`,{ref_key:`reelControlsElement`,ref:d,class:`reel-media-controls-host`,"data-test":`reel-media-controls-host`},null,512)]),n.cardFooter&&T.value&&n.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(ie,{key:1,index:m.value,item:T.value,layout:`reel`,"loaded-count":n.items.length,"media-index":E.value,"media-source":n.mediaSource,placement:`footer`,region:n.cardFooter,style:(0,e.normalizeStyle)(n.mediaCard?.footer),total:n.total},null,8,[`index`,`item`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0),M.value?((0,e.openBlock)(),(0,e.createBlock)(We,{key:A.value,"duration-ms":n.reelAutoAdvance.intervalMs,label:j.value,onComplete:Y},null,8,[`duration-ms`,`label`])):(0,e.createCommentVNode)(``,!0)],2))}}),Qe=[`data-info-sheet-open`,`data-info-sheet-mode`],$e=[`aria-hidden`,`inert`],et={key:0,class:`reel-info-sheet-layer`,"data-test":`reel-info-sheet`},tt=[`role`,`aria-modal`,`tabindex`,`data-active-post-id`],nt=(0,e.defineComponent)({__name:`ReelLayout`,props:{forwardIndex:{default:null},forwardItem:{default:null},infoSheet:{},infoSheetEnabled:{type:Boolean},infoSheetOverlay:{type:Boolean},origin:{},initialPostId:{},mediaSource:{},reelAutoAdvance:{},reelForward:{default:()=>({error:null,status:`idle`})},canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},hasNext:{type:Boolean},infiniteScroll:{type:Boolean},isLoadingMore:{type:Boolean},items:{},loadMoreLocked:{type:Boolean},mediaCard:{},mediaIndices:{},nextPageError:{type:Boolean},previewStates:{},state:{},total:{}},emits:[`activeChange`,`closeInfoSheet`,`error`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`retryForward`],setup(n,{expose:i,emit:a}){let o=n,s=a,c=(0,e.shallowRef)(null),l=(0,e.shallowRef)(null),u=null,d=(0,e.computed)(()=>{let e=o.initialPostId===null||o.initialPostId===void 0?-1:o.items.findIndex(e=>e.postId===o.initialPostId);return Math.max(0,e)}),f=(0,e.computed)(()=>o.items[d.value]),p=(0,e.computed)(()=>f.value??(o.reelForward.status===`idle`?void 0:o.forwardItem??void 0)),m=(0,e.computed)(()=>f.value?d.value:o.forwardIndex??0),h=(0,e.computed)(()=>{let e=p.value?.postId;return e===void 0?0:o.mediaIndices.get(e)??0}),g=(0,e.computed)(()=>!!(o.infoSheet&&o.infoSheetEnabled&&p.value)),_=(0,e.computed)(()=>{let e=p.value;return e?{close:v,index:m.value,item:e,layout:`reel`,loadedCount:o.items.length,mediaCount:t(e).length,mediaIndex:h.value,mediaItem:r(e,h.value),mediaSource:o.mediaSource??`preview`,origin:o.origin,total:o.total}:null});function v(){s(`closeInfoSheet`)}function y(e){return c.value?.changeActiveMedia(e)??!1}function b(){c.value?.loadIfNearBottom()}function x(e){return c.value?.moveActivePost(e)??!1}function S(e,t){return c.value?.navigateToItem(e,t)??!1}function C(e){return c.value?.transitionActiveMedia(e)??Promise.resolve(!1)}function w(e){return c.value?.transitionActivePost(e)??Promise.resolve(!1)}function T(e,t){s(`error`,e,t)}function E(e,t){s(`mediaChange`,e,t)}function D(e,t){s(`ready`,e,t)}return(0,e.watch)(()=>({overlay:o.infoSheetOverlay,visible:g.value}),async(t,n)=>{if(t.visible&&!n?.visible){u=document.activeElement instanceof HTMLElement?document.activeElement:null,t.overlay&&(await(0,e.nextTick)(),l.value?.focus({preventScroll:!0}));return}if(!t.visible&&n?.visible&&u?.isConnected){let t=u;u=null,await(0,e.nextTick)(),t.focus({preventScroll:!0})}}),(0,e.onBeforeUnmount)(()=>{u=null}),i({changeActiveMedia:y,loadIfNearBottom:b,moveActivePost:x,navigateToItem:S,transitionActiveMedia:C,transitionActivePost:w}),(t,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{class:(0,e.normalizeClass)([`reel-layout`,`reel-layout--${n.infoSheetOverlay?`overlay`:`layout`}`]),"data-info-sheet-open":g.value||void 0,"data-info-sheet-mode":n.infoSheetOverlay?`overlay`:`layout`},[(0,e.createElementVNode)(`div`,{class:`reel-layout-main`,"aria-hidden":n.infoSheetOverlay&&g.value||void 0,inert:n.infoSheetOverlay&&g.value||void 0},[(0,e.createVNode)(Ze,{ref_key:`reelFeed`,ref:c,"can-retry-end":n.canRetryEnd,"card-footer":n.cardFooter,"card-header":n.cardHeader,"feed-footer":n.feedFooter,"feed-footer-actions":n.feedFooterActions,"media-card":n.mediaCard,"has-next":n.hasNext,"infinite-scroll":n.infiniteScroll,"initial-post-id":n.initialPostId,"is-loading-more":n.isLoadingMore,items:n.items,"load-more-locked":n.loadMoreLocked,"media-indices":n.mediaIndices,"media-source":n.mediaSource,"next-page-error":n.nextPageError,"preview-states":n.previewStates,"reel-auto-advance":n.reelAutoAdvance,"reel-forward":n.reelForward,state:n.state,total:n.total,onActiveChange:r[0]||=e=>s(`activeChange`,e),onError:T,onLoadMore:r[1]||=e=>s(`loadMore`),onMediaChange:E,onReady:D,onRetryEnd:r[2]||=e=>s(`retryEnd`),onRetryForward:r[3]||=e=>s(`retryForward`)},null,8,[`can-retry-end`,`card-footer`,`card-header`,`feed-footer`,`feed-footer-actions`,`media-card`,`has-next`,`infinite-scroll`,`initial-post-id`,`is-loading-more`,`items`,`load-more-locked`,`media-indices`,`media-source`,`next-page-error`,`preview-states`,`reel-auto-advance`,`reel-forward`,`state`,`total`])],8,$e),(0,e.createVNode)(e.Transition,{name:`vibe-info-sheet`},{default:(0,e.withCtx)(()=>[g.value&&n.infoSheet&&_.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,et,[(0,e.createElementVNode)(`aside`,{ref_key:`sheetElement`,ref:l,class:`reel-info-sheet`,role:n.infoSheetOverlay?`dialog`:`complementary`,"aria-label":`Reel information`,"aria-modal":n.infoSheetOverlay?`true`:void 0,tabindex:n.infoSheetOverlay?-1:void 0,"data-active-post-id":p.value?.postId},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(n.infoSheet.component),(0,e.normalizeProps)((0,e.guardReactiveProps)(_.value)),null,16))],8,tt)])):(0,e.createCommentVNode)(``,!0)]),_:1})],10,Qe))}});function rt(e,t,i,a,o){let s=e.items.findIndex(e=>e.postId===t),c=e.items[s];if(!c)return null;let l=n(c,i),u=r(c,l);return{item:c,layout:a,media:u,mediaId:u.mediaId??null,mediaIndex:l,origin:o,phoneMode:e.phoneMode,postId:c.postId,postIndex:s}}function it(t,n){(0,e.watch)(()=>{let e=t.layout===`reel`||t.reelOrigin===`masonry`?t.activeReelPostId:null;return{mediaIndex:e===null?0:t.mediaIndices.get(e)??0,origin:t.reelOrigin??`reel`,postId:e}},(e,r)=>{if(e.postId===null||e.postId===r?.postId&&e.mediaIndex===r.mediaIndex&&e.origin===r.origin)return;let i=rt(t,e.postId,e.mediaIndex,`reel`,e.origin);i&&n(i)},{flush:`sync`})}function at(t,n){let r=(0,e.shallowRef)(new Map),a=(0,e.shallowRef)(new Map),o=(0,e.computed)(()=>t.reelMediaSource===`original`?a.value:r.value);function s(e,t,n,r){let a=i(t,n);e.value.get(a)!==r&&(e.value=new Map(e.value).set(a,r))}function c(e,n,r,i){return rt(t,e,n,r,i)}function l(e,t,r,i){let a=c(e,t,r,i);a&&n.ready(a)}function u(e,t){s(r,e,t,`error`)}function d(e,t){s(r,e,t,`ready`),l(e,t,`masonry`,null)}function f(e,n){s(t.reelMediaSource===`original`?a:r,e,n,`error`)}function p(e,n){s(t.reelMediaSource===`original`?a:r,e,n,`ready`),l(e,n,`reel`,t.reelOrigin??`reel`)}function m(e,t){let r=c(e,t,`masonry`,null);r&&n.visible(r)}return it(t,n.reelChange),(0,e.watch)(()=>{let e=t.layout===`reel`||t.reelOrigin===`masonry`?t.activeReelPostId:null,n=e===null?0:t.mediaIndices.get(e)??0;return{mediaIndex:n,origin:t.reelOrigin??`reel`,postId:e,ready:e!==null&&o.value.get(i(e,n))===`ready`}},(e,t)=>{if(e.postId===null||!e.ready||t?.ready&&t.postId===e.postId&&t.mediaIndex===e.mediaIndex&&t.origin===e.origin)return;let r=c(e.postId,e.mediaIndex,`reel`,e.origin);r&&n.visible(r)},{flush:`post`}),{markMasonryVisible:m,markPreviewError:u,markPreviewReady:d,markReelError:f,markReelReady:p,originalStates:a,previewStates:r,reelStates:o}}var ot=[];function st(e){return ot.push(e),()=>{let t=ot.indexOf(e);t>=0&&ot.splice(t,1)}}function ct(e){if(!e.isActive())return!1;let t=ot.filter(e=>e.isActive()),n=e.element();return n!==null&&t.some(t=>{if(t===e)return!1;let r=t.element();return r!==null&&n.contains(r)})?!1:t.filter(e=>{let n=e.element();return n===null||!t.some(t=>{if(t===e)return!1;let r=t.element();return r!==null&&n.contains(r)})}).at(-1)===e}function lt(t){let n={element:t.element,isActive:()=>t.state.layout===`reel`||t.state.reelOrigin===`masonry`},r=null;function i(e){let r=n.isActive();if(e.key===`Escape`&&r&&!ct(n))return;if(e.key===`Escape`&&t.state.reelOrigin===`masonry`){e.preventDefault(),t.state.reelInfoSheetOverlay&&t.state.reelInfoSheet.enabled&&t.setReelInfoSheet(!1),t.closeMasonryReel();return}if(e.key===`Escape`&&r&&t.state.reelInfoSheet.enabled){e.preventDefault(),t.setReelInfoSheet(!1);return}if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||t.isReelLeaving()||!r)return;let i=e.target;if(i instanceof HTMLElement&&(i.isContentEditable||[`INPUT`,`SELECT`,`TEXTAREA`].includes(i.tagName)))return;let a=e.key===`ArrowLeft`?-1:e.key===`ArrowRight`?1:0;a!==0&&t.reelRenderer()?.changeActiveMedia?.(a)&&e.preventDefault()}(0,e.onMounted)(()=>{r=st(n),window.addEventListener(`keydown`,i)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`keydown`,i),r?.(),r=null})}var ut=35,dt=420,ft=(0,e.defineComponent)({__name:`VibeSurface`,props:{canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},mediaCard:{},masonry:{},reelInfoSheet:{},state:{}},emits:[`activeReelChange`,`closeReel`,`loadMore`,`mediaReady`,`mediaVisible`,`openReel`,`reelMediaChange`,`reelInfoSheetChange`,`retryEnd`,`retryForward`],setup(r,{expose:i,emit:a}){let s=r,c=a,l=(0,e.shallowRef)(null),u=(0,e.shallowRef)(null),d=(0,e.shallowRef)(null),f=(0,e.shallowRef)(null),p=(0,e.shallowRef)({}),m=(0,e.shallowRef)(!1),h=(0,e.shallowRef)(new Set),_=(0,e.shallowRef)(new Map),v=(0,e.shallowRef)(new Set),y=(0,e.shallowRef)(new Map),b=(0,e.computed)(()=>Object.freeze([...s.state.items])),x=(0,e.computed)(()=>o(s.state,b.value)),{markMasonryVisible:S,markPreviewError:C,markPreviewReady:w,markReelError:T,markReelReady:E,originalStates:D,previewStates:O,reelStates:k}=at(s.state,{ready:e=>c(`mediaReady`,e),reelChange:e=>c(`reelMediaChange`,e),visible:e=>c(`mediaVisible`,e)}),A=new Set(s.state.items.map(e=>e.postId)),j=null,M=null,N=!1;function P(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function F(){j!==null&&cancelAnimationFrame(j),j=requestAnimationFrame(()=>{j=requestAnimationFrame(()=>{j=null,h.value=new Set})})}function I(e,t){let r=s.state.items.find(t=>t.postId===e);if(!r)return;let i=n(r,t);(s.state.mediaIndices.get(e)??0)!==i&&(s.state.mediaIndices=new Map(s.state.mediaIndices).set(e,i))}async function L(){await(0,e.nextTick)(),(s.state.layout===`reel`||s.state.reelOrigin===`masonry`?u.value:l.value)?.loadIfNearBottom()}function R(e){return s.state.isLoading||s.state.items.length===0||s.state.layout!==`reel`&&s.state.reelOrigin!==`masonry`?!1:u.value?.changeActiveMedia?.(e)??!1}function z(e){return s.state.isLoading||s.state.items.length===0||s.state.layout!==`reel`&&s.state.reelOrigin!==`masonry`?!1:u.value?.moveActivePost?.(e)??!1}function B(e){if(!(s.state.layout===`reel`||s.state.reelOrigin===`masonry`)||s.state.isLoading)return`reel-inactive`;let n=s.state.items.find(t=>t.postId===e.postId);if(!n)return`not-found`;let r=t(n).findIndex(t=>t.mediaId===e.mediaId);return r<0?`not-found`:u.value?.navigateToItem?.(e.postId,r)?`navigated`:`reel-inactive`}function V(){return s.state.layout!==`masonry`||s.state.reelOrigin===`masonry`?null:l.value?.getScrollElement?.()??null}function H(t,n){M=t,N=n===`keyboard`,p.value=ee(t),c(`openReel`,t),(0,e.nextTick)(()=>d.value?.focus())}function U(e){let t=f.value?.querySelectorAll(`.masonry-feed [data-post-id]`)??[];return Array.from(t).find(t=>t.dataset.postId===String(e))??null}function W(e,t){if(s.state.layout!==`masonry`||s.state.reelOrigin!==null||P())return 0;let n=[...new Set(e)],r=n.filter(U);if(r.length===0)return 0;let i=new Map(y.value),a=t?.staggerMs??ut;return r.forEach((e,t)=>{i.set(e,t*a)}),h.value=new Set([...h.value].filter(e=>!r.includes(e))),v.value=new Set([...v.value,...n]),y.value=i,dt+(r.length-1)*a}function G(e,t){let n=U(e),r=n?.querySelector(`.media-card-activator`)??n;r&&(r.classList.toggle(`media-card-focus-silent`,!t),t||r.addEventListener(`blur`,()=>{r.classList.remove(`media-card-focus-silent`)},{once:!0}),r?.focus({preventScroll:!0}))}function ee(e){let t=f.value,n=U(e);if(t===null||n===null)return{};let r=t.getBoundingClientRect(),i=n.getBoundingClientRect();return{"--vibe-reel-origin-top":`${Math.max(0,i.top-r.top)}px`,"--vibe-reel-origin-right":`${Math.max(0,r.right-i.right)}px`,"--vibe-reel-origin-bottom":`${Math.max(0,r.bottom-i.bottom)}px`,"--vibe-reel-origin-left":`${Math.max(0,i.left-r.left)}px`}}function K(){s.state.reelOrigin===`masonry`&&(M??=s.state.activeReelPostId,m.value=!0,c(`closeReel`))}function q(){let t=M,n=N;m.value=!1,M=null,N=!1,p.value={},(0,e.nextTick)(()=>{t!==null&&G(t,n)})}return lt({closeMasonryReel:K,element:()=>f.value,isReelLeaving:()=>m.value,reelRenderer:()=>u.value,setReelInfoSheet:e=>c(`reelInfoSheetChange`,e),state:s.state}),(0,e.watch)(()=>s.state.items.map(e=>e.postId),e=>{let t=e.filter(e=>!A.has(e)),n=new Set(e);if(A=new Set(e),v.value=new Set([...v.value].filter(e=>n.has(e))),y.value=new Map([...y.value].filter(([e])=>n.has(e))),t.length===0||P())return;let r=new Map;e.forEach(e=>{let t=_.value.get(e);t!==void 0&&r.set(e,t)}),t.forEach((e,t)=>{r.set(e,t*ut)}),_.value=r,h.value=new Set([...h.value,...t]),F()},{flush:`sync`}),(0,e.onBeforeUnmount)(()=>{j!==null&&cancelAnimationFrame(j)}),i({changeActiveReelMedia:R,getAutoScrollElement:V,loadIfNearBottom:L,moveActiveReelPost:z,navigateToReelItem:B,startItemRemoval:W,transitionActiveReelMedia:e=>u.value?.transitionActiveMedia?.(e)??Promise.resolve(!1),transitionActiveReelPost:e=>u.value?.transitionActivePost?.(e)??Promise.resolve(!1)}),(t,n)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{ref_key:`surfaceElement`,ref:f,class:`vibe-surface`},[r.state.layout===`reel`&&(r.state.items.length>0||r.state.reelForward.status!==`idle`)?((0,e.openBlock)(),(0,e.createBlock)(nt,{key:0,ref_key:`reelRenderer`,ref:u,"can-retry-end":r.canRetryEnd,"has-next":r.state.next!==null,"card-footer":r.cardFooter,"card-header":r.cardHeader,"feed-footer":r.feedFooter,"feed-footer-actions":r.feedFooterActions,"forward-index":r.state.reelForwardIndex,"forward-item":r.state.reelForwardItem,"media-card":r.mediaCard,"infinite-scroll":r.state.infiniteScroll,"is-loading-more":r.state.isLoadingMore,items:r.state.items,"load-more-locked":r.state.loadMoreLocked,"media-source":r.state.reelMediaSource,"media-indices":r.state.mediaIndices,"initial-post-id":r.state.activeReelPostId,"info-sheet":r.reelInfoSheet,"info-sheet-enabled":r.state.reelInfoSheet.enabled,"info-sheet-overlay":r.state.reelInfoSheetOverlay,"next-page-error":!!r.state.nextPageError,origin:`reel`,"preview-states":(0,e.unref)(k),"reel-auto-advance":r.state.reelAutoAdvance,"reel-forward":r.state.reelForward,state:x.value,total:r.state.total,onActiveChange:n[0]||=e=>c(`activeReelChange`,e),onCloseInfoSheet:n[1]||=e=>c(`reelInfoSheetChange`,!1),onError:(0,e.unref)(T),onLoadMore:n[2]||=e=>c(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(E),onRetryEnd:n[3]||=e=>c(`retryEnd`),onRetryForward:n[4]||=e=>c(`retryForward`)},null,8,`can-retry-end.has-next.card-footer.card-header.feed-footer.feed-footer-actions.forward-index.forward-item.media-card.infinite-scroll.is-loading-more.items.load-more-locked.media-source.media-indices.initial-post-id.info-sheet.info-sheet-enabled.info-sheet-overlay.next-page-error.preview-states.reel-auto-advance.reel-forward.state.total.onError.onReady`.split(`.`))):r.state.error||r.state.isLoading||r.state.items.length===0&&r.state.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(g,{key:1,actions:r.feedFooterActions,"can-retry-end":r.canRetryEnd,"feed-footer":r.feedFooter,state:x.value,onLoadMore:n[5]||=e=>c(`loadMore`),onRetryEnd:n[6]||=e=>c(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`state`])):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:2},[(0,e.createVNode)(Be,{ref_key:`masonryRenderer`,ref:l,"can-retry-end":r.canRetryEnd,"entering-post-ids":h.value,"entry-delays":_.value,"leaving-post-ids":v.value,"removal-delays":y.value,"card-footer":r.cardFooter,"card-header":r.cardHeader,"feed-footer":r.feedFooter,"feed-footer-actions":r.feedFooterActions,"media-card":r.mediaCard,masonry:r.masonry,"has-next":r.state.next!==null,"infinite-scroll":r.state.infiniteScroll,"is-loading-more":r.state.isLoadingMore,items:r.state.items,"load-more-locked":r.state.loadMoreLocked,"media-indices":r.state.mediaIndices,"next-page-error":!!r.state.nextPageError,"preview-states":(0,e.unref)(O),suspended:r.state.reelOrigin===`masonry`||m.value,state:x.value,total:r.state.total,onActivate:H,onError:(0,e.unref)(C),onLoadMore:n[7]||=e=>c(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(w),onRetryEnd:n[8]||=e=>c(`retryEnd`),onVisible:(0,e.unref)(S)},null,8,[`can-retry-end`,`entering-post-ids`,`entry-delays`,`leaving-post-ids`,`removal-delays`,`card-footer`,`card-header`,`feed-footer`,`feed-footer-actions`,`media-card`,`masonry`,`has-next`,`infinite-scroll`,`is-loading-more`,`items`,`load-more-locked`,`media-indices`,`next-page-error`,`preview-states`,`suspended`,`state`,`total`,`onError`,`onReady`,`onVisible`]),(0,e.createVNode)(e.Transition,{name:`vibe-reel-viewer`,onAfterLeave:q},{default:(0,e.withCtx)(()=>[r.state.reelOrigin===`masonry`?((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{key:0,ref_key:`reelOverlay`,ref:d,class:`vibe-reel-overlay`,role:`dialog`,"aria-label":`Media viewer`,"aria-modal":`true`,tabindex:`-1`,style:(0,e.normalizeStyle)(p.value)},[(0,e.createVNode)(nt,{ref_key:`reelRenderer`,ref:u,"can-retry-end":r.canRetryEnd,"card-footer":r.cardFooter,"card-header":r.cardHeader,"feed-footer":r.feedFooter,"feed-footer-actions":r.feedFooterActions,"forward-index":r.state.reelForwardIndex,"forward-item":r.state.reelForwardItem,"media-card":r.mediaCard,"has-next":r.state.next!==null,"infinite-scroll":r.state.infiniteScroll,"initial-post-id":r.state.activeReelPostId,"info-sheet":r.reelInfoSheet,"info-sheet-enabled":r.state.reelInfoSheet.enabled,"info-sheet-overlay":r.state.reelInfoSheetOverlay,"is-loading-more":r.state.isLoadingMore,items:r.state.items,"load-more-locked":r.state.loadMoreLocked,"media-indices":r.state.mediaIndices,"media-source":`original`,"next-page-error":!!r.state.nextPageError,origin:`masonry`,"preview-states":(0,e.unref)(D),"reel-auto-advance":r.state.reelAutoAdvance,"reel-forward":r.state.reelForward,state:x.value,total:r.state.total,onActiveChange:n[9]||=e=>c(`activeReelChange`,e),onCloseInfoSheet:n[10]||=e=>c(`reelInfoSheetChange`,!1),onError:(0,e.unref)(T),onLoadMore:n[11]||=e=>c(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(E),onRetryEnd:n[12]||=e=>c(`retryEnd`),onRetryForward:n[13]||=e=>c(`retryForward`)},null,8,`can-retry-end.card-footer.card-header.feed-footer.feed-footer-actions.forward-index.forward-item.media-card.has-next.infinite-scroll.initial-post-id.info-sheet.info-sheet-enabled.info-sheet-overlay.is-loading-more.items.load-more-locked.media-indices.next-page-error.preview-states.reel-auto-advance.reel-forward.state.total.onError.onReady`.split(`.`))],4)):(0,e.createCommentVNode)(``,!0)]),_:1})],64))],512))}});function pt(e){if(!e||typeof e!=`object`||!Array.isArray(e.items))throw TypeError(`Vibe loadPage must resolve to a page with an items array.`);if(e.current!==void 0&&e.current!==null&&typeof e.current!=`string`&&typeof e.current!=`number`)throw TypeError(`Vibe page current must be a string, number, null, or undefined.`);if(e.next!==null&&typeof e.next!=`string`&&typeof e.next!=`number`)throw TypeError(`Vibe page next must be a string, number, or null.`);if(e.total!==void 0&&(!Number.isFinite(e.total)||e.total<0))throw TypeError(`Vibe page total must be a non-negative number when provided.`);return e}function Z(e,t){let n=new Set(e.map(e=>e.postId));return[...e,...t.filter(e=>n.has(e.postId)?!1:(n.add(e.postId),!0))]}function mt(e){return`${typeof e}:${String(e)}`}function ht(e){return e.mediaId===void 0?`source:${e.src}\u0000${e.preview.src}`:`id:${mt(e.mediaId)}`}function gt(e,t){let n=[...e],r=new Map(e.map((e,t)=>[mt(e.postId),t]));return t.forEach(e=>{let t=mt(e.postId),i=r.get(t);if(i===void 0){r.set(t,n.length),n.push(e);return}let a=n[i],o=new Set([a,...a.items].map(ht)),s=[e,...e.items].filter(e=>{let t=ht(e);return o.has(t)?!1:(o.add(t),!0)});s.length>0&&(n[i]={...a,items:[...a.items,...s]})}),n}function _t(e){return Object.prototype.hasOwnProperty.call(e,`current`)?e.current??null:e.next}function vt(e,t,n,r){let i=pt(e),a=n.filterItems(i.items),o=_t(i);t.items=gt(t.items,a),t.next=i.next,i.total!==void 0&&(t.total=i.total),r(o),n.recordPages([{contributionIds:a.map(({postId:e})=>e),cursor:o,next:i.next,returnedIds:a.map(({postId:e})=>e)}])}var yt=2e3,bt=1e4,xt=250,St={delayRemainingMs:null,nextRequestAt:null};function Ct(e,t){return e===void 0?t:Math.floor(e)}function wt(e,t){for(let[n,r]of[[`delayStepMs`,e.delayStepMs],[`delayMaxMs`,e.delayMaxMs]])if(r!==void 0&&(!Number.isFinite(r)||r<0))throw TypeError(`Vibe ${t} ${n} must be a non-negative number.`)}function Tt(e,t={}){let n=Ct(t.delayStepMs,yt),r=Ct(t.delayMaxMs,bt);return Math.min(Math.max(0,e)*n,r)}function Q(e){if(e==null||!Number.isFinite(e))return{...St};let t=Math.max(0,Math.floor(e-Date.now()));return t>0?{delayRemainingMs:t,nextRequestAt:e}:{...St}}async function Et({delayMs:e,onChange:t,signal:n}){if(n.aborted)throw new DOMException(`Aborted`,`AbortError`);if(e<=0){t({...St});return}let r=Date.now()+e;t({delayRemainingMs:e,nextRequestAt:r}),await new Promise((i,a)=>{let o=!1,s=setInterval(f,xt),c=setTimeout(()=>u(),e);function l(){clearInterval(s),clearTimeout(c),n.removeEventListener(`abort`,d),t({...St})}function u(e){o||(o=!0,l(),e?a(e):i())}function d(){u(new DOMException(`Aborted`,`AbortError`))}function f(){let e=Q(r);t(e),e.delayRemainingMs===null&&u()}n.addEventListener(`abort`,d,{once:!0})})}var Dt=class{interval=null;constructor(e){this.onChange=e}clear(){this.interval!==null&&clearInterval(this.interval),this.interval=null,this.onChange({...St})}sync(e){this.clear();let t=Q(e);this.onChange(t),t.delayRemainingMs!==null&&(this.interval=setInterval(()=>{let t=Q(e);this.onChange(t),t.delayRemainingMs===null&&this.clear()},xt))}};function Ot(e,t=!0){return e.maxAdditionalPages===`unlimited`?1/0:(e.maxAdditionalPages??10)+(t?1:0)}function kt(e){return`${typeof e}:${String(e)}`}function At(e,t){if(!Number.isInteger(e)||e<=0)throw TypeError(`Vibe ${t} must be a positive integer.`)}function jt(e){if(!e)return;if(At(e.pageSize,`autofill pageSize`),e.strategy===`frontend`){wt(e,`frontend autofill`);let t=e.maxAdditionalPages;if(t!==void 0&&t!==`unlimited`&&(!Number.isInteger(t)||t<0))throw TypeError(`Vibe autofill maxAdditionalPages must be a non-negative integer or "unlimited".`);return}if(!e.feedKey.trim())throw TypeError(`Vibe backend autofill requires a feedKey.`);let t=e.initialSession;if(t){if(t.feedKey!==e.feedKey)throw TypeError(`Vibe backend autofill initialSession feedKey must match autofill feedKey.`);if(t.pageSize!==e.pageSize)throw TypeError(`Vibe backend autofill initialSession pageSize must match autofill pageSize.`)}}function Mt(e,t,n=!0){if(!e)return{cycleId:null,delayRemainingMs:null,enabled:!1,error:null,feedKey:null,missing:0,nextRequestAt:null,pageSize:null,received:0,requests:0,sequence:0,sessionId:null,status:`idle`,strategy:null};let r=e.strategy===`backend`?t??(n?e.initialSession:void 0):void 0,i=r?.received??0,a=Q(r?.nextRequestAt);return{cycleId:r?.cycleId??null,...a,enabled:!0,error:r?.error??null,feedKey:e.strategy===`backend`?e.feedKey:null,missing:Math.max(0,e.pageSize-i),pageSize:e.pageSize,received:i,requests:r?.requests??0,sequence:r?.sequence??0,sessionId:r?.sessionId??null,status:r?r.status:`idle`,strategy:e.strategy}}function Nt(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function Pt(e,t,n){let r=t.autofill;if(!Nt(r)||!r.cycleId)return;let i={cycleId:r.cycleId,feedKey:r.feedKey??``,sessionId:r.sessionId};n(),r.status=`cancelling`;try{e?.strategy===`backend`&&await e.onCancel(i),r.error=null,r.status=`cancelled`}catch(e){throw r.error=e,r.status=`error`,e}}function Ft(e,t,n){return e?.strategy===`backend`&&t.feedKey===e.feedKey&&t.sessionId===n.sessionId}async function It({existingItems:e,initialCursor:t,loadPage:n,maximumRequests:r,onCollection:i,onDelayChange:a,onProgress:o,options:s,receivedOffset:c=0,requestOffset:l=0,shouldPause:u=()=>!1,signal:d}){let f=[],p=[...e],m=new Set,h=r??Ot(s),g=t,_=t,v=t,y=0,b=[],x;for(;y<h;){let e=kt(g);if(m.has(e))throw Error(`Vibe autofill received a repeated cursor.`);if(m.add(e),await Et({delayMs:Tt(l+y,s),onChange:a,signal:d}),y>0&&u())return{items:f,lastCursor:_,missing:Math.max(0,s.pageSize-c-f.length),next:v,pages:b,received:c+f.length,requests:l+y,status:`paused`,total:x};let t=pt(await n({cursor:g,signal:d}));y+=1,_=g;let r=Z(p,t.items).slice(p.length);b.push({contributionIds:r.map(({postId:e})=>e),cursor:g,next:t.next,returnedIds:t.items.map(({postId:e})=>e)}),p.push(...r),f.push(...r),v=t.next,t.total!==void 0&&(x=t.total);let h={missing:Math.max(0,s.pageSize-c-f.length),next:v,received:c+f.length,requests:l+y};o(h);let S={...h,items:[...f],lastCursor:_,pages:[...b],total:x};if(i(S),h.missing===0)return{...S,pages:b,status:`complete`};if(v===null)return{...S,pages:b,status:`exhausted`};if(u())return{...S,pages:b,status:`paused`};g=v}return{items:f,lastCursor:_,missing:Math.max(0,s.pageSize-c-f.length),next:v,pages:b,received:c+f.length,requests:l+y,status:`exhausted`,total:x}}var Lt=class{collection=null;cycle=0;delayCountdown;constructor(e){this.context=e,this.delayCountdown=new Dt(t=>Object.assign(e.state.autofill,t)),this.syncCountdown()}beginCycle(){let{options:e,state:t}=this.context;if(!e)return``;this.clear();let n=`vibe-autofill-${Date.now().toString(36)}-${++this.cycle}`;return t.autofill={...Mt(e,void 0,!1),cycleId:n,status:`filling`},n}async cancel(){let{cancelRequest:e,options:t,state:n}=this.context;await Pt(t,n,e),this.commitCollection()}captureCollection(e,t){t&&(this.collection=e)}clear(){this.delayCountdown.clear(),this.collection=null}clearCountdown(){this.delayCountdown.clear()}clearCollection(){this.collection=null}syncCountdown(){let{autofill:e}=this.context.state;this.delayCountdown.sync(e.strategy===`backend`&&e.status===`waiting`?e.nextRequestAt:null)}commitCollection(){let{onLastCursor:e,options:t,state:n}=this.context;if(t?.strategy!==`frontend`)return!1;let r=this.collection;return this.collection=null,r?(n.items=Z(n.items,r.items),e(r.lastCursor),this.context.onPages(r.pages),n.next=r.next,r.total!==void 0&&(n.total=r.total),Object.assign(n.autofill,{missing:r.missing,received:r.received,requests:r.requests}),!0):!1}},Rt=100;function zt(e,t){if(!Number.isFinite(t)||t<=0)throw TypeError(`Vibe ${e} must be a positive number.`)}function Bt(e,t,n){return Math.min(n,Math.max(t,e))}function Vt(e){if(!e)return;let t=e.minSpeedPxPerSecond??20,n=e.maxSpeedPxPerSecond??240;if(zt(`autoScroll.minSpeedPxPerSecond`,t),zt(`autoScroll.maxSpeedPxPerSecond`,n),t>n)throw TypeError(`Vibe autoScroll.minSpeedPxPerSecond cannot exceed maxSpeedPxPerSecond.`);e.speedPxPerSecond!==void 0&&zt(`autoScroll.speedPxPerSecond`,e.speedPxPerSecond)}function Ht(e){let t=e?.minSpeedPxPerSecond??20,n=e?.maxSpeedPxPerSecond??240;return{enabled:e?.enabled??!1,maxSpeedPxPerSecond:n,minSpeedPxPerSecond:t,paused:!1,speedPxPerSecond:Bt(e?.speedPxPerSecond??80,t,n)}}var Ut=class{frame=null;lastTimestamp=null;mounted=!1;constructor(e){this.options=e}mount(){this.mounted=!0,this.schedule()}destroy(){this.mounted=!1,this.cancelFrame()}setEnabled(e,t){t!==void 0&&this.setSpeed(t),this.options.state.enabled=e,this.options.state.paused=!1,this.lastTimestamp=null,e?this.schedule():this.cancelFrame()}setPaused(e){this.options.state.enabled&&(this.options.state.paused=e,this.lastTimestamp=null,e?this.cancelFrame():this.schedule())}setSpeed(e){zt(`auto-scroll speed`,e);let t=this.options.state;t.speedPxPerSecond=Bt(e,t.minSpeedPxPerSecond,t.maxSpeedPxPerSecond)}tick=e=>{this.frame=null;let t=this.options.state;if(!this.mounted||!t.enabled)return;let n=t.paused?null:this.options.getScrollElement();if(!n){this.lastTimestamp=null,this.schedule();return}if(this.lastTimestamp!==null){let r=Math.min(Rt,Math.max(0,e-this.lastTimestamp)),i=Math.max(0,n.scrollHeight-n.clientHeight);n.scrollTop=Math.min(i,n.scrollTop+t.speedPxPerSecond*r/1e3)}this.lastTimestamp=e,this.schedule()};schedule(){!this.mounted||!this.options.state.enabled||this.frame!==null||typeof requestAnimationFrame==`function`&&(this.frame=requestAnimationFrame(this.tick))}cancelFrame(){this.frame!==null&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(this.frame),this.frame=null,this.lastTimestamp=null}};async function Wt(e,t,n,r){let i=await e.onUnderfilled(n);if(!r())return;if(!i.sessionId.trim())throw TypeError(`Vibe backend autofill requires a sessionId.`);let a=Math.max(n.received,i.received??n.received);Object.assign(t.autofill,{...Q(i.nextRequestAt),missing:Math.max(0,e.pageSize-a),received:a,sequence:i.sequence??0,sessionId:i.sessionId,status:`waiting`})}function Gt(e,t){[`complete`,`exhausted`].includes(t.status)&&t.items&&(e.items=Z(e.items,t.items)),t.next!==void 0&&(e.next=t.next),t.total!==void 0&&(e.total=t.total)}function Kt(e,t,n){let r=t.autofill;return!Ft(e,n,r)||n.sequence<=r.sequence||[`cancelled`,`cancelling`].includes(r.status)||[`complete`,`exhausted`].includes(n.status)&&n.next===void 0?!1:(Gt(t,n),Object.assign(r,Q(n.status===`waiting`?n.nextRequestAt:null)),r.error=n.error??null,r.missing=Math.max(0,(r.pageSize??0)-n.received),r.received=n.received,n.requests!==void 0&&(r.requests=n.requests),r.sequence=n.sequence,r.status=n.status,!0)}function qt(e,t,n){return e?.strategy!==`backend`||n.feedKey!==e.feedKey||n.pageSize!==e.pageSize?!1:(t.autofill=Mt(e,n),Gt(t,n),!0)}async function Jt(e,t,n){if(!e)return;let r=new AbortController;n(r);try{await e({appendPage:t,signal:r.signal})}finally{n(null)}}async function Yt({cycleId:e,isCurrent:t,onCollection:n,onLastCursor:r,onPages:i,options:a,signal:o,state:s}){let c=a.autofill;if(!c)return;let l=s.items.length;if(Object.assign(s.autofill,{missing:Math.max(0,c.pageSize-l),received:l,requests:1}),l>=c.pageSize){s.autofill.status=`complete`;return}if(c.strategy===`backend`){await Wt(c,s,{cycleId:e,feedKey:c.feedKey,items:[...s.items],missing:c.pageSize-l,next:s.next,pageSize:c.pageSize,received:l,signal:o,total:s.total},t);return}if(!a.loadPage||s.next===null){s.autofill.status=`exhausted`;return}let u=await It({existingItems:s.items,initialCursor:s.next,loadPage:a.loadPage,maximumRequests:Ot(c,!1),onCollection:n,onDelayChange:e=>{t()&&Object.assign(s.autofill,e)},onProgress:e=>{t()&&Object.assign(s.autofill,e,{status:`filling`})},options:c,receivedOffset:l,requestOffset:1,shouldPause:()=>s.loadMoreLocked,signal:o});t()&&(s.items=Z(s.items,u.items),s.next=u.next,u.total!==void 0&&(s.total=u.total),r(u.lastCursor),i(u.pages),Object.assign(s.autofill,{missing:u.missing,received:u.received,requests:u.requests,status:u.status}))}function Xt(e){return`items`in e?{items:e.items}:`pages`in e?{pages:e.pages}:{until:`end`}}function Zt(e){return`${typeof e}:${String(e)}`}function Qt(e){if(!e||typeof e!=`object`)throw TypeError(`Vibe fill target must be an object.`);if(`pages`in e){if(!Number.isInteger(e.pages)||e.pages<=0)throw TypeError(`Vibe fill pages must be a positive integer.`);return{pages:e.pages}}if(`items`in e){if(!Number.isInteger(e.items)||e.items<=0)throw TypeError(`Vibe fill items must be a positive integer.`);return{items:e.items}}if(`until`in e&&e.until===`end`)return{until:`end`};throw TypeError(`Vibe fill target must be { items }, { pages }, or { until: 'end' }.`)}function $t(e){if(!e)return;if(e.strategy===`frontend`){wt(e,`frontend fill`);return}if(!e.feedKey.trim())throw TypeError(`Vibe backend fill requires a feedKey.`);let t=e.initialSession;if(t){if(t.feedKey!==e.feedKey)throw TypeError(`Vibe backend fill initialSession feedKey must match fill feedKey.`);Qt(t.target)}}function en(e,t,n=!0){let r=e?.strategy===`backend`&&n?e.initialSession:void 0,i=t??r,a=Q(i?.nextRequestAt);return{completedPages:i?.completedPages??0,cycleId:i?.cycleId??null,...a,enabled:!!e,error:i?.error??null,feedKey:e?.strategy===`backend`?e.feedKey:null,received:i?.received??0,sequence:i?.sequence??0,sessionId:i?.sessionId??null,status:i?.status??`idle`,strategy:e?.strategy??null,target:i?Xt(i.target):null}}function tn(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function nn({existingItems:e,initialCursor:t,loadPage:n,onCollection:r=()=>void 0,onDelayChange:i,onProgress:a,options:o,shouldPause:s=()=>!1,signal:c,target:l}){let u=[],d=[],f=[...e],p=new Set,m=0,h=t,g=t,_=t,v=0,y;if(`items`in l&&f.length>=l.items)return{completedPages:m,items:u,lastCursor:g,next:_,pages:d,received:v,status:`complete`};for(;_!==null;){let e=Zt(h);if(p.has(e))throw Error(`Vibe fill received a repeated cursor.`);if(p.add(e),await Et({delayMs:Tt(m,o),onChange:i,signal:c}),m>0&&s())return{completedPages:m,items:u,lastCursor:g,next:_,pages:d,received:v,status:`paused`,total:y};let t=pt(await n({cursor:h,signal:c}));m+=1,g=h;let b=Z(f,t.items).slice(f.length);if(d.push({contributionIds:b.map(({postId:e})=>e),cursor:h,next:t.next,returnedIds:t.items.map(({postId:e})=>e)}),f.push(...b),u.push(...b),v=u.length,_=t.next,t.total!==void 0&&(y=t.total),a({completedPages:m,next:_,received:v}),r({completedPages:m,items:[...u],lastCursor:h,next:_,pages:[...d],received:v,total:y}),`items`in l&&f.length>=l.items||`pages`in l&&m>=l.pages)return{completedPages:m,items:u,lastCursor:h,next:_,pages:d,received:v,status:`complete`,total:y};if(_===null)return{completedPages:m,items:u,lastCursor:h,next:_,pages:d,received:v,status:`until`in l?`complete`:`exhausted`,total:y};if(s())return{completedPages:m,items:u,lastCursor:h,next:_,pages:d,received:v,status:`paused`,total:y};h=_}return{completedPages:m,items:u,lastCursor:h,next:null,pages:d,received:v,status:`until`in l?`complete`:`exhausted`,total:y}}async function rn(e,t,n,r){let i=await e.onStart(n);if(r()){if(!i.sessionId.trim())throw TypeError(`Vibe backend fill requires a sessionId.`);Object.assign(t.fill,{...Q(i.nextRequestAt),completedPages:i.completedPages??0,received:i.received??0,sequence:i.sequence??0,sessionId:i.sessionId,status:`waiting`})}}function an(e,t,n){return e?.strategy===`backend`&&n.feedKey===e.feedKey&&n.sessionId===t.fill.sessionId}function on(e){return Number.isInteger(e.completedPages)&&e.completedPages>=0&&Number.isInteger(e.received)&&e.received>=0&&Number.isInteger(e.sequence)&&e.sequence>=0}function sn(e,t){if(![`complete`,`exhausted`].includes(t.status))return!0;let n=e.fill.target;return!n||!Array.isArray(t.items)||t.next===void 0||t.lastCursor===void 0?!1:t.status===`exhausted`?`pages`in n&&t.completedPages<n.pages&&t.next===null:`pages`in n?t.completedPages===n.pages:t.next===null}function cn(e,t,n){t.total!==void 0&&(e.total=t.total),[`complete`,`exhausted`].includes(t.status)&&(e.items=Z(e.items,t.items??[]),e.next=t.next??null,n(t.lastCursor??null))}function ln(e,t,n,r){return!an(e,t,n)||!on(n)||n.sequence<=t.fill.sequence||[`cancelled`,`cancelling`].includes(t.fill.status)||!sn(t,n)?!1:(cn(t,n,r),Object.assign(t.fill,{...Q(n.status===`waiting`?n.nextRequestAt:null),completedPages:n.completedPages,error:n.error??null,received:n.received,sequence:n.sequence,status:n.status}),!0)}function un(e,t,n,r){if(e?.strategy!==`backend`||n.feedKey!==e.feedKey)return!1;let i=t.fill;return t.fill=en(e,n),!on(n)||!sn(t,n)?(t.fill=i,!1):(cn(t,n,r),!0)}var dn=class{abortController=null;cycle=0;delayCountdown;requestVersion=0;collection=null;constructor(e){this.options=e,this.delayCountdown=new Dt(e=>{Object.assign(this.options.state.fill,e)}),this.syncBackendCountdown()}isActive(){return tn(this.options.state.fill)}applyUpdate(e){let t=ln(this.options.fill,this.options.state,e,this.options.onLastCursor);return t&&this.syncBackendCountdown(),t}restoreSession(e){let t=un(this.options.fill,this.options.state,e,this.options.onLastCursor);return t&&this.syncBackendCountdown(),t}async start(e,t={}){let n=this.options.fill;if(!n)throw Error(`Vibe fill is not configured.`);if(this.isActive())throw Error(`Vibe fill is already active.`);let r=Qt(e),i=Qt(t.target??r),a=t.progressOffset??{completedPages:0,received:0},o=t.cycleId??`vibe-fill-${Date.now().toString(36)}-${++this.cycle}`;if(this.options.state.fill={...en(n,void 0,!1),completedPages:a.completedPages,cycleId:o,received:a.received,status:`filling`,target:i},n.strategy===`backend`&&this.options.state.next===null){this.options.state.fill.status=`until`in r?`complete`:`exhausted`;return}let s=++this.requestVersion,c=new AbortController;this.abortController=c;try{n.strategy===`frontend`?await this.startFrontend(n,r,c,s,t.prepareFrontend!==!1,a):(await rn(n,this.options.state,{cycleId:o,feedKey:n.feedKey,items:[...this.options.state.items],next:this.options.state.next,signal:c.signal,target:r,total:this.options.state.total},()=>this.isCurrent(s)),this.syncBackendCountdown())}catch(e){if(c.signal.aborted||!this.isCurrent(s))return;throw this.commitCollection(),this.options.state.fill.error=e,this.options.state.fill.status=`error`,e}finally{this.isCurrent(s)&&(this.abortController=null,this.options.state.isLoadingMore=!1)}}async cancel(){let{fill:e,state:t}=this.options;if(!tn(t.fill)||!t.fill.cycleId)return;let n={cycleId:t.fill.cycleId,feedKey:t.fill.feedKey??``,sessionId:t.fill.sessionId};t.fill.status=`cancelling`,this.delayCountdown.clear(),this.abortController?.abort(),this.requestVersion+=1,this.abortController=null,t.isLoadingMore=!1,this.commitCollection();try{e?.strategy===`backend`&&await e.onCancel(n),t.fill.error=null,t.fill.status=`cancelled`}catch(e){throw t.fill.error=e,t.fill.status=`error`,e}}resume(e){let{fill:t}=this.options.state;if(t.status!==`paused`||!t.target)return Promise.resolve();let n=t.target,r=`pages`in n?n.pages-t.completedPages:null;if(r!==null&&r<=0)return t.status=`complete`,Promise.resolve();let i=r===null?n:{pages:r};return t.strategy===`backend`?this.start(i):this.start(i,{cycleId:t.cycleId??void 0,prepareFrontend:e,progressOffset:{completedPages:t.completedPages,received:t.received},target:n})}retry(e){let{fill:t}=this.options.state;if(t.status!==`error`||!t.target)return Promise.resolve();let n=t.target,r=`pages`in n?n.pages-t.completedPages:null;return r!==null&&r<=0?(t.status=`complete`,Promise.resolve()):this.start(r===null?n:{pages:r},{cycleId:t.cycleId??void 0,prepareFrontend:e,progressOffset:{completedPages:t.completedPages,received:t.received},target:n})}reset(){this.abortLocalRequest(),this.delayCountdown.clear(),this.options.state.fill=en(this.options.fill,void 0,!1),this.collection=null}destroy(){this.abortLocalRequest(),this.delayCountdown.clear()}abortLocalRequest(){this.requestVersion+=1,this.abortController?.abort(),this.abortController=null,this.options.state.isLoadingMore=!1}isCurrent(e){return e===this.requestVersion&&![`cancelled`,`cancelling`].includes(this.options.state.fill.status)}async startFrontend(e,t,n,r,i,a){let o=this.options.loadPage;if(!o)throw Error(`Vibe frontend fill requires loadPage.`);let s=this.options.state;if(s.isLoadingMore=!0,i&&this.options.prepareFrontend&&(this.options.needsFrontendPreparation?.()??!0)){s.fill.status=`restoring`;let e=await this.options.prepareFrontend({isCurrent:()=>this.isCurrent(r),onDelayChange:e=>{this.isCurrent(r)&&Object.assign(s.fill,e)},signal:n.signal});if(!this.isCurrent(r))return;if(e===`paused`||s.loadMoreLocked){s.fill.status=`paused`;return}s.fill.status=`filling`}if(s.next===null){s.fill.status=`until`in t?`complete`:`exhausted`;return}let c=await nn({existingItems:s.items,initialCursor:s.next,loadPage:o,onCollection:e=>{this.isCurrent(r)&&(this.collection={...e,completedPages:a.completedPages+e.completedPages,received:a.received+e.received},this.commitCollection())},onDelayChange:e=>{this.isCurrent(r)&&Object.assign(s.fill,e)},onProgress:e=>{this.isCurrent(r)&&Object.assign(s.fill,{...e,completedPages:a.completedPages+e.completedPages,received:a.received+e.received})},options:e,shouldPause:()=>s.loadMoreLocked,signal:n.signal,target:t});this.isCurrent(r)&&(s.items=Z(s.items,c.items),s.next=c.next,c.total!==void 0&&(s.total=c.total),this.options.onLastCursor(c.lastCursor),Object.assign(s.fill,{completedPages:a.completedPages+c.completedPages,received:a.received+c.received,status:c.status}),this.collection=null)}commitCollection(){let e=this.collection;if(this.collection=null,!e||this.options.fill?.strategy!==`frontend`)return;let t=this.options.state;t.items=Z(t.items,e.items),t.next=e.next,e.total!==void 0&&(t.total=e.total),this.options.onLastCursor(e.lastCursor),this.options.onPages(e.pages),Object.assign(t.fill,{completedPages:e.completedPages,received:e.received})}syncBackendCountdown(){let e=this.options.state.fill;this.delayCountdown.sync(e.strategy===`backend`&&e.status===`waiting`?e.nextRequestAt:null)}};async function fn({controller:e,isCurrent:t,loadPage:n,onDelayChange:r,setLastCursor:i,signal:a,state:o}){if(!e.needsReconciliation(o.items))return`skipped`;let s=await e.reconcile({existingItems:o.items,loadPage:n,onDelayChange:r,shouldPause:()=>o.loadMoreLocked,signal:a});return t()?(o.items=Z(o.items,s.items),o.next=s.next,i(s.lastCursor),s.total!==void 0&&(o.total=s.total),e.completeReconciliation(s),s.status):s.status}function pn(e){return{cancelAutofill:()=>e.cancelAutofill(),loadMore:()=>e.loadNext(),retry:()=>{let t=e.getState();return t.autofill.strategy===`frontend`&&t.autofill.status===`error`&&t.items.length>0&&t.next!==null?e.loadNext():e.reload()},retryEnd:()=>e.retryEnd(),retryFill:()=>e.retryFill()}}function mn(e){if(!Number.isFinite(e)||e<=0)throw TypeError(`Vibe reelAutoAdvance.intervalMs must be a positive number.`)}function hn(e){e?.intervalMs!==void 0&&mn(e.intervalMs)}function gn(e){return{enabled:e?.enabled??!1,includePostItems:e?.includePostItems??!1,intervalMs:e?.intervalMs??5e3}}function _n(e,t){if(typeof t==`boolean`){e.enabled=t;return}hn(t),t.enabled!==void 0&&(e.enabled=t.enabled),t.includePostItems!==void 0&&(e.includePostItems=t.includePostItems),t.intervalMs!==void 0&&(e.intervalMs=t.intervalMs)}function vn(e){return{enabled:e?.enabled??!1}}function yn(e,t,n){if(n&&!t)throw Error(`Vibe cannot enable reelInfoSheet without a configured component.`);e.enabled=n}function bn(e,t){let n=e.initialPage;return{activeReelPostId:null,autoScroll:Ht(e.autoScroll),autofill:Mt(e.autofill),current:n?.current??null,error:null,fill:en(e.fill),infiniteScroll:e.infiniteScroll??!0,isLoading:!n,isLoadingMore:!1,items:n?Z([],n.items):[],layout:t===`reel`?`reel`:`masonry`,loadMoreLocked:!1,mediaIndices:new Map,next:n?.next??null,nextPageError:null,phoneMode:!1,reelAutoAdvance:gn(e.reelAutoAdvance),reelForward:{error:null,status:`idle`},reelForwardIndex:null,reelForwardItem:null,reelInfoSheet:vn(e.reelInfoSheet),reelInfoSheetOverlay:!1,reelMediaSource:`original`,reelOrigin:null,total:n?.total??null}}function xn(e,t){if(t){if(!Number.isFinite(t.height)||t.height<=0)throw TypeError(`Vibe ${e} height must be a positive number.`);if(t.background!==void 0&&t.background!==`default`&&t.background!==`transparent`)throw TypeError(`Vibe ${e} background must be "default" or "transparent".`)}}function Sn(e,t){if(t){if(t.background!==void 0&&t.background!==`default`&&t.background!==`transparent`)throw TypeError(`Vibe mediaCard ${e} background must be "default" or "transparent".`);for(let[n,r]of[[`paddingX`,t.paddingX],[`paddingY`,t.paddingY]])if(r!==void 0&&(!Number.isFinite(r)||r<0))throw TypeError(`Vibe mediaCard ${e} ${n} must be a non-negative number.`)}}function Cn(e){if(Vt(e.autoScroll),xn(`cardHeader`,e.cardHeader),xn(`cardFooter`,e.cardFooter),Sn(`header`,e.mediaCard?.header),Sn(`footer`,e.mediaCard?.footer),jt(e.autofill),$t(e.fill),D(e.masonry),hn(e.reelAutoAdvance),e.removalReconciliation){if(!Number.isInteger(e.removalReconciliation.pageSize)||e.removalReconciliation.pageSize<=0)throw TypeError(`Vibe removalReconciliation pageSize must be a positive integer.`);let t=e.removalReconciliation.maxReplayPages??5;if(!Number.isInteger(t)||t<=0)throw TypeError(`Vibe removalReconciliation maxReplayPages must be a positive integer.`);if(!e.loadPage)throw TypeError(`Vibe removalReconciliation requires loadPage.`);if(e.autofill?.strategy===`backend`)throw TypeError(`Vibe removalReconciliation does not support backend autofill.`);if(e.autofill?.strategy===`frontend`&&e.autofill.pageSize<e.removalReconciliation.pageSize)throw TypeError(`Vibe autofill pageSize must be greater than or equal to removalReconciliation pageSize.`);if(e.fill?.strategy===`backend`)throw TypeError(`Vibe removalReconciliation does not support backend fill.`)}if(e.removalHistoryLimit!==void 0&&(!Number.isInteger(e.removalHistoryLimit)||e.removalHistoryLimit<0))throw TypeError(`Vibe removalHistoryLimit must be a non-negative integer.`);if(!e.initialPage&&!e.loadPage)throw TypeError(`Vibe requires either initialPage or loadPage.`);if(e.initialPage?.next!==null&&!e.loadPage)throw TypeError(`Vibe requires loadPage when initialPage has a next cursor.`);if(e.fill?.strategy===`frontend`&&!e.loadPage)throw TypeError(`Vibe frontend fill requires loadPage.`);if(e.fill?.strategy===`backend`&&e.fill.initialSession&&!e.initialPage)throw TypeError(`Vibe backend fill restoration requires initialPage.`)}function wn(e){if(typeof e!=`string`)return e;if(typeof document>`u`)throw Error(`Vibe cannot resolve a selector without a document.`);let t=document.querySelector(e);if(!t)throw Error(`Vibe target not found: ${e}`);return t}async function Tn({append:e,autofillController:t,cursor:n,isCurrent:r,loadPage:i,onLastCursor:a,onPages:o,options:s,signal:c,state:l}){let u=s.autofill,d=e&&u?.strategy===`frontend`&&(l.autofill.status===`paused`||l.autofill.status===`error`),f=d?{received:l.autofill.received,requests:l.autofill.requests}:null,p=u?d?l.autofill.cycleId:t.beginCycle():null;d&&Object.assign(l.autofill,{error:null,status:`filling`});let m=!1;try{if(u?.strategy===`frontend`){let s=await It({existingItems:e?l.items:[],initialCursor:n,loadPage:i,maximumRequests:f?Math.max(0,Ot(u)-f.requests):void 0,onCollection:e=>t.captureCollection(e,r()),onDelayChange:e=>{r()&&Object.assign(l.autofill,e)},onProgress:e=>{r()&&Object.assign(l.autofill,e,{status:`filling`})},options:u,receivedOffset:f?.received,requestOffset:f?.requests,shouldPause:()=>l.loadMoreLocked,signal:c});if(!r())return;l.items=e?Z(l.items,s.items):[...s.items],a(s.lastCursor),l.next=s.next,s.total!==void 0&&(l.total=s.total),Object.assign(l.autofill,{missing:s.missing,received:s.received,requests:s.requests,status:s.status}),o(s.pages),t.clearCollection();return}let s=pt(await i({cursor:n,signal:c}));if(!r())return;let d=e?l.items:[],h=Z(d,s.items),g=h.length-d.length;if(l.items=h,a(n),o([{contributionIds:h.slice(d.length).map(({postId:e})=>e),cursor:n,next:s.next,returnedIds:s.items.map(({postId:e})=>e)}]),l.next=s.next,s.total!==void 0&&(l.total=s.total),m=!0,u?.strategy===`backend`&&p){if(Object.assign(l.autofill,{missing:Math.max(0,u.pageSize-g),received:g,requests:1}),g>=u.pageSize){l.autofill.status=`complete`;return}await Wt(u,l,{cycleId:p,feedKey:u.feedKey,items:h.slice(d.length),missing:u.pageSize-g,next:s.next,pageSize:u.pageSize,received:g,signal:c,total:l.total},r),t.syncCountdown()}}catch(n){if(c.aborted||!r())return;let i=u?.strategy===`frontend`?t.commitCollection():!1;u&&(l.autofill.error=n,l.autofill.status=`error`),m||(e||i?l.nextPageError=n:l.error=n)}finally{r()&&(t.clearCollection(),l.isLoading=!1,l.isLoadingMore=!1)}}function $(e){return`${typeof e}:${String(e)}`}function En(e){return`${typeof e}:${String(e)}`}function Dn(e){return e.map(({postId:e})=>e)}var On=class{delay;enabled;maxReplayPages;pageSize;pages=[];pending=null;tombstones=new Set;constructor(e){let t=e.removalReconciliation;this.enabled=!!t,this.maxReplayPages=t?.maxReplayPages??5,this.pageSize=t?.pageSize??0,this.delay=e.autofill?.strategy===`frontend`?e.autofill:{delayMaxMs:0,delayStepMs:0}}completeReconciliation(e){e.status===`complete`&&(this.pages=[...this.pages.slice(0,e.replaceFrom),...e.pages].slice(-this.maxReplayPages),this.pending=null)}filterItems(e){return this.tombstones.size===0?[...e]:e.filter(({postId:e})=>!this.tombstones.has($(e)))}needsReconciliation(e){return this.pending!==null||this.findUnderfilledPage(e)>=0}hasPendingSession(){return this.pending!==null}recordPages(e){!this.enabled||e.length===0||(e.forEach(e=>this.recordPage(e)),this.pages=this.pages.slice(-this.maxReplayPages))}recordInitialPage(e){e&&this.recordPages([{contributionIds:Dn(e.items),cursor:_t(e),next:e.next,returnedIds:Dn(e.items)}])}remove(e){e.forEach(e=>this.tombstones.add($(e)))}reset(){this.pages=[],this.pending=null,this.tombstones.clear()}restore(e){e.forEach(e=>this.tombstones.delete($(e)))}async reconcile({existingItems:e,loadPage:t,onDelayChange:n=()=>void 0,shouldPause:r=()=>!1,signal:i}){let a=this.pending??this.createSession(e);for(this.pending=a;a.remainingRequests>0;){let e=En(a.cursor);if(a.seenCursors.has(e))throw Error(`Vibe removal reconciliation received a repeated cursor.`);if(await Et({delayMs:Tt(a.pages.length,this.delay),onChange:n,signal:i}),a.pages.length>0&&r())return this.result(a,`paused`);let o=pt(await t({cursor:a.cursor,signal:i}));a.seenCursors.add(e);let s=this.filterItems(o.items),c=[];if(s.forEach(e=>{let t=$(e.postId);a.attributed.has(t)||(a.attributed.add(t),c.push(e.postId)),a.appended.has(t)||(a.appended.add(t),a.items.push(e))}),a.pages.push({contributionIds:c,cursor:a.cursor,next:o.next,returnedIds:Dn(s)}),a.lastCursor=a.cursor,a.next=o.next,--a.remainingRequests,o.total!==void 0&&(a.total=o.total),a.next===null?a.remainingRequests=0:a.cursor=a.next,a.remainingRequests>0&&r())return this.result(a,`paused`)}return this.result(a,`complete`)}createSession(e){let t=this.findUnderfilledPage(e),n=t<0?[]:this.pages.slice(t),r=n[0];if(!r)throw Error(`Vibe has no underfilled provider page to reconcile.`);let i=new Set(n.flatMap(({contributionIds:e})=>e.map($))),a=new Set(e.map(({postId:e})=>$(e)).filter(e=>!i.has(e)));return{appended:new Set(e.map(({postId:e})=>$(e))),attributed:new Set(a),cursor:r.cursor,items:[],lastCursor:r.cursor,next:r.cursor,pages:[],remainingRequests:n.length,replaceFrom:t,seenCursors:new Set}}result(e,t){return{items:[...e.items],lastCursor:e.lastCursor,next:e.next,pages:[...e.pages],replaceFrom:e.replaceFrom,status:t,total:e.total}}findUnderfilledPage(e){if(!this.enabled||this.pages.length===0)return-1;let t=new Set(e.map(({postId:e})=>$(e)));return this.pages.findIndex(({contributionIds:e})=>e.filter(e=>t.has($(e))).length<this.pageSize)}recordPage(e){let t=En(e.cursor),n=this.pages.findIndex(({cursor:e})=>En(e)===t);n>=0&&(this.pages=this.pages.slice(0,n)),this.pages.push({...e,contributionIds:[...e.contributionIds],returnedIds:[...e.returnedIds]})}};function kn(e,t,n,r,i){let a=new Set(t.map(({item:e})=>e.postId));if(e.activeReelPostId===null||!a.has(e.activeReelPostId))return;let o=e.items[Math.max(n,0)];if(o){r(o.postId);return}let s=t.find(({item:t})=>t.postId===e.activeReelPostId)?.item;s&&i(Math.max(n,0),s)}function An(e,t){let[n,...r]=t;if(!n)throw Error(`Vibe items must contain at least one media asset.`);return{...e,...n,items:r}}function jn(e){if(!Number.isInteger(e.mediaIndex)||e.mediaIndex<0)throw TypeError(`Vibe mediaIndex must be a non-negative integer.`)}var Mn=class{generation=0;metadata=new WeakMap;state;constructor(e){this.options=e,this.state=e.state}remove(e){jn(e);let n=this.state.items.findIndex(({postId:t})=>t===e.postId),r=this.state.items[n];if(!r)return null;let i=[...t(r)],a=i[e.mediaIndex];if(!a)return null;let o=Object.freeze({media:a,mediaIndex:e.mediaIndex,postId:e.postId,postIndex:n});this.metadata.set(o,{generation:this.generation,originalItem:r,restored:!1});let s=this.state.mediaIndices.get(r.postId)??0,c=this.isReelOpen()&&this.state.activeReelPostId===r.postId,l=c&&s===e.mediaIndex;return i.splice(e.mediaIndex,1),i.length>0?(this.state.items[n]=An(r,i),this.updateMediaIndexAfterRemoval(r.postId,e.mediaIndex,l),o):(this.state.items.splice(n,1),this.options.onPostRemoved(r.postId),this.state.mediaIndices.delete(r.postId),c&&this.advanceFromRemovedPost(o,r),o)}reset(){this.generation+=1}restore(e){let t=this.metadata.get(e);if(!t)throw TypeError(`Vibe media removal does not belong to this instance.`);if(t.generation!==this.generation||t.restored)return!1;t.restored=!0,this.options.onPostRestored(e.postId);let n=this.state.items.findIndex(({postId:t})=>t===e.postId);return n>=0?this.restoreIntoPost(n,e):this.state.items.splice(Math.min(e.postIndex,this.state.items.length),0,t.originalItem),this.options.reelForward.cancel(e)&&(this.state.mediaIndices.set(e.postId,e.mediaIndex),this.options.onActivate(e.postId)),!0}advanceFromRemovedPost(e,t){let n=this.state.items[e.postIndex];if(n){this.options.onActivate(n.postId);return}this.options.reelForward.start(e,e.postIndex,t)}isReelOpen(){return this.state.layout===`reel`||this.state.reelOrigin===`masonry`}restoreIntoPost(e,n){let r=this.state.items[e],i=[...t(r)],a=Math.min(n.mediaIndex,i.length);if(i.splice(a,0,n.media),this.state.items[e]=An(r,i),this.state.activeReelPostId!==n.postId)return;let o=this.state.mediaIndices.get(n.postId)??0;o>=a&&this.state.mediaIndices.set(n.postId,o+1)}updateMediaIndexAfterRemoval(e,n,r){let i=this.state.items.find(t=>t.postId===e);if(!i)return;let a=t(i).length,o=this.state.mediaIndices.get(e)??0,s=o;r?s=n<a?n:0:n<o&&(s=o-1),this.state.mediaIndices.set(e,Math.min(s,a-1))}};function Nn(e,t){let n=new Set(t);return e.flatMap((e,t)=>n.has(e.postId)?[{index:t,item:e}]:[])}function Pn(e,t){let n=new Set(t.map(({item:e})=>e.postId));return e.filter(e=>!n.has(e.postId))}function Fn(e,t){t.forEach(({index:e})=>{if(!Number.isInteger(e)||e<0)throw Error(`Vibe item restore indexes must be non-negative integers.`)});let n=[...e],r=new Set(e.map(e=>e.postId));return[...t].sort((e,t)=>e.index-t.index).forEach(({index:e,item:t})=>{r.has(t.postId)||(n.splice(Math.min(e,n.length),0,t),r.add(t.postId))}),n}var In=20,Ln=class{generation=0;historyLimit;metadata=new WeakMap;state;history=[];itemOrder;stopItemsWatcher;constructor(t){this.options=t,this.historyLimit=t.historyLimit??In,this.state=t.state,this.itemOrder=this.state.items.map(({postId:e})=>e),this.stopItemsWatcher=(0,e.watch)(()=>this.state.items,e=>this.appendUnknownItems(e),{flush:`sync`})}destroy(){this.reset(),this.stopItemsWatcher()}async remove(e,t){if(t?.staggerMs!==void 0&&(!Number.isFinite(t.staggerMs)||t.staggerMs<0))throw TypeError(`Vibe item removal staggerMs must be a non-negative number.`);let n=this.collectOrderedPlacements(e),r=this.createRemoval(n);if(n.length===0)return r;let i=n.map(({item:e})=>e.postId);if(await this.options.prepareRemoval(i),this.metadata.get(r)?.generation!==this.generation)return r;let a=this.options.startRemoval(i,t);if(a>0&&await new Promise(e=>setTimeout(e,a)),this.metadata.get(r)?.generation!==this.generation)return r;let o=this.state.items.findIndex(e=>e.postId===this.state.activeReelPostId),s=new Set(n.map(({item:e})=>e.postId)),c=o<0?0:this.state.items.slice(0,o).filter(({postId:e})=>s.has(e)).length,l=Math.max(o-c,0);return this.state.items=Pn(this.state.items,n),this.options.onItemsRemoved(r,n,l),this.record(r),r}reset(){this.generation+=1,this.history=[],this.itemOrder=[]}restoreItems(e){let t=e;if(this.metadata.has(t)){this.restoreRemoval(t);return}let n=new Set(this.state.items.map(({postId:e})=>e)),r=e.filter(({item:e})=>n.has(e.postId)?!1:(n.add(e.postId),!0)),i=Fn(this.state.items,r);this.registerExternalPlacements(r),this.state.items=i,r.length>0&&this.options.onRemovalRestored(r)}restoreRemoval(e){let t=this.metadata.get(e);if(!t)throw TypeError(`Vibe removal does not belong to this instance.`);if(t.generation!==this.generation||t.restored)return!1;t.restored=!0,this.removeFromHistory(e);let n=this.restoreOrderedPlacements(e);return n&&this.options.onRemovalRestored(e),n}undoLast(){for(;this.history.length>0;){let e=this.history.pop();if(this.restoreRemoval(e))return e}return null}appendUnknownItems(e){let t=new Set(this.itemOrder);e.forEach(({postId:e})=>{t.has(e)||(this.itemOrder.push(e),t.add(e))})}collectOrderedPlacements(e){let t=new Map(this.itemOrder.map((e,t)=>[e,t]));return Nn(this.state.items,e).map(e=>({index:t.get(e.item.postId)??e.index,item:e.item}))}createRemoval(e){let t=Object.freeze(e.map(e=>Object.freeze({...e})));return this.metadata.set(t,{generation:this.generation,restored:e.length===0}),t}record(e){this.historyLimit!==0&&(this.history.push(e),this.history.length>this.historyLimit&&this.history.shift())}registerExternalPlacements(e){let t=new Set(this.itemOrder);[...e].sort((e,t)=>e.index-t.index).forEach(({index:e,item:n})=>{t.has(n.postId)||(this.itemOrder.splice(Math.min(e,this.itemOrder.length),0,n.postId),t.add(n.postId))})}removeFromHistory(e){let t=this.history.indexOf(e);t>=0&&this.history.splice(t,1)}restoreOrderedPlacements(e){let t=new Set(this.state.items.map(({postId:e})=>e)),n=e.map(({item:e})=>e).filter(({postId:e})=>!t.has(e));if(n.length===0)return!1;let r=new Map(this.itemOrder.map((e,t)=>[e,t]));return this.state.items=[...this.state.items,...n].sort((e,t)=>(r.get(e.postId)??2**53-1)-(r.get(t.postId)??2**53-1)),!0}},Rn=class{forward=null;forwardPromise=null;forwardVersion=0;state;constructor(e){this.options=e,this.state=e.state}start(e,t,n){this.forward={item:n,postIndex:t,token:e,version:++this.forwardVersion},this.state.reelForward={error:null,status:`loading`},this.state.reelForwardIndex=t,this.state.reelForwardItem=n,this.startForwardRequest()}cancel(e){if(this.forward?.token!==e||this.state.reelForward.status===`idle`)return null;let t=this.forward.item;return this.forwardVersion+=1,this.forward=null,this.clearState(),t}reset(){this.forwardVersion+=1,this.forward=null,this.forwardPromise=null,this.clearState()}retry(){return!this.forward||this.state.reelForward.status===`idle`?Promise.resolve():(this.state.nextPageError=null,this.state.reelForward={error:null,status:`loading`},this.startForwardRequest())}clearState(){this.state.reelForward={error:null,status:`idle`},this.state.reelForwardIndex=null,this.state.reelForwardItem=null}startForwardRequest(){if(this.forwardPromise)return this.forwardPromise;let e=this.loadForward();return this.forwardPromise=e,e.finally(()=>{this.forwardPromise===e&&(this.forwardPromise=null,this.forward&&this.state.reelForward.status===`loading`&&this.startForwardRequest())})}async loadForward(){let e=this.forward;if(e)for(;this.forward===e&&e.version===this.forwardVersion;){let t=this.state.items[e.postIndex];if(t){this.forward=null,this.clearState(),this.options.onActivate(t.postId);return}if(this.state.nextPageError){this.state.reelForward={error:this.state.nextPageError,status:`error`};return}let n=this.state.next,r=this.state.items.length;if(await this.options.replenishAfterRemoval(),this.state.nextPageError){this.state.reelForward={error:this.state.nextPageError,status:`error`};return}if(!this.state.items[e.postIndex]){if(this.state.next===null){this.state.reelForward={error:null,status:`end`};return}if(this.state.next===n&&this.state.items.length===r){this.state.reelForward={error:Error(`Vibe could not advance while page loading is unavailable.`),status:`error`};return}}}}},zn=class{generation=0;pending=Promise.resolve();constructor(e){this.options=e}prepareItems(e){return this.serialize(()=>this.preparePosts(e))}prepareMedia(e){return this.serialize(async()=>{let{state:n}=this.options;if(!this.isReelActive()||n.activeReelPostId!==e.postId)return;let r=n.items.find(({postId:t})=>t===e.postId);if(!r)return;let i=n.mediaIndices.get(e.postId)??0;if(e.mediaIndex===i){if(t(r).length>1){await this.options.transitionMedia(1);return}await this.preparePosts([e.postId])}})}reset(){this.generation+=1,this.pending=Promise.resolve()}async preparePosts(e){let{state:t}=this.options,n=t.activeReelPostId,r=new Set(e);if(!this.isReelActive()||n===null||!r.has(n))return;let i=this.generation,a=t.items.findIndex(({postId:e})=>e===n);if(a<0)return;let o=this.nextSurvivor(a,r);o&&i===this.generation&&t.activeReelPostId===n&&await this.options.transitionPost(o.postId)}isReelActive(){let{state:e}=this.options;return e.layout===`reel`||e.reelOrigin===`masonry`}nextSurvivor(e,t){if(!(e<0))return this.options.state.items.slice(e+1).find(({postId:e})=>!t.has(e))}serialize(e){let t=this.pending.then(e,e);return this.pending=t.catch(()=>void 0),t}};function Bn(e){let t=new Rn(e),n=new zn({state:e.state,transitionMedia:t=>e.surface()?.transitionActiveReelMedia(t)??Promise.resolve(!1),transitionPost:t=>e.surface()?.transitionActiveReelPost(t)??Promise.resolve(!1)});return{exactMediaRemoval:new Mn({onActivate:e.onActivate,onPostRemoved:t=>e.onItemsRemoved([t]),onPostRestored:t=>e.onItemsRestored([t]),reelForward:t,state:e.state}),itemRemoval:new Ln({historyLimit:e.historyLimit,onItemsRemoved:(n,r,i)=>{e.onItemsRemoved(r.map(({item:e})=>e.postId)),kn(e.state,r,i,e.onActivate,(e,r)=>t.start(n,e,r))},onRemovalRestored:n=>{e.onItemsRestored(n.map(({item:e})=>e.postId));let r=t.cancel(n);r&&e.onActivate(r.postId)},prepareRemoval:e=>n.prepareItems(e),startRemoval:(t,n)=>e.surface()?.startItemRemoval(t,n)??0,state:e.state}),reelForward:t,reelRemoval:n}}var Vn=1.5;function Hn(e){let t=Math.min(e.screenWidth,e.screenHeight);if(t>0&&t<600)return!0;let n=Math.min(e.viewportWidth,e.viewportHeight),r=t>=n*Vn;return!e.hasHover&&n>0&&n<600&&r}function Un(e){return Hn(e)?`reel`:`masonry`}function Wn(e){let t=e.ownerDocument.defaultView,n=e.ownerDocument.documentElement;return{hasHover:typeof t?.matchMedia==`function`&&t.matchMedia(`(hover: hover)`).matches,screenHeight:t?.screen.height??0,screenWidth:t?.screen.width??0,viewportHeight:n.clientHeight,viewportWidth:n.clientWidth}}function Gn(e){return Hn(Wn(e))}function Kn(e){return Un(Wn(e))}var qn=class{layoutMode;resizeObserver=null;target=null;constructor(e,t,n){this.state=t,this.onFeedLayout=n,this.layoutMode=e}mount(e){this.target=e,this.handleResponsiveLayout();let t=e.ownerDocument.defaultView;t?.addEventListener(`resize`,this.handleResponsiveLayout);let n=t?.ResizeObserver??globalThis.ResizeObserver;n!==void 0&&(this.resizeObserver=new n(this.handleResponsiveLayout),this.resizeObserver.observe(e))}destroy(){this.target?.ownerDocument.defaultView?.removeEventListener(`resize`,this.handleResponsiveLayout),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.target=null}setLayout(e){e!==this.layoutMode&&(this.layoutMode=e,e===`responsive`?this.handleResponsiveLayout():this.applyLayout(e))}applyLayout(e){e!==this.state.layout&&(e===`masonry`&&(this.state.activeReelPostId=null,this.onFeedLayout()),this.state.reelOrigin=null,this.state.layout=e)}handleResponsiveLayout=()=>{if(!this.target)return;let e=Kn(this.target);this.state.phoneMode=Gn(this.target),this.state.reelInfoSheetOverlay=this.state.phoneMode,this.state.reelMediaSource=e===`reel`?`preview`:`original`,this.layoutMode===`responsive`&&this.applyLayout(e)}},Jn=class{routedReelPostId=null;reelRouteIsActive=!1;constructor(e,t){this.options=e,this.state=t}syncFeed(){if(!this.options||!this.reelRouteIsActive)return;this.reelRouteIsActive=!1,this.routedReelPostId=null;let e=typeof this.options.feed==`function`?this.options.feed():this.options.feed;this.options.router.replace(e)}syncReel(e){if(!this.options)return;let t=this.state.items.findIndex(t=>t.postId===e),n=this.state.items[t];if(!n||this.reelRouteIsActive&&this.routedReelPostId===e)return;let r=this.options.reel({index:t,item:n,loadedCount:this.state.items.length,origin:this.state.reelOrigin??`reel`,total:this.state.total});if(r===null)return;let i=this.reelRouteIsActive?`replace`:`push`;this.reelRouteIsActive=!0,this.routedReelPostId=e,this.options.router[i](r)}},Yn=class{app=null;autoScroll;autofillController;abortController=null;pendingRequest=null;requestVersion=0;restoreController=null;responsiveLayout;routing;fillController;exactMediaRemoval;itemRemoval;removalReconciliation;reelForward;reelRemoval;surface=null;stopStateWatcher=null;lastLoadedCursor=null;notificationItems;state;constructor(t){this.options=t,Cn(t);let n=t.layout??`masonry`;this.state=(0,e.reactive)(bn(t,n)),this.lastLoadedCursor=t.initialPage?_t(t.initialPage):null,this.notificationItems=a(this.state),this.autoScroll=new Ut({getScrollElement:()=>this.surface?.getAutoScrollElement()??null,state:this.state.autoScroll}),this.autofillController=new Lt({cancelRequest:()=>this.cancelRequest(),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:t.autofill,state:this.state}),this.removalReconciliation=new On(t),this.removalReconciliation.recordInitialPage(t.initialPage),this.fillController=new dn({fill:t.fill,loadPage:t.loadPage?e=>this.loadFilteredPage(e):void 0,needsFrontendPreparation:()=>this.removalReconciliation.needsReconciliation(this.state.items),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),prepareFrontend:({isCurrent:e,onDelayChange:n,signal:r})=>fn({controller:this.removalReconciliation,isCurrent:e,loadPage:t.loadPage,onDelayChange:n,setLastCursor:e=>this.setCurrentCursor(e),signal:r,state:this.state}),state:this.state}),this.routing=new Jn(t.routing,this.state);let r=Bn({historyLimit:t.removalHistoryLimit,onActivate:e=>this.setActiveReelPost(e),onItemsRemoved:e=>this.removalReconciliation.remove(e),onItemsRestored:e=>this.removalReconciliation.restore(e),replenishAfterRemoval:()=>this.replenishAfterRemoval(),state:this.state,surface:()=>this.surface});this.exactMediaRemoval=r.exactMediaRemoval,this.itemRemoval=r.itemRemoval,this.reelForward=r.reelForward,this.reelRemoval=r.reelRemoval,this.responsiveLayout=new qn(n,this.state,()=>{this.routing.syncFeed()}),this.startStateNotifications()}async mount(){if(this.app)throw Error(`Vibe is already mounted.`);this.startStateNotifications();let t=wn(this.options.target);this.responsiveLayout.mount(t),this.app=(0,e.createApp)(ft,{canRetryEnd:!!this.options.loadPage,cardFooter:this.options.cardFooter,cardHeader:this.options.cardHeader,feedFooter:this.options.feedFooter,feedFooterActions:pn(this),mediaCard:this.options.mediaCard,masonry:this.options.masonry,onMediaReady:this.options.onMediaReady,onMediaVisible:this.options.onMediaVisible,onReelMediaChange:this.options.onReelMediaChange,reelInfoSheet:this.options.reelInfoSheet,state:this.state,onActiveReelChange:e=>{this.state.reelForward.status===`idle`&&this.setActiveReelPost(e)},onCloseReel:()=>this.closeMasonryReel(),onLoadMore:()=>{this.loadNext()},onOpenReel:e=>this.openMasonryReel(e),onReelInfoSheetChange:e=>this.setReelInfoSheet(e),onRetryEnd:()=>{this.retryEnd()},onRetryForward:()=>{this.retryReelForward()}}),this.surface=this.app.mount(t),this.autoScroll.mount(),await Jt(this.options.restoreBacklog,e=>this.appendPage(e),e=>{this.restoreController=e}),!this.options.initialPage&&this.state.items.length===0?await this.reload():this.options.autofill&&this.state.autofill.status===`idle`&&!this.fillController.isActive()&&!this.state.loadMoreLocked&&await this.startInitialAutofill()}destroy(){this.restoreController?.abort(),this.restoreController=null,this.autoScroll.destroy(),this.fillController.destroy(),this.cancelRequest(),this.reelForward.reset(),this.reelRemoval.reset(),this.exactMediaRemoval.reset(),this.itemRemoval.destroy(),this.removalReconciliation.reset(),this.responsiveLayout.destroy(),this.stopStateWatcher?.(),this.stopStateWatcher=null,this.app?.unmount(),this.app=null,this.surface=null}getState(){return o(this.state)}removeMedia(e){return this.exactMediaRemoval.remove(e)}removeMediaAnimated(e){return this.reelRemoval.prepareMedia(e).then(()=>this.exactMediaRemoval.remove(e))}removeItems(e,t){return this.itemRemoval.remove(e,t)}restoreItems(e){this.itemRemoval.restoreItems(e)}restoreMediaRemoval(e){return this.exactMediaRemoval.restore(e)}restoreRemoval(e){return this.itemRemoval.restoreRemoval(e)}retryReelForward(){return this.reelForward.retry()}retryFill(){return this.fillController.retry(this.removalReconciliation.hasPendingSession())}undoLastRemoval(){return this.itemRemoval.undoLast()}nextReelMediaItem(){return this.surface?.changeActiveReelMedia(1)??!1}previousReelMediaItem(){return this.surface?.changeActiveReelMedia(-1)??!1}nextReelPost(){return this.surface?.moveActiveReelPost(1)??!1}previousReelPost(){return this.surface?.moveActiveReelPost(-1)??!1}navigateToReelItem(e){return this.surface?.navigateToReelItem(e)??`reel-inactive`}pauseAutoScroll(){this.autoScroll.setPaused(!0)}resumeAutoScroll(){this.autoScroll.setPaused(!1)}setAutoScroll(e,t){this.autoScroll.setEnabled(e,t)}setAutoScrollSpeed(e){this.autoScroll.setSpeed(e)}applyAutofillUpdate(e){let t=Kt(this.options.autofill,this.state,e);return t&&this.autofillController.syncCountdown(),t}cancelAutofill(){return this.autofillController.cancel()}async cancelLoading(){if(this.state.loadMoreLocked=!1,this.fillController.isActive()){await this.cancelFill();return}if(Nt(this.state.autofill)){await this.cancelAutofill();return}this.cancelRequest()}applyFillUpdate(e){return this.fillController.applyUpdate(e)}cancelFill(){return this.fillController.cancel()}async fill(e){if(!this.state.loadMoreLocked){if(this.pendingRequest||Nt(this.state.autofill))throw Error(`Vibe cannot fill while another page operation is active.`);await this.fillController.start(e)}}restoreAutofillSession(e){let t=qt(this.options.autofill,this.state,e);return t&&this.autofillController.syncCountdown(),t}restoreFillSession(e){return this.fillController.restoreSession(e)}loadNext(){return this.startLoadMore(()=>this.loadNextSequence())}appendPage(e){vt(e,this.state,this.removalReconciliation,e=>this.setCurrentCursor(e))}replenishAfterRemoval(){return this.startLoadMore(()=>this.replenishAfterRemovalSequence())}async startLoadMore(e){if(this.pendingRequest)return this.pendingRequest;if(this.state.loadMoreLocked||Nt(this.state.autofill)||this.fillController.isActive()||!this.options.loadPage||this.state.next===null&&!this.removalReconciliation.needsReconciliation(this.state.items))return;this.state.isLoadingMore=!0,this.state.nextPageError=null;let t=e();return this.pendingRequest=t,t.finally(()=>{this.pendingRequest===t&&(this.pendingRequest=null),this.state.isLoadingMore=!1})}async refresh(){return this.replaceFeed(this.lastLoadedCursor,`refresh`)}async reload(){return this.replaceFeed(null,`reload`)}async replaceFeed(e,t){if(!this.options.loadPage)throw Error(`Vibe cannot ${t} without loadPage.`);return Nt(this.state.autofill)&&await this.cancelAutofill(),this.fillController.isActive()&&await this.cancelFill(),this.cancelRequest(),this.state.autofill=Mt(this.options.autofill,void 0,!1),this.fillController.reset(),this.reelForward.reset(),this.reelRemoval.reset(),this.exactMediaRemoval.reset(),this.itemRemoval.reset(),this.removalReconciliation.reset(),this.state.error=null,this.state.current=null,this.state.isLoading=!0,this.state.items=[],this.state.next=null,this.state.nextPageError=null,this.state.total=null,this.startRequest(e,!1)}async loadFilteredPage(e){let t=this.options.loadPage;if(!t)throw Error(`Vibe cannot load a page without loadPage.`);let n=pt(await t(e));return{...n,items:this.removalReconciliation.filterItems(n.items)}}async loadNextSequence(){this.removalReconciliation.needsReconciliation(this.state.items)&&!await this.reconcileBeforeNext()||this.state.loadMoreLocked||this.state.next!==null&&await this.fetchPage(this.state.next,!0)}async replenishAfterRemovalSequence(){let e=this.state.items.length;this.removalReconciliation.needsReconciliation(this.state.items)&&(!await this.reconcileBeforeNext()||this.state.items.length>e)||this.state.loadMoreLocked||this.state.next===null||await this.fetchPage(this.state.next,!0)}async reconcileBeforeNext(){let e=this.options.loadPage;if(!e)return!1;let t=++this.requestVersion,n=new AbortController;this.abortController=n;try{let r=await fn({controller:this.removalReconciliation,isCurrent:()=>t===this.requestVersion,loadPage:e,onDelayChange:()=>void 0,setLastCursor:e=>this.setCurrentCursor(e),signal:n.signal,state:this.state});return t===this.requestVersion&&r===`complete`}catch(e){return!n.signal.aborted&&t===this.requestVersion&&(this.state.nextPageError=e),!1}finally{this.abortController===n&&(this.abortController=null)}}async retryEnd(){if(this.pendingRequest)return this.pendingRequest;if(!this.state.loadMoreLocked&&!(Nt(this.state.autofill)||this.fillController.isActive())&&!(this.state.next!==null||!this.options.loadPage))return this.state.isLoadingMore=!0,this.state.nextPageError=null,this.startRequest(this.lastLoadedCursor,!0)}setInfiniteScroll(t){this.state.infiniteScroll=t,t&&(0,e.nextTick)(()=>this.surface?.loadIfNearBottom())}setLoadMoreLocked(t){if(this.state.loadMoreLocked!==t&&(this.state.loadMoreLocked=t,!t)){if(this.state.fill.status===`paused`&&this.state.fill.target){this.fillController.resume(this.removalReconciliation.hasPendingSession());return}if(this.state.autofill.status===`paused`||this.removalReconciliation.hasPendingSession()){let e=this.pendingRequest;e?e.finally(()=>{this.loadNext()}):this.loadNext()}else this.state.infiniteScroll&&(0,e.nextTick)(()=>this.surface?.loadIfNearBottom())}}setTotal(e){if(e!==null&&(!Number.isInteger(e)||e<0))throw TypeError(`Vibe total must be a non-negative integer or null.`);this.state.total=e}setReelAutoAdvance(e){_n(this.state.reelAutoAdvance,e)}setReelInfoSheet(e){yn(this.state.reelInfoSheet,this.options.reelInfoSheet,e)}setLayout(e){this.responsiveLayout.setLayout(e)}closeMasonryReel(){this.state.reelOrigin===`masonry`&&(this.state.activeReelPostId=null,this.state.reelOrigin=null,this.routing.syncFeed())}openMasonryReel(e){this.state.layout===`masonry`&&this.state.items.some(t=>t.postId===e)&&(this.state.activeReelPostId=e,this.state.reelOrigin=`masonry`,this.routing.syncReel(e))}setActiveReelPost(e){this.state.layout!==`reel`&&this.state.reelOrigin!==`masonry`||(this.state.activeReelPostId=e,this.routing.syncReel(e))}cancelRequest(){this.autofillController.clearCountdown(),this.requestVersion+=1,this.abortController?.abort(),this.abortController=null,this.pendingRequest=null,this.state.isLoading=!1,this.state.isLoadingMore=!1}async fetchPage(e,t){if(!this.options.loadPage)return;let n=++this.requestVersion,r=new AbortController;this.abortController=r,await Tn({append:t,autofillController:this.autofillController,cursor:e,isCurrent:()=>n===this.requestVersion,loadPage:e=>this.loadFilteredPage(e),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:this.options,signal:r.signal,state:this.state}),n===this.requestVersion&&(this.abortController=null)}startRequest(e,t){let n=this.fetchPage(e,t);return this.pendingRequest=n,n.finally(()=>{this.pendingRequest===n&&(this.pendingRequest=null)})}startInitialAutofill(){let e=++this.requestVersion,t=new AbortController,n=this.autofillController.beginCycle();this.abortController=t,this.state.isLoadingMore=!0;let r=Yt({cycleId:n,isCurrent:()=>e===this.requestVersion,onCollection:t=>this.autofillController.captureCollection(t,e===this.requestVersion),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:this.options,signal:t.signal,state:this.state}).catch(n=>{t.signal.aborted||e!==this.requestVersion||(this.autofillController.commitCollection(),this.state.autofill.error=n,this.state.autofill.status=`error`,this.state.nextPageError=n)}).finally(()=>{e===this.requestVersion&&(this.autofillController.clearCollection(),this.autofillController.syncCountdown(),this.abortController=null,this.state.isLoadingMore=!1,this.pendingRequest===r&&(this.pendingRequest=null))});return this.pendingRequest=r,r}startStateNotifications(){let t=this.options.onStateChange;!t||this.stopStateWatcher||(t(o(this.state,this.notificationItems.value)),this.stopStateWatcher=(0,e.watch)(this.state,()=>t(o(this.state,this.notificationItems.value)),{deep:!0,flush:`post`}))}setCurrentCursor(e){this.lastLoadedCursor=e,this.state.current=e}};function Xn(e){return new Yn(e)}exports.createVibe=Xn;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`);function t(e){return{height:e.height,src:e.src,type:e.type,width:e.width}}function n(e,n){return n===`preview`?{...e.preview,type:e.preview.type??e.type}:n===`mobile`&&e.mobile?{...e.mobile,type:e.mobile.type??e.type}:t(e)}function r(e){return[e,...e.items]}function i(e,t){return Math.min(e.items.length,Math.max(0,t))}function a(e,t){return r(e)[i(e,t)]??e}function o(e,t){return`${String(e)}:${t}`}function s(t){return(0,e.computed)(()=>Object.freeze([...t.items]))}function c(e,t=[...e.items]){return{activeReelPostId:e.activeReelPostId,autoScroll:{...e.autoScroll},autofill:{...e.autofill},current:e.current,error:e.error,fill:{...e.fill,target:e.fill.target?{...e.fill.target}:null},infiniteScroll:e.infiniteScroll,isLoading:e.isLoading,isLoadingMore:e.isLoadingMore,items:t,layout:e.layout,lifecycle:e.isLoading||e.isLoadingMore?`loading`:e.error||e.nextPageError?`error`:`loaded`,loadMoreLocked:e.loadMoreLocked,next:e.next,nextPageError:e.nextPageError,phoneMode:e.phoneMode,reelAutoAdvance:{...e.reelAutoAdvance},reelForward:{...e.reelForward},reelInfoSheet:{...e.reelInfoSheet},reelOrigin:e.reelOrigin,total:e.total}}var l={key:0,class:`gallery-footer`},u={key:0,class:`load-more-status`,role:`status`},d=[`disabled`],f={key:2,class:`end-feed`},p=[`disabled`],m=(0,e.defineComponent)({__name:`GalleryFooter`,props:{canRetryEnd:{type:Boolean},hasError:{type:Boolean},hasNext:{type:Boolean},isLoading:{type:Boolean},loadMoreLocked:{type:Boolean},showLoadMore:{type:Boolean}},emits:[`loadMore`,`retryEnd`],setup(t,{emit:n}){let r=t,i=n;function a(){r.loadMoreLocked||(r.hasNext?i(`loadMore`):i(`retryEnd`))}return(n,r)=>t.isLoading||t.hasError||t.hasNext&&t.showLoadMore||!t.hasNext&&t.canRetryEnd?((0,e.openBlock)(),(0,e.createElementBlock)(`footer`,l,[t.isLoading?((0,e.openBlock)(),(0,e.createElementBlock)(`p`,u,` Loading more… `)):t.hasError||t.hasNext&&t.showLoadMore?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:1,"data-test":`load-more`,class:`load-more-button`,type:`button`,disabled:t.loadMoreLocked,onClick:a},(0,e.toDisplayString)(t.hasError?`Try again`:t.loadMoreLocked?`Loading paused`:`Load more`),9,d)):((0,e.openBlock)(),(0,e.createElementBlock)(`div`,f,[r[1]||=(0,e.createElementVNode)(`p`,{class:`end-feed-message`,role:`status`},` You've reached the end. `,-1),(0,e.createElementVNode)(`button`,{"data-test":`retry-end`,class:`load-more-button`,type:`button`,disabled:t.loadMoreLocked,onClick:r[0]||=e=>n.$emit(`retryEnd`)},` Check for more `,8,p)]))])):(0,e.createCommentVNode)(``,!0)}}),h=(0,e.defineComponent)({__name:`FeedFooter`,props:{actions:{},canRetryEnd:{type:Boolean},feedFooter:{},hasError:{type:Boolean},hasNext:{type:Boolean},isLoading:{type:Boolean},loadMoreLocked:{type:Boolean},showLoadMore:{type:Boolean},state:{}},emits:[`loadMore`,`retryEnd`],setup(t,{emit:n}){let r=t,i=n;function a(){r.actions?.cancelAutofill()}function o(){r.actions?.retry()}return(n,r)=>t.feedFooter&&t.actions&&t.state?((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.feedFooter.component),{key:0,actions:t.actions,"can-retry-end":t.canRetryEnd,"show-load-more":t.showLoadMore,state:t.state,onAutofillCancel:a,onLoadMore:r[0]||=e=>i(`loadMore`),onRetry:o,onRetryEnd:r[1]||=e=>i(`retryEnd`)},null,40,[`actions`,`can-retry-end`,`show-load-more`,`state`])):((0,e.openBlock)(),(0,e.createBlock)(m,{key:1,"can-retry-end":t.canRetryEnd,"has-error":t.hasError,"has-next":t.hasNext,"is-loading":t.isLoading,"load-more-locked":t.loadMoreLocked,"show-load-more":t.showLoadMore,onLoadMore:r[2]||=e=>i(`loadMore`),onRetryEnd:r[3]||=e=>i(`retryEnd`)},null,8,[`can-retry-end`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`show-load-more`]))}}),g=[`role`],_={class:`gallery-status`},v=(0,e.defineComponent)({__name:`FeedStatus`,props:{actions:{},canRetryEnd:{type:Boolean},feedFooter:{},state:{}},emits:[`loadMore`,`retryEnd`],setup(t,{emit:n}){let r=t,i=n;return(n,a)=>((0,e.openBlock)(),(0,e.createElementBlock)(`main`,{class:`gallery-shell`,role:r.state.error?`alert`:r.state.isLoading?`status`:void 0},[(0,e.createElementVNode)(`p`,_,[r.state.error?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:0},[(0,e.createTextVNode)(` Unable to load media. `)],64)):r.state.isLoading?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:1},[(0,e.createTextVNode)(` Loading media… `)],64)):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:2},[(0,e.createTextVNode)(` No media found. `)],64))]),t.feedFooter?((0,e.openBlock)(),(0,e.createBlock)(h,{key:0,actions:t.actions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,"has-error":!!t.state.nextPageError,"has-next":t.state.next!==null,"is-loading":t.state.isLoadingMore,"load-more-locked":t.state.loadMoreLocked,"show-load-more":``,state:t.state,onLoadMore:a[0]||=e=>i(`loadMore`),onRetryEnd:a[1]||=e=>i(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`state`])):(0,e.createCommentVNode)(``,!0)],8,g))}});function y(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=240}function b(e){let t=e.preview.width??e.width,n=e.preview.height??e.height;return!t||!n||t<=0||n<=0?1:n/t}function x(e){return e.reduce((t,n,r)=>n<e[t]?r:t,0)}function S(e){return Math.max(0,e.containerHeight)+Math.max(0,e.gap)}function C(e,t,n){if(t<=0||e.length===0)return{columns:0,height:0,items:[]};let r=Math.max(0,n.gap),i=Number.isFinite(n.additionalHeight)?Math.max(0,n.additionalHeight??0):0,a=Math.max(1,n.minColumnWidth),o=Math.max(1,Math.floor((t+r)/(a+r))),s=(t-r*(o-1))/o,c=Array.from({length:o},()=>0),l=e.map(e=>{let t=x(c),n=s*b(e)+i,a={x:t*(s+r),y:c[t],width:s,height:n};return c[t]+=n+r,a});return{columns:o,height:Math.max(...c)-r,items:l}}function w(e,t){let n=new Map;return e.forEach((e,r)=>{let i=n.get(e.x)??[];i.push({bottom:e.y+e.height,index:t?.[r]??r,top:e.y}),n.set(e.x,i)}),{columns:[...n.entries()].sort(([e],[t])=>e-t).map(([,e])=>e.sort((e,t)=>e.top-t.top||e.index-t.index))}}function T(e,t){let n=0,r=0,i=e.length;for(;r<i;){let a=Math.floor((r+i)/2);n+=1,e[a].bottom<t?r=a+1:i=a}return{index:r,inspected:n}}function E(e,t){let n=Math.max(0,t.overscan),r=t.scrollTop-n,i=t.scrollTop+Math.max(0,t.viewportHeight)+n,a=[],o=0;return e.columns.forEach(e=>{let t=T(e,r);o+=t.inspected;for(let n=t.index;n<e.length;n+=1){let t=e[n];if(o+=1,t.top>i)break;a.push(t.index)}}),{indices:a.sort((e,t)=>e-t),inspected:o}}function D(e){return e?.minColumnWidth??240}function O(e,t){let n=e?.overscan?.minimumPx??800,r=e?.overscan?.viewportMultiplier??1.5,i=Math.max(n,t*r),a=e?.overscan?.maximumPx;return a===void 0?i:Math.min(i,a)}function k(e){if(e?.minColumnWidth!==void 0&&(!Number.isFinite(e.minColumnWidth)||e.minColumnWidth<=0))throw TypeError(`Vibe masonry minColumnWidth must be a positive number.`);let t=e?.overscan;if(t){for(let[e,n]of[[`maximumPx`,t.maximumPx],[`minimumPx`,t.minimumPx],[`viewportMultiplier`,t.viewportMultiplier]])if(n!==void 0&&(!Number.isFinite(n)||n<0))throw TypeError(`Vibe masonry overscan ${e} must be a non-negative number.`);if(t.maximumPx!==void 0&&t.minimumPx!==void 0&&t.maximumPx<t.minimumPx)throw TypeError(`Vibe masonry overscan maximumPx must be greater than or equal to minimumPx.`)}}function A(e,t,n){return Math.min(n,Math.max(t,e))}function j({contentSize:e,minimumThumbSize:t,scrollPosition:n,trackSize:r,viewportSize:i}){let a=Math.max(0,e),o=Math.max(0,r),s=Math.max(0,i),c=Math.max(0,a-s);if(!(c>0&&o>0))return{maximumScrollPosition:c,scrollable:!1,thumbOffset:0,thumbSize:o,thumbTravel:0};let l=A(s/a*o,Math.min(Math.max(0,t),o),o),u=Math.max(0,o-l);return{maximumScrollPosition:c,scrollable:!0,thumbOffset:u*(A(n,0,c)/c),thumbSize:l,thumbTravel:u}}var M=[`aria-hidden`],N=[`aria-controls`,`aria-valuemax`,`aria-valuenow`,`tabindex`],P=32,F=40,I=120,L=(0,e.defineComponent)({__name:`GalleryScrollbar`,props:{contentSize:{},controlsId:{},scrollElement:{},suspended:{type:Boolean}},setup(t){let n=t,r={maximumScrollPosition:0,scrollable:!1,thumbOffset:0,thumbSize:0,thumbTravel:0},i=(0,e.shallowRef)(null),a=(0,e.shallowRef)(r),o=(0,e.shallowRef)(!1),s=(0,e.shallowRef)(!1),c=(0,e.shallowRef)(!1),l=null,u=0,d=0,f=null,p=null,m=null,h=null,g=!1,_=null,v=(0,e.computed)(()=>a.value.scrollable&&!n.suspended),y=(0,e.computed)(()=>({height:`${a.value.thumbSize}px`,transform:`translate3d(0, ${a.value.thumbOffset}px, 0)`}));function b(){f!==null&&clearTimeout(f),f=setTimeout(()=>{f=null,o.value||(s.value=!1)},I)}function x(){s.value=!0,b()}function S(){let e=n.scrollElement,t=i.value;return!e||!t?r:j({contentSize:e.scrollHeight,minimumThumbSize:P,scrollPosition:e.scrollTop,trackSize:t.clientHeight,viewportSize:e.clientHeight})}function C(e){if(o.value&&e!==`scroll`){g=!0;return}if(o.value){let e=n.scrollElement;if(!e||a.value.maximumScrollPosition<=0)return;let t=Math.min(1,Math.max(0,e.scrollTop/a.value.maximumScrollPosition));a.value={...a.value,thumbOffset:a.value.thumbTravel*t};return}a.value=S(),!(c.value||p!==null)&&(p=requestAnimationFrame(()=>{p=null,c.value=!0}))}function w(){x(),C(`scroll`)}function T(e){let t=n.scrollElement;t&&(t.scrollTop=Math.min(a.value.maximumScrollPosition,Math.max(0,e)),C(`scroll`))}function E(e){if(!v.value||e.target!==e.currentTarget)return;let t=i.value;if(!t||a.value.thumbTravel<=0)return;e.preventDefault(),x();let n=e.clientY-t.getBoundingClientRect().top-a.value.thumbSize/2;T(Math.min(1,Math.max(0,n/a.value.thumbTravel))*a.value.maximumScrollPosition)}function D(e){v.value&&(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture?.(e.pointerId),l=e.pointerId,u=e.clientY,d=n.scrollElement?.scrollTop??0,o.value=!0,s.value=!0,f!==null&&clearTimeout(f),f=null)}function O(e){if(!o.value||e.pointerId!==l||(e.preventDefault(),a.value.thumbTravel<=0))return;let t=(e.clientY-u)/a.value.thumbTravel*a.value.maximumScrollPosition;T(d+t)}function k(e){!o.value||e.pointerId!==l||(e.currentTarget.releasePointerCapture?.(e.pointerId),l=null,o.value=!1,g&&(g=!1,C(`content`)),b())}function A(e){if(!v.value)return;let t=n.scrollElement?.clientHeight??0,r=n.scrollElement?.scrollTop??0,i=e.key===`ArrowUp`?r-F:e.key===`ArrowDown`?r+F:e.key===`PageUp`?r-t:e.key===`PageDown`?r+t:e.key===`Home`?0:e.key===`End`?a.value.maximumScrollPosition:null;i!==null&&(e.preventDefault(),x(),T(i))}function L(e){if(h?.disconnect(),!(typeof ResizeObserver>`u`)){h=new ResizeObserver(()=>C(`content`));for(let t of e.children)h.observe(t)}}return(0,e.watch)(()=>n.scrollElement,(t,n)=>{n?.removeEventListener(`scroll`,w),m?.disconnect(),m=null,h?.disconnect(),h=null,_?.disconnect(),_=null,t?.addEventListener(`scroll`,w,{passive:!0}),t&&typeof ResizeObserver<`u`&&(_=new ResizeObserver(()=>{x(),C(`resize`)}),_.observe(t),L(t)),t&&typeof MutationObserver<`u`&&(m=new MutationObserver(()=>{L(t),C(`content`)}),m.observe(t,{childList:!0})),(0,e.nextTick)(()=>C(`resize`))},{immediate:!0}),(0,e.watch)(()=>n.contentSize,()=>{(0,e.nextTick)(()=>C(`content`))}),(0,e.onBeforeUnmount)(()=>{n.scrollElement?.removeEventListener(`scroll`,w),m?.disconnect(),h?.disconnect(),_?.disconnect(),f!==null&&clearTimeout(f),p!==null&&cancelAnimationFrame(p)}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{ref_key:`trackElement`,ref:i,class:(0,e.normalizeClass)([`gallery-scrollbar`,{"gallery-scrollbar--dragging":o.value,"gallery-scrollbar--interacting":s.value,"gallery-scrollbar--ready":c.value,"gallery-scrollbar--visible":v.value}]),"aria-hidden":!v.value||void 0,onPointerdown:E},[(0,e.createElementVNode)(`div`,{class:`gallery-scrollbar-thumb`,"aria-controls":t.controlsId,"aria-label":`Media gallery scroll position`,"aria-orientation":`vertical`,"aria-valuemax":Math.round(a.value.maximumScrollPosition),"aria-valuemin":`0`,"aria-valuenow":Math.round(t.scrollElement?.scrollTop??0),role:`scrollbar`,style:(0,e.normalizeStyle)(y.value),tabindex:v.value?0:-1,onKeydown:A,onPointercancel:k,onPointerdown:D,onPointermove:O,onPointerup:k},null,44,N)],42,M))}}),ee=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},R=e=>e===``,z=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),B=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),V=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),H=e=>{let t=V(e);return t.charAt(0).toUpperCase()+t.slice(1)},U={xmlns:`http://www.w3.org/2000/svg`,width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"stroke-width":2,"stroke-linecap":`round`,"stroke-linejoin":`round`},W=({name:t,iconNode:n,absoluteStrokeWidth:r,"absolute-stroke-width":i,strokeWidth:a,"stroke-width":o,size:s=U.width,color:c=U.stroke,...l},{slots:u})=>(0,e.h)(`svg`,{...U,...l,width:s,height:s,stroke:c,"stroke-width":R(r)||R(i)||r===!0||i===!0?Number(a||o||U[`stroke-width`])*24/Number(s):a||o||U[`stroke-width`],class:z(`lucide`,l.class,...t?[`lucide-${B(H(t))}-icon`,`lucide-${B(t)}`]:[`lucide-icon`]),...!u.default&&!ee(l)&&{"aria-hidden":`true`}},[...n.map(t=>(0,e.h)(...t)),...u.default?[u.default()]:[]]),G=(t,n)=>(r,{slots:i,attrs:a})=>(0,e.h)(W,{...a,...r,iconNode:n,name:t},i),te=G(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),ne=G(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),K=G(`pause`,[[`rect`,{x:`14`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`kaeet6`}],[`rect`,{x:`5`,y:`3`,width:`5`,height:`18`,rx:`1`,key:`1wsw3u`}]]),q=G(`play`,[[`path`,{d:`M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z`,key:`10ikf1`}]]),re=G(`volume-2`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`path`,{d:`M16 9a5 5 0 0 1 0 6`,key:`1q6k2b`}],[`path`,{d:`M19.364 18.364a9 9 0 0 0 0-12.728`,key:`ijwkga`}]]),ie=G(`volume-x`,[[`path`,{d:`M11 4.702a.705.705 0 0 0-1.203-.498L6.413 7.587A1.4 1.4 0 0 1 5.416 8H3a1 1 0 0 0-1 1v6a1 1 0 0 0 1 1h2.416a1.4 1.4 0 0 1 .997.413l3.383 3.384A.705.705 0 0 0 11 19.298z`,key:`uqj9uw`}],[`line`,{x1:`22`,x2:`16`,y1:`9`,y2:`15`,key:`1ewh16`}],[`line`,{x1:`16`,x2:`22`,y1:`9`,y2:`15`,key:`5ykzw1`}]]),J={401:`Authentication required`,403:`Access forbidden`,404:`Preview not found`,419:`Session expired`,500:`Server error`};function ae(e){return e.match(/\/demo-errors\/(401|403|404|419|500)\//)?.[1]??`Error`}function oe(e){return J[ae(e)]??`Preview unavailable`}var se=(0,e.defineComponent)({__name:`CardRegion`,props:{index:{},item:{},layout:{},loadedCount:{},mediaIndex:{},mediaSource:{},placement:{},region:{},style:{},total:{}},setup(t){let n=t,o=(0,e.computed)(()=>i(n.item,n.mediaIndex)),s=(0,e.computed)(()=>r(n.item)),c=(0,e.computed)(()=>a(n.item,o.value)),l=(0,e.computed)(()=>({height:`${n.region.height}px`,paddingBlock:n.style?.paddingY===void 0?void 0:`${n.style.paddingY}px`,paddingInline:n.style?.paddingX===void 0?void 0:`${n.style.paddingX}px`})),u=(0,e.computed)(()=>n.style?.background??n.region.background);return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:(0,e.normalizeClass)([`media-card-region`,[`media-card-${t.placement}`,{"media-card-region--transparent":u.value===`transparent`}]]),style:(0,e.normalizeStyle)(l.value),onClick:r[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:r[1]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.region.component),{index:t.index,item:t.item,layout:t.layout,"loaded-count":t.loadedCount,"media-count":s.value.length,"media-index":o.value,"media-item":c.value,"media-source":t.mediaSource??`preview`,total:t.total},null,8,[`index`,`item`,`layout`,`loaded-count`,`media-count`,`media-index`,`media-item`,`media-source`,`total`]))],38))}}),ce=[`max`,`value`,`aria-valuetext`,`disabled`],le={key:0,class:`media-controls-row`},ue=[`aria-label`,`title`],de={class:`media-controls-audio`},fe=[`aria-label`,`title`],pe=[`value`,`aria-valuetext`],me={class:`media-control-time`,"aria-live":`off`},he=(0,e.defineComponent)({__name:`MediaControls`,props:{currentTime:{},duration:{},layout:{},muted:{type:Boolean},playing:{type:Boolean},volume:{}},emits:[`seek`,`toggleMute`,`togglePlayback`,`volumeChange`],setup(t,{emit:n}){let r=t,i=n;function a(e,t=1){return Number.isFinite(e)?Math.min(t,Math.max(0,e)):0}function o(e){let t=Math.floor(a(e,2**53-1)),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${r}:${String(i).padStart(2,`0`)}`}function s(e){return Number(e.target.value)}let c=(0,e.computed)(()=>Math.max(0,r.duration)),l=(0,e.computed)(()=>a(r.currentTime,c.value)),u=(0,e.computed)(()=>({"--media-range-progress":`${c.value>0?l.value/c.value*100:0}%`})),d=(0,e.computed)(()=>({"--media-range-progress":`${a(r.volume)*100}%`}));return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:(0,e.normalizeClass)([`media-controls`,`media-controls--${t.layout}`]),"aria-label":`Video controls`,onClick:r[4]||=(0,e.withModifiers)(()=>{},[`stop`]),onDblclick:r[5]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:r[6]||=(0,e.withModifiers)(()=>{},[`stop`]),onWheel:r[7]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createElementVNode)(`input`,{class:`media-control-range media-control-seek`,type:`range`,min:`0`,max:c.value||0,step:`0.1`,value:l.value,style:(0,e.normalizeStyle)(u.value),"aria-label":`Seek video`,"aria-valuetext":`${o(l.value)} of ${o(c.value)}`,disabled:c.value<=0,onInput:r[0]||=e=>i(`seek`,s(e))},null,44,ce),t.layout===`reel`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,le,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button media-control-playback`,"aria-label":t.playing?`Pause video`:`Play video`,title:t.playing?`Pause`:`Play`,onClick:r[1]||=e=>i(`togglePlayback`)},[t.playing?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(K),{key:0,size:18,fill:`currentColor`})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(q),{key:1,size:18,fill:`currentColor`}))],8,ue),(0,e.createElementVNode)(`div`,de,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button`,"aria-label":t.muted?`Unmute video`:`Mute video`,title:t.muted?`Unmute`:`Mute`,onClick:r[2]||=e=>i(`toggleMute`)},[t.muted||t.volume===0?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(ie),{key:0,size:18})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(re),{key:1,size:18}))],8,fe),(0,e.createElementVNode)(`input`,{class:`media-control-range media-control-volume`,type:`range`,min:`0`,max:`1`,step:`0.05`,value:t.volume,style:(0,e.normalizeStyle)(d.value),"aria-label":`Video volume`,"aria-valuetext":`${Math.round(t.volume*100)} percent`,onInput:r[3]||=e=>i(`volumeChange`,s(e))},null,44,pe)]),(0,e.createElementVNode)(`output`,me,(0,e.toDisplayString)(o(l.value))+` / `+(0,e.toDisplayString)(o(c.value)),1)])):(0,e.createCommentVNode)(``,!0)],34))}});function ge(t){let n=(0,e.computed)(()=>t.layout()!==`reel`||t.active()===!0),r=(0,e.computed)(()=>n.value?t.videoIsMuted.value:!0);function i(){if(!n.value){t.videoElement.value?.pause(),t.videoIsPlaying.value=!1;return}t.videoIsPlaying.value=!0}return(0,e.watch)(n,r=>{let i=t.videoElement.value;if(!r){i?.pause(),i&&(i.muted=!0),t.videoIsPlaying.value=!1;return}(0,e.nextTick)().then(async()=>{let e=t.videoElement.value;if(!(!e||!n.value)){e.muted=t.videoIsMuted.value;try{await e.play()}catch{t.videoIsPlaying.value=!1}}})}),{effectiveMuted:r,onPlaying:i,playbackAllowed:n}}var Y=/\.(aac|flac|m4a|mp3|mp4|mov|ogg|opus|wav|webm)$/i;function _e(e){try{return Y.test(new URL(e).pathname)}catch{return Y.test(e.split(`?`)[0]??e)}}function ve(e,t){return e===void 0?_e(t):e===`video`}function ye(t){let n=(0,e.computed)(()=>ve(t.mediaType(),t.mediaSource())),r=(0,e.computed)(()=>t.layout()===`masonry`&&t.fetchPriority()===`low`?`lazy`:`eager`),i=(0,e.computed)(()=>t.layout()===`reel`&&!t.active()?`none`:t.fetchPriority()===`high`?`auto`:t.layout()===`masonry`?`none`:`metadata`);return(0,e.watch)(i,(n,r)=>{r!==`none`||n===`none`||(0,e.nextTick)(()=>t.videoElement.value?.load())}),{imageLoading:r,mediaIsTimed:n,videoPreload:i}}function be(t){let n=(0,e.shallowRef)(null),r=(0,e.shallowRef)(null),i=(0,e.shallowRef)(0),a=(0,e.shallowRef)(0),o=(0,e.shallowRef)(!0),s=(0,e.shallowRef)(!1),c=null,l=!1,u=(0,e.computed)(()=>s.value?`error`:o.value?`loading`:t.previewState());function d(){c!==null&&clearTimeout(c),c=null}function f(e){return Number(e.currentTarget.dataset.sourceGeneration)===i.value}function p(){d(),c=setTimeout(()=>g(),15e3)}function m(e){e&&!f(e)||(d(),o.value=!1,s.value=!1,t.onReady(t.mediaIndex()))}function h(){let e=n.value;if(e?.complete){e.naturalWidth>0?m():g();return}let t=r.value;if(t&&t.readyState>=HTMLMediaElement.HAVE_METADATA){m();return}p()}function g(n){if(!(n&&!f(n))){if(d(),!n&&a.value===0){a.value=1,i.value+=1,o.value=!0,(0,e.nextTick)(h);return}o.value=!1,s.value=!0,t.onError(t.mediaIndex())}}function _(){a.value=0,s.value=!1,o.value=!0,i.value+=1,(0,e.nextTick)(h)}function v(e){f(e)&&o.value&&p()}return(0,e.watch)(t.identity,()=>{d(),i.value+=1,a.value=0,o.value=l||t.previewState()===`loading`,s.value=!1,l=!0,(0,e.nextTick)(h)},{immediate:!0}),(0,e.onBeforeUnmount)(d),{effectivePreviewState:u,failSourceAttempt:g,imageElement:n,markSourceReady:m,noteSourceActivity:v,retrySource:_,sourceGeneration:i,videoElement:r}}var xe=[`data-post-id`,`data-media-index`,`aria-hidden`,`aria-busy`,`inert`,`role`,`tabindex`],Se={class:`media-card-content`},Ce=[`data-media-direction`],we=[`data-media-index`],Te={key:0,"data-test":`media-loading`,class:`media-loading`,"aria-hidden":`true`},Ee=[`aria-label`],De={class:`media-error-code`},Oe=[`data-source-generation`,`src`,`width`,`height`,`autoplay`,`loop`,`muted`,`preload`],ke=[`data-source-generation`,`src`,`width`,`height`,`fetchpriority`,`loading`],Ae=[`aria-label`],je=[`aria-label`],Me=[`aria-label`],Ne=40,Pe=160,Fe=24,Ie=(0,e.defineComponent)({__name:`MediaCard`,props:{active:{type:Boolean},advanceOnMediaEnd:{type:Boolean},cardFooter:{},cardHeader:{},entering:{type:Boolean},fetchPriority:{},index:{},item:{},itemStyle:{},interactive:{type:Boolean},leaving:{type:Boolean},layout:{},loadedCount:{},mediaIndex:{},mediaCard:{},mediaSource:{},previewState:{},reelControlsTarget:{},stationaryReelControls:{type:Boolean},total:{}},emits:[`activate`,`ended`,`error`,`mediaChange`,`ready`],setup(t,{emit:o}){let s=t,c=null,l=0,u=!1,d=null,f=null,p=(0,e.shallowRef)(`next`),m=o;function h(e=!1,t=`pointer`){e&&m(`activate`,t)}let g=(0,e.computed)(()=>r(s.item)),_=(0,e.computed)(()=>i(s.item,s.mediaIndex)),v=(0,e.computed)(()=>a(s.item,_.value)),y=(0,e.computed)(()=>n(v.value,s.mediaSource??`preview`)),b=(0,e.computed)(()=>y.value.src),x=(0,e.computed)(()=>y.value.type),S=(0,e.computed)(()=>y.value.width),C=(0,e.computed)(()=>y.value.height),{effectivePreviewState:w,failSourceAttempt:T,imageElement:E,markSourceReady:D,noteSourceActivity:O,retrySource:k,sourceGeneration:A,videoElement:j}=be({identity:()=>`${s.item.postId}:${_.value}:${s.mediaSource??`preview`}:${b.value}:${x.value??``}`,mediaIndex:()=>_.value,onError:e=>m(`error`,e),onReady:e=>m(`ready`,e),previewState:()=>s.previewState}),M=(0,e.shallowRef)(0),N=(0,e.shallowRef)(0),P=(0,e.shallowRef)(s.mediaCard?.videoMuted??s.layout===`masonry`),F=(0,e.shallowRef)(!1),I=(0,e.shallowRef)(1),L=1,{effectiveMuted:ee,onPlaying:R,playbackAllowed:z}=ge({active:()=>s.active,layout:()=>s.layout,videoElement:j,videoIsMuted:P,videoIsPlaying:F}),B=(0,e.computed)(()=>s.interactive&&!!(s.cardHeader||s.cardFooter));function V(e){return e.detail===0?`keyboard`:`pointer`}function H(e,t){let n=g.value.length,r=(e+n)%n;r!==_.value&&(p.value=e<_.value?`previous`:`next`,m(`mediaChange`,r),t&&t.detail>0&&t.currentTarget?.blur())}function U(e,t,n){return t===1?e*16:t===2?e*n:e}function W(){l=0,u=!1,c!==null&&clearTimeout(c),c=null}function G(){c!==null&&clearTimeout(c),c=setTimeout(W,Pe)}function K(e){if(g.value.length<=1)return;let t=e.currentTarget?.clientWidth||1,n=U(e.deltaX,e.deltaMode,t);if(n===0||(e.preventDefault(),G(),u)||(l+=n,Math.abs(l)<Fe))return;let r=Math.sign(l);l=0,u=!0,H(_.value+r)}function q(e){let t=e.touches[0];s.layout!==`reel`||!t||(d=t.clientX,f=t.clientY)}function re(e){let t=e.changedTouches[0];if(d===null||f===null||!t)return;let n=d-t.clientX,r=f-t.clientY;d=null,f=null,!(Math.abs(n)<=Math.abs(r))&&(Math.abs(n)<Ne||H(_.value+Math.sign(n)))}let{imageLoading:ie,mediaIsTimed:J,videoPreload:ce}=ye({active:()=>s.active,fetchPriority:()=>s.fetchPriority,layout:()=>s.layout,mediaSource:()=>b.value,mediaType:()=>x.value,videoElement:j}),le=(0,e.computed)(()=>s.layout===`reel`&&s.stationaryReelControls===!0),ue=(0,e.computed)(()=>J.value&&w.value===`ready`&&(!le.value||!!(s.active&&s.reelControlsTarget))),de=(0,e.computed)(()=>`${s.item.postId}:${_.value}:${b.value}`);function fe(e){s.layout===`reel`&&(e.stopPropagation(),pe())}async function pe(){if(!(!j.value||!z.value)){if(F.value){j.value.pause();return}try{await j.value.play()}catch{F.value=!1}}}function me(e){return Number.isFinite(e)?Math.max(0,e):0}function Y(e){let t=e?.currentTarget??j.value;t&&(M.value=me(t.currentTime),N.value=me(t.duration),z.value&&(P.value=t.muted),I.value=t.volume,t.volume>0&&(L=t.volume))}function _e(e){Y(e),D(e)}function ve(){F.value=!1,m(`ended`,_.value)}function Ie(e){let t=j.value;!t||!Number.isFinite(e)||(t.currentTime=Math.min(me(t.duration),Math.max(0,e)),M.value=t.currentTime)}function Le(e){let t=j.value;if(!t||!Number.isFinite(e))return;let n=Math.min(1,Math.max(0,e));t.volume=n,t.muted=n===0,n>0&&(L=n),Y()}function Re(){let e=j.value;e&&(e.muted&&e.volume===0&&(e.volume=L),e.muted=!e.muted,Y())}return(0,e.onBeforeUnmount)(()=>{W()}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`article`,{"data-post-id":t.item.postId,"data-media-index":_.value,class:(0,e.normalizeClass)([`media-card`,{"media-card--entering":t.entering,"media-card--leaving":t.leaving,"media-card--error":(0,e.unref)(w)===`error`,"media-card--transparent-chrome":t.mediaCard?.header?.background===`transparent`||t.mediaCard?.footer?.background===`transparent`||t.cardHeader?.background===`transparent`||t.cardFooter?.background===`transparent`}]),style:(0,e.normalizeStyle)(t.itemStyle),"aria-hidden":t.leaving||void 0,"aria-busy":(0,e.unref)(w)===`loading`,inert:t.leaving||void 0,role:t.interactive&&!t.leaving&&!B.value?`button`:void 0,tabindex:t.interactive&&!t.leaving&&!B.value?0:void 0,onClick:r[15]||=e=>h(t.interactive&&!B.value,V(e)),onKeydown:[r[16]||=(0,e.withKeys)(e=>h(t.interactive&&!B.value,`keyboard`),[`enter`]),r[17]||=(0,e.withKeys)((0,e.withModifiers)(e=>h(t.interactive&&!B.value,`keyboard`),[`prevent`]),[`space`])]},[(0,e.createElementVNode)(`div`,Se,[t.cardHeader?((0,e.openBlock)(),(0,e.createBlock)(se,{key:0,index:t.index,item:t.item,layout:t.layout,"loaded-count":t.loadedCount,"media-index":_.value,"media-source":t.mediaSource,placement:`header`,region:t.cardHeader,style:(0,e.normalizeStyle)(t.mediaCard?.header),total:t.total},null,8,[`index`,`item`,`layout`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,{class:(0,e.normalizeClass)([`media-card-media`,{"media-card-media--carousel":t.layout===`reel`&&g.value.length>1}]),"data-media-direction":p.value,onWheel:K,onTouchstartPassive:q,onTouchendPassive:re},[(0,e.createVNode)(e.Transition,{name:`media-slide-${p.value}`},{default:(0,e.withCtx)(()=>[((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:`${t.item.postId}:${v.value.src}:${t.mediaSource??`preview`}:${(0,e.unref)(A)}`,class:`media-card-frame`,"data-media-index":_.value},[(0,e.unref)(w)===`loading`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Te,[...r[18]||=[(0,e.createElementVNode)(`span`,{class:`media-loading-shimmer`},null,-1)]])):(0,e.unref)(w)===`error`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:1,"data-test":`media-error`,class:`media-error`,role:`img`,"aria-label":`${(0,e.unref)(ae)(b.value)} ${(0,e.unref)(oe)(b.value)}`},[(0,e.createElementVNode)(`strong`,De,(0,e.toDisplayString)((0,e.unref)(ae)(b.value)),1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)((0,e.unref)(oe)(b.value)),1),(0,e.createElementVNode)(`button`,{type:`button`,"data-test":`media-retry`,onClick:r[0]||=(0,e.withModifiers)((...t)=>(0,e.unref)(k)&&(0,e.unref)(k)(...t),[`stop`])},`Retry`)],8,Ee)):(0,e.createCommentVNode)(``,!0),(0,e.unref)(J)?((0,e.openBlock)(),(0,e.createElementBlock)(`video`,{key:2,ref_key:`videoElement`,ref:j,"data-source-generation":(0,e.unref)(A),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(w)===`ready`,"media-preview--reel-video":t.layout===`reel`}]),src:b.value,width:S.value??void 0,height:C.value??void 0,autoplay:(0,e.unref)(z),loop:!t.advanceOnMediaEnd,muted:(0,e.unref)(ee),playsinline:``,preload:(0,e.unref)(ce),onLoadedmetadata:_e,onProgress:r[1]||=(...t)=>(0,e.unref)(O)&&(0,e.unref)(O)(...t),onLoadeddata:r[2]||=(...t)=>(0,e.unref)(O)&&(0,e.unref)(O)(...t),onCanplay:r[3]||=(...t)=>(0,e.unref)(O)&&(0,e.unref)(O)(...t),onDurationchange:Y,onTimeupdate:Y,onVolumechange:Y,onPlaying:r[4]||=(...t)=>(0,e.unref)(R)&&(0,e.unref)(R)(...t),onPause:r[5]||=e=>F.value=!1,onEnded:ve,onClick:fe,onError:r[6]||=(...t)=>(0,e.unref)(T)&&(0,e.unref)(T)(...t)},null,42,Oe)):((0,e.openBlock)(),(0,e.createElementBlock)(`img`,{key:3,ref_key:`imageElement`,ref:E,"data-source-generation":(0,e.unref)(A),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(w)===`ready`}]),src:b.value,width:S.value??void 0,height:C.value??void 0,fetchpriority:t.fetchPriority,alt:``,decoding:`async`,loading:(0,e.unref)(ie),onLoad:r[7]||=(...t)=>(0,e.unref)(D)&&(0,e.unref)(D)(...t),onError:r[8]||=(...t)=>(0,e.unref)(T)&&(0,e.unref)(T)(...t)},null,42,ke))],8,we))]),_:1},8,[`name`]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{disabled:!le.value||!t.reelControlsTarget,to:t.reelControlsTarget??`body`},[(0,e.createVNode)(e.Transition,{name:`vibe-reel-media-controls`,css:le.value},{default:(0,e.withCtx)(()=>[ue.value?((0,e.openBlock)(),(0,e.createBlock)(he,{key:de.value,"current-time":M.value,"data-control-post-id":le.value?t.item.postId:void 0,duration:N.value,layout:t.layout,muted:P.value,playing:F.value,volume:I.value,onSeek:Ie,onToggleMute:Re,onTogglePlayback:pe,onVolumeChange:Le},null,8,[`current-time`,`data-control-post-id`,`duration`,`layout`,`muted`,`playing`,`volume`])):(0,e.createCommentVNode)(``,!0)]),_:1},8,[`css`])],8,[`disabled`,`to`])),g.value.length>1?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:(0,e.normalizeClass)([`media-carousel-controls`,{"media-carousel-controls--persistent":t.layout===`reel`}]),"aria-label":`Media navigation`},[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-carousel-control media-carousel-control--previous`,"aria-label":`Previous media for post ${t.item.postId}`,onClick:r[9]||=(0,e.withModifiers)(e=>H(_.value-1,e),[`stop`]),onKeydown:r[10]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(te),{size:20})],40,Ae),(0,e.createElementVNode)(`button`,{type:`button`,class:`media-carousel-control media-carousel-control--next`,"aria-label":`Next media for post ${t.item.postId}`,onClick:r[11]||=(0,e.withModifiers)(e=>H(_.value+1,e),[`stop`]),onKeydown:r[12]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(ne),{size:20})],40,je)],2)):(0,e.createCommentVNode)(``,!0),B.value?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:1,class:`media-card-activator`,type:`button`,"aria-label":`Open post ${t.item.postId}`,onClick:r[13]||=(0,e.withModifiers)(e=>n.$emit(`activate`,V(e)),[`stop`]),onKeydown:r[14]||=(0,e.withModifiers)(()=>{},[`stop`])},null,40,Me)):(0,e.createCommentVNode)(``,!0)],42,Ce),t.cardFooter?((0,e.openBlock)(),(0,e.createBlock)(se,{key:1,index:t.index,item:t.item,layout:t.layout,"loaded-count":t.loadedCount,"media-index":_.value,"media-source":t.mediaSource,placement:`footer`,region:t.cardFooter,style:(0,e.normalizeStyle)(t.mediaCard?.footer),total:t.total},null,8,[`index`,`item`,`layout`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0)])],46,xe))}}),Le={class:`masonry-feed-shell`},Re=[`aria-hidden`,`inert`],ze={key:0,class:`masonry-feed-status-overlay`},Be=6,Ve=12,He=250,Ue=(0,e.defineComponent)({__name:`MasonryFeed`,props:{enteringPostIds:{},entryDelays:{},leavingPostIds:{default:()=>new Set},removalDelays:{default:()=>new Map},masonry:{},suspended:{type:Boolean},canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},hasNext:{type:Boolean},infiniteScroll:{type:Boolean},isLoadingMore:{type:Boolean},items:{},loadMoreLocked:{type:Boolean},mediaCard:{},mediaIndices:{},nextPageError:{type:Boolean},previewStates:{},state:{},total:{}},emits:[`activate`,`error`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`visible`],setup(t,{expose:n,emit:r}){let i=0,a=t,s=r,c=(0,e.shallowRef)(null),l=`vibe-masonry-${(0,e.useId)()}`,u=(0,e.shallowRef)(null),d=(0,e.shallowRef)(0),f=(0,e.shallowRef)(Be),p=(0,e.shallowRef)(0),m=(0,e.shallowRef)(0),g=(0,e.shallowRef)(0),_=(0,e.shallowRef)([]),v=(0,e.shallowRef)([]),b=0,x=null,T=null,k=null,A=null,j=(0,e.computed)(()=>C(a.items,d.value,{additionalHeight:(a.cardHeader?.height??0)+(a.cardFooter?.height??0),gap:f.value,minColumnWidth:D(a.masonry)})),M=(0,e.computed)(()=>{if(a.leavingPostIds.size===0)return null;let e=a.items.flatMap((e,t)=>a.leavingPostIds.has(e.postId)?[]:[{index:t,item:e}]),t=C(e.map(({item:e})=>e),d.value,{additionalHeight:(a.cardHeader?.height??0)+(a.cardFooter?.height??0),gap:f.value,minColumnWidth:D(a.masonry)});return{indices:e.map(({index:e})=>e),layout:t,positions:new Map(e.map(({item:e},n)=>[e.postId,t.items[n]]))}}),N=(0,e.computed)(()=>{let e=j.value,t=M.value;return t?{...t.layout,items:a.items.map((n,r)=>a.leavingPostIds.has(n.postId)?e.items[r]:t.positions.get(n.postId)??e.items[r])}:e}),P=(0,e.computed)(()=>w(j.value.items)),F=(0,e.computed)(()=>{let e=M.value;return e?w(e.layout.items,e.indices):null}),I=(0,e.computed)(()=>Math.max(m.value,a.leavingPostIds.size===0?N.value.height:j.value.height)),ee=(0,e.computed)(()=>({height:`${I.value}px`})),R=(0,e.computed)(()=>!a.infiniteScroll||p.value>0&&g.value+N.value.height<=p.value+1),z=(0,e.computed)(()=>new Set(_.value)),B=(0,e.computed)(()=>v.value.flatMap(e=>{let t=a.items[e];return t?[{fetchPriority:z.value.has(e)?`high`:`low`,index:e,item:t}]:[]}));function V(e,t){return[...new Set([...e,...t])].sort((e,t)=>e-t)}function H(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function U(e){let t={scrollTop:b-g.value,viewportHeight:p.value},n=F.value,r=E(n??P.value,{...t,overscan:e}).indices;return V(r,a.leavingPostIds.size===0?[]:E(P.value,{...t,overscan:e}).indices)}function W(){let e=U(0),t=U(O(a.masonry,p.value));H(_.value,e)||(_.value=e),H(v.value,t)||(v.value=t)}function G(){if(A!==null)return;A=-1;let e=requestAnimationFrame(()=>{A=null,W()});A!==null&&(A=e)}let te=new Set;(0,e.watch)(()=>[...z.value].flatMap(e=>{let t=a.items[e];if(!t)return[];let n=a.mediaIndices.get(t.postId)??0,r=o(t.postId,n);return a.previewStates.get(r)===`ready`?[{key:r,mediaIndex:n,postId:t.postId}]:[]}),e=>{let t=new Set(e.map(({key:e})=>e));e.forEach(({key:e,mediaIndex:t,postId:n})=>{te.has(e)||s(`visible`,n,t)}),te=t},{immediate:!0,flush:`post`});function ne(e){let t=N.value.items[e],n=a.items[e]?.postId;if(!t)return{};let r=n!==void 0&&a.enteringPostIds.has(n),i=n!==void 0&&a.leavingPostIds.has(n),o=r||i?S({containerHeight:Math.max(m.value,j.value.height),gap:f.value}):0,s=n===void 0?0:i?a.removalDelays.get(n)??0:r?a.entryDelays.get(n)??0:0;return{"--masonry-entry-delay":`${s}ms`,width:`${t.width}px`,height:`${t.height}px`,transform:`translate3d(${t.x}px, ${t.y+o}px, 0)`}}function K(){let e=c.value;if(!e)return;b=e.scrollTop,p.value=e.clientHeight;let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(Number.parseFloat(t?.paddingTop??``)||0)+(Number.parseFloat(t?.paddingBottom??``)||0);m.value=Math.max(0,e.clientHeight-n);let r=u.value;r&&(g.value=r.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,W())}function q(e){let t=e.ownerDocument.documentElement.clientWidth;d.value=e.clientWidth,f.value=Math.min(Ve,Math.max(Be,t*.0075)),K()}function re(e){let t=e.currentTarget;t&&(b=t.scrollTop,G(),Date.now()>=i&&!a.loadMoreLocked&&a.infiniteScroll&&y(t)&&s(`loadMore`))}function ie(){let e=c.value;Date.now()>=i&&!a.loadMoreLocked&&e&&y(e)&&s(`loadMore`)}(0,e.watch)(()=>a.items.length,(e,t)=>{e>0&&e<t&&(i=Date.now()+He)});function J(){return c.value}return(0,e.watch)(u,e=>{x?.disconnect(),x=null,k!==null&&cancelAnimationFrame(k),e&&(q(e),!(typeof ResizeObserver>`u`)&&(x=new ResizeObserver(([t])=>{let n=t?.contentRect.width??e.clientWidth;Math.abs(n-d.value)<.5||(k=requestAnimationFrame(()=>{k=null,q(e)}))}),x.observe(e)))}),(0,e.watch)(c,e=>{T?.disconnect(),T=null,e&&(K(),!(typeof ResizeObserver>`u`)&&(T=new ResizeObserver(K),T.observe(e)))}),(0,e.watch)([j,N,()=>a.masonry],W,{flush:`post`}),(0,e.onBeforeUnmount)(()=>{x?.disconnect(),T?.disconnect(),k!==null&&cancelAnimationFrame(k),A!==null&&cancelAnimationFrame(A)}),n({getScrollElement:J,loadIfNearBottom:ie}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Le,[(0,e.createElementVNode)(`main`,{id:l,ref_key:`galleryElement`,ref:c,class:(0,e.normalizeClass)([`gallery-shell masonry-feed`,{"masonry-feed--suspended":t.suspended}]),"data-layout-mode":`masonry`,"aria-hidden":t.suspended||void 0,inert:t.suspended||void 0,onScrollPassive:re},[(0,e.createElementVNode)(`section`,{ref_key:`masonryElement`,ref:u,class:(0,e.normalizeClass)([`masonry`,{"masonry--ready":d.value>0}]),style:(0,e.normalizeStyle)(ee.value),"aria-label":`Media gallery`},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(B.value,({fetchPriority:n,item:r,index:i})=>((0,e.openBlock)(),(0,e.createBlock)(Ie,{key:r.postId,class:`masonry-item`,entering:t.enteringPostIds.has(r.postId),leaving:t.leavingPostIds.has(r.postId),"fetch-priority":n,"card-footer":t.cardFooter,"card-header":t.cardHeader,"media-card":t.mediaCard,index:i,item:r,"item-style":ne(i),interactive:``,layout:`masonry`,"loaded-count":t.items.length,"media-index":t.mediaIndices.get(r.postId)??0,"preview-state":t.previewStates.get((0,e.unref)(o)(r.postId,t.mediaIndices.get(r.postId)??0))??`loading`,total:t.total,onActivate:e=>s(`activate`,r.postId,e),onMediaChange:e=>s(`mediaChange`,r.postId,e),onReady:e=>s(`ready`,r.postId,e),onError:e=>s(`error`,r.postId,e)},null,8,[`entering`,`leaving`,`fetch-priority`,`card-footer`,`card-header`,`media-card`,`index`,`item`,`item-style`,`loaded-count`,`media-index`,`preview-state`,`total`,`onActivate`,`onMediaChange`,`onReady`,`onError`]))),128))],6)],42,Re),t.feedFooter||t.isLoadingMore||t.nextPageError||t.hasNext&&R.value||!t.hasNext&&t.canRetryEnd?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,ze,[(0,e.createVNode)(h,{actions:t.feedFooterActions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,"has-error":t.nextPageError,"has-next":t.hasNext,"is-loading":t.isLoadingMore,"load-more-locked":t.loadMoreLocked,"show-load-more":R.value,state:t.state,onLoadMore:r[0]||=e=>s(`loadMore`),onRetryEnd:r[1]||=e=>s(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`show-load-more`,`state`])])):(0,e.createCommentVNode)(``,!0),(0,e.createVNode)(L,{"content-size":N.value.height,"controls-id":l,"scroll-element":c.value,suspended:t.suspended},null,8,[`content-size`,`scroll-element`,`suspended`])]))}}),We=300;function Ge(e,t,n){let r=e.scrollTop;if(n||Math.abs(r-t)<=1)return e.scrollTop=t,Promise.resolve();e.setAttribute(`data-transitioning`,``);let i=performance.now(),a=0;return new Promise(n=>{let o=s=>{a+=1;let c=Math.max(s-i,1e3/60*a),l=Math.min(1,c/We),u=1-(1-l)**3;if(e.scrollTop=r+(t-r)*u,l<1){requestAnimationFrame(o);return}e.removeAttribute(`data-transitioning`),e.scrollTop=t,n()};requestAnimationFrame(o)})}var Ke=[`aria-label`],qe=(0,e.defineComponent)({__name:`ReelAutoAdvanceProgress`,props:{durationMs:{},label:{}},emits:[`complete`],setup(t,{emit:n}){let r=t,i=n,a=(0,e.computed)(()=>({"--vibe-reel-auto-advance-duration":`${r.durationMs}ms`}));return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:`reel-auto-advance`,"data-test":`reel-auto-advance`,role:`timer`,"aria-label":t.label},[(0,e.createElementVNode)(`span`,{class:`reel-auto-advance-progress`,style:(0,e.normalizeStyle)(a.value),onAnimationend:r[0]||=e=>i(`complete`)},null,36)],8,Ke))}}),Je={class:`reel-viewport`},Ye=[`data-active-post-id`,`data-active-media-index`],Xe=[`role`,`data-status`],Ze=2,Qe=300,$e=250,et=(0,e.defineComponent)({__name:`ReelFeed`,props:{initialPostId:{},mediaSource:{},reelAutoAdvance:{},reelForward:{default:()=>({error:null,status:`idle`})},canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},hasNext:{type:Boolean},infiniteScroll:{type:Boolean},isLoadingMore:{type:Boolean},items:{},loadMoreLocked:{type:Boolean},mediaCard:{},mediaIndices:{},nextPageError:{type:Boolean},previewStates:{},state:{},total:{}},emits:[`activeChange`,`error`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`retryForward`],setup(t,{expose:i,emit:s}){let c=0,l=t,u=s,d=(0,e.shallowRef)(null),f=(0,e.shallowRef)(null),p=l.initialPostId===null||l.initialPostId===void 0?-1:l.items.findIndex(e=>e.postId===l.initialPostId),m=(0,e.shallowRef)(Math.max(0,p)),g=(0,e.shallowRef)(!1),_=(0,e.shallowRef)(!1),v=0,b=null,x=null,S=null,C=(0,e.computed)(()=>({gridTemplateRows:`repeat(${l.items.length}, 100cqh)`})),w=(0,e.computed)(()=>{let e=Math.max(0,m.value-Ze),t=Math.min(l.items.length-1,m.value+Ze);return l.items.slice(e,t+1).map((t,n)=>({fetchPriority:e+n===m.value?`high`:`low`,index:e+n,item:t}))}),T=(0,e.computed)(()=>l.items[m.value]?.postId),E=(0,e.computed)(()=>l.items[m.value]),D=(0,e.computed)(()=>{let e=T.value;return e===void 0?0:l.mediaIndices.get(e)??0}),O=(0,e.computed)(()=>{let e=T.value;return e===void 0?`loading`:l.previewStates.get(o(e,D.value))??`loading`}),k=(0,e.computed)(()=>E.value?a(E.value,D.value):null),A=(0,e.computed)(()=>k.value?n(k.value,l.mediaSource??`preview`):null),j=(0,e.computed)(()=>O.value===`ready`&&!!(A.value&&ve(A.value.type,A.value.src))),M=(0,e.computed)(()=>[T.value,D.value,l.items.length,l.loadMoreLocked,l.reelAutoAdvance.enabled,l.reelAutoAdvance.includePostItems,l.reelAutoAdvance.intervalMs].join(`:`)),N=(0,e.computed)(()=>{let e=E.value,t=!!(e&&l.reelAutoAdvance.includePostItems&&D.value<r(e).length-1),n=l.reelAutoAdvance.intervalMs/1e3;return`Auto advance to the next ${t?`post item`:`post`} in ${n}s`}),P=(0,e.computed)(()=>l.reelAutoAdvance.enabled&&l.reelForward.status===`idle`&&E.value!==void 0&&O.value!==`loading`&&!j.value),F=(0,e.computed)(()=>!l.infiniteScroll||l.items.length<=1),I=(0,e.computed)(()=>l.reelForward.status===`loading`?`Loading the next media…`:l.reelForward.status===`error`?`Unable to load the next media.`:`You reached the end of this feed.`);function L(e){return{gridRow:`${e+1}`}}function ee(e){let t=v||e.clientHeight;return t<=0||l.items.length===0?0:Math.min(l.items.length-1,Math.max(0,Math.round(e.scrollTop/t)))}function R(e){let t=e.currentTarget;if(!t)return;let n=v||t.clientHeight,r=Math.max(0,l.items.length-1)*n;g.value=l.items.length>0&&t.scrollTop>r+1,_.value||(m.value=ee(t)),Date.now()>=c&&!l.loadMoreLocked&&l.infiniteScroll&&y(t)&&u(`loadMore`)}function z(){let e=d.value;e&&(g.value=!1,H(!0),v=e.clientHeight,e.scrollTop=m.value*v,x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{e.scrollTop=m.value*e.clientHeight,v=e.clientHeight,x=null}),B())}function B(){S!==null&&clearTimeout(S),S=setTimeout(()=>{S=null;let e=d.value;e&&(v=e.clientHeight,e.scrollTop=m.value*v),H(!1)},120)}function V(){H(!0);let e=d.value;e&&(v=e.clientHeight,e.scrollTop=m.value*v),B()}function H(e){_.value=e,d.value?.toggleAttribute(`data-resizing`,e)}function U(){let e=d.value;Date.now()>=c&&!l.loadMoreLocked&&e&&y(e)&&u(`loadMore`)}(0,e.watch)(()=>l.items.length,(e,t)=>{e>0&&e<t&&(c=Date.now()+$e)});function W(e){let t=E.value;if(!t)return!1;let n=r(t).length;if(n<=1)return!1;let i=(D.value+e+n)%n;return u(`mediaChange`,t.postId,i),!0}function G(e){let t=m.value+e;return!d.value||t<0||t>=l.items.length?!1:(q(t),!0)}function te(e,t){let n=l.items.findIndex(t=>t.postId===e),r=l.items[n];return!d.value||!r||t<0||t>r.items.length?!1:((l.mediaIndices.get(e)??0)!==t&&u(`mediaChange`,e,t),n!==m.value&&q(n),!0)}function ne(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function K(e){let t=d.value;if(!t)return Promise.resolve();let n=e*(v||t.clientHeight);return m.value=e,Ge(t,n,ne())}function q(e){K(e)}async function re(e){let t=l.items.findIndex(t=>t.postId===e);return t<0||t===m.value?!1:(await K(t),!0)}async function ie(e){return W(e)?(ne()||await new Promise(e=>setTimeout(e,Qe)),!0):!1}function J(){if(!l.reelAutoAdvance.enabled)return;let e=E.value;if(!e)return;if(l.reelAutoAdvance.includePostItems&&D.value<r(e).length-1){u(`mediaChange`,e.postId,D.value+1);return}let t=m.value+1,n=l.items[t];if(!n){l.hasNext&&!l.loadMoreLocked&&u(`loadMore`);return}l.reelAutoAdvance.includePostItems&&(l.mediaIndices.get(n.postId)??0)!==0&&u(`mediaChange`,n.postId,0),q(t)}function ae(e,t){!l.reelAutoAdvance.enabled||e!==T.value||t!==D.value||!j.value||J()}return(0,e.watch)(d,e=>{b?.disconnect(),b=null,e&&(v=e.clientHeight,!(typeof ResizeObserver>`u`)&&(b=new ResizeObserver(z),b.observe(e)))}),(0,e.watch)(()=>l.items.length,async t=>{let n=l.initialPostId,r=n==null?-1:l.items.findIndex(({postId:e})=>e===n);m.value=r>=0?r:Math.min(m.value,Math.max(0,t-1)),await(0,e.nextTick)(),z()}),(0,e.watch)(T,e=>{e!==void 0&&u(`activeChange`,e)},{immediate:!0}),(0,e.onMounted)(()=>{window.addEventListener(`resize`,V),window.addEventListener(`orientationchange`,V),p>=0&&(0,e.nextTick)(z)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`resize`,V),window.removeEventListener(`orientationchange`,V),b?.disconnect(),x!==null&&cancelAnimationFrame(x),S!==null&&clearTimeout(S)}),i({activeIndex:m,activePostId:T,changeActiveMedia:W,loadIfNearBottom:U,moveActivePost:G,navigateToItem:te,transitionActiveMedia:ie,transitionActivePost:re}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`main`,{class:(0,e.normalizeClass)([`reel-shell`,{"reel-shell--has-footer":!!t.cardFooter,"reel-shell--has-header":!!t.cardHeader}]),"data-layout-mode":`reel`},[t.cardHeader&&E.value&&t.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(se,{key:0,index:m.value,item:E.value,layout:`reel`,"loaded-count":t.items.length,"media-index":D.value,"media-source":t.mediaSource,placement:`header`,region:t.cardHeader,style:(0,e.normalizeStyle)(t.mediaCard?.header),total:t.total},null,8,[`index`,`item`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0),(0,e.createElementVNode)(`div`,Je,[(0,e.createElementVNode)(`div`,{ref_key:`galleryElement`,ref:d,class:`gallery-shell reel-feed`,"data-active-post-id":T.value,"data-active-media-index":D.value,onScrollPassive:R},[t.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{key:1,class:`reel-track`,style:(0,e.normalizeStyle)(C.value),"aria-label":`Media gallery`},[((0,e.openBlock)(!0),(0,e.createElementBlock)(e.Fragment,null,(0,e.renderList)(w.value,({fetchPriority:n,item:r,index:i})=>((0,e.openBlock)(),(0,e.createBlock)(Ie,{key:r.postId,active:i===m.value&&!g.value,"advance-on-media-end":l.reelAutoAdvance.enabled&&i===m.value,class:`reel-item`,entering:!1,"fetch-priority":n,index:i,item:r,"item-style":L(i),"media-card":t.mediaCard,layout:`reel`,"loaded-count":t.items.length,"media-index":t.mediaIndices.get(r.postId)??0,"media-source":t.mediaSource,"preview-state":t.previewStates.get((0,e.unref)(o)(r.postId,t.mediaIndices.get(r.postId)??0))??`loading`,"reel-controls-target":f.value,"stationary-reel-controls":``,total:t.total,onMediaChange:e=>u(`mediaChange`,r.postId,e),onEnded:e=>ae(r.postId,e),onReady:e=>u(`ready`,r.postId,e),onError:e=>u(`error`,r.postId,e)},null,8,[`active`,`advance-on-media-end`,`fetch-priority`,`index`,`item`,`item-style`,`media-card`,`loaded-count`,`media-index`,`media-source`,`preview-state`,`reel-controls-target`,`total`,`onMediaChange`,`onEnded`,`onReady`,`onError`]))),128))],4)):((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`reel-forward-status`,role:t.reelForward.status===`error`?`alert`:`status`,"data-status":t.reelForward.status},[(0,e.createElementVNode)(`p`,null,(0,e.toDisplayString)(I.value),1),t.reelForward.status===`error`||t.reelForward.status===`end`?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:0,class:`reel-forward-retry`,type:`button`,onClick:r[0]||=e=>u(`retryForward`)},` Retry `)):(0,e.createCommentVNode)(``,!0)],8,Xe)),t.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(h,{key:2,actions:t.feedFooterActions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,"has-error":t.nextPageError,"has-next":t.hasNext,"is-loading":t.isLoadingMore,"load-more-locked":t.loadMoreLocked,"show-load-more":F.value,state:t.state,onLoadMore:r[1]||=e=>u(`loadMore`),onRetryEnd:r[2]||=e=>u(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`has-error`,`has-next`,`is-loading`,`load-more-locked`,`show-load-more`,`state`])):(0,e.createCommentVNode)(``,!0)],40,Ye),(0,e.createElementVNode)(`div`,{ref_key:`reelControlsElement`,ref:f,class:`reel-media-controls-host`,"data-test":`reel-media-controls-host`},null,512)]),t.cardFooter&&E.value&&t.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(se,{key:1,index:m.value,item:E.value,layout:`reel`,"loaded-count":t.items.length,"media-index":D.value,"media-source":t.mediaSource,placement:`footer`,region:t.cardFooter,style:(0,e.normalizeStyle)(t.mediaCard?.footer),total:t.total},null,8,[`index`,`item`,`loaded-count`,`media-index`,`media-source`,`region`,`style`,`total`])):(0,e.createCommentVNode)(``,!0),P.value?((0,e.openBlock)(),(0,e.createBlock)(qe,{key:M.value,"duration-ms":t.reelAutoAdvance.intervalMs,label:N.value,onComplete:J},null,8,[`duration-ms`,`label`])):(0,e.createCommentVNode)(``,!0)],2))}}),tt=[`data-info-sheet-open`,`data-info-sheet-mode`],nt=[`aria-hidden`,`inert`],rt={key:0,class:`reel-info-sheet-layer`,"data-test":`reel-info-sheet`},it=[`role`,`aria-modal`,`tabindex`,`data-active-post-id`],at=(0,e.defineComponent)({__name:`ReelLayout`,props:{forwardIndex:{default:null},forwardItem:{default:null},infoSheet:{},infoSheetEnabled:{type:Boolean},infoSheetOverlay:{type:Boolean},origin:{},initialPostId:{},mediaSource:{},reelAutoAdvance:{},reelForward:{default:()=>({error:null,status:`idle`})},canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},hasNext:{type:Boolean},infiniteScroll:{type:Boolean},isLoadingMore:{type:Boolean},items:{},loadMoreLocked:{type:Boolean},mediaCard:{},mediaIndices:{},nextPageError:{type:Boolean},previewStates:{},state:{},total:{}},emits:[`activeChange`,`closeInfoSheet`,`error`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:i}){let o=t,s=i,c=(0,e.shallowRef)(null),l=(0,e.shallowRef)(null),u=null,d=(0,e.computed)(()=>{let e=o.initialPostId===null||o.initialPostId===void 0?-1:o.items.findIndex(e=>e.postId===o.initialPostId);return Math.max(0,e)}),f=(0,e.computed)(()=>o.items[d.value]),p=(0,e.computed)(()=>f.value??(o.reelForward.status===`idle`?void 0:o.forwardItem??void 0)),m=(0,e.computed)(()=>f.value?d.value:o.forwardIndex??0),h=(0,e.computed)(()=>{let e=p.value?.postId;return e===void 0?0:o.mediaIndices.get(e)??0}),g=(0,e.computed)(()=>!!(o.infoSheet&&o.infoSheetEnabled&&p.value)),_=(0,e.computed)(()=>{let e=p.value;return e?{close:v,index:m.value,item:e,layout:`reel`,loadedCount:o.items.length,mediaCount:r(e).length,mediaIndex:h.value,mediaItem:a(e,h.value),mediaSource:o.mediaSource??`preview`,origin:o.origin,total:o.total}:null});function v(){s(`closeInfoSheet`)}function y(e){return c.value?.changeActiveMedia(e)??!1}function b(){c.value?.loadIfNearBottom()}function x(e){return c.value?.moveActivePost(e)??!1}function S(e,t){return c.value?.navigateToItem(e,t)??!1}function C(e){return c.value?.transitionActiveMedia(e)??Promise.resolve(!1)}function w(e){return c.value?.transitionActivePost(e)??Promise.resolve(!1)}function T(e,t){s(`error`,e,t)}function E(e,t){s(`mediaChange`,e,t)}function D(e,t){s(`ready`,e,t)}return(0,e.watch)(()=>({overlay:o.infoSheetOverlay,visible:g.value}),async(t,n)=>{if(t.visible&&!n?.visible){u=document.activeElement instanceof HTMLElement?document.activeElement:null,t.overlay&&(await(0,e.nextTick)(),l.value?.focus({preventScroll:!0}));return}if(!t.visible&&n?.visible&&u?.isConnected){let t=u;u=null,await(0,e.nextTick)(),t.focus({preventScroll:!0})}}),(0,e.onBeforeUnmount)(()=>{u=null}),n({changeActiveMedia:y,loadIfNearBottom:b,moveActivePost:x,navigateToItem:S,transitionActiveMedia:C,transitionActivePost:w}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{class:(0,e.normalizeClass)([`reel-layout`,`reel-layout--${t.infoSheetOverlay?`overlay`:`layout`}`]),"data-info-sheet-open":g.value||void 0,"data-info-sheet-mode":t.infoSheetOverlay?`overlay`:`layout`},[(0,e.createElementVNode)(`div`,{class:`reel-layout-main`,"aria-hidden":t.infoSheetOverlay&&g.value||void 0,inert:t.infoSheetOverlay&&g.value||void 0},[(0,e.createVNode)(et,{ref_key:`reelFeed`,ref:c,"can-retry-end":t.canRetryEnd,"card-footer":t.cardFooter,"card-header":t.cardHeader,"feed-footer":t.feedFooter,"feed-footer-actions":t.feedFooterActions,"media-card":t.mediaCard,"has-next":t.hasNext,"infinite-scroll":t.infiniteScroll,"initial-post-id":t.initialPostId,"is-loading-more":t.isLoadingMore,items:t.items,"load-more-locked":t.loadMoreLocked,"media-indices":t.mediaIndices,"media-source":t.mediaSource,"next-page-error":t.nextPageError,"preview-states":t.previewStates,"reel-auto-advance":t.reelAutoAdvance,"reel-forward":t.reelForward,state:t.state,total:t.total,onActiveChange:r[0]||=e=>s(`activeChange`,e),onError:T,onLoadMore:r[1]||=e=>s(`loadMore`),onMediaChange:E,onReady:D,onRetryEnd:r[2]||=e=>s(`retryEnd`),onRetryForward:r[3]||=e=>s(`retryForward`)},null,8,[`can-retry-end`,`card-footer`,`card-header`,`feed-footer`,`feed-footer-actions`,`media-card`,`has-next`,`infinite-scroll`,`initial-post-id`,`is-loading-more`,`items`,`load-more-locked`,`media-indices`,`media-source`,`next-page-error`,`preview-states`,`reel-auto-advance`,`reel-forward`,`state`,`total`])],8,nt),(0,e.createVNode)(e.Transition,{name:`vibe-info-sheet`},{default:(0,e.withCtx)(()=>[g.value&&t.infoSheet&&_.value?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,rt,[(0,e.createElementVNode)(`aside`,{ref_key:`sheetElement`,ref:l,class:`reel-info-sheet`,role:t.infoSheetOverlay?`dialog`:`complementary`,"aria-label":`Reel information`,"aria-modal":t.infoSheetOverlay?`true`:void 0,tabindex:t.infoSheetOverlay?-1:void 0,"data-active-post-id":p.value?.postId},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.infoSheet.component),(0,e.normalizeProps)((0,e.guardReactiveProps)(_.value)),null,16))],8,it)])):(0,e.createCommentVNode)(``,!0)]),_:1})],10,tt))}});function ot(e,t,n,r,o){let s=e.items.findIndex(e=>e.postId===t),c=e.items[s];if(!c)return null;let l=i(c,n),u=a(c,l);return{item:c,layout:r,media:u,mediaId:u.mediaId??null,mediaIndex:l,origin:o,phoneMode:e.phoneMode,postId:c.postId,postIndex:s}}function st(t,n){(0,e.watch)(()=>{let e=t.layout===`reel`||t.reelOrigin===`masonry`?t.activeReelPostId:null;return{mediaIndex:e===null?0:t.mediaIndices.get(e)??0,origin:t.reelOrigin??`reel`,postId:e}},(e,r)=>{if(e.postId===null||e.postId===r?.postId&&e.mediaIndex===r.mediaIndex&&e.origin===r.origin)return;let i=ot(t,e.postId,e.mediaIndex,`reel`,e.origin);i&&n(i)},{flush:`sync`})}function ct(t,n){let r=(0,e.shallowRef)(new Map),i=(0,e.shallowRef)(new Map),a=(0,e.shallowRef)(new Map),s=()=>t.reelMediaSource===`preview`?r:t.reelMediaSource===`mobile`?a:i,c=(0,e.computed)(()=>s().value);function l(e,t,n,r){let i=o(t,n);e.value.get(i)!==r&&(e.value=new Map(e.value).set(i,r))}function u(e,n,r,i){return ot(t,e,n,r,i)}function d(e,t,r,i){let a=u(e,t,r,i);a&&n.ready(a)}function f(e,t){l(r,e,t,`error`)}function p(e,t){l(r,e,t,`ready`),d(e,t,`masonry`,null)}function m(e,t){l(s(),e,t,`error`)}function h(e,n){l(s(),e,n,`ready`),d(e,n,`reel`,t.reelOrigin??`reel`)}function g(e,t){let r=u(e,t,`masonry`,null);r&&n.visible(r)}return st(t,n.reelChange),(0,e.watch)(()=>{let e=t.layout===`reel`||t.reelOrigin===`masonry`?t.activeReelPostId:null,n=e===null?0:t.mediaIndices.get(e)??0;return{mediaIndex:n,origin:t.reelOrigin??`reel`,postId:e,ready:e!==null&&c.value.get(o(e,n))===`ready`}},(e,t)=>{if(e.postId===null||!e.ready||t?.ready&&t.postId===e.postId&&t.mediaIndex===e.mediaIndex&&t.origin===e.origin)return;let r=u(e.postId,e.mediaIndex,`reel`,e.origin);r&&n.visible(r)},{flush:`post`}),{markMasonryVisible:g,markPreviewError:f,markPreviewReady:p,markReelError:m,markReelReady:h,originalStates:i,previewStates:r,reelStates:c}}var lt=[];function ut(e){return lt.push(e),()=>{let t=lt.indexOf(e);t>=0&&lt.splice(t,1)}}function dt(e){if(!e.isActive())return!1;let t=lt.filter(e=>e.isActive()),n=e.element();return n!==null&&t.some(t=>{if(t===e)return!1;let r=t.element();return r!==null&&n.contains(r)})?!1:t.filter(e=>{let n=e.element();return n===null||!t.some(t=>{if(t===e)return!1;let r=t.element();return r!==null&&n.contains(r)})}).at(-1)===e}function ft(t){let n={element:t.element,isActive:()=>t.state.layout===`reel`||t.state.reelOrigin===`masonry`},r=null;function i(e){let r=n.isActive();if(e.key===`Escape`&&r&&!dt(n))return;if(e.key===`Escape`&&t.state.reelOrigin===`masonry`){e.preventDefault(),t.state.reelInfoSheetOverlay&&t.state.reelInfoSheet.enabled&&t.setReelInfoSheet(!1),t.closeMasonryReel();return}if(e.key===`Escape`&&r&&t.state.reelInfoSheet.enabled){e.preventDefault(),t.setReelInfoSheet(!1);return}if(e.defaultPrevented||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||t.isReelLeaving()||!r)return;let i=e.target;if(i instanceof HTMLElement&&(i.isContentEditable||[`INPUT`,`SELECT`,`TEXTAREA`].includes(i.tagName)))return;let a=e.key===`ArrowLeft`?-1:e.key===`ArrowRight`?1:0;a!==0&&t.reelRenderer()?.changeActiveMedia?.(a)&&e.preventDefault()}(0,e.onMounted)(()=>{r=ut(n),window.addEventListener(`keydown`,i)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`keydown`,i),r?.(),r=null})}var pt=35,mt=420,ht=(0,e.defineComponent)({__name:`VibeSurface`,props:{canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},mediaCard:{},masonry:{},reelInfoSheet:{},state:{}},emits:[`activeReelChange`,`closeReel`,`loadMore`,`mediaReady`,`mediaVisible`,`openReel`,`reelMediaChange`,`reelInfoSheetChange`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:a}){let o=t,s=a,l=(0,e.shallowRef)(null),u=(0,e.shallowRef)(null),d=(0,e.shallowRef)(null),f=(0,e.shallowRef)(null),p=(0,e.shallowRef)({}),m=(0,e.shallowRef)(!1),h=(0,e.shallowRef)(new Set),g=(0,e.shallowRef)(new Map),_=(0,e.shallowRef)(new Set),y=(0,e.shallowRef)(new Map),b=(0,e.computed)(()=>Object.freeze([...o.state.items])),x=(0,e.computed)(()=>c(o.state,b.value)),{markMasonryVisible:S,markPreviewError:C,markPreviewReady:w,markReelError:T,markReelReady:E,originalStates:D,previewStates:O,reelStates:k}=ct(o.state,{ready:e=>s(`mediaReady`,e),reelChange:e=>s(`reelMediaChange`,e),visible:e=>s(`mediaVisible`,e)}),A=new Set(o.state.items.map(e=>e.postId)),j=null,M=null,N=!1;function P(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function F(){j!==null&&cancelAnimationFrame(j),j=requestAnimationFrame(()=>{j=requestAnimationFrame(()=>{j=null,h.value=new Set})})}function I(e,t){let n=o.state.items.find(t=>t.postId===e);if(!n)return;let r=i(n,t);(o.state.mediaIndices.get(e)??0)!==r&&(o.state.mediaIndices=new Map(o.state.mediaIndices).set(e,r))}async function L(){await(0,e.nextTick)(),(o.state.layout===`reel`||o.state.reelOrigin===`masonry`?u.value:l.value)?.loadIfNearBottom()}function ee(e){return o.state.isLoading||o.state.items.length===0||o.state.layout!==`reel`&&o.state.reelOrigin!==`masonry`?!1:u.value?.changeActiveMedia?.(e)??!1}function R(e){return o.state.isLoading||o.state.items.length===0||o.state.layout!==`reel`&&o.state.reelOrigin!==`masonry`?!1:u.value?.moveActivePost?.(e)??!1}function z(e){if(!(o.state.layout===`reel`||o.state.reelOrigin===`masonry`)||o.state.isLoading)return`reel-inactive`;let t=o.state.items.find(t=>t.postId===e.postId);if(!t)return`not-found`;let n=r(t).findIndex(t=>t.mediaId===e.mediaId);return n<0?`not-found`:u.value?.navigateToItem?.(e.postId,n)?`navigated`:`reel-inactive`}function B(){return o.state.layout!==`masonry`||o.state.reelOrigin===`masonry`?null:l.value?.getScrollElement?.()??null}function V(t,n){M=t,N=n===`keyboard`,p.value=G(t),s(`openReel`,t),(0,e.nextTick)(()=>d.value?.focus())}function H(e){let t=f.value?.querySelectorAll(`.masonry-feed [data-post-id]`)??[];return Array.from(t).find(t=>t.dataset.postId===String(e))??null}function U(e,t){if(o.state.layout!==`masonry`||o.state.reelOrigin!==null||P())return 0;let n=[...new Set(e)],r=n.filter(H);if(r.length===0)return 0;let i=new Map(y.value),a=t?.staggerMs??pt;return r.forEach((e,t)=>{i.set(e,t*a)}),h.value=new Set([...h.value].filter(e=>!r.includes(e))),_.value=new Set([..._.value,...n]),y.value=i,mt+(r.length-1)*a}function W(e,t){let n=H(e),r=n?.querySelector(`.media-card-activator`)??n;r&&(r.classList.toggle(`media-card-focus-silent`,!t),t||r.addEventListener(`blur`,()=>{r.classList.remove(`media-card-focus-silent`)},{once:!0}),r?.focus({preventScroll:!0}))}function G(e){let t=f.value,n=H(e);if(t===null||n===null)return{};let r=t.getBoundingClientRect(),i=n.getBoundingClientRect();return{"--vibe-reel-origin-top":`${Math.max(0,i.top-r.top)}px`,"--vibe-reel-origin-right":`${Math.max(0,r.right-i.right)}px`,"--vibe-reel-origin-bottom":`${Math.max(0,r.bottom-i.bottom)}px`,"--vibe-reel-origin-left":`${Math.max(0,i.left-r.left)}px`}}function te(){o.state.reelOrigin===`masonry`&&(M??=o.state.activeReelPostId,m.value=!0,s(`closeReel`))}function ne(){let t=M,n=N;m.value=!1,M=null,N=!1,p.value={},(0,e.nextTick)(()=>{t!==null&&W(t,n)})}return ft({closeMasonryReel:te,element:()=>f.value,isReelLeaving:()=>m.value,reelRenderer:()=>u.value,setReelInfoSheet:e=>s(`reelInfoSheetChange`,e),state:o.state}),(0,e.watch)(()=>o.state.items.map(e=>e.postId),e=>{let t=e.filter(e=>!A.has(e)),n=new Set(e);if(A=new Set(e),_.value=new Set([..._.value].filter(e=>n.has(e))),y.value=new Map([...y.value].filter(([e])=>n.has(e))),t.length===0||P())return;let r=new Map;e.forEach(e=>{let t=g.value.get(e);t!==void 0&&r.set(e,t)}),t.forEach((e,t)=>{r.set(e,t*pt)}),g.value=r,h.value=new Set([...h.value,...t]),F()},{flush:`sync`}),(0,e.onBeforeUnmount)(()=>{j!==null&&cancelAnimationFrame(j)}),n({changeActiveReelMedia:ee,getAutoScrollElement:B,loadIfNearBottom:L,moveActiveReelPost:R,navigateToReelItem:z,startItemRemoval:U,transitionActiveReelMedia:e=>u.value?.transitionActiveMedia?.(e)??Promise.resolve(!1),transitionActiveReelPost:e=>u.value?.transitionActivePost?.(e)??Promise.resolve(!1)}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{ref_key:`surfaceElement`,ref:f,class:`vibe-surface`},[t.state.layout===`reel`&&(t.state.items.length>0||t.state.reelForward.status!==`idle`)?((0,e.openBlock)(),(0,e.createBlock)(at,{key:0,ref_key:`reelRenderer`,ref:u,"can-retry-end":t.canRetryEnd,"has-next":t.state.next!==null,"card-footer":t.cardFooter,"card-header":t.cardHeader,"feed-footer":t.feedFooter,"feed-footer-actions":t.feedFooterActions,"forward-index":t.state.reelForwardIndex,"forward-item":t.state.reelForwardItem,"media-card":t.mediaCard,"infinite-scroll":t.state.infiniteScroll,"is-loading-more":t.state.isLoadingMore,items:t.state.items,"load-more-locked":t.state.loadMoreLocked,"media-source":t.state.reelMediaSource,"media-indices":t.state.mediaIndices,"initial-post-id":t.state.activeReelPostId,"info-sheet":t.reelInfoSheet,"info-sheet-enabled":t.state.reelInfoSheet.enabled,"info-sheet-overlay":t.state.reelInfoSheetOverlay,"next-page-error":!!t.state.nextPageError,origin:`reel`,"preview-states":(0,e.unref)(k),"reel-auto-advance":t.state.reelAutoAdvance,"reel-forward":t.state.reelForward,state:x.value,total:t.state.total,onActiveChange:r[0]||=e=>s(`activeReelChange`,e),onCloseInfoSheet:r[1]||=e=>s(`reelInfoSheetChange`,!1),onError:(0,e.unref)(T),onLoadMore:r[2]||=e=>s(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(E),onRetryEnd:r[3]||=e=>s(`retryEnd`),onRetryForward:r[4]||=e=>s(`retryForward`)},null,8,`can-retry-end.has-next.card-footer.card-header.feed-footer.feed-footer-actions.forward-index.forward-item.media-card.infinite-scroll.is-loading-more.items.load-more-locked.media-source.media-indices.initial-post-id.info-sheet.info-sheet-enabled.info-sheet-overlay.next-page-error.preview-states.reel-auto-advance.reel-forward.state.total.onError.onReady`.split(`.`))):t.state.error||t.state.isLoading||t.state.items.length===0&&t.state.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(v,{key:1,actions:t.feedFooterActions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,state:x.value,onLoadMore:r[5]||=e=>s(`loadMore`),onRetryEnd:r[6]||=e=>s(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`state`])):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:2},[(0,e.createVNode)(Ue,{ref_key:`masonryRenderer`,ref:l,"can-retry-end":t.canRetryEnd,"entering-post-ids":h.value,"entry-delays":g.value,"leaving-post-ids":_.value,"removal-delays":y.value,"card-footer":t.cardFooter,"card-header":t.cardHeader,"feed-footer":t.feedFooter,"feed-footer-actions":t.feedFooterActions,"media-card":t.mediaCard,masonry:t.masonry,"has-next":t.state.next!==null,"infinite-scroll":t.state.infiniteScroll,"is-loading-more":t.state.isLoadingMore,items:t.state.items,"load-more-locked":t.state.loadMoreLocked,"media-indices":t.state.mediaIndices,"next-page-error":!!t.state.nextPageError,"preview-states":(0,e.unref)(O),suspended:t.state.reelOrigin===`masonry`||m.value,state:x.value,total:t.state.total,onActivate:V,onError:(0,e.unref)(C),onLoadMore:r[7]||=e=>s(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(w),onRetryEnd:r[8]||=e=>s(`retryEnd`),onVisible:(0,e.unref)(S)},null,8,[`can-retry-end`,`entering-post-ids`,`entry-delays`,`leaving-post-ids`,`removal-delays`,`card-footer`,`card-header`,`feed-footer`,`feed-footer-actions`,`media-card`,`masonry`,`has-next`,`infinite-scroll`,`is-loading-more`,`items`,`load-more-locked`,`media-indices`,`next-page-error`,`preview-states`,`suspended`,`state`,`total`,`onError`,`onReady`,`onVisible`]),(0,e.createVNode)(e.Transition,{name:`vibe-reel-viewer`,onAfterLeave:ne},{default:(0,e.withCtx)(()=>[t.state.reelOrigin===`masonry`?((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{key:0,ref_key:`reelOverlay`,ref:d,class:`vibe-reel-overlay`,role:`dialog`,"aria-label":`Media viewer`,"aria-modal":`true`,tabindex:`-1`,style:(0,e.normalizeStyle)(p.value)},[(0,e.createVNode)(at,{ref_key:`reelRenderer`,ref:u,"can-retry-end":t.canRetryEnd,"card-footer":t.cardFooter,"card-header":t.cardHeader,"feed-footer":t.feedFooter,"feed-footer-actions":t.feedFooterActions,"forward-index":t.state.reelForwardIndex,"forward-item":t.state.reelForwardItem,"media-card":t.mediaCard,"has-next":t.state.next!==null,"infinite-scroll":t.state.infiniteScroll,"initial-post-id":t.state.activeReelPostId,"info-sheet":t.reelInfoSheet,"info-sheet-enabled":t.state.reelInfoSheet.enabled,"info-sheet-overlay":t.state.reelInfoSheetOverlay,"is-loading-more":t.state.isLoadingMore,items:t.state.items,"load-more-locked":t.state.loadMoreLocked,"media-indices":t.state.mediaIndices,"media-source":`original`,"next-page-error":!!t.state.nextPageError,origin:`masonry`,"preview-states":(0,e.unref)(D),"reel-auto-advance":t.state.reelAutoAdvance,"reel-forward":t.state.reelForward,state:x.value,total:t.state.total,onActiveChange:r[9]||=e=>s(`activeReelChange`,e),onCloseInfoSheet:r[10]||=e=>s(`reelInfoSheetChange`,!1),onError:(0,e.unref)(T),onLoadMore:r[11]||=e=>s(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(E),onRetryEnd:r[12]||=e=>s(`retryEnd`),onRetryForward:r[13]||=e=>s(`retryForward`)},null,8,`can-retry-end.card-footer.card-header.feed-footer.feed-footer-actions.forward-index.forward-item.media-card.has-next.infinite-scroll.initial-post-id.info-sheet.info-sheet-enabled.info-sheet-overlay.is-loading-more.items.load-more-locked.media-indices.next-page-error.preview-states.reel-auto-advance.reel-forward.state.total.onError.onReady`.split(`.`))],4)):(0,e.createCommentVNode)(``,!0)]),_:1})],64))],512))}});function X(e){if(!e||typeof e!=`object`||!Array.isArray(e.items))throw TypeError(`Vibe loadPage must resolve to a page with an items array.`);if(e.current!==void 0&&e.current!==null&&typeof e.current!=`string`&&typeof e.current!=`number`)throw TypeError(`Vibe page current must be a string, number, null, or undefined.`);if(e.next!==null&&typeof e.next!=`string`&&typeof e.next!=`number`)throw TypeError(`Vibe page next must be a string, number, or null.`);if(e.total!==void 0&&(!Number.isFinite(e.total)||e.total<0))throw TypeError(`Vibe page total must be a non-negative number when provided.`);return e}function Z(e,t){let n=new Set(e.map(e=>e.postId));return[...e,...t.filter(e=>n.has(e.postId)?!1:(n.add(e.postId),!0))]}function gt(e){return`${typeof e}:${String(e)}`}function _t(e){return e.mediaId===void 0?`source:${e.src}\u0000${e.preview.src}`:`id:${gt(e.mediaId)}`}function vt(e,t){let n=[...e],r=new Map(e.map((e,t)=>[gt(e.postId),t]));return t.forEach(e=>{let t=gt(e.postId),i=r.get(t);if(i===void 0){r.set(t,n.length),n.push(e);return}let a=n[i],o=new Set([a,...a.items].map(_t)),s=[e,...e.items].filter(e=>{let t=_t(e);return o.has(t)?!1:(o.add(t),!0)});s.length>0&&(n[i]={...a,items:[...a.items,...s]})}),n}function yt(e){return Object.prototype.hasOwnProperty.call(e,`current`)?e.current??null:e.next}function bt(e,t,n,r){let i=X(e),a=n.filterItems(i.items),o=yt(i);t.items=vt(t.items,a),t.next=i.next,i.total!==void 0&&(t.total=i.total),r(o),n.recordPages([{contributionIds:a.map(({postId:e})=>e),cursor:o,next:i.next,returnedIds:a.map(({postId:e})=>e)}])}var xt=2e3,St=1e4,Ct=250,wt={delayRemainingMs:null,nextRequestAt:null};function Tt(e,t){return e===void 0?t:Math.floor(e)}function Et(e,t){for(let[n,r]of[[`delayStepMs`,e.delayStepMs],[`delayMaxMs`,e.delayMaxMs]])if(r!==void 0&&(!Number.isFinite(r)||r<0))throw TypeError(`Vibe ${t} ${n} must be a non-negative number.`)}function Dt(e,t={}){let n=Tt(t.delayStepMs,xt),r=Tt(t.delayMaxMs,St);return Math.min(Math.max(0,e)*n,r)}function Q(e){if(e==null||!Number.isFinite(e))return{...wt};let t=Math.max(0,Math.floor(e-Date.now()));return t>0?{delayRemainingMs:t,nextRequestAt:e}:{...wt}}async function Ot({delayMs:e,onChange:t,signal:n}){if(n.aborted)throw new DOMException(`Aborted`,`AbortError`);if(e<=0){t({...wt});return}let r=Date.now()+e;t({delayRemainingMs:e,nextRequestAt:r}),await new Promise((i,a)=>{let o=!1,s=setInterval(f,Ct),c=setTimeout(()=>u(),e);function l(){clearInterval(s),clearTimeout(c),n.removeEventListener(`abort`,d),t({...wt})}function u(e){o||(o=!0,l(),e?a(e):i())}function d(){u(new DOMException(`Aborted`,`AbortError`))}function f(){let e=Q(r);t(e),e.delayRemainingMs===null&&u()}n.addEventListener(`abort`,d,{once:!0})})}var kt=class{interval=null;constructor(e){this.onChange=e}clear(){this.interval!==null&&clearInterval(this.interval),this.interval=null,this.onChange({...wt})}sync(e){this.clear();let t=Q(e);this.onChange(t),t.delayRemainingMs!==null&&(this.interval=setInterval(()=>{let t=Q(e);this.onChange(t),t.delayRemainingMs===null&&this.clear()},Ct))}};function At(e,t=!0){return e.maxAdditionalPages===`unlimited`?1/0:(e.maxAdditionalPages??10)+(t?1:0)}function jt(e){return`${typeof e}:${String(e)}`}function Mt(e,t){if(!Number.isInteger(e)||e<=0)throw TypeError(`Vibe ${t} must be a positive integer.`)}function Nt(e){if(!e)return;if(Mt(e.pageSize,`autofill pageSize`),e.strategy===`frontend`){Et(e,`frontend autofill`);let t=e.maxAdditionalPages;if(t!==void 0&&t!==`unlimited`&&(!Number.isInteger(t)||t<0))throw TypeError(`Vibe autofill maxAdditionalPages must be a non-negative integer or "unlimited".`);return}if(!e.feedKey.trim())throw TypeError(`Vibe backend autofill requires a feedKey.`);let t=e.initialSession;if(t){if(t.feedKey!==e.feedKey)throw TypeError(`Vibe backend autofill initialSession feedKey must match autofill feedKey.`);if(t.pageSize!==e.pageSize)throw TypeError(`Vibe backend autofill initialSession pageSize must match autofill pageSize.`)}}function Pt(e,t,n=!0){if(!e)return{cycleId:null,delayRemainingMs:null,enabled:!1,error:null,feedKey:null,missing:0,nextRequestAt:null,pageSize:null,received:0,requests:0,sequence:0,sessionId:null,status:`idle`,strategy:null};let r=e.strategy===`backend`?t??(n?e.initialSession:void 0):void 0,i=r?.received??0,a=Q(r?.nextRequestAt);return{cycleId:r?.cycleId??null,...a,enabled:!0,error:r?.error??null,feedKey:e.strategy===`backend`?e.feedKey:null,missing:Math.max(0,e.pageSize-i),pageSize:e.pageSize,received:i,requests:r?.requests??0,sequence:r?.sequence??0,sessionId:r?.sessionId??null,status:r?r.status:`idle`,strategy:e.strategy}}function Ft(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function It(e,t,n){let r=t.autofill;if(!Ft(r)||!r.cycleId)return;let i={cycleId:r.cycleId,feedKey:r.feedKey??``,sessionId:r.sessionId};n(),r.status=`cancelling`;try{e?.strategy===`backend`&&await e.onCancel(i),r.error=null,r.status=`cancelled`}catch(e){throw r.error=e,r.status=`error`,e}}function Lt(e,t,n){return e?.strategy===`backend`&&t.feedKey===e.feedKey&&t.sessionId===n.sessionId}async function Rt({existingItems:e,initialCursor:t,loadPage:n,maximumRequests:r,onCollection:i,onDelayChange:a,onProgress:o,options:s,receivedOffset:c=0,requestOffset:l=0,shouldPause:u=()=>!1,signal:d}){let f=[],p=[...e],m=new Set,h=r??At(s),g=t,_=t,v=t,y=0,b=[],x;for(;y<h;){let e=jt(g);if(m.has(e))throw Error(`Vibe autofill received a repeated cursor.`);if(m.add(e),await Ot({delayMs:Dt(l+y,s),onChange:a,signal:d}),y>0&&u())return{items:f,lastCursor:_,missing:Math.max(0,s.pageSize-c-f.length),next:v,pages:b,received:c+f.length,requests:l+y,status:`paused`,total:x};let t=X(await n({cursor:g,signal:d}));y+=1,_=g;let r=Z(p,t.items).slice(p.length);b.push({contributionIds:r.map(({postId:e})=>e),cursor:g,next:t.next,returnedIds:t.items.map(({postId:e})=>e)}),p.push(...r),f.push(...r),v=t.next,t.total!==void 0&&(x=t.total);let h={missing:Math.max(0,s.pageSize-c-f.length),next:v,received:c+f.length,requests:l+y};o(h);let S={...h,items:[...f],lastCursor:_,pages:[...b],total:x};if(i(S),h.missing===0)return{...S,pages:b,status:`complete`};if(v===null)return{...S,pages:b,status:`exhausted`};if(u())return{...S,pages:b,status:`paused`};g=v}return{items:f,lastCursor:_,missing:Math.max(0,s.pageSize-c-f.length),next:v,pages:b,received:c+f.length,requests:l+y,status:`exhausted`,total:x}}var zt=class{collection=null;cycle=0;delayCountdown;constructor(e){this.context=e,this.delayCountdown=new kt(t=>Object.assign(e.state.autofill,t)),this.syncCountdown()}beginCycle(){let{options:e,state:t}=this.context;if(!e)return``;this.clear();let n=`vibe-autofill-${Date.now().toString(36)}-${++this.cycle}`;return t.autofill={...Pt(e,void 0,!1),cycleId:n,status:`filling`},n}async cancel(){let{cancelRequest:e,options:t,state:n}=this.context;await It(t,n,e),this.commitCollection()}captureCollection(e,t){t&&(this.collection=e)}clear(){this.delayCountdown.clear(),this.collection=null}clearCountdown(){this.delayCountdown.clear()}clearCollection(){this.collection=null}syncCountdown(){let{autofill:e}=this.context.state;this.delayCountdown.sync(e.strategy===`backend`&&e.status===`waiting`?e.nextRequestAt:null)}commitCollection(){let{onLastCursor:e,options:t,state:n}=this.context;if(t?.strategy!==`frontend`)return!1;let r=this.collection;return this.collection=null,r?(n.items=Z(n.items,r.items),e(r.lastCursor),this.context.onPages(r.pages),n.next=r.next,r.total!==void 0&&(n.total=r.total),Object.assign(n.autofill,{missing:r.missing,received:r.received,requests:r.requests}),!0):!1}},Bt=100;function Vt(e,t){if(!Number.isFinite(t)||t<=0)throw TypeError(`Vibe ${e} must be a positive number.`)}function Ht(e,t,n){return Math.min(n,Math.max(t,e))}function Ut(e){if(!e)return;let t=e.minSpeedPxPerSecond??20,n=e.maxSpeedPxPerSecond??240;if(Vt(`autoScroll.minSpeedPxPerSecond`,t),Vt(`autoScroll.maxSpeedPxPerSecond`,n),t>n)throw TypeError(`Vibe autoScroll.minSpeedPxPerSecond cannot exceed maxSpeedPxPerSecond.`);e.speedPxPerSecond!==void 0&&Vt(`autoScroll.speedPxPerSecond`,e.speedPxPerSecond)}function Wt(e){let t=e?.minSpeedPxPerSecond??20,n=e?.maxSpeedPxPerSecond??240;return{enabled:e?.enabled??!1,maxSpeedPxPerSecond:n,minSpeedPxPerSecond:t,paused:!1,speedPxPerSecond:Ht(e?.speedPxPerSecond??80,t,n)}}var Gt=class{frame=null;lastTimestamp=null;mounted=!1;constructor(e){this.options=e}mount(){this.mounted=!0,this.schedule()}destroy(){this.mounted=!1,this.cancelFrame()}setEnabled(e,t){t!==void 0&&this.setSpeed(t),this.options.state.enabled=e,this.options.state.paused=!1,this.lastTimestamp=null,e?this.schedule():this.cancelFrame()}setPaused(e){this.options.state.enabled&&(this.options.state.paused=e,this.lastTimestamp=null,e?this.cancelFrame():this.schedule())}setSpeed(e){Vt(`auto-scroll speed`,e);let t=this.options.state;t.speedPxPerSecond=Ht(e,t.minSpeedPxPerSecond,t.maxSpeedPxPerSecond)}tick=e=>{this.frame=null;let t=this.options.state;if(!this.mounted||!t.enabled)return;let n=t.paused?null:this.options.getScrollElement();if(!n){this.lastTimestamp=null,this.schedule();return}if(this.lastTimestamp!==null){let r=Math.min(Bt,Math.max(0,e-this.lastTimestamp)),i=Math.max(0,n.scrollHeight-n.clientHeight);n.scrollTop=Math.min(i,n.scrollTop+t.speedPxPerSecond*r/1e3)}this.lastTimestamp=e,this.schedule()};schedule(){!this.mounted||!this.options.state.enabled||this.frame!==null||typeof requestAnimationFrame==`function`&&(this.frame=requestAnimationFrame(this.tick))}cancelFrame(){this.frame!==null&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(this.frame),this.frame=null,this.lastTimestamp=null}};async function Kt(e,t,n,r){let i=await e.onUnderfilled(n);if(!r())return;if(!i.sessionId.trim())throw TypeError(`Vibe backend autofill requires a sessionId.`);let a=Math.max(n.received,i.received??n.received);Object.assign(t.autofill,{...Q(i.nextRequestAt),missing:Math.max(0,e.pageSize-a),received:a,sequence:i.sequence??0,sessionId:i.sessionId,status:`waiting`})}function qt(e,t){[`complete`,`exhausted`].includes(t.status)&&t.items&&(e.items=Z(e.items,t.items)),t.next!==void 0&&(e.next=t.next),t.total!==void 0&&(e.total=t.total)}function Jt(e,t,n){let r=t.autofill;return!Lt(e,n,r)||n.sequence<=r.sequence||[`cancelled`,`cancelling`].includes(r.status)||[`complete`,`exhausted`].includes(n.status)&&n.next===void 0?!1:(qt(t,n),Object.assign(r,Q(n.status===`waiting`?n.nextRequestAt:null)),r.error=n.error??null,r.missing=Math.max(0,(r.pageSize??0)-n.received),r.received=n.received,n.requests!==void 0&&(r.requests=n.requests),r.sequence=n.sequence,r.status=n.status,!0)}function Yt(e,t,n){return e?.strategy!==`backend`||n.feedKey!==e.feedKey||n.pageSize!==e.pageSize?!1:(t.autofill=Pt(e,n),qt(t,n),!0)}async function Xt(e,t,n){if(!e)return;let r=new AbortController;n(r);try{await e({appendPage:t,signal:r.signal})}finally{n(null)}}async function Zt({cycleId:e,isCurrent:t,onCollection:n,onLastCursor:r,onPages:i,options:a,signal:o,state:s}){let c=a.autofill;if(!c)return;let l=s.items.length;if(Object.assign(s.autofill,{missing:Math.max(0,c.pageSize-l),received:l,requests:1}),l>=c.pageSize){s.autofill.status=`complete`;return}if(c.strategy===`backend`){await Kt(c,s,{cycleId:e,feedKey:c.feedKey,items:[...s.items],missing:c.pageSize-l,next:s.next,pageSize:c.pageSize,received:l,signal:o,total:s.total},t);return}if(!a.loadPage||s.next===null){s.autofill.status=`exhausted`;return}let u=await Rt({existingItems:s.items,initialCursor:s.next,loadPage:a.loadPage,maximumRequests:At(c,!1),onCollection:n,onDelayChange:e=>{t()&&Object.assign(s.autofill,e)},onProgress:e=>{t()&&Object.assign(s.autofill,e,{status:`filling`})},options:c,receivedOffset:l,requestOffset:1,shouldPause:()=>s.loadMoreLocked,signal:o});t()&&(s.items=Z(s.items,u.items),s.next=u.next,u.total!==void 0&&(s.total=u.total),r(u.lastCursor),i(u.pages),Object.assign(s.autofill,{missing:u.missing,received:u.received,requests:u.requests,status:u.status}))}function Qt(e){return`items`in e?{items:e.items}:`pages`in e?{pages:e.pages}:{until:`end`}}function $t(e){return`${typeof e}:${String(e)}`}function en(e){if(!e||typeof e!=`object`)throw TypeError(`Vibe fill target must be an object.`);if(`pages`in e){if(!Number.isInteger(e.pages)||e.pages<=0)throw TypeError(`Vibe fill pages must be a positive integer.`);return{pages:e.pages}}if(`items`in e){if(!Number.isInteger(e.items)||e.items<=0)throw TypeError(`Vibe fill items must be a positive integer.`);return{items:e.items}}if(`until`in e&&e.until===`end`)return{until:`end`};throw TypeError(`Vibe fill target must be { items }, { pages }, or { until: 'end' }.`)}function tn(e){if(!e)return;if(e.strategy===`frontend`){Et(e,`frontend fill`);return}if(!e.feedKey.trim())throw TypeError(`Vibe backend fill requires a feedKey.`);let t=e.initialSession;if(t){if(t.feedKey!==e.feedKey)throw TypeError(`Vibe backend fill initialSession feedKey must match fill feedKey.`);en(t.target)}}function nn(e,t,n=!0){let r=e?.strategy===`backend`&&n?e.initialSession:void 0,i=t??r,a=Q(i?.nextRequestAt);return{completedPages:i?.completedPages??0,cycleId:i?.cycleId??null,...a,enabled:!!e,error:i?.error??null,feedKey:e?.strategy===`backend`?e.feedKey:null,received:i?.received??0,sequence:i?.sequence??0,sessionId:i?.sessionId??null,status:i?.status??`idle`,strategy:e?.strategy??null,target:i?Qt(i.target):null}}function rn(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function an({existingItems:e,initialCursor:t,loadPage:n,onCollection:r=()=>void 0,onDelayChange:i,onProgress:a,options:o,shouldPause:s=()=>!1,signal:c,target:l}){let u=[],d=[],f=[...e],p=new Set,m=0,h=t,g=t,_=t,v=0,y;if(`items`in l&&f.length>=l.items)return{completedPages:m,items:u,lastCursor:g,next:_,pages:d,received:v,status:`complete`};for(;_!==null;){let e=$t(h);if(p.has(e))throw Error(`Vibe fill received a repeated cursor.`);if(p.add(e),await Ot({delayMs:Dt(m,o),onChange:i,signal:c}),m>0&&s())return{completedPages:m,items:u,lastCursor:g,next:_,pages:d,received:v,status:`paused`,total:y};let t=X(await n({cursor:h,signal:c}));m+=1,g=h;let b=Z(f,t.items).slice(f.length);if(d.push({contributionIds:b.map(({postId:e})=>e),cursor:h,next:t.next,returnedIds:t.items.map(({postId:e})=>e)}),f.push(...b),u.push(...b),v=u.length,_=t.next,t.total!==void 0&&(y=t.total),a({completedPages:m,next:_,received:v}),r({completedPages:m,items:[...u],lastCursor:h,next:_,pages:[...d],received:v,total:y}),`items`in l&&f.length>=l.items||`pages`in l&&m>=l.pages)return{completedPages:m,items:u,lastCursor:h,next:_,pages:d,received:v,status:`complete`,total:y};if(_===null)return{completedPages:m,items:u,lastCursor:h,next:_,pages:d,received:v,status:`until`in l?`complete`:`exhausted`,total:y};if(s())return{completedPages:m,items:u,lastCursor:h,next:_,pages:d,received:v,status:`paused`,total:y};h=_}return{completedPages:m,items:u,lastCursor:h,next:null,pages:d,received:v,status:`until`in l?`complete`:`exhausted`,total:y}}async function on(e,t,n,r){let i=await e.onStart(n);if(r()){if(!i.sessionId.trim())throw TypeError(`Vibe backend fill requires a sessionId.`);Object.assign(t.fill,{...Q(i.nextRequestAt),completedPages:i.completedPages??0,received:i.received??0,sequence:i.sequence??0,sessionId:i.sessionId,status:`waiting`})}}function sn(e,t,n){return e?.strategy===`backend`&&n.feedKey===e.feedKey&&n.sessionId===t.fill.sessionId}function cn(e){return Number.isInteger(e.completedPages)&&e.completedPages>=0&&Number.isInteger(e.received)&&e.received>=0&&Number.isInteger(e.sequence)&&e.sequence>=0}function ln(e,t){if(![`complete`,`exhausted`].includes(t.status))return!0;let n=e.fill.target;return!n||!Array.isArray(t.items)||t.next===void 0||t.lastCursor===void 0?!1:t.status===`exhausted`?`pages`in n&&t.completedPages<n.pages&&t.next===null:`pages`in n?t.completedPages===n.pages:t.next===null}function un(e,t,n){t.total!==void 0&&(e.total=t.total),[`complete`,`exhausted`].includes(t.status)&&(e.items=Z(e.items,t.items??[]),e.next=t.next??null,n(t.lastCursor??null))}function dn(e,t,n,r){return!sn(e,t,n)||!cn(n)||n.sequence<=t.fill.sequence||[`cancelled`,`cancelling`].includes(t.fill.status)||!ln(t,n)?!1:(un(t,n,r),Object.assign(t.fill,{...Q(n.status===`waiting`?n.nextRequestAt:null),completedPages:n.completedPages,error:n.error??null,received:n.received,sequence:n.sequence,status:n.status}),!0)}function fn(e,t,n,r){if(e?.strategy!==`backend`||n.feedKey!==e.feedKey)return!1;let i=t.fill;return t.fill=nn(e,n),!cn(n)||!ln(t,n)?(t.fill=i,!1):(un(t,n,r),!0)}var pn=class{abortController=null;cycle=0;delayCountdown;requestVersion=0;collection=null;constructor(e){this.options=e,this.delayCountdown=new kt(e=>{Object.assign(this.options.state.fill,e)}),this.syncBackendCountdown()}isActive(){return rn(this.options.state.fill)}applyUpdate(e){let t=dn(this.options.fill,this.options.state,e,this.options.onLastCursor);return t&&this.syncBackendCountdown(),t}restoreSession(e){let t=fn(this.options.fill,this.options.state,e,this.options.onLastCursor);return t&&this.syncBackendCountdown(),t}async start(e,t={}){let n=this.options.fill;if(!n)throw Error(`Vibe fill is not configured.`);if(this.isActive())throw Error(`Vibe fill is already active.`);let r=en(e),i=en(t.target??r),a=t.progressOffset??{completedPages:0,received:0},o=t.cycleId??`vibe-fill-${Date.now().toString(36)}-${++this.cycle}`;if(this.options.state.fill={...nn(n,void 0,!1),completedPages:a.completedPages,cycleId:o,received:a.received,status:`filling`,target:i},n.strategy===`backend`&&this.options.state.next===null){this.options.state.fill.status=`until`in r?`complete`:`exhausted`;return}let s=++this.requestVersion,c=new AbortController;this.abortController=c;try{n.strategy===`frontend`?await this.startFrontend(n,r,c,s,t.prepareFrontend!==!1,a):(await on(n,this.options.state,{cycleId:o,feedKey:n.feedKey,items:[...this.options.state.items],next:this.options.state.next,signal:c.signal,target:r,total:this.options.state.total},()=>this.isCurrent(s)),this.syncBackendCountdown())}catch(e){if(c.signal.aborted||!this.isCurrent(s))return;throw this.commitCollection(),this.options.state.fill.error=e,this.options.state.fill.status=`error`,e}finally{this.isCurrent(s)&&(this.abortController=null,this.options.state.isLoadingMore=!1)}}async cancel(){let{fill:e,state:t}=this.options;if(!rn(t.fill)||!t.fill.cycleId)return;let n={cycleId:t.fill.cycleId,feedKey:t.fill.feedKey??``,sessionId:t.fill.sessionId};t.fill.status=`cancelling`,this.delayCountdown.clear(),this.abortController?.abort(),this.requestVersion+=1,this.abortController=null,t.isLoadingMore=!1,this.commitCollection();try{e?.strategy===`backend`&&await e.onCancel(n),t.fill.error=null,t.fill.status=`cancelled`}catch(e){throw t.fill.error=e,t.fill.status=`error`,e}}resume(e){let{fill:t}=this.options.state;if(t.status!==`paused`||!t.target)return Promise.resolve();let n=t.target,r=`pages`in n?n.pages-t.completedPages:null;if(r!==null&&r<=0)return t.status=`complete`,Promise.resolve();let i=r===null?n:{pages:r};return t.strategy===`backend`?this.start(i):this.start(i,{cycleId:t.cycleId??void 0,prepareFrontend:e,progressOffset:{completedPages:t.completedPages,received:t.received},target:n})}retry(e){let{fill:t}=this.options.state;if(t.status!==`error`||!t.target)return Promise.resolve();let n=t.target,r=`pages`in n?n.pages-t.completedPages:null;return r!==null&&r<=0?(t.status=`complete`,Promise.resolve()):this.start(r===null?n:{pages:r},{cycleId:t.cycleId??void 0,prepareFrontend:e,progressOffset:{completedPages:t.completedPages,received:t.received},target:n})}reset(){this.abortLocalRequest(),this.delayCountdown.clear(),this.options.state.fill=nn(this.options.fill,void 0,!1),this.collection=null}destroy(){this.abortLocalRequest(),this.delayCountdown.clear()}abortLocalRequest(){this.requestVersion+=1,this.abortController?.abort(),this.abortController=null,this.options.state.isLoadingMore=!1}isCurrent(e){return e===this.requestVersion&&![`cancelled`,`cancelling`].includes(this.options.state.fill.status)}async startFrontend(e,t,n,r,i,a){let o=this.options.loadPage;if(!o)throw Error(`Vibe frontend fill requires loadPage.`);let s=this.options.state;if(s.isLoadingMore=!0,i&&this.options.prepareFrontend&&(this.options.needsFrontendPreparation?.()??!0)){s.fill.status=`restoring`;let e=await this.options.prepareFrontend({isCurrent:()=>this.isCurrent(r),onDelayChange:e=>{this.isCurrent(r)&&Object.assign(s.fill,e)},signal:n.signal});if(!this.isCurrent(r))return;if(e===`paused`||s.loadMoreLocked){s.fill.status=`paused`;return}s.fill.status=`filling`}if(s.next===null){s.fill.status=`until`in t?`complete`:`exhausted`;return}let c=await an({existingItems:s.items,initialCursor:s.next,loadPage:o,onCollection:e=>{this.isCurrent(r)&&(this.collection={...e,completedPages:a.completedPages+e.completedPages,received:a.received+e.received},this.commitCollection())},onDelayChange:e=>{this.isCurrent(r)&&Object.assign(s.fill,e)},onProgress:e=>{this.isCurrent(r)&&Object.assign(s.fill,{...e,completedPages:a.completedPages+e.completedPages,received:a.received+e.received})},options:e,shouldPause:()=>s.loadMoreLocked,signal:n.signal,target:t});this.isCurrent(r)&&(s.items=Z(s.items,c.items),s.next=c.next,c.total!==void 0&&(s.total=c.total),this.options.onLastCursor(c.lastCursor),Object.assign(s.fill,{completedPages:a.completedPages+c.completedPages,received:a.received+c.received,status:c.status}),this.collection=null)}commitCollection(){let e=this.collection;if(this.collection=null,!e||this.options.fill?.strategy!==`frontend`)return;let t=this.options.state;t.items=Z(t.items,e.items),t.next=e.next,e.total!==void 0&&(t.total=e.total),this.options.onLastCursor(e.lastCursor),this.options.onPages(e.pages),Object.assign(t.fill,{completedPages:e.completedPages,received:e.received})}syncBackendCountdown(){let e=this.options.state.fill;this.delayCountdown.sync(e.strategy===`backend`&&e.status===`waiting`?e.nextRequestAt:null)}};async function mn({controller:e,isCurrent:t,loadPage:n,onDelayChange:r,setLastCursor:i,signal:a,state:o}){if(!e.needsReconciliation(o.items))return`skipped`;let s=await e.reconcile({existingItems:o.items,loadPage:n,onDelayChange:r,shouldPause:()=>o.loadMoreLocked,signal:a});return t()?(o.items=Z(o.items,s.items),o.next=s.next,i(s.lastCursor),s.total!==void 0&&(o.total=s.total),e.completeReconciliation(s),s.status):s.status}function hn(e){return{cancelAutofill:()=>e.cancelAutofill(),loadMore:()=>e.loadNext(),retry:()=>{let t=e.getState();return t.autofill.strategy===`frontend`&&t.autofill.status===`error`&&t.items.length>0&&t.next!==null?e.loadNext():e.reload()},retryEnd:()=>e.retryEnd(),retryFill:()=>e.retryFill()}}function gn(e){if(!Number.isFinite(e)||e<=0)throw TypeError(`Vibe reelAutoAdvance.intervalMs must be a positive number.`)}function _n(e){e?.intervalMs!==void 0&&gn(e.intervalMs)}function vn(e){return{enabled:e?.enabled??!1,includePostItems:e?.includePostItems??!1,intervalMs:e?.intervalMs??5e3}}function yn(e,t){if(typeof t==`boolean`){e.enabled=t;return}_n(t),t.enabled!==void 0&&(e.enabled=t.enabled),t.includePostItems!==void 0&&(e.includePostItems=t.includePostItems),t.intervalMs!==void 0&&(e.intervalMs=t.intervalMs)}function bn(e){return{enabled:e?.enabled??!1}}function xn(e,t,n){if(n&&!t)throw Error(`Vibe cannot enable reelInfoSheet without a configured component.`);e.enabled=n}function Sn(e,t){let n=e.initialPage;return{activeReelPostId:null,autoScroll:Wt(e.autoScroll),autofill:Pt(e.autofill),current:n?.current??null,error:null,fill:nn(e.fill),infiniteScroll:e.infiniteScroll??!0,isLoading:!n,isLoadingMore:!1,items:n?Z([],n.items):[],layout:t===`reel`?`reel`:`masonry`,loadMoreLocked:!1,mediaIndices:new Map,next:n?.next??null,nextPageError:null,phoneMode:!1,reelAutoAdvance:vn(e.reelAutoAdvance),reelForward:{error:null,status:`idle`},reelForwardIndex:null,reelForwardItem:null,reelInfoSheet:bn(e.reelInfoSheet),reelInfoSheetOverlay:!1,reelMediaSource:`original`,reelOrigin:null,total:n?.total??null}}function Cn(e,t){if(t){if(!Number.isFinite(t.height)||t.height<=0)throw TypeError(`Vibe ${e} height must be a positive number.`);if(t.background!==void 0&&t.background!==`default`&&t.background!==`transparent`)throw TypeError(`Vibe ${e} background must be "default" or "transparent".`)}}function wn(e,t){if(t){if(t.background!==void 0&&t.background!==`default`&&t.background!==`transparent`)throw TypeError(`Vibe mediaCard ${e} background must be "default" or "transparent".`);for(let[n,r]of[[`paddingX`,t.paddingX],[`paddingY`,t.paddingY]])if(r!==void 0&&(!Number.isFinite(r)||r<0))throw TypeError(`Vibe mediaCard ${e} ${n} must be a non-negative number.`)}}function Tn(e){if(Ut(e.autoScroll),Cn(`cardHeader`,e.cardHeader),Cn(`cardFooter`,e.cardFooter),wn(`header`,e.mediaCard?.header),wn(`footer`,e.mediaCard?.footer),Nt(e.autofill),tn(e.fill),k(e.masonry),_n(e.reelAutoAdvance),e.removalReconciliation){if(!Number.isInteger(e.removalReconciliation.pageSize)||e.removalReconciliation.pageSize<=0)throw TypeError(`Vibe removalReconciliation pageSize must be a positive integer.`);let t=e.removalReconciliation.maxReplayPages??5;if(!Number.isInteger(t)||t<=0)throw TypeError(`Vibe removalReconciliation maxReplayPages must be a positive integer.`);if(!e.loadPage)throw TypeError(`Vibe removalReconciliation requires loadPage.`);if(e.autofill?.strategy===`backend`)throw TypeError(`Vibe removalReconciliation does not support backend autofill.`);if(e.autofill?.strategy===`frontend`&&e.autofill.pageSize<e.removalReconciliation.pageSize)throw TypeError(`Vibe autofill pageSize must be greater than or equal to removalReconciliation pageSize.`);if(e.fill?.strategy===`backend`)throw TypeError(`Vibe removalReconciliation does not support backend fill.`)}if(e.removalHistoryLimit!==void 0&&(!Number.isInteger(e.removalHistoryLimit)||e.removalHistoryLimit<0))throw TypeError(`Vibe removalHistoryLimit must be a non-negative integer.`);if(!e.initialPage&&!e.loadPage)throw TypeError(`Vibe requires either initialPage or loadPage.`);if(e.initialPage?.next!==null&&!e.loadPage)throw TypeError(`Vibe requires loadPage when initialPage has a next cursor.`);if(e.fill?.strategy===`frontend`&&!e.loadPage)throw TypeError(`Vibe frontend fill requires loadPage.`);if(e.fill?.strategy===`backend`&&e.fill.initialSession&&!e.initialPage)throw TypeError(`Vibe backend fill restoration requires initialPage.`)}function En(e){if(typeof e!=`string`)return e;if(typeof document>`u`)throw Error(`Vibe cannot resolve a selector without a document.`);let t=document.querySelector(e);if(!t)throw Error(`Vibe target not found: ${e}`);return t}async function Dn({append:e,autofillController:t,cursor:n,isCurrent:r,loadPage:i,onLastCursor:a,onPages:o,options:s,signal:c,state:l}){let u=s.autofill,d=e&&u?.strategy===`frontend`&&(l.autofill.status===`paused`||l.autofill.status===`error`),f=d?{received:l.autofill.received,requests:l.autofill.requests}:null,p=u?d?l.autofill.cycleId:t.beginCycle():null;d&&Object.assign(l.autofill,{error:null,status:`filling`});let m=!1;try{if(u?.strategy===`frontend`){let s=await Rt({existingItems:e?l.items:[],initialCursor:n,loadPage:i,maximumRequests:f?Math.max(0,At(u)-f.requests):void 0,onCollection:e=>t.captureCollection(e,r()),onDelayChange:e=>{r()&&Object.assign(l.autofill,e)},onProgress:e=>{r()&&Object.assign(l.autofill,e,{status:`filling`})},options:u,receivedOffset:f?.received,requestOffset:f?.requests,shouldPause:()=>l.loadMoreLocked,signal:c});if(!r())return;l.items=e?Z(l.items,s.items):[...s.items],a(s.lastCursor),l.next=s.next,s.total!==void 0&&(l.total=s.total),Object.assign(l.autofill,{missing:s.missing,received:s.received,requests:s.requests,status:s.status}),o(s.pages),t.clearCollection();return}let s=X(await i({cursor:n,signal:c}));if(!r())return;let d=e?l.items:[],h=Z(d,s.items),g=h.length-d.length;if(l.items=h,a(n),o([{contributionIds:h.slice(d.length).map(({postId:e})=>e),cursor:n,next:s.next,returnedIds:s.items.map(({postId:e})=>e)}]),l.next=s.next,s.total!==void 0&&(l.total=s.total),m=!0,u?.strategy===`backend`&&p){if(Object.assign(l.autofill,{missing:Math.max(0,u.pageSize-g),received:g,requests:1}),g>=u.pageSize){l.autofill.status=`complete`;return}await Kt(u,l,{cycleId:p,feedKey:u.feedKey,items:h.slice(d.length),missing:u.pageSize-g,next:s.next,pageSize:u.pageSize,received:g,signal:c,total:l.total},r),t.syncCountdown()}}catch(n){if(c.aborted||!r())return;let i=u?.strategy===`frontend`?t.commitCollection():!1;u&&(l.autofill.error=n,l.autofill.status=`error`),m||(e||i?l.nextPageError=n:l.error=n)}finally{r()&&(t.clearCollection(),l.isLoading=!1,l.isLoadingMore=!1)}}function $(e){return`${typeof e}:${String(e)}`}function On(e){return`${typeof e}:${String(e)}`}function kn(e){return e.map(({postId:e})=>e)}var An=class{delay;enabled;maxReplayPages;pageSize;pages=[];pending=null;tombstones=new Set;constructor(e){let t=e.removalReconciliation;this.enabled=!!t,this.maxReplayPages=t?.maxReplayPages??5,this.pageSize=t?.pageSize??0,this.delay=e.autofill?.strategy===`frontend`?e.autofill:{delayMaxMs:0,delayStepMs:0}}completeReconciliation(e){e.status===`complete`&&(this.pages=[...this.pages.slice(0,e.replaceFrom),...e.pages].slice(-this.maxReplayPages),this.pending=null)}filterItems(e){return this.tombstones.size===0?[...e]:e.filter(({postId:e})=>!this.tombstones.has($(e)))}needsReconciliation(e){return this.pending!==null||this.findUnderfilledPage(e)>=0}hasPendingSession(){return this.pending!==null}recordPages(e){!this.enabled||e.length===0||(e.forEach(e=>this.recordPage(e)),this.pages=this.pages.slice(-this.maxReplayPages))}recordInitialPage(e){e&&this.recordPages([{contributionIds:kn(e.items),cursor:yt(e),next:e.next,returnedIds:kn(e.items)}])}remove(e){e.forEach(e=>this.tombstones.add($(e)))}reset(){this.pages=[],this.pending=null,this.tombstones.clear()}restore(e){e.forEach(e=>this.tombstones.delete($(e)))}async reconcile({existingItems:e,loadPage:t,onDelayChange:n=()=>void 0,shouldPause:r=()=>!1,signal:i}){let a=this.pending??this.createSession(e);for(this.pending=a;a.remainingRequests>0;){let e=On(a.cursor);if(a.seenCursors.has(e))throw Error(`Vibe removal reconciliation received a repeated cursor.`);if(await Ot({delayMs:Dt(a.pages.length,this.delay),onChange:n,signal:i}),a.pages.length>0&&r())return this.result(a,`paused`);let o=X(await t({cursor:a.cursor,signal:i}));a.seenCursors.add(e);let s=this.filterItems(o.items),c=[];if(s.forEach(e=>{let t=$(e.postId);a.attributed.has(t)||(a.attributed.add(t),c.push(e.postId)),a.appended.has(t)||(a.appended.add(t),a.items.push(e))}),a.pages.push({contributionIds:c,cursor:a.cursor,next:o.next,returnedIds:kn(s)}),a.lastCursor=a.cursor,a.next=o.next,--a.remainingRequests,o.total!==void 0&&(a.total=o.total),a.next===null?a.remainingRequests=0:a.cursor=a.next,a.remainingRequests>0&&r())return this.result(a,`paused`)}return this.result(a,`complete`)}createSession(e){let t=this.findUnderfilledPage(e),n=t<0?[]:this.pages.slice(t),r=n[0];if(!r)throw Error(`Vibe has no underfilled provider page to reconcile.`);let i=new Set(n.flatMap(({contributionIds:e})=>e.map($))),a=new Set(e.map(({postId:e})=>$(e)).filter(e=>!i.has(e)));return{appended:new Set(e.map(({postId:e})=>$(e))),attributed:new Set(a),cursor:r.cursor,items:[],lastCursor:r.cursor,next:r.cursor,pages:[],remainingRequests:n.length,replaceFrom:t,seenCursors:new Set}}result(e,t){return{items:[...e.items],lastCursor:e.lastCursor,next:e.next,pages:[...e.pages],replaceFrom:e.replaceFrom,status:t,total:e.total}}findUnderfilledPage(e){if(!this.enabled||this.pages.length===0)return-1;let t=new Set(e.map(({postId:e})=>$(e)));return this.pages.findIndex(({contributionIds:e})=>e.filter(e=>t.has($(e))).length<this.pageSize)}recordPage(e){let t=On(e.cursor),n=this.pages.findIndex(({cursor:e})=>On(e)===t);n>=0&&(this.pages=this.pages.slice(0,n)),this.pages.push({...e,contributionIds:[...e.contributionIds],returnedIds:[...e.returnedIds]})}};function jn(e,t,n,r,i){let a=new Set(t.map(({item:e})=>e.postId));if(e.activeReelPostId===null||!a.has(e.activeReelPostId))return;let o=e.items[Math.max(n,0)];if(o){r(o.postId);return}let s=t.find(({item:t})=>t.postId===e.activeReelPostId)?.item;s&&i(Math.max(n,0),s)}function Mn(e,t){let[n,...r]=t;if(!n)throw Error(`Vibe items must contain at least one media asset.`);return{...e,...n,items:r}}function Nn(e){if(!Number.isInteger(e.mediaIndex)||e.mediaIndex<0)throw TypeError(`Vibe mediaIndex must be a non-negative integer.`)}var Pn=class{generation=0;metadata=new WeakMap;state;constructor(e){this.options=e,this.state=e.state}remove(e){Nn(e);let t=this.state.items.findIndex(({postId:t})=>t===e.postId),n=this.state.items[t];if(!n)return null;let i=[...r(n)],a=i[e.mediaIndex];if(!a)return null;let o=Object.freeze({media:a,mediaIndex:e.mediaIndex,postId:e.postId,postIndex:t});this.metadata.set(o,{generation:this.generation,originalItem:n,restored:!1});let s=this.state.mediaIndices.get(n.postId)??0,c=this.isReelOpen()&&this.state.activeReelPostId===n.postId,l=c&&s===e.mediaIndex;return i.splice(e.mediaIndex,1),i.length>0?(this.state.items[t]=Mn(n,i),this.updateMediaIndexAfterRemoval(n.postId,e.mediaIndex,l),o):(this.state.items.splice(t,1),this.options.onPostRemoved(n.postId),this.state.mediaIndices.delete(n.postId),c&&this.advanceFromRemovedPost(o,n),o)}reset(){this.generation+=1}restore(e){let t=this.metadata.get(e);if(!t)throw TypeError(`Vibe media removal does not belong to this instance.`);if(t.generation!==this.generation||t.restored)return!1;t.restored=!0,this.options.onPostRestored(e.postId);let n=this.state.items.findIndex(({postId:t})=>t===e.postId);return n>=0?this.restoreIntoPost(n,e):this.state.items.splice(Math.min(e.postIndex,this.state.items.length),0,t.originalItem),this.options.reelForward.cancel(e)&&(this.state.mediaIndices.set(e.postId,e.mediaIndex),this.options.onActivate(e.postId)),!0}advanceFromRemovedPost(e,t){let n=this.state.items[e.postIndex];if(n){this.options.onActivate(n.postId);return}this.options.reelForward.start(e,e.postIndex,t)}isReelOpen(){return this.state.layout===`reel`||this.state.reelOrigin===`masonry`}restoreIntoPost(e,t){let n=this.state.items[e],i=[...r(n)],a=Math.min(t.mediaIndex,i.length);if(i.splice(a,0,t.media),this.state.items[e]=Mn(n,i),this.state.activeReelPostId!==t.postId)return;let o=this.state.mediaIndices.get(t.postId)??0;o>=a&&this.state.mediaIndices.set(t.postId,o+1)}updateMediaIndexAfterRemoval(e,t,n){let i=this.state.items.find(t=>t.postId===e);if(!i)return;let a=r(i).length,o=this.state.mediaIndices.get(e)??0,s=o;n?s=t<a?t:0:t<o&&(s=o-1),this.state.mediaIndices.set(e,Math.min(s,a-1))}};function Fn(e,t){let n=new Set(t);return e.flatMap((e,t)=>n.has(e.postId)?[{index:t,item:e}]:[])}function In(e,t){let n=new Set(t.map(({item:e})=>e.postId));return e.filter(e=>!n.has(e.postId))}function Ln(e,t){t.forEach(({index:e})=>{if(!Number.isInteger(e)||e<0)throw Error(`Vibe item restore indexes must be non-negative integers.`)});let n=[...e],r=new Set(e.map(e=>e.postId));return[...t].sort((e,t)=>e.index-t.index).forEach(({index:e,item:t})=>{r.has(t.postId)||(n.splice(Math.min(e,n.length),0,t),r.add(t.postId))}),n}var Rn=20,zn=class{generation=0;historyLimit;metadata=new WeakMap;state;history=[];itemOrder;stopItemsWatcher;constructor(t){this.options=t,this.historyLimit=t.historyLimit??Rn,this.state=t.state,this.itemOrder=this.state.items.map(({postId:e})=>e),this.stopItemsWatcher=(0,e.watch)(()=>this.state.items,e=>this.appendUnknownItems(e),{flush:`sync`})}destroy(){this.reset(),this.stopItemsWatcher()}async remove(e,t){if(t?.staggerMs!==void 0&&(!Number.isFinite(t.staggerMs)||t.staggerMs<0))throw TypeError(`Vibe item removal staggerMs must be a non-negative number.`);let n=this.collectOrderedPlacements(e),r=this.createRemoval(n);if(n.length===0)return r;let i=n.map(({item:e})=>e.postId);if(await this.options.prepareRemoval(i),this.metadata.get(r)?.generation!==this.generation)return r;let a=this.options.startRemoval(i,t);if(a>0&&await new Promise(e=>setTimeout(e,a)),this.metadata.get(r)?.generation!==this.generation)return r;let o=this.state.items.findIndex(e=>e.postId===this.state.activeReelPostId),s=new Set(n.map(({item:e})=>e.postId)),c=o<0?0:this.state.items.slice(0,o).filter(({postId:e})=>s.has(e)).length,l=Math.max(o-c,0);return this.state.items=In(this.state.items,n),this.options.onItemsRemoved(r,n,l),this.record(r),r}reset(){this.generation+=1,this.history=[],this.itemOrder=[]}restoreItems(e){let t=e;if(this.metadata.has(t)){this.restoreRemoval(t);return}let n=new Set(this.state.items.map(({postId:e})=>e)),r=e.filter(({item:e})=>n.has(e.postId)?!1:(n.add(e.postId),!0)),i=Ln(this.state.items,r);this.registerExternalPlacements(r),this.state.items=i,r.length>0&&this.options.onRemovalRestored(r)}restoreRemoval(e){let t=this.metadata.get(e);if(!t)throw TypeError(`Vibe removal does not belong to this instance.`);if(t.generation!==this.generation||t.restored)return!1;t.restored=!0,this.removeFromHistory(e);let n=this.restoreOrderedPlacements(e);return n&&this.options.onRemovalRestored(e),n}undoLast(){for(;this.history.length>0;){let e=this.history.pop();if(this.restoreRemoval(e))return e}return null}appendUnknownItems(e){let t=new Set(this.itemOrder);e.forEach(({postId:e})=>{t.has(e)||(this.itemOrder.push(e),t.add(e))})}collectOrderedPlacements(e){let t=new Map(this.itemOrder.map((e,t)=>[e,t]));return Fn(this.state.items,e).map(e=>({index:t.get(e.item.postId)??e.index,item:e.item}))}createRemoval(e){let t=Object.freeze(e.map(e=>Object.freeze({...e})));return this.metadata.set(t,{generation:this.generation,restored:e.length===0}),t}record(e){this.historyLimit!==0&&(this.history.push(e),this.history.length>this.historyLimit&&this.history.shift())}registerExternalPlacements(e){let t=new Set(this.itemOrder);[...e].sort((e,t)=>e.index-t.index).forEach(({index:e,item:n})=>{t.has(n.postId)||(this.itemOrder.splice(Math.min(e,this.itemOrder.length),0,n.postId),t.add(n.postId))})}removeFromHistory(e){let t=this.history.indexOf(e);t>=0&&this.history.splice(t,1)}restoreOrderedPlacements(e){let t=new Set(this.state.items.map(({postId:e})=>e)),n=e.map(({item:e})=>e).filter(({postId:e})=>!t.has(e));if(n.length===0)return!1;let r=new Map(this.itemOrder.map((e,t)=>[e,t]));return this.state.items=[...this.state.items,...n].sort((e,t)=>(r.get(e.postId)??2**53-1)-(r.get(t.postId)??2**53-1)),!0}},Bn=class{forward=null;forwardPromise=null;forwardVersion=0;state;constructor(e){this.options=e,this.state=e.state}start(e,t,n){this.forward={item:n,postIndex:t,token:e,version:++this.forwardVersion},this.state.reelForward={error:null,status:`loading`},this.state.reelForwardIndex=t,this.state.reelForwardItem=n,this.startForwardRequest()}cancel(e){if(this.forward?.token!==e||this.state.reelForward.status===`idle`)return null;let t=this.forward.item;return this.forwardVersion+=1,this.forward=null,this.clearState(),t}reset(){this.forwardVersion+=1,this.forward=null,this.forwardPromise=null,this.clearState()}retry(){return!this.forward||this.state.reelForward.status===`idle`?Promise.resolve():(this.state.nextPageError=null,this.state.reelForward={error:null,status:`loading`},this.startForwardRequest())}clearState(){this.state.reelForward={error:null,status:`idle`},this.state.reelForwardIndex=null,this.state.reelForwardItem=null}startForwardRequest(){if(this.forwardPromise)return this.forwardPromise;let e=this.loadForward();return this.forwardPromise=e,e.finally(()=>{this.forwardPromise===e&&(this.forwardPromise=null,this.forward&&this.state.reelForward.status===`loading`&&this.startForwardRequest())})}async loadForward(){let e=this.forward;if(e)for(;this.forward===e&&e.version===this.forwardVersion;){let t=this.state.items[e.postIndex];if(t){this.forward=null,this.clearState(),this.options.onActivate(t.postId);return}if(this.state.nextPageError){this.state.reelForward={error:this.state.nextPageError,status:`error`};return}let n=this.state.next,r=this.state.items.length;if(await this.options.replenishAfterRemoval(),this.state.nextPageError){this.state.reelForward={error:this.state.nextPageError,status:`error`};return}if(!this.state.items[e.postIndex]){if(this.state.next===null){this.state.reelForward={error:null,status:`end`};return}if(this.state.next===n&&this.state.items.length===r){this.state.reelForward={error:Error(`Vibe could not advance while page loading is unavailable.`),status:`error`};return}}}}},Vn=class{generation=0;pending=Promise.resolve();constructor(e){this.options=e}prepareItems(e){return this.serialize(()=>this.preparePosts(e))}prepareMedia(e){return this.serialize(async()=>{let{state:t}=this.options;if(!this.isReelActive()||t.activeReelPostId!==e.postId)return;let n=t.items.find(({postId:t})=>t===e.postId);if(!n)return;let i=t.mediaIndices.get(e.postId)??0;if(e.mediaIndex===i){if(r(n).length>1){await this.options.transitionMedia(1);return}await this.preparePosts([e.postId])}})}reset(){this.generation+=1,this.pending=Promise.resolve()}async preparePosts(e){let{state:t}=this.options,n=t.activeReelPostId,r=new Set(e);if(!this.isReelActive()||n===null||!r.has(n))return;let i=this.generation,a=t.items.findIndex(({postId:e})=>e===n);if(a<0)return;let o=this.nextSurvivor(a,r);o&&i===this.generation&&t.activeReelPostId===n&&await this.options.transitionPost(o.postId)}isReelActive(){let{state:e}=this.options;return e.layout===`reel`||e.reelOrigin===`masonry`}nextSurvivor(e,t){if(!(e<0))return this.options.state.items.slice(e+1).find(({postId:e})=>!t.has(e))}serialize(e){let t=this.pending.then(e,e);return this.pending=t.catch(()=>void 0),t}};function Hn(e){let t=new Bn(e),n=new Vn({state:e.state,transitionMedia:t=>e.surface()?.transitionActiveReelMedia(t)??Promise.resolve(!1),transitionPost:t=>e.surface()?.transitionActiveReelPost(t)??Promise.resolve(!1)});return{exactMediaRemoval:new Pn({onActivate:e.onActivate,onPostRemoved:t=>e.onItemsRemoved([t]),onPostRestored:t=>e.onItemsRestored([t]),reelForward:t,state:e.state}),itemRemoval:new zn({historyLimit:e.historyLimit,onItemsRemoved:(n,r,i)=>{e.onItemsRemoved(r.map(({item:e})=>e.postId)),jn(e.state,r,i,e.onActivate,(e,r)=>t.start(n,e,r))},onRemovalRestored:n=>{e.onItemsRestored(n.map(({item:e})=>e.postId));let r=t.cancel(n);r&&e.onActivate(r.postId)},prepareRemoval:e=>n.prepareItems(e),startRemoval:(t,n)=>e.surface()?.startItemRemoval(t,n)??0,state:e.state}),reelForward:t,reelRemoval:n}}var Un=1.5;function Wn(e){let t=Math.min(e.screenWidth,e.screenHeight);if(t>0&&t<600)return!0;let n=Math.min(e.viewportWidth,e.viewportHeight),r=t>=n*Un;return!e.hasHover&&n>0&&n<600&&r}function Gn(e){return Wn(e)?`reel`:`masonry`}function Kn(e){let t=e.ownerDocument.defaultView,n=e.ownerDocument.documentElement;return{hasHover:typeof t?.matchMedia==`function`&&t.matchMedia(`(hover: hover)`).matches,screenHeight:t?.screen.height??0,screenWidth:t?.screen.width??0,viewportHeight:n.clientHeight,viewportWidth:n.clientWidth}}function qn(e){return Wn(Kn(e))}function Jn(e){return Gn(Kn(e))}var Yn=class{layoutMode;resizeObserver=null;target=null;constructor(e,t,n){this.state=t,this.onFeedLayout=n,this.layoutMode=e}mount(e){this.target=e,this.handleResponsiveLayout();let t=e.ownerDocument.defaultView;t?.addEventListener(`resize`,this.handleResponsiveLayout);let n=t?.ResizeObserver??globalThis.ResizeObserver;n!==void 0&&(this.resizeObserver=new n(this.handleResponsiveLayout),this.resizeObserver.observe(e))}destroy(){this.target?.ownerDocument.defaultView?.removeEventListener(`resize`,this.handleResponsiveLayout),this.resizeObserver?.disconnect(),this.resizeObserver=null,this.target=null}setLayout(e){e!==this.layoutMode&&(this.layoutMode=e,e===`responsive`?this.handleResponsiveLayout():this.applyLayout(e))}applyLayout(e){e!==this.state.layout&&(e===`masonry`&&(this.state.activeReelPostId=null,this.onFeedLayout()),this.state.reelOrigin=null,this.state.layout=e)}handleResponsiveLayout=()=>{if(!this.target)return;let e=Jn(this.target);this.state.phoneMode=qn(this.target),this.state.reelInfoSheetOverlay=this.state.phoneMode,this.state.reelMediaSource=this.state.phoneMode?`mobile`:`original`,this.layoutMode===`responsive`&&this.applyLayout(e)}},Xn=class{routedReelPostId=null;reelRouteIsActive=!1;constructor(e,t){this.options=e,this.state=t}syncFeed(){if(!this.options||!this.reelRouteIsActive)return;this.reelRouteIsActive=!1,this.routedReelPostId=null;let e=typeof this.options.feed==`function`?this.options.feed():this.options.feed;this.options.router.replace(e)}syncReel(e){if(!this.options)return;let t=this.state.items.findIndex(t=>t.postId===e),n=this.state.items[t];if(!n||this.reelRouteIsActive&&this.routedReelPostId===e)return;let r=this.options.reel({index:t,item:n,loadedCount:this.state.items.length,origin:this.state.reelOrigin??`reel`,total:this.state.total});if(r===null)return;let i=this.reelRouteIsActive?`replace`:`push`;this.reelRouteIsActive=!0,this.routedReelPostId=e,this.options.router[i](r)}},Zn=class{app=null;autoScroll;autofillController;abortController=null;pendingRequest=null;requestVersion=0;restoreController=null;responsiveLayout;routing;fillController;exactMediaRemoval;itemRemoval;removalReconciliation;reelForward;reelRemoval;surface=null;stopStateWatcher=null;lastLoadedCursor=null;notificationItems;state;constructor(t){this.options=t,Tn(t);let n=t.layout??`masonry`;this.state=(0,e.reactive)(Sn(t,n)),this.lastLoadedCursor=t.initialPage?yt(t.initialPage):null,this.notificationItems=s(this.state),this.autoScroll=new Gt({getScrollElement:()=>this.surface?.getAutoScrollElement()??null,state:this.state.autoScroll}),this.autofillController=new zt({cancelRequest:()=>this.cancelRequest(),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:t.autofill,state:this.state}),this.removalReconciliation=new An(t),this.removalReconciliation.recordInitialPage(t.initialPage),this.fillController=new pn({fill:t.fill,loadPage:t.loadPage?e=>this.loadFilteredPage(e):void 0,needsFrontendPreparation:()=>this.removalReconciliation.needsReconciliation(this.state.items),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),prepareFrontend:({isCurrent:e,onDelayChange:n,signal:r})=>mn({controller:this.removalReconciliation,isCurrent:e,loadPage:t.loadPage,onDelayChange:n,setLastCursor:e=>this.setCurrentCursor(e),signal:r,state:this.state}),state:this.state}),this.routing=new Xn(t.routing,this.state);let r=Hn({historyLimit:t.removalHistoryLimit,onActivate:e=>this.setActiveReelPost(e),onItemsRemoved:e=>this.removalReconciliation.remove(e),onItemsRestored:e=>this.removalReconciliation.restore(e),replenishAfterRemoval:()=>this.replenishAfterRemoval(),state:this.state,surface:()=>this.surface});this.exactMediaRemoval=r.exactMediaRemoval,this.itemRemoval=r.itemRemoval,this.reelForward=r.reelForward,this.reelRemoval=r.reelRemoval,this.responsiveLayout=new Yn(n,this.state,()=>{this.routing.syncFeed()}),this.startStateNotifications()}async mount(){if(this.app)throw Error(`Vibe is already mounted.`);this.startStateNotifications();let t=En(this.options.target);this.responsiveLayout.mount(t),this.app=(0,e.createApp)(ht,{canRetryEnd:!!this.options.loadPage,cardFooter:this.options.cardFooter,cardHeader:this.options.cardHeader,feedFooter:this.options.feedFooter,feedFooterActions:hn(this),mediaCard:this.options.mediaCard,masonry:this.options.masonry,onMediaReady:this.options.onMediaReady,onMediaVisible:this.options.onMediaVisible,onReelMediaChange:this.options.onReelMediaChange,reelInfoSheet:this.options.reelInfoSheet,state:this.state,onActiveReelChange:e=>{this.state.reelForward.status===`idle`&&this.setActiveReelPost(e)},onCloseReel:()=>this.closeMasonryReel(),onLoadMore:()=>{this.loadNext()},onOpenReel:e=>this.openMasonryReel(e),onReelInfoSheetChange:e=>this.setReelInfoSheet(e),onRetryEnd:()=>{this.retryEnd()},onRetryForward:()=>{this.retryReelForward()}}),this.surface=this.app.mount(t),this.autoScroll.mount(),await Xt(this.options.restoreBacklog,e=>this.appendPage(e),e=>{this.restoreController=e}),!this.options.initialPage&&this.state.items.length===0?await this.reload():this.options.autofill&&this.state.autofill.status===`idle`&&!this.fillController.isActive()&&!this.state.loadMoreLocked&&await this.startInitialAutofill()}destroy(){this.restoreController?.abort(),this.restoreController=null,this.autoScroll.destroy(),this.fillController.destroy(),this.cancelRequest(),this.reelForward.reset(),this.reelRemoval.reset(),this.exactMediaRemoval.reset(),this.itemRemoval.destroy(),this.removalReconciliation.reset(),this.responsiveLayout.destroy(),this.stopStateWatcher?.(),this.stopStateWatcher=null,this.app?.unmount(),this.app=null,this.surface=null}getState(){return c(this.state)}removeMedia(e){return this.exactMediaRemoval.remove(e)}removeMediaAnimated(e){return this.reelRemoval.prepareMedia(e).then(()=>this.exactMediaRemoval.remove(e))}removeItems(e,t){return this.itemRemoval.remove(e,t)}restoreItems(e){this.itemRemoval.restoreItems(e)}restoreMediaRemoval(e){return this.exactMediaRemoval.restore(e)}restoreRemoval(e){return this.itemRemoval.restoreRemoval(e)}retryReelForward(){return this.reelForward.retry()}retryFill(){return this.fillController.retry(this.removalReconciliation.hasPendingSession())}undoLastRemoval(){return this.itemRemoval.undoLast()}nextReelMediaItem(){return this.surface?.changeActiveReelMedia(1)??!1}previousReelMediaItem(){return this.surface?.changeActiveReelMedia(-1)??!1}nextReelPost(){return this.surface?.moveActiveReelPost(1)??!1}previousReelPost(){return this.surface?.moveActiveReelPost(-1)??!1}navigateToReelItem(e){return this.surface?.navigateToReelItem(e)??`reel-inactive`}pauseAutoScroll(){this.autoScroll.setPaused(!0)}resumeAutoScroll(){this.autoScroll.setPaused(!1)}setAutoScroll(e,t){this.autoScroll.setEnabled(e,t)}setAutoScrollSpeed(e){this.autoScroll.setSpeed(e)}applyAutofillUpdate(e){let t=Jt(this.options.autofill,this.state,e);return t&&this.autofillController.syncCountdown(),t}cancelAutofill(){return this.autofillController.cancel()}async cancelLoading(){if(this.state.loadMoreLocked=!1,this.fillController.isActive()){await this.cancelFill();return}if(Ft(this.state.autofill)){await this.cancelAutofill();return}this.cancelRequest()}applyFillUpdate(e){return this.fillController.applyUpdate(e)}cancelFill(){return this.fillController.cancel()}async fill(e){if(!this.state.loadMoreLocked){if(this.pendingRequest||Ft(this.state.autofill))throw Error(`Vibe cannot fill while another page operation is active.`);await this.fillController.start(e)}}restoreAutofillSession(e){let t=Yt(this.options.autofill,this.state,e);return t&&this.autofillController.syncCountdown(),t}restoreFillSession(e){return this.fillController.restoreSession(e)}loadNext(){return this.startLoadMore(()=>this.loadNextSequence())}appendPage(e){bt(e,this.state,this.removalReconciliation,e=>this.setCurrentCursor(e))}replenishAfterRemoval(){return this.startLoadMore(()=>this.replenishAfterRemovalSequence())}async startLoadMore(e){if(this.pendingRequest)return this.pendingRequest;if(this.state.loadMoreLocked||Ft(this.state.autofill)||this.fillController.isActive()||!this.options.loadPage||this.state.next===null&&!this.removalReconciliation.needsReconciliation(this.state.items))return;this.state.isLoadingMore=!0,this.state.nextPageError=null;let t=e();return this.pendingRequest=t,t.finally(()=>{this.pendingRequest===t&&(this.pendingRequest=null),this.state.isLoadingMore=!1})}async refresh(){return this.replaceFeed(this.lastLoadedCursor,`refresh`)}async reload(){return this.replaceFeed(null,`reload`)}async replaceFeed(e,t){if(!this.options.loadPage)throw Error(`Vibe cannot ${t} without loadPage.`);return Ft(this.state.autofill)&&await this.cancelAutofill(),this.fillController.isActive()&&await this.cancelFill(),this.cancelRequest(),this.state.autofill=Pt(this.options.autofill,void 0,!1),this.fillController.reset(),this.reelForward.reset(),this.reelRemoval.reset(),this.exactMediaRemoval.reset(),this.itemRemoval.reset(),this.removalReconciliation.reset(),this.state.error=null,this.state.current=null,this.state.isLoading=!0,this.state.items=[],this.state.next=null,this.state.nextPageError=null,this.state.total=null,this.startRequest(e,!1)}async loadFilteredPage(e){let t=this.options.loadPage;if(!t)throw Error(`Vibe cannot load a page without loadPage.`);let n=X(await t(e));return{...n,items:this.removalReconciliation.filterItems(n.items)}}async loadNextSequence(){this.removalReconciliation.needsReconciliation(this.state.items)&&!await this.reconcileBeforeNext()||this.state.loadMoreLocked||this.state.next!==null&&await this.fetchPage(this.state.next,!0)}async replenishAfterRemovalSequence(){let e=this.state.items.length;this.removalReconciliation.needsReconciliation(this.state.items)&&(!await this.reconcileBeforeNext()||this.state.items.length>e)||this.state.loadMoreLocked||this.state.next===null||await this.fetchPage(this.state.next,!0)}async reconcileBeforeNext(){let e=this.options.loadPage;if(!e)return!1;let t=++this.requestVersion,n=new AbortController;this.abortController=n;try{let r=await mn({controller:this.removalReconciliation,isCurrent:()=>t===this.requestVersion,loadPage:e,onDelayChange:()=>void 0,setLastCursor:e=>this.setCurrentCursor(e),signal:n.signal,state:this.state});return t===this.requestVersion&&r===`complete`}catch(e){return!n.signal.aborted&&t===this.requestVersion&&(this.state.nextPageError=e),!1}finally{this.abortController===n&&(this.abortController=null)}}async retryEnd(){if(this.pendingRequest)return this.pendingRequest;if(!this.state.loadMoreLocked&&!(Ft(this.state.autofill)||this.fillController.isActive())&&!(this.state.next!==null||!this.options.loadPage))return this.state.isLoadingMore=!0,this.state.nextPageError=null,this.startRequest(this.lastLoadedCursor,!0)}setInfiniteScroll(t){this.state.infiniteScroll=t,t&&(0,e.nextTick)(()=>this.surface?.loadIfNearBottom())}setLoadMoreLocked(t){if(this.state.loadMoreLocked!==t&&(this.state.loadMoreLocked=t,!t)){if(this.state.fill.status===`paused`&&this.state.fill.target){this.fillController.resume(this.removalReconciliation.hasPendingSession());return}if(this.state.autofill.status===`paused`||this.removalReconciliation.hasPendingSession()){let e=this.pendingRequest;e?e.finally(()=>{this.loadNext()}):this.loadNext()}else this.state.infiniteScroll&&(0,e.nextTick)(()=>this.surface?.loadIfNearBottom())}}setTotal(e){if(e!==null&&(!Number.isInteger(e)||e<0))throw TypeError(`Vibe total must be a non-negative integer or null.`);this.state.total=e}setReelAutoAdvance(e){yn(this.state.reelAutoAdvance,e)}setReelInfoSheet(e){xn(this.state.reelInfoSheet,this.options.reelInfoSheet,e)}setLayout(e){this.responsiveLayout.setLayout(e)}closeMasonryReel(){this.state.reelOrigin===`masonry`&&(this.state.activeReelPostId=null,this.state.reelOrigin=null,this.routing.syncFeed())}openMasonryReel(e){this.state.layout===`masonry`&&this.state.items.some(t=>t.postId===e)&&(this.state.activeReelPostId=e,this.state.reelOrigin=`masonry`,this.routing.syncReel(e))}setActiveReelPost(e){this.state.layout!==`reel`&&this.state.reelOrigin!==`masonry`||(this.state.activeReelPostId=e,this.routing.syncReel(e))}cancelRequest(){this.autofillController.clearCountdown(),this.requestVersion+=1,this.abortController?.abort(),this.abortController=null,this.pendingRequest=null,this.state.isLoading=!1,this.state.isLoadingMore=!1}async fetchPage(e,t){if(!this.options.loadPage)return;let n=++this.requestVersion,r=new AbortController;this.abortController=r,await Dn({append:t,autofillController:this.autofillController,cursor:e,isCurrent:()=>n===this.requestVersion,loadPage:e=>this.loadFilteredPage(e),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:this.options,signal:r.signal,state:this.state}),n===this.requestVersion&&(this.abortController=null)}startRequest(e,t){let n=this.fetchPage(e,t);return this.pendingRequest=n,n.finally(()=>{this.pendingRequest===n&&(this.pendingRequest=null)})}startInitialAutofill(){let e=++this.requestVersion,t=new AbortController,n=this.autofillController.beginCycle();this.abortController=t,this.state.isLoadingMore=!0;let r=Zt({cycleId:n,isCurrent:()=>e===this.requestVersion,onCollection:t=>this.autofillController.captureCollection(t,e===this.requestVersion),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:this.options,signal:t.signal,state:this.state}).catch(n=>{t.signal.aborted||e!==this.requestVersion||(this.autofillController.commitCollection(),this.state.autofill.error=n,this.state.autofill.status=`error`,this.state.nextPageError=n)}).finally(()=>{e===this.requestVersion&&(this.autofillController.clearCollection(),this.autofillController.syncCountdown(),this.abortController=null,this.state.isLoadingMore=!1,this.pendingRequest===r&&(this.pendingRequest=null))});return this.pendingRequest=r,r}startStateNotifications(){let t=this.options.onStateChange;!t||this.stopStateWatcher||(t(c(this.state,this.notificationItems.value)),this.stopStateWatcher=(0,e.watch)(this.state,()=>t(c(this.state,this.notificationItems.value)),{deep:!0,flush:`post`}))}setCurrentCursor(e){this.lastLoadedCursor=e,this.state.current=e}};function Qn(e){return new Zn(e)}exports.createVibe=Qn;