"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const React = require("react"); function _interopNamespace(e) { if (e && e.__esModule) return e; const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); if (e) { for (const k in e) { if (k !== "default") { const d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: () => e[k] }); } } } n.default = e; return Object.freeze(n); } const React__namespace = /* @__PURE__ */ _interopNamespace(React); var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var _a; function traverseFiber(fiber, ascending, selector) { if (!fiber) return; if (selector(fiber) === true) return fiber; let child = ascending ? fiber.return : fiber.child; while (child) { const match = traverseFiber(child, ascending, selector); if (match) return match; child = ascending ? null : child.sibling; } } function wrapContext(context) { try { return Object.defineProperties(context, { _currentRenderer: { get() { return null; }, set() { } }, _currentRenderer2: { get() { return null; }, set() { } } }); } catch (_) { return context; } } const FiberContext = wrapContext(React__namespace.createContext(null)); class FiberProvider extends React__namespace.Component { render() { return /* @__PURE__ */ React__namespace.createElement(FiberContext.Provider, { value: this._reactInternals }, this.props.children); } } const { ReactCurrentOwner, ReactCurrentDispatcher } = (_a = React__namespace.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) != null ? _a : {}; function useFiber() { const root = React__namespace.useContext(FiberContext); if (!root) throw new Error("No FiberProvider found. Call useFiber() within a FiberProvider."); const id = React__namespace.useId(); const fiber = React__namespace.useMemo( () => { var _a2; return (_a2 = ReactCurrentOwner == null ? void 0 : ReactCurrentOwner.current) != null ? _a2 : traverseFiber(root, false, (node) => { let state = node.memoizedState; while (state) { if (state.memoizedState === id) return true; state = state.next; } }); }, [root, id] ); return fiber; } function useContainer() { const fiber = useFiber(); const root = React__namespace.useMemo( () => traverseFiber(fiber, true, (node) => { var _a2; return ((_a2 = node.stateNode) == null ? void 0 : _a2.containerInfo) != null; }), [fiber] ); return root == null ? void 0 : root.stateNode.containerInfo; } function useNearestChild(type) { const fiber = useFiber(); const childRef = React__namespace.useRef(); React__namespace.useLayoutEffect(() => { var _a2; childRef.current = (_a2 = traverseFiber( fiber, false, (node) => typeof node.type === "string" && (type === void 0 || node.type === type) )) == null ? void 0 : _a2.stateNode; }, [fiber]); return childRef; } function useNearestParent(type) { const fiber = useFiber(); const parentRef = React__namespace.useRef(); React__namespace.useLayoutEffect(() => { var _a2; parentRef.current = (_a2 = traverseFiber( fiber, true, (node) => typeof node.type === "string" && (type === void 0 || node.type === type) )) == null ? void 0 : _a2.stateNode; }, [fiber]); return parentRef; } function useAllContexts() { var _a2, _b; const fiber = useFiber(); const [contexts] = React__namespace.useState(() => /* @__PURE__ */ new Map()); contexts.clear(); let node = fiber; while (node) { const context = (_a2 = node.type) == null ? void 0 : _a2._context; if (context && context !== FiberContext && !contexts.has(context)) { contexts.set(context, (_b = ReactCurrentDispatcher == null ? void 0 : ReactCurrentDispatcher.current) == null ? void 0 : _b.readContext(wrapContext(context))); } node = node.return; } return contexts; } function useContextBridge() { const contexts = useAllContexts(); return React__namespace.useMemo( () => Array.from(contexts.keys()).reduce( (Prev, context) => (props) => /* @__PURE__ */ React__namespace.createElement(Prev, null, /* @__PURE__ */ React__namespace.createElement(context.Provider, __spreadProps(__spreadValues({}, props), { value: contexts.get(context) }))), (props) => /* @__PURE__ */ React__namespace.createElement(FiberProvider, __spreadValues({}, props)) ), [contexts] ); } exports.FiberProvider = FiberProvider; exports.traverseFiber = traverseFiber; exports.useAllContexts = useAllContexts; exports.useContainer = useContainer; exports.useContextBridge = useContextBridge; exports.useFiber = useFiber; exports.useNearestChild = useNearestChild; exports.useNearestParent = useNearestParent; //# sourceMappingURL=index.cjs.map