{"name":"its-fine","version":"0.0.0","description":"it's fine","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["react","hacks"],"author":"","license":"MIT","gitHead":"361932b2a60c893c2e11e50e227c57fd01632144","_id":"its-fine@0.0.0","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-ylwXY4n0Rr6FPqDPASHlZMmgVGIQWMhf5VHgBEXOCFSqsXs5lgDMvRK+zwfgfebyt7RQpsx/aEePkvwnCrNyKA==","shasum":"489b70fc400976a03485ae9dea914c71564b7b86","tarball":"http://registry-npm.ywwl.com/its-fine/download/its-fine-0.0.0.tgz","fileCount":1,"unpackedSize":259,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC9kFNKP/mJPbNL6exBzHsxPMn25brq51v+moVqvLqQtAiBi4cR3keXI/eo92z1hx5bicyvstsFZIN8lvLD41m8DGA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjFF7KACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpV0w//bXjxrgI0VtWdwnbDBK9dH2dfYSFbYumQ4oTgLjYgcoF4b8SK\r\ngap335OmzYCpVsw4eTzncH67V4Qwhe8pDOazEO2wseV+LitrqHh9LQkZ69R2\r\nHB1X8sOGPZySvHecbsQcHZtRA3sc+tRyvh651hdEOaW4vejzWayfF5kXACZZ\r\nSv8k8ver5FCPCgtm1zmfK/96J8j/O7zk5YsfcHx602bt+ln6T/hCphPdtKpW\r\nlpPV9PC7pmrg8E2Qisi9qS3XNsExOeiW3wWWsCLos2A8QiVZLBuKR1NUXXss\r\n6fjT6wOCtMF1VCKq4XnGoKPfl+9C8V5r4y3lfVF4JlpYDMMbyMh34VevUfK4\r\nndsX2QAgSvrsjDiBkYy4JWts9VjbTBo4wM4VGbAe/oGEbNxNipEYW1Y+e9os\r\ns8CKhVopXKHyZ54TUqFqKlZEAJhTZj03oemERwrYX3Y//rAH/R8XBXmkY5Ln\r\ni/kOHnhFTLsq4MqVuIjlBuP9ky45Pq1GTj2gei0nQFeB7xpkL5KmyDKHaYcU\r\n6Uv70b5JFFLTXhbP8VYhJT0nYDZqkKvgSnSXwrVPzw2doUgIvXMN5rlpY/TA\r\n3KB7KEnE/MqPmENMZZY4pUepD4C9FwqaQdkiPbnxONnEfCbKZEWs6aXcQWZh\r\n226JFqeX0Mum2i5nWDxVN0ZLt40stWY2DSQ=\r\n=VgKw\r\n-----END PGP SIGNATURE-----\r\n","size":264,"noattachment":false,"key":"/its-fine/-/its-fine-0.0.0.tgz"},"_npmUser":{"name":"drcmda","email":"drcmda@gmail.com"},"directories":{},"maintainers":[{"name":"drcmda","email":"drcmda@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/its-fine_0.0.0_1662279370414_0.899232776640942"},"_hasShrinkwrap":false,"readme":"# its-fine\n\n[![Size](https://img.shields.io/bundlephobia/minzip/its-fine?label=gzip&style=flat&colorA=000000&colorB=000000)](https://bundlephobia.com/package/its-fine)\n[![Version](https://img.shields.io/npm/v/its-fine?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/its-fine)\n[![Downloads](https://img.shields.io/npm/dt/its-fine.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/its-fine)\n[![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/pmndrs)\n[![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/poimandres)\n\n<p align=\"left\">\n  <a id=\"cover\" href=\"#cover\">\n    <img src=\".github/itsfine.jpg\" alt=\"It's gonna be alright\" />\n  </a>\n</p>\n\nA collection of escape hatches for React.\n\nAs such, you can go beyond React's component abstraction; components are self-aware and can tap into the [React Fiber](https://youtu.be/ZCuYPiUIONs) tree. This enables powerful abstractions that can modify or extend React behavior without explicitly taking reconciliation into your own hands.\n\n## Table of Contents\n\n- [Components](#components)\n  - [FiberProvider](#fiberprovider)\n- [Hooks](#hooks)\n  - [useFiber](#useFiber)\n  - [useContainer](#useContainer)\n  - [useNearestChild](#useNearestChild)\n  - [useNearestParent](#useNearestParent)\n  - [useContextMap](#useContextMap)\n  - [useContextBridge](#useContextBridge)\n- [Utils](#utils)\n  - [traverseFiber](#traverseFiber)\n\n## Components\n\n### FiberProvider\n\nA react-internal `Fiber` provider. This component binds React children to the React Fiber tree. Call its-fine hooks within this.\n\n> **Note**: pmndrs renderers like react-three-fiber implement this internally to make use of [`useContextBridge`](#usecontextbridge), so you would only need this when using hooks inside of `react-dom` or `react-native`.\n\n```tsx\nimport * as ReactDOM from 'react-dom/client'\nimport { FiberProvider, useFiber } from 'its-fine'\n\nfunction App() {\n  const fiber = useFiber()\n}\n\nReactDOM.createRoot(document.getElementById('root')!).render(\n  <FiberProvider>\n    <App />\n  </FiberProvider>,\n)\n```\n\n## Hooks\n\nUseful React hook abstractions for manipulating and querying from a component. These must be called within a [`FiberProvider`](#fiberprovider) component.\n\n### useFiber\n\nReturns the current react-internal `Fiber`. This is an implementation detail of [react-reconciler](https://github.com/facebook/react/tree/main/packages/react-reconciler).\n\n```tsx\nimport * as React from 'react'\nimport { type Fiber, useFiber } from 'its-fine'\n\nfunction Component() {\n  // Returns the current component's react-internal Fiber\n  const fiber: Fiber<null> | undefined = useFiber()\n\n  // function Component() {}\n  if (fiber) console.log(fiber.type)\n}\n```\n\n### useContainer\n\nReturns the current react-reconciler container info passed to `Reconciler.createContainer`.\n\nIn react-dom, a container will point to the root DOM element; in react-three-fiber, it will point to the root Zustand store.\n\n```tsx\nimport * as React from 'react'\nimport { useContainer } from 'its-fine'\n\nfunction Component() {\n  // Returns the current renderer's root container\n  const container: HTMLDivElement | undefined = useContainer<HTMLDivElement>()\n\n  // <div> (e.g. react-dom)\n  if (container) console.log(container)\n}\n```\n\n### useNearestChild\n\nReturns the nearest react-reconciler child instance or the node created from `Reconciler.createInstance`.\n\nIn react-dom, this would be a DOM element; in react-three-fiber this would be an `Instance` descriptor.\n\n```tsx\nimport * as React from 'react'\nimport { useNearestChild } from 'its-fine'\n\nfunction Component() {\n  // Returns a React Ref which points to the nearest child <div /> element.\n  // Omit the element type to match the nearest element of any kind\n  const childRef: React.MutableRefObject<HTMLDivElement | undefined> = useNearestChild<HTMLDivElement>('div')\n\n  // Access child Ref on mount\n  React.useEffect(() => {\n    // <div> (e.g. react-dom)\n    const child = childRef.current\n    if (child) console.log(child)\n  }, [])\n\n  // A child element, can live deep down another component\n  return <div />\n}\n```\n\n### useNearestParent\n\nReturns the nearest react-reconciler parent instance or the node created from `Reconciler.createInstance`.\n\nIn react-dom, this would be a DOM element; in react-three-fiber this would be an instance descriptor.\n\n```tsx\nimport * as React from 'react'\nimport { useNearestParent } from 'its-fine'\n\nfunction Component() {\n  // Returns a React Ref which points to the nearest parent <div /> element.\n  // Omit the element type to match the nearest element of any kind\n  const parentRef: React.MutableRefObject<HTMLDivElement | undefined> = useNearestParent<HTMLDivElement>('div')\n\n  // Access parent Ref on mount\n  React.useEffect(() => {\n    // <div> (e.g. react-dom)\n    const parent = parentRef.current\n    if (parent) console.log(parent)\n  }, [])\n}\n\n// A parent element wrapping Component, can live deep up another component\n;<div>\n  <Component />\n</div>\n```\n\n### useContextMap\n\nReturns a map of all contexts and their values.\n\n```tsx\nimport * as React from 'react'\nimport { useContextMap } from 'its-fine'\n\nconst SomeContext = React.createContext<string>(null!)\n\nfunction Component() {\n  const contextMap = useContextMap()\n  return contextMap.get(SomeContext)\n}\n```\n\n### useContextBridge\n\nReact 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 `ContextBridge` of live context providers to pierce Context across renderers.\n\nPass `ContextBridge` as a component to a secondary renderer to enable context-sharing within its children.\n\n```tsx\nimport * as React from 'react'\n// react-nil is a secondary renderer that is usually used for testing.\n// This also includes Fabric, react-three-fiber, etc\nimport * as ReactNil from 'react-nil'\n// react-dom is a primary renderer that works on top of a secondary renderer.\n// This also includes react-native, react-pixi, etc.\nimport * as ReactDOM from 'react-dom/client'\nimport { type ContextBridge, useContextBridge, FiberProvider } from 'its-fine'\n\nfunction Canvas(props: { children: React.ReactNode }) {\n  // Returns a bridged context provider that forwards context\n  const Bridge: ContextBridge = useContextBridge()\n  // Renders children with bridged context into a secondary renderer\n  ReactNil.render(<Bridge>{props.children}</Bridge>)\n}\n\n// A React Context whose provider lives in react-dom\nconst DOMContext = React.createContext<string>(null!)\n\n// A component that reads from DOMContext\nfunction Component() {\n  // \"Hello from react-dom\"\n  console.log(React.useContext(DOMContext))\n}\n\n// Renders into a primary renderer like react-dom or react-native,\n// DOMContext wraps Canvas and is bridged into Component\nReactDOM.createRoot(document.getElementById('root')!).render(\n  <FiberProvider>\n    <DOMContext.Provider value=\"Hello from react-dom\">\n      <Canvas>\n        <Component />\n      </Canvas>\n    </DOMContext.Provider>\n  </FiberProvider>,\n)\n```\n\n## Utils\n\nAdditional exported utility functions for raw handling of Fibers.\n\n### traverseFiber\n\nTraverses up or down a `Fiber`, return `true` to stop and select a node.\n\n```ts\nimport { type Fiber, traverseFiber } from 'its-fine'\n\n// Traverses through the Fiber tree, returns the current node when `true` is passed via selector\nconst parentDiv: Fiber<HTMLDivElement> | undefined = traverseFiber<HTMLDivElement>(\n  // Input Fiber to traverse\n  fiber as Fiber,\n  // Whether to ascend and walk up the tree. Will walk down if `false`\n  true,\n  // A Fiber node selector, returns the first match when `true` is passed\n  (node: Fiber<HTMLDivElement | null>) => node.type === 'div',\n)\n```\n","publish_time":1662279370565,"_cnpm_publish_time":1662279370565,"dist-tags":{"latest":"2.1.1"}}