UNPKG

bippy

Version:

hack into react internals

9 lines 11.3 kB
var Bippy=function(e){"use strict"; /** * @license bippy * * Copyright (c) Aiden Bai, Million Software, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var t="0.3.8",n=`bippy-${t}`,o=Object.defineProperty,r=Object.prototype.hasOwnProperty,i=()=>{},s=e=>{try{Function.prototype.toString.call(e).indexOf("^_^")>-1&&setTimeout((()=>{throw new Error("React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://reactjs.org/link/perf-use-production-build")}))}catch{}},a=(e=b())=>"getFiberRoots"in e,l=!1,c=void 0,u=(e=b())=>!!l||("function"==typeof e.inject&&(c=e.inject.toString()),Boolean(c?.includes("(injected)"))),m=new Set,d=e=>{const t=new Map;let r=0,a={checkDCE:s,supportsFiber:!0,supportsFlight:!0,hasUnsupportedRendererAttached:!1,renderers:t,onCommitFiberRoot:i,onCommitFiberUnmount:i,onPostCommitFiberRoot:i,inject(e){const n=++r;return t.set(n,e),a._instrumentationIsActive||(a._instrumentationIsActive=!0,m.forEach((e=>e()))),n},_instrumentationSource:n,_instrumentationIsActive:!1};try{o(globalThis,"__REACT_DEVTOOLS_GLOBAL_HOOK__",{get:()=>a,set(t){if(t&&"object"==typeof t){const n=a.renderers;a=t,n.size>0&&(n.forEach(((e,n)=>{t.renderers.set(n,e)})),p(e))}},configurable:!0,enumerable:!0});const t=window.hasOwnProperty;let n=!1;o(window,"hasOwnProperty",{value:function(){try{return n||"__REACT_DEVTOOLS_GLOBAL_HOOK__"!==arguments[0]?t.apply(this,arguments):(globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__=void 0,n=!0,-0)}catch{return t.apply(this,arguments)}},configurable:!0,writable:!0})}catch{p(e)}return a},p=e=>{e&&m.add(e);try{const t=globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!t)return;if(!t._instrumentationSource){if(t.checkDCE=s,t.supportsFiber=!0,t.supportsFlight=!0,t.hasUnsupportedRendererAttached=!1,t._instrumentationSource=n,t._instrumentationIsActive=!1,t.renderers.size)return t._instrumentationIsActive=!0,void m.forEach((e=>e()));const e=t.inject;if(u(t)&&!a()){l=!0;t.inject({scheduleRefresh(){}})&&(t._instrumentationIsActive=!0)}t.inject=n=>{const o=e(n);return t._instrumentationIsActive=!0,m.forEach((e=>e())),o}}(t.renderers.size||t._instrumentationIsActive||u())&&e?.()}catch{}},f=()=>r.call(globalThis,"__REACT_DEVTOOLS_GLOBAL_HOOK__"),b=e=>f()?(p(e),globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__):d(e),h=()=>Boolean("undefined"!=typeof window&&(window.document?.createElement||"ReactNative"===window.navigator?.product)),_=()=>{try{h()&&b()}catch{}},g="Symbol(react.element)",T="Symbol(react.transitional.element)",y="Symbol(react.concurrent_mode)",R="Symbol(react.async_mode)",C=e=>{switch(e.tag){case 5:case 26:case 27:return!0;default:return"string"==typeof e.type}},F=e=>{const t=e.memoizedProps,n=e.alternate?.memoizedProps||{},o=e.flags??e.effectTag??0;switch(e.tag){case 1:case 0:case 9:case 11:case 14:case 15:return!(1&~o);default:return!e.alternate||(n!==t||e.alternate.memoizedState!==e.memoizedState||e.alternate.ref!==e.ref)}},O=e=>Boolean(!!(13374&e.flags)||!!(13374&e.subtreeFlags)),S=e=>{switch(e.tag){case 18:case 6:case 7:case 23:case 22:return!0;case 3:return!1;default:{const t="object"==typeof e.type&&null!==e.type?e.type.$$typeof:e.type;switch("symbol"==typeof t?t.toString():t){case 60111:case y:case R:return!0;default:return!1}}}},E=(e,t,n=!1)=>{if(!e)return null;if(!0===t(e))return e;let o=n?e.return:e.child;for(;o;){const e=E(o,t,n);if(e)return e;o=n?null:o.sibling}return null},v=e=>{const t=e;return"function"==typeof t?t:"object"==typeof t&&t?v(t.type||t.render):null},A=e=>{try{if("string"==typeof e.version&&e.bundleType>0)return"development"}catch{}return"production"},L=0,I=new WeakMap,w=(e,t=L++)=>{I.set(e,t)},N=e=>{let t=I.get(e);return!t&&e.alternate&&(t=I.get(e.alternate)),t||(t=L++,w(e,t)),t},D=(e,t,n)=>{let o=t;for(;null!=o;){I.has(o)||N(o);if(!S(o)&&F(o)&&e(o,"mount"),13===o.tag){if(null!==o.memoizedState){const t=o.child,n=t?t.sibling:null;if(n){const t=n.child;null!==t&&D(e,t,!1)}}else{let t=null;null!==o.child&&(t=o.child.child),null!==t&&D(e,t,!1)}}else null!=o.child&&D(e,o.child,!0);o=n?o.sibling:null}},H=(e,t,n,o)=>{if(I.has(t)||N(t),!n)return;I.has(n)||N(n);const r=13===t.tag;!S(t)&&F(t)&&e(t,"update");const i=r&&null!==n.memoizedState,s=r&&null!==t.memoizedState;if(i&&s){const o=t.child?.sibling??null,r=n.child?.sibling??null;null!==o&&null!==r&&H(e,o,r)}else if(i&&!s){const n=t.child;null!==n&&D(e,n,!0)}else if(!i&&s){j(e,n);const o=t.child?.sibling??null;null!==o&&D(e,o,!0)}else if(t.child!==n.child){let n=t.child;for(;n;){if(n.alternate){const t=n.alternate;H(e,n,t)}else D(e,n,!1);n=n.sibling}}},P=(e,t)=>{!(3===t.tag)&&S(t)||e(t,"unmount")},j=(e,t)=>{const n=13===t.tag&&null!==t.memoizedState;let o=t.child;if(n){const e=t.child,n=e?.sibling??null;o=n?.child??null}for(;null!==o;)null!==o.return&&(P(e,o),j(e,o)),o=o.sibling},z=0,B=new WeakMap,M=(e,t)=>{const n="current"in e?e.current:e;let o=B.get(e);o||(o={prevFiber:null,id:z++},B.set(e,o));const{prevFiber:r}=o;if(n)if(null!==r){const e=r&&null!=r.memoizedState&&null!=r.memoizedState.element&&!0!==r.memoizedState.isDehydrated,o=null!=n.memoizedState&&null!=n.memoizedState.element&&!0!==n.memoizedState.isDehydrated;!e&&o?D(t,n,!1):e&&o?H(t,n,n.alternate):e&&!o&&P(t,n)}else D(t,n,!0);else P(t,n);o.prevFiber=n},k=e=>b((()=>{const t=b();e.onActive?.(),t._instrumentationSource=e.name??n;const o=t.onCommitFiberRoot;e.onCommitFiberRoot&&(t.onCommitFiberRoot=(t,n,r)=>{o&&o(t,n,r),e.onCommitFiberRoot?.(t,n,r)});const r=t.onCommitFiberUnmount;e.onCommitFiberUnmount&&(t.onCommitFiberUnmount=(t,n)=>{r&&r(t,n),e.onCommitFiberUnmount?.(t,n)});const i=t.onPostCommitFiberRoot;e.onPostCommitFiberRoot&&(t.onPostCommitFiberRoot=(t,n)=>{i&&i(t,n),e.onPostCommitFiberRoot?.(t,n)})})),U=new Error,G=new Set,V=(e,t={})=>{const n=e.onActive,o=f(),r=a(),i=u();let s,l=t.isProduction??!1;return e.onActive=()=>{clearTimeout(s);let o=!0;try{const e=b();for(const n of e.renderers.values()){const[e]=n.version.split(".");Number(e)<(t.minReactMajorVersion??17)&&(o=!1);"development"!==A(n)&&(l=!0,t.dangerouslyRunInProduction||(o=!1))}}catch(e){t.onError?.(e)}if(!o)return e.onCommitFiberRoot=void 0,e.onCommitFiberUnmount=void 0,e.onPostCommitFiberRoot=void 0,void(e.onActive=void 0);n?.();try{const n=e.onCommitFiberRoot;n&&(e.onCommitFiberRoot=(e,o,r)=>{G.has(o)||G.add(o);try{n(e,o,r)}catch(e){t.onError?.(e)}});const o=e.onCommitFiberUnmount;o&&(e.onCommitFiberUnmount=(e,n)=>{try{o(e,n)}catch(e){t.onError?.(e)}});const r=e.onPostCommitFiberRoot;r&&(e.onPostCommitFiberRoot=(e,n)=>{try{r(e,n)}catch(e){t.onError?.(e)}})}catch(e){t.onError?.(e)}},o||r||i||(s=setTimeout((()=>{l||t.onError?.(U),stop()}),t.installCheckTimeout??100)),e};return _(),e.BIPPY_INSTRUMENTATION_STRING=n,e.CONCURRENT_MODE_NUMBER=60111,e.CONCURRENT_MODE_SYMBOL_STRING=y,e.ClassComponentTag=1,e.ContextConsumerTag=9,e.DEPRECATED_ASYNC_MODE_SYMBOL_STRING=R,e.DehydratedSuspenseComponentTag=18,e.ELEMENT_TYPE_SYMBOL_STRING=g,e.ForwardRefTag=11,e.FragmentTag=7,e.FunctionComponentTag=0,e.HostComponentTag=5,e.HostHoistableTag=26,e.HostRootTag=3,e.HostSingletonTag=27,e.HostTextTag=6,e.INSTALL_ERROR=U,e.INSTALL_HOOK_SCRIPT_STRING="(()=>{try{var t=()=>{};const n=new Map;let o=0;globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__={checkDCE:t,supportsFiber:!0,supportsFlight:!0,hasUnsupportedRendererAttached:!1,renderers:n,onCommitFiberRoot:t,onCommitFiberUnmount:t,onPostCommitFiberRoot:t,inject(t){var e=++o;return n.set(e,t),globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__._instrumentationIsActive=!0,e},_instrumentationIsActive:!1,_script:!0}}catch{}})()",e.LegacyHiddenComponentTag=23,e.MemoComponentTag=14,e.OffscreenComponentTag=22,e.SimpleMemoComponentTag=15,e.SuspenseComponentTag=13,e.TRANSITIONAL_ELEMENT_TYPE_SYMBOL_STRING=T,e._fiberRoots=G,e.createFiberVisitor=({onRender:e})=>(t,n,o)=>{M(n,e)},e.detectReactBuildType=A,e.didFiberCommit=O,e.didFiberRender=F,e.fiberIdMap=I,e.getDisplayName=e=>{const t=e;if("string"==typeof t)return t;if("function"!=typeof t&&("object"!=typeof t||!t))return null;const n=t.displayName||t.name||null;if(n)return n;const o=v(t);return o&&(o.displayName||o.name)||null},e.getFiberFromHostInstance=e=>{const t=b();for(const n of t.renderers.values())try{const t=n.findFiberByHostInstance?.(e);if(t)return t}catch{}if("object"==typeof e&&null!=e){if("_reactRootContainer"in e)return e._reactRootContainer?._internalRoot?.current?.child;for(const t in e)if(t.startsWith("__reactInternalInstance$")||t.startsWith("__reactFiber"))return e[t]||null}return null},e.getFiberId=N,e.getFiberStack=e=>{const t=[];let n=e;for(;n.return;)t.push(n),n=n.return;return t},e.getLatestFiber=e=>{const t=e.alternate;if(!t)return e;if(t.actualStartTime&&e.actualStartTime)return t.actualStartTime>e.actualStartTime?t:e;for(const n of G){return E(n.current,(t=>{if(t===e)return!0}))||t}return e},e.getMutatedHostFibers=e=>{const t=[],n=[e];for(;n.length;){const e=n.pop();e&&(C(e)&&O(e)&&F(e)&&t.push(e),e.child&&n.push(e.child),e.sibling&&n.push(e.sibling))}return t},e.getNearestHostFiber=(e,t=!1)=>{let n=E(e,C,t);return n||(n=E(e,C,!t)),n},e.getNearestHostFibers=e=>{const t=[],n=[];for(C(e)?t.push(e):e.child&&n.push(e.child);n.length;){const e=n.pop();if(!e)break;C(e)?t.push(e):e.child&&n.push(e.child),e.sibling&&n.push(e.sibling)}return t},e.getRDTHook=b,e.getTimings=e=>{const t=e?.actualDuration??0;let n=t,o=e?.child??null;for(;t>0&&null!=o;)n-=o.actualDuration??0,o=o.sibling;return{selfTime:n,totalTime:t}},e.getType=v,e.hasMemoCache=e=>Boolean(e.updateQueue?.memoCache),e.hasRDTHook=f,e.installRDTHook=d,e.instrument=k,e.isClientEnvironment=h,e.isCompositeFiber=e=>{switch(e.tag){case 0:case 1:case 15:case 14:case 11:return!0;default:return!1}},e.isHostFiber=C,e.isInstrumentationActive=()=>{const e=b();return Boolean(e._instrumentationIsActive)||a()||u()},e.isReactRefresh=u,e.isRealReactDevtools=a,e.isValidElement=e=>"object"==typeof e&&null!=e&&"$$typeof"in e&&[g,T].includes(String(e.$$typeof)),e.isValidFiber=e=>"object"==typeof e&&null!=e&&"tag"in e&&"stateNode"in e&&"return"in e&&"child"in e&&"sibling"in e&&"flags"in e,e.mountFiberRecursively=D,e.onCommitFiberRoot=e=>k(V({onCommitFiberRoot:(t,n)=>{e(n)}})),e.patchRDTHook=p,e.safelyInstallRDTHook=_,e.secure=V,e.setFiberId=w,e.shouldFilterFiber=S,e.traverseContexts=(e,t)=>{try{const n=e.dependencies,o=e.alternate?.dependencies;if(!n||!o)return!1;if("object"!=typeof n||!("firstContext"in n)||"object"!=typeof o||!("firstContext"in o))return!1;let r=n.firstContext,i=o.firstContext;for(;r&&"object"==typeof r&&"memoizedValue"in r||i&&"object"==typeof i&&"memoizedValue"in i;){if(!0===t(r,i))return!0;r=r?.next,i=i?.next}}catch{}return!1},e.traverseFiber=E,e.traverseProps=(e,t)=>{try{const n=e.memoizedProps,o=e.alternate?.memoizedProps||{},r=new Set([...Object.keys(o),...Object.keys(n)]);for(const e of r){const r=o?.[e],i=n?.[e];if(!0===t(e,i,r))return!0}}catch{}return!1},e.traverseRenderedFibers=M,e.traverseState=(e,t)=>{try{let n=e.memoizedState,o=e.alternate?.memoizedState;for(;n||o;){if(!0===t(n,o))return!0;n=n?.next,o=o?.next}}catch{}return!1},e.unmountFiber=P,e.unmountFiberChildrenRecursively=j,e.updateFiberRecursively=H,e.version=t,e}({});