/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/react-performance-testing@2.0.0/dist/index.cjs.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});const getDisplayName=e=>e.displayName||e.name||e.type&&getDisplayName(e.type)||e.render&&getDisplayName(e.render),isClassComponent=e=>e.prototype&&!!e.prototype.isReactComponent;let REACT_MEMO_TYPE=60115,REACT_FORWARD_REF_TYPE=60112;const symbolFor="function"==typeof Symbol&&Symbol.for;symbolFor&&(REACT_MEMO_TYPE=Symbol.for("react.memo"),REACT_FORWARD_REF_TYPE=Symbol.for("react.forward_ref"));const isMemoComponent=e=>e.$$typeof===REACT_MEMO_TYPE,isForwardRefComponent=e=>e.$$typeof===REACT_FORWARD_REF_TYPE,isFunctionComponent=e=>"function"==typeof e,W=(null===global||void 0===global?void 0:global.window)?window:global,pushTask=e=>{W.setImmediate(e)},setArray=(e,t,r)=>{const n=t.current[e];let o=-1;return n&&(t.current[e]=Array.isArray(n)?[...n,r]:[{...n},r],o=Array.isArray(n)?n.length:1),o},updateRenderCount=(e,t,r)=>{if(!r)return;const n=e.current;n[r]||(n[r]={value:0}),pushTask((()=>{const n=e.current[r];if(Array.isArray(n)){n[-1===t?0:t].value+=1}else n.value+=1}))},startMeasureRenderTime=(e,t,r)=>{if(!r)return()=>{};const n=e.current;n[r]||(n[r]={mount:null,updates:[]});const o=performance.now();return()=>{const n=performance.now()-o;pushTask((()=>{const o=e.current,a=o[r];if(Array.isArray(a)){const e=-1===t?0:t,r=a[e];a[e]={mount:r.mount||n,updates:r.mount?[...r.updates,n]:[]}}else o[r]={mount:a.mount||n,updates:a.mount?[...a.updates,n]:[]}}))}},createClassComponent=(e,{renderCount:t,renderTime:r},{hasRenderCount:n,hasRenderTime:o})=>{const a=e,s=getDisplayName(e);s||console.warn("[react-performance-testing] You have anonymous component. If your component don't have display name, we can not set property to renderCount.current");class c extends a{constructor(e,i){super(e,i);const l=super.render||this.render;o&&(this.currentIndex=setArray(s,r,{mount:null,updates:[]})),n&&(this.currentIndex=setArray(s,t,{value:0}));l!==a.prototype.render&&(this.render=()=>(c.prototype.render.apply(this),l()))}componentDidMount(){this.endMeasureRenderTime&&this.endMeasureRenderTime()}componentDidUpdate(){this.endMeasureRenderTime&&this.endMeasureRenderTime()}render(){return n&&updateRenderCount(t,this.currentIndex,s),o&&(this.endMeasureRenderTime=startMeasureRenderTime(r,this.currentIndex,s)),super.render?super.render():null}}return c},createFunctionComponent=(e,{renderCount:t,renderTime:r},{hasRenderCount:n,hasRenderTime:o},a)=>{const s=e,c=getDisplayName(e);c||console.warn("[react-performance-testing] You have anonymous component. If your component don't have display name, we can not set property to renderCount.current");return(...e)=>{const i=a.useMemo((()=>{let e=-1;return o&&(e=setArray(c,r,{mount:null,updates:[]})),n&&(e=setArray(c,t,{value:0})),e}),[]),l=a.useRef(null);return n&&updateRenderCount(t,i,c),a.useLayoutEffect((()=>{l.current&&l.current()})),o&&(l.current=startMeasureRenderTime(r,i,c)),s(...e)}},createMemoComponent=(e,t,r,n)=>{const{type:o}=e,a=isForwardRefComponent(o),s=a?o.render:o,c=isClassComponent(o)?createClassComponent(s,t,r):isMemoComponent(o)?createMemoComponent(s,t,r,n):createFunctionComponent(s,t,r,n);try{c.displayName=getDisplayName(s)}catch(e){}return n.memo(a?n.forwardRef(c):c,e.compare)},createForwardRefComponent=(e,t,r,n)=>{const{render:o}=e,a=isMemoComponent(o),s=a?o.type:o,c=createFunctionComponent(s,t,r,n);try{c.displayName=getDisplayName(s)}catch(e){}return n.forwardRef(a?n.memo(c,s.compare):c)},createPatchedComponent=(e,t,r,n)=>isMemoComponent(e)?createMemoComponent(e,t,r,n):isForwardRefComponent(e)?createForwardRefComponent(e,t,r,n):isClassComponent(e)?createClassComponent(e,t,r):isFunctionComponent(e)?createFunctionComponent(e,t,r,n):void 0,getPatchedComponent=(e,t,r,n,o)=>{const a=createPatchedComponent(t,r,n,o);try{a.displayName=getDisplayName(t)}catch(e){}return e.set(t,a),a},shouldTrack=e=>isClassComponent(e)||isMemoComponent(e)||isForwardRefComponent(e)||"function"==typeof e,globalOption={isDeclaredRenderTime:!1},checkRenderTimeDeclaring=e=>{"renderTime"===e&&globalOption.isDeclaredRenderTime?console.warn("[react-performance-testing] You need to execute test one by one when you use `renderTime`. Please check here: https://github.com/keiya01/react-performance-testing#renderTime"):globalOption.isDeclaredRenderTime=!0},getDefaultStore=()=>({tools:{renderCount:{current:{}},renderTime:{current:{}}},componentsMap:new WeakMap,perfState:Object.defineProperties({hasRenderCount:!Proxy,hasRenderTime:!Proxy},{renderCount:{set(e){this.hasRenderCount=e}},renderTime:{set(e){this.hasRenderTime=e}}})}),store=getDefaultStore(),getPerfTools=()=>new Proxy(store.tools,{get:(e,t)=>(checkRenderTimeDeclaring(t),store.perfState[t]=!0,e[t])});let origCreateElement=null,origCreateFactory=null,origCloneElement=null,origReact=null;const perf=e=>{if(!e)return getPerfTools();const{tools:t,perfState:r,componentsMap:n}=store;return origReact=e,origCreateElement=e.createElement,origCreateFactory=e.createFactory,origCloneElement=e.cloneElement,e.createElement=function(o,...a){if(!shouldTrack(o))return origCreateElement.apply(e,[o,...a]);let s;return s=n.has(o)?n.get(o):getPatchedComponent(n,o,t,r,e),origCreateElement.apply(e,[s,...a])},Object.assign(e.createElement,origCreateElement),e.createFactory=t=>{const r=e.createElement.bind(null,t);return r.type=t,r},Object.assign(e.createFactory,origCreateFactory),e.cloneElement=(...t)=>origCloneElement.apply(e,t),Object.assign(e.cloneElement,origCloneElement),getPerfTools()},cleanup=()=>{Object.assign(store,getDefaultStore()),origReact&&(Object.assign(origReact,{createElement:origCreateElement,createFactory:origCreateFactory,cloneElement:origCloneElement}),origReact=null,origCreateElement=null,origCreateFactory=null,origCloneElement=null)};process.env.RPT_SKIP_AUTO_CLEANUP||("function"==typeof afterEach?afterEach(cleanup):"function"==typeof teardown&&teardown(cleanup));const wait=e=>new Promise((t=>pushTask((()=>{e(),t(void 0)}))));exports.__getDisplayName=getDisplayName,exports.__getPatchedComponent=getPatchedComponent,exports.__shouldTrack=shouldTrack,exports.__store=store,exports.cleanup=cleanup,exports.perf=perf,exports.wait=wait;
//# sourceMappingURL=/sm/1bb854c91088256e688ba7798b9166e6ea469c3c4e070321dbcbaedbeb738d3c.map