@memlab/lens 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/dist/config/config.d.ts +22 -0
  3. package/dist/core/dom-observer.d.ts +10 -0
  4. package/dist/core/event-listener-tracker.d.ts +33 -0
  5. package/dist/core/react-fiber-analysis.d.ts +4 -0
  6. package/dist/core/react-memory-scan.d.ts +36 -0
  7. package/{src/core/types.ts → dist/core/types.d.ts} +56 -80
  8. package/{src/index.ts → dist/core/valid-component-name.d.ts} +2 -7
  9. package/dist/extensions/basic-extension.d.ts +30 -0
  10. package/dist/extensions/dom-visualization-extension.d.ts +17 -0
  11. package/dist/index.d.ts +1 -0
  12. package/dist/memlens.lib.bundle.js +1695 -0
  13. package/dist/memlens.lib.bundle.min.js +1 -0
  14. package/dist/memlens.lib.d.ts +12 -0
  15. package/dist/memlens.run.bundle.js +2673 -0
  16. package/dist/memlens.run.bundle.min.js +1 -0
  17. package/dist/memlens.run.d.ts +1 -0
  18. package/dist/tests/bundle/lib.bundle.test.d.ts +1 -0
  19. package/dist/tests/bundle/run.bundle.start.head.test.d.ts +1 -0
  20. package/dist/tests/bundle/run.bundle.start.test.d.ts +1 -0
  21. package/dist/tests/bundle/run.bundle.test.d.ts +1 -0
  22. package/dist/tests/fiber/dev.fiber.complex.dev.test.d.ts +1 -0
  23. package/dist/tests/fiber/dev.fiber.complex.list.dev.test.d.ts +1 -0
  24. package/dist/tests/fiber/dev.fiber.complex.prod.test.d.ts +1 -0
  25. package/dist/tests/fiber/dev.fiber.name.dev.test.d.ts +1 -0
  26. package/dist/tests/fiber/dev.fiber.name.prod.test.d.ts +1 -0
  27. package/dist/tests/utils/test-utils.d.ts +11 -0
  28. package/dist/utils/intersection-observer.d.ts +18 -0
  29. package/dist/utils/react-fiber-utils.d.ts +56 -0
  30. package/dist/utils/utils.d.ts +26 -0
  31. package/dist/utils/weak-ref-utils.d.ts +67 -0
  32. package/dist/visual/components/component-stack-panel.d.ts +11 -0
  33. package/dist/visual/components/control-widget.d.ts +13 -0
  34. package/dist/visual/components/overlay-rectangle.d.ts +11 -0
  35. package/dist/visual/components/status-text.d.ts +2 -0
  36. package/dist/visual/components/toggle-button.d.ts +3 -0
  37. package/dist/visual/components/visual-overlay.d.ts +1 -0
  38. package/dist/visual/dom-element-visualizer-interactive.d.ts +26 -0
  39. package/{src/core/valid-component-name.ts → dist/visual/dom-element-visualizer.d.ts} +5 -7
  40. package/dist/visual/visual-utils.d.ts +16 -0
  41. package/package.json +5 -1
  42. package/explainer.md +0 -54
  43. package/playwright.config.ts +0 -21
  44. package/src/config/config.ts +0 -32
  45. package/src/core/dom-observer.ts +0 -189
  46. package/src/core/event-listener-tracker.ts +0 -171
  47. package/src/core/react-fiber-analysis.ts +0 -123
  48. package/src/core/react-memory-scan.ts +0 -366
  49. package/src/extensions/basic-extension.ts +0 -41
  50. package/src/extensions/dom-visualization-extension.ts +0 -42
  51. package/src/memlens.lib.js.flow +0 -75
  52. package/src/memlens.lib.ts +0 -22
  53. package/src/memlens.run.ts +0 -21
  54. package/src/tests/bundle/lib.bundle.test.ts +0 -31
  55. package/src/tests/bundle/run.bundle.start.head.test.ts +0 -48
  56. package/src/tests/bundle/run.bundle.start.test.ts +0 -48
  57. package/src/tests/bundle/run.bundle.test.ts +0 -51
  58. package/src/tests/fiber/dev.fiber.complex.dev.test.ts +0 -92
  59. package/src/tests/fiber/dev.fiber.complex.list.dev.test.ts +0 -118
  60. package/src/tests/fiber/dev.fiber.complex.prod.test.ts +0 -92
  61. package/src/tests/fiber/dev.fiber.name.dev.test.ts +0 -77
  62. package/src/tests/fiber/dev.fiber.name.prod.test.ts +0 -79
  63. package/src/tests/lib/babel.prod.js +0 -4
  64. package/src/tests/lib/react-dom-v18.dev.js +0 -29926
  65. package/src/tests/lib/react-dom-v18.prod.js +0 -269
  66. package/src/tests/lib/react-v18.dev.js +0 -3345
  67. package/src/tests/lib/react-v18.prod.js +0 -33
  68. package/src/tests/manual/playwright-open-manual.js +0 -40
  69. package/src/tests/manual/todo-list/todo-with-run.bundle.html +0 -80
  70. package/src/tests/utils/test-utils.ts +0 -28
  71. package/src/utils/intersection-observer.ts +0 -65
  72. package/src/utils/react-fiber-utils.ts +0 -212
  73. package/src/utils/utils.ts +0 -201
  74. package/src/utils/weak-ref-utils.ts +0 -308
  75. package/src/visual/components/component-stack-panel.ts +0 -85
  76. package/src/visual/components/control-widget.ts +0 -96
  77. package/src/visual/components/overlay-rectangle.ts +0 -167
  78. package/src/visual/components/status-text.ts +0 -53
  79. package/src/visual/components/toggle-button.ts +0 -57
  80. package/src/visual/components/visual-overlay.ts +0 -19
  81. package/src/visual/dom-element-visualizer-interactive.ts +0 -358
  82. package/src/visual/dom-element-visualizer.ts +0 -130
  83. package/src/visual/visual-utils.ts +0 -89
  84. package/tsconfig.json +0 -18
  85. package/webpack.config.js +0 -105
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MemLens=t():e.MemLens=t()}(self,(()=>(()=>{"use strict";var e={54:function(e,t,n){var o,i,s,r,a,l,c,u,f,d,h,p,v=this&&this.__classPrivateFieldSet||function(e,t,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n},m=this&&this.__classPrivateFieldGet||function(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.DOMObserver=void 0;const g=n(313),b=n(498),w=(0,g.isWeakAPINative)(),y=void 0!==window.MutationObserver;t.DOMObserver=class{constructor(){o.add(this),i.set(this,void 0),s.set(this,void 0),r.set(this,void 0),a.set(this,void 0),l.set(this,void 0),c.set(this,void 0),u.set(this,void 0),v(this,i,0,"f"),v(this,s,0,"f"),v(this,a,[],"f"),v(this,l,new WeakSet,"f"),v(this,u,[],"f"),this.startMonitoring()}register(e){m(this,u,"f").push(e)}startMonitoring(){if(!w||!y)return;if(null!=m(this,r,"f"))return;v(this,r,new MutationObserver((e=>{let t=[];const n=e=>{if(null==e)return;if(e.nodeType!=Node.ELEMENT_NODE)return;const n=e;if(!(0,b.isVisualizerElement)(n)){const e=m(this,o,"m",p).call(this,n);t=[...t,...e]}};e.forEach((e=>{e.addedNodes.forEach(n),e.removedNodes.forEach(n)})),m(this,u,"f").forEach((e=>e(t)))})),"f");const e=()=>{var t;document.body?null===(t=m(this,r,"f"))||void 0===t||t.observe(document.body,{childList:!0,subtree:!0}):setTimeout(e,0)};e(),v(this,c,window.setInterval((()=>{m(this,o,"m",f).call(this)}),3e3),"f")}stopMonitoring(){null!=m(this,r,"f")&&(m(this,r,"f").disconnect(),v(this,r,null,"f")),null!=m(this,c,"f")&&(window.clearInterval(m(this,c,"f")),v(this,c,null,"f"))}getDOMElements(){return[...m(this,a,"f")]}getStats(){try{v(this,i,m(this,o,"m",d).call(this),"f"),v(this,s,m(this,o,"m",h).call(this),"f")}catch(e){}return{elements:m(this,i,"f"),detachedElements:m(this,s,"f")}}},i=new WeakMap,s=new WeakMap,r=new WeakMap,a=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,o=new WeakSet,f=function(){const e=[],t=new Set;for(const n of m(this,a,"f")){const o=n.deref();null==o||t.has(o)||(e.push(n),t.add(o))}v(this,a,e,"f")},d=function(){var e,t;return v(this,i,null!==(t=null===(e=null===document||void 0===document?void 0:document.getElementsByTagName("*"))||void 0===e?void 0:e.length)&&void 0!==t?t:0,"f")},h=function(){let e=0;for(const t of m(this,a,"f")){const n=t.deref();n&&!1===n.isConnected&&++e}return v(this,s,e,"f")},p=function(e){const t=[e],n=new Set,o=[];for(;t.length>0;){const e=t.pop();if(null==e||n.has(e))continue;if((null==e?void 0:e.nodeType)!==Node.ELEMENT_NODE)continue;const i=e;if((0,b.isVisualizerElement)(i))continue;if(n.add(i),!m(this,l,"f").has(i)){const e=new WeakRef(i);m(this,a,"f").push(e),m(this,l,"f").add(i),o.push(e)}const s=i.childNodes;for(let e=0;e<s.length;++e)t.push(s[e])}return o}},235:function(e,t,n){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.createReactMemoryScan=function(e={}){return new i.default(e)};const i=o(n(282))},282:function(e,t,n){var o,i,s,r,a,l,c,u,f,d,h,p,v,m,g,b,w,y,M,k,_,E,O,C,T=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),W=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),S=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),i=0;i<n.length;i++)"default"!==n[i]&&T(t,e,n[i]);return W(t,e),t}),N=this&&this.__classPrivateFieldSet||function(e,t,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n},F=this&&this.__classPrivateFieldGet||function(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)},R=this&&this.__rest||function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(o=Object.getOwnPropertySymbols(e);i<o.length;i++)t.indexOf(o[i])<0&&Object.prototype.propertyIsEnumerable.call(e,o[i])&&(n[o[i]]=e[o[i]])}return n},P=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const D=S(n(476)),I=P(n(302)),j=n(737),L=n(54),H=n(346),x=n(953);class A{constructor(e={}){var t,n,o,b;i.add(this),s.set(this,void 0),r.set(this,void 0),a.set(this,void 0),l.set(this,void 0),c.set(this,void 0),u.set(this,void 0),f.set(this,void 0),d.set(this,void 0),h.set(this,void 0),p.set(this,void 0),v.set(this,void 0),m.set(this,void 0),g.set(this,void 0),N(this,s,[],"f"),N(this,r,!1,"f"),N(this,l,new WeakMap,"f"),N(this,c,new WeakMap,"f"),N(this,u,[],"f"),N(this,g,e.trackEventListenerLeaks?x.EventListenerTracker.getInstance():null,"f"),N(this,f,new I.default,"f"),N(this,a,0,"f"),N(this,d,null!==(t=e.isDevMode)&&void 0!==t&&t,"f"),N(this,h,null!==(n=e.subscribers)&&void 0!==n?n:[],"f"),N(this,p,null!==(o=e.extensions)&&void 0!==o?o:[],"f"),N(this,v,null!==(b=e.scanIntervalMs)&&void 0!==b?b:H.config.performance.scanIntervalMs,"f")}subscribe(e){return F(this,h,"f").push(e),()=>this.unsubscribe(e)}unsubscribe(e){N(this,h,F(this,h,"f").filter((t=>t!==e)),"f")}registerExtension(e){return F(this,p,"f").push(e),()=>this.unregisterExtension(e)}unregisterExtension(e){N(this,p,F(this,p,"f").filter((t=>t!==e)),"f")}start(){N(this,r,!0,"f"),N(this,a,setInterval(F(this,i,"m",k).bind(this),F(this,v,"f")),"f"),H.config.features.enableMutationObserver&&(null==F(this,m,"f")&&N(this,m,new L.DOMObserver,"f"),F(this,m,"f").startMonitoring()),console.log("[Memory] Tracking React and DOM memory...")}pause(){N(this,r,!1,"f")}stop(){var e;N(this,r,!1,"f"),clearInterval(F(this,a,"f")),N(this,s,[],"f"),null===(e=F(this,m,"f"))||void 0===e||e.stopMonitoring()}recordBoundingRectangles(e){for(const t of e){const e=t.deref();if(null==e||F(this,l,"f").has(e))continue;const n=D.getBoundingClientRect(e);null!=n&&F(this,l,"f").set(e,n)}}getDetachedDOMInfo(){var e;const t=[];for(const n of F(this,s,"f")){const o=n.deref();if(null==o||o.isConnected)continue;const i=o;if(null==i.detachedElementId){const e=A.nextElementId++;i.detachedElementIdStr=`memory-id-${e}@`,i.detachedElementId=e}const s=null!==(e=F(this,c,"f").get(o))&&void 0!==e?e:[];t.push({element:n,boundingRect:F(this,l,"f").get(o),componentStack:s})}return t}isDevMode(){return F(this,d,"f")}getCachedComponentName(e){var t;const n="<Unknown>",o=e.deref();if(null==o)return n;const i=F(this,c,"f").get(o);return null==i?n:null!==(t=i[0])&&void 0!==t?t:n}updateFiberNodes(e){const t=new WeakSet;for(const e of F(this,u,"f")){const n=e.deref();null!=n&&t.add(n)}const n=new WeakSet;for(const t of e){const e=t.deref();null!=e&&n.add(e)}const o=[],s=[];for(const e of F(this,u,"f")){const t=e.deref();null!=t&&(n.has(t)?(s.push(e),null==t.return&&o.push(e)):o.push(e))}for(const n of e){const e=n.deref();null!=e&&(t.has(e)||s.push(n))}return N(this,u,s,"f"),F(this,i,"m",b).call(this,"known fibers: ",F(this,u,"f").length),F(this,i,"m",b).call(this,"leaked fibers: ",o.length),o}packLeakedFibers(e){const t=[];for(const n of e)t.push(new B(n));return t}scan(){const e=Date.now();F(this,i,"m",O).call(this);const t=F(this,s,"f"),n=F(this,i,"m",E).call(this);F(this,i,"m",_).call(this,n),this.recordBoundingRectangles(n),D.updateWeakRefList(t,n);const o=F(this,f,"f").scan(t,F(this,c,"f")),r=this.updateFiberNodes(o.fiberNodes);o.leakedFibers=r,o.eventListenerLeaks=F(this,i,"m",C).call(this),window.leakedFibers=this.packLeakedFibers(r);const a=Date.now();return F(this,i,"m",b).call(this,`scan took ${a-e}ms`),o}}s=new WeakMap,r=new WeakMap,a=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,f=new WeakMap,d=new WeakMap,h=new WeakMap,p=new WeakMap,v=new WeakMap,m=new WeakMap,g=new WeakMap,i=new WeakSet,b=function(...e){F(this,d,"f")&&H.config.features.enableConsoleLogs&&D.consoleLog(...e)},w=function(e){for(const t of F(this,h,"f"))t(e);const t=e.end-e.start;F(this,i,"m",b).call(this,"duration: ",`${t} ms`);const{scanner:n,leakedFibers:o,fiberNodes:s}=e,r=R(e,["scanner","leakedFibers","fiberNodes"]);F(this,i,"m",b).call(this,r)},y=function(){for(const e of F(this,p,"f"))null==e||e.beforeScan()},M=function(e){for(const t of F(this,p,"f"))null==t||t.afterScan(e)},k=function(){if(!F(this,r,"f"))return;F(this,i,"m",y).call(this);const e=performance.now(),t=this.scan(),n=performance.now(),o=Object.assign(Object.assign({},t),{start:e,end:n,scanner:this});F(this,i,"m",w).call(this,o),F(this,i,"m",M).call(this,o)},_=function(e){for(const t of e){const e=t.deref();if(null==e||F(this,c,"f").has(e))continue;const n=(0,j.getFiberNodeFromElement)(e);null!=n&&F(this,c,"f").set(e,(0,j.getReactComponentStack)(n))}},E=function(){return null==F(this,m,"f")?D.getDOMElements():[...D.getDOMElements(),...F(this,m,"f").getDOMElements()]},O=function(){null!=(null===window||void 0===window?void 0:window.gc)&&window.gc()},C=function(){var e;if(null==F(this,g,"f"))return[];const t=F(this,g,"f").scan(this.getCachedComponentName.bind(this)),n=[];for(const[o,i]of t.entries()){const t=new Map;for(const n of i){const o=null!==(e=t.get(n.type))&&void 0!==e?e:0;t.set(n.type,o+1)}for(const[e,i]of t.entries())n.push({type:e,componentName:o,count:i})}return n},A.nextElementId=0,t.default=A;class B{constructor(e){this.leakedFiber=e}}},302:function(e,t,n){var o,i=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,o,i)}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),s=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),r=this&&this.__importStar||(o=function(e){return o=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},o(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n=o(e),r=0;r<n.length;r++)"default"!==n[r]&&i(t,e,n[r]);return s(t,e),t});Object.defineProperty(t,"__esModule",{value:!0});const a=r(n(476)),l=n(737),c=n(847);t.default=class{scan(e,t){var n;const o=new Set,i=new Set,s=new Map,r=new Map,u=new Set,f=new Set,d=[];let h=0,p=0;function v(e){(0,l.traverseFiber)(e,(e=>{if(f.has(e))return!0;f.add(e);const t=(0,l.getDisplayNameOfFiberNode)(e);return null!=t&&(0,c.isValidComponentName)(t)?(i.add(t),a.addCountbyKey(s,t,1),!0):void 0}),!0)}for(const i of e){const e=i.deref();if(null==e)continue;if(++h,!e.isConnected){if(t.has(e)){const o=(null!==(n=t.get(e))&&void 0!==n?n:[])[0];e.__component_name=o,a.addCountbyKey(r,o,1)}++p}const s=(0,l.getFiberNodeFromElement)(e);if(null==s)continue;v(s);const c=(0,l.getTopMostFiberWithChild)(s);null!=c&&(o.has(c)||(o.add(c),(0,l.traverseFiber)(c,(e=>{if(u.has(e))return!0;u.add(e),d.push(new WeakRef(e)),v(e)}),!1)))}return u.clear(),f.clear(),o.clear(),{components:i,componentToFiberNodeCount:s,totalElements:h,totalDetachedElements:p,detachedComponentToFiberNodeCount:r,fiberNodes:d,leakedFibers:[]}}}},313:(e,t)=>{var n,o,i;Object.defineProperty(t,"__esModule",{value:!0}),t.WeakMapPlus=t.WeakMapNoOp=t.WeakSetNoOp=t.WeakRefNoOp=void 0,t.getNativeWeakMap=function(){return a?r:null},t.getNativeWeakMapOrFallback=function(){return a&&r?r:v},t.getNativeWeakSet=function(){return c?l:null},t.getNativeWeakSetOrFallback=function(){return c&&l?l:p},t.getNativeWeakRef=function(){return f?u:null},t.getNativeWeakRefOrFallback=function(){return f&&u?u:h},t.isWeakMapNative=g,t.isWeakSetNative=b,t.isWeakRefNative=w,t.isWeakAPINative=function(){return d};const s="undefined"!=typeof window?window:self,r=null!==(n=s.WeakMap)&&void 0!==n?n:null,a=g(),l=null!==(o=s.WeakSet)&&void 0!==o?o:null,c=b(),u=null!==(i=s.WeakRef)&&void 0!==i?i:null,f=w(),d=a&&c&&f;class h{constructor(e){}deref(){}}t.WeakRefNoOp=h;class p{constructor(e){}add(e){return this}delete(e){return!1}has(e){return!1}}t.WeakSetNoOp=p;class v{constructor(e){}delete(e){return!1}get(e){}has(e){return!1}set(e,t){return this}}function m(e){return"function"==typeof e.replace?e.replace(/\n/g," ").replace(/\s+/g," "):null}function g(){return null!==r&&"function"==typeof r.toString&&"function WeakMap() { [native code] }"===m(r.toString())}function b(){return null!==l&&"function"==typeof l.toString&&"function WeakSet() { [native code] }"===m(l.toString())}function w(){return null!==u&&"function"==typeof u.toString&&"function WeakRef() { [native code] }"===m(u.toString())}t.WeakMapNoOp=v;class y{constructor(e={}){this.strongMap=null,this.noopMap=!1,this.entriesMap=new Map,this.keyToId=new WeakMap;const{fallback:t="strong",cleanupMs:n=1e3}=e;this.isWeak=d,this.fallbackMode=t,this.isWeak?this.cleanupInterval=setInterval((()=>this.cleanup()),n):("strong"===t?this.strongMap=new Map:"noop"===t&&(this.noopMap=!0),this.cleanupInterval=-1)}getOrCreateId(e){let t=this.keyToId.get(e);return t||(t=Symbol(),this.keyToId.set(e,t)),t}set(e,t){var n;if(!this.isWeak)return this.noopMap||null===(n=this.strongMap)||void 0===n||n.set(e,t),this;const o=this.getOrCreateId(e);return this.entriesMap.set(o,{ref:new WeakRef(e),value:t}),this}get(e){var t,n;if(!this.isWeak){if(this.noopMap)return;return null===(t=this.strongMap)||void 0===t?void 0:t.get(e)}const o=this.keyToId.get(e);if(!o)return;const i=this.entriesMap.get(o);return(null===(n=null==i?void 0:i.ref)||void 0===n?void 0:n.deref())?null==i?void 0:i.value:void 0}has(e){var t,n;if(!this.isWeak)return!this.noopMap&&null!==(n=null===(t=this.strongMap)||void 0===t?void 0:t.has(e))&&void 0!==n&&n;const o=this.keyToId.get(e);if(!o)return!1;const i=this.entriesMap.get(o);return!(!i||!i.ref.deref())}delete(e){var t,n;if(!this.isWeak)return!this.noopMap&&null!==(n=null===(t=this.strongMap)||void 0===t?void 0:t.delete(e))&&void 0!==n&&n;const o=this.keyToId.get(e);return!!o&&(this.keyToId.delete(e),this.entriesMap.delete(o))}*liveEntries(){for(const[,e]of this.entriesMap){const t=e.ref.deref();t&&(yield[t,e.value])}}entries(){var e,t;return this.isWeak?this.liveEntries():this.noopMap?[][Symbol.iterator]():null!==(t=null===(e=this.strongMap)||void 0===e?void 0:e.entries())&&void 0!==t?t:[][Symbol.iterator]()}keys(){return function*(e){for(const[t]of e.entries())yield t}(this)}values(){return function*(e){for(const[,t]of e.entries())yield t}(this)}[Symbol.iterator](){return this.entries()}get size(){var e,t;if(!this.isWeak)return this.noopMap?0:null!==(t=null===(e=this.strongMap)||void 0===e?void 0:e.size)&&void 0!==t?t:0;let n=0;for(const e of this.liveEntries())n++;return n}getFallbackMode(){return this.fallbackMode}cleanup(){if(this.isWeak)for(const[e,t]of this.entriesMap)t.ref.deref()||this.entriesMap.delete(e)}destroy(){this.isWeak&&clearInterval(this.cleanupInterval)}}t.WeakMapPlus=y},346:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.config=t.featureFlags=t.performanceConfig=void 0,t.performanceConfig={scanIntervalMs:1e3,maxComponentStackDepth:100,memoryMeasurementIntervalMs:5e3},t.featureFlags={enableMutationObserver:!0,enableMemoryTracking:!0,enableComponentStack:!0,enableConsoleLogs:null===window||void 0===window?void 0:window.TEST_MEMORY_SCAN},t.config={performance:t.performanceConfig,features:t.featureFlags}},476:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.getDOMElements=function(){const e=Array.from(document.querySelectorAll("*")),t=[];for(const n of e)(0,o.isVisualizerElement)(n)||t.push(new WeakRef(n));return t},t.getDOMElementCount=function(){const e=Array.from(document.querySelectorAll("*"));let t=0;for(const n of e)(0,o.isVisualizerElement)(n)||++t;return t},t.getMeaningfulName=function(e){return null==e||i(e)?null:e},t.isMinifiedName=i,t.addCountbyKey=function(e,t,n){var o;e.set(t,(null!==(o=e.get(t))&&void 0!==o?o:0)+n)},t.updateWeakRefList=function(e,t){!function(e){const t=[];for(const n of e)null!=n.deref()&&t.push(n);for(;e.length>0;)e.pop();for(const n of t)e.push(n)}(e);const n=function(e){const t=new Set;for(const n of e)t.add(n.deref());return t}(e);for(const o of t){const t=o.deref();null==t||n.has(t)||(n.add(t),e.push(new WeakRef(t)))}return e},t.getBoundingClientRect=function(e){if(null==e)return null;if("function"!=typeof e.getBoundingClientRect)return null;let t=null;try{t=e.getBoundingClientRect()}catch(e){}if(null==t)return null;const n=window.scrollY,o=window.scrollX,i={};return i.bottom=t.bottom,i.height=t.height,i.left=t.left,i.right=t.right,i.top=t.top,i.width=t.width,i.x=t.x,i.y=t.y,i.scrollLeft=o,i.scrollTop=n,i},t.consoleLog=function(...e){r.apply(s,e)},t.hasRunInSession=function(){if(!l())return!1;try{return"true"===sessionStorage.getItem(a)}catch(e){return!1}},t.setRunInSession=function(){if(l())try{sessionStorage.setItem(a,"true")}catch(e){}};const o=n(498);function i(e){return!(e.length>=5)&&(e.length<=3||!/[^a-zA-Z0-9$_]/.test(e)&&!/^[A-Z][a-z]+([A-Z][a-z]*)*$|^[a-z]+([A-Z][a-z]*)*$/.test(e))}const s=console,r=s.log,a="memory_lens_session";function l(){try{const e="__memory_lens_session_test__";return sessionStorage.setItem(e,"1"),sessionStorage.removeItem(e),!0}catch(e){return!1}}},498:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isVisualizerElement=function(e){return"true"===e.getAttribute(n)},t.createVisualizerElement=function(e){const t=document.createElement(e);return function(e){e.setAttribute(n,"true"),e.setAttribute("data-visualcompletion","ignore")}(t),t},t.tryToAttachOverlay=function(e){document.body&&document.body.appendChild(e)},t.addTrackedListener=function(e,t,n,i){var s;const r=e.deref();r&&(r.addEventListener(t,n,i),o.has(r)||o.set(r,[]),null===(s=o.get(r))||void 0===s||s.push({type:t,cb:n,options:i}))},t.removeAllListeners=function(e){const t=e.deref();if(!t)return;const n=o.get(t);if(n){for(const{type:e,cb:o,options:i}of n)t.removeEventListener(e,o,i);o.delete(t)}},t.debounce=function(e,t){let n=null;return(...o)=>{n&&clearTimeout(n),n=setTimeout((()=>{e(...o)}),t)}};const n="data-visualizer",o=new WeakMap},737:(e,t,n)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.traverseFiber=t.getTopMostFiberWithChild=t.getTopMostHostFiber=t.getNearestHostFiber=t.isHostFiber=t.MutationMask=t.Visibility=t.Snapshot=t.Ref=t.ContentReset=t.ChildDeletion=t.Cloned=t.Update=t.Hydrating=t.DidCapture=t.Placement=t.PerformedWork=t.DEPRECATED_ASYNC_MODE_SYMBOL_STRING=t.CONCURRENT_MODE_SYMBOL_STRING=t.CONCURRENT_MODE_NUMBER=t.HostRoot=t.OffscreenComponent=t.LegacyHiddenComponent=t.Fragment=t.HostText=t.DehydratedSuspenseComponent=t.HostSingletonTag=t.HostHoistableTag=t.HostComponentTag=t.SimpleMemoComponentTag=t.MemoComponentTag=t.ForwardRefTag=t.OffscreenComponentTag=t.SuspenseComponentTag=t.ContextConsumerTag=t.FunctionComponentTag=t.ClassComponentTag=void 0,t.getFiberNodeFromElement=function(e){for(const t of s){const n=r(e).find((e=>e.startsWith(t)));if(n)return e[n]}return null},t.getReactComponentStack=function(e){const t=[],n=new Set;let o=e;for(;o&&!n.has(o);){n.add(o);const e=a(o);e&&t.push(e),o=o.return}return t},t.getDisplayNameOfFiberNode=a,t.isFunctionalComponent=function(e){return"function"==typeof(null==e?void 0:e.elementType)},t.extractReactComponentName=l;const o=n(476),i=n(847);t.ClassComponentTag=1,t.FunctionComponentTag=0,t.ContextConsumerTag=9,t.SuspenseComponentTag=13,t.OffscreenComponentTag=22,t.ForwardRefTag=11,t.MemoComponentTag=14,t.SimpleMemoComponentTag=15,t.HostComponentTag=5,t.HostHoistableTag=26,t.HostSingletonTag=27,t.DehydratedSuspenseComponent=18,t.HostText=6,t.Fragment=7,t.LegacyHiddenComponent=23,t.OffscreenComponent=22,t.HostRoot=3,t.CONCURRENT_MODE_NUMBER=60111,t.CONCURRENT_MODE_SYMBOL_STRING="Symbol(react.concurrent_mode)",t.DEPRECATED_ASYNC_MODE_SYMBOL_STRING="Symbol(react.async_mode)",t.PerformedWork=1,t.Placement=2,t.DidCapture=128,t.Hydrating=4096,t.Update=4,t.Cloned=8,t.ChildDeletion=16,t.ContentReset=32,t.Ref=512,t.Snapshot=1024,t.Visibility=8192,t.MutationMask=t.Placement|t.Update|t.ChildDeletion|t.ContentReset|t.Hydrating|t.Visibility|t.Snapshot,t.isHostFiber=e=>e.tag===t.HostComponentTag||e.tag===t.HostHoistableTag||e.tag===t.HostSingletonTag||"string"==typeof e.type,t.getNearestHostFiber=e=>{let n=(0,t.traverseFiber)(e,t.isHostFiber);return n||(n=(0,t.traverseFiber)(e,t.isHostFiber,!0)),n},t.getTopMostHostFiber=e=>{let n=null;return(0,t.traverseFiber)(e,(function(e){(0,t.isHostFiber)(e)&&(n=e)}),!0),n},t.getTopMostFiberWithChild=e=>{let n=null;return(0,t.traverseFiber)(e,(function(e){null!=e.child&&(n=e)}),!0),n},t.traverseFiber=(e,n,o=!1)=>{if(!e)return null;if(!0===n(e))return e;let i=o?e.return:e.child;for(;i;){const e=(0,t.traverseFiber)(i,n,o);if(e)return e;i=o?null:i.sibling}return null};const s=["__reactFiber$","__reactInternalInstance$","_reactRootContainer"],r=Object.getOwnPropertyNames.bind(Object);function a(e){var t,n,s,r;const a=null!==(t=e.type)&&void 0!==t?t:e.elementType;let c=null!==(n=null==a?void 0:a.displayName)&&void 0!==n?n:null==a?void 0:a.name;if(null==c)if(null==a?void 0:a.render){const e=null==a?void 0:a.render;c=null!==(s=null==e?void 0:e.displayName)&&void 0!==s?s:null==e?void 0:e.name}else(null==a?void 0:a.type)&&(c=null!==(r=a.type.displayName)&&void 0!==r?r:a.type.name);c||"function"!=typeof a||(c=a.name);const u=(0,o.getMeaningfulName)(l(c));return(0,i.isValidComponentName)(u)?u:null}function l(e){if("string"!=typeof e)return null;if(!e.includes("[")||!e.includes("]"))return e;const t=e.indexOf("["),n=e.indexOf("]");if(t>n)return e;const o=e.substring(t+1,n);return o.startsWith("from ")?o.substring(5):o}},847:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isValidComponentName=function(e){return null!=e&&!n.has(e)};const n=new Set},953:function(e,t,n){var o,i,s,r,a,l,c,u=this&&this.__classPrivateFieldSet||function(e,t,n,o,i){if("m"===o)throw new TypeError("Private method is not writable");if("a"===o&&!i)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===o?i.call(e,n):i?i.value=n:t.set(e,n),n},f=this&&this.__classPrivateFieldGet||function(e,t,n,o){if("a"===n&&!o)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!o:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?o:"a"===n?o.call(e):o?o.value:t.get(e)};Object.defineProperty(t,"__esModule",{value:!0}),t.EventListenerTracker=void 0;const d=n(737),h=n(313);class p{constructor(){o.add(this),i.set(this,void 0),s.set(this,void 0),r.set(this,void 0),a.set(this,void 0),u(this,i,new h.WeakMapPlus({fallback:"noop",cleanupMs:100}),"f"),u(this,s,new Map,"f"),u(this,r,EventTarget.prototype.addEventListener,"f"),u(this,a,EventTarget.prototype.removeEventListener,"f"),f(this,o,"m",l).call(this)}static getInstance(){return p.instance||(p.instance=new p),p.instance}addListener(e,t,n,o){e.addEventListener(t,n,o)}removeListener(e,t,n,o){e.removeEventListener(t,n,o)}scan(e){const t=new Map;for(const[n,o]of f(this,i,"f").entries())if(n instanceof Element&&!n.isConnected)for(const i of o){if(!i.cb.deref())continue;const o=e(new WeakRef(n));t.has(o)||t.set(o,[]);const s=t.get(o);let r=null==s?void 0:s.find((e=>e.type===i.type));r||(r={type:i.type,count:0,entries:[]},null==s||s.push(r)),r.count++,r.entries.push(new WeakRef(i))}return u(this,s,t,"f"),t}getDetachedListeners(){return f(this,s,"f")}destroy(){f(this,o,"m",c).call(this),f(this,i,"f").destroy(),f(this,s,"f").clear(),p.instance=null}}t.EventListenerTracker=p,i=new WeakMap,s=new WeakMap,r=new WeakMap,a=new WeakMap,o=new WeakSet,l=function(){const e=this;EventTarget.prototype.addEventListener=function(t,n,o){var s;if(f(e,r,"f").call(this,t,n,o),this instanceof Element){const r=(0,d.getFiberNodeFromElement)(this),a={type:t,cb:new WeakRef(n),options:o,fiber:r?new WeakRef(r):void 0},l=null!==(s=f(e,i,"f").get(this))&&void 0!==s?s:[];l.push(a),f(e,i,"f").set(this,l)}},EventTarget.prototype.removeEventListener=function(t,n,o){if(f(e,a,"f").call(this,t,n,o),this instanceof Element){const s=f(e,i,"f").get(this);if(s){const r=s.findIndex((e=>e.type===t&&e.cb.deref()===n&&e.options===o));-1!==r&&s.splice(r,1),0===s.length?f(e,i,"f").delete(this):f(e,i,"f").set(this,s)}}}},c=function(){EventTarget.prototype.addEventListener=f(this,r,"f"),EventTarget.prototype.removeEventListener=f(this,a,"f")},p.instance=null}},t={};return function n(o){var i=t[o];if(void 0!==i)return i.exports;var s=t[o]={exports:{}};return e[o].call(s.exports,s,s.exports,n),s.exports}(235)})()));
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @format
8
+ * @oncall memory_lab
9
+ */
10
+ import ReactMemoryScan from './core/react-memory-scan';
11
+ import { CreateOptions } from './core/types';
12
+ export declare function createReactMemoryScan(options?: CreateOptions): ReactMemoryScan;