@wyxos/vibe 5.13.3 → 5.14.0

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,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`);var t=/\.(aac|flac|m4a|mp3|oga|ogg|opus|wav)$/i,n=/\.(m4v|mkv|mov|mp4|ogv|webm)$/i;function r(e){try{return new URL(e).pathname}catch{return e.split(/[?#]/)[0]??e}}function i(e){let i=r(e);return t.test(i)?`audio`:n.test(i)?`video`:`image`}function a(e,t){return e??i(t)}function o(e,t){return a(e,t)!==`image`}function s(e){return{height:e.height,src:e.src,type:e.type,width:e.width}}function c(e,t){if(t===`preview`&&e.preview){let t=a(e.type,e.src)===`audio`?a(e.preview.type,e.preview.src):e.preview.type??e.type;return{...e.preview,type:t}}return t===`mobile`&&e.mobile?{...e.mobile,type:e.mobile.type??e.type}:s(e)}function l(e){let t=e.preview;return!t?.src||t.src===e.src||a(t.type,t.src)!==`image`?null:{...t,type:`image`}}function u(e,t){return a(e.type,e.src)===`audio`?t===`mobile`&&e.mobile&&a(e.mobile.type,e.mobile.src)===`audio`?{...e.mobile,type:`audio`}:{...s(e),type:`audio`}:c(e,t)}function d(e){return[e,...e.items]}function f(e,t){return Math.min(e.items.length,Math.max(0,t))}function p(e,t){return d(e)[f(e,t)]??e}function m(e,t){return`${String(e)}:${t}`}function h(t){return(0,e.computed)(()=>Object.freeze([...t.items]))}function g(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 _={key:0,class:`gallery-footer`},v={key:0,class:`load-more-status`,role:`status`},y=[`disabled`],b={key:2,class:`end-feed`},x=[`disabled`],S=(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`,_,[t.isLoading?((0,e.openBlock)(),(0,e.createElementBlock)(`p`,v,` 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,y)):((0,e.openBlock)(),(0,e.createElementBlock)(`div`,b,[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,x)]))])):(0,e.createCommentVNode)(``,!0)}}),C=(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)(S,{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`]))}}),w=[`role`],T={class:`gallery-status`},E=(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||r.state.isLoadingMore?`status`:void 0},[(0,e.createElementVNode)(`p`,T,[r.state.error?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:0},[(0,e.createTextVNode)(` Unable to load media. `)],64)):r.state.isLoading||r.state.isLoadingMore?((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)(C,{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,w))}});function D(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=240}function O(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 k(e){return e.reduce((t,n,r)=>n<e[t]?r:t,0)}function ee(e){return Math.max(0,e.containerHeight)+Math.max(0,e.gap)}var A=.8,j=.5;function M(e,t,n){let r=Math.max(0,n.viewportHeight);if(r===0)return[];let i=n.scrollTop,a=i+r;return t.filter(t=>{let n=e[t];if(!n||n.height<=0)return!1;let o=Math.max(0,Math.min(n.y+n.height,a)-Math.max(n.y,i)),s=n.height<=r?n.height:r*A;return o+j>=s})}function N(e,t){if(e<=0)return null;let n=Math.max(0,t.gap),r=Number.isFinite(t.additionalHeight)?Math.max(0,t.additionalHeight??0):0,i=Math.max(1,t.minColumnWidth),a=Math.max(1,Math.floor((e+n)/(i+n)));return{additionalHeight:r,columns:a,gap:n,itemWidth:(e-n*(a-1))/a}}function P(e,t,n){let r=k(t),i=n.itemWidth*O(e)+n.additionalHeight,a={x:r*(n.itemWidth+n.gap),y:t[r],width:n.itemWidth,height:i};return t[r]+=i+n.gap,a}function F(e,t){let n=Array.from({length:t.columns},()=>0),r=t.itemWidth+t.gap;return e.forEach(e=>{let i=r===0?0:Math.round(e.x/r);i<0||i>=t.columns||(n[i]=Math.max(n[i],e.y+e.height+t.gap))}),n}function I(e,t){return e.length===0?0:Math.max(0,Math.max(...e)-t)}function L(e,t,n){let r=N(t,n);if(!r||e.length===0)return{columns:0,height:0,items:[]};let i=Array.from({length:r.columns},()=>0),a=e.map(e=>P(e,i,r));return{columns:r.columns,height:I(i,r.gap),items:a}}function R(e,t,n,r,i,a){let o=N(t,n);if(!o||e.length===0)return{columns:0,height:0,items:[]};if(r.columns!==o.columns||i>0&&r.items.length<i)return L(e,t,n);let s=Math.max(0,i),c=a?.untilIndex??e.length,l=a?.untilBottom,u=a?.throughIndex??s,d=s===0?[]:r.items.slice(0,s),f=s===0?Array.from({length:o.columns},()=>0):F(d,o);for(let t=s;t<e.length&&t<c&&!(l!==void 0&&t>s&&t>u&&f.every(e=>e>=l));t+=1)d.push(P(e[t],f,o));return{columns:o.columns,height:I(f,o.gap),items:d}}function te(e,t,n,r,i,a){let o=N(t,n);if(!o||e.length===0)return{columns:0,fromIndex:0,height:0,items:[],retainedIndices:[]};if(r.items.length!==e.length||r.columns!==o.columns){let a=e.map((e,t)=>t).filter(e=>!i(e)),o=L(a.map(t=>e[t]),t,n),s=e.map((e,t)=>r.items[t]??{height:0,width:0,x:0,y:0});return a.forEach((e,t)=>{s[e]=o.items[t]}),{columns:o.columns,fromIndex:0,height:o.height,items:s,retainedIndices:a}}let s=0;for(;s<e.length&&!i(s);)s+=1;if(s>=e.length)return{...r,fromIndex:s,retainedIndices:e.map((e,t)=>t)};let c=r.items.slice(),l=[];for(let e=0;e<s;e+=1)l.push(e);let u=a?.untilBottom,d=a?.throughIndex??s,f=F(c.slice(0,s),o);for(let t=s;t<e.length;t+=1)if(!i(t)){if(u!==void 0&&l.length>s&&t>d&&f.every(e=>e>=u))break;c[t]=P(e[t],f,o),l.push(t)}let p=new Set(l);for(let t=s;t<e.length;t+=1)i(t)||p.has(t)||(c[t]={height:0,width:0,x:0,y:0});return{columns:o.columns,fromIndex:s,height:I(f,o.gap),items:c,retainedIndices:l}}function z(e){return{columns:[...e.entries()].sort(([e],[t])=>e-t).map(([,e])=>e.sort((e,t)=>e.top-t.top||e.index-t.index))}}function B(e,t,n){let r=e.get(t.x)??[];r.push({bottom:t.y+t.height,index:n,top:t.y}),e.set(t.x,r)}function V(e,t){let n=new Map;return e.forEach((e,r)=>{B(n,e,t?.[r]??r)}),z(n)}function H(e,t,n,r){if(n<=0)return V(e,r);let i=new Map;t.columns.forEach(t=>{t.forEach(t=>{if(t.index>=n)return;let r=e[t.index];if(!r)return;let a=i.get(r.x)??[];a.push(t),i.set(r.x,a)})});for(let t=n;t<e.length;t+=1)B(i,e[t],r?.[t]??t);return z(i)}function ne(e,t,n,r){if(r<=0)return V(t.map(t=>e[t]),t);let i=new Map;return n.columns.forEach(t=>{t.forEach(t=>{if(t.index>=r)return;let n=e[t.index];if(!n)return;let a=i.get(n.x)??[];a.push(t),i.set(n.x,a)})}),t.forEach(t=>{t<r||B(i,e[t],t)}),z(i)}function U(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 re(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=U(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 W(e){return e?.minColumnWidth??240}function ie(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 G(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 K(e,t,n){return Math.min(n,Math.max(t,e))}function q({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=K(s/a*o,Math.min(Math.max(0,t),o),o),u=Math.max(0,o-l);return{maximumScrollPosition:c,scrollable:!0,thumbOffset:u*(K(n,0,c)/c),thumbSize:l,thumbTravel:u}}var ae=[`aria-hidden`],J=[`aria-controls`,`aria-valuemax`,`aria-valuenow`,`tabindex`],oe=32,se=40,ce=120,le=(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)},ce)}function x(){s.value=!0,b()}function S(){let e=n.scrollElement,t=i.value;return!e||!t?r:q({contentSize:e.scrollHeight,minimumThumbSize:oe,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 ee(e){if(!v.value)return;let t=n.scrollElement?.clientHeight??0,r=n.scrollElement?.scrollTop??0,i=e.key===`ArrowUp`?r-se:e.key===`ArrowDown`?r+se: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 A(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),A(t)),t&&typeof MutationObserver<`u`&&(m=new MutationObserver(()=>{A(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:ee,onPointercancel:k,onPointerdown:D,onPointermove:O,onPointerup:k},null,44,J)],42,ae))}}),ue=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},de=e=>e===``,fe=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),pe=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),me=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),he=e=>{let t=me(e);return t.charAt(0).toUpperCase()+t.slice(1)},Y={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`},ge=({name:t,iconNode:n,absoluteStrokeWidth:r,"absolute-stroke-width":i,strokeWidth:a,"stroke-width":o,size:s=Y.width,color:c=Y.stroke,...l},{slots:u})=>(0,e.h)(`svg`,{...Y,...l,width:s,height:s,stroke:c,"stroke-width":de(r)||de(i)||r===!0||i===!0?Number(a||o||Y[`stroke-width`])*24/Number(s):a||o||Y[`stroke-width`],class:fe(`lucide`,l.class,...t?[`lucide-${pe(he(t))}-icon`,`lucide-${pe(t)}`]:[`lucide-icon`]),...!u.default&&!ue(l)&&{"aria-hidden":`true`}},[...n.map(t=>(0,e.h)(...t)),...u.default?[u.default()]:[]]),X=(t,n)=>(r,{slots:i,attrs:a})=>(0,e.h)(ge,{...a,...r,iconNode:n,name:t},i),_e=X(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),ve=X(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),ye=X(`disc-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M6 12c0-1.7.7-3.2 1.8-4.2`,key:`oqkarx`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`M18 12c0 1.7-.7 3.2-1.8 4.2`,key:`1eah9h`}]]),be=X(`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`}]]),xe=X(`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`}]]),Se=X(`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`}]]),Ce=X(`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`}]]),we={401:`Authentication required`,403:`Access forbidden`,404:`Preview not found`,419:`Session expired`,500:`Server error`};function Te(e){return e.match(/\/demo-errors\/(401|403|404|419|500)\//)?.[1]??`Error`}function Ee(e){return we[Te(e)]??`Preview unavailable`}var De=(0,e.defineComponent)({__name:`CardRegion`,props:{index:{},item:{},layout:{},loadedCount:{},mediaIndex:{},mediaSource:{},placement:{},region:{},style:{},total:{}},setup(t){let n=t,r=(0,e.computed)(()=>f(n.item,n.mediaIndex)),i=(0,e.computed)(()=>d(n.item)),a=(0,e.computed)(()=>p(n.item,r.value)),o=(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`})),s=(0,e.computed)(()=>n.style?.background??n.region.background);return(n,c)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:(0,e.normalizeClass)([`media-card-region`,[`media-card-${t.placement}`,{"media-card-region--transparent":s.value===`transparent`}]]),style:(0,e.normalizeStyle)(o.value),onClick:c[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:c[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":i.value.length,"media-index":r.value,"media-item":a.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))}}),Oe=[`aria-busy`,`aria-label`],ke={class:`media-error-code`},Ae=[`disabled`],je=(0,e.defineComponent)({__name:`MediaError`,props:{component:{},label:{},retrying:{type:Boolean},status:{}},emits:[`retry`],setup(t,{emit:n}){let r=t,i=n;function a(){r.retrying||i(`retry`)}return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{"data-test":`media-error`,class:`media-error`,role:`group`,"aria-busy":t.retrying,"aria-label":`${t.status} ${t.label}`},[t.component?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`media-error-component`,onClick:r[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:r[1]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.component),{label:t.label,retry:a,retrying:t.retrying,status:t.status},null,8,[`label`,`retrying`,`status`]))],32)):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:1},[(0,e.createElementVNode)(`strong`,ke,(0,e.toDisplayString)(t.status),1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.label),1),(0,e.createElementVNode)(`button`,{"data-test":`media-retry`,class:`media-error-retry`,type:`button`,disabled:t.retrying,onClick:(0,e.withModifiers)(a,[`stop`]),onKeydown:r[2]||=(0,e.withModifiers)(()=>{},[`stop`])},(0,e.toDisplayString)(t.retrying?`Retrying…`:`Retry`),41,Ae)],64))],8,Oe))}}),Me=[`aria-label`],Ne=[`max`,`value`,`aria-label`,`aria-valuetext`,`disabled`],Pe={key:0,class:`media-controls-row`},Fe=[`aria-label`,`title`],Ie={class:`media-controls-audio`},Le=[`aria-label`,`title`],Re=[`value`,`aria-label`,`aria-valuetext`],ze={class:`media-control-time`,"aria-live":`off`},Be=(0,e.defineComponent)({__name:`MediaControls`,props:{currentTime:{},duration:{},layout:{},mediaType:{},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)(()=>r.mediaType===`audio`?`audio`:`video`),u=(0,e.computed)(()=>r.mediaType===`audio`?`Audio`:`Video`),d=(0,e.computed)(()=>a(r.currentTime,c.value)),f=(0,e.computed)(()=>({"--media-range-progress":`${c.value>0?d.value/c.value*100:0}%`})),p=(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}`]),role:`group`,"aria-label":`${u.value} 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:d.value,style:(0,e.normalizeStyle)(f.value),"aria-label":`Seek ${l.value}`,"aria-valuetext":`${o(d.value)} of ${o(c.value)}`,disabled:c.value<=0,onInput:r[0]||=e=>i(`seek`,s(e))},null,44,Ne),t.layout===`reel`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Pe,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button media-control-playback`,"aria-label":t.playing?`Pause ${l.value}`:`Play ${l.value}`,title:t.playing?`Pause`:`Play`,onClick:r[1]||=e=>i(`togglePlayback`)},[t.playing?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(be),{key:0,size:18,fill:`currentColor`})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(xe),{key:1,size:18,fill:`currentColor`}))],8,Fe),(0,e.createElementVNode)(`div`,Ie,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button`,"aria-label":t.muted?`Unmute ${l.value}`:`Mute ${l.value}`,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)(Ce),{key:0,size:18})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(Se),{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)(p.value),"aria-label":`${u.value} volume`,"aria-valuetext":`${Math.round(t.volume*100)} percent`,onInput:r[3]||=e=>i(`volumeChange`,s(e))},null,44,Re)]),(0,e.createElementVNode)(`output`,ze,(0,e.toDisplayString)(o(d.value))+` / `+(0,e.toDisplayString)(o(c.value)),1)])):(0,e.createCommentVNode)(``,!0)],42,Me))}}),Ve={key:0,class:`media-card-overlay-host`,"data-test":`media-card-overlay`},He=(0,e.defineComponent)({__name:`MediaContextOverlay`,props:{item:{},mediaCard:{},mediaIndex:{},mediaItem:{},mediaSource:{}},setup(t){return(n,r)=>t.mediaCard?.overlay?.component?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Ve,[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.mediaCard.overlay.component),{item:t.item,"media-index":t.mediaIndex,"media-item":t.mediaItem,"media-source":t.mediaSource},null,8,[`item`,`media-index`,`media-item`,`media-source`]))])):(0,e.createCommentVNode)(``,!0)}}),Ue=40,We=160,Ge=24;function Ke(t){let n=(0,e.shallowRef)(`next`),r=null,i=0,a=!1,o=null,s=null;function c(e,r){let i=d(t.item()).length,a=(e+i)%i;a!==t.mediaIndex()&&(n.value=e<t.mediaIndex()?`previous`:`next`,t.onChange(a),r?.detail&&r.detail>0&&r.currentTarget?.blur())}function l(){i=0,a=!1,r!==null&&clearTimeout(r),r=null}function u(){r!==null&&clearTimeout(r),r=setTimeout(l,We)}function f(e,t,n){return t===1?e*16:t===2?e*n:e}function p(e){if(d(t.item()).length<=1)return;let n=e.currentTarget,r=f(e.deltaX,e.deltaMode,n?.clientWidth||1);if(r===0||(e.preventDefault(),u(),a)||(i+=r,Math.abs(i)<Ge))return;let o=Math.sign(i);i=0,a=!0,c(t.mediaIndex()+o)}function m(e){let n=e.touches[0];t.layout()!==`reel`||!n||(o=n.clientX,s=n.clientY)}function h(e){let n=e.changedTouches[0];if(o===null||s===null||!n)return;let r=o-n.clientX,i=s-n.clientY;o=null,s=null,!(Math.abs(r)<=Math.abs(i))&&(Math.abs(r)<Ue||c(t.mediaIndex()+Math.sign(r)))}return(0,e.onBeforeUnmount)(l),{change:c,direction:n,onTouchEnd:h,onTouchStart:m,onWheel:p}}var qe=new Map,Je=[],Ye=0,Xe=0;function Ze(e,t){return`${t?`timed`:`image`}:${e}`}function Qe(e,t,n){let r=d(e);if(r.length<2)return[];let i=f(e,t),s=[];for(let e=1;e<r.length;e+=1){let t=i+e,n=i-e;t<r.length&&s.push(t),n>=0&&s.push(n)}let u=new Set;return s.flatMap(e=>{let t=r[e];if(!t)return[];let i=a(t.type,t.src)===`audio`?l(t):c(t,n);if(!i)return[];let s=o(i.type,i.src),d=Ze(i.src,s);return u.has(d)?[]:(u.add(d),[{key:d,src:i.src,timed:s}])})}function $e(e){let t=e.element;e.element=null,t&&(t instanceof HTMLVideoElement?(t.pause(),t.removeAttribute(`src`),t.load()):t.removeAttribute(`src`))}function et(e){qe.delete(e.key);let t=Je.indexOf(e);t>=0&&Je.splice(t,1),e.cancel?.(),e.cancel=null,$e(e)}function tt(e){e.state=`loading`,Ye+=1,e.timed&&(Xe+=1);let t=!1,n=()=>void 0,r=r=>{t||(t=!0,n(),--Ye,e.timed&&--Xe,e.cancel=null,e.state=r,r===`failed`&&$e(e),e.refs===0&&et(e),nt())};if(e.cancel=()=>{t||(t=!0,n(),--Ye,e.timed&&--Xe,$e(e),nt())},e.timed){let t=document.createElement(`video`),i=()=>r(`ready`),a=()=>r(`failed`);n=()=>{t.removeEventListener(`loadedmetadata`,i),t.removeEventListener(`error`,a)},t.addEventListener(`loadedmetadata`,i,{once:!0}),t.addEventListener(`error`,a,{once:!0}),t.muted=!0,t.playsInline=!0,t.preload=`metadata`,t.src=e.src,e.element=t,t.load();return}let i=document.createElement(`img`),a=()=>{if(typeof i.decode!=`function`){r(`ready`);return}i.decode().then(()=>r(`ready`),()=>r(`failed`))},o=()=>r(`failed`);n=()=>{i.removeEventListener(`load`,a),i.removeEventListener(`error`,o)},i.addEventListener(`load`,a,{once:!0}),i.addEventListener(`error`,o,{once:!0}),i.decoding=`async`,i.fetchPriority=`low`,i.src=e.src,e.element=i}function nt(){for(;Ye<6;){let e=Je.findIndex(e=>e.refs>0&&e.state===`queued`&&(!e.timed||Xe<2));if(e<0)return;let[t]=Je.splice(e,1);t&&tt(t)}}function rt(e){let t=qe.get(e.key);t||(t={...e,cancel:null,element:null,refs:0,state:`queued`},qe.set(t.key,t),Je.push(t)),t.refs+=1,nt();let n=!1;return()=>{n||(n=!0,--t.refs,t.refs===0&&et(t))}}function it(t){let n=(0,e.computed)(()=>t.layout()===`masonry`&&t.inViewport()&&t.mediaReady()&&t.mediaCard()?.feedPreload===`visible-post`),r=(0,e.computed)(()=>n.value?Qe(t.item(),t.mediaIndex(),t.mediaSource()):[]),i=new Map;function a(){let e=new Map(r.value.map(e=>[e.key,e]));i.forEach((t,n)=>{e.has(n)||(t(),i.delete(n))}),r.value.forEach(e=>{i.has(e.key)||i.set(e.key,rt(e))})}(0,e.watch)(()=>r.value.map(({key:e})=>e).join(`
2
- `),a,{immediate:!0}),(0,e.onBeforeUnmount)(()=>{i.forEach(e=>e()),i.clear()})}function at(t){let n=(0,e.computed)(()=>o(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.mediaElement.value?.load())}),{imageLoading:r,mediaIsTimed:n,timedMediaPreload:i}}function ot(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=(0,e.shallowRef)(!1),l=null,u=!1,d=(0,e.computed)(()=>c.value||s.value?`error`:o.value?`loading`:t.previewState());function f(){l!==null&&clearTimeout(l),l=null}function p(e){return Number(e.currentTarget.dataset.sourceGeneration)===i.value}function m(){f(),l=setTimeout(()=>_(),15e3)}function h(e){e&&!p(e)||(f(),o.value=!1,s.value=!1,c.value=!1,t.onReady(t.mediaIndex()))}function g(){let e=n.value;if(e?.complete){e.naturalWidth>0?h():_();return}let t=r.value;if(t&&t.readyState>=HTMLMediaElement.HAVE_METADATA){h();return}m()}function _(n){if(!(n&&!p(n))){if(f(),!n&&a.value===0){a.value=1,i.value+=1,o.value=!0,(0,e.nextTick)(g);return}o.value=!1,s.value=!0,c.value=!1,t.onError(t.mediaIndex())}}function v(){c.value||d.value!==`error`||(a.value=0,s.value=!0,o.value=!0,c.value=!0,i.value+=1,(0,e.nextTick)(g))}function y(e){p(e)&&o.value&&m()}return(0,e.watch)(t.identity,()=>{f(),i.value+=1,a.value=0,o.value=u||t.previewState()===`loading`,s.value=!1,c.value=!1,u=!0,(0,e.nextTick)(g)},{immediate:!0}),(0,e.onBeforeUnmount)(f),{effectivePreviewState:d,failSourceAttempt:_,imageElement:n,markSourceReady:h,noteSourceActivity:y,retrySource:v,retrying:c,sourceGeneration:i,mediaElement:r}}var st={lastAudibleVolume:1,muted:!1,volume:1};function ct(e,t){return typeof e==`number`&&Number.isFinite(e)?Math.min(1,Math.max(0,e)):t}function lt(e,t=st){let n=ct(e?.volume,t.volume),r=ct(e?.lastAudibleVolume,n>0?n:t.lastAudibleVolume);return{lastAudibleVolume:r>0?r:st.lastAudibleVolume,muted:typeof e?.muted==`boolean`?e.muted:n===0||t.muted,volume:n}}function ut(t){let n=lt(t.reelAudioState()),r=t.layout()===`reel`&&t.reelAudioState(),i=(0,e.shallowRef)(r?n.muted:t.mediaCard()?.videoMuted??t.layout()===`masonry`),a=(0,e.shallowRef)(r?n.volume:1),o=r?n.lastAudibleVolume:1;function s(){let e=t.mediaElement.value,n=t.reelAudioState();if(!e||t.layout()!==`reel`||!n)return;let r=lt(n);o=r.lastAudibleVolume,a.value=r.volume,i.value=r.muted,e.volume=r.volume,e.muted=t.active()===!1?!0:r.muted}function c(e,t){t&&(i.value=e.muted),a.value=e.volume,e.volume>0&&(o=e.volume)}function l(e){if(t.layout()!==`reel`)return;let n=lt({lastAudibleVolume:o,muted:e.muted,volume:e.volume});i.value=n.muted,a.value=n.volume,o=n.lastAudibleVolume,t.onChange(n)}function u(e){let n=t.mediaElement.value;if(!n||!Number.isFinite(e))return;let r=Math.min(1,Math.max(0,e));n.volume=r,n.muted=r===0,r>0&&(o=r),c(n,!0),l(n)}function d(){let e=t.mediaElement.value;e&&(e.muted&&e.volume===0&&(e.volume=o),e.muted=!e.muted,c(e,!0),l(e))}return(0,e.watch)([t.active,t.layout,()=>t.reelAudioState()?.lastAudibleVolume,()=>t.reelAudioState()?.muted,()=>t.reelAudioState()?.volume,t.mediaElement],s,{immediate:!0}),{apply:s,setVolume:u,sync:c,toggleMute:d,videoIsMuted:i,videoVolume:a}}function dt(t){let n=(0,e.computed)(()=>t.layout()===`reel`?t.active()===!0:t.inViewport()),r=(0,e.computed)(()=>n.value?t.mediaIsMuted.value:!0);function i(){if(!n.value){t.mediaElement.value?.pause(),t.mediaIsPlaying.value=!1;return}t.mediaIsPlaying.value=!0}return(0,e.watch)(n,r=>{let i=t.mediaElement.value;if(!r){i?.pause(),i&&(i.muted=!0),t.mediaIsPlaying.value=!1;return}(0,e.nextTick)().then(async()=>{let e=t.mediaElement.value;if(!(!e||!n.value)){e.muted=t.mediaIsMuted.value;try{await e.play()}catch{t.mediaIsPlaying.value=!1}}})}),{effectiveMuted:r,onPlaying:i,playbackAllowed:n}}function ft(e){return Number.isFinite(e)?Math.max(0,e):0}function pt(t){let n=(0,e.shallowRef)(0),r=(0,e.shallowRef)(0),i=(0,e.shallowRef)(!1),{apply:a,setVolume:o,sync:s,toggleMute:c,videoIsMuted:l,videoVolume:u}=ut({active:t.active,layout:t.layout,mediaCard:t.mediaCard,mediaElement:t.mediaElement,onChange:t.onAudioChange,reelAudioState:t.reelAudioState}),{effectiveMuted:d,onPlaying:f,playbackAllowed:p}=dt({active:t.active,inViewport:t.inViewport,layout:t.layout,mediaElement:t.mediaElement,mediaIsMuted:l,mediaIsPlaying:i});function m(e){let i=e?.currentTarget??t.mediaElement.value;i&&(n.value=ft(i.currentTime),r.value=ft(i.duration),s(i,p.value))}function h(e){a(),m(e),t.onReady(e)}function g(){i.value=!1,t.onEnded()}function _(e){let r=t.mediaElement.value;!r||!Number.isFinite(e)||(r.currentTime=Math.min(ft(r.duration),Math.max(0,e)),n.value=r.currentTime)}async function v(){let e=t.mediaElement.value;if(!(!e||!p.value)){if(i.value){e.pause();return}try{await e.play()}catch{i.value=!1}}}return(0,e.watch)(t.mediaElement,()=>{n.value=0,r.value=0,i.value=!1},{flush:`sync`}),{currentTime:n,duration:r,effectiveMuted:d,isMuted:l,isPlaying:i,onEnded:g,onLoadedMetadata:h,onPlaying:f,playbackAllowed:p,seek:_,setVolume:o,sync:m,toggleMute:c,togglePlayback:v,volume:u}}var mt=[`data-post-id`,`data-media-index`,`aria-hidden`,`aria-busy`,`inert`,`role`,`tabindex`],ht={class:`media-card-content`},gt=[`data-media-direction`],_t=[`data-media-index`],vt={key:0,"data-test":`media-loading`,class:`media-loading`,"aria-hidden":`true`},yt=[`data-source-generation`,`src`,`autoplay`,`loop`,`muted`,`preload`],bt=[`aria-label`,`disabled`],xt=[`src`,`width`,`height`,`fetchpriority`,`loading`],St={key:1,class:`media-audio-fallback`,"aria-hidden":`true`},Ct=[`data-source-generation`,`src`,`width`,`height`,`autoplay`,`loop`,`muted`,`preload`],wt=[`data-source-generation`,`src`,`width`,`height`,`fetchpriority`,`loading`],Tt=[`aria-label`],Et=[`aria-label`],Dt=[`aria-label`],Ot=(0,e.defineComponent)({__name:`MediaCard`,props:{active:{type:Boolean},advanceOnMediaEnd:{type:Boolean},cardFooter:{},cardHeader:{},entering:{type:Boolean},fetchPriority:{},inViewport:{type:Boolean},index:{},item:{},itemStyle:{},interactive:{type:Boolean},leaving:{type:Boolean},layout:{},loadedCount:{},mediaIndex:{},mediaCard:{},mediaSource:{},previewState:{},reelControlsTarget:{},reelAudioState:{},stationaryReelControls:{type:Boolean},total:{}},emits:[`activate`,`ended`,`error`,`mediaChange`,`ready`,`reelAudioChange`],setup(t,{emit:n}){let r=t,i=n;function o(e=!1,t=`pointer`){e&&i(`activate`,t)}let s=(0,e.computed)(()=>d(r.item)),m=(0,e.computed)(()=>f(r.item,r.mediaIndex)),h=(0,e.computed)(()=>p(r.item,m.value)),g=(0,e.computed)(()=>c(h.value,r.mediaSource??`preview`)),_=(0,e.computed)(()=>a(h.value.type,h.value.src)),v=(0,e.computed)(()=>_.value===`audio`),y=(0,e.computed)(()=>u(h.value,r.mediaSource??`preview`)),b=(0,e.computed)(()=>v.value?y.value:g.value),x=(0,e.computed)(()=>b.value.src),S=(0,e.computed)(()=>a(b.value.type,b.value.src)),C=(0,e.computed)(()=>g.value.width),w=(0,e.computed)(()=>g.value.height),T=(0,e.computed)(()=>l(h.value)),E=(0,e.shallowRef)(!1),D=(0,e.computed)(()=>E.value?null:T.value),{effectivePreviewState:O,failSourceAttempt:k,imageElement:ee,markSourceReady:A,noteSourceActivity:j,retrySource:M,retrying:N,sourceGeneration:P,mediaElement:F}=ot({identity:()=>`${r.item.postId}:${m.value}:${r.mediaSource??`preview`}:${x.value}:${S.value??``}`,mediaIndex:()=>m.value,onError:e=>i(`error`,e),onReady:e=>i(`ready`,e),previewState:()=>r.previewState});it({inViewport:()=>r.inViewport===!0,item:()=>r.item,layout:()=>r.layout,mediaCard:()=>r.mediaCard,mediaIndex:()=>m.value,mediaReady:()=>O.value===`ready`,mediaSource:()=>r.mediaSource??`preview`});let{currentTime:I,duration:L,effectiveMuted:R,isMuted:te,isPlaying:z,onEnded:B,onLoadedMetadata:V,onPlaying:H,playbackAllowed:ne,seek:U,setVolume:re,sync:W,toggleMute:ie,togglePlayback:G,volume:K}=pt({active:()=>r.active,inViewport:()=>r.inViewport===!0,layout:()=>r.layout,mediaCard:()=>r.mediaCard,mediaElement:F,onAudioChange:e=>i(`reelAudioChange`,e),onEnded:()=>i(`ended`,m.value),onReady:A,reelAudioState:()=>r.reelAudioState}),q=(0,e.computed)(()=>r.interactive&&!!(r.cardHeader||r.cardFooter));function ae(e){return e.detail===0?`keyboard`:`pointer`}let{change:J,direction:oe,onTouchEnd:se,onTouchStart:ce,onWheel:le}=Ke({item:()=>r.item,layout:()=>r.layout,mediaIndex:()=>m.value,onChange:e=>i(`mediaChange`,e)}),{imageLoading:ue,mediaIsTimed:de,timedMediaPreload:fe}=at({active:()=>r.active,fetchPriority:()=>r.fetchPriority,layout:()=>r.layout,mediaSource:()=>x.value,mediaType:()=>S.value,mediaElement:F}),pe=(0,e.computed)(()=>r.layout===`reel`&&r.stationaryReelControls===!0),me=(0,e.computed)(()=>de.value&&(!v.value||r.layout===`reel`)&&O.value===`ready`&&(!pe.value||!!(r.active&&r.reelControlsTarget))),he=(0,e.computed)(()=>`${r.item.postId}:${m.value}:${x.value}`);function Y(e){r.layout===`reel`&&(e.stopPropagation(),G())}function ge(){E.value=!0,r.layout===`masonry`&&A()}return(0,e.watch)(()=>T.value?.src,()=>{E.value=!1}),(0,e.watch)([v,()=>r.layout,D],([t,n,r])=>{t&&n===`masonry`&&!r&&(0,e.nextTick)(()=>A())},{immediate:!0}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`article`,{"data-post-id":t.item.postId,"data-media-index":m.value,class:(0,e.normalizeClass)([`media-card`,{"media-card--entering":t.entering,"media-card--leaving":t.leaving,"media-card--error":(0,e.unref)(O)===`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)(O)===`loading`||(0,e.unref)(N),inert:t.leaving||void 0,role:t.interactive&&!t.leaving&&!q.value?`button`:void 0,tabindex:t.interactive&&!t.leaving&&!q.value?0:void 0,onClick:r[34]||=e=>o(t.interactive&&!q.value,ae(e)),onKeydown:[r[35]||=(0,e.withKeys)(e=>o(t.interactive&&!q.value,`keyboard`),[`enter`]),r[36]||=(0,e.withKeys)((0,e.withModifiers)(e=>o(t.interactive&&!q.value,`keyboard`),[`prevent`]),[`space`])]},[(0,e.createElementVNode)(`div`,ht,[t.cardHeader?((0,e.openBlock)(),(0,e.createBlock)(De,{key:0,index:t.index,item:t.item,layout:t.layout,"loaded-count":t.loadedCount,"media-index":m.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`&&s.value.length>1}]),"data-media-direction":(0,e.unref)(oe),onWheel:r[31]||=(...t)=>(0,e.unref)(le)&&(0,e.unref)(le)(...t),onTouchstartPassive:r[32]||=(...t)=>(0,e.unref)(ce)&&(0,e.unref)(ce)(...t),onTouchendPassive:r[33]||=(...t)=>(0,e.unref)(se)&&(0,e.unref)(se)(...t)},[(0,e.createVNode)(e.Transition,{css:!(0,e.unref)(N),name:`media-slide-${(0,e.unref)(oe)}`},{default:(0,e.withCtx)(()=>[((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:`${t.item.postId}:${h.value.src}:${t.mediaSource??`preview`}:${(0,e.unref)(P)}`,class:`media-card-frame`,"data-media-index":m.value},[(0,e.unref)(O)===`loading`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,vt,[...r[37]||=[(0,e.createElementVNode)(`span`,{class:`media-loading-shimmer`},null,-1)]])):(0,e.unref)(O)===`error`?((0,e.openBlock)(),(0,e.createBlock)(je,{key:1,component:t.mediaCard?.error?.component,label:(0,e.unref)(Ee)(x.value),retrying:(0,e.unref)(N),status:(0,e.unref)(Te)(x.value),onRetry:(0,e.unref)(M)},null,8,[`component`,`label`,`retrying`,`status`,`onRetry`])):(0,e.createCommentVNode)(``,!0),v.value&&t.layout===`reel`?((0,e.openBlock)(),(0,e.createElementBlock)(`audio`,{key:2,ref_key:`mediaElement`,ref:F,"data-source-generation":(0,e.unref)(P),class:`media-audio-element`,src:x.value,autoplay:(0,e.unref)(ne),loop:!t.advanceOnMediaEnd,muted:(0,e.unref)(R),preload:(0,e.unref)(fe),onLoadedmetadata:r[0]||=(...t)=>(0,e.unref)(V)&&(0,e.unref)(V)(...t),onProgress:r[1]||=(...t)=>(0,e.unref)(j)&&(0,e.unref)(j)(...t),onLoadeddata:r[2]||=(...t)=>(0,e.unref)(j)&&(0,e.unref)(j)(...t),onCanplay:r[3]||=(...t)=>(0,e.unref)(j)&&(0,e.unref)(j)(...t),onDurationchange:r[4]||=(...t)=>(0,e.unref)(W)&&(0,e.unref)(W)(...t),onTimeupdate:r[5]||=(...t)=>(0,e.unref)(W)&&(0,e.unref)(W)(...t),onVolumechange:r[6]||=(...t)=>(0,e.unref)(W)&&(0,e.unref)(W)(...t),onPlaying:r[7]||=(...t)=>(0,e.unref)(H)&&(0,e.unref)(H)(...t),onPause:r[8]||=e=>z.value=!1,onEnded:r[9]||=(...t)=>(0,e.unref)(B)&&(0,e.unref)(B)(...t),onError:r[10]||=(...t)=>(0,e.unref)(k)&&(0,e.unref)(k)(...t)},null,40,yt)):(0,e.createCommentVNode)(``,!0),v.value?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:3,type:`button`,class:(0,e.normalizeClass)([`media-audio-artwork media-preview`,{"media-preview--ready":(0,e.unref)(O)===`ready`}]),"aria-label":t.layout===`reel`?(0,e.unref)(z)?`Pause audio`:`Play audio`:`Audio`,disabled:t.layout!==`reel`,onClick:Y},[D.value?((0,e.openBlock)(),(0,e.createElementBlock)(`img`,{key:0,class:`media-audio-cover`,src:D.value.src,width:D.value.width??void 0,height:D.value.height??void 0,fetchpriority:t.fetchPriority,alt:``,decoding:`async`,loading:(0,e.unref)(ue),onLoad:r[11]||=n=>t.layout===`masonry`&&(0,e.unref)(A)(n),onError:ge},null,40,xt)):((0,e.openBlock)(),(0,e.createElementBlock)(`span`,St,[(0,e.createVNode)((0,e.unref)(ye),{size:64,"stroke-width":1.5})]))],10,bt)):(0,e.unref)(de)?((0,e.openBlock)(),(0,e.createElementBlock)(`video`,{key:4,ref_key:`mediaElement`,ref:F,"data-source-generation":(0,e.unref)(P),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(O)===`ready`,"media-preview--reel-video":t.layout===`reel`}]),src:x.value,width:C.value??void 0,height:w.value??void 0,autoplay:(0,e.unref)(ne),loop:!t.advanceOnMediaEnd,muted:(0,e.unref)(R),playsinline:``,preload:(0,e.unref)(fe),onLoadedmetadata:r[12]||=(...t)=>(0,e.unref)(V)&&(0,e.unref)(V)(...t),onProgress:r[13]||=(...t)=>(0,e.unref)(j)&&(0,e.unref)(j)(...t),onLoadeddata:r[14]||=(...t)=>(0,e.unref)(j)&&(0,e.unref)(j)(...t),onCanplay:r[15]||=(...t)=>(0,e.unref)(j)&&(0,e.unref)(j)(...t),onDurationchange:r[16]||=(...t)=>(0,e.unref)(W)&&(0,e.unref)(W)(...t),onTimeupdate:r[17]||=(...t)=>(0,e.unref)(W)&&(0,e.unref)(W)(...t),onVolumechange:r[18]||=(...t)=>(0,e.unref)(W)&&(0,e.unref)(W)(...t),onPlaying:r[19]||=(...t)=>(0,e.unref)(H)&&(0,e.unref)(H)(...t),onPause:r[20]||=e=>z.value=!1,onEnded:r[21]||=(...t)=>(0,e.unref)(B)&&(0,e.unref)(B)(...t),onClick:Y,onError:r[22]||=(...t)=>(0,e.unref)(k)&&(0,e.unref)(k)(...t)},null,42,Ct)):v.value?(0,e.createCommentVNode)(``,!0):((0,e.openBlock)(),(0,e.createElementBlock)(`img`,{key:5,ref_key:`imageElement`,ref:ee,"data-source-generation":(0,e.unref)(P),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(O)===`ready`}]),src:x.value,width:C.value??void 0,height:w.value??void 0,fetchpriority:t.fetchPriority,alt:``,decoding:`async`,loading:(0,e.unref)(ue),onLoad:r[23]||=(...t)=>(0,e.unref)(A)&&(0,e.unref)(A)(...t),onError:r[24]||=(...t)=>(0,e.unref)(k)&&(0,e.unref)(k)(...t)},null,42,wt))],8,_t))]),_:1},8,[`css`,`name`]),(0,e.createVNode)(He,{item:t.item,"media-card":t.mediaCard,"media-index":m.value,"media-item":h.value,"media-source":t.mediaSource??`preview`},null,8,[`item`,`media-card`,`media-index`,`media-item`,`media-source`]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{disabled:!pe.value||!t.reelControlsTarget,to:t.reelControlsTarget??`body`},[(0,e.createVNode)(e.Transition,{name:`vibe-reel-media-controls`,css:pe.value},{default:(0,e.withCtx)(()=>[me.value?((0,e.openBlock)(),(0,e.createBlock)(Be,{key:he.value,"current-time":(0,e.unref)(I),"data-control-post-id":pe.value?t.item.postId:void 0,duration:(0,e.unref)(L),layout:t.layout,"media-type":v.value?`audio`:`video`,muted:(0,e.unref)(te),playing:(0,e.unref)(z),volume:(0,e.unref)(K),onSeek:(0,e.unref)(U),onToggleMute:(0,e.unref)(ie),onTogglePlayback:(0,e.unref)(G),onVolumeChange:(0,e.unref)(re)},null,8,[`current-time`,`data-control-post-id`,`duration`,`layout`,`media-type`,`muted`,`playing`,`volume`,`onSeek`,`onToggleMute`,`onTogglePlayback`,`onVolumeChange`])):(0,e.createCommentVNode)(``,!0)]),_:1},8,[`css`])],8,[`disabled`,`to`])),s.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[25]||=(0,e.withModifiers)(t=>(0,e.unref)(J)(m.value-1,t),[`stop`]),onKeydown:r[26]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(_e),{size:20})],40,Tt),(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[27]||=(0,e.withModifiers)(t=>(0,e.unref)(J)(m.value+1,t),[`stop`]),onKeydown:r[28]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(ve),{size:20})],40,Et)],2)):(0,e.createCommentVNode)(``,!0),q.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[29]||=(0,e.withModifiers)(e=>n.$emit(`activate`,ae(e)),[`stop`]),onKeydown:r[30]||=(0,e.withModifiers)(()=>{},[`stop`])},null,40,Dt)):(0,e.createCommentVNode)(``,!0)],42,gt),t.cardFooter?((0,e.openBlock)(),(0,e.createBlock)(De,{key:1,index:t.index,item:t.item,layout:t.layout,"loaded-count":t.loadedCount,"media-index":m.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,mt))}});function kt(t){function n(e){return e.flatMap(e=>{let n=t.items()[e];if(!n)return[];let r=t.mediaIndices().get(n.postId)??0,i=m(n.postId,r);return t.previewStates().get(i)===`ready`?[{key:i,mediaIndex:r,postId:n.postId}]:[]})}function r(t,r){let i=new Set;(0,e.watch)(()=>n(t()),e=>{let t=new Set(e.map(({key:e})=>e));e.forEach(({key:e,mediaIndex:t,postId:n})=>{i.has(e)||r(n,t)}),i=t},{immediate:!0,flush:`post`})}r(t.visibleIndices,t.onVisible),r(t.fullyVisibleIndices,t.onFullyVisible)}var At=1500;function jt(t){let n=(0,e.shallowRef)(0),r=0,i=null,a=0,o=0,s=null,c=0,l=null,u=null,d=0;function f(){s!==null&&(cancelAnimationFrame(s),s=null)}function p(e,t,n,r){return i=e,l=t.slice(),u=H(e.items,u??V(r.items),n),c=e.items.length<t.length?Math.max(c,r.height,e.height):0,e.items.length<t.length&&e.items.length>n&&m(),e}function m(){s===null&&(s=requestAnimationFrame(()=>{s=null;let e=t.items(),r=i;if(!r||r.items.length>=e.length)return;let a=r.items.length;p(R(e,t.width.value,{additionalHeight:t.additionalHeight.value,gap:t.gap.value,minColumnWidth:t.minColumnWidth.value},r,a,{throughIndex:t.packThroughIndex(),untilIndex:a+At}),e,a,r),n.value+=1}))}let h=(0,e.computed)(()=>{n.value;let e=t.items(),s=t.width.value,h={additionalHeight:t.additionalHeight.value,gap:t.gap.value,minColumnWidth:t.minColumnWidth.value},g=i;if(g&&l&&d===s&&a===h.gap&&r===h.additionalHeight&&o===h.minColumnWidth){let n=0,r=l,i=Math.min(r.length,e.length);for(;n<i&&r[n]===e[n];)n+=1;return n===e.length&&n===r.length?(g.items.length>0&&g.items.length<e.length&&m(),g):(f(),p(R(e,s,h,g,n,{throughIndex:t.packThroughIndex(),untilBottom:t.packUntilBottom()}),e,n,g))}f();let _=L(e,s,h);return i=_,l=e.slice(),d=s,a=h.gap,r=h.additionalHeight,o=h.minColumnWidth,u=V(_.items),c=0,_}),g=(0,e.computed)(()=>(h.value,u??V(h.value.items)));return(0,e.onBeforeUnmount)(f),{ensurePackedThrough(e){let r=t.items(),a=i;if(!a||a.items.length>=r.length||a.height>=e)return;f();let o=a.items.length;p(R(r,t.width.value,{additionalHeight:t.additionalHeight.value,gap:t.gap.value,minColumnWidth:t.minColumnWidth.value},a,o,{throughIndex:t.packThroughIndex(),untilBottom:e}),r,o,a),n.value+=1},layout:h,reservedHeight:()=>c,viewportIndex:g}}var Mt={class:`masonry-feed-shell`},Nt=[`aria-hidden`,`inert`],Pt={key:0,class:`masonry-feed-status-overlay`},Ft=6,It=12,Lt=250,Rt=(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:{},reelAudioState:{},state:{},total:{}},emits:[`activate`,`error`,`fullyVisible`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`visible`],setup(t,{expose:n,emit:r}){let i=0,a=t,o=r,s=(0,e.shallowRef)(null),c=`vibe-masonry-${(0,e.useId)()}`,l=(0,e.shallowRef)(null),u=(0,e.shallowRef)(0),d=(0,e.shallowRef)(Ft),f=(0,e.shallowRef)(0),p=(0,e.shallowRef)(0),h=(0,e.shallowRef)(0),g=(0,e.shallowRef)([]),_=(0,e.shallowRef)([]),v=(0,e.shallowRef)([]),y=0,b=null,x=null,S=null,w=null,T=(0,e.computed)(()=>({additionalHeight:(a.cardHeader?.height??0)+(a.cardFooter?.height??0),gap:d.value,minColumnWidth:W(a.masonry)})),E=[];function O(){let e=y-h.value+f.value+ie(a.masonry,f.value),t=v.value.reduce((e,t)=>{let n=E[t];return n?Math.max(e,n.y+n.height):e},0);return Math.max(e,t)}function k(){return v.value.reduce((e,t)=>Math.max(e,t),-1)}let A=jt({additionalHeight:(0,e.computed)(()=>T.value.additionalHeight),gap:d,items:()=>a.items,minColumnWidth:(0,e.computed)(()=>T.value.minColumnWidth),packThroughIndex:k,packUntilBottom:O,width:u}),j=A.layout,N=A.viewportIndex,P=(0,e.computed)(()=>a.leavingPostIds.size===0?null:te(a.items,u.value,T.value,j.value,e=>a.leavingPostIds.has(a.items[e].postId),{throughIndex:k(),untilBottom:O()})),F=(0,e.computed)(()=>{let e=P.value;return e?{columns:e.columns,height:e.height,items:e.items}:j.value}),I=(0,e.computed)(()=>{let e=P.value;return e?ne(e.items,e.retainedIndices,N.value,e.fromIndex):null}),L=(0,e.computed)(()=>(j.value,Math.max(p.value,A.reservedHeight(),a.leavingPostIds.size===0?F.value.height:j.value.height))),R=(0,e.computed)(()=>({height:`${L.value}px`})),z=(0,e.computed)(()=>!a.infiniteScroll||f.value>0&&h.value+F.value.height<=f.value+1),B=(0,e.computed)(()=>new Set(_.value)),V=(0,e.computed)(()=>v.value.flatMap(e=>{let t=a.items[e],n=F.value.items[e];return!t||!n||n.width<=0||n.height<=0?[]:[{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 G(e){let t={scrollTop:y-h.value,viewportHeight:f.value},n=I.value,r=re(n??N.value,{...t,overscan:e}).indices;return H(r,a.leavingPostIds.size===0?[]:re(N.value,{...t,overscan:e}).indices.filter(e=>{let t=a.items[e];return t!==void 0&&a.leavingPostIds.has(t.postId)}))}function K(){let e=G(0),t=G(ie(a.masonry,f.value));U(_.value,e)||(_.value=e);let n=M(F.value.items,e.filter(e=>{let t=a.items[e];return t&&!a.leavingPostIds.has(t.postId)}),{scrollTop:y-h.value,viewportHeight:f.value});U(g.value,n)||(g.value=n),U(v.value,t)||(v.value=t)}function q(){if(w!==null)return;w=-1;let e=requestAnimationFrame(()=>{w=null,K()});w!==null&&(w=e)}kt({fullyVisibleIndices:()=>g.value,items:()=>a.items,mediaIndices:()=>a.mediaIndices,onFullyVisible:(e,t)=>o(`fullyVisible`,e,t),onVisible:(e,t)=>o(`visible`,e,t),previewStates:()=>a.previewStates,visibleIndices:()=>_.value});function ae(e){let t=F.value.items[e],n=a.items[e]?.postId;if(!t||t.width<=0||t.height<=0)return{};let r=n!==void 0&&a.enteringPostIds.has(n),i=n!==void 0&&a.leavingPostIds.has(n),o=r||i?ee({containerHeight:Math.max(p.value,j.value.height),gap:d.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 J(){let e=s.value;if(!e)return;y=e.scrollTop,f.value=e.clientHeight;let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(Number.parseFloat(t?.paddingTop??``)||0)+(Number.parseFloat(t?.paddingBottom??``)||0);p.value=Math.max(0,e.clientHeight-n);let r=l.value;r&&(h.value=r.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,K())}function oe(e){let t=e.ownerDocument.documentElement.clientWidth;u.value=e.clientWidth,d.value=Math.min(It,Math.max(Ft,t*.0075)),J()}function se(e){let t=e.currentTarget;t&&(y=t.scrollTop,A.ensurePackedThrough(O()),q(),Date.now()>=i&&!a.loadMoreLocked&&a.infiniteScroll&&D(t)&&o(`loadMore`))}function ce(){let e=s.value;Date.now()>=i&&!a.loadMoreLocked&&e&&D(e)&&o(`loadMore`)}(0,e.watch)(()=>a.items.length,(e,t)=>{e>0&&e<t&&(i=Date.now()+Lt)});function ue(){return s.value}return(0,e.watch)(l,e=>{b?.disconnect(),b=null,S!==null&&cancelAnimationFrame(S),e&&(oe(e),!(typeof ResizeObserver>`u`)&&(b=new ResizeObserver(([t])=>{let n=t?.contentRect.width??e.clientWidth;Math.abs(n-u.value)<.5||(S=requestAnimationFrame(()=>{S=null,oe(e)}))}),b.observe(e)))}),(0,e.watch)(s,e=>{x?.disconnect(),x=null,e&&(J(),!(typeof ResizeObserver>`u`)&&(x=new ResizeObserver(J),x.observe(e)))}),(0,e.watch)(F,e=>{E=e.items},{flush:`sync`}),(0,e.watch)([j,F,()=>a.masonry],K,{flush:`post`}),(0,e.onBeforeUnmount)(()=>{b?.disconnect(),x?.disconnect(),S!==null&&cancelAnimationFrame(S),w!==null&&cancelAnimationFrame(w)}),n({getScrollElement:ue,loadIfNearBottom:ce}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Mt,[(0,e.createElementVNode)(`main`,{id:c,ref_key:`galleryElement`,ref:s,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:se},[(0,e.createElementVNode)(`section`,{ref_key:`masonryElement`,ref:l,class:(0,e.normalizeClass)([`masonry`,{"masonry--ready":u.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:i})=>((0,e.openBlock)(),(0,e.createBlock)(Ot,{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,"in-viewport":B.value.has(i),index:i,item:r,"item-style":ae(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)(m)(r.postId,t.mediaIndices.get(r.postId)??0))??`loading`,total:t.total,onActivate:e=>o(`activate`,r.postId,e),onMediaChange:e=>o(`mediaChange`,r.postId,e),onReady:e=>o(`ready`,r.postId,e),onError:e=>o(`error`,r.postId,e)},null,8,[`entering`,`leaving`,`fetch-priority`,`card-footer`,`card-header`,`media-card`,`in-viewport`,`index`,`item`,`item-style`,`loaded-count`,`media-index`,`preview-state`,`total`,`onActivate`,`onMediaChange`,`onReady`,`onError`]))),128))],6)],42,Nt),t.feedFooter||t.isLoadingMore||t.nextPageError||t.hasNext&&z.value||!t.hasNext&&t.canRetryEnd?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Pt,[(0,e.createVNode)(C,{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=>o(`loadMore`),onRetryEnd:r[1]||=e=>o(`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)(le,{"content-size":F.value.height,"controls-id":c,"scroll-element":s.value,suspended:t.suspended},null,8,[`content-size`,`scroll-element`,`suspended`])]))}}),zt=300;function Bt(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/zt),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 Vt=[`aria-label`],Ht=(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,Vt))}}),Ut={class:`reel-viewport`},Wt=[`data-active-post-id`,`data-active-media-index`],Gt=[`role`,`data-status`],Kt=300,qt=250,Jt=(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:{},reelAudioState:{},state:{},total:{}},emits:[`activeChange`,`error`,`loadMore`,`mediaChange`,`ready`,`reelAudioChange`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:r}){let i=0,a=t,s=r,c=(0,e.shallowRef)(null),l=(0,e.shallowRef)(null),f=a.initialPostId===null||a.initialPostId===void 0?-1:a.items.findIndex(e=>e.postId===a.initialPostId),h=(0,e.shallowRef)(Math.max(0,f)),g=(0,e.shallowRef)(!1),_=(0,e.shallowRef)(!1),v=0,y=null,b=null,x=null,S=(0,e.computed)(()=>({gridTemplateRows:`repeat(${a.items.length}, 100cqh)`})),w=(0,e.computed)(()=>{let e=Math.max(0,h.value-2),t=Math.min(a.items.length-1,h.value+2);return a.items.slice(e,t+1).map((t,n)=>({fetchPriority:e+n===h.value?`high`:`low`,index:e+n,item:t}))}),T=(0,e.computed)(()=>a.items[h.value]?.postId),E=(0,e.computed)(()=>a.items[h.value]),O=(0,e.computed)(()=>{let e=T.value;return e===void 0?0:a.mediaIndices.get(e)??0}),k=(0,e.computed)(()=>{let e=T.value;return e===void 0?`loading`:a.previewStates.get(m(e,O.value))??`loading`}),ee=(0,e.computed)(()=>E.value?p(E.value,O.value):null),A=(0,e.computed)(()=>ee.value?u(ee.value,a.mediaSource??`preview`):null),j=(0,e.computed)(()=>k.value===`ready`&&!!(A.value&&o(A.value.type,A.value.src))),M=(0,e.computed)(()=>[T.value,O.value,a.items.length,a.loadMoreLocked,a.reelAutoAdvance.enabled,a.reelAutoAdvance.includePostItems,a.reelAutoAdvance.intervalMs].join(`:`)),N=(0,e.computed)(()=>{let e=E.value,t=!!(e&&a.reelAutoAdvance.includePostItems&&O.value<d(e).length-1),n=a.reelAutoAdvance.intervalMs/1e3;return`Auto advance to the next ${t?`post item`:`post`} in ${n}s`}),P=(0,e.computed)(()=>a.reelAutoAdvance.enabled&&a.reelForward.status===`idle`&&E.value!==void 0&&k.value!==`loading`&&!j.value),F=(0,e.computed)(()=>!a.infiniteScroll||a.items.length<=1),I=(0,e.computed)(()=>a.reelForward.status===`loading`?`Loading the next media…`:a.reelForward.status===`error`?`Unable to load the next media.`:`You reached the end of this feed.`);function L(e){return{gridRow:`${e+1}`}}function R(e){let t=v||e.clientHeight;return t<=0||a.items.length===0?0:Math.min(a.items.length-1,Math.max(0,Math.round(e.scrollTop/t)))}function te(e){let t=e.currentTarget;if(!t)return;let n=v||t.clientHeight,r=Math.max(0,a.items.length-1)*n;g.value=a.items.length>0&&t.scrollTop>r+1,_.value||(h.value=R(t)),Date.now()>=i&&!a.loadMoreLocked&&a.infiniteScroll&&D(t)&&s(`loadMore`)}function z(){let e=c.value;e&&(g.value=!1,H(!0),v=e.clientHeight,e.scrollTop=h.value*v,b!==null&&cancelAnimationFrame(b),b=requestAnimationFrame(()=>{e.scrollTop=h.value*e.clientHeight,v=e.clientHeight,b=null}),B())}function B(){x!==null&&clearTimeout(x),x=setTimeout(()=>{x=null;let e=c.value;e&&(v=e.clientHeight,e.scrollTop=h.value*v),H(!1)},120)}function V(){H(!0);let e=c.value;e&&(v=e.clientHeight,e.scrollTop=h.value*v),B()}function H(e){_.value=e,c.value?.toggleAttribute(`data-resizing`,e)}function ne(){let e=c.value;Date.now()>=i&&!a.loadMoreLocked&&e&&D(e)&&s(`loadMore`)}(0,e.watch)(()=>a.items.length,(e,t)=>{e>0&&e<t&&(i=Date.now()+qt)});function U(e){let t=E.value;if(!t)return!1;let n=d(t).length;if(n<=1)return!1;let r=(O.value+e+n)%n;return s(`mediaChange`,t.postId,r),!0}function re(e){let t=h.value+e;return!c.value||t<0||t>=a.items.length?!1:(K(t),!0)}function W(e,t){let n=a.items.findIndex(t=>t.postId===e),r=a.items[n];return!c.value||!r||t<0||t>r.items.length?!1:((a.mediaIndices.get(e)??0)!==t&&s(`mediaChange`,e,t),n!==h.value&&K(n),!0)}function ie(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function G(e){let t=c.value;if(!t)return Promise.resolve();let n=e*(v||t.clientHeight);return h.value=e,Bt(t,n,ie())}function K(e){G(e)}async function q(e){let t=a.items.findIndex(t=>t.postId===e);return t<0||t===h.value?!1:(await G(t),!0)}async function ae(e){return U(e)?(ie()||await new Promise(e=>setTimeout(e,Kt)),!0):!1}function J(){if(!a.reelAutoAdvance.enabled)return;let e=E.value;if(!e)return;if(a.reelAutoAdvance.includePostItems&&O.value<d(e).length-1){s(`mediaChange`,e.postId,O.value+1);return}let t=h.value+1,n=a.items[t];if(!n){a.hasNext&&!a.loadMoreLocked&&s(`loadMore`);return}a.reelAutoAdvance.includePostItems&&(a.mediaIndices.get(n.postId)??0)!==0&&s(`mediaChange`,n.postId,0),K(t)}function oe(e,t){!a.reelAutoAdvance.enabled||e!==T.value||t!==O.value||!j.value||J()}return(0,e.watch)(c,e=>{y?.disconnect(),y=null,e&&(v=e.clientHeight,!(typeof ResizeObserver>`u`)&&(y=new ResizeObserver(z),y.observe(e)))}),(0,e.watch)(()=>a.items.length,async t=>{let n=a.initialPostId,r=n==null?-1:a.items.findIndex(({postId:e})=>e===n);h.value=r>=0?r:Math.min(h.value,Math.max(0,t-1)),await(0,e.nextTick)(),z()}),(0,e.watch)(T,e=>{e!==void 0&&s(`activeChange`,e)},{immediate:!0}),(0,e.onMounted)(()=>{window.addEventListener(`resize`,V),window.addEventListener(`orientationchange`,V),f>=0&&(0,e.nextTick)(z)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`resize`,V),window.removeEventListener(`orientationchange`,V),y?.disconnect(),b!==null&&cancelAnimationFrame(b),x!==null&&clearTimeout(x)}),n({activeIndex:h,activePostId:T,changeActiveMedia:U,loadIfNearBottom:ne,moveActivePost:re,navigateToItem:W,transitionActiveMedia:ae,transitionActivePost:q}),(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)(De,{key:0,index:h.value,item:E.value,layout:`reel`,"loaded-count":t.items.length,"media-index":O.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`,Ut,[(0,e.createElementVNode)(`div`,{ref_key:`galleryElement`,ref:c,class:`gallery-shell reel-feed`,"data-active-post-id":T.value,"data-active-media-index":O.value,onScrollPassive:te},[t.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)(w.value,({fetchPriority:n,item:i,index:o})=>((0,e.openBlock)(),(0,e.createBlock)(Ot,{key:i.postId,active:o===h.value&&!g.value,"advance-on-media-end":a.reelAutoAdvance.enabled&&o===h.value,class:`reel-item`,entering:!1,"fetch-priority":n,index:o,item:i,"item-style":L(o),"media-card":t.mediaCard,layout:`reel`,"loaded-count":t.items.length,"media-index":t.mediaIndices.get(i.postId)??0,"media-source":t.mediaSource,"preview-state":t.previewStates.get((0,e.unref)(m)(i.postId,t.mediaIndices.get(i.postId)??0))??`loading`,"reel-controls-target":l.value,"reel-audio-state":t.reelAudioState,"stationary-reel-controls":``,total:t.total,onMediaChange:e=>s(`mediaChange`,i.postId,e),onEnded:e=>oe(i.postId,e),onReady:e=>s(`ready`,i.postId,e),onReelAudioChange:r[1]||=e=>s(`reelAudioChange`,e),onError:e=>s(`error`,i.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`,`reel-audio-state`,`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=>s(`retryForward`)},` Retry `)):(0,e.createCommentVNode)(``,!0)],8,Gt)),t.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(C,{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[2]||=e=>s(`loadMore`),onRetryEnd:r[3]||=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)],40,Wt),(0,e.createElementVNode)(`div`,{ref_key:`reelControlsElement`,ref:l,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)(De,{key:1,index:h.value,item:E.value,layout:`reel`,"loaded-count":t.items.length,"media-index":O.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)(Ht,{key:M.value,"duration-ms":t.reelAutoAdvance.intervalMs,label:N.value,onComplete:J},null,8,[`duration-ms`,`label`])):(0,e.createCommentVNode)(``,!0)],2))}}),Yt=[`data-info-sheet-open`,`data-info-sheet-mode`],Xt=[`aria-hidden`,`inert`],Zt={key:0,class:`reel-info-sheet-layer`,"data-test":`reel-info-sheet`},Qt=[`role`,`aria-modal`,`tabindex`,`data-active-post-id`],$t=(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:{},reelAudioState:{},state:{},total:{}},emits:[`activeChange`,`closeInfoSheet`,`error`,`loadMore`,`mediaChange`,`ready`,`reelAudioChange`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:r}){let i=t,a=r,o=(0,e.shallowRef)(null),s=(0,e.shallowRef)(null),c=null,l=(0,e.computed)(()=>{let e=i.initialPostId===null||i.initialPostId===void 0?-1:i.items.findIndex(e=>e.postId===i.initialPostId);return Math.max(0,e)}),u=(0,e.computed)(()=>i.items[l.value]),f=(0,e.computed)(()=>u.value??(i.reelForward.status===`idle`?void 0:i.forwardItem??void 0)),m=(0,e.computed)(()=>u.value?l.value:i.forwardIndex??0),h=(0,e.computed)(()=>{let e=f.value?.postId;return e===void 0?0:i.mediaIndices.get(e)??0}),g=(0,e.computed)(()=>!!(i.infoSheet&&i.infoSheetEnabled&&f.value)),_=(0,e.computed)(()=>{let e=f.value;return e?{close:v,index:m.value,item:e,layout:`reel`,loadedCount:i.items.length,mediaCount:d(e).length,mediaIndex:h.value,mediaItem:p(e,h.value),mediaSource:i.mediaSource??`preview`,origin:i.origin,total:i.total}:null});function v(){a(`closeInfoSheet`)}function y(e){return o.value?.changeActiveMedia(e)??!1}function b(){o.value?.loadIfNearBottom()}function x(e){return o.value?.moveActivePost(e)??!1}function S(e,t){return o.value?.navigateToItem(e,t)??!1}function C(e){return o.value?.transitionActiveMedia(e)??Promise.resolve(!1)}function w(e){return o.value?.transitionActivePost(e)??Promise.resolve(!1)}function T(e,t){a(`error`,e,t)}function E(e,t){a(`mediaChange`,e,t)}function D(e,t){a(`ready`,e,t)}return(0,e.watch)(()=>({overlay:i.infoSheetOverlay,visible:g.value}),async(t,n)=>{if(t.visible&&!n?.visible){c=document.activeElement instanceof HTMLElement?document.activeElement:null,t.overlay&&(await(0,e.nextTick)(),s.value?.focus({preventScroll:!0}));return}if(!t.visible&&n?.visible&&c?.isConnected){let t=c;c=null,await(0,e.nextTick)(),t.focus({preventScroll:!0})}}),(0,e.onBeforeUnmount)(()=>{c=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)(Jt,{ref_key:`reelFeed`,ref:o,"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-audio-state":t.reelAudioState,"reel-forward":t.reelForward,state:t.state,total:t.total,onActiveChange:r[0]||=e=>a(`activeChange`,e),onError:T,onLoadMore:r[1]||=e=>a(`loadMore`),onMediaChange:E,onReady:D,onRetryEnd:r[2]||=e=>a(`retryEnd`),onRetryForward:r[3]||=e=>a(`retryForward`),onReelAudioChange:r[4]||=e=>a(`reelAudioChange`,e)},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-audio-state`,`reel-forward`,`state`,`total`])],8,Xt),(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`,Zt,[(0,e.createElementVNode)(`aside`,{ref_key:`sheetElement`,ref:s,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":f.value?.postId},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.infoSheet.component),(0,e.normalizeProps)((0,e.guardReactiveProps)(_.value)),null,16))],8,Qt)])):(0,e.createCommentVNode)(``,!0)]),_:1})],10,Yt))}});function en(e,t,n,r,i){let a=e.items.findIndex(e=>e.postId===t),o=e.items[a];if(!o)return null;let s=f(o,n),c=p(o,s);return{item:o,layout:r,media:c,mediaId:c.mediaId??null,mediaIndex:s,origin:i,phoneMode:e.phoneMode,postId:o.postId,postIndex:a}}function tn(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=en(t,e.postId,e.mediaIndex,`reel`,e.origin);i&&n(i)},{flush:`sync`})}function nn(t,n){let r=new Set,i=(0,e.shallowRef)(new Map),a=(0,e.shallowRef)(new Map),o=(0,e.shallowRef)(new Map),s=()=>t.reelMediaSource===`preview`?i:t.reelMediaSource===`mobile`?o:a,c=(0,e.computed)(()=>s().value),l=new Set;function u(){r.clear(),l.clear(),i.value=new Map,a.value=new Map,o.value=new Map}function d(e,t,n,r){let i=m(t,n);e.value.get(i)!==r&&(e.value=new Map(e.value).set(i,r))}function f(e,n,r,i){return en(t,e,n,r,i)}function p(e,t,r,i){let a=f(e,t,r,i);a&&n.ready(a)}function h(e,t){d(i,e,t,`error`)}function g(e,t){d(i,e,t,`ready`),p(e,t,`masonry`,null)}function _(e,t){d(s(),e,t,`error`)}function v(e,n){d(s(),e,n,`ready`),p(e,n,`reel`,t.reelOrigin??`reel`)}function y(e,t){let r=m(e,t);if(l.has(r))return;let i=f(e,t,`masonry`,null);i&&(l.add(r),n.visible(i))}function b(e,t,i,a){let o=[i,m(e,t)].join(`:`);if(r.has(o))return;let s=f(e,t,i,a);s&&(r.add(o),n.fullyVisible(s))}function x(e,t){b(e,t,`masonry`,null)}return tn(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(m(e,n))===`ready`}},(e,t)=>{e.postId===null||!e.ready||t?.ready&&t.postId===e.postId&&t.mediaIndex===e.mediaIndex&&t.origin===e.origin||b(e.postId,e.mediaIndex,`reel`,e.origin)},{flush:`post`}),{markMasonryFullyVisible:x,markMasonryVisible:y,markPreviewError:h,markPreviewReady:g,markReelError:_,markReelReady:v,originalStates:a,previewStates:i,reelStates:c,resetMediaLifecycle:u}}var rn=[];function an(e){return rn.push(e),()=>{let t=rn.indexOf(e);t>=0&&rn.splice(t,1)}}function on(e){if(!e.isActive())return!1;let t=rn.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 sn(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&&!on(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=an(n),window.addEventListener(`keydown`,i)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`keydown`,i),r?.(),r=null})}var cn=35,ln=420,un=(0,e.defineComponent)({__name:`VibeSurface`,props:{canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},mediaCard:{},masonry:{},reelInfoSheet:{},reelAudioState:{},state:{}},emits:[`activeReelChange`,`closeReel`,`loadMore`,`mediaFullyVisible`,`mediaReady`,`mediaVisible`,`openReel`,`reelMediaChange`,`reelInfoSheetChange`,`reelAudioChange`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:r}){let i=t,a=r,o=(0,e.shallowRef)(null),s=(0,e.shallowRef)(null),c=(0,e.shallowRef)(null),l=(0,e.shallowRef)(null),u=(0,e.shallowRef)(!1),p=(0,e.shallowRef)(new Set),m=(0,e.shallowRef)(new Map),h=(0,e.shallowRef)(new Set),_=(0,e.shallowRef)(new Map),v=(0,e.computed)(()=>Object.freeze([...i.state.items])),y=(0,e.computed)(()=>g(i.state,v.value)),{markMasonryFullyVisible:b,markMasonryVisible:x,markPreviewError:S,markPreviewReady:C,markReelError:w,markReelReady:T,originalStates:D,previewStates:O,reelStates:k,resetMediaLifecycle:ee}=nn(i.state,{fullyVisible:e=>a(`mediaFullyVisible`,e),ready:e=>a(`mediaReady`,e),reelChange:e=>a(`reelMediaChange`,e),visible:e=>a(`mediaVisible`,e)}),A=new Set(i.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,p.value=new Set})})}function I(e,t){let n=i.state.items.find(t=>t.postId===e);if(!n)return;let r=f(n,t);(i.state.mediaIndices.get(e)??0)!==r&&(i.state.mediaIndices=new Map(i.state.mediaIndices).set(e,r))}async function L(){await(0,e.nextTick)(),(i.state.layout===`reel`||i.state.reelOrigin===`masonry`?s.value:o.value)?.loadIfNearBottom()}function R(e){return i.state.isLoading||i.state.items.length===0||i.state.layout!==`reel`&&i.state.reelOrigin!==`masonry`?!1:s.value?.changeActiveMedia?.(e)??!1}function te(e){return i.state.isLoading||i.state.items.length===0||i.state.layout!==`reel`&&i.state.reelOrigin!==`masonry`?!1:s.value?.moveActivePost?.(e)??!1}function z(e){if(!(i.state.layout===`reel`||i.state.reelOrigin===`masonry`)||i.state.isLoading)return`reel-inactive`;let t=i.state.items.find(t=>t.postId===e.postId);if(!t)return`not-found`;let n=d(t).findIndex(t=>t.mediaId===e.mediaId);return n<0?`not-found`:s.value?.navigateToItem?.(e.postId,n)?`navigated`:`reel-inactive`}function B(){return i.state.layout!==`masonry`||i.state.reelOrigin===`masonry`?null:o.value?.getScrollElement?.()??null}function V(t,n){M=t,N=n===`keyboard`,a(`openReel`,t),(0,e.nextTick)(()=>c.value?.focus())}function H(e){let t=l.value?.querySelectorAll(`.masonry-feed [data-post-id]`)??[];return Array.from(t).find(t=>t.dataset.postId===String(e))??null}function ne(e,t){if(i.state.layout!==`masonry`||i.state.reelOrigin!==null||P())return 0;let n=[...new Set(e)],r=n.filter(H);if(r.length===0)return 0;let a=new Map(_.value),o=t?.staggerMs??cn;return r.forEach((e,t)=>{a.set(e,t*o)}),p.value=new Set([...p.value].filter(e=>!r.includes(e))),h.value=new Set([...h.value,...n]),_.value=a,ln+(r.length-1)*o}function U(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 re(){i.state.reelOrigin===`masonry`&&(M??=i.state.activeReelPostId,u.value=!0,a(`closeReel`))}function W(){let t=M,n=N;u.value=!1,M=null,N=!1,(0,e.nextTick)(()=>{t!==null&&U(t,n)})}return sn({closeMasonryReel:re,element:()=>l.value,isReelLeaving:()=>u.value,reelRenderer:()=>s.value,setReelInfoSheet:e=>a(`reelInfoSheetChange`,e),state:i.state}),(0,e.watch)(()=>{let e=i.state.items;return[e,e.length]},([e])=>{let t=e.map(e=>e.postId),n=t.filter(e=>!A.has(e)),r=new Set(t);if(A=new Set(t),h.value=new Set([...h.value].filter(e=>r.has(e))),_.value=new Map([..._.value].filter(([e])=>r.has(e))),n.length===0||P())return;let i=new Map;t.forEach(e=>{let t=m.value.get(e);t!==void 0&&i.set(e,t)}),n.forEach((e,t)=>{i.set(e,t*cn)}),m.value=i,p.value=new Set([...p.value,...n]),F()},{flush:`sync`}),(0,e.onBeforeUnmount)(()=>{j!==null&&cancelAnimationFrame(j)}),n({changeActiveReelMedia:R,getAutoScrollElement:B,loadIfNearBottom:L,moveActiveReelPost:te,navigateToReelItem:z,resetMediaLifecycle:ee,startItemRemoval:ne,transitionActiveReelMedia:e=>s.value?.transitionActiveMedia?.(e)??Promise.resolve(!1),transitionActiveReelPost:e=>s.value?.transitionActivePost?.(e)??Promise.resolve(!1)}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{ref_key:`surfaceElement`,ref:l,class:`vibe-surface`},[t.state.layout===`reel`&&(t.state.items.length>0||t.state.reelForward.status!==`idle`)?((0,e.openBlock)(),(0,e.createBlock)($t,{key:0,ref_key:`reelRenderer`,ref:s,"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-audio-state":t.reelAudioState,"reel-forward":t.state.reelForward,state:y.value,total:t.state.total,onActiveChange:r[0]||=e=>a(`activeReelChange`,e),onCloseInfoSheet:r[1]||=e=>a(`reelInfoSheetChange`,!1),onError:(0,e.unref)(w),onLoadMore:r[2]||=e=>a(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(T),onRetryEnd:r[3]||=e=>a(`retryEnd`),onRetryForward:r[4]||=e=>a(`retryForward`),onReelAudioChange:r[5]||=e=>a(`reelAudioChange`,e)},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-audio-state.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)(E,{key:1,actions:t.feedFooterActions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,state:y.value,onLoadMore:r[6]||=e=>a(`loadMore`),onRetryEnd:r[7]||=e=>a(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`state`])):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:2},[(0,e.createVNode)(Rt,{ref_key:`masonryRenderer`,ref:o,"can-retry-end":t.canRetryEnd,"entering-post-ids":p.value,"entry-delays":m.value,"leaving-post-ids":h.value,"removal-delays":_.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`||u.value,state:y.value,total:t.state.total,onActivate:V,onError:(0,e.unref)(S),onFullyVisible:(0,e.unref)(b),onLoadMore:r[8]||=e=>a(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(C),onRetryEnd:r[9]||=e=>a(`retryEnd`),onVisible:(0,e.unref)(x)},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.onFullyVisible.onReady.onVisible`.split(`.`)),(0,e.createVNode)(e.Transition,{name:`vibe-reel-viewer`,onAfterLeave:W},{default:(0,e.withCtx)(()=>[t.state.reelOrigin===`masonry`?((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{key:0,ref_key:`reelOverlay`,ref:c,class:`vibe-reel-overlay`,role:`dialog`,"aria-label":`Media viewer`,"aria-modal":`true`,tabindex:`-1`},[(0,e.createVNode)($t,{ref_key:`reelRenderer`,ref:s,"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-audio-state":t.reelAudioState,"reel-forward":t.state.reelForward,state:y.value,total:t.state.total,onActiveChange:r[10]||=e=>a(`activeReelChange`,e),onCloseInfoSheet:r[11]||=e=>a(`reelInfoSheetChange`,!1),onError:(0,e.unref)(w),onLoadMore:r[12]||=e=>a(`loadMore`),onMediaChange:I,onReady:(0,e.unref)(T),onRetryEnd:r[13]||=e=>a(`retryEnd`),onRetryForward:r[14]||=e=>a(`retryForward`),onReelAudioChange:r[15]||=e=>a(`reelAudioChange`,e)},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-audio-state.reel-forward.state.total.onError.onReady`.split(`.`))],512)):(0,e.createCommentVNode)(``,!0)]),_:1})],64))],512))}});function dn(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 fn(e){return`${typeof e}:${String(e)}`}function pn(e){return e.mediaId===void 0?`source:${e.src}\u0000${e.preview?.src??``}`:`id:${fn(e.mediaId)}`}function mn(e,t){let n=[...e],r=new Map(e.map((e,t)=>[fn(e.postId),t]));return t.forEach(e=>{let t=fn(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(pn)),s=[e,...e.items].filter(e=>{let t=pn(e);return o.has(t)?!1:(o.add(t),!0)});s.length>0&&(n[i]={...a,items:[...a.items,...s]})}),n}function hn(e){return Object.prototype.hasOwnProperty.call(e,`current`)?e.current??null:e.next}function gn(e,t,n,r){let i=dn(e),a=n.filterItems(i.items),o=hn(i);t.items=mn(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 _n=2e3,vn=1e4,yn=250,bn={delayRemainingMs:null,nextRequestAt:null};function xn(e,t){return e===void 0?t:Math.floor(e)}function Sn(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 Cn(e,t={}){let n=xn(t.delayStepMs,_n),r=xn(t.delayMaxMs,vn);return Math.min(Math.max(0,e)*n,r)}function Q(e){if(e==null||!Number.isFinite(e))return{...bn};let t=Math.max(0,Math.floor(e-Date.now()));return t>0?{delayRemainingMs:t,nextRequestAt:e}:{...bn}}async function wn({delayMs:e,onChange:t,signal:n}){if(n.aborted)throw new DOMException(`Aborted`,`AbortError`);if(e<=0){t({...bn});return}let r=Date.now()+e;t({delayRemainingMs:e,nextRequestAt:r}),await new Promise((i,a)=>{let o=!1,s=setInterval(f,yn),c=setTimeout(()=>u(),e);function l(){clearInterval(s),clearTimeout(c),n.removeEventListener(`abort`,d),t({...bn})}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 Tn=class{interval=null;constructor(e){this.onChange=e}clear(){this.interval!==null&&clearInterval(this.interval),this.interval=null,this.onChange({...bn})}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()},yn))}};function En(e,t=!0){return e.maxAdditionalPages===`unlimited`?1/0:(e.maxAdditionalPages??10)+(t?1:0)}function Dn(e){return`${typeof e}:${String(e)}`}function On(e,t){if(!Number.isInteger(e)||e<=0)throw TypeError(`Vibe ${t} must be a positive integer.`)}function kn(e){if(!e)return;if(On(e.pageSize,`autofill pageSize`),e.strategy===`frontend`){Sn(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 An(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 jn(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function Mn(e,t,n){let r=t.autofill;if(!jn(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 Nn(e,t,n){return e?.strategy===`backend`&&t.feedKey===e.feedKey&&t.sessionId===n.sessionId}async function Pn({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??En(s),g=t,_=t,v=t,y=0,b=[],x;for(;y<h;){let e=Dn(g);if(m.has(e))throw Error(`Vibe autofill received a repeated cursor.`);if(m.add(e),await wn({delayMs:Cn(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=dn(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 Fn=class{collection=null;cycle=0;delayCountdown;constructor(e){this.context=e,this.delayCountdown=new Tn(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={...An(e,void 0,!1),cycleId:n,status:`filling`},n}async cancel(){let{cancelRequest:e,options:t,state:n}=this.context;await Mn(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}},In=100;function Ln(e,t){if(!Number.isFinite(t)||t<=0)throw TypeError(`Vibe ${e} must be a positive number.`)}function Rn(e,t,n){return Math.min(n,Math.max(t,e))}function zn(e){if(!e)return;let t=e.minSpeedPxPerSecond??20,n=e.maxSpeedPxPerSecond??240;if(Ln(`autoScroll.minSpeedPxPerSecond`,t),Ln(`autoScroll.maxSpeedPxPerSecond`,n),t>n)throw TypeError(`Vibe autoScroll.minSpeedPxPerSecond cannot exceed maxSpeedPxPerSecond.`);e.speedPxPerSecond!==void 0&&Ln(`autoScroll.speedPxPerSecond`,e.speedPxPerSecond)}function Bn(e){let t=e?.minSpeedPxPerSecond??20,n=e?.maxSpeedPxPerSecond??240;return{enabled:e?.enabled??!1,maxSpeedPxPerSecond:n,minSpeedPxPerSecond:t,paused:!1,speedPxPerSecond:Rn(e?.speedPxPerSecond??80,t,n)}}var Vn=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){Ln(`auto-scroll speed`,e);let t=this.options.state;t.speedPxPerSecond=Rn(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(In,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 Hn(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 Un(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 Wn(e,t,n){let r=t.autofill;return!Nn(e,n,r)||n.sequence<=r.sequence||[`cancelled`,`cancelling`].includes(r.status)||[`complete`,`exhausted`].includes(n.status)&&n.next===void 0?!1:(Un(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 Gn(e,t,n){return e?.strategy!==`backend`||n.feedKey!==e.feedKey||n.pageSize!==e.pageSize?!1:(t.autofill=An(e,n),Un(t,n),!0)}async function Kn(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 qn({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 Hn(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 Pn({existingItems:s.items,initialCursor:s.next,loadPage:a.loadPage,maximumRequests:En(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 Jn(e){return`items`in e?{items:e.items}:`pages`in e?{pages:e.pages}:{until:`end`}}function Yn(e){return`${typeof e}:${String(e)}`}function Xn(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 Zn(e){if(!e)return;if(e.strategy===`frontend`){Sn(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.`);Xn(t.target)}}function Qn(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?Jn(i.target):null}}function $n(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function er({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=Yn(h);if(p.has(e))throw Error(`Vibe fill received a repeated cursor.`);if(p.add(e),await wn({delayMs:Cn(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=dn(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 tr(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 nr(e,t,n){return e?.strategy===`backend`&&n.feedKey===e.feedKey&&n.sessionId===t.fill.sessionId}function rr(e){return Number.isInteger(e.completedPages)&&e.completedPages>=0&&Number.isInteger(e.received)&&e.received>=0&&Number.isInteger(e.sequence)&&e.sequence>=0}function ir(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 ar(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 or(e,t,n,r){return!nr(e,t,n)||!rr(n)||n.sequence<=t.fill.sequence||[`cancelled`,`cancelling`].includes(t.fill.status)||!ir(t,n)?!1:(ar(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 sr(e,t,n,r){if(e?.strategy!==`backend`||n.feedKey!==e.feedKey)return!1;let i=t.fill;return t.fill=Qn(e,n),!rr(n)||!ir(t,n)?(t.fill=i,!1):(ar(t,n,r),!0)}var cr=class{abortController=null;cycle=0;delayCountdown;requestVersion=0;collection=null;constructor(e){this.options=e,this.delayCountdown=new Tn(e=>{Object.assign(this.options.state.fill,e)}),this.syncBackendCountdown()}isActive(){return $n(this.options.state.fill)}applyUpdate(e){let t=or(this.options.fill,this.options.state,e,this.options.onLastCursor);return t&&this.syncBackendCountdown(),t}restoreSession(e){let t=sr(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=Xn(e),i=Xn(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={...Qn(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 tr(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(!$n(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=Qn(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 er({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 lr({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 ur(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 dr(e){if(!Number.isFinite(e)||e<=0)throw TypeError(`Vibe reelAutoAdvance.intervalMs must be a positive number.`)}function fr(e){e?.intervalMs!==void 0&&dr(e.intervalMs)}function pr(e){return{enabled:e?.enabled??!1,includePostItems:e?.includePostItems??!1,intervalMs:e?.intervalMs??5e3}}function mr(e,t){if(typeof t==`boolean`){e.enabled=t;return}fr(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 hr(e){return{enabled:e?.enabled??!1}}function gr(e,t,n){if(n&&!t)throw Error(`Vibe cannot enable reelInfoSheet without a configured component.`);e.enabled=n}function _r(e,t){let n=e.initialPage;return{activeReelPostId:null,autoScroll:Bn(e.autoScroll),autofill:An(e.autofill),current:n?.current??null,error:null,fill:Qn(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:pr(e.reelAutoAdvance),reelForward:{error:null,status:`idle`},reelForwardIndex:null,reelForwardItem:null,reelInfoSheet:hr(e.reelInfoSheet),reelInfoSheetOverlay:!1,reelMediaSource:`original`,reelOrigin:null,total:n?.total??null}}function vr(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 yr(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 br(e){if(zn(e.autoScroll),vr(`cardHeader`,e.cardHeader),vr(`cardFooter`,e.cardFooter),yr(`header`,e.mediaCard?.header),yr(`footer`,e.mediaCard?.footer),e.mediaCard?.feedPreload!==void 0&&e.mediaCard.feedPreload!==`none`&&e.mediaCard.feedPreload!==`visible-post`)throw TypeError(`Vibe mediaCard feedPreload must be "none" or "visible-post".`);if(kn(e.autofill),Zn(e.fill),G(e.masonry),fr(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 xr(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 Sr({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 Pn({existingItems:e?l.items:[],initialCursor:n,loadPage:i,maximumRequests:f?Math.max(0,En(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=dn(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 Hn(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 Cr(e){return`${typeof e}:${String(e)}`}function wr(e){return e.map(({postId:e})=>e)}var Tr=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:wr(e.items),cursor:hn(e),next:e.next,returnedIds:wr(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=Cr(a.cursor);if(a.seenCursors.has(e))throw Error(`Vibe removal reconciliation received a repeated cursor.`);if(await wn({delayMs:Cn(a.pages.length,this.delay),onChange:n,signal:i}),a.pages.length>0&&r())return this.result(a,`paused`);let o=dn(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:wr(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=Cr(e.cursor),n=this.pages.findIndex(({cursor:e})=>Cr(e)===t);n>=0&&(this.pages=this.pages.slice(0,n)),this.pages.push({...e,contributionIds:[...e.contributionIds],returnedIds:[...e.returnedIds]})}};function Er(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 Dr(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 Or(e){if(!Number.isInteger(e.mediaIndex)||e.mediaIndex<0)throw TypeError(`Vibe mediaIndex must be a non-negative integer.`)}var kr=class{generation=0;metadata=new WeakMap;state;constructor(e){this.options=e,this.state=e.state}remove(e){Or(e);let t=this.state.items.findIndex(({postId:t})=>t===e.postId),n=this.state.items[t];if(!n)return null;let r=[...d(n)],i=r[e.mediaIndex];if(!i)return null;let a=Object.freeze({media:i,mediaIndex:e.mediaIndex,postId:e.postId,postIndex:t});this.metadata.set(a,{generation:this.generation,originalItem:n,restored:!1});let o=this.state.mediaIndices.get(n.postId)??0,s=this.isReelOpen()&&this.state.activeReelPostId===n.postId,c=s&&o===e.mediaIndex;return r.splice(e.mediaIndex,1),r.length>0?(this.state.items[t]=Dr(n,r),this.updateMediaIndexAfterRemoval(n.postId,e.mediaIndex,c),a):(this.state.items.splice(t,1),this.options.onPostRemoved(n.postId),this.state.mediaIndices.delete(n.postId),s&&this.advanceFromRemovedPost(a,n),a)}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],r=[...d(n)],i=Math.min(t.mediaIndex,r.length);if(r.splice(i,0,t.media),this.state.items[e]=Dr(n,r),this.state.activeReelPostId!==t.postId)return;let a=this.state.mediaIndices.get(t.postId)??0;a>=i&&this.state.mediaIndices.set(t.postId,a+1)}updateMediaIndexAfterRemoval(e,t,n){let r=this.state.items.find(t=>t.postId===e);if(!r)return;let i=d(r).length,a=this.state.mediaIndices.get(e)??0,o=a;n?o=t<i?t:0:t<a&&(o=a-1),this.state.mediaIndices.set(e,Math.min(o,i-1))}};function Ar(e,t){let n=new Set(t);return e.flatMap((e,t)=>n.has(e.postId)?[{index:t,item:e}]:[])}function jr(e,t){let n=new Set(t.map(({item:e})=>e.postId));return e.filter(e=>!n.has(e.postId))}function Mr(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 Nr=20,Pr=class{generation=0;historyLimit;metadata=new WeakMap;state;history=[];itemOrder;stopItemsWatcher;constructor(t){this.options=t,this.historyLimit=t.historyLimit??Nr,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=jr(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=Mr(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 Ar(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}},Fr=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}stopAtLock(){return this.state.loadMoreLocked?(this.state.reelOrigin===`masonry`?(this.reset(),this.options.onCloseReel()):this.state.reelForward={error:null,status:`end`},!0):!1}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.stopAtLock())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.forward!==e||e.version!==this.forwardVersion)return;if(!this.state.items[e.postIndex]){if(this.stopAtLock())return;if(this.state.nextPageError){this.state.reelForward={error:this.state.nextPageError,status:`error`};return}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}}}}},Ir=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 r=t.mediaIndices.get(e.postId)??0;if(e.mediaIndex===r){if(d(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 Lr(e){let t=new Fr(e),n=new Ir({state:e.state,transitionMedia:t=>e.surface()?.transitionActiveReelMedia(t)??Promise.resolve(!1),transitionPost:t=>e.surface()?.transitionActiveReelPost(t)??Promise.resolve(!1)});return{exactMediaRemoval:new kr({onActivate:e.onActivate,onPostRemoved:t=>e.onItemsRemoved([t]),onPostRestored:t=>e.onItemsRestored([t]),reelForward:t,state:e.state}),itemRemoval:new Pr({historyLimit:e.historyLimit,onItemsRemoved:(n,r,i)=>{e.onItemsRemoved(r.map(({item:e})=>e.postId)),Er(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 Rr=1.5;function zr(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*Rr;return!e.hasHover&&n>0&&n<600&&r}function Br(e){return zr(e)?`reel`:`masonry`}function Vr(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 Hr(e){return zr(Vr(e))}function Ur(e){return Br(Vr(e))}var Wr=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=Ur(this.target);this.state.phoneMode=Hr(this.target),this.state.reelInfoSheetOverlay=this.state.phoneMode,this.state.reelMediaSource=this.state.phoneMode?`mobile`:`original`,this.layoutMode===`responsive`&&this.applyLayout(e)}},Gr=class{state;constructor(t){this.options=t,this.state=(0,e.reactive)(lt({...t.initialReelAudioState,muted:t.initialReelAudioState?.muted??t.mediaCard?.videoMuted??!1}))}get(){return{...this.state}}set(e,t=!1){Object.assign(this.state,lt(e,this.state)),t&&this.options.onReelAudioStateChange?.(this.get())}},Kr=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)}};function qr(e){return String(e)}function Jr(e,t){let n=d(t).length;(e.mediaIndices.get(t.postId)??0)>=n&&e.mediaIndices.set(t.postId,Math.max(0,n-1))}function Yr(e,t){let n=new Map;if(t.forEach(e=>n.set(qr(e.postId),e)),n.size===0)return[];let r=[],i=e.items.map(t=>{let i=n.get(qr(t.postId));if(!i)return t;let a={...i,postId:t.postId};return Jr(e,a),e.reelForwardItem&&qr(e.reelForwardItem.postId)===qr(t.postId)&&(e.reelForwardItem=a),r.push(t.postId),a});return r.length>0&&(e.items=i),r}var Xr=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;reelAudio;state;constructor(t){this.options=t,br(t);let n=t.layout??`masonry`;this.state=(0,e.reactive)(_r(t,n)),this.reelAudio=new Gr(t),this.lastLoadedCursor=t.initialPage?hn(t.initialPage):null,this.notificationItems=h(this.state),this.autoScroll=new Vn({getScrollElement:()=>this.surface?.getAutoScrollElement()??null,state:this.state.autoScroll}),this.autofillController=new Fn({cancelRequest:()=>this.cancelRequest(),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:t.autofill,state:this.state}),this.removalReconciliation=new Tr(t),this.removalReconciliation.recordInitialPage(t.initialPage),this.fillController=new cr({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})=>lr({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 Kr(t.routing,this.state);let r=Lr({historyLimit:t.removalHistoryLimit,onActivate:e=>this.setActiveReelPost(e),onCloseReel:()=>this.closeMasonryReel(),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 Wr(n,this.state,()=>{this.routing.syncFeed()}),this.startStateNotifications()}async mount(){if(this.app)throw Error(`Vibe is already mounted.`);this.startStateNotifications();let t=xr(this.options.target);this.responsiveLayout.mount(t),this.app=(0,e.createApp)(un,{canRetryEnd:!!this.options.loadPage,cardFooter:this.options.cardFooter,cardHeader:this.options.cardHeader,feedFooter:this.options.feedFooter,feedFooterActions:ur(this),mediaCard:this.options.mediaCard,masonry:this.options.masonry,onMediaFullyVisible:this.options.onMediaFullyVisible,onMediaReady:this.options.onMediaReady,onMediaVisible:this.options.onMediaVisible,onReelMediaChange:this.options.onReelMediaChange,reelAudioState:this.reelAudio.state,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),onReelAudioChange:e=>this.reelAudio.set(e,!0),onRetryEnd:()=>{this.retryEnd()},onRetryForward:()=>{this.retryReelForward()}}),this.surface=this.app.mount(t),this.autoScroll.mount(),await Kn(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 g(this.state)}getReelAudioState(){return this.reelAudio.get()}setReelAudioState(e){this.reelAudio.set(e)}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)}updateItems(e){return Yr(this.state,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=Wn(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(jn(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||jn(this.state.autofill))throw Error(`Vibe cannot fill while another page operation is active.`);await this.fillController.start(e)}}restoreAutofillSession(e){let t=Gn(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){gn(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||jn(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 jn(this.state.autofill)&&await this.cancelAutofill(),this.fillController.isActive()&&await this.cancelFill(),this.cancelRequest(),this.state.autofill=An(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.surface?.resetMediaLifecycle(),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=dn(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 lr({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`&&(this.state.nextPageError=null),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&&!(jn(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){mr(this.state.reelAutoAdvance,e)}setReelInfoSheet(e){gr(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 Sr({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=qn({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(g(this.state,this.notificationItems.value)),this.stopStateWatcher=(0,e.watch)(()=>g(this.state,this.notificationItems.value),e=>t(e),{flush:`post`}))}setCurrentCursor(e){this.lastLoadedCursor=e,this.state.current=e}},Zr=e=>new Xr(e);exports.createVibe=Zr;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`vue`);var t=/\.(aac|flac|m4a|mp3|oga|ogg|opus|wav)$/i,n=/\.(m4v|mkv|mov|mp4|ogv|webm)$/i;function r(e){try{return new URL(e).pathname}catch{return e.split(/[?#]/)[0]??e}}function i(e){let i=r(e);return t.test(i)?`audio`:n.test(i)?`video`:`image`}function a(e,t){return e??i(t)}function o(e,t){return a(e,t)!==`image`}function s(e){return{height:e.height,src:e.src,type:e.type,width:e.width}}function c(e,t){if(t===`preview`&&e.preview){let t=a(e.type,e.src)===`audio`?a(e.preview.type,e.preview.src):e.preview.type??e.type;return{...e.preview,type:t}}return t===`mobile`&&e.mobile?{...e.mobile,type:e.mobile.type??e.type}:s(e)}function l(e){let t=e.preview;return!t?.src||t.src===e.src||a(t.type,t.src)!==`image`?null:{...t,type:`image`}}function u(e,t){return a(e.type,e.src)===`audio`?t===`mobile`&&e.mobile&&a(e.mobile.type,e.mobile.src)===`audio`?{...e.mobile,type:`audio`}:{...s(e),type:`audio`}:c(e,t)}function d(e){return[e,...e.items]}function f(e,t){return Math.min(e.items.length,Math.max(0,t))}function p(e,t){return d(e)[f(e,t)]??e}function m(e,t){return`${String(e)}:${t}`}function h(t){return(0,e.computed)(()=>Object.freeze([...t.items]))}function g(t,n,r){return r(_(t,n.value)),(0,e.watch)(()=>_(t,n.value),r,{flush:`post`})}function _(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 v={key:0,class:`gallery-footer`},y={key:0,class:`load-more-status`,role:`status`},b=[`disabled`],x={key:2,class:`end-feed`},S=[`disabled`],C=(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`,v,[t.isLoading?((0,e.openBlock)(),(0,e.createElementBlock)(`p`,y,` 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,b)):((0,e.openBlock)(),(0,e.createElementBlock)(`div`,x,[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,S)]))])):(0,e.createCommentVNode)(``,!0)}}),w=(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)(C,{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`]))}}),T=[`role`],E={class:`gallery-status`},D=(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||r.state.isLoadingMore?`status`:void 0},[(0,e.createElementVNode)(`p`,E,[r.state.error?((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:0},[(0,e.createTextVNode)(` Unable to load media. `)],64)):r.state.isLoading||r.state.isLoadingMore?((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)(w,{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,T))}});function O(e){return e.scrollHeight-e.scrollTop-e.clientHeight<=240}function k(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 A(e){return e.reduce((t,n,r)=>n<e[t]?r:t,0)}function j(e){return Math.max(0,e.containerHeight)+Math.max(0,e.gap)}var M=.8,N=.5;function P(e,t,n){let r=Math.max(0,n.viewportHeight);if(r===0)return[];let i=n.scrollTop,a=i+r;return t.filter(t=>{let n=e[t];if(!n||n.height<=0)return!1;let o=Math.max(0,Math.min(n.y+n.height,a)-Math.max(n.y,i)),s=n.height<=r?n.height:r*M;return o+N>=s})}function F(e,t){if(e<=0)return null;let n=Math.max(0,t.gap),r=Number.isFinite(t.additionalHeight)?Math.max(0,t.additionalHeight??0):0,i=Math.max(1,t.minColumnWidth),a=Math.max(1,Math.floor((e+n)/(i+n)));return{additionalHeight:r,columns:a,gap:n,itemWidth:(e-n*(a-1))/a}}function I(e,t,n){let r=A(t),i=n.itemWidth*k(e)+n.additionalHeight,a={x:r*(n.itemWidth+n.gap),y:t[r],width:n.itemWidth,height:i};return t[r]+=i+n.gap,a}function L(e,t){let n=Array.from({length:t.columns},()=>0),r=t.itemWidth+t.gap;return e.forEach(e=>{let i=r===0?0:Math.round(e.x/r);i<0||i>=t.columns||(n[i]=Math.max(n[i],e.y+e.height+t.gap))}),n}function ee(e,t){return e.length===0?0:Math.max(0,Math.max(...e)-t)}function R(e,t,n){let r=F(t,n);if(!r||e.length===0)return{columns:0,height:0,items:[]};let i=Array.from({length:r.columns},()=>0),a=e.map(e=>I(e,i,r));return{columns:r.columns,height:ee(i,r.gap),items:a}}function z(e,t,n,r,i,a){let o=F(t,n);if(!o||e.length===0)return{columns:0,height:0,items:[]};if(r.columns!==o.columns||i>0&&r.items.length<i)return R(e,t,n);let s=Math.max(0,i),c=a?.untilIndex??e.length,l=a?.untilBottom,u=a?.throughIndex??s,d=s===0?[]:r.items.slice(0,s),f=s===0?Array.from({length:o.columns},()=>0):L(d,o);for(let t=s;t<e.length&&t<c&&!(l!==void 0&&t>s&&t>u&&f.every(e=>e>=l));t+=1)d.push(I(e[t],f,o));return{columns:o.columns,height:ee(f,o.gap),items:d}}function B(e,t,n,r,i,a){let o=F(t,n);if(!o||e.length===0)return{columns:0,fromIndex:0,height:0,items:[],retainedIndices:[]};if(r.items.length!==e.length||r.columns!==o.columns){let a=e.map((e,t)=>t).filter(e=>!i(e)),o=R(a.map(t=>e[t]),t,n),s=e.map((e,t)=>r.items[t]??{height:0,width:0,x:0,y:0});return a.forEach((e,t)=>{s[e]=o.items[t]}),{columns:o.columns,fromIndex:0,height:o.height,items:s,retainedIndices:a}}let s=0;for(;s<e.length&&!i(s);)s+=1;if(s>=e.length)return{...r,fromIndex:s,retainedIndices:e.map((e,t)=>t)};let c=r.items.slice(),l=[];for(let e=0;e<s;e+=1)l.push(e);let u=a?.untilBottom,d=a?.throughIndex??s,f=L(c.slice(0,s),o);for(let t=s;t<e.length;t+=1)if(!i(t)){if(u!==void 0&&l.length>s&&t>d&&f.every(e=>e>=u))break;c[t]=I(e[t],f,o),l.push(t)}let p=new Set(l);for(let t=s;t<e.length;t+=1)i(t)||p.has(t)||(c[t]={height:0,width:0,x:0,y:0});return{columns:o.columns,fromIndex:s,height:ee(f,o.gap),items:c,retainedIndices:l}}function V(e){return{columns:[...e.entries()].sort(([e],[t])=>e-t).map(([,e])=>e.sort((e,t)=>e.top-t.top||e.index-t.index))}}function H(e,t,n){let r=e.get(t.x)??[];r.push({bottom:t.y+t.height,index:n,top:t.y}),e.set(t.x,r)}function U(e,t){let n=new Map;return e.forEach((e,r)=>{H(n,e,t?.[r]??r)}),V(n)}function W(e,t,n,r){if(n<=0)return U(e,r);let i=new Map;t.columns.forEach(t=>{t.forEach(t=>{if(t.index>=n)return;let r=e[t.index];if(!r)return;let a=i.get(r.x)??[];a.push(t),i.set(r.x,a)})});for(let t=n;t<e.length;t+=1)H(i,e[t],r?.[t]??t);return V(i)}function te(e,t,n,r){if(r<=0)return U(t.map(t=>e[t]),t);let i=new Map;return n.columns.forEach(t=>{t.forEach(t=>{if(t.index>=r)return;let n=e[t.index];if(!n)return;let a=i.get(n.x)??[];a.push(t),i.set(n.x,a)})}),t.forEach(t=>{t<r||H(i,e[t],t)}),V(i)}function ne(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 G(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=ne(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 re(e){return e?.minColumnWidth??240}function ie(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 ae(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 K(e,t,n){return Math.min(n,Math.max(t,e))}function oe({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=K(s/a*o,Math.min(Math.max(0,t),o),o),u=Math.max(0,o-l);return{maximumScrollPosition:c,scrollable:!0,thumbOffset:u*(K(n,0,c)/c),thumbSize:l,thumbTravel:u}}var q=[`aria-hidden`],J=[`aria-controls`,`aria-valuemax`,`aria-valuenow`,`tabindex`],se=32,ce=40,le=120,ue=(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)},le)}function x(){s.value=!0,b()}function S(){let e=n.scrollElement,t=i.value;return!e||!t?r:oe({contentSize:e.scrollHeight,minimumThumbSize:se,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-ce:e.key===`ArrowDown`?r+ce: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 j(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),j(t)),t&&typeof MutationObserver<`u`&&(m=new MutationObserver(()=>{j(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,J)],42,q))}}),de=e=>{for(let t in e)if(t.startsWith(`aria-`)||t===`role`||t===`title`)return!0;return!1},fe=e=>e===``,pe=(...e)=>e.filter((e,t,n)=>!!e&&e.trim()!==``&&n.indexOf(e)===t).join(` `).trim(),me=e=>e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).toLowerCase(),he=e=>e.replace(/^([A-Z])|[\s-_]+(\w)/g,(e,t,n)=>n?n.toUpperCase():t.toLowerCase()),ge=e=>{let t=he(e);return t.charAt(0).toUpperCase()+t.slice(1)},_e={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`},ve=({name:t,iconNode:n,absoluteStrokeWidth:r,"absolute-stroke-width":i,strokeWidth:a,"stroke-width":o,size:s=_e.width,color:c=_e.stroke,...l},{slots:u})=>(0,e.h)(`svg`,{..._e,...l,width:s,height:s,stroke:c,"stroke-width":fe(r)||fe(i)||r===!0||i===!0?Number(a||o||_e[`stroke-width`])*24/Number(s):a||o||_e[`stroke-width`],class:pe(`lucide`,l.class,...t?[`lucide-${me(ge(t))}-icon`,`lucide-${me(t)}`]:[`lucide-icon`]),...!u.default&&!de(l)&&{"aria-hidden":`true`}},[...n.map(t=>(0,e.h)(...t)),...u.default?[u.default()]:[]]),Y=(t,n)=>(r,{slots:i,attrs:a})=>(0,e.h)(ve,{...a,...r,iconNode:n,name:t},i),ye=Y(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),be=Y(`chevron-right`,[[`path`,{d:`m9 18 6-6-6-6`,key:`mthhwq`}]]),xe=Y(`disc-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M6 12c0-1.7.7-3.2 1.8-4.2`,key:`oqkarx`}],[`circle`,{cx:`12`,cy:`12`,r:`2`,key:`1c9p78`}],[`path`,{d:`M18 12c0 1.7-.7 3.2-1.8 4.2`,key:`1eah9h`}]]),Se=Y(`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`}]]),Ce=Y(`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`}]]),we=Y(`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=Y(`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`}]]),Ee={401:`Authentication required`,403:`Access forbidden`,404:`Preview not found`,419:`Session expired`,500:`Server error`};function De(e){return e.match(/\/demo-errors\/(401|403|404|419|500)\//)?.[1]??`Error`}function Oe(e){return Ee[De(e)]??`Preview unavailable`}var ke=(0,e.defineComponent)({__name:`CardRegion`,props:{index:{},item:{},layout:{},loadedCount:{},mediaIndex:{},mediaSource:{},placement:{},region:{},style:{},total:{}},setup(t){let n=t,r=(0,e.computed)(()=>f(n.item,n.mediaIndex)),i=(0,e.computed)(()=>d(n.item)),a=(0,e.computed)(()=>p(n.item,r.value)),o=(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`})),s=(0,e.computed)(()=>n.style?.background??n.region.background);return(n,c)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{class:(0,e.normalizeClass)([`media-card-region`,[`media-card-${t.placement}`,{"media-card-region--transparent":s.value===`transparent`}]]),style:(0,e.normalizeStyle)(o.value),onClick:c[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:c[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":i.value.length,"media-index":r.value,"media-item":a.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))}}),Ae=[`aria-busy`,`aria-label`],je={class:`media-error-code`},Me=[`disabled`],Ne=(0,e.defineComponent)({__name:`MediaError`,props:{component:{},label:{},retrying:{type:Boolean},status:{}},emits:[`retry`],setup(t,{emit:n}){let r=t,i=n;function a(){r.retrying||i(`retry`)}return(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{"data-test":`media-error`,class:`media-error`,role:`group`,"aria-busy":t.retrying,"aria-label":`${t.status} ${t.label}`},[t.component?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:0,class:`media-error-component`,onClick:r[0]||=(0,e.withModifiers)(()=>{},[`stop`]),onKeydown:r[1]||=(0,e.withModifiers)(()=>{},[`stop`])},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.component),{label:t.label,retry:a,retrying:t.retrying,status:t.status},null,8,[`label`,`retrying`,`status`]))],32)):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:1},[(0,e.createElementVNode)(`strong`,je,(0,e.toDisplayString)(t.status),1),(0,e.createElementVNode)(`span`,null,(0,e.toDisplayString)(t.label),1),(0,e.createElementVNode)(`button`,{"data-test":`media-retry`,class:`media-error-retry`,type:`button`,disabled:t.retrying,onClick:(0,e.withModifiers)(a,[`stop`]),onKeydown:r[2]||=(0,e.withModifiers)(()=>{},[`stop`])},(0,e.toDisplayString)(t.retrying?`Retrying…`:`Retry`),41,Me)],64))],8,Ae))}}),Pe=[`aria-label`],Fe=[`max`,`value`,`aria-label`,`aria-valuetext`,`disabled`],Ie={key:0,class:`media-controls-row`},Le=[`aria-label`,`title`],Re={class:`media-controls-audio`},ze=[`aria-label`,`title`],Be=[`value`,`aria-label`,`aria-valuetext`],Ve={class:`media-control-time`,"aria-live":`off`},He=(0,e.defineComponent)({__name:`MediaControls`,props:{currentTime:{},duration:{},layout:{},mediaType:{},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)(()=>r.mediaType===`audio`?`audio`:`video`),u=(0,e.computed)(()=>r.mediaType===`audio`?`Audio`:`Video`),d=(0,e.computed)(()=>a(r.currentTime,c.value)),f=(0,e.computed)(()=>({"--media-range-progress":`${c.value>0?d.value/c.value*100:0}%`})),p=(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}`]),role:`group`,"aria-label":`${u.value} 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:d.value,style:(0,e.normalizeStyle)(f.value),"aria-label":`Seek ${l.value}`,"aria-valuetext":`${o(d.value)} of ${o(c.value)}`,disabled:c.value<=0,onInput:r[0]||=e=>i(`seek`,s(e))},null,44,Fe),t.layout===`reel`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Ie,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button media-control-playback`,"aria-label":t.playing?`Pause ${l.value}`:`Play ${l.value}`,title:t.playing?`Pause`:`Play`,onClick:r[1]||=e=>i(`togglePlayback`)},[t.playing?((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(Se),{key:0,size:18,fill:`currentColor`})):((0,e.openBlock)(),(0,e.createBlock)((0,e.unref)(Ce),{key:1,size:18,fill:`currentColor`}))],8,Le),(0,e.createElementVNode)(`div`,Re,[(0,e.createElementVNode)(`button`,{type:`button`,class:`media-control-button`,"aria-label":t.muted?`Unmute ${l.value}`:`Mute ${l.value}`,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)(we),{key:1,size:18}))],8,ze),(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)(p.value),"aria-label":`${u.value} volume`,"aria-valuetext":`${Math.round(t.volume*100)} percent`,onInput:r[3]||=e=>i(`volumeChange`,s(e))},null,44,Be)]),(0,e.createElementVNode)(`output`,Ve,(0,e.toDisplayString)(o(d.value))+` / `+(0,e.toDisplayString)(o(c.value)),1)])):(0,e.createCommentVNode)(``,!0)],42,Pe))}}),Ue={key:0,class:`media-card-overlay-host`,"data-test":`media-card-overlay`},We=(0,e.defineComponent)({__name:`MediaContextOverlay`,props:{item:{},mediaCard:{},mediaIndex:{},mediaItem:{},mediaSource:{}},setup(t){return(n,r)=>t.mediaCard?.overlay?.component?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Ue,[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.mediaCard.overlay.component),{item:t.item,"media-index":t.mediaIndex,"media-item":t.mediaItem,"media-source":t.mediaSource},null,8,[`item`,`media-index`,`media-item`,`media-source`]))])):(0,e.createCommentVNode)(``,!0)}}),Ge=40,Ke=160,qe=24;function Je(t){let n=(0,e.shallowRef)(`next`),r=null,i=0,a=!1,o=null,s=null;function c(e,r){let i=d(t.item()).length,a=(e+i)%i;a!==t.mediaIndex()&&(n.value=e<t.mediaIndex()?`previous`:`next`,t.onChange(a),r?.detail&&r.detail>0&&r.currentTarget?.blur())}function l(){i=0,a=!1,r!==null&&clearTimeout(r),r=null}function u(){r!==null&&clearTimeout(r),r=setTimeout(l,Ke)}function f(e,t,n){return t===1?e*16:t===2?e*n:e}function p(e){if(d(t.item()).length<=1)return;let n=e.currentTarget,r=f(e.deltaX,e.deltaMode,n?.clientWidth||1);if(r===0||(e.preventDefault(),u(),a)||(i+=r,Math.abs(i)<qe))return;let o=Math.sign(i);i=0,a=!0,c(t.mediaIndex()+o)}function m(e){let n=e.touches[0];t.layout()!==`reel`||!n||(o=n.clientX,s=n.clientY)}function h(e){let n=e.changedTouches[0];if(o===null||s===null||!n)return;let r=o-n.clientX,i=s-n.clientY;o=null,s=null,!(Math.abs(r)<=Math.abs(i))&&(Math.abs(r)<Ge||c(t.mediaIndex()+Math.sign(r)))}return(0,e.onBeforeUnmount)(l),{change:c,direction:n,onTouchEnd:h,onTouchStart:m,onWheel:p}}var Ye=new Map,Xe=[],Ze=0,Qe=0;function $e(e,t){return`${t?`timed`:`image`}:${e}`}function et(e,t,n){let r=d(e);if(r.length<2)return[];let i=f(e,t),s=[];for(let e=1;e<r.length;e+=1){let t=i+e,n=i-e;t<r.length&&s.push(t),n>=0&&s.push(n)}let u=new Set;return s.flatMap(e=>{let t=r[e];if(!t)return[];let i=a(t.type,t.src)===`audio`?l(t):c(t,n);if(!i)return[];let s=o(i.type,i.src),d=$e(i.src,s);return u.has(d)?[]:(u.add(d),[{key:d,src:i.src,timed:s}])})}function tt(e){let t=e.element;e.element=null,t&&(t instanceof HTMLVideoElement?(t.pause(),t.removeAttribute(`src`),t.load()):t.removeAttribute(`src`))}function nt(e){Ye.delete(e.key);let t=Xe.indexOf(e);t>=0&&Xe.splice(t,1),e.cancel?.(),e.cancel=null,tt(e)}function rt(e){e.state=`loading`,Ze+=1,e.timed&&(Qe+=1);let t=!1,n=()=>void 0,r=r=>{t||(t=!0,n(),--Ze,e.timed&&--Qe,e.cancel=null,e.state=r,r===`failed`&&tt(e),e.refs===0&&nt(e),it())};if(e.cancel=()=>{t||(t=!0,n(),--Ze,e.timed&&--Qe,tt(e),it())},e.timed){let t=document.createElement(`video`),i=()=>r(`ready`),a=()=>r(`failed`);n=()=>{t.removeEventListener(`loadedmetadata`,i),t.removeEventListener(`error`,a)},t.addEventListener(`loadedmetadata`,i,{once:!0}),t.addEventListener(`error`,a,{once:!0}),t.muted=!0,t.playsInline=!0,t.preload=`metadata`,t.src=e.src,e.element=t,t.load();return}let i=document.createElement(`img`),a=()=>{if(typeof i.decode!=`function`){r(`ready`);return}i.decode().then(()=>r(`ready`),()=>r(`failed`))},o=()=>r(`failed`);n=()=>{i.removeEventListener(`load`,a),i.removeEventListener(`error`,o)},i.addEventListener(`load`,a,{once:!0}),i.addEventListener(`error`,o,{once:!0}),i.decoding=`async`,i.fetchPriority=`low`,i.src=e.src,e.element=i}function it(){for(;Ze<6;){let e=Xe.findIndex(e=>e.refs>0&&e.state===`queued`&&(!e.timed||Qe<2));if(e<0)return;let[t]=Xe.splice(e,1);t&&rt(t)}}function at(e){let t=Ye.get(e.key);t||(t={...e,cancel:null,element:null,refs:0,state:`queued`},Ye.set(t.key,t),Xe.push(t)),t.refs+=1,it();let n=!1;return()=>{n||(n=!0,--t.refs,t.refs===0&&nt(t))}}function ot(t){let n=(0,e.computed)(()=>t.layout()===`masonry`&&t.inViewport()&&t.mediaReady()&&t.mediaCard()?.feedPreload===`visible-post`),r=(0,e.computed)(()=>n.value?et(t.item(),t.mediaIndex(),t.mediaSource()):[]),i=new Map;function a(){let e=new Map(r.value.map(e=>[e.key,e]));i.forEach((t,n)=>{e.has(n)||(t(),i.delete(n))}),r.value.forEach(e=>{i.has(e.key)||i.set(e.key,at(e))})}(0,e.watch)(()=>r.value.map(({key:e})=>e).join(`
2
+ `),a,{immediate:!0}),(0,e.onBeforeUnmount)(()=>{i.forEach(e=>e()),i.clear()})}function st(t){let n=(0,e.computed)(()=>o(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.mediaElement.value?.load())}),{imageLoading:r,mediaIsTimed:n,timedMediaPreload:i}}function ct(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=(0,e.shallowRef)(!1),l=null,u=!1,d=(0,e.computed)(()=>c.value||s.value?`error`:o.value?`loading`:t.previewState());function f(){l!==null&&clearTimeout(l),l=null}function p(e){return Number(e.currentTarget.dataset.sourceGeneration)===i.value}function m(){f(),l=setTimeout(()=>_(),15e3)}function h(e){e&&!p(e)||(f(),o.value=!1,s.value=!1,c.value=!1,t.onReady(t.mediaIndex()))}function g(){let e=n.value;if(e?.complete){e.naturalWidth>0?h():_();return}let t=r.value;if(t&&t.readyState>=HTMLMediaElement.HAVE_METADATA){h();return}m()}function _(n){if(!(n&&!p(n))){if(f(),!n&&a.value===0){a.value=1,i.value+=1,o.value=!0,(0,e.nextTick)(g);return}o.value=!1,s.value=!0,c.value=!1,t.onError(t.mediaIndex())}}function v(){c.value||d.value!==`error`||(a.value=0,s.value=!0,o.value=!0,c.value=!0,i.value+=1,(0,e.nextTick)(g))}function y(e){p(e)&&o.value&&m()}return(0,e.watch)(t.identity,()=>{f(),i.value+=1,a.value=0,o.value=u||t.previewState()===`loading`,s.value=!1,c.value=!1,u=!0,(0,e.nextTick)(g)},{immediate:!0}),(0,e.onBeforeUnmount)(f),{effectivePreviewState:d,failSourceAttempt:_,imageElement:n,markSourceReady:h,noteSourceActivity:y,retrySource:v,retrying:c,sourceGeneration:i,mediaElement:r}}var lt={lastAudibleVolume:1,muted:!1,volume:1};function ut(e,t){return typeof e==`number`&&Number.isFinite(e)?Math.min(1,Math.max(0,e)):t}function dt(e,t=lt){let n=ut(e?.volume,t.volume),r=ut(e?.lastAudibleVolume,n>0?n:t.lastAudibleVolume);return{lastAudibleVolume:r>0?r:lt.lastAudibleVolume,muted:typeof e?.muted==`boolean`?e.muted:n===0||t.muted,volume:n}}function ft(t){let n=dt(t.reelAudioState()),r=t.layout()===`reel`&&t.reelAudioState(),i=(0,e.shallowRef)(r?n.muted:t.mediaCard()?.videoMuted??t.layout()===`masonry`),a=(0,e.shallowRef)(r?n.volume:1),o=r?n.lastAudibleVolume:1;function s(){let e=t.mediaElement.value,n=t.reelAudioState();if(!e||t.layout()!==`reel`||!n)return;let r=dt(n);o=r.lastAudibleVolume,a.value=r.volume,i.value=r.muted,e.volume=r.volume,e.muted=t.active()===!1?!0:r.muted}function c(e,t){t&&(i.value=e.muted),a.value=e.volume,e.volume>0&&(o=e.volume)}function l(e){if(t.layout()!==`reel`)return;let n=dt({lastAudibleVolume:o,muted:e.muted,volume:e.volume});i.value=n.muted,a.value=n.volume,o=n.lastAudibleVolume,t.onChange(n)}function u(e){let n=t.mediaElement.value;if(!n||!Number.isFinite(e))return;let r=Math.min(1,Math.max(0,e));n.volume=r,n.muted=r===0,r>0&&(o=r),c(n,!0),l(n)}function d(){let e=t.mediaElement.value;e&&(e.muted&&e.volume===0&&(e.volume=o),e.muted=!e.muted,c(e,!0),l(e))}return(0,e.watch)([t.active,t.layout,()=>t.reelAudioState()?.lastAudibleVolume,()=>t.reelAudioState()?.muted,()=>t.reelAudioState()?.volume,t.mediaElement],s,{immediate:!0}),{apply:s,setVolume:u,sync:c,toggleMute:d,videoIsMuted:i,videoVolume:a}}function pt(t){let n=(0,e.computed)(()=>t.layout()===`reel`?t.active()===!0:t.inViewport()),r=(0,e.computed)(()=>n.value?t.mediaIsMuted.value:!0);function i(){if(!n.value){t.mediaElement.value?.pause(),t.mediaIsPlaying.value=!1;return}t.mediaIsPlaying.value=!0}return(0,e.watch)(n,r=>{let i=t.mediaElement.value;if(!r){i?.pause(),i&&(i.muted=!0),t.mediaIsPlaying.value=!1;return}(0,e.nextTick)().then(async()=>{let e=t.mediaElement.value;if(!(!e||!n.value)){e.muted=t.mediaIsMuted.value;try{await e.play()}catch{t.mediaIsPlaying.value=!1}}})}),{effectiveMuted:r,onPlaying:i,playbackAllowed:n}}function mt(e){return Number.isFinite(e)?Math.max(0,e):0}function ht(t){let n=(0,e.shallowRef)(0),r=(0,e.shallowRef)(0),i=(0,e.shallowRef)(!1),{apply:a,setVolume:o,sync:s,toggleMute:c,videoIsMuted:l,videoVolume:u}=ft({active:t.active,layout:t.layout,mediaCard:t.mediaCard,mediaElement:t.mediaElement,onChange:t.onAudioChange,reelAudioState:t.reelAudioState}),{effectiveMuted:d,onPlaying:f,playbackAllowed:p}=pt({active:t.active,inViewport:t.inViewport,layout:t.layout,mediaElement:t.mediaElement,mediaIsMuted:l,mediaIsPlaying:i});function m(e){let i=e?.currentTarget??t.mediaElement.value;i&&(n.value=mt(i.currentTime),r.value=mt(i.duration),s(i,p.value))}function h(e){a(),m(e),t.onReady(e)}function g(){i.value=!1,t.onEnded()}function _(e){let r=t.mediaElement.value;!r||!Number.isFinite(e)||(r.currentTime=Math.min(mt(r.duration),Math.max(0,e)),n.value=r.currentTime)}async function v(){let e=t.mediaElement.value;if(!(!e||!p.value)){if(i.value){e.pause();return}try{await e.play()}catch{i.value=!1}}}return(0,e.watch)(t.mediaElement,()=>{n.value=0,r.value=0,i.value=!1},{flush:`sync`}),{currentTime:n,duration:r,effectiveMuted:d,isMuted:l,isPlaying:i,onEnded:g,onLoadedMetadata:h,onPlaying:f,playbackAllowed:p,seek:_,setVolume:o,sync:m,toggleMute:c,togglePlayback:v,volume:u}}var gt=[`data-post-id`,`data-media-index`,`aria-hidden`,`aria-busy`,`inert`,`role`,`tabindex`],_t={class:`media-card-content`},vt=[`data-media-direction`],yt=[`data-media-index`],bt={key:0,"data-test":`media-loading`,class:`media-loading`,"aria-hidden":`true`},xt=[`data-source-generation`,`src`,`autoplay`,`loop`,`muted`,`preload`],St=[`aria-label`,`disabled`],Ct=[`src`,`width`,`height`,`fetchpriority`,`loading`],wt={key:1,class:`media-audio-fallback`,"aria-hidden":`true`},Tt=[`data-source-generation`,`src`,`width`,`height`,`autoplay`,`loop`,`muted`,`preload`],Et=[`data-source-generation`,`src`,`width`,`height`,`fetchpriority`,`loading`],Dt=[`aria-label`],Ot=[`aria-label`],kt=[`aria-label`],At=(0,e.defineComponent)({__name:`MediaCard`,props:{active:{type:Boolean},advanceOnMediaEnd:{type:Boolean},cardFooter:{},cardHeader:{},entering:{type:Boolean},fetchPriority:{},inViewport:{type:Boolean},index:{},item:{},itemStyle:{},interactive:{type:Boolean},leaving:{type:Boolean},layout:{},loadedCount:{},mediaIndex:{},mediaCard:{},mediaSource:{},previewState:{},reelControlsTarget:{},reelAudioState:{},stationaryReelControls:{type:Boolean},total:{}},emits:[`activate`,`ended`,`error`,`mediaChange`,`ready`,`reelAudioChange`],setup(t,{emit:n}){let r=t,i=n;function o(e=!1,t=`pointer`){e&&i(`activate`,t)}let s=(0,e.computed)(()=>d(r.item)),m=(0,e.computed)(()=>f(r.item,r.mediaIndex)),h=(0,e.computed)(()=>p(r.item,m.value)),g=(0,e.computed)(()=>c(h.value,r.mediaSource??`preview`)),_=(0,e.computed)(()=>a(h.value.type,h.value.src)),v=(0,e.computed)(()=>_.value===`audio`),y=(0,e.computed)(()=>u(h.value,r.mediaSource??`preview`)),b=(0,e.computed)(()=>v.value?y.value:g.value),x=(0,e.computed)(()=>b.value.src),S=(0,e.computed)(()=>a(b.value.type,b.value.src)),C=(0,e.computed)(()=>g.value.width),w=(0,e.computed)(()=>g.value.height),T=(0,e.computed)(()=>l(h.value)),E=(0,e.shallowRef)(!1),D=(0,e.computed)(()=>E.value?null:T.value),{effectivePreviewState:O,failSourceAttempt:k,imageElement:A,markSourceReady:j,noteSourceActivity:M,retrySource:N,retrying:P,sourceGeneration:F,mediaElement:I}=ct({identity:()=>`${r.item.postId}:${m.value}:${r.mediaSource??`preview`}:${x.value}:${S.value??``}`,mediaIndex:()=>m.value,onError:e=>i(`error`,e),onReady:e=>i(`ready`,e),previewState:()=>r.previewState});ot({inViewport:()=>r.inViewport===!0,item:()=>r.item,layout:()=>r.layout,mediaCard:()=>r.mediaCard,mediaIndex:()=>m.value,mediaReady:()=>O.value===`ready`,mediaSource:()=>r.mediaSource??`preview`});let{currentTime:L,duration:ee,effectiveMuted:R,isMuted:z,isPlaying:B,onEnded:V,onLoadedMetadata:H,onPlaying:U,playbackAllowed:W,seek:te,setVolume:ne,sync:G,toggleMute:re,togglePlayback:ie,volume:ae}=ht({active:()=>r.active,inViewport:()=>r.inViewport===!0,layout:()=>r.layout,mediaCard:()=>r.mediaCard,mediaElement:I,onAudioChange:e=>i(`reelAudioChange`,e),onEnded:()=>i(`ended`,m.value),onReady:j,reelAudioState:()=>r.reelAudioState}),K=(0,e.computed)(()=>r.interactive&&!!(r.cardHeader||r.cardFooter));function oe(e){return e.detail===0?`keyboard`:`pointer`}let{change:q,direction:J,onTouchEnd:se,onTouchStart:ce,onWheel:le}=Je({item:()=>r.item,layout:()=>r.layout,mediaIndex:()=>m.value,onChange:e=>i(`mediaChange`,e)}),{imageLoading:ue,mediaIsTimed:de,timedMediaPreload:fe}=st({active:()=>r.active,fetchPriority:()=>r.fetchPriority,layout:()=>r.layout,mediaSource:()=>x.value,mediaType:()=>S.value,mediaElement:I}),pe=(0,e.computed)(()=>r.layout===`reel`&&r.stationaryReelControls===!0),me=(0,e.computed)(()=>de.value&&(!v.value||r.layout===`reel`)&&O.value===`ready`&&(!pe.value||!!(r.active&&r.reelControlsTarget))),he=(0,e.computed)(()=>`${r.item.postId}:${m.value}:${x.value}`);function ge(e){r.layout===`reel`&&(e.stopPropagation(),ie())}function _e(){E.value=!0,r.layout===`masonry`&&j()}return(0,e.watch)(()=>T.value?.src,()=>{E.value=!1}),(0,e.watch)([v,()=>r.layout,D],([t,n,r])=>{t&&n===`masonry`&&!r&&(0,e.nextTick)(()=>j())},{immediate:!0}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`article`,{"data-post-id":t.item.postId,"data-media-index":m.value,class:(0,e.normalizeClass)([`media-card`,{"media-card--entering":t.entering,"media-card--leaving":t.leaving,"media-card--error":(0,e.unref)(O)===`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)(O)===`loading`||(0,e.unref)(P),inert:t.leaving||void 0,role:t.interactive&&!t.leaving&&!K.value?`button`:void 0,tabindex:t.interactive&&!t.leaving&&!K.value?0:void 0,onClick:r[34]||=e=>o(t.interactive&&!K.value,oe(e)),onKeydown:[r[35]||=(0,e.withKeys)(e=>o(t.interactive&&!K.value,`keyboard`),[`enter`]),r[36]||=(0,e.withKeys)((0,e.withModifiers)(e=>o(t.interactive&&!K.value,`keyboard`),[`prevent`]),[`space`])]},[(0,e.createElementVNode)(`div`,_t,[t.cardHeader?((0,e.openBlock)(),(0,e.createBlock)(ke,{key:0,index:t.index,item:t.item,layout:t.layout,"loaded-count":t.loadedCount,"media-index":m.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`&&s.value.length>1}]),"data-media-direction":(0,e.unref)(J),onWheel:r[31]||=(...t)=>(0,e.unref)(le)&&(0,e.unref)(le)(...t),onTouchstartPassive:r[32]||=(...t)=>(0,e.unref)(ce)&&(0,e.unref)(ce)(...t),onTouchendPassive:r[33]||=(...t)=>(0,e.unref)(se)&&(0,e.unref)(se)(...t)},[(0,e.createVNode)(e.Transition,{css:!(0,e.unref)(P),name:`media-slide-${(0,e.unref)(J)}`},{default:(0,e.withCtx)(()=>[((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{key:`${t.item.postId}:${h.value.src}:${t.mediaSource??`preview`}:${(0,e.unref)(F)}`,class:`media-card-frame`,"data-media-index":m.value},[(0,e.unref)(O)===`loading`?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,bt,[...r[37]||=[(0,e.createElementVNode)(`span`,{class:`media-loading-shimmer`},null,-1)]])):(0,e.unref)(O)===`error`?((0,e.openBlock)(),(0,e.createBlock)(Ne,{key:1,component:t.mediaCard?.error?.component,label:(0,e.unref)(Oe)(x.value),retrying:(0,e.unref)(P),status:(0,e.unref)(De)(x.value),onRetry:(0,e.unref)(N)},null,8,[`component`,`label`,`retrying`,`status`,`onRetry`])):(0,e.createCommentVNode)(``,!0),v.value&&t.layout===`reel`?((0,e.openBlock)(),(0,e.createElementBlock)(`audio`,{key:2,ref_key:`mediaElement`,ref:I,"data-source-generation":(0,e.unref)(F),class:`media-audio-element`,src:x.value,autoplay:(0,e.unref)(W),loop:!t.advanceOnMediaEnd,muted:(0,e.unref)(R),preload:(0,e.unref)(fe),onLoadedmetadata:r[0]||=(...t)=>(0,e.unref)(H)&&(0,e.unref)(H)(...t),onProgress:r[1]||=(...t)=>(0,e.unref)(M)&&(0,e.unref)(M)(...t),onLoadeddata:r[2]||=(...t)=>(0,e.unref)(M)&&(0,e.unref)(M)(...t),onCanplay:r[3]||=(...t)=>(0,e.unref)(M)&&(0,e.unref)(M)(...t),onDurationchange:r[4]||=(...t)=>(0,e.unref)(G)&&(0,e.unref)(G)(...t),onTimeupdate:r[5]||=(...t)=>(0,e.unref)(G)&&(0,e.unref)(G)(...t),onVolumechange:r[6]||=(...t)=>(0,e.unref)(G)&&(0,e.unref)(G)(...t),onPlaying:r[7]||=(...t)=>(0,e.unref)(U)&&(0,e.unref)(U)(...t),onPause:r[8]||=e=>B.value=!1,onEnded:r[9]||=(...t)=>(0,e.unref)(V)&&(0,e.unref)(V)(...t),onError:r[10]||=(...t)=>(0,e.unref)(k)&&(0,e.unref)(k)(...t)},null,40,xt)):(0,e.createCommentVNode)(``,!0),v.value?((0,e.openBlock)(),(0,e.createElementBlock)(`button`,{key:3,type:`button`,class:(0,e.normalizeClass)([`media-audio-artwork media-preview`,{"media-preview--ready":(0,e.unref)(O)===`ready`}]),"aria-label":t.layout===`reel`?(0,e.unref)(B)?`Pause audio`:`Play audio`:`Audio`,disabled:t.layout!==`reel`,onClick:ge},[D.value?((0,e.openBlock)(),(0,e.createElementBlock)(`img`,{key:0,class:`media-audio-cover`,src:D.value.src,width:D.value.width??void 0,height:D.value.height??void 0,fetchpriority:t.fetchPriority,alt:``,decoding:`async`,loading:(0,e.unref)(ue),onLoad:r[11]||=n=>t.layout===`masonry`&&(0,e.unref)(j)(n),onError:_e},null,40,Ct)):((0,e.openBlock)(),(0,e.createElementBlock)(`span`,wt,[(0,e.createVNode)((0,e.unref)(xe),{size:64,"stroke-width":1.5})]))],10,St)):(0,e.unref)(de)?((0,e.openBlock)(),(0,e.createElementBlock)(`video`,{key:4,ref_key:`mediaElement`,ref:I,"data-source-generation":(0,e.unref)(F),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(O)===`ready`,"media-preview--reel-video":t.layout===`reel`}]),src:x.value,width:C.value??void 0,height:w.value??void 0,autoplay:(0,e.unref)(W),loop:!t.advanceOnMediaEnd,muted:(0,e.unref)(R),playsinline:``,preload:(0,e.unref)(fe),onLoadedmetadata:r[12]||=(...t)=>(0,e.unref)(H)&&(0,e.unref)(H)(...t),onProgress:r[13]||=(...t)=>(0,e.unref)(M)&&(0,e.unref)(M)(...t),onLoadeddata:r[14]||=(...t)=>(0,e.unref)(M)&&(0,e.unref)(M)(...t),onCanplay:r[15]||=(...t)=>(0,e.unref)(M)&&(0,e.unref)(M)(...t),onDurationchange:r[16]||=(...t)=>(0,e.unref)(G)&&(0,e.unref)(G)(...t),onTimeupdate:r[17]||=(...t)=>(0,e.unref)(G)&&(0,e.unref)(G)(...t),onVolumechange:r[18]||=(...t)=>(0,e.unref)(G)&&(0,e.unref)(G)(...t),onPlaying:r[19]||=(...t)=>(0,e.unref)(U)&&(0,e.unref)(U)(...t),onPause:r[20]||=e=>B.value=!1,onEnded:r[21]||=(...t)=>(0,e.unref)(V)&&(0,e.unref)(V)(...t),onClick:ge,onError:r[22]||=(...t)=>(0,e.unref)(k)&&(0,e.unref)(k)(...t)},null,42,Tt)):v.value?(0,e.createCommentVNode)(``,!0):((0,e.openBlock)(),(0,e.createElementBlock)(`img`,{key:5,ref_key:`imageElement`,ref:A,"data-source-generation":(0,e.unref)(F),class:(0,e.normalizeClass)([`media-preview`,{"media-preview--ready":(0,e.unref)(O)===`ready`}]),src:x.value,width:C.value??void 0,height:w.value??void 0,fetchpriority:t.fetchPriority,alt:``,decoding:`async`,loading:(0,e.unref)(ue),onLoad:r[23]||=(...t)=>(0,e.unref)(j)&&(0,e.unref)(j)(...t),onError:r[24]||=(...t)=>(0,e.unref)(k)&&(0,e.unref)(k)(...t)},null,42,Et))],8,yt))]),_:1},8,[`css`,`name`]),(0,e.createVNode)(We,{item:t.item,"media-card":t.mediaCard,"media-index":m.value,"media-item":h.value,"media-source":t.mediaSource??`preview`},null,8,[`item`,`media-card`,`media-index`,`media-item`,`media-source`]),((0,e.openBlock)(),(0,e.createBlock)(e.Teleport,{disabled:!pe.value||!t.reelControlsTarget,to:t.reelControlsTarget??`body`},[(0,e.createVNode)(e.Transition,{name:`vibe-reel-media-controls`,css:pe.value},{default:(0,e.withCtx)(()=>[me.value?((0,e.openBlock)(),(0,e.createBlock)(He,{key:he.value,"current-time":(0,e.unref)(L),"data-control-post-id":pe.value?t.item.postId:void 0,duration:(0,e.unref)(ee),layout:t.layout,"media-type":v.value?`audio`:`video`,muted:(0,e.unref)(z),playing:(0,e.unref)(B),volume:(0,e.unref)(ae),onSeek:(0,e.unref)(te),onToggleMute:(0,e.unref)(re),onTogglePlayback:(0,e.unref)(ie),onVolumeChange:(0,e.unref)(ne)},null,8,[`current-time`,`data-control-post-id`,`duration`,`layout`,`media-type`,`muted`,`playing`,`volume`,`onSeek`,`onToggleMute`,`onTogglePlayback`,`onVolumeChange`])):(0,e.createCommentVNode)(``,!0)]),_:1},8,[`css`])],8,[`disabled`,`to`])),s.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[25]||=(0,e.withModifiers)(t=>(0,e.unref)(q)(m.value-1,t),[`stop`]),onKeydown:r[26]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(ye),{size:20})],40,Dt),(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[27]||=(0,e.withModifiers)(t=>(0,e.unref)(q)(m.value+1,t),[`stop`]),onKeydown:r[28]||=(0,e.withModifiers)(()=>{},[`stop`])},[(0,e.createVNode)((0,e.unref)(be),{size:20})],40,Ot)],2)):(0,e.createCommentVNode)(``,!0),K.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[29]||=(0,e.withModifiers)(e=>n.$emit(`activate`,oe(e)),[`stop`]),onKeydown:r[30]||=(0,e.withModifiers)(()=>{},[`stop`])},null,40,kt)):(0,e.createCommentVNode)(``,!0)],42,vt),t.cardFooter?((0,e.openBlock)(),(0,e.createBlock)(ke,{key:1,index:t.index,item:t.item,layout:t.layout,"loaded-count":t.loadedCount,"media-index":m.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,gt))}});function jt(t){function n(e){return e.flatMap(e=>{let n=t.items()[e];if(!n)return[];let r=t.mediaIndices().get(n.postId)??0,i=m(n.postId,r);return t.previewStates().get(i)===`ready`?[{key:i,mediaIndex:r,postId:n.postId}]:[]})}function r(t,r){let i=new Set;(0,e.watch)(()=>n(t()),e=>{let t=new Set(e.map(({key:e})=>e));e.forEach(({key:e,mediaIndex:t,postId:n})=>{i.has(e)||r(n,t)}),i=t},{immediate:!0,flush:`post`})}r(t.visibleIndices,t.onVisible),r(t.fullyVisibleIndices,t.onFullyVisible)}var Mt=1500;function Nt(t){let n=(0,e.shallowRef)(0),r=0,i=null,a=0,o=0,s=null,c=0,l=null,u=null,d=0;function f(){s!==null&&(cancelAnimationFrame(s),s=null)}function p(e,t,n,r){return i=e,l=t.slice(),u=W(e.items,u??U(r.items),n),c=e.items.length<t.length?Math.max(c,r.height,e.height):0,e.items.length<t.length&&e.items.length>n&&m(),e}function m(){s===null&&(s=requestAnimationFrame(()=>{s=null;let e=t.items(),r=i;if(!r||r.items.length>=e.length)return;let a=r.items.length;p(z(e,t.width.value,{additionalHeight:t.additionalHeight.value,gap:t.gap.value,minColumnWidth:t.minColumnWidth.value},r,a,{throughIndex:t.packThroughIndex(),untilIndex:a+Mt}),e,a,r),n.value+=1}))}let h=(0,e.computed)(()=>{n.value;let e=t.items(),s=t.width.value,h={additionalHeight:t.additionalHeight.value,gap:t.gap.value,minColumnWidth:t.minColumnWidth.value},g=i;if(g&&l&&d===s&&a===h.gap&&r===h.additionalHeight&&o===h.minColumnWidth){let n=0,r=l,i=Math.min(r.length,e.length);for(;n<i&&r[n]===e[n];)n+=1;return n===e.length&&n===r.length?(g.items.length>0&&g.items.length<e.length&&m(),g):(f(),p(z(e,s,h,g,n,{throughIndex:t.packThroughIndex(),untilBottom:t.packUntilBottom()}),e,n,g))}f();let _=R(e,s,h);return i=_,l=e.slice(),d=s,a=h.gap,r=h.additionalHeight,o=h.minColumnWidth,u=U(_.items),c=0,_}),g=(0,e.computed)(()=>(h.value,u??U(h.value.items)));return(0,e.onBeforeUnmount)(f),{ensurePackedThrough(e){let r=t.items(),a=i;if(!a||a.items.length>=r.length||a.height>=e)return;f();let o=a.items.length;p(z(r,t.width.value,{additionalHeight:t.additionalHeight.value,gap:t.gap.value,minColumnWidth:t.minColumnWidth.value},a,o,{throughIndex:t.packThroughIndex(),untilBottom:e}),r,o,a),n.value+=1},layout:h,reservedHeight:()=>c,viewportIndex:g}}var Pt={class:`masonry-feed-shell`},Ft=[`aria-hidden`,`inert`],It={key:0,class:`masonry-feed-status-overlay`},Lt=6,Rt=12,zt=250,Bt=(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:{},reelAudioState:{},state:{},total:{}},emits:[`activate`,`error`,`fullyVisible`,`loadMore`,`mediaChange`,`ready`,`retryEnd`,`visible`],setup(t,{expose:n,emit:r}){let i=0,a=t,o=r,s=(0,e.shallowRef)(null),c=`vibe-masonry-${(0,e.useId)()}`,l=(0,e.shallowRef)(null),u=(0,e.shallowRef)(0),d=(0,e.shallowRef)(Lt),f=(0,e.shallowRef)(0),p=(0,e.shallowRef)(0),h=(0,e.shallowRef)(0),g=(0,e.shallowRef)([]),_=(0,e.shallowRef)([]),v=(0,e.shallowRef)([]),y=0,b=null,x=null,S=null,C=null,T=(0,e.computed)(()=>({additionalHeight:(a.cardHeader?.height??0)+(a.cardFooter?.height??0),gap:d.value,minColumnWidth:re(a.masonry)})),E=[];function D(){let e=y-h.value+f.value+ie(a.masonry,f.value),t=v.value.reduce((e,t)=>{let n=E[t];return n?Math.max(e,n.y+n.height):e},0);return Math.max(e,t)}function k(){return v.value.reduce((e,t)=>Math.max(e,t),-1)}let A=Nt({additionalHeight:(0,e.computed)(()=>T.value.additionalHeight),gap:d,items:()=>a.items,minColumnWidth:(0,e.computed)(()=>T.value.minColumnWidth),packThroughIndex:k,packUntilBottom:D,width:u}),M=A.layout,N=A.viewportIndex,F=(0,e.computed)(()=>a.leavingPostIds.size===0?null:B(a.items,u.value,T.value,M.value,e=>a.leavingPostIds.has(a.items[e].postId),{throughIndex:k(),untilBottom:D()})),I=(0,e.computed)(()=>{let e=F.value;return e?{columns:e.columns,height:e.height,items:e.items}:M.value}),L=(0,e.computed)(()=>{let e=F.value;return e?te(e.items,e.retainedIndices,N.value,e.fromIndex):null}),ee=(0,e.computed)(()=>(M.value,Math.max(p.value,A.reservedHeight(),a.leavingPostIds.size===0?I.value.height:M.value.height))),R=(0,e.computed)(()=>({height:`${ee.value}px`})),z=(0,e.computed)(()=>!a.infiniteScroll||f.value>0&&h.value+I.value.height<=f.value+1),V=(0,e.computed)(()=>new Set(_.value)),H=(0,e.computed)(()=>v.value.flatMap(e=>{let t=a.items[e],n=I.value.items[e];return!t||!n||n.width<=0||n.height<=0?[]:[{fetchPriority:V.value.has(e)?`high`:`low`,index:e,item:t}]}));function U(e,t){return[...new Set([...e,...t])].sort((e,t)=>e-t)}function W(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function ne(e){let t={scrollTop:y-h.value,viewportHeight:f.value},n=L.value,r=G(n??N.value,{...t,overscan:e}).indices;return U(r,a.leavingPostIds.size===0?[]:G(N.value,{...t,overscan:e}).indices.filter(e=>{let t=a.items[e];return t!==void 0&&a.leavingPostIds.has(t.postId)}))}function ae(){let e=ne(0),t=ne(ie(a.masonry,f.value));W(_.value,e)||(_.value=e);let n=P(I.value.items,e.filter(e=>{let t=a.items[e];return t&&!a.leavingPostIds.has(t.postId)}),{scrollTop:y-h.value,viewportHeight:f.value});W(g.value,n)||(g.value=n),W(v.value,t)||(v.value=t)}function K(){if(C!==null)return;C=-1;let e=requestAnimationFrame(()=>{C=null,ae()});C!==null&&(C=e)}jt({fullyVisibleIndices:()=>g.value,items:()=>a.items,mediaIndices:()=>a.mediaIndices,onFullyVisible:(e,t)=>o(`fullyVisible`,e,t),onVisible:(e,t)=>o(`visible`,e,t),previewStates:()=>a.previewStates,visibleIndices:()=>_.value});function oe(e){let t=I.value.items[e],n=a.items[e]?.postId;if(!t||t.width<=0||t.height<=0)return{};let r=n!==void 0&&a.enteringPostIds.has(n),i=n!==void 0&&a.leavingPostIds.has(n),o=r||i?j({containerHeight:Math.max(p.value,M.value.height),gap:d.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 q(){let e=s.value;if(!e)return;y=e.scrollTop,f.value=e.clientHeight;let t=e.ownerDocument.defaultView?.getComputedStyle(e),n=(Number.parseFloat(t?.paddingTop??``)||0)+(Number.parseFloat(t?.paddingBottom??``)||0);p.value=Math.max(0,e.clientHeight-n);let r=l.value;r&&(h.value=r.getBoundingClientRect().top-e.getBoundingClientRect().top+e.scrollTop,ae())}function J(e){let t=e.ownerDocument.documentElement.clientWidth;u.value=e.clientWidth,d.value=Math.min(Rt,Math.max(Lt,t*.0075)),q()}function se(e){let t=e.currentTarget;t&&(y=t.scrollTop,A.ensurePackedThrough(D()),K(),Date.now()>=i&&!a.loadMoreLocked&&a.infiniteScroll&&O(t)&&o(`loadMore`))}function ce(){let e=s.value;Date.now()>=i&&!a.loadMoreLocked&&e&&O(e)&&o(`loadMore`)}(0,e.watch)(()=>a.items.length,(e,t)=>{e>0&&e<t&&(i=Date.now()+zt)});function le(){return s.value}return(0,e.watch)(l,e=>{b?.disconnect(),b=null,S!==null&&cancelAnimationFrame(S),e&&(J(e),!(typeof ResizeObserver>`u`)&&(b=new ResizeObserver(([t])=>{let n=t?.contentRect.width??e.clientWidth;Math.abs(n-u.value)<.5||(S=requestAnimationFrame(()=>{S=null,J(e)}))}),b.observe(e)))}),(0,e.watch)(s,e=>{x?.disconnect(),x=null,e&&(q(),!(typeof ResizeObserver>`u`)&&(x=new ResizeObserver(q),x.observe(e)))}),(0,e.watch)(I,e=>{E=e.items},{flush:`sync`}),(0,e.watch)([M,I,()=>a.masonry],ae,{flush:`post`}),(0,e.onBeforeUnmount)(()=>{b?.disconnect(),x?.disconnect(),S!==null&&cancelAnimationFrame(S),C!==null&&cancelAnimationFrame(C)}),n({getScrollElement:le,loadIfNearBottom:ce}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,Pt,[(0,e.createElementVNode)(`main`,{id:c,ref_key:`galleryElement`,ref:s,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:se},[(0,e.createElementVNode)(`section`,{ref_key:`masonryElement`,ref:l,class:(0,e.normalizeClass)([`masonry`,{"masonry--ready":u.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)(H.value,({fetchPriority:n,item:r,index:i})=>((0,e.openBlock)(),(0,e.createBlock)(At,{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,"in-viewport":V.value.has(i),index:i,item:r,"item-style":oe(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)(m)(r.postId,t.mediaIndices.get(r.postId)??0))??`loading`,total:t.total,onActivate:e=>o(`activate`,r.postId,e),onMediaChange:e=>o(`mediaChange`,r.postId,e),onReady:e=>o(`ready`,r.postId,e),onError:e=>o(`error`,r.postId,e)},null,8,[`entering`,`leaving`,`fetch-priority`,`card-footer`,`card-header`,`media-card`,`in-viewport`,`index`,`item`,`item-style`,`loaded-count`,`media-index`,`preview-state`,`total`,`onActivate`,`onMediaChange`,`onReady`,`onError`]))),128))],6)],42,Ft),t.feedFooter||t.isLoadingMore||t.nextPageError||t.hasNext&&z.value||!t.hasNext&&t.canRetryEnd?((0,e.openBlock)(),(0,e.createElementBlock)(`div`,It,[(0,e.createVNode)(w,{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=>o(`loadMore`),onRetryEnd:r[1]||=e=>o(`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)(ue,{"content-size":I.value.height,"controls-id":c,"scroll-element":s.value,suspended:t.suspended},null,8,[`content-size`,`scroll-element`,`suspended`])]))}}),Vt=300;function Ht(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/Vt),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 Ut=[`aria-label`],Wt=(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,Ut))}}),Gt={class:`reel-viewport`},Kt=[`data-active-post-id`,`data-active-media-index`],qt=[`role`,`data-status`],Jt=[`disabled`],Yt=300,Xt=250,Zt=(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:{},reelAudioState:{},state:{},total:{}},emits:[`activeChange`,`error`,`loadMore`,`mediaChange`,`ready`,`reelAudioChange`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:r}){let i=0,a=t,s=r,c=(0,e.shallowRef)(null),l=(0,e.shallowRef)(null),f=a.initialPostId===null||a.initialPostId===void 0?-1:a.items.findIndex(e=>e.postId===a.initialPostId),h=(0,e.shallowRef)(Math.max(0,f)),g=(0,e.shallowRef)(!1),_=(0,e.shallowRef)(!1),v=0,y=null,b=null,x=null,S=(0,e.computed)(()=>({gridTemplateRows:`repeat(${a.items.length}, 100cqh)`})),C=(0,e.computed)(()=>{let e=Math.max(0,h.value-2),t=Math.min(a.items.length-1,h.value+2);return a.items.slice(e,t+1).map((t,n)=>({fetchPriority:e+n===h.value?`high`:`low`,index:e+n,item:t}))}),T=(0,e.computed)(()=>a.items[h.value]?.postId),E=(0,e.computed)(()=>a.items[h.value]),D=(0,e.computed)(()=>{let e=T.value;return e===void 0?0:a.mediaIndices.get(e)??0}),k=(0,e.computed)(()=>{let e=T.value;return e===void 0?`loading`:a.previewStates.get(m(e,D.value))??`loading`}),A=(0,e.computed)(()=>E.value?p(E.value,D.value):null),j=(0,e.computed)(()=>A.value?u(A.value,a.mediaSource??`preview`):null),M=(0,e.computed)(()=>k.value===`ready`&&!!(j.value&&o(j.value.type,j.value.src))),N=(0,e.computed)(()=>[T.value,D.value,a.items.length,a.loadMoreLocked,a.reelAutoAdvance.enabled,a.reelAutoAdvance.includePostItems,a.reelAutoAdvance.intervalMs].join(`:`)),P=(0,e.computed)(()=>{let e=E.value,t=!!(e&&a.reelAutoAdvance.includePostItems&&D.value<d(e).length-1),n=a.reelAutoAdvance.intervalMs/1e3;return`Auto advance to the next ${t?`post item`:`post`} in ${n}s`}),F=(0,e.computed)(()=>a.reelAutoAdvance.enabled&&a.reelForward.status===`idle`&&E.value!==void 0&&k.value!==`loading`&&!M.value),I=(0,e.computed)(()=>!a.infiniteScroll||a.items.length<=1),L=(0,e.computed)(()=>a.reelForward.status===`end`&&a.hasNext&&!a.infiniteScroll&&!a.loadMoreLocked),ee=(0,e.computed)(()=>a.reelForward.status===`loading`?`Loading the next media…`:a.reelForward.status===`error`?`Unable to load the next media.`:L.value?`Load the next page to continue.`:`You reached the end of this feed.`);function R(e){return{gridRow:`${e+1}`}}function z(e){let t=v||e.clientHeight;return t<=0||a.items.length===0?0:Math.min(a.items.length-1,Math.max(0,Math.round(e.scrollTop/t)))}function B(e){let t=e.currentTarget;if(!t)return;let n=v||t.clientHeight,r=Math.max(0,a.items.length-1)*n;g.value=a.items.length>0&&t.scrollTop>r+1,_.value||(h.value=z(t)),Date.now()>=i&&!a.loadMoreLocked&&a.infiniteScroll&&O(t)&&s(`loadMore`)}function V(){let e=c.value;e&&(g.value=!1,W(!0),v=e.clientHeight,e.scrollTop=h.value*v,b!==null&&cancelAnimationFrame(b),b=requestAnimationFrame(()=>{e.scrollTop=h.value*e.clientHeight,v=e.clientHeight,b=null}),H())}function H(){x!==null&&clearTimeout(x),x=setTimeout(()=>{x=null;let e=c.value;e&&(v=e.clientHeight,e.scrollTop=h.value*v),W(!1)},120)}function U(){W(!0);let e=c.value;e&&(v=e.clientHeight,e.scrollTop=h.value*v),H()}function W(e){_.value=e,c.value?.toggleAttribute(`data-resizing`,e)}function te(){let e=c.value;Date.now()>=i&&!a.loadMoreLocked&&e&&O(e)&&s(`loadMore`)}(0,e.watch)(()=>a.items.length,(e,t)=>{e>0&&e<t&&(i=Date.now()+Xt)});function ne(e){let t=E.value;if(!t)return!1;let n=d(t).length;if(n<=1)return!1;let r=(D.value+e+n)%n;return s(`mediaChange`,t.postId,r),!0}function G(e){let t=h.value+e;return!c.value||t<0||t>=a.items.length?!1:(K(t),!0)}function re(e,t){let n=a.items.findIndex(t=>t.postId===e),r=a.items[n];return!c.value||!r||t<0||t>r.items.length?!1:((a.mediaIndices.get(e)??0)!==t&&s(`mediaChange`,e,t),n!==h.value&&K(n),!0)}function ie(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function ae(e){let t=c.value;if(!t)return Promise.resolve();let n=e*(v||t.clientHeight);return h.value=e,Ht(t,n,ie())}function K(e){ae(e)}async function oe(e){let t=a.items.findIndex(t=>t.postId===e);return t<0||t===h.value?!1:(await ae(t),!0)}async function q(e){return ne(e)?(ie()||await new Promise(e=>setTimeout(e,Yt)),!0):!1}function J(){if(!a.reelAutoAdvance.enabled)return;let e=E.value;if(!e)return;if(a.reelAutoAdvance.includePostItems&&D.value<d(e).length-1){s(`mediaChange`,e.postId,D.value+1);return}let t=h.value+1,n=a.items[t];if(!n){a.hasNext&&a.infiniteScroll&&!a.loadMoreLocked&&s(`loadMore`);return}a.reelAutoAdvance.includePostItems&&(a.mediaIndices.get(n.postId)??0)!==0&&s(`mediaChange`,n.postId,0),K(t)}function se(e,t){!a.reelAutoAdvance.enabled||e!==T.value||t!==D.value||!M.value||J()}return(0,e.watch)(c,e=>{y?.disconnect(),y=null,e&&(v=e.clientHeight,!(typeof ResizeObserver>`u`)&&(y=new ResizeObserver(V),y.observe(e)))}),(0,e.watch)(()=>a.items.length,async t=>{let n=a.initialPostId,r=n==null?-1:a.items.findIndex(({postId:e})=>e===n);h.value=r>=0?r:Math.min(h.value,Math.max(0,t-1)),await(0,e.nextTick)(),V()}),(0,e.watch)(T,e=>{e!==void 0&&s(`activeChange`,e)},{immediate:!0}),(0,e.onMounted)(()=>{window.addEventListener(`resize`,U),window.addEventListener(`orientationchange`,U),f>=0&&(0,e.nextTick)(V)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`resize`,U),window.removeEventListener(`orientationchange`,U),y?.disconnect(),b!==null&&cancelAnimationFrame(b),x!==null&&clearTimeout(x)}),n({activeIndex:h,activePostId:T,changeActiveMedia:ne,loadIfNearBottom:te,moveActivePost:G,navigateToItem:re,transitionActiveMedia:q,transitionActivePost:oe}),(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)(ke,{key:0,index:h.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`,Gt,[(0,e.createElementVNode)(`div`,{ref_key:`galleryElement`,ref:c,class:`gallery-shell reel-feed`,"data-active-post-id":T.value,"data-active-media-index":D.value,onScrollPassive:B},[t.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:n,item:i,index:o})=>((0,e.openBlock)(),(0,e.createBlock)(At,{key:i.postId,active:o===h.value&&!g.value,"advance-on-media-end":a.reelAutoAdvance.enabled&&o===h.value,class:`reel-item`,entering:!1,"fetch-priority":n,index:o,item:i,"item-style":R(o),"media-card":t.mediaCard,layout:`reel`,"loaded-count":t.items.length,"media-index":t.mediaIndices.get(i.postId)??0,"media-source":t.mediaSource,"preview-state":t.previewStates.get((0,e.unref)(m)(i.postId,t.mediaIndices.get(i.postId)??0))??`loading`,"reel-controls-target":l.value,"reel-audio-state":t.reelAudioState,"stationary-reel-controls":``,total:t.total,onMediaChange:e=>s(`mediaChange`,i.postId,e),onEnded:e=>se(i.postId,e),onReady:e=>s(`ready`,i.postId,e),onReelAudioChange:r[1]||=e=>s(`reelAudioChange`,e),onError:e=>s(`error`,i.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`,`reel-audio-state`,`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)(ee.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`,disabled:t.loadMoreLocked,onClick:r[0]||=e=>s(`retryForward`)},(0,e.toDisplayString)(L.value?`Load more`:`Retry`),9,Jt)):(0,e.createCommentVNode)(``,!0)],8,qt)),t.reelForward.status===`idle`?((0,e.openBlock)(),(0,e.createBlock)(w,{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":I.value,state:t.state,onLoadMore:r[2]||=e=>s(`loadMore`),onRetryEnd:r[3]||=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)],40,Kt),(0,e.createElementVNode)(`div`,{ref_key:`reelControlsElement`,ref:l,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)(ke,{key:1,index:h.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),F.value?((0,e.openBlock)(),(0,e.createBlock)(Wt,{key:N.value,"duration-ms":t.reelAutoAdvance.intervalMs,label:P.value,onComplete:J},null,8,[`duration-ms`,`label`])):(0,e.createCommentVNode)(``,!0)],2))}}),Qt=[`data-info-sheet-open`,`data-info-sheet-mode`],$t=[`aria-hidden`,`inert`],en={key:0,class:`reel-info-sheet-layer`,"data-test":`reel-info-sheet`},tn=[`role`,`aria-modal`,`tabindex`,`data-active-post-id`],nn=(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:{},reelAudioState:{},state:{},total:{}},emits:[`activeChange`,`closeInfoSheet`,`error`,`loadMore`,`mediaChange`,`ready`,`reelAudioChange`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:r}){let i=t,a=r,o=(0,e.shallowRef)(null),s=(0,e.shallowRef)(null),c=null,l=(0,e.computed)(()=>{let e=i.initialPostId===null||i.initialPostId===void 0?-1:i.items.findIndex(e=>e.postId===i.initialPostId);return Math.max(0,e)}),u=(0,e.computed)(()=>i.items[l.value]),f=(0,e.computed)(()=>u.value??(i.reelForward.status===`idle`?void 0:i.forwardItem??void 0)),m=(0,e.computed)(()=>u.value?l.value:i.forwardIndex??0),h=(0,e.computed)(()=>{let e=f.value?.postId;return e===void 0?0:i.mediaIndices.get(e)??0}),g=(0,e.computed)(()=>!!(i.infoSheet&&i.infoSheetEnabled&&f.value)),_=(0,e.computed)(()=>{let e=f.value;return e?{close:v,index:m.value,item:e,layout:`reel`,loadedCount:i.items.length,mediaCount:d(e).length,mediaIndex:h.value,mediaItem:p(e,h.value),mediaSource:i.mediaSource??`preview`,origin:i.origin,total:i.total}:null});function v(){a(`closeInfoSheet`)}function y(e){return o.value?.changeActiveMedia(e)??!1}function b(){o.value?.loadIfNearBottom()}function x(e){return o.value?.moveActivePost(e)??!1}function S(e,t){return o.value?.navigateToItem(e,t)??!1}function C(e){return o.value?.transitionActiveMedia(e)??Promise.resolve(!1)}function w(e){return o.value?.transitionActivePost(e)??Promise.resolve(!1)}function T(e,t){a(`error`,e,t)}function E(e,t){a(`mediaChange`,e,t)}function D(e,t){a(`ready`,e,t)}return(0,e.watch)(()=>({overlay:i.infoSheetOverlay,visible:g.value}),async(t,n)=>{if(t.visible&&!n?.visible){c=document.activeElement instanceof HTMLElement?document.activeElement:null,t.overlay&&(await(0,e.nextTick)(),s.value?.focus({preventScroll:!0}));return}if(!t.visible&&n?.visible&&c?.isConnected){let t=c;c=null,await(0,e.nextTick)(),t.focus({preventScroll:!0})}}),(0,e.onBeforeUnmount)(()=>{c=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)(Zt,{ref_key:`reelFeed`,ref:o,"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-audio-state":t.reelAudioState,"reel-forward":t.reelForward,state:t.state,total:t.total,onActiveChange:r[0]||=e=>a(`activeChange`,e),onError:T,onLoadMore:r[1]||=e=>a(`loadMore`),onMediaChange:E,onReady:D,onRetryEnd:r[2]||=e=>a(`retryEnd`),onRetryForward:r[3]||=e=>a(`retryForward`),onReelAudioChange:r[4]||=e=>a(`reelAudioChange`,e)},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-audio-state`,`reel-forward`,`state`,`total`])],8,$t),(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`,en,[(0,e.createElementVNode)(`aside`,{ref_key:`sheetElement`,ref:s,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":f.value?.postId},[((0,e.openBlock)(),(0,e.createBlock)((0,e.resolveDynamicComponent)(t.infoSheet.component),(0,e.normalizeProps)((0,e.guardReactiveProps)(_.value)),null,16))],8,tn)])):(0,e.createCommentVNode)(``,!0)]),_:1})],10,Qt))}});function rn(e,t,n,r,i){let a=e.items.findIndex(e=>e.postId===t),o=e.items[a];if(!o)return null;let s=f(o,n),c=p(o,s);return{item:o,layout:r,media:c,mediaId:c.mediaId??null,mediaIndex:s,origin:i,phoneMode:e.phoneMode,postId:o.postId,postIndex:a}}function an(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=rn(t,e.postId,e.mediaIndex,`reel`,e.origin);i&&n(i)},{flush:`sync`})}function on(t,n){let r=new Set,i=(0,e.shallowRef)(new Map),a=(0,e.shallowRef)(new Map),o=(0,e.shallowRef)(new Map),s=()=>t.reelMediaSource===`preview`?i:t.reelMediaSource===`mobile`?o:a,c=(0,e.computed)(()=>s().value),l=new Set;function u(){r.clear(),l.clear(),i.value=new Map,a.value=new Map,o.value=new Map}function d(e,t,n,r){let i=m(t,n);e.value.get(i)!==r&&(e.value=new Map(e.value).set(i,r))}function f(e,n,r,i){return rn(t,e,n,r,i)}function p(e,t,r,i){let a=f(e,t,r,i);a&&n.ready(a)}function h(e,t){d(i,e,t,`error`)}function g(e,t){d(i,e,t,`ready`),p(e,t,`masonry`,null)}function _(e,t){d(s(),e,t,`error`)}function v(e,n){d(s(),e,n,`ready`),p(e,n,`reel`,t.reelOrigin??`reel`)}function y(e,t){let r=m(e,t);if(l.has(r))return;let i=f(e,t,`masonry`,null);i&&(l.add(r),n.visible(i))}function b(e,t,i,a){let o=[i,m(e,t)].join(`:`);if(r.has(o))return;let s=f(e,t,i,a);s&&(r.add(o),n.fullyVisible(s))}function x(e,t){b(e,t,`masonry`,null)}return an(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(m(e,n))===`ready`}},(e,t)=>{e.postId===null||!e.ready||t?.ready&&t.postId===e.postId&&t.mediaIndex===e.mediaIndex&&t.origin===e.origin||b(e.postId,e.mediaIndex,`reel`,e.origin)},{flush:`post`}),{markMasonryFullyVisible:x,markMasonryVisible:y,markPreviewError:h,markPreviewReady:g,markReelError:_,markReelReady:v,originalStates:a,previewStates:i,reelStates:c,resetMediaLifecycle:u}}var sn=[];function cn(e){return sn.push(e),()=>{let t=sn.indexOf(e);t>=0&&sn.splice(t,1)}}function ln(e){if(!e.isActive())return!1;let t=sn.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 un(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&&!ln(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=cn(n),window.addEventListener(`keydown`,i)}),(0,e.onBeforeUnmount)(()=>{window.removeEventListener(`keydown`,i),r?.(),r=null})}var dn=35,fn=420,pn=(0,e.defineComponent)({__name:`VibeSurface`,props:{canRetryEnd:{type:Boolean},cardFooter:{},cardHeader:{},feedFooter:{},feedFooterActions:{},mediaCard:{},masonry:{},reelInfoSheet:{},reelAudioState:{},state:{}},emits:[`activeReelChange`,`closeReel`,`loadMore`,`mediaFullyVisible`,`mediaReady`,`mediaVisible`,`openReel`,`reelMediaChange`,`reelInfoSheetChange`,`reelAudioChange`,`retryEnd`,`retryForward`],setup(t,{expose:n,emit:r}){let i=t,a=r,o=(0,e.shallowRef)(null),s=(0,e.shallowRef)(null),c=(0,e.shallowRef)(null),l=(0,e.shallowRef)(null),u=(0,e.shallowRef)(!1),p=(0,e.shallowRef)(new Set),m=(0,e.shallowRef)(new Map),h=(0,e.shallowRef)(new Set),g=(0,e.shallowRef)(new Map),v=(0,e.computed)(()=>Object.freeze([...i.state.items])),y=(0,e.computed)(()=>_(i.state,v.value)),{markMasonryFullyVisible:b,markMasonryVisible:x,markPreviewError:S,markPreviewReady:C,markReelError:w,markReelReady:T,originalStates:E,previewStates:O,reelStates:k,resetMediaLifecycle:A}=on(i.state,{fullyVisible:e=>a(`mediaFullyVisible`,e),ready:e=>a(`mediaReady`,e),reelChange:e=>a(`reelMediaChange`,e),visible:e=>a(`mediaVisible`,e)}),j=new Set(i.state.items.map(e=>e.postId)),M=null,N=null,P=!1;function F(){return typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function I(){M!==null&&cancelAnimationFrame(M),M=requestAnimationFrame(()=>{M=requestAnimationFrame(()=>{M=null,p.value=new Set})})}function L(e,t){let n=i.state.items.find(t=>t.postId===e);if(!n)return;let r=f(n,t);(i.state.mediaIndices.get(e)??0)!==r&&(i.state.mediaIndices=new Map(i.state.mediaIndices).set(e,r))}async function ee(){await(0,e.nextTick)(),(i.state.layout===`reel`||i.state.reelOrigin===`masonry`?s.value:o.value)?.loadIfNearBottom()}function R(e){return i.state.isLoading||i.state.items.length===0||i.state.layout!==`reel`&&i.state.reelOrigin!==`masonry`?!1:s.value?.changeActiveMedia?.(e)??!1}function z(e){return i.state.isLoading||i.state.items.length===0||i.state.layout!==`reel`&&i.state.reelOrigin!==`masonry`?!1:s.value?.moveActivePost?.(e)??!1}function B(e){if(!(i.state.layout===`reel`||i.state.reelOrigin===`masonry`)||i.state.isLoading)return`reel-inactive`;let t=i.state.items.find(t=>t.postId===e.postId);if(!t)return`not-found`;let n=d(t).findIndex(t=>t.mediaId===e.mediaId);return n<0?`not-found`:s.value?.navigateToItem?.(e.postId,n)?`navigated`:`reel-inactive`}function V(){return i.state.layout!==`masonry`||i.state.reelOrigin===`masonry`?null:o.value?.getScrollElement?.()??null}function H(t,n){N=t,P=n===`keyboard`,a(`openReel`,t),(0,e.nextTick)(()=>c.value?.focus())}function U(e){let t=l.value?.querySelectorAll(`.masonry-feed [data-post-id]`)??[];return Array.from(t).find(t=>t.dataset.postId===String(e))??null}function W(e,t){if(i.state.layout!==`masonry`||i.state.reelOrigin!==null||F())return 0;let n=[...new Set(e)],r=new Set(Array.from(l.value?.querySelectorAll(`.masonry-feed [data-post-id]`)??[],e=>e.dataset.postId)),a=n.filter(e=>r.has(String(e)));if(a.length===0)return 0;let o=new Map(g.value),s=t?.staggerMs??dn;return a.forEach((e,t)=>{o.set(e,t*s)}),p.value=new Set([...p.value].filter(e=>!a.includes(e))),h.value=new Set([...h.value,...n]),g.value=o,fn+(a.length-1)*s}function te(){h.value=new Set,g.value=new Map}async function ne(t,n){if(n.aborted||W(t,{staggerMs:0})===0||(await(0,e.nextTick)(),n.aborted))return;let r=l.value?.querySelectorAll(`.masonry-feed .media-card--leaving`)??[],i=Array.from(r).flatMap(e=>(getComputedStyle(e).opacity,e.getAnimations?.().filter(e=>e.effect?.getTiming().iterations!==1/0)??[]));await new Promise(e=>{let t=()=>{n.removeEventListener(`abort`,t),e()};n.addEventListener(`abort`,t,{once:!0}),n.aborted?t():Promise.allSettled(i.map(e=>e.finished)).then(t)})}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 re(){i.state.reelOrigin===`masonry`&&(N??=i.state.activeReelPostId,u.value=!0,a(`closeReel`))}function ie(){let t=N,n=P;u.value=!1,N=null,P=!1,(0,e.nextTick)(()=>{t!==null&&G(t,n)})}return un({closeMasonryReel:re,element:()=>l.value,isReelLeaving:()=>u.value,reelRenderer:()=>s.value,setReelInfoSheet:e=>a(`reelInfoSheetChange`,e),state:i.state}),(0,e.watch)(()=>{let e=i.state.items;return[e,e.length]},([e])=>{let t=e.map(e=>e.postId),n=t.filter(e=>!j.has(e)),r=new Set(t);if(j=new Set(t),h.value=new Set([...h.value].filter(e=>r.has(e))),g.value=new Map([...g.value].filter(([e])=>r.has(e))),n.length===0||F())return;let i=new Map;t.forEach(e=>{let t=m.value.get(e);t!==void 0&&i.set(e,t)}),n.forEach((e,t)=>{i.set(e,t*dn)}),m.value=i,p.value=new Set([...p.value,...n]),I()},{flush:`sync`}),(0,e.onBeforeUnmount)(()=>{M!==null&&cancelAnimationFrame(M)}),n({animateItemRemoval:ne,cancelItemRemoval:te,changeActiveReelMedia:R,getAutoScrollElement:V,loadIfNearBottom:ee,moveActiveReelPost:z,navigateToReelItem:B,resetMediaLifecycle:A,startItemRemoval:W,transitionActiveReelMedia:e=>s.value?.transitionActiveMedia?.(e)??Promise.resolve(!1),transitionActiveReelPost:e=>s.value?.transitionActivePost?.(e)??Promise.resolve(!1)}),(n,r)=>((0,e.openBlock)(),(0,e.createElementBlock)(`div`,{ref_key:`surfaceElement`,ref:l,class:`vibe-surface`},[t.state.layout===`reel`&&(t.state.items.length>0||t.state.reelForward.status!==`idle`)?((0,e.openBlock)(),(0,e.createBlock)(nn,{key:0,ref_key:`reelRenderer`,ref:s,"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-audio-state":t.reelAudioState,"reel-forward":t.state.reelForward,state:y.value,total:t.state.total,onActiveChange:r[0]||=e=>a(`activeReelChange`,e),onCloseInfoSheet:r[1]||=e=>a(`reelInfoSheetChange`,!1),onError:(0,e.unref)(w),onLoadMore:r[2]||=e=>a(`loadMore`),onMediaChange:L,onReady:(0,e.unref)(T),onRetryEnd:r[3]||=e=>a(`retryEnd`),onRetryForward:r[4]||=e=>a(`retryForward`),onReelAudioChange:r[5]||=e=>a(`reelAudioChange`,e)},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-audio-state.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)(D,{key:1,actions:t.feedFooterActions,"can-retry-end":t.canRetryEnd,"feed-footer":t.feedFooter,state:y.value,onLoadMore:r[6]||=e=>a(`loadMore`),onRetryEnd:r[7]||=e=>a(`retryEnd`)},null,8,[`actions`,`can-retry-end`,`feed-footer`,`state`])):((0,e.openBlock)(),(0,e.createElementBlock)(e.Fragment,{key:2},[(0,e.createVNode)(Bt,{ref_key:`masonryRenderer`,ref:o,"can-retry-end":t.canRetryEnd,"entering-post-ids":p.value,"entry-delays":m.value,"leaving-post-ids":h.value,"removal-delays":g.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`||u.value,state:y.value,total:t.state.total,onActivate:H,onError:(0,e.unref)(S),onFullyVisible:(0,e.unref)(b),onLoadMore:r[8]||=e=>a(`loadMore`),onMediaChange:L,onReady:(0,e.unref)(C),onRetryEnd:r[9]||=e=>a(`retryEnd`),onVisible:(0,e.unref)(x)},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.onFullyVisible.onReady.onVisible`.split(`.`)),(0,e.createVNode)(e.Transition,{name:`vibe-reel-viewer`,onAfterLeave:ie},{default:(0,e.withCtx)(()=>[t.state.reelOrigin===`masonry`?((0,e.openBlock)(),(0,e.createElementBlock)(`section`,{key:0,ref_key:`reelOverlay`,ref:c,class:`vibe-reel-overlay`,role:`dialog`,"aria-label":`Media viewer`,"aria-modal":`true`,tabindex:`-1`},[(0,e.createVNode)(nn,{ref_key:`reelRenderer`,ref:s,"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)(E),"reel-auto-advance":t.state.reelAutoAdvance,"reel-audio-state":t.reelAudioState,"reel-forward":t.state.reelForward,state:y.value,total:t.state.total,onActiveChange:r[10]||=e=>a(`activeReelChange`,e),onCloseInfoSheet:r[11]||=e=>a(`reelInfoSheetChange`,!1),onError:(0,e.unref)(w),onLoadMore:r[12]||=e=>a(`loadMore`),onMediaChange:L,onReady:(0,e.unref)(T),onRetryEnd:r[13]||=e=>a(`retryEnd`),onRetryForward:r[14]||=e=>a(`retryForward`),onReelAudioChange:r[15]||=e=>a(`reelAudioChange`,e)},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-audio-state.reel-forward.state.total.onError.onReady`.split(`.`))],512)):(0,e.createCommentVNode)(``,!0)]),_:1})],64))],512))}});function mn(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 X(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 hn(e){return`${typeof e}:${String(e)}`}function gn(e){return e.mediaId===void 0?`source:${e.src}\u0000${e.preview?.src??``}`:`id:${hn(e.mediaId)}`}function _n(e,t){let n=[...e],r=new Map(e.map((e,t)=>[hn(e.postId),t]));return t.forEach(e=>{let t=hn(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(gn)),s=[e,...e.items].filter(e=>{let t=gn(e);return o.has(t)?!1:(o.add(t),!0)});s.length>0&&(n[i]={...a,items:[...a.items,...s]})}),n}function vn(e){return Object.prototype.hasOwnProperty.call(e,`current`)?e.current??null:e.next}function yn(e,t,n,r){let i=mn(e),a=n.filterItems(i.items),o=vn(i);t.items=_n(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 bn=2e3,xn=1e4,Sn=250,Cn={delayRemainingMs:null,nextRequestAt:null};function wn(e,t){return e===void 0?t:Math.floor(e)}function Tn(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 En(e,t={}){let n=wn(t.delayStepMs,bn),r=wn(t.delayMaxMs,xn);return Math.min(Math.max(0,e)*n,r)}function Z(e){if(e==null||!Number.isFinite(e))return{...Cn};let t=Math.max(0,Math.floor(e-Date.now()));return t>0?{delayRemainingMs:t,nextRequestAt:e}:{...Cn}}async function Dn({delayMs:e,onChange:t,signal:n}){if(n.aborted)throw new DOMException(`Aborted`,`AbortError`);if(e<=0){t({...Cn});return}let r=Date.now()+e;t({delayRemainingMs:e,nextRequestAt:r}),await new Promise((i,a)=>{let o=!1,s=setInterval(f,Sn),c=setTimeout(()=>u(),e);function l(){clearInterval(s),clearTimeout(c),n.removeEventListener(`abort`,d),t({...Cn})}function u(e){o||(o=!0,l(),e?a(e):i())}function d(){u(new DOMException(`Aborted`,`AbortError`))}function f(){let e=Z(r);t(e),e.delayRemainingMs===null&&u()}n.addEventListener(`abort`,d,{once:!0})})}var On=class{interval=null;constructor(e){this.onChange=e}clear(){this.interval!==null&&clearInterval(this.interval),this.interval=null,this.onChange({...Cn})}sync(e){this.clear();let t=Z(e);this.onChange(t),t.delayRemainingMs!==null&&(this.interval=setInterval(()=>{let t=Z(e);this.onChange(t),t.delayRemainingMs===null&&this.clear()},Sn))}};function kn(e,t=!0){return e.maxAdditionalPages===`unlimited`?1/0:(e.maxAdditionalPages??10)+(t?1:0)}function An(e){return`${typeof e}:${String(e)}`}function jn(e,t){if(!Number.isInteger(e)||e<=0)throw TypeError(`Vibe ${t} must be a positive integer.`)}function Mn(e){if(!e)return;if(jn(e.pageSize,`autofill pageSize`),e.strategy===`frontend`){Tn(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 Nn(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=Z(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 Q(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function Pn(e,t,n){let r=t.autofill;if(!Q(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 Fn(e,t,n){return e?.strategy===`backend`&&t.feedKey===e.feedKey&&t.sessionId===n.sessionId}async function In({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??kn(s),g=t,_=t,v=t,y=0,b=[],x;for(;y<h;){let e=An(g);if(m.has(e))throw Error(`Vibe autofill received a repeated cursor.`);if(m.add(e),await Dn({delayMs:En(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=mn(await n({cursor:g,signal:d}));y+=1,_=g;let r=X(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 Ln=class{collection=null;cycle=0;delayCountdown;constructor(e){this.context=e,this.delayCountdown=new On(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={...Nn(e,void 0,!1),cycleId:n,status:`filling`},n}async cancel(){let{cancelRequest:e,options:t,state:n}=this.context;await Pn(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=X(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}},Rn=100;function zn(e,t){if(!Number.isFinite(t)||t<=0)throw TypeError(`Vibe ${e} must be a positive number.`)}function Bn(e,t,n){return Math.min(n,Math.max(t,e))}function Vn(e){if(!e)return;let t=e.minSpeedPxPerSecond??20,n=e.maxSpeedPxPerSecond??240;if(zn(`autoScroll.minSpeedPxPerSecond`,t),zn(`autoScroll.maxSpeedPxPerSecond`,n),t>n)throw TypeError(`Vibe autoScroll.minSpeedPxPerSecond cannot exceed maxSpeedPxPerSecond.`);e.speedPxPerSecond!==void 0&&zn(`autoScroll.speedPxPerSecond`,e.speedPxPerSecond)}function Hn(e){let t=e?.minSpeedPxPerSecond??20,n=e?.maxSpeedPxPerSecond??240;return{enabled:e?.enabled??!1,maxSpeedPxPerSecond:n,minSpeedPxPerSecond:t,paused:!1,speedPxPerSecond:Bn(e?.speedPxPerSecond??80,t,n)}}var Un=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){zn(`auto-scroll speed`,e);let t=this.options.state;t.speedPxPerSecond=Bn(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(Rn,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 Wn(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,{...Z(i.nextRequestAt),missing:Math.max(0,e.pageSize-a),received:a,sequence:i.sequence??0,sessionId:i.sessionId,status:`waiting`})}function Gn(e,t){[`complete`,`exhausted`].includes(t.status)&&t.items&&(e.items=X(e.items,t.items)),t.next!==void 0&&(e.next=t.next),t.total!==void 0&&(e.total=t.total)}function Kn(e,t,n){let r=t.autofill;return!Fn(e,n,r)||n.sequence<=r.sequence||[`cancelled`,`cancelling`].includes(r.status)||[`complete`,`exhausted`].includes(n.status)&&n.next===void 0?!1:(Gn(t,n),Object.assign(r,Z(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 qn(e,t,n){return e?.strategy!==`backend`||n.feedKey!==e.feedKey||n.pageSize!==e.pageSize?!1:(t.autofill=Nn(e,n),Gn(t,n),!0)}async function Jn(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 Yn({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 Wn(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 In({existingItems:s.items,initialCursor:s.next,loadPage:a.loadPage,maximumRequests:kn(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=X(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 Xn(e){return`items`in e?{items:e.items}:`pages`in e?{pages:e.pages}:{until:`end`}}function Zn(e){return`${typeof e}:${String(e)}`}function Qn(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 $n(e){if(!e)return;if(e.strategy===`frontend`){Tn(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.`);Qn(t.target)}}function er(e,t,n=!0){let r=e?.strategy===`backend`&&n?e.initialSession:void 0,i=t??r,a=Z(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?Xn(i.target):null}}function tr(e){return[`cancelling`,`filling`,`restoring`,`waiting`].includes(e.status)}async function nr({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=Zn(h);if(p.has(e))throw Error(`Vibe fill received a repeated cursor.`);if(p.add(e),await Dn({delayMs:En(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=mn(await n({cursor:h,signal:c}));m+=1,g=h;let b=X(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 rr(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,{...Z(i.nextRequestAt),completedPages:i.completedPages??0,received:i.received??0,sequence:i.sequence??0,sessionId:i.sessionId,status:`waiting`})}}function ir(e,t,n){return e?.strategy===`backend`&&n.feedKey===e.feedKey&&n.sessionId===t.fill.sessionId}function ar(e){return Number.isInteger(e.completedPages)&&e.completedPages>=0&&Number.isInteger(e.received)&&e.received>=0&&Number.isInteger(e.sequence)&&e.sequence>=0}function or(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 sr(e,t,n){t.total!==void 0&&(e.total=t.total),[`complete`,`exhausted`].includes(t.status)&&(e.items=X(e.items,t.items??[]),e.next=t.next??null,n(t.lastCursor??null))}function cr(e,t,n,r){return!ir(e,t,n)||!ar(n)||n.sequence<=t.fill.sequence||[`cancelled`,`cancelling`].includes(t.fill.status)||!or(t,n)?!1:(sr(t,n,r),Object.assign(t.fill,{...Z(n.status===`waiting`?n.nextRequestAt:null),completedPages:n.completedPages,error:n.error??null,received:n.received,sequence:n.sequence,status:n.status}),!0)}function lr(e,t,n,r){if(e?.strategy!==`backend`||n.feedKey!==e.feedKey)return!1;let i=t.fill;return t.fill=er(e,n),!ar(n)||!or(t,n)?(t.fill=i,!1):(sr(t,n,r),!0)}var ur=class{abortController=null;cycle=0;delayCountdown;requestVersion=0;collection=null;constructor(e){this.options=e,this.delayCountdown=new On(e=>{Object.assign(this.options.state.fill,e)}),this.syncBackendCountdown()}isActive(){return tr(this.options.state.fill)}applyUpdate(e){let t=cr(this.options.fill,this.options.state,e,this.options.onLastCursor);return t&&this.syncBackendCountdown(),t}restoreSession(e){let t=lr(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=Qn(e),i=Qn(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={...er(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 rr(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(!tr(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=er(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 nr({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=X(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=X(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 dr({controller:e,isCurrent:t,loadPage:n,onDelayChange:r,pauseWhenManual:i=!1,setLastCursor:a,signal:o,state:s}){if(!e.needsReconciliation(s.items))return`skipped`;let c=await e.reconcile({existingItems:s.items,loadPage:n,onDelayChange:r,shouldPause:()=>s.loadMoreLocked||i&&!s.infiniteScroll,signal:o});return t()?(s.items=X(s.items,c.items),s.next=c.next,a(c.lastCursor),c.total!==void 0&&(s.total=c.total),e.completeReconciliation(c),c.status):c.status}function fr(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 pr(e){if(!Number.isFinite(e)||e<=0)throw TypeError(`Vibe reelAutoAdvance.intervalMs must be a positive number.`)}function mr(e){e?.intervalMs!==void 0&&pr(e.intervalMs)}function hr(e){return{enabled:e?.enabled??!1,includePostItems:e?.includePostItems??!1,intervalMs:e?.intervalMs??5e3}}function gr(e,t){if(typeof t==`boolean`){e.enabled=t;return}mr(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 _r(e){return{enabled:e?.enabled??!1}}function vr(e,t,n){if(n&&!t)throw Error(`Vibe cannot enable reelInfoSheet without a configured component.`);e.enabled=n}function yr(e,t){let n=e.initialPage;return{activeReelPostId:null,autoScroll:Hn(e.autoScroll),autofill:Nn(e.autofill),current:n?.current??null,error:null,fill:er(e.fill),infiniteScroll:e.infiniteScroll??!0,isLoading:!n,isLoadingMore:!1,items:n?X([],n.items):[],layout:t===`reel`?`reel`:`masonry`,loadMoreLocked:!1,mediaIndices:new Map,next:n?.next??null,nextPageError:null,phoneMode:!1,reelAutoAdvance:hr(e.reelAutoAdvance),reelForward:{error:null,status:`idle`},reelForwardIndex:null,reelForwardItem:null,reelInfoSheet:_r(e.reelInfoSheet),reelInfoSheetOverlay:!1,reelMediaSource:`original`,reelOrigin:null,total:n?.total??null}}function br(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 xr(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 Sr(e){if(Vn(e.autoScroll),br(`cardHeader`,e.cardHeader),br(`cardFooter`,e.cardFooter),xr(`header`,e.mediaCard?.header),xr(`footer`,e.mediaCard?.footer),e.mediaCard?.feedPreload!==void 0&&e.mediaCard.feedPreload!==`none`&&e.mediaCard.feedPreload!==`visible-post`)throw TypeError(`Vibe mediaCard feedPreload must be "none" or "visible-post".`);if(Mn(e.autofill),$n(e.fill),ae(e.masonry),mr(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 Cr(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 wr({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 In({existingItems:e?l.items:[],initialCursor:n,loadPage:i,maximumRequests:f?Math.max(0,kn(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?X(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=mn(await i({cursor:n,signal:c}));if(!r())return;let d=e?l.items:[],h=X(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 Wn(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)}}var Tr=class{controller=null;constructor(e){this.options=e}isActive(){return this.controller!==null}cancel(){this.controller?.abort(),this.controller=null,this.options.surface()?.cancelItemRemoval()}async replace(e,t){let n=mn(e);this.cancel();let r=new AbortController;this.controller=r;try{if(await this.options.prepare(),r.signal.aborted)return;let e=this.options.state,i=new Map(e.items.map(e=>[String(e.postId),e])),a=[],o=new Set;for(let e of n.items){let t=String(e.postId);o.has(t)||(o.add(t),a.push({...e,postId:i.get(t)?.postId??e.postId}))}let s=e.items.filter(e=>!o.has(String(e.postId))).map(e=>e.postId);if(await this.options.surface()?.animateItemRemoval(s,r.signal),r.signal.aborted)return;if(t?.resetScroll){let e=this.options.surface()?.getAutoScrollElement();e&&(e.scrollTop=0)}e.mediaIndices=new Map(a.map(t=>[t.postId,f(t,e.mediaIndices.get(t.postId)??0)])),e.activeReelPostId!==null&&!o.has(String(e.activeReelPostId))&&(e.activeReelPostId=null,e.reelOrigin=null),e.items=a,e.next=n.next,e.total=n.total??null,e.error=null,e.nextPageError=null,this.options.commit({...n,items:a})}finally{this.controller===r&&(this.controller=null,this.options.surface()?.cancelItemRemoval())}}};function Er(t,n,r){if(t.loadMoreLocked!==n&&(t.loadMoreLocked=n,!n)){if(t.fill.status===`paused`&&t.fill.target){r.resumeFill();return}if(t.autofill.status===`paused`||r.hasPendingSession()){let e=r.getPending();e?e.finally(()=>{r.loadNext()}):r.loadNext()}else t.infiniteScroll&&(0,e.nextTick)(r.loadIfNearBottom)}}function $(e){return`${typeof e}:${String(e)}`}function Dr(e){return`${typeof e}:${String(e)}`}function Or(e){return e.map(({postId:e})=>e)}var kr=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:Or(e.items),cursor:vn(e),next:e.next,returnedIds:Or(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=Dr(a.cursor);if(a.seenCursors.has(e))throw Error(`Vibe removal reconciliation received a repeated cursor.`);if(await Dn({delayMs:En(a.pages.length,this.delay),onChange:n,signal:i}),a.pages.length>0&&r())return this.result(a,`paused`);let o=mn(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:Or(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=Dr(e.cursor),n=this.pages.findIndex(({cursor:e})=>Dr(e)===t);n>=0&&(this.pages=this.pages.slice(0,n)),this.pages.push({...e,contributionIds:[...e.contributionIds],returnedIds:[...e.returnedIds]})}};function Ar(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 jr(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 Mr(e){if(!Number.isInteger(e.mediaIndex)||e.mediaIndex<0)throw TypeError(`Vibe mediaIndex must be a non-negative integer.`)}var Nr=class{generation=0;metadata=new WeakMap;state;constructor(e){this.options=e,this.state=e.state}remove(e){Mr(e);let t=this.state.items.findIndex(({postId:t})=>t===e.postId),n=this.state.items[t];if(!n)return null;let r=[...d(n)],i=r[e.mediaIndex];if(!i)return null;let a=Object.freeze({media:i,mediaIndex:e.mediaIndex,postId:e.postId,postIndex:t});this.metadata.set(a,{generation:this.generation,originalItem:n,restored:!1});let o=this.state.mediaIndices.get(n.postId)??0,s=this.isReelOpen()&&this.state.activeReelPostId===n.postId,c=s&&o===e.mediaIndex;return r.splice(e.mediaIndex,1),r.length>0?(this.state.items[t]=jr(n,r),this.updateMediaIndexAfterRemoval(n.postId,e.mediaIndex,c),a):(this.state.items.splice(t,1),this.options.onPostRemoved(n.postId),this.state.mediaIndices.delete(n.postId),s&&this.advanceFromRemovedPost(a,n),a)}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],r=[...d(n)],i=Math.min(t.mediaIndex,r.length);if(r.splice(i,0,t.media),this.state.items[e]=jr(n,r),this.state.activeReelPostId!==t.postId)return;let a=this.state.mediaIndices.get(t.postId)??0;a>=i&&this.state.mediaIndices.set(t.postId,a+1)}updateMediaIndexAfterRemoval(e,t,n){let r=this.state.items.find(t=>t.postId===e);if(!r)return;let i=d(r).length,a=this.state.mediaIndices.get(e)??0,o=a;n?o=t<i?t:0:t<a&&(o=a-1),this.state.mediaIndices.set(e,Math.min(o,i-1))}};function Pr(e,t){let n=new Set(t);return e.flatMap((e,t)=>n.has(e.postId)?[{index:t,item:e}]:[])}function Fr(e,t){let n=new Set(t.map(({item:e})=>e.postId));return e.filter(e=>!n.has(e.postId))}function Ir(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 Lr=20,Rr=class{generation=0;historyLimit;metadata=new WeakMap;state;history=[];itemOrder;stopItemsWatcher;constructor(t){this.options=t,this.historyLimit=t.historyLimit??Lr,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=Fr(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=Ir(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 Pr(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}},zr=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.forwardPromise?this.forwardPromise.then(()=>this.retry()):(this.state.nextPageError=null,this.state.reelForward={error:null,status:`loading`},this.startForwardRequest(!0))}clearState(){this.state.reelForward={error:null,status:`idle`},this.state.reelForwardIndex=null,this.state.reelForwardItem=null}stopAtPaginationBoundary(e){return!this.state.loadMoreLocked&&(this.state.infiniteScroll||e)?!1:(this.state.reelOrigin===`masonry`?(this.reset(),this.options.onCloseReel()):this.state.reelForward={error:null,status:`end`},!0)}startForwardRequest(e=!1){if(this.forwardPromise)return this.forwardPromise;let t=this.loadForward(e);return this.forwardPromise=t,t.finally(()=>{this.forwardPromise===t&&(this.forwardPromise=null,this.forward&&this.state.reelForward.status===`loading`&&this.startForwardRequest(e))})}async loadForward(e){let t=this.forward;if(t)for(;this.forward===t&&t.version===this.forwardVersion;){let n=this.state.items[t.postIndex];if(n){this.forward=null,this.clearState(),this.options.onActivate(n.postId);return}if(this.stopAtPaginationBoundary(e))return;if(this.state.nextPageError){this.state.reelForward={error:this.state.nextPageError,status:`error`};return}let r=this.state.next,i=this.state.items.length;if(await this.options.replenishAfterRemoval(e),this.forward!==t||t.version!==this.forwardVersion)return;if(!this.state.items[t.postIndex]){if(this.stopAtPaginationBoundary(e))return;if(this.state.nextPageError){this.state.reelForward={error:this.state.nextPageError,status:`error`};return}if(this.state.next===null){this.state.reelForward={error:null,status:`end`};return}if(this.state.next===r&&this.state.items.length===i){this.state.reelForward={error:Error(`Vibe could not advance while page loading is unavailable.`),status:`error`};return}}}}},Br=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 r=t.mediaIndices.get(e.postId)??0;if(e.mediaIndex===r){if(d(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 Vr(e){let t=new zr(e),n=new Br({state:e.state,transitionMedia:t=>e.surface()?.transitionActiveReelMedia(t)??Promise.resolve(!1),transitionPost:t=>e.surface()?.transitionActiveReelPost(t)??Promise.resolve(!1)});return{exactMediaRemoval:new Nr({onActivate:e.onActivate,onPostRemoved:t=>e.onItemsRemoved([t]),onPostRestored:t=>e.onItemsRestored([t]),reelForward:t,state:e.state}),itemRemoval:new Rr({historyLimit:e.historyLimit,onItemsRemoved:(n,r,i)=>{e.onItemsRemoved(r.map(({item:e})=>e.postId)),Ar(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 Hr=1.5;function Ur(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*Hr;return!e.hasHover&&n>0&&n<600&&r}function Wr(e){return Ur(e)?`reel`:`masonry`}function Gr(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 Kr(e){return Ur(Gr(e))}function qr(e){return Wr(Gr(e))}var Jr=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=qr(this.target);this.state.phoneMode=Kr(this.target),this.state.reelInfoSheetOverlay=this.state.phoneMode,this.state.reelMediaSource=this.state.phoneMode?`mobile`:`original`,this.layoutMode===`responsive`&&this.applyLayout(e)}},Yr=class{state;constructor(t){this.options=t,this.state=(0,e.reactive)(dt({...t.initialReelAudioState,muted:t.initialReelAudioState?.muted??t.mediaCard?.videoMuted??!1}))}get(){return{...this.state}}set(e,t=!1){Object.assign(this.state,dt(e,this.state)),t&&this.options.onReelAudioStateChange?.(this.get())}},Xr=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)}};function Zr(e){return String(e)}function Qr(e,t){let n=d(t).length;(e.mediaIndices.get(t.postId)??0)>=n&&e.mediaIndices.set(t.postId,Math.max(0,n-1))}function $r(e,t){let n=new Map;if(t.forEach(e=>n.set(Zr(e.postId),e)),n.size===0)return[];let r=[],i=e.items.map(t=>{let i=n.get(Zr(t.postId));if(!i)return t;let a={...i,postId:t.postId};return Qr(e,a),e.reelForwardItem&&Zr(e.reelForwardItem.postId)===Zr(t.postId)&&(e.reelForwardItem=a),r.push(t.postId),a});return r.length>0&&(e.items=i),r}var ei=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;reelAudio;state;pageReplacement;constructor(t){this.options=t,Sr(t);let n=t.layout??`masonry`;this.state=(0,e.reactive)(yr(t,n)),this.reelAudio=new Yr(t),this.lastLoadedCursor=t.initialPage?vn(t.initialPage):null,this.notificationItems=h(this.state),this.autoScroll=new Un({getScrollElement:()=>this.surface?.getAutoScrollElement()??null,state:this.state.autoScroll}),this.autofillController=new Ln({cancelRequest:()=>this.cancelRequest(!this.pageReplacement?.isActive()),onLastCursor:e=>this.setCurrentCursor(e),onPages:e=>this.removalReconciliation.recordPages(e),options:t.autofill,state:this.state}),this.removalReconciliation=new kr(t),this.removalReconciliation.recordInitialPage(t.initialPage),this.fillController=new ur({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})=>dr({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 Xr(t.routing,this.state);let r=Vr({historyLimit:t.removalHistoryLimit,onActivate:e=>this.setActiveReelPost(e),onCloseReel:()=>this.closeMasonryReel(),onItemsRemoved:e=>this.removalReconciliation.remove(e),onItemsRestored:e=>this.removalReconciliation.restore(e),replenishAfterRemoval:e=>this.replenishAfterRemoval(e),state:this.state,surface:()=>this.surface});this.exactMediaRemoval=r.exactMediaRemoval,this.itemRemoval=r.itemRemoval,this.reelForward=r.reelForward,this.reelRemoval=r.reelRemoval,this.pageReplacement=new Tr({state:this.state,surface:()=>this.surface,prepare:async()=>{this.cancelRequest(!1),Q(this.state.autofill)&&await this.cancelAutofill(),this.fillController.isActive()&&await this.cancelFill()},commit:e=>{this.resetFeedVisit(),this.setCurrentCursor(vn(e)),this.removalReconciliation.recordInitialPage(e),this.state.reelOrigin===null&&this.routing.syncFeed()}}),this.responsiveLayout=new Jr(n,this.state,()=>{this.routing.syncFeed()}),this.startStateNotifications()}async mount(){if(this.app)throw Error(`Vibe is already mounted.`);this.startStateNotifications();let t=Cr(this.options.target);this.responsiveLayout.mount(t),this.app=(0,e.createApp)(pn,{canRetryEnd:!!this.options.loadPage,cardFooter:this.options.cardFooter,cardHeader:this.options.cardHeader,feedFooter:this.options.feedFooter,feedFooterActions:fr(this),mediaCard:this.options.mediaCard,masonry:this.options.masonry,onMediaFullyVisible:this.options.onMediaFullyVisible,onMediaReady:this.options.onMediaReady,onMediaVisible:this.options.onMediaVisible,onReelMediaChange:this.options.onReelMediaChange,reelAudioState:this.reelAudio.state,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),onReelAudioChange:e=>this.reelAudio.set(e,!0),onRetryEnd:()=>{this.retryEnd()},onRetryForward:()=>{this.retryReelForward()}}),this.surface=this.app.mount(t),this.autoScroll.mount(),await Jn(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 _(this.state)}getReelAudioState(){return this.reelAudio.get()}setReelAudioState(e){this.reelAudio.set(e)}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)}updateItems(e){return $r(this.state,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=Kn(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.cancelRequest(),this.fillController.isActive()){await this.cancelFill();return}if(Q(this.state.autofill)){await this.cancelAutofill();return}}applyFillUpdate(e){return this.fillController.applyUpdate(e)}cancelFill(){return this.fillController.cancel()}async fill(e){if(!(this.state.loadMoreLocked||this.pageReplacement.isActive())){if(this.pendingRequest||Q(this.state.autofill))throw Error(`Vibe cannot fill while another page operation is active.`);await this.fillController.start(e)}}restoreAutofillSession(e){let t=qn(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){yn(e,this.state,this.removalReconciliation,e=>this.setCurrentCursor(e))}replenishAfterRemoval(e=!0){return this.startLoadMore(()=>this.replenishAfterRemovalSequence(e))}async startLoadMore(e){if(this.pageReplacement.isActive())return;if(this.pendingRequest)return this.pendingRequest;if(this.state.loadMoreLocked||Q(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`)}replacePage(e,t){return this.pageReplacement.replace(e,t)}async replaceFeed(e,t){if(!this.options.loadPage)throw Error(`Vibe cannot ${t} without loadPage.`);return Q(this.state.autofill)&&await this.cancelAutofill(),this.fillController.isActive()&&await this.cancelFill(),this.cancelRequest(),this.resetFeedVisit(),this.surface?.resetMediaLifecycle(),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)}resetFeedVisit(){this.state.autofill=Nn(this.options.autofill,void 0,!1),this.fillController.reset(),this.reelForward.reset(),this.reelRemoval.reset(),this.exactMediaRemoval.reset(),this.itemRemoval.reset(),this.removalReconciliation.reset()}async loadFilteredPage(e){let t=this.options.loadPage;if(!t)throw Error(`Vibe cannot load a page without loadPage.`);let n=mn(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(e){if(!e&&!this.state.infiniteScroll)return;let t=this.state.items.length;this.removalReconciliation.needsReconciliation(this.state.items)&&(!await this.reconcileBeforeNext(!e)||this.state.items.length>t)||this.state.loadMoreLocked||!e&&!this.state.infiniteScroll||this.state.next===null||await this.fetchPage(this.state.next,!0)}async reconcileBeforeNext(e=!1){let t=this.options.loadPage;if(!t)return!1;let n=++this.requestVersion,r=new AbortController;this.abortController=r;try{let i=await dr({controller:this.removalReconciliation,isCurrent:()=>n===this.requestVersion,loadPage:t,onDelayChange:()=>void 0,pauseWhenManual:e,setLastCursor:e=>this.setCurrentCursor(e),signal:r.signal,state:this.state});return n===this.requestVersion&&i===`complete`&&(this.state.nextPageError=null),n===this.requestVersion&&i===`complete`}catch(e){return!r.signal.aborted&&n===this.requestVersion&&(this.state.nextPageError=e),!1}finally{this.abortController===r&&(this.abortController=null)}}async retryEnd(){if(!this.pageReplacement.isActive()){if(this.pendingRequest)return this.pendingRequest;if(!this.state.loadMoreLocked&&!(Q(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(e){Er(this.state,e,{getPending:()=>this.pendingRequest,hasPendingSession:()=>this.removalReconciliation.hasPendingSession(),loadNext:()=>this.loadNext(),resumeFill:()=>this.fillController.resume(this.removalReconciliation.hasPendingSession()),loadIfNearBottom:()=>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){gr(this.state.reelAutoAdvance,e)}setReelInfoSheet(e){vr(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(e=!0){e&&this.pageReplacement.cancel(),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 wr({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=Yn({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 e=this.options.onStateChange;!e||this.stopStateWatcher||(this.stopStateWatcher=g(this.state,this.notificationItems,e))}setCurrentCursor(e){this.lastLoadedCursor=this.state.current=e}},ti=e=>new ei(e);exports.createVibe=ti;