react-grep 0.2.0 → 0.2.2

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.
@@ -1,3 +1,3 @@
1
- var ReactGrep=(function(exports){'use strict';var k=new Map,T="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",P=[];for(let e=0;e<T.length;e++)P[T.charCodeAt(e)]=e;var m=(e,t)=>{let n=0,i=0;for(;t.i<e.length;){let o=P[e.charCodeAt(t.i++)];if(i+=(o&31)<<n,!(o&32))return i&1?-(i>>1):i>>1;n+=5;}return 0},F=e=>{let t=[],n=0,i=0,o=0;for(let r of e.split(";")){let s=[],a=0;if(r){let l={i:0};for(;l.i<r.length;){if(r.charCodeAt(l.i)===44){l.i++;continue}a+=m(r,l),!(l.i>=r.length||r.charCodeAt(l.i)===44)&&(n+=m(r,l),i+=m(r,l),o+=m(r,l),l.i<r.length&&r.charCodeAt(l.i)!==44&&m(r,l),s.push([a,n,i,o]));}}t.push(s);}return t},U=/^data:application\/json[^,]*;base64,([A-Za-z0-9+/=]+)$/,j=(e,t)=>{try{return new URL(e).origin===new URL(t).origin}catch{return false}},I=async(e,t)=>{if(e.startsWith("data:")){let o=U.exec(e);return o?atob(o[1]):null}let n=new URL(e,t).href;if(!j(t,n))return null;let i=await fetch(n);return i.ok?i.text():null},K=e=>{let t=[],n=[];for(let i of e){let o=F(i.map.mappings),r=i.offset.line,s=i.offset.column,a=t.length;for(;n.length<r+o.length;)n.push([]);for(let l=0;l<o.length;l++){let d=n[r+l];for(let h of o[l])d.push([l===0?h[0]+s:h[0],h[1]+a,h[2],h[3]]);}t.push(...i.map.sources);}for(let i of n)i.length>1&&i.sort((o,r)=>o[0]-r[0]);return {sources:t,mappings:n}},f=e=>{try{let t=JSON.parse(e);return Array.isArray(t.sections)?K(t.sections):!t.sources||!t.mappings?null:{sources:t.sources,mappings:F(t.mappings)}}catch{return null}},W=async e=>{try{let t=await fetch(e),i=(await t.text()).match(/\/\/[#@]\s*sourceMappingURL=([^\s]+)$/m);if(i){let s=await I(i[1].trim(),e);if(s){let a=f(s);if(a)return a}}let o=t.headers.get("SourceMap")??t.headers.get("X-SourceMap");if(o){let s=await I(o.trim(),e);if(s){let a=f(s);if(a)return a}}let r=await fetch(`${e}.map`);if(r.ok){let s=await r.text();return f(s)}return null}catch{return null}},R=/^about:\/\/React\/Server\/file:\/\/\//,G=/[/\\](\.next[/\\].+?)(?:\?.*)?$/,X=async e=>{try{let t=decodeURIComponent(e.replace(R,"")),n=G.exec(t);if(!n)return null;let o=`${typeof location<"u"?location.origin:""}/__nextjs_source-map?filename=${encodeURIComponent(n[1])}`,r=await fetch(o);if(!r.ok)return null;let s=await r.text();return s?f(s):null}catch{return null}},z=e=>{let t=k.get(e);return t||(t=R.test(e)?X(e):W(e),k.set(e,t)),t},V=(e,t,n)=>{if(t<0||t>=e.mappings.length)return null;let i=e.mappings[t];if(!i.length)return null;let o=0,r=i.length-1;for(;o<r;){let s=o+r+1>>1;i[s][0]<=n?o=s:r=s-1;}return i[o]},D=async(e,t,n)=>{let i=await z(e);if(!i)return null;let o=V(i,t-1,n-1);if(!o)return null;let r=i.sources[o[1]];return r.startsWith("file:///")&&(r=decodeURIComponent(new URL(r).pathname)),{fileName:r,lineNumber:o[2]+1,columnNumber:o[3]+1}};var g=e=>"env"in e&&typeof e.name=="string",w=new Set([0,1,11,14,15]),Y=e=>{try{let t=Object.keys(e).find(n=>n.startsWith("__reactFiber$"));return t?e[t]:null}catch{return null}},B=e=>{let t=e;for(;t;){if(w.has(t.tag))return t;t=t.return;}return null},J=e=>{if(typeof e=="function")return e;if(e&&typeof e=="object"){if("render"in e&&typeof e.render=="function")return e.render;if("type"in e&&typeof e.type=="function")return e.type}return null},v=e=>{let{type:t}=e;if(typeof t=="function")return t.displayName||t.name||"Anonymous";if(t&&typeof t=="object"){if("displayName"in t&&t.displayName)return t.displayName;let n=J(t);if(n)return n.displayName||n.name||"Anonymous"}return "Anonymous"},Q=new Set(["jsxDEV","jsxs","jsx","react-stack-top-frame","react_stack_bottom_frame","fakeJSXCallSite"]),q=/at (?:(\S+) )?\(?(.+):(\d+):(\d+)\)?$/,C=e=>{let t=e._debugStack?.stack;if(!t)return null;for(let n of t.split(`
2
- `)){let i=q.exec(n.trim());if(!i)continue;let[,o,r,s,a]=i;if(!(o&&Q.has(o))&&!r.includes("/node_modules/"))return {url:r,line:Number(s),column:Number(a)}}return null},x=async e=>{let t=await D(e.url,e.line,e.column);if(t)return t;let n=e.url;try{let i=new URL(e.url);n=decodeURIComponent(i.pathname);let o=n.indexOf("?");o!==-1&&(n=n.substring(0,o));}catch{}return n=n.replace(/\.\.\//g,""),n.startsWith("/")&&(n=n.substring(1)),{fileName:n,lineNumber:e.line,columnNumber:e.column}},$=async e=>{if(e._debugSource)return e._debugSource;let t=e._debugOwner;if(t&&!g(t)&&t._debugSource)return t._debugSource;let n=C(e);if(n)return x(n);if(t&&!g(t)){let i=C(t);if(i)return x(i)}return null},N=async e=>{if(e._debugSource)return e._debugSource;let t=C(e);return t?x(t):null},M=async e=>{let t=Y(e);if(!t)return null;let n=B(t);if(!n)return null;if(t.return!=null&&w.has(t.return.tag))return {kind:"component",name:v(n),elementTag:null,source:await $(n),callSite:null};let o=t._debugOwner,r=typeof t.type=="string"?t.type:null;return o&&!g(o)&&o===n?{kind:"element",name:v(o),elementTag:r,source:await N(t),callSite:await $(n)}:{kind:"children",name:o&&g(o)?o.name:v(o&&!g(o)&&w.has(o.tag)?o:n),elementTag:r,source:await N(t),callSite:null}};var Z=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),c={name:"#93c5fd",tag:"#a78bfa",path:"#71717a",pathActive:"#a1a1aa",pathDim:"#3f3f46",hint:"#52525b"},tt={position:"fixed",pointerEvents:"none",zIndex:"2147483646",backgroundColor:"rgba(66, 135, 245, 0.15)",border:"1.5px solid rgba(66, 135, 245, 0.6)",borderRadius:"3px",display:"none",transition:"top 60ms ease-out, left 60ms ease-out, width 60ms ease-out, height 60ms ease-out"},et={position:"fixed",pointerEvents:"none",zIndex:"2147483647",display:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace",fontSize:"12px",lineHeight:"1.4",color:"#e4e4e7",backgroundColor:"#18181b",border:"1px solid #3f3f46",borderRadius:"6px",padding:"4px 8px",whiteSpace:"nowrap",maxWidth:"500px",overflow:"hidden",textOverflow:"ellipsis",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},_=(e,t)=>{Object.assign(e.style,t);},y=e=>{let t=e.split("/");return t.length<=2?e:`.../${t.slice(-2).join("/")}`},u=(e,t)=>{let n=document.createElement("span");return n.textContent=e,Object.assign(n.style,t),n},b=class{highlight=null;tooltip=null;init(){this.highlight||(this.highlight=document.createElement("div"),this.highlight.dataset.reactGrep="highlight",_(this.highlight,tt),document.body.appendChild(this.highlight),this.tooltip=document.createElement("div"),this.tooltip.dataset.reactGrep="tooltip",_(this.tooltip,et),document.body.appendChild(this.tooltip));}show(t,n,i="source"){if(!this.highlight||!this.tooltip)return;let o=t.getBoundingClientRect();this.highlight.style.top=`${o.top}px`,this.highlight.style.left=`${o.left}px`,this.highlight.style.width=`${o.width}px`,this.highlight.style.height=`${o.height}px`,this.highlight.style.display="block",this.tooltip.textContent="",this.tooltip.appendChild(u(n.name,{color:c.name,fontWeight:"600"})),n.elementTag!=null&&(this.tooltip.appendChild(u(" > ",{color:c.path})),this.tooltip.appendChild(u(n.elementTag,{color:c.tag,fontWeight:"600"})));let r=n.source?`${n.source.fileName}:${n.source.lineNumber}`:null,s=n.callSite?`${n.callSite.fileName}:${n.callSite.lineNumber}`:null;if(r&&s){let h=i==="source"?c.pathActive:c.pathDim,A=i==="callSite"?c.pathActive:c.pathDim,L=Z?"\u21E7":"Shift",O=y(r),H=y(s);this.tooltip.appendChild(u(` ${i==="callSite"?"(":""}${O}${i==="callSite"?")":""}`,{color:h})),this.tooltip.appendChild(u(` ${L} `,{color:c.hint})),this.tooltip.appendChild(u(`${i==="source"?"(":""}${H}${i==="source"?")":""}`,{color:A}));}else r&&this.tooltip.appendChild(u(` ${y(r)}`,{color:c.path}));let a=this.tooltip.getBoundingClientRect(),l=o.top-a.height-6,d=o.left;l<4&&(l=o.bottom+6),d+a.width>window.innerWidth-4&&(d=window.innerWidth-a.width-4),this.tooltip.style.top=`${l}px`,this.tooltip.style.left=`${Math.max(4,d)}px`,this.tooltip.style.display="block";}showCopied(t){this.tooltip&&(this.tooltip.textContent="",this.tooltip.appendChild(u("Copied!",{color:"#4ade80",fontWeight:"600"})),this.tooltip.appendChild(u(` ${y(t)}`,{color:"#a1a1aa"})),this.tooltip.style.display="block",setTimeout(()=>this.hide(),1500));}hide(){this.highlight&&(this.highlight.style.display="none"),this.tooltip&&(this.tooltip.style.display="none");}destroy(){this.highlight?.remove(),this.tooltip?.remove(),this.highlight=null,this.tooltip=null;}};var E=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform),S=class{overlay=new b;moveGeneration=0;lastTarget=null;lastInfo=null;sourceToggled=false;shiftPressedClean=false;boundHandlers;constructor(){this.boundHandlers={mousemove:this.handleMouseMove.bind(this),click:this.handleClick.bind(this),keydown:this.handleKeyDown.bind(this),keyup:this.handleKeyUp.bind(this)};}start(){window.addEventListener("mousemove",this.boundHandlers.mousemove),window.addEventListener("click",this.boundHandlers.click,true),window.addEventListener("keydown",this.boundHandlers.keydown),window.addEventListener("keyup",this.boundHandlers.keyup);}stop(){window.removeEventListener("mousemove",this.boundHandlers.mousemove),window.removeEventListener("click",this.boundHandlers.click,true),window.removeEventListener("keydown",this.boundHandlers.keydown),window.removeEventListener("keyup",this.boundHandlers.keyup),this.overlay.destroy(),document.body.style.cursor="",this.lastTarget=null,this.lastInfo=null,this.sourceToggled=false,this.shiftPressedClean=false;}isModifierHeld(t){return E?t.metaKey:t.ctrlKey}async handleMouseMove(t){if(!this.isModifierHeld(t)){this.overlay.hide(),document.body.style.cursor="",this.lastTarget=null,this.lastInfo=null;return}this.overlay.init(),document.body.style.cursor="crosshair";let n=document.elementFromPoint(t.clientX,t.clientY);if(!n||n.closest("[data-react-grep]"))return;n!==this.lastTarget&&(this.sourceToggled=false);let i=++this.moveGeneration,o=await M(n);if(i===this.moveGeneration){if(!o){this.overlay.hide(),this.lastTarget=null,this.lastInfo=null;return}this.lastTarget=n,this.lastInfo=o,this.overlay.show(n,o,this.getActiveSource());}}async handleClick(t){if(!this.isModifierHeld(t)||!t.shiftKey)return;let n=document.elementFromPoint(t.clientX,t.clientY);if(!n||n.closest("[data-react-grep]"))return;t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),this.shiftPressedClean=false;let i=await M(n);if(!i)return;let o=this.getActiveCopySource(i);if(!o)return;let{fileName:r,lineNumber:s,columnNumber:a}=o,l=a!=null?`${r}:${s}:${a}`:`${r}:${s}`;await this.copyToClipboard(l),this.overlay.showCopied(l);}handleKeyDown(t){t.key==="Shift"&&this.isModifierHeld(t)&&(this.shiftPressedClean=true);}handleKeyUp(t){if(E&&t.key==="Meta"||!E&&t.key==="Control"){this.overlay.hide(),document.body.style.cursor="",this.lastTarget=null,this.lastInfo=null;return}t.key==="Shift"&&this.shiftPressedClean&&this.lastTarget&&this.lastInfo&&this.lastInfo.callSite&&(this.sourceToggled=!this.sourceToggled,this.overlay.show(this.lastTarget,this.lastInfo,this.getActiveSource())),this.shiftPressedClean=false;}getActiveSource(){return this.sourceToggled?"callSite":"source"}getActiveCopySource(t){return this.sourceToggled&&t.callSite?t.callSite:t.source}async copyToClipboard(t){try{await navigator.clipboard.writeText(t);}catch{}}};var p=null,nt=()=>{p||(p=new S,p.start());},ht=()=>{p&&(p.stop(),p=null);};if(typeof window<"u"){let e=()=>nt();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e();}
3
- exports.destroy=ht;exports.init=nt;return exports;})({});
1
+ var ReactGrep=(function(exports){'use strict';var d=typeof navigator<"u"&&/mac/i.test(navigator.userAgentData?.platform??navigator.userAgent);var g=new Map,M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",R=[];for(let e=0;e<M.length;e++)R[M.charCodeAt(e)]=e;var f=(e,t)=>{let n=0,i=0;for(;t.i<e.length;){let o=R[e.charCodeAt(t.i++)];if(i+=(o&31)<<n,!(o&32))return i&1?-(i>>1):i>>1;n+=5;}return 0},D=e=>{let t=[],n=0,i=0,o=0;for(let r of e.split(";")){let s=[],a=0;if(r){let l={i:0};for(;l.i<r.length;){if(r.charCodeAt(l.i)===44){l.i++;continue}a+=f(r,l),!(l.i>=r.length||r.charCodeAt(l.i)===44)&&(n+=f(r,l),i+=f(r,l),o+=f(r,l),l.i<r.length&&r.charCodeAt(l.i)!==44&&f(r,l),s.push([a,n,i,o]));}}t.push(s);}return t},U=/^data:application\/json[^,]*;base64,([A-Za-z0-9+/=]+)$/,j=(e,t)=>{try{return new URL(e).origin===new URL(t).origin}catch{return false}},I=async(e,t)=>{if(e.startsWith("data:")){let o=U.exec(e);return o?atob(o[1]):null}let n=new URL(e,t).href;if(!j(t,n))return null;let i=await fetch(n);return i.ok?i.text():null},K=e=>{let t=[],n=[];for(let i of e){let o=D(i.map.mappings),r=i.offset.line,s=i.offset.column,a=t.length;for(;n.length<r+o.length;)n.push([]);for(let l=0;l<o.length;l++){let h=n[r+l];for(let p of o[l])h.push([l===0?p[0]+s:p[0],p[1]+a,p[2],p[3]]);}t.push(...i.map.sources);}for(let i of n)i.length>1&&i.sort((o,r)=>o[0]-r[0]);return {sources:t,mappings:n}},b=e=>{try{let t=JSON.parse(e);return Array.isArray(t.sections)?K(t.sections):!t.sources||!t.mappings?null:{sources:t.sources,mappings:D(t.mappings)}}catch{return null}},G=async e=>{try{let t=await fetch(e),i=(await t.text()).match(/\/\/[#@]\s*sourceMappingURL=([^\s]+)$/m);if(i){let s=await I(i[1].trim(),e);if(s){let a=b(s);if(a)return a}}let o=t.headers.get("SourceMap")??t.headers.get("X-SourceMap");if(o){let s=await I(o.trim(),e);if(s){let a=b(s);if(a)return a}}let r=await fetch(`${e}.map`);if(r.ok){let s=await r.text();return b(s)}return null}catch{return null}},A=/^about:\/\/React\/Server\/file:\/\/\//,W=/[/\\](\.next[/\\].+?)(?:\?.*)?$/,X=async e=>{try{let t=decodeURIComponent(e.replace(A,"")),n=W.exec(t);if(!n)return null;let o=`${typeof location<"u"?location.origin:""}/__nextjs_source-map?filename=${encodeURIComponent(n[1])}`,r=await fetch(o);if(!r.ok)return null;let s=await r.text();return s?b(s):null}catch{return null}},z=e=>{let t=g.get(e);if(!t){if(g.size>=100){let n=g.keys().next().value;g.delete(n);}t=A.test(e)?X(e):G(e),g.set(e,t);}return t},V=(e,t,n)=>{if(t<0||t>=e.mappings.length)return null;let i=e.mappings[t];if(!i.length)return null;let o=0,r=i.length-1;for(;o<r;){let s=o+r+1>>1;i[s][0]<=n?o=s:r=s-1;}return i[o]},F=async(e,t,n)=>{let i=await z(e);if(!i)return null;let o=V(i,t-1,n-1);if(!o)return null;let r=i.sources[o[1]];return r.startsWith("file:///")&&(r=decodeURIComponent(new URL(r).pathname)),{fileName:r,lineNumber:o[2]+1,columnNumber:o[3]+1}};var y=e=>"env"in e&&typeof e.name=="string",x=new Set([0,1,11,14,15]),Y=e=>{try{let t=Object.keys(e).find(n=>n.startsWith("__reactFiber$"));return t?e[t]:null}catch{return null}},B=e=>{let t=e;for(;t;){if(x.has(t.tag))return t;t=t.return;}return null},J=e=>{if(typeof e=="function")return e;if(e&&typeof e=="object"){if("render"in e&&typeof e.render=="function")return e.render;if("type"in e&&typeof e.type=="function")return e.type}return null},C=e=>{let{type:t}=e;if(typeof t=="function")return t.displayName||t.name||"Anonymous";if(t&&typeof t=="object"){if("displayName"in t&&t.displayName)return t.displayName;let n=J(t);if(n)return n.displayName||n.name||"Anonymous"}return "Anonymous"},Z=new Set(["jsxDEV","jsxs","jsx","react-stack-top-frame","react_stack_bottom_frame","fakeJSXCallSite"]),Q=/at (?:(\S+) )?\(?(.+):(\d+):(\d+)\)?$/,T=e=>{let t=e._debugStack?.stack;if(!t)return null;for(let n of t.split(`
2
+ `)){let i=Q.exec(n.trim());if(!i)continue;let[,o,r,s,a]=i;if(!(o&&Z.has(o))&&!r.includes("/node_modules/"))return {url:r,line:Number(s),column:Number(a)}}return null},k=async e=>{let t=await F(e.url,e.line,e.column);if(t)return t;let n=e.url;try{let i=new URL(e.url);n=decodeURIComponent(i.pathname);let o=n.indexOf("?");o!==-1&&(n=n.substring(0,o));}catch{}return n=n.replace(/\.\.\//g,""),n.startsWith("/")&&(n=n.substring(1)),{fileName:n,lineNumber:e.line,columnNumber:e.column}},P=async e=>{if(e._debugSource)return e._debugSource;let t=e._debugOwner;if(t&&!y(t)&&t._debugSource)return t._debugSource;let n=T(e);if(n)return k(n);if(t&&!y(t)){let i=T(t);if(i)return k(i)}return null},_=async e=>{if(e._debugSource)return e._debugSource;let t=T(e);return t?k(t):null},E=async e=>{let t=Y(e);if(!t)return null;let n=B(t);if(!n)return null;if(t.return!=null&&x.has(t.return.tag))return {kind:"component",name:C(n),elementTag:null,source:await P(n),callSite:null};let o=t._debugOwner,r=typeof t.type=="string"?t.type:null;return o&&!y(o)&&o===n?{kind:"element",name:C(o),elementTag:r,source:await _(t),callSite:await P(n)}:{kind:"children",name:o&&y(o)?o.name:C(o&&!y(o)&&x.has(o.tag)?o:n),elementTag:r,source:await _(t),callSite:null}};var c={name:"#93c5fd",tag:"#a78bfa",path:"#71717a",pathActive:"#a1a1aa",pathDim:"#3f3f46",hint:"#52525b"},q={position:"fixed",pointerEvents:"none",zIndex:"2147483646",backgroundColor:"rgba(66, 135, 245, 0.15)",border:"1.5px solid rgba(66, 135, 245, 0.6)",borderRadius:"3px",display:"none",transition:"top 60ms ease-out, left 60ms ease-out, width 60ms ease-out, height 60ms ease-out"},tt={position:"fixed",pointerEvents:"none",zIndex:"2147483647",display:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace",fontSize:"12px",lineHeight:"1.4",color:"#e4e4e7",backgroundColor:"#18181b",border:"1px solid #3f3f46",borderRadius:"6px",padding:"4px 8px",whiteSpace:"nowrap",maxWidth:"500px",overflow:"hidden",textOverflow:"ellipsis",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.4)"},$=(e,t)=>{Object.assign(e.style,t);},v=e=>{let t=e.split("/");return t.length<=2?e:`.../${t.slice(-2).join("/")}`},u=(e,t)=>{let n=document.createElement("span");return n.textContent=e,Object.assign(n.style,t),n},S=class{highlight=null;tooltip=null;copiedTimer=null;init(){this.highlight||(this.highlight=document.createElement("div"),this.highlight.dataset.reactGrep="highlight",$(this.highlight,q),document.body.appendChild(this.highlight),this.tooltip=document.createElement("div"),this.tooltip.dataset.reactGrep="tooltip",$(this.tooltip,tt),document.body.appendChild(this.tooltip));}show(t,n,i="source"){if(!this.highlight||!this.tooltip)return;let o=t.getBoundingClientRect();this.highlight.style.top=`${o.top}px`,this.highlight.style.left=`${o.left}px`,this.highlight.style.width=`${o.width}px`,this.highlight.style.height=`${o.height}px`,this.highlight.style.display="block",this.tooltip.textContent="",this.tooltip.appendChild(u(n.name,{color:c.name,fontWeight:"600"})),n.elementTag!=null&&(this.tooltip.appendChild(u(" > ",{color:c.path})),this.tooltip.appendChild(u(n.elementTag,{color:c.tag,fontWeight:"600"})));let r=n.source?`${n.source.fileName}:${n.source.lineNumber}`:null,s=n.callSite?`${n.callSite.fileName}:${n.callSite.lineNumber}`:null;if(r&&s){let p=i==="source"?c.pathActive:c.pathDim,N=i==="callSite"?c.pathActive:c.pathDim,L=d?"\u21E7":"Shift",H=v(r),O=v(s);this.tooltip.appendChild(u(` ${i==="callSite"?"(":""}${H}${i==="callSite"?")":""}`,{color:p})),this.tooltip.appendChild(u(` ${L} `,{color:c.hint})),this.tooltip.appendChild(u(`${i==="source"?"(":""}${O}${i==="source"?")":""}`,{color:N}));}else r&&this.tooltip.appendChild(u(` ${v(r)}`,{color:c.path}));let a=this.tooltip.getBoundingClientRect(),l=o.top-a.height-6,h=o.left;l<4&&(l=o.bottom+6),h+a.width>window.innerWidth-4&&(h=window.innerWidth-a.width-4),this.tooltip.style.top=`${l}px`,this.tooltip.style.left=`${Math.max(4,h)}px`,this.tooltip.style.display="block";}showCopied(t){this.tooltip&&(this.tooltip.textContent="",this.tooltip.appendChild(u("Copied!",{color:"#4ade80",fontWeight:"600"})),this.tooltip.appendChild(u(` ${v(t)}`,{color:"#a1a1aa"})),this.tooltip.style.display="block",this.copiedTimer&&clearTimeout(this.copiedTimer),this.copiedTimer=setTimeout(()=>this.hide(),1500));}hide(){this.highlight&&(this.highlight.style.display="none"),this.tooltip&&(this.tooltip.style.display="none");}destroy(){this.copiedTimer&&(clearTimeout(this.copiedTimer),this.copiedTimer=null),this.highlight?.remove(),this.tooltip?.remove(),this.highlight=null,this.tooltip=null;}};var w=class{overlay=new S;moveGeneration=0;clickGeneration=0;lastTarget=null;lastInfo=null;sourceToggled=false;shiftPressedClean=false;savedCursor="";boundHandlers;constructor(){this.boundHandlers={mousemove:this.handleMouseMove.bind(this),click:this.handleClick.bind(this),keydown:this.handleKeyDown.bind(this),keyup:this.handleKeyUp.bind(this)};}start(){window.addEventListener("mousemove",this.boundHandlers.mousemove),window.addEventListener("click",this.boundHandlers.click,true),window.addEventListener("keydown",this.boundHandlers.keydown),window.addEventListener("keyup",this.boundHandlers.keyup);}stop(){window.removeEventListener("mousemove",this.boundHandlers.mousemove),window.removeEventListener("click",this.boundHandlers.click,true),window.removeEventListener("keydown",this.boundHandlers.keydown),window.removeEventListener("keyup",this.boundHandlers.keyup),this.overlay.destroy(),this.restoreCursor(),this.lastTarget=null,this.lastInfo=null,this.sourceToggled=false,this.shiftPressedClean=false;}isModifierHeld(t){return d?t.metaKey:t.ctrlKey}async handleMouseMove(t){if(!this.isModifierHeld(t)){this.overlay.hide(),this.restoreCursor(),this.lastTarget=null,this.lastInfo=null;return}this.overlay.init(),this.setCrosshairCursor();let n=document.elementFromPoint(t.clientX,t.clientY);if(!n||n.closest("[data-react-grep]"))return;n!==this.lastTarget&&(this.sourceToggled=false);let i=++this.moveGeneration,o=await E(n);if(i===this.moveGeneration){if(!o){this.overlay.hide(),this.lastTarget=null,this.lastInfo=null;return}this.lastTarget=n,this.lastInfo=o,this.overlay.show(n,o,this.getActiveSource());}}async handleClick(t){if(!this.isModifierHeld(t)||!t.shiftKey)return;let n=document.elementFromPoint(t.clientX,t.clientY);if(!n||n.closest("[data-react-grep]"))return;t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation(),this.shiftPressedClean=false;let i=++this.clickGeneration,o=await E(n);if(i!==this.clickGeneration||!o)return;let r=this.getActiveCopySource(o);if(!r)return;let{fileName:s,lineNumber:a,columnNumber:l}=r,h=l!=null?`${s}:${a}:${l}`:`${s}:${a}`;await this.copyToClipboard(h),this.overlay.showCopied(h);}handleKeyDown(t){t.key==="Shift"&&this.isModifierHeld(t)&&(this.shiftPressedClean=true);}handleKeyUp(t){if(d&&t.key==="Meta"||!d&&t.key==="Control"){this.overlay.hide(),this.restoreCursor(),this.lastTarget=null,this.lastInfo=null;return}t.key==="Shift"&&this.shiftPressedClean&&this.lastTarget&&this.lastInfo&&this.lastInfo.callSite&&(this.sourceToggled=!this.sourceToggled,this.overlay.show(this.lastTarget,this.lastInfo,this.getActiveSource())),this.shiftPressedClean=false;}getActiveSource(){return this.sourceToggled?"callSite":"source"}getActiveCopySource(t){return this.sourceToggled&&t.callSite?t.callSite:t.source}setCrosshairCursor(){document.body.style.cursor!=="crosshair"&&(this.savedCursor=document.body.style.cursor,document.body.style.cursor="crosshair");}restoreCursor(){document.body.style.cursor==="crosshair"&&(document.body.style.cursor=this.savedCursor);}async copyToClipboard(t){try{await navigator.clipboard.writeText(t);}catch{}}};var m=null,et=()=>{m||(m=new w,m.start());},dt=()=>{m&&(m.stop(),m=null);};if(typeof window<"u"){let e=()=>et();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",e):e();}
3
+ exports.destroy=dt;exports.init=et;return exports;})({});
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
+ // src/env.ts
2
+ var isMac = typeof navigator !== "undefined" && /mac/i.test(
3
+ navigator.userAgentData?.platform ?? navigator.userAgent
4
+ );
5
+
1
6
  // src/source-map.ts
7
+ var MAX_CACHE_SIZE = 100;
2
8
  var cache = /* @__PURE__ */ new Map();
3
9
  var VLQ_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4
10
  var charToInt = [];
@@ -144,6 +150,10 @@ var fetchAndParseServerFile = async (url) => {
144
150
  var getSourceMap = (url) => {
145
151
  let promise = cache.get(url);
146
152
  if (!promise) {
153
+ if (cache.size >= MAX_CACHE_SIZE) {
154
+ const oldest = cache.keys().next().value;
155
+ cache.delete(oldest);
156
+ }
147
157
  promise = ABOUT_SERVER_RE.test(url) ? fetchAndParseServerFile(url) : fetchAndParse(url);
148
158
  cache.set(url, promise);
149
159
  }
@@ -212,10 +222,8 @@ var getCompositeComponentFiber = (fiber) => {
212
222
  var getInnerFunction = (type) => {
213
223
  if (typeof type === "function") return type;
214
224
  if (type && typeof type === "object") {
215
- if ("render" in type && typeof type.render === "function")
216
- return type.render;
217
- if ("type" in type && typeof type.type === "function")
218
- return type.type;
225
+ if ("render" in type && typeof type.render === "function") return type.render;
226
+ if ("type" in type && typeof type.type === "function") return type.type;
219
227
  }
220
228
  return null;
221
229
  };
@@ -325,7 +333,6 @@ var getComponentInfo = async (el) => {
325
333
  };
326
334
 
327
335
  // src/overlay.ts
328
- var isMac = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
329
336
  var COLORS = {
330
337
  name: "#93c5fd",
331
338
  tag: "#a78bfa",
@@ -380,6 +387,7 @@ var createSpan = (text, styles) => {
380
387
  var OverlayManager = class {
381
388
  highlight = null;
382
389
  tooltip = null;
390
+ copiedTimer = null;
383
391
  init() {
384
392
  if (this.highlight) return;
385
393
  this.highlight = document.createElement("div");
@@ -450,13 +458,18 @@ var OverlayManager = class {
450
458
  this.tooltip.appendChild(createSpan("Copied!", { color: "#4ade80", fontWeight: "600" }));
451
459
  this.tooltip.appendChild(createSpan(` ${truncatePath(location2)}`, { color: "#a1a1aa" }));
452
460
  this.tooltip.style.display = "block";
453
- setTimeout(() => this.hide(), 1500);
461
+ if (this.copiedTimer) clearTimeout(this.copiedTimer);
462
+ this.copiedTimer = setTimeout(() => this.hide(), 1500);
454
463
  }
455
464
  hide() {
456
465
  if (this.highlight) this.highlight.style.display = "none";
457
466
  if (this.tooltip) this.tooltip.style.display = "none";
458
467
  }
459
468
  destroy() {
469
+ if (this.copiedTimer) {
470
+ clearTimeout(this.copiedTimer);
471
+ this.copiedTimer = null;
472
+ }
460
473
  this.highlight?.remove();
461
474
  this.tooltip?.remove();
462
475
  this.highlight = null;
@@ -465,14 +478,15 @@ var OverlayManager = class {
465
478
  };
466
479
 
467
480
  // src/inspector.ts
468
- var isMac2 = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform);
469
481
  var Inspector = class {
470
482
  overlay = new OverlayManager();
471
483
  moveGeneration = 0;
484
+ clickGeneration = 0;
472
485
  lastTarget = null;
473
486
  lastInfo = null;
474
487
  sourceToggled = false;
475
488
  shiftPressedClean = false;
489
+ savedCursor = "";
476
490
  boundHandlers;
477
491
  constructor() {
478
492
  this.boundHandlers = {
@@ -494,25 +508,25 @@ var Inspector = class {
494
508
  window.removeEventListener("keydown", this.boundHandlers.keydown);
495
509
  window.removeEventListener("keyup", this.boundHandlers.keyup);
496
510
  this.overlay.destroy();
497
- document.body.style.cursor = "";
511
+ this.restoreCursor();
498
512
  this.lastTarget = null;
499
513
  this.lastInfo = null;
500
514
  this.sourceToggled = false;
501
515
  this.shiftPressedClean = false;
502
516
  }
503
517
  isModifierHeld(e) {
504
- return isMac2 ? e.metaKey : e.ctrlKey;
518
+ return isMac ? e.metaKey : e.ctrlKey;
505
519
  }
506
520
  async handleMouseMove(e) {
507
521
  if (!this.isModifierHeld(e)) {
508
522
  this.overlay.hide();
509
- document.body.style.cursor = "";
523
+ this.restoreCursor();
510
524
  this.lastTarget = null;
511
525
  this.lastInfo = null;
512
526
  return;
513
527
  }
514
528
  this.overlay.init();
515
- document.body.style.cursor = "crosshair";
529
+ this.setCrosshairCursor();
516
530
  const target = document.elementFromPoint(e.clientX, e.clientY);
517
531
  if (!target || target.closest("[data-react-grep]")) return;
518
532
  if (target !== this.lastTarget) {
@@ -539,8 +553,9 @@ var Inspector = class {
539
553
  e.stopPropagation();
540
554
  e.stopImmediatePropagation();
541
555
  this.shiftPressedClean = false;
556
+ const gen = ++this.clickGeneration;
542
557
  const info = await getComponentInfo(target);
543
- if (!info) return;
558
+ if (gen !== this.clickGeneration || !info) return;
544
559
  const source = this.getActiveCopySource(info);
545
560
  if (!source) return;
546
561
  const { fileName, lineNumber, columnNumber } = source;
@@ -554,9 +569,9 @@ var Inspector = class {
554
569
  }
555
570
  }
556
571
  handleKeyUp(e) {
557
- if (isMac2 && e.key === "Meta" || !isMac2 && e.key === "Control") {
572
+ if (isMac && e.key === "Meta" || !isMac && e.key === "Control") {
558
573
  this.overlay.hide();
559
- document.body.style.cursor = "";
574
+ this.restoreCursor();
560
575
  this.lastTarget = null;
561
576
  this.lastInfo = null;
562
577
  return;
@@ -573,6 +588,17 @@ var Inspector = class {
573
588
  getActiveCopySource(info) {
574
589
  return this.sourceToggled && info.callSite ? info.callSite : info.source;
575
590
  }
591
+ setCrosshairCursor() {
592
+ if (document.body.style.cursor !== "crosshair") {
593
+ this.savedCursor = document.body.style.cursor;
594
+ document.body.style.cursor = "crosshair";
595
+ }
596
+ }
597
+ restoreCursor() {
598
+ if (document.body.style.cursor === "crosshair") {
599
+ document.body.style.cursor = this.savedCursor;
600
+ }
601
+ }
576
602
  async copyToClipboard(text) {
577
603
  try {
578
604
  await navigator.clipboard.writeText(text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-grep",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Hold CMD to see React component names + file:line overlaid on any element",
5
5
  "keywords": [
6
6
  "component",
@@ -12,7 +12,7 @@
12
12
  "react",
13
13
  "source"
14
14
  ],
15
- "homepage": "https://github.com/maxmurr/react-grep",
15
+ "homepage": "https://react-grep.com",
16
16
  "bugs": {
17
17
  "url": "https://github.com/maxmurr/react-grep/issues"
18
18
  },
@@ -37,6 +37,7 @@
37
37
  "./package.json": "./package.json",
38
38
  ".": {
39
39
  "types": "./dist/index.d.ts",
40
+ "import": "./dist/index.js",
40
41
  "default": "./dist/index.js"
41
42
  }
42
43
  },