"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),v=(()=>{var e,t;return typeof window!="undefined"&&(((e=window.document)==null?void 0:e.createElement)||((t=window.navigator)==null?void 0:t.product)==="ReactNative")})()?n.useLayoutEffect:n.useEffect;function f(e,t,i){if(!e)return;if(i(e)===!0)return e;let r=t?e.return:e.child;for(;r;){const s=f(r,t,i);if(s)return s;r=t?null:r.sibling}}function p(e){try{return Object.defineProperties(e,{_currentRenderer:{get(){return null},set(){}},_currentRenderer2:{get(){return null},set(){}}})}catch(t){return e}}const b=p(n.createContext(null));class h extends n.Component{render(){return n.createElement(b.Provider,{value:this._reactInternals},this.props.children)}}function d(){const e=n.useContext(b);if(e===null)throw new Error("its-fine: useFiber must be called within a !");const t=n.useId();return n.useMemo(()=>{for(const r of[e,e==null?void 0:e.alternate]){if(!r)continue;const s=f(r,!1,m=>{let o=m.memoizedState;for(;o;){if(o.memoizedState===t)return!0;o=o.next}});if(s)return s}},[e,t])}function g(){const e=d(),t=n.useMemo(()=>f(e,!0,i=>{var r;return((r=i.stateNode)==null?void 0:r.containerInfo)!=null}),[e]);return t==null?void 0:t.stateNode.containerInfo}function E(e){const t=d(),i=n.useRef(void 0);return v(()=>{var r;i.current=(r=f(t,!1,s=>typeof s.type=="string"&&(e===void 0||s.type===e)))==null?void 0:r.stateNode},[t]),i}function C(e){const t=d(),i=n.useRef(void 0);return v(()=>{var r;i.current=(r=f(t,!0,s=>typeof s.type=="string"&&(e===void 0||s.type===e)))==null?void 0:r.stateNode},[t]),i}const x=Symbol.for("react.context"),F=e=>e!==null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===x;function w(){const e=d(),[t]=n.useState(()=>new Map);t.clear();let i=e;for(;i;){const r=i.type;F(r)&&r!==b&&!t.has(r)&&t.set(r,n.use(p(r))),i=i.return}return t}function A(){const e=w();return n.useMemo(()=>Array.from(e.keys()).reduce((t,i)=>r=>n.createElement(t,null,n.createElement(i.Provider,{...r,value:e.get(i)})),t=>n.createElement(h,{...t})),[e])}function M(e){if(typeof requestAnimationFrame=="function"){const i=requestAnimationFrame(e);return()=>cancelAnimationFrame(i)}const t=setTimeout(e,16);return()=>clearTimeout(t)}function N(){if(!n.Activity)throw new Error("its-fine: useActivityBridge requires React 19.2 or later!");const e=d(),[t]=n.useState(()=>{const i=[];let r=!1;f(e,!0,u=>{var c,l;if(u.elementType===n.Activity){const y=((c=u.child)==null?void 0:c.tag)===22?u.child.stateNode:null;if(typeof(y==null?void 0:y._visibility)!="number")throw new Error("its-fine: unsupported React Activity internals!");i.push(y)}else u.tag===22&&((l=u.return)==null?void 0:l.elementType)!==n.Activity&&(r=!0)});let s="hidden";const m=new Set;let o;const a={mounted:!1,connected:!1,subscribe(u){return m.add(u),()=>{m.delete(u)}},sync(u){a.mounted&&!a.connected&&r&&i.length>0?o||(o=M(()=>{o=void 0,a.sync(!0)})):(o==null||o(),o=void 0);let c=s;if(a.mounted?a.connected?c="visible":u&&(c=i.every(l=>(l._visibility&1)!==0)?"visible":"hidden"):c="hidden",s!==c){s=c;for(const l of m)l()}},Bridge({children:u}){return n.createElement(n.Activity,{mode:n.useSyncExternalStore(a.subscribe,()=>s,()=>"hidden")},u)}};return a});return n.useInsertionEffect(()=>(t.mounted=!0,queueMicrotask(()=>t.sync(!1)),()=>{t.mounted=!1,queueMicrotask(()=>t.sync(!1))}),[t]),n.useLayoutEffect(()=>(t.connected=!0,t.sync(!1),()=>{t.connected=!1,t.sync(!0)}),[t]),t.Bridge}exports.FiberProvider=h;exports.traverseFiber=f;exports.useActivityBridge=N;exports.useContainer=g;exports.useContextBridge=A;exports.useContextMap=w;exports.useFiber=d;exports.useNearestChild=E;exports.useNearestParent=C; //# sourceMappingURL=index.cjs.map