autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
10 lines (9 loc) • 31.3 kB
JavaScript
import{r as a,j as M,i as ot,g as qt,s as Vt,a as Dt,b as it,c as Lt,d as Kt,e as Jt,f as Zt,h as Qt,k as te,l as ee,m as bt,n as ne,o as se,p as oe,q as ie,S as re,H as ae,F as D,t as ue,u as At,v as F,w as rt,x as E,y as Tt,z as le,A as at,B as ce,C as O,D as q,E as ut,G as fe,I as he,J as V,K as de,L as me,M as pe,N as lt,O as ge,P as ve,Q as ct,R as ye,T as Pe,U as j,V as xe,W as we,X as Rt,Y as Ce,Z as Ee}from"./vendor-BZEJEVBn.js";const Z=a.createContext({});function Q(e){const t=a.useRef(null);return t.current===null&&(t.current=e()),t.current}const Se=typeof window<"u",It=Se?a.useLayoutEffect:a.useEffect,G=a.createContext(null),tt=a.createContext({transformPagePoint:e=>e,isStatic:!1,reducedMotion:"never"});function ft(e,t){if(typeof e=="function")return e(t);e!=null&&(e.current=t)}function Me(...e){return t=>{let n=!1;const s=e.map(o=>{const i=ft(o,t);return!n&&typeof i=="function"&&(n=!0),i});if(n)return()=>{for(let o=0;o<s.length;o++){const i=s[o];typeof i=="function"?i():ft(e[o],null)}}}}function Ve(...e){return a.useCallback(Me(...e),e)}class De extends a.Component{getSnapshotBeforeUpdate(t){const n=this.props.childRef.current;if(n&&t.isPresent&&!this.props.isPresent&&this.props.pop!==!1){const s=n.offsetParent,o=ot(s)&&s.offsetWidth||0,i=ot(s)&&s.offsetHeight||0,r=this.props.sizeRef.current;r.height=n.offsetHeight||0,r.width=n.offsetWidth||0,r.top=n.offsetTop,r.left=n.offsetLeft,r.right=o-r.width-r.left,r.bottom=i-r.height-r.top}return null}componentDidUpdate(){}render(){return this.props.children}}function Le({children:e,isPresent:t,anchorX:n,anchorY:s,root:o,pop:i}){const r=a.useId(),l=a.useRef(null),p=a.useRef({width:0,height:0,top:0,left:0,right:0,bottom:0}),{nonce:h}=a.useContext(tt),m=e.props?.ref??e?.ref,c=Ve(l,m);return a.useInsertionEffect(()=>{const{width:u,height:d,top:f,left:g,right:v,bottom:y}=p.current;if(t||i===!1||!l.current||!u||!d)return;const P=n==="left"?`left: ${g}`:`right: ${v}`,w=s==="bottom"?`bottom: ${y}`:`top: ${f}`;l.current.dataset.motionPopId=r;const x=document.createElement("style");h&&(x.nonce=h);const L=o??document.head;return L.appendChild(x),x.sheet&&x.sheet.insertRule(`
[data-motion-pop-id="${r}"] {
position: absolute !important;
width: ${u}px !important;
height: ${d}px !important;
${P}px !important;
${w}px !important;
}
`),()=>{L.contains(x)&&L.removeChild(x)}},[t]),M.jsx(De,{isPresent:t,childRef:l,sizeRef:p,pop:i,children:i===!1?e:a.cloneElement(e,{ref:c})})}const be=({children:e,initial:t,isPresent:n,onExitComplete:s,custom:o,presenceAffectsLayout:i,mode:r,anchorX:l,anchorY:p,root:h})=>{const m=Q(Ae),c=a.useId();let u=!0,d=a.useMemo(()=>(u=!1,{id:c,initial:t,isPresent:n,custom:o,onExitComplete:f=>{m.set(f,!0);for(const g of m.values())if(!g)return;s&&s()},register:f=>(m.set(f,!1),()=>m.delete(f))}),[n,m,s]);return i&&u&&(d={...d}),a.useMemo(()=>{m.forEach((f,g)=>m.set(g,!1))},[n]),a.useEffect(()=>{!n&&!m.size&&s&&s()},[n]),e=M.jsx(Le,{pop:r==="popLayout",isPresent:n,anchorX:l,anchorY:p,root:h,children:e}),M.jsx(G.Provider,{value:d,children:e})};function Ae(){return new Map}function kt(e=!0){const t=a.useContext(G);if(t===null)return[!0,null];const{isPresent:n,onExitComplete:s,register:o}=t,i=a.useId();a.useEffect(()=>{if(e)return o(i)},[e]);const r=a.useCallback(()=>e&&s&&s(i),[i,s,e]);return!n&&s?[!1,r]:[!0]}const I=e=>e.key||"";function ht(e){const t=[];return a.Children.forEach(e,n=>{a.isValidElement(n)&&t.push(n)}),t}const Hn=({children:e,custom:t,initial:n=!0,onExitComplete:s,presenceAffectsLayout:o=!0,mode:i="sync",propagate:r=!1,anchorX:l="left",anchorY:p="top",root:h})=>{const[m,c]=kt(r),u=a.useMemo(()=>ht(e),[e]),d=r&&!m?[]:u.map(I),f=a.useRef(!0),g=a.useRef(u),v=Q(()=>new Map),y=a.useRef(new Set),[P,w]=a.useState(u),[x,L]=a.useState(u);It(()=>{f.current=!1,g.current=u;for(let S=0;S<x.length;S++){const C=I(x[S]);d.includes(C)?(v.delete(C),y.current.delete(C)):v.get(C)!==!0&&v.set(C,!1)}},[x,d.length,d.join("-")]);const B=[];if(u!==P){let S=[...u];for(let C=0;C<x.length;C++){const b=x[C],U=I(b);d.includes(U)||(S.splice(C,0,b),B.push(b))}return i==="wait"&&B.length&&(S=B),L(ht(S)),w(u),null}const{forceRender:Xt}=a.useContext(Z);return M.jsx(M.Fragment,{children:x.map(S=>{const C=I(S),b=r&&!m?!1:u===x||d.includes(C),U=()=>{if(y.current.has(C))return;if(y.current.add(C),v.has(C))v.set(C,!0);else return;let st=!0;v.forEach(Yt=>{Yt||(st=!1)}),st&&(Xt?.(),L(g.current),r&&c?.(),s&&s())};return M.jsx(be,{isPresent:b,initial:!f.current||n?void 0:!1,custom:t,presenceAffectsLayout:o,mode:i,root:h,onExitComplete:b?void 0:U,anchorX:l,anchorY:p,children:S},C)})})},jt=a.createContext({strict:!1}),dt={animation:["animate","variants","whileHover","whileTap","exit","whileInView","whileFocus","whileDrag"],exit:["exit"],drag:["drag","dragControls"],focus:["whileFocus"],hover:["whileHover","onHoverStart","onHoverEnd"],tap:["whileTap","onTap","onTapStart","onTapCancel"],pan:["onPan","onPanStart","onPanSessionStart","onPanEnd"],inView:["whileInView","onViewportEnter","onViewportLeave"],layout:["layout","layoutId"]};let mt=!1;function Te(){if(mt)return;const e={};for(const t in dt)e[t]={isEnabled:n=>dt[t].some(s=>!!n[s])};Vt(e),mt=!0}function Ft(){return Te(),qt()}function Re(e){const t=Ft();for(const n in e)t[n]={...t[n],...e[n]};Vt(t)}const Ie=new Set(["animate","exit","variants","initial","style","values","variants","transition","transformTemplate","custom","inherit","onBeforeLayoutMeasure","onAnimationStart","onAnimationComplete","onUpdate","onDragStart","onDrag","onDragEnd","onMeasureDragConstraints","onDirectionLock","onDragTransitionEnd","_dragX","_dragY","onHoverStart","onHoverEnd","onViewportEnter","onViewportLeave","globalTapTarget","propagate","ignoreStrict","viewport"]);function W(e){return e.startsWith("while")||e.startsWith("drag")&&e!=="draggable"||e.startsWith("layout")||e.startsWith("onTap")||e.startsWith("onPan")||e.startsWith("onLayout")||Ie.has(e)}let Ot=e=>!W(e);function ke(e){typeof e=="function"&&(Ot=t=>t.startsWith("on")?!W(t):e(t))}try{ke(require("@emotion/is-prop-valid").default)}catch{}function je(e,t,n){const s={};for(const o in e)o==="values"&&typeof e.values=="object"||(Ot(o)||n===!0&&W(o)||!t&&!W(o)||e.draggable&&o.startsWith("onDrag"))&&(s[o]=e[o]);return s}const H=a.createContext({});function Fe(e,t){if(Dt(e)){const{initial:n,animate:s}=e;return{initial:n===!1||it(n)?n:void 0,animate:it(s)?s:void 0}}return e.inherit!==!1?t:{}}function Oe(e){const{initial:t,animate:n}=Fe(e,a.useContext(H));return a.useMemo(()=>({initial:t,animate:n}),[pt(t),pt(n)])}function pt(e){return Array.isArray(e)?e.join(" "):e}const et=()=>({style:{},transform:{},transformOrigin:{},vars:{}});function Wt(e,t,n){for(const s in t)!Lt(t[s])&&!Kt(s,n)&&(e[s]=t[s])}function We({transformTemplate:e},t){return a.useMemo(()=>{const n=et();return Jt(n,t,e),Object.assign({},n.vars,n.style)},[t])}function Ge(e,t){const n=e.style||{},s={};return Wt(s,n,e),Object.assign(s,We(e,t)),s}function He(e,t){const n={},s=Ge(e,t);return e.drag&&e.dragListener!==!1&&(n.draggable=!1,s.userSelect=s.WebkitUserSelect=s.WebkitTouchCallout="none",s.touchAction=e.drag===!0?"none":`pan-${e.drag==="x"?"y":"x"}`),e.tabIndex===void 0&&(e.onTap||e.onTapStart||e.whileTap)&&(n.tabIndex=0),n.style=s,n}const Gt=()=>({...et(),attrs:{}});function Be(e,t,n,s){const o=a.useMemo(()=>{const i=Gt();return Zt(i,t,Qt(s),e.transformTemplate,e.style),{...i.attrs,style:{...i.style}}},[t]);if(e.style){const i={};Wt(i,e.style,e),o.style={...i,...o.style}}return o}const Ue=["animate","circle","defs","desc","ellipse","g","image","line","filter","marker","mask","metadata","path","pattern","polygon","polyline","rect","stop","switch","symbol","svg","text","tspan","use","view"];function nt(e){return typeof e!="string"||e.includes("-")?!1:!!(Ue.indexOf(e)>-1||/[A-Z]/u.test(e))}function Ne(e,t,n,{latestValues:s},o,i=!1,r){const p=(r??nt(e)?Be:He)(t,s,o,e),h=je(t,typeof e=="string",i),m=e!==a.Fragment?{...h,...p,ref:n}:{},{children:c}=t,u=a.useMemo(()=>Lt(c)?c.get():c,[c]);return a.createElement(e,{...m,children:u})}function $e({scrapeMotionValuesFromProps:e,createRenderState:t},n,s,o){return{latestValues:ze(n,s,o,e),renderState:t()}}function ze(e,t,n,s){const o={},i=s(e,{});for(const u in i)o[u]=te(i[u]);let{initial:r,animate:l}=e;const p=Dt(e),h=ee(e);t&&h&&!p&&e.inherit!==!1&&(r===void 0&&(r=t.initial),l===void 0&&(l=t.animate));let m=n?n.initial===!1:!1;m=m||r===!1;const c=m?l:r;if(c&&typeof c!="boolean"&&!bt(c)){const u=Array.isArray(c)?c:[c];for(let d=0;d<u.length;d++){const f=ne(e,u[d]);if(f){const{transitionEnd:g,transition:v,...y}=f;for(const P in y){let w=y[P];if(Array.isArray(w)){const x=m?w.length-1:0;w=w[x]}w!==null&&(o[P]=w)}for(const P in g)o[P]=g[P]}}}return o}const Ht=e=>(t,n)=>{const s=a.useContext(H),o=a.useContext(G),i=()=>$e(e,t,s,o);return n?i():Q(i)},_e=Ht({scrapeMotionValuesFromProps:se,createRenderState:et}),Xe=Ht({scrapeMotionValuesFromProps:oe,createRenderState:Gt}),Ye=Symbol.for("motionComponentSymbol");function qe(e,t,n){const s=a.useRef(n);a.useInsertionEffect(()=>{s.current=n});const o=a.useRef(null);return a.useCallback(i=>{i&&e.onMount?.(i);const r=s.current;if(typeof r=="function")if(i){const l=r(i);typeof l=="function"&&(o.current=l)}else o.current?(o.current(),o.current=null):r(i);else r&&(r.current=i);t&&(i?t.mount(i):t.unmount())},[t])}const Bt=a.createContext({});function A(e){return e&&typeof e=="object"&&Object.prototype.hasOwnProperty.call(e,"current")}function Ke(e,t,n,s,o,i){const{visualElement:r}=a.useContext(H),l=a.useContext(jt),p=a.useContext(G),h=a.useContext(tt),m=h.reducedMotion,c=h.skipAnimations,u=a.useRef(null),d=a.useRef(!1);s=s||l.renderer,!u.current&&s&&(u.current=s(e,{visualState:t,parent:r,props:n,presenceContext:p,blockInitialAnimation:p?p.initial===!1:!1,reducedMotionConfig:m,skipAnimations:c,isSVG:i}),d.current&&u.current&&(u.current.manuallyAnimateOnMount=!0));const f=u.current,g=a.useContext(Bt);f&&!f.projection&&o&&(f.type==="html"||f.type==="svg")&&Je(u.current,n,o,g);const v=a.useRef(!1);a.useInsertionEffect(()=>{f&&v.current&&f.update(n,p)});const y=n[ie],P=a.useRef(!!y&&typeof window<"u"&&!window.MotionHandoffIsComplete?.(y)&&window.MotionHasOptimisedAnimation?.(y));return It(()=>{d.current=!0,f&&(v.current=!0,window.MotionIsMounted=!0,f.updateFeatures(),f.scheduleRenderMicrotask(),P.current&&f.animationState&&f.animationState.animateChanges())}),a.useEffect(()=>{f&&(!P.current&&f.animationState&&f.animationState.animateChanges(),P.current&&(queueMicrotask(()=>{window.MotionHandoffMarkAsComplete?.(y)}),P.current=!1),f.enteringChildren=void 0)}),f}function Je(e,t,n,s){const{layoutId:o,layout:i,drag:r,dragConstraints:l,layoutScroll:p,layoutRoot:h,layoutCrossfade:m}=t;e.projection=new n(e.latestValues,t["data-framer-portal-id"]?void 0:Ut(e.parent)),e.projection.setOptions({layoutId:o,layout:i,alwaysMeasureLayout:!!r||l&&A(l),visualElement:e,animationType:typeof i=="string"?i:"both",initialPromotionConfig:s,crossfade:m,layoutScroll:p,layoutRoot:h})}function Ut(e){if(e)return e.options.allowProjection!==!1?e.projection:Ut(e.parent)}function N(e,{forwardMotionProps:t=!1,type:n}={},s,o){s&&Re(s);const i=n?n==="svg":nt(e),r=i?Xe:_e;function l(h,m){let c;const u={...a.useContext(tt),...h,layoutId:Ze(h)},{isStatic:d}=u,f=Oe(h),g=r(h,d);if(!d&&typeof window<"u"){Qe();const v=tn(u);c=v.MeasureLayout,f.visualElement=Ke(e,g,u,o,v.ProjectionNode,i)}return M.jsxs(H.Provider,{value:f,children:[c&&f.visualElement?M.jsx(c,{visualElement:f.visualElement,...u}):null,Ne(e,h,qe(g,f.visualElement,m),g,d,t,i)]})}l.displayName=`motion.${typeof e=="string"?e:`create(${e.displayName??e.name??""})`}`;const p=a.forwardRef(l);return p[Ye]=e,p}function Ze({layoutId:e}){const t=a.useContext(Z).id;return t&&e!==void 0?t+"-"+e:e}function Qe(e,t){a.useContext(jt).strict}function tn(e){const t=Ft(),{drag:n,layout:s}=t;if(!n&&!s)return{};const o={...n,...s};return{MeasureLayout:n?.isEnabled(e)||s?.isEnabled(e)?o.MeasureLayout:void 0,ProjectionNode:o.ProjectionNode}}function en(e,t){if(typeof Proxy>"u")return N;const n=new Map,s=(i,r)=>N(i,r,e,t),o=(i,r)=>s(i,r);return new Proxy(o,{get:(i,r)=>r==="create"?s:(n.has(r)||n.set(r,N(r,void 0,e,t)),n.get(r))})}const nn=(e,t)=>t.isSVG??nt(e)?new re(t):new ae(t,{allowProjection:e!==a.Fragment});class sn extends D{constructor(t){super(t),t.animationState||(t.animationState=ue(t))}updateAnimationControlsSubscription(){const{animate:t}=this.node.getProps();bt(t)&&(this.unmountControls=t.subscribe(this.node))}mount(){this.updateAnimationControlsSubscription()}update(){const{animate:t}=this.node.getProps(),{animate:n}=this.node.prevProps||{};t!==n&&this.updateAnimationControlsSubscription()}unmount(){this.node.animationState.reset(),this.unmountControls?.()}}let on=0;class rn extends D{constructor(){super(...arguments),this.id=on++}update(){if(!this.node.presenceContext)return;const{isPresent:t,onExitComplete:n}=this.node.presenceContext,{isPresent:s}=this.node.prevPresenceContext||{};if(!this.node.animationState||t===s)return;const o=this.node.animationState.setActive("exit",!t);n&&!t&&o.then(()=>{n(this.id)})}mount(){const{register:t,onExitComplete:n}=this.node.presenceContext||{};n&&n(this.id),t&&(this.unmount=t(this.id))}unmount(){}}const an={animation:{Feature:sn},exit:{Feature:rn}};function R(e){return{point:{x:e.pageX,y:e.pageY}}}const un=e=>t=>At(t)&&e(t,R(t));function T(e,t,n,s){return F(e,t,un(n),s)}const Nt=({current:e})=>e?e.ownerDocument.defaultView:null,gt=(e,t)=>Math.abs(e-t);function ln(e,t){const n=gt(e.x,t.x),s=gt(e.y,t.y);return Math.sqrt(n**2+s**2)}const vt=new Set(["auto","scroll"]);class $t{constructor(t,n,{transformPagePoint:s,contextWindow:o=window,dragSnapToOrigin:i=!1,distanceThreshold:r=3,element:l}={}){if(this.startEvent=null,this.lastMoveEvent=null,this.lastMoveEventInfo=null,this.handlers={},this.contextWindow=window,this.scrollPositions=new Map,this.removeScrollListeners=null,this.onElementScroll=d=>{this.handleScroll(d.target)},this.onWindowScroll=()=>{this.handleScroll(window)},this.updatePoint=()=>{if(!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const d=z(this.lastMoveEventInfo,this.history),f=this.startEvent!==null,g=ln(d.offset,{x:0,y:0})>=this.distanceThreshold;if(!f&&!g)return;const{point:v}=d,{timestamp:y}=rt;this.history.push({...v,timestamp:y});const{onStart:P,onMove:w}=this.handlers;f||(P&&P(this.lastMoveEvent,d),this.startEvent=this.lastMoveEvent),w&&w(this.lastMoveEvent,d)},this.handlePointerMove=(d,f)=>{this.lastMoveEvent=d,this.lastMoveEventInfo=$(f,this.transformPagePoint),E.update(this.updatePoint,!0)},this.handlePointerUp=(d,f)=>{this.end();const{onEnd:g,onSessionEnd:v,resumeAnimation:y}=this.handlers;if((this.dragSnapToOrigin||!this.startEvent)&&y&&y(),!(this.lastMoveEvent&&this.lastMoveEventInfo))return;const P=z(d.type==="pointercancel"?this.lastMoveEventInfo:$(f,this.transformPagePoint),this.history);this.startEvent&&g&&g(d,P),v&&v(d,P)},!At(t))return;this.dragSnapToOrigin=i,this.handlers=n,this.transformPagePoint=s,this.distanceThreshold=r,this.contextWindow=o||window;const p=R(t),h=$(p,this.transformPagePoint),{point:m}=h,{timestamp:c}=rt;this.history=[{...m,timestamp:c}];const{onSessionStart:u}=n;u&&u(t,z(h,this.history)),this.removeListeners=Tt(T(this.contextWindow,"pointermove",this.handlePointerMove),T(this.contextWindow,"pointerup",this.handlePointerUp),T(this.contextWindow,"pointercancel",this.handlePointerUp)),l&&this.startScrollTracking(l)}startScrollTracking(t){let n=t.parentElement;for(;n;){const s=getComputedStyle(n);(vt.has(s.overflowX)||vt.has(s.overflowY))&&this.scrollPositions.set(n,{x:n.scrollLeft,y:n.scrollTop}),n=n.parentElement}this.scrollPositions.set(window,{x:window.scrollX,y:window.scrollY}),window.addEventListener("scroll",this.onElementScroll,{capture:!0}),window.addEventListener("scroll",this.onWindowScroll),this.removeScrollListeners=()=>{window.removeEventListener("scroll",this.onElementScroll,{capture:!0}),window.removeEventListener("scroll",this.onWindowScroll)}}handleScroll(t){const n=this.scrollPositions.get(t);if(!n)return;const s=t===window,o=s?{x:window.scrollX,y:window.scrollY}:{x:t.scrollLeft,y:t.scrollTop},i={x:o.x-n.x,y:o.y-n.y};i.x===0&&i.y===0||(s?this.lastMoveEventInfo&&(this.lastMoveEventInfo.point.x+=i.x,this.lastMoveEventInfo.point.y+=i.y):this.history.length>0&&(this.history[0].x-=i.x,this.history[0].y-=i.y),this.scrollPositions.set(t,o),E.update(this.updatePoint,!0))}updateHandlers(t){this.handlers=t}end(){this.removeListeners&&this.removeListeners(),this.removeScrollListeners&&this.removeScrollListeners(),this.scrollPositions.clear(),le(this.updatePoint)}}function $(e,t){return t?{point:t(e.point)}:e}function yt(e,t){return{x:e.x-t.x,y:e.y-t.y}}function z({point:e},t){return{point:e,delta:yt(e,zt(t)),offset:yt(e,cn(t)),velocity:fn(t,.1)}}function cn(e){return e[0]}function zt(e){return e[e.length-1]}function fn(e,t){if(e.length<2)return{x:0,y:0};let n=e.length-1,s=null;const o=zt(e);for(;n>=0&&(s=e[n],!(o.timestamp-s.timestamp>at(t)));)n--;if(!s)return{x:0,y:0};s===e[0]&&e.length>2&&o.timestamp-s.timestamp>at(t)*2&&(s=e[1]);const i=ce(o.timestamp-s.timestamp);if(i===0)return{x:0,y:0};const r={x:(o.x-s.x)/i,y:(o.y-s.y)/i};return r.x===1/0&&(r.x=0),r.y===1/0&&(r.y=0),r}function hn(e,{min:t,max:n},s){return t!==void 0&&e<t?e=s?O(t,e,s.min):Math.max(e,t):n!==void 0&&e>n&&(e=s?O(n,e,s.max):Math.min(e,n)),e}function Pt(e,t,n){return{min:t!==void 0?e.min+t:void 0,max:n!==void 0?e.max+n-(e.max-e.min):void 0}}function dn(e,{top:t,left:n,bottom:s,right:o}){return{x:Pt(e.x,n,o),y:Pt(e.y,t,s)}}function xt(e,t){let n=t.min-e.min,s=t.max-e.max;return t.max-t.min<e.max-e.min&&([n,s]=[s,n]),{min:n,max:s}}function mn(e,t){return{x:xt(e.x,t.x),y:xt(e.y,t.y)}}function pn(e,t){let n=.5;const s=q(e),o=q(t);return o>s?n=ut(t.min,t.max-s,e.min):s>o&&(n=ut(e.min,e.max-o,t.min)),fe(0,1,n)}function gn(e,t){const n={};return t.min!==void 0&&(n.min=t.min-e.min),t.max!==void 0&&(n.max=t.max-e.min),n}const K=.35;function vn(e=K){return e===!1?e=0:e===!0&&(e=K),{x:wt(e,"left","right"),y:wt(e,"top","bottom")}}function wt(e,t,n){return{min:Ct(e,t),max:Ct(e,n)}}function Ct(e,t){return typeof e=="number"?e:e[t]||0}const yn=new WeakMap;class Pn{constructor(t){this.openDragLock=null,this.isDragging=!1,this.currentDirection=null,this.originPoint={x:0,y:0},this.constraints=!1,this.hasMutatedConstraints=!1,this.elastic=he(),this.latestPointerEvent=null,this.latestPanInfo=null,this.visualElement=t}start(t,{snapToCursor:n=!1,distanceThreshold:s}={}){const{presenceContext:o}=this.visualElement;if(o&&o.isPresent===!1)return;const i=c=>{n&&this.snapToCursor(R(c).point),this.stopAnimation()},r=(c,u)=>{const{drag:d,dragPropagation:f,onDragStart:g}=this.getProps();if(d&&!f&&(this.openDragLock&&this.openDragLock(),this.openDragLock=ve(d),!this.openDragLock))return;this.latestPointerEvent=c,this.latestPanInfo=u,this.isDragging=!0,this.currentDirection=null,this.resolveConstraints(),this.visualElement.projection&&(this.visualElement.projection.isAnimationBlocked=!0,this.visualElement.projection.target=void 0),V(y=>{let P=this.getAxisMotionValue(y).get()||0;if(ye.test(P)){const{projection:w}=this.visualElement;if(w&&w.layout){const x=w.layout.layoutBox[y];x&&(P=q(x)*(parseFloat(P)/100))}}this.originPoint[y]=P}),g&&E.update(()=>g(c,u),!1,!0),lt(this.visualElement,"transform");const{animationState:v}=this.visualElement;v&&v.setActive("whileDrag",!0)},l=(c,u)=>{this.latestPointerEvent=c,this.latestPanInfo=u;const{dragPropagation:d,dragDirectionLock:f,onDirectionLock:g,onDrag:v}=this.getProps();if(!d&&!this.openDragLock)return;const{offset:y}=u;if(f&&this.currentDirection===null){this.currentDirection=wn(y),this.currentDirection!==null&&g&&g(this.currentDirection);return}this.updateAxis("x",u.point,y),this.updateAxis("y",u.point,y),this.visualElement.render(),v&&E.update(()=>v(c,u),!1,!0)},p=(c,u)=>{this.latestPointerEvent=c,this.latestPanInfo=u,this.stop(c,u),this.latestPointerEvent=null,this.latestPanInfo=null},h=()=>{const{dragSnapToOrigin:c}=this.getProps();(c||this.constraints)&&this.startAnimation({x:0,y:0})},{dragSnapToOrigin:m}=this.getProps();this.panSession=new $t(t,{onSessionStart:i,onStart:r,onMove:l,onSessionEnd:p,resumeAnimation:h},{transformPagePoint:this.visualElement.getTransformPagePoint(),dragSnapToOrigin:m,distanceThreshold:s,contextWindow:Nt(this.visualElement),element:this.visualElement.current})}stop(t,n){const s=t||this.latestPointerEvent,o=n||this.latestPanInfo,i=this.isDragging;if(this.cancel(),!i||!o||!s)return;const{velocity:r}=o;this.startAnimation(r);const{onDragEnd:l}=this.getProps();l&&E.postRender(()=>l(s,o))}cancel(){this.isDragging=!1;const{projection:t,animationState:n}=this.visualElement;t&&(t.isAnimationBlocked=!1),this.endPanSession();const{dragPropagation:s}=this.getProps();!s&&this.openDragLock&&(this.openDragLock(),this.openDragLock=null),n&&n.setActive("whileDrag",!1)}endPanSession(){this.panSession&&this.panSession.end(),this.panSession=void 0}updateAxis(t,n,s){const{drag:o}=this.getProps();if(!s||!k(t,o,this.currentDirection))return;const i=this.getAxisMotionValue(t);let r=this.originPoint[t]+s[t];this.constraints&&this.constraints[t]&&(r=hn(r,this.constraints[t],this.elastic[t])),i.set(r)}resolveConstraints(){const{dragConstraints:t,dragElastic:n}=this.getProps(),s=this.visualElement.projection&&!this.visualElement.projection.layout?this.visualElement.projection.measure(!1):this.visualElement.projection?.layout,o=this.constraints;t&&A(t)?this.constraints||(this.constraints=this.resolveRefConstraints()):t&&s?this.constraints=dn(s.layoutBox,t):this.constraints=!1,this.elastic=vn(n),o!==this.constraints&&!A(t)&&s&&this.constraints&&!this.hasMutatedConstraints&&V(i=>{this.constraints!==!1&&this.getAxisMotionValue(i)&&(this.constraints[i]=gn(s.layoutBox[i],this.constraints[i]))})}resolveRefConstraints(){const{dragConstraints:t,onMeasureDragConstraints:n}=this.getProps();if(!t||!A(t))return!1;const s=t.current,{projection:o}=this.visualElement;if(!o||!o.layout)return!1;const i=de(s,o.root,this.visualElement.getTransformPagePoint());let r=mn(o.layout.layoutBox,i);if(n){const l=n(me(r));this.hasMutatedConstraints=!!l,l&&(r=pe(l))}return r}startAnimation(t){const{drag:n,dragMomentum:s,dragElastic:o,dragTransition:i,dragSnapToOrigin:r,onDragTransitionEnd:l}=this.getProps(),p=this.constraints||{},h=V(m=>{if(!k(m,n,this.currentDirection))return;let c=p&&p[m]||{};r&&(c={min:0,max:0});const u=o?200:1e6,d=o?40:1e7,f={type:"inertia",velocity:s?t[m]:0,bounceStiffness:u,bounceDamping:d,timeConstant:750,restDelta:1,restSpeed:10,...i,...c};return this.startAxisValueAnimation(m,f)});return Promise.all(h).then(l)}startAxisValueAnimation(t,n){const s=this.getAxisMotionValue(t);return lt(this.visualElement,t),s.start(ge(t,s,0,n,this.visualElement,!1))}stopAnimation(){V(t=>this.getAxisMotionValue(t).stop())}getAxisMotionValue(t){const n=`_drag${t.toUpperCase()}`,s=this.visualElement.getProps(),o=s[n];return o||this.visualElement.getValue(t,(s.initial?s.initial[t]:void 0)||0)}snapToCursor(t){V(n=>{const{drag:s}=this.getProps();if(!k(n,s,this.currentDirection))return;const{projection:o}=this.visualElement,i=this.getAxisMotionValue(n);if(o&&o.layout){const{min:r,max:l}=o.layout.layoutBox[n],p=i.get()||0;i.set(t[n]-O(r,l,.5)+p)}})}scalePositionWithinConstraints(){if(!this.visualElement.current)return;const{drag:t,dragConstraints:n}=this.getProps(),{projection:s}=this.visualElement;if(!A(n)||!s||!this.constraints)return;this.stopAnimation();const o={x:0,y:0};V(r=>{const l=this.getAxisMotionValue(r);if(l&&this.constraints!==!1){const p=l.get();o[r]=pn({min:p,max:p},this.constraints[r])}});const{transformTemplate:i}=this.visualElement.getProps();this.visualElement.current.style.transform=i?i({},""):"none",s.root&&s.root.updateScroll(),s.updateLayout(),this.constraints=!1,this.resolveConstraints(),V(r=>{if(!k(r,t,null))return;const l=this.getAxisMotionValue(r),{min:p,max:h}=this.constraints[r];l.set(O(p,h,o[r]))}),this.visualElement.render()}addListeners(){if(!this.visualElement.current)return;yn.set(this.visualElement,this);const t=this.visualElement.current,n=T(t,"pointerdown",h=>{const{drag:m,dragListener:c=!0}=this.getProps(),u=h.target,d=u!==t&&Pe(u);m&&c&&!d&&this.start(h)});let s;const o=()=>{const{dragConstraints:h}=this.getProps();A(h)&&h.current&&(this.constraints=this.resolveRefConstraints(),s||(s=xn(t,h.current,()=>this.scalePositionWithinConstraints())))},{projection:i}=this.visualElement,r=i.addEventListener("measure",o);i&&!i.layout&&(i.root&&i.root.updateScroll(),i.updateLayout()),E.read(o);const l=F(window,"resize",()=>this.scalePositionWithinConstraints()),p=i.addEventListener("didUpdate",(({delta:h,hasLayoutChanged:m})=>{this.isDragging&&m&&(V(c=>{const u=this.getAxisMotionValue(c);u&&(this.originPoint[c]+=h[c].translate,u.set(u.get()+h[c].translate))}),this.visualElement.render())}));return()=>{l(),n(),r(),p&&p(),s&&s()}}getProps(){const t=this.visualElement.getProps(),{drag:n=!1,dragDirectionLock:s=!1,dragPropagation:o=!1,dragConstraints:i=!1,dragElastic:r=K,dragMomentum:l=!0}=t;return{...t,drag:n,dragDirectionLock:s,dragPropagation:o,dragConstraints:i,dragElastic:r,dragMomentum:l}}}function Et(e){let t=!0;return()=>{if(t){t=!1;return}e()}}function xn(e,t,n){const s=ct(e,Et(n)),o=ct(t,Et(n));return()=>{s(),o()}}function k(e,t,n){return(t===!0||t===e)&&(n===null||n===e)}function wn(e,t=10){let n=null;return Math.abs(e.y)>t?n="y":Math.abs(e.x)>t&&(n="x"),n}class Cn extends D{constructor(t){super(t),this.removeGroupControls=j,this.removeListeners=j,this.controls=new Pn(t)}mount(){const{dragControls:t}=this.node.getProps();t&&(this.removeGroupControls=t.subscribe(this.controls)),this.removeListeners=this.controls.addListeners()||j}update(){const{dragControls:t}=this.node.getProps(),{dragControls:n}=this.node.prevProps||{};t!==n&&(this.removeGroupControls(),t&&(this.removeGroupControls=t.subscribe(this.controls)))}unmount(){this.removeGroupControls(),this.removeListeners(),this.controls.isDragging||this.controls.endPanSession()}}const _=e=>(t,n)=>{e&&E.update(()=>e(t,n),!1,!0)};class En extends D{constructor(){super(...arguments),this.removePointerDownListener=j}onPointerDown(t){this.session=new $t(t,this.createPanHandlers(),{transformPagePoint:this.node.getTransformPagePoint(),contextWindow:Nt(this.node)})}createPanHandlers(){const{onPanSessionStart:t,onPanStart:n,onPan:s,onPanEnd:o}=this.node.getProps();return{onSessionStart:_(t),onStart:_(n),onMove:_(s),onEnd:(i,r)=>{delete this.session,o&&E.postRender(()=>o(i,r))}}}mount(){this.removePointerDownListener=T(this.node.current,"pointerdown",t=>this.onPointerDown(t))}update(){this.session&&this.session.updateHandlers(this.createPanHandlers())}unmount(){this.removePointerDownListener(),this.session&&this.session.end()}}let X=!1;class Sn extends a.Component{componentDidMount(){const{visualElement:t,layoutGroup:n,switchLayoutGroup:s,layoutId:o}=this.props,{projection:i}=t;i&&(n.group&&n.group.add(i),s&&s.register&&o&&s.register(i),X&&i.root.didUpdate(),i.addEventListener("animationComplete",()=>{this.safeToRemove()}),i.setOptions({...i.options,layoutDependency:this.props.layoutDependency,onExitComplete:()=>this.safeToRemove()})),we.hasEverUpdated=!0}getSnapshotBeforeUpdate(t){const{layoutDependency:n,visualElement:s,drag:o,isPresent:i}=this.props,{projection:r}=s;return r&&(r.isPresent=i,t.layoutDependency!==n&&r.setOptions({...r.options,layoutDependency:n}),X=!0,o||t.layoutDependency!==n||n===void 0||t.isPresent!==i?r.willUpdate():this.safeToRemove(),t.isPresent!==i&&(i?r.promote():r.relegate()||E.postRender(()=>{const l=r.getStack();(!l||!l.members.length)&&this.safeToRemove()}))),null}componentDidUpdate(){const{projection:t}=this.props.visualElement;t&&(t.root.didUpdate(),xe.postRender(()=>{!t.currentAnimation&&t.isLead()&&this.safeToRemove()}))}componentWillUnmount(){const{visualElement:t,layoutGroup:n,switchLayoutGroup:s}=this.props,{projection:o}=t;X=!0,o&&(o.scheduleCheckAfterUnmount(),n&&n.group&&n.group.remove(o),s&&s.deregister&&s.deregister(o))}safeToRemove(){const{safeToRemove:t}=this.props;t&&t()}render(){return null}}function _t(e){const[t,n]=kt(),s=a.useContext(Z);return M.jsx(Sn,{...e,layoutGroup:s,switchLayoutGroup:a.useContext(Bt),isPresent:t,safeToRemove:n})}const Mn={pan:{Feature:En},drag:{Feature:Cn,ProjectionNode:Rt,MeasureLayout:_t}};function St(e,t,n){const{props:s}=e;e.animationState&&s.whileHover&&e.animationState.setActive("whileHover",n==="Start");const o="onHover"+n,i=s[o];i&&E.postRender(()=>i(t,R(t)))}class Vn extends D{mount(){const{current:t}=this.node;t&&(this.unmount=Ce(t,(n,s)=>(St(this.node,s,"Start"),o=>St(this.node,o,"End"))))}unmount(){}}class Dn extends D{constructor(){super(...arguments),this.isActive=!1}onFocus(){let t=!1;try{t=this.node.current.matches(":focus-visible")}catch{t=!0}!t||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!0),this.isActive=!0)}onBlur(){!this.isActive||!this.node.animationState||(this.node.animationState.setActive("whileFocus",!1),this.isActive=!1)}mount(){this.unmount=Tt(F(this.node.current,"focus",()=>this.onFocus()),F(this.node.current,"blur",()=>this.onBlur()))}unmount(){}}function Mt(e,t,n){const{props:s}=e;if(e.current instanceof HTMLButtonElement&&e.current.disabled)return;e.animationState&&s.whileTap&&e.animationState.setActive("whileTap",n==="Start");const o="onTap"+(n==="End"?"":n),i=s[o];i&&E.postRender(()=>i(t,R(t)))}class Ln extends D{mount(){const{current:t}=this.node;if(!t)return;const{globalTapTarget:n,propagate:s}=this.node.props;this.unmount=Ee(t,(o,i)=>(Mt(this.node,i,"Start"),(r,{success:l})=>Mt(this.node,r,l?"End":"Cancel")),{useGlobalTarget:n,stopPropagation:s?.tap===!1})}unmount(){}}const J=new WeakMap,Y=new WeakMap,bn=e=>{const t=J.get(e.target);t&&t(e)},An=e=>{e.forEach(bn)};function Tn({root:e,...t}){const n=e||document;Y.has(n)||Y.set(n,{});const s=Y.get(n),o=JSON.stringify(t);return s[o]||(s[o]=new IntersectionObserver(An,{root:e,...t})),s[o]}function Rn(e,t,n){const s=Tn(t);return J.set(e,n),s.observe(e),()=>{J.delete(e),s.unobserve(e)}}const In={some:0,all:1};class kn extends D{constructor(){super(...arguments),this.hasEnteredView=!1,this.isInView=!1}startObserver(){this.unmount();const{viewport:t={}}=this.node.getProps(),{root:n,margin:s,amount:o="some",once:i}=t,r={root:n?n.current:void 0,rootMargin:s,threshold:typeof o=="number"?o:In[o]},l=p=>{const{isIntersecting:h}=p;if(this.isInView===h||(this.isInView=h,i&&!h&&this.hasEnteredView))return;h&&(this.hasEnteredView=!0),this.node.animationState&&this.node.animationState.setActive("whileInView",h);const{onViewportEnter:m,onViewportLeave:c}=this.node.getProps(),u=h?m:c;u&&u(p)};return Rn(this.node.current,r,l)}mount(){this.startObserver()}update(){if(typeof IntersectionObserver>"u")return;const{props:t,prevProps:n}=this.node;["amount","margin","root"].some(jn(t,n))&&this.startObserver()}unmount(){}}function jn({viewport:e={}},{viewport:t={}}={}){return n=>e[n]!==t[n]}const Fn={inView:{Feature:kn},tap:{Feature:Ln},focus:{Feature:Dn},hover:{Feature:Vn}},On={layout:{ProjectionNode:Rt,MeasureLayout:_t}},Wn={...an,...Fn,...Mn,...On},Bn=en(Wn,nn);export{Hn as A,Bn as m};