first commit
This commit is contained in:
+2
@@ -0,0 +1,2 @@
|
||||
"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 <FiberProvider />!");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
|
||||
+1
File diff suppressed because one or more lines are too long
+93
@@ -0,0 +1,93 @@
|
||||
import React from 'react';
|
||||
import type ReactReconciler from 'react-reconciler';
|
||||
/**
|
||||
* Represents a react-internal Fiber node.
|
||||
*/
|
||||
export type Fiber<T = any> = Omit<ReactReconciler.Fiber, 'stateNode'> & {
|
||||
stateNode: T;
|
||||
};
|
||||
/**
|
||||
* Represents a {@link Fiber} node selector for traversal.
|
||||
*/
|
||||
export type FiberSelector<T = any> = (
|
||||
/** The current {@link Fiber} node. */
|
||||
node: Fiber<T | null>) => boolean | void;
|
||||
/**
|
||||
* Traverses up or down a {@link Fiber}, return `true` to stop and select a node.
|
||||
*/
|
||||
export declare function traverseFiber<T = any>(
|
||||
/** Input {@link Fiber} to traverse. */
|
||||
fiber: Fiber | undefined,
|
||||
/** Whether to ascend and walk up the tree. Will walk down if `false`. */
|
||||
ascending: boolean,
|
||||
/** A {@link Fiber} node selector, returns the first match when `true` is passed. */
|
||||
selector: FiberSelector<T>): Fiber<T> | undefined;
|
||||
/**
|
||||
* A react-internal {@link Fiber} provider. This component binds React children to the React Fiber tree. Call its-fine hooks within this.
|
||||
*/
|
||||
export declare class FiberProvider extends React.Component<{
|
||||
children?: React.ReactNode;
|
||||
}> {
|
||||
private _reactInternals;
|
||||
render(): React.JSX.Element;
|
||||
}
|
||||
/**
|
||||
* Returns the current react-internal {@link Fiber}. This is an implementation detail of [react-reconciler](https://github.com/facebook/react/tree/main/packages/react-reconciler).
|
||||
*/
|
||||
export declare function useFiber(): Fiber<null> | undefined;
|
||||
/**
|
||||
* Represents a react-reconciler container instance.
|
||||
*/
|
||||
export interface ContainerInstance<T = any> {
|
||||
containerInfo: T;
|
||||
}
|
||||
/**
|
||||
* Returns the current react-reconciler container info passed to {@link ReactReconciler.Reconciler.createContainer}.
|
||||
*
|
||||
* In react-dom, a container will point to the root DOM element; in react-three-fiber, it will point to the root Zustand store.
|
||||
*/
|
||||
export declare function useContainer<T = any>(): T | undefined;
|
||||
/**
|
||||
* Returns the nearest react-reconciler child instance or the node created from {@link ReactReconciler.HostConfig.createInstance}.
|
||||
*
|
||||
* In react-dom, this would be a DOM element; in react-three-fiber this would be an instance descriptor.
|
||||
*/
|
||||
export declare function useNearestChild<T = any>(
|
||||
/** An optional element type to filter to. */
|
||||
type?: keyof React.JSX.IntrinsicElements): React.RefObject<T | undefined>;
|
||||
/**
|
||||
* Returns the nearest react-reconciler parent instance or the node created from {@link ReactReconciler.HostConfig.createInstance}.
|
||||
*
|
||||
* In react-dom, this would be a DOM element; in react-three-fiber this would be an instance descriptor.
|
||||
*/
|
||||
export declare function useNearestParent<T = any>(
|
||||
/** An optional element type to filter to. */
|
||||
type?: keyof React.JSX.IntrinsicElements): React.RefObject<T | undefined>;
|
||||
export type ContextMap = Map<React.Context<any>, any> & {
|
||||
get<T>(context: React.Context<T>): T | undefined;
|
||||
};
|
||||
/**
|
||||
* Returns a map of all contexts and their values.
|
||||
*/
|
||||
export declare function useContextMap(): ContextMap;
|
||||
/**
|
||||
* Represents a react-context bridge provider component.
|
||||
*/
|
||||
export type ContextBridge = React.FC<React.PropsWithChildren<{}>>;
|
||||
/**
|
||||
* React Context currently cannot be shared across [React renderers](https://reactjs.org/docs/codebase-overview.html#renderers) but explicitly forwarded between providers (see [react#17275](https://github.com/facebook/react/issues/17275)). This hook returns a {@link ContextBridge} of live context providers to pierce Context across renderers.
|
||||
*
|
||||
* Pass {@link ContextBridge} as a component to a secondary renderer to enable context-sharing within its children.
|
||||
*/
|
||||
export declare function useContextBridge(): ContextBridge;
|
||||
/** A component that forwards ancestor Activity visibility into another React root. */
|
||||
export type ActivityBridge = React.FC<React.PropsWithChildren<{}>>;
|
||||
/**
|
||||
* Forwards ancestor Activity visibility into another root. Requires React 19.2+,
|
||||
* an Activity capable destination renderer, and a {@link FiberProvider}.
|
||||
*
|
||||
* Suspense does not hide the destination. While Suspense hides the source,
|
||||
* visibility is sampled once per frame and changes between samples can be missed.
|
||||
* Source deletion hides the destination without unmounting its root.
|
||||
*/
|
||||
export declare function useActivityBridge(): ActivityBridge;
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
import r from "react";
|
||||
const v = /* @__PURE__ */ (() => {
|
||||
var e, t;
|
||||
return typeof window != "undefined" && (((e = window.document) == null ? void 0 : e.createElement) || ((t = window.navigator) == null ? void 0 : t.product) === "ReactNative");
|
||||
})() ? r.useLayoutEffect : r.useEffect;
|
||||
function l(e, t, i) {
|
||||
if (!e) return;
|
||||
if (i(e) === !0) return e;
|
||||
let n = t ? e.return : e.child;
|
||||
for (; n; ) {
|
||||
const o = l(n, t, i);
|
||||
if (o) return o;
|
||||
n = t ? null : n.sibling;
|
||||
}
|
||||
}
|
||||
function b(e) {
|
||||
try {
|
||||
return Object.defineProperties(e, {
|
||||
_currentRenderer: {
|
||||
get() {
|
||||
return null;
|
||||
},
|
||||
set() {
|
||||
}
|
||||
},
|
||||
_currentRenderer2: {
|
||||
get() {
|
||||
return null;
|
||||
},
|
||||
set() {
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (t) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
const p = /* @__PURE__ */ b(/* @__PURE__ */ r.createContext(null));
|
||||
class h extends r.Component {
|
||||
render() {
|
||||
return /* @__PURE__ */ r.createElement(p.Provider, { value: this._reactInternals }, this.props.children);
|
||||
}
|
||||
}
|
||||
function m() {
|
||||
const e = r.useContext(p);
|
||||
if (e === null) throw new Error("its-fine: useFiber must be called within a <FiberProvider />!");
|
||||
const t = r.useId();
|
||||
return r.useMemo(() => {
|
||||
for (const n of [e, e == null ? void 0 : e.alternate]) {
|
||||
if (!n) continue;
|
||||
const o = l(n, !1, (d) => {
|
||||
let s = d.memoizedState;
|
||||
for (; s; ) {
|
||||
if (s.memoizedState === t) return !0;
|
||||
s = s.next;
|
||||
}
|
||||
});
|
||||
if (o) return o;
|
||||
}
|
||||
}, [e, t]);
|
||||
}
|
||||
function C() {
|
||||
const e = m(), t = r.useMemo(
|
||||
() => l(e, !0, (i) => {
|
||||
var n;
|
||||
return ((n = i.stateNode) == null ? void 0 : n.containerInfo) != null;
|
||||
}),
|
||||
[e]
|
||||
);
|
||||
return t == null ? void 0 : t.stateNode.containerInfo;
|
||||
}
|
||||
function F(e) {
|
||||
const t = m(), i = r.useRef(void 0);
|
||||
return v(() => {
|
||||
var n;
|
||||
i.current = (n = l(
|
||||
t,
|
||||
!1,
|
||||
(o) => typeof o.type == "string" && (e === void 0 || o.type === e)
|
||||
)) == null ? void 0 : n.stateNode;
|
||||
}, [t]), i;
|
||||
}
|
||||
function R(e) {
|
||||
const t = m(), i = r.useRef(void 0);
|
||||
return v(() => {
|
||||
var n;
|
||||
i.current = (n = l(
|
||||
t,
|
||||
!0,
|
||||
(o) => typeof o.type == "string" && (e === void 0 || o.type === e)
|
||||
)) == null ? void 0 : n.stateNode;
|
||||
}, [t]), i;
|
||||
}
|
||||
const w = Symbol.for("react.context"), E = (e) => e !== null && typeof e == "object" && "$$typeof" in e && e.$$typeof === w;
|
||||
function g() {
|
||||
const e = m(), [t] = r.useState(() => /* @__PURE__ */ new Map());
|
||||
t.clear();
|
||||
let i = e;
|
||||
for (; i; ) {
|
||||
const n = i.type;
|
||||
E(n) && n !== p && !t.has(n) && t.set(n, r.use(b(n))), i = i.return;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
function M() {
|
||||
const e = g();
|
||||
return r.useMemo(
|
||||
() => Array.from(e.keys()).reduce(
|
||||
(t, i) => (n) => /* @__PURE__ */ r.createElement(t, null, /* @__PURE__ */ r.createElement(i.Provider, { ...n, value: e.get(i) })),
|
||||
(t) => /* @__PURE__ */ r.createElement(h, { ...t })
|
||||
),
|
||||
[e]
|
||||
);
|
||||
}
|
||||
function x(e) {
|
||||
if (typeof requestAnimationFrame == "function") {
|
||||
const i = requestAnimationFrame(e);
|
||||
return () => cancelAnimationFrame(i);
|
||||
}
|
||||
const t = setTimeout(e, 16);
|
||||
return () => clearTimeout(t);
|
||||
}
|
||||
function N() {
|
||||
if (!r.Activity) throw new Error("its-fine: useActivityBridge requires React 19.2 or later!");
|
||||
const e = m(), [t] = r.useState(() => {
|
||||
const i = [];
|
||||
let n = !1;
|
||||
l(e, !0, (u) => {
|
||||
var c, a;
|
||||
if (u.elementType === r.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 && ((a = u.return) == null ? void 0 : a.elementType) !== r.Activity && (n = !0);
|
||||
});
|
||||
let o = "hidden";
|
||||
const d = /* @__PURE__ */ new Set();
|
||||
let s;
|
||||
const f = {
|
||||
mounted: !1,
|
||||
connected: !1,
|
||||
subscribe(u) {
|
||||
return d.add(u), () => {
|
||||
d.delete(u);
|
||||
};
|
||||
},
|
||||
sync(u) {
|
||||
f.mounted && !f.connected && n && i.length > 0 ? s || (s = x(() => {
|
||||
s = void 0, f.sync(!0);
|
||||
})) : (s == null || s(), s = void 0);
|
||||
let c = o;
|
||||
if (f.mounted ? f.connected ? c = "visible" : u && (c = i.every((a) => (a._visibility & 1) !== 0) ? "visible" : "hidden") : c = "hidden", o !== c) {
|
||||
o = c;
|
||||
for (const a of d) a();
|
||||
}
|
||||
},
|
||||
Bridge({ children: u }) {
|
||||
return /* @__PURE__ */ r.createElement(
|
||||
r.Activity,
|
||||
{
|
||||
mode: r.useSyncExternalStore(
|
||||
f.subscribe,
|
||||
() => o,
|
||||
() => "hidden"
|
||||
)
|
||||
},
|
||||
u
|
||||
);
|
||||
}
|
||||
};
|
||||
return f;
|
||||
});
|
||||
return r.useInsertionEffect(() => (t.mounted = !0, queueMicrotask(() => t.sync(!1)), () => {
|
||||
t.mounted = !1, queueMicrotask(() => t.sync(!1));
|
||||
}), [t]), r.useLayoutEffect(() => (t.connected = !0, t.sync(!1), () => {
|
||||
t.connected = !1, t.sync(!0);
|
||||
}), [t]), t.Bridge;
|
||||
}
|
||||
export {
|
||||
h as FiberProvider,
|
||||
l as traverseFiber,
|
||||
N as useActivityBridge,
|
||||
C as useContainer,
|
||||
M as useContextBridge,
|
||||
g as useContextMap,
|
||||
m as useFiber,
|
||||
F as useNearestChild,
|
||||
R as useNearestParent
|
||||
};
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user