react-grep 0.2.3 → 0.3.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.
@@ -1,3 +1,3 @@
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;})({});
1
+ var ReactGrep=(function(exports){'use strict';var d=typeof navigator<"u"&&/mac/i.test(navigator.userAgentData?.platform??navigator.userAgent);var g=new Map,I="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",_=[];for(let t=0;t<I.length;t++)_[I.charCodeAt(t)]=t;var y=(t,e)=>{let n=0,i=0;for(;e.i<t.length;){let o=_[t.charCodeAt(e.i++)];if(i+=(o&31)<<n,!(o&32))return i&1?-(i>>1):i>>1;n+=5;}return 0},A=t=>{let e=[],n=0,i=0,o=0;for(let r of t.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+=y(r,l),!(l.i>=r.length||r.charCodeAt(l.i)===44)&&(n+=y(r,l),i+=y(r,l),o+=y(r,l),l.i<r.length&&r.charCodeAt(l.i)!==44&&y(r,l),s.push([a,n,i,o]));}}e.push(s);}return e},K=/^data:application\/json[^,]*;base64,([A-Za-z0-9+/=]+)$/,G=(t,e)=>{try{return new URL(t).origin===new URL(e).origin}catch{return false}},C=async(t,e)=>{if(t.startsWith("data:")){let o=K.exec(t);return o?atob(o[1]):null}let n=new URL(t,e).href;if(!G(e,n))return null;let i=await fetch(n);return i.ok?i.text():null},B=t=>{let e=[],n=[];for(let i of t){let o=A(i.map.mappings),r=i.offset.line,s=i.offset.column,a=e.length;for(;n.length<r+o.length;)n.push([]);for(let l=0;l<o.length;l++){let c=n[r+l];for(let u of o[l])c.push([l===0?u[0]+s:u[0],u[1]+a,u[2],u[3]]);}e.push(...i.map.sources);}for(let i of n)i.length>1&&i.sort((o,r)=>o[0]-r[0]);return {sources:e,mappings:n}},m=t=>{try{let e=JSON.parse(t);return Array.isArray(e.sections)?B(e.sections):!e.sources||!e.mappings?null:{sources:e.sources,mappings:A(e.mappings)}}catch{return null}},X=async t=>{try{let e=await fetch(t),i=(await e.text()).match(/\/\/[#@]\s*sourceMappingURL=([^\s]+)$/m);if(i){let s=await C(i[1].trim(),t);if(s){let a=m(s);if(a)return a}}let o=e.headers.get("SourceMap")??e.headers.get("X-SourceMap");if(o){let s=await C(o.trim(),t);if(s){let a=m(s);if(a)return a}}let r=await fetch(`${t}.map`);if(r.ok){let s=await r.text();return m(s)}return null}catch{return null}},z=/^webpack-internal:\/\/\//,D=/^about:\/\/React\/Server\/file:\/\/\//,$=/^about:\/\/React\/Server\/webpack-internal:\/\/\//,V=/[/\\](\.next[/\\].+?)(?:\?.*)?$/,Y=async t=>{try{let e=decodeURIComponent(t.replace(D,"")),n=V.exec(e);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?m(s):null}catch{return null}},J=async t=>{try{let e=decodeURIComponent(t.replace($,"").replace(/\?.*$/,"")),i=`${typeof location<"u"?location.origin:""}/__nextjs_source-map?filename=${encodeURIComponent(e)}`,o=await fetch(i);if(!o.ok)return null;let r=await o.text();return r?m(r):null}catch{return null}},P=/sourceMappingURL=(data:application\/json[^"'\s\\]+)/g,Z=()=>{if(typeof performance>"u"||!performance.getEntriesByType)return [];let t=new Set,e=[];for(let n of performance.getEntriesByType("resource")){let i=n;!i.name.endsWith(".js")||t.has(i.name)||(t.add(i.name),e.push(i.name));}return e},Q=async t=>{try{let e=Z(),n=`sourceURL=${t}`;for(let i of e){let o=await fetch(i);if(!o.ok)continue;let r=await o.text(),s=r.indexOf(n);if(s===-1)continue;let a=r.substring(Math.max(0,s-2e5),s),l=null,c;for(P.lastIndex=0;(c=P.exec(a))!==null;)l=c[1];if(!l)continue;let u=await C(l,t);if(u)return m(u)}return null}catch{return null}},q=t=>{let e=g.get(t);if(!e){if(g.size>=100){let n=g.keys().next().value;g.delete(n);}$.test(t)?e=J(t):D.test(t)?e=Y(t):z.test(t)?e=Q(t):e=X(t),g.set(t,e);}return e},ee=(t,e,n)=>{if(e<0||e>=t.mappings.length)return null;let i=t.mappings[e];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(t,e,n)=>{let i=await q(t);if(!i)return null;let o=ee(i,e-1,n-1);if(!o)return null;let r=i.sources[o[1]];return r.startsWith("file:///")?r=decodeURIComponent(new URL(r).pathname):r.startsWith("webpack://")&&(r=r.replace(/^webpack:\/\/\/?\.\/?/,"")),r=r.replace(/^(?:\.\.\/)+/,""),{fileName:r,lineNumber:o[2]+1,columnNumber:o[3]+1}};var b=t=>"env"in t&&typeof t.name=="string",k=new Set([0,1,11,14,15]),te=t=>{try{let e=Object.keys(t).find(n=>n.startsWith("__reactFiber$"));return e?t[e]:null}catch{return null}},ne=t=>{let e=t;for(;e;){if(k.has(e.tag))return e;e=e.return;}return null},oe=t=>{if(typeof t=="function")return t;if(t&&typeof t=="object"){if("render"in t&&typeof t.render=="function")return t.render;if("type"in t&&typeof t.type=="function")return t.type}return null},x=t=>{let{type:e}=t;if(typeof e=="function")return e.displayName||e.name||"Anonymous";if(e&&typeof e=="object"){if("displayName"in e&&e.displayName)return e.displayName;let n=oe(e);if(n)return n.displayName||n.name||"Anonymous"}return "Anonymous"},E=new Set(["jsxDEV","jsxs","jsx","createElement","react-stack-top-frame","react_stack_bottom_frame","fakeJSXCallSite"]),ie=/at (?:(.+) \()?(.+):(\d+):(\d+)\)?$/,re=t=>{if(E.has(t))return true;let e=t.lastIndexOf(".");if(e!==-1){let i=t.substring(e+1).replace(/\s*\[.*$/,"");if(E.has(i))return true}let n=/\[as (\w+)\]/.exec(t);return n!==null&&E.has(n[1])},T=t=>{let e=t._debugStack?.stack;if(!e)return null;for(let n of e.split(`
2
+ `)){let i=ie.exec(n.trim());if(!i)continue;let[,o,r,s,a]=i;if(!(o&&re(o))&&!r.includes("/node_modules/"))return {url:r,line:Number(s),column:Number(a)}}return null},M=async t=>{let e=await F(t.url,t.line,t.column);if(e)return e;let n=t.url;try{let i=new URL(t.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:t.line,columnNumber:t.column}},N=async t=>{if(t._debugSource)return t._debugSource;let e=t._debugOwner;if(e&&!b(e)&&e._debugSource)return e._debugSource;let n=T(t);if(n)return M(n);if(e&&!b(e)){let i=T(e);if(i)return M(i)}return null},L=async t=>{if(t._debugSource)return t._debugSource;let e=T(t);return e?M(e):null},R=async t=>{let e=te(t);if(!e)return null;let n=ne(e);if(!n)return null;if(e.return!=null&&k.has(e.return.tag))return {kind:"component",name:x(n),elementTag:null,source:await N(n),callSite:null};let o=e._debugOwner,r=typeof e.type=="string"?e.type:null;return o&&!b(o)&&o===n?{kind:"element",name:x(o),elementTag:r,source:await L(e),callSite:await N(n)}:{kind:"children",name:o&&b(o)?o.name:x(o&&!b(o)&&k.has(o.tag)?o:n),elementTag:r,source:await L(e),callSite:null}};var p={name:"#93c5fd",tag:"#a78bfa",path:"#71717a",pathActive:"#a1a1aa",pathDim:"#3f3f46",hint:"#52525b"},se={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"},le={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)"},O=(t,e)=>{Object.assign(t.style,e);},S=t=>{let e=t.split("/");return e.length<=2?t:`.../${e.slice(-2).join("/")}`},h=(t,e)=>{let n=document.createElement("span");return n.textContent=t,Object.assign(n.style,e),n},v=class{highlight=null;tooltip=null;copiedTimer=null;init(){this.highlight||(this.highlight=document.createElement("div"),this.highlight.dataset.reactGrep="highlight",O(this.highlight,se),document.body.appendChild(this.highlight),this.tooltip=document.createElement("div"),this.tooltip.dataset.reactGrep="tooltip",O(this.tooltip,le),document.body.appendChild(this.tooltip));}show(e,n,i="source"){if(!this.highlight||!this.tooltip)return;let o=e.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(h(n.name,{color:p.name,fontWeight:"600"})),n.elementTag!=null&&(this.tooltip.appendChild(h(" > ",{color:p.path})),this.tooltip.appendChild(h(n.elementTag,{color:p.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 u=i==="source"?p.pathActive:p.pathDim,H=i==="callSite"?p.pathActive:p.pathDim,U=d?"\u21E7":"Shift",j=S(r),W=S(s);this.tooltip.appendChild(h(` ${i==="callSite"?"(":""}${j}${i==="callSite"?")":""}`,{color:u})),this.tooltip.appendChild(h(` ${U} `,{color:p.hint})),this.tooltip.appendChild(h(`${i==="source"?"(":""}${W}${i==="source"?")":""}`,{color:H}));}else r&&this.tooltip.appendChild(h(` ${S(r)}`,{color:p.path}));let a=this.tooltip.getBoundingClientRect(),l=o.top-a.height-6,c=o.left;l<4&&(l=o.bottom+6),c+a.width>window.innerWidth-4&&(c=window.innerWidth-a.width-4),this.tooltip.style.top=`${l}px`,this.tooltip.style.left=`${Math.max(4,c)}px`,this.tooltip.style.display="block";}showCopied(e){this.tooltip&&(this.tooltip.textContent="",this.tooltip.appendChild(h("Copied!",{color:"#4ade80",fontWeight:"600"})),this.tooltip.appendChild(h(` ${S(e)}`,{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 v;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(e){return d?e.metaKey:e.ctrlKey}async handleMouseMove(e){if(!this.isModifierHeld(e)){this.overlay.hide(),this.restoreCursor(),this.lastTarget=null,this.lastInfo=null;return}this.overlay.init(),this.setCrosshairCursor();let n=document.elementFromPoint(e.clientX,e.clientY);if(!n||n.closest("[data-react-grep]"))return;n!==this.lastTarget&&(this.sourceToggled=false);let i=++this.moveGeneration,o=await R(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(e){if(!this.isModifierHeld(e)||!e.shiftKey)return;let n=document.elementFromPoint(e.clientX,e.clientY);if(!n||n.closest("[data-react-grep]"))return;e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),this.shiftPressedClean=false;let i=++this.clickGeneration,o=await R(n);if(i!==this.clickGeneration||!o)return;let r=this.getActiveCopySource(o);if(!r)return;let{fileName:s,lineNumber:a,columnNumber:l}=r,c=l!=null?`${s}:${a}:${l}`:`${s}:${a}`;await this.copyToClipboard(c),this.overlay.showCopied(c);}handleKeyDown(e){e.key==="Shift"&&this.isModifierHeld(e)&&(this.shiftPressedClean=true);}handleKeyUp(e){if(d&&e.key==="Meta"||!d&&e.key==="Control"){this.overlay.hide(),this.restoreCursor(),this.lastTarget=null,this.lastInfo=null;return}e.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(e){return this.sourceToggled&&e.callSite?e.callSite:e.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(e){try{await navigator.clipboard.writeText(e);}catch{}}};var f=null,ae=()=>{f||(f=new w,f.start());},ve=()=>{f&&(f.stop(),f=null);};if(typeof window<"u"){let t=()=>ae();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t):t();}
3
+ exports.destroy=ve;exports.init=ae;return exports;})({});
package/dist/index.js CHANGED
@@ -129,7 +129,9 @@ var fetchAndParse = async (url) => {
129
129
  return null;
130
130
  }
131
131
  };
132
+ var WEBPACK_INTERNAL_RE = /^webpack-internal:\/\/\//;
132
133
  var ABOUT_SERVER_RE = /^about:\/\/React\/Server\/file:\/\/\//;
134
+ var ABOUT_SERVER_WEBPACK_RE = /^about:\/\/React\/Server\/webpack-internal:\/\/\//;
133
135
  var NEXT_DOTDIR_RE = /[/\\](\.next[/\\].+?)(?:\?.*)?$/;
134
136
  var fetchAndParseServerFile = async (url) => {
135
137
  try {
@@ -147,6 +149,59 @@ var fetchAndParseServerFile = async (url) => {
147
149
  return null;
148
150
  }
149
151
  };
152
+ var fetchAndParseServerWebpackInternal = async (url) => {
153
+ try {
154
+ const modulePath = decodeURIComponent(
155
+ url.replace(ABOUT_SERVER_WEBPACK_RE, "").replace(/\?.*$/, "")
156
+ );
157
+ const origin = typeof location !== "undefined" ? location.origin : "";
158
+ const mapUrl = `${origin}/__nextjs_source-map?filename=${encodeURIComponent(modulePath)}`;
159
+ const res = await fetch(mapUrl);
160
+ if (!res.ok) return null;
161
+ const json = await res.text();
162
+ if (!json) return null;
163
+ return parseSourceMap(json);
164
+ } catch {
165
+ return null;
166
+ }
167
+ };
168
+ var WEBPACK_SM_RE = /sourceMappingURL=(data:application\/json[^"'\s\\]+)/g;
169
+ var getScriptUrls = () => {
170
+ if (typeof performance === "undefined" || !performance.getEntriesByType) return [];
171
+ const seen = /* @__PURE__ */ new Set();
172
+ const urls = [];
173
+ for (const entry of performance.getEntriesByType("resource")) {
174
+ const re = entry;
175
+ if (!re.name.endsWith(".js") || seen.has(re.name)) continue;
176
+ seen.add(re.name);
177
+ urls.push(re.name);
178
+ }
179
+ return urls;
180
+ };
181
+ var fetchAndParseWebpackInternal = async (url) => {
182
+ try {
183
+ const scriptUrls = getScriptUrls();
184
+ const marker = `sourceURL=${url}`;
185
+ for (const scriptUrl of scriptUrls) {
186
+ const res = await fetch(scriptUrl);
187
+ if (!res.ok) continue;
188
+ const text = await res.text();
189
+ const markerIdx = text.indexOf(marker);
190
+ if (markerIdx === -1) continue;
191
+ const before = text.substring(Math.max(0, markerIdx - 2e5), markerIdx);
192
+ let lastRef = null;
193
+ let m;
194
+ WEBPACK_SM_RE.lastIndex = 0;
195
+ while ((m = WEBPACK_SM_RE.exec(before)) !== null) lastRef = m[1];
196
+ if (!lastRef) continue;
197
+ const json = await fetchSourceMapJson(lastRef, url);
198
+ if (json) return parseSourceMap(json);
199
+ }
200
+ return null;
201
+ } catch {
202
+ return null;
203
+ }
204
+ };
150
205
  var getSourceMap = (url) => {
151
206
  let promise = cache.get(url);
152
207
  if (!promise) {
@@ -154,7 +209,10 @@ var getSourceMap = (url) => {
154
209
  const oldest = cache.keys().next().value;
155
210
  cache.delete(oldest);
156
211
  }
157
- promise = ABOUT_SERVER_RE.test(url) ? fetchAndParseServerFile(url) : fetchAndParse(url);
212
+ if (ABOUT_SERVER_WEBPACK_RE.test(url)) promise = fetchAndParseServerWebpackInternal(url);
213
+ else if (ABOUT_SERVER_RE.test(url)) promise = fetchAndParseServerFile(url);
214
+ else if (WEBPACK_INTERNAL_RE.test(url)) promise = fetchAndParseWebpackInternal(url);
215
+ else promise = fetchAndParse(url);
158
216
  cache.set(url, promise);
159
217
  }
160
218
  return promise;
@@ -180,7 +238,10 @@ var resolveOriginalPosition = async (url, line, column) => {
180
238
  let fileName = map.sources[seg[1]];
181
239
  if (fileName.startsWith("file:///")) {
182
240
  fileName = decodeURIComponent(new URL(fileName).pathname);
241
+ } else if (fileName.startsWith("webpack://")) {
242
+ fileName = fileName.replace(/^webpack:\/\/\/?\.\/?/, "");
183
243
  }
244
+ fileName = fileName.replace(/^(?:\.\.\/)+/, "");
184
245
  return {
185
246
  fileName,
186
247
  lineNumber: seg[2] + 1,
@@ -243,11 +304,22 @@ var SKIP_FRAMES = /* @__PURE__ */ new Set([
243
304
  "jsxDEV",
244
305
  "jsxs",
245
306
  "jsx",
307
+ "createElement",
246
308
  "react-stack-top-frame",
247
309
  "react_stack_bottom_frame",
248
310
  "fakeJSXCallSite"
249
311
  ]);
250
- var FRAME_RE = /at (?:(\S+) )?\(?(.+):(\d+):(\d+)\)?$/;
312
+ var FRAME_RE = /at (?:(.+) \()?(.+):(\d+):(\d+)\)?$/;
313
+ var isSkippedFn = (name) => {
314
+ if (SKIP_FRAMES.has(name)) return true;
315
+ const dotIdx = name.lastIndexOf(".");
316
+ if (dotIdx !== -1) {
317
+ const base = name.substring(dotIdx + 1).replace(/\s*\[.*$/, "");
318
+ if (SKIP_FRAMES.has(base)) return true;
319
+ }
320
+ const aliasMatch = /\[as (\w+)\]/.exec(name);
321
+ return aliasMatch !== null && SKIP_FRAMES.has(aliasMatch[1]);
322
+ };
251
323
  var parseFirstUserFrame = (fiber) => {
252
324
  const stack = fiber._debugStack?.stack;
253
325
  if (!stack) return null;
@@ -255,7 +327,7 @@ var parseFirstUserFrame = (fiber) => {
255
327
  const match = FRAME_RE.exec(line.trim());
256
328
  if (!match) continue;
257
329
  const [, fnName, url, lineStr, colStr] = match;
258
- if (fnName && SKIP_FRAMES.has(fnName)) continue;
330
+ if (fnName && isSkippedFn(fnName)) continue;
259
331
  if (url.includes("/node_modules/")) continue;
260
332
  return { url, line: Number(lineStr), column: Number(colStr) };
261
333
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-grep",
3
- "version": "0.2.3",
3
+ "version": "0.3.1",
4
4
  "description": "Hold CMD to see React component names + file:line overlaid on any element",
5
5
  "keywords": [
6
6
  "component",
@@ -48,10 +48,16 @@
48
48
  "scripts": {
49
49
  "build": "tsup",
50
50
  "dev": "tsup --watch",
51
- "check-types": "tsc --noEmit"
51
+ "check-types": "tsc --noEmit",
52
+ "test": "vitest run",
53
+ "test:watch": "vitest",
54
+ "test:coverage": "vitest run --coverage"
52
55
  },
53
56
  "devDependencies": {
57
+ "@vitest/coverage-v8": "^4.0.18",
58
+ "jsdom": "^28.0.0",
54
59
  "tsup": "^8.2.4",
55
- "typescript": "^5.7.0"
60
+ "typescript": "^5.7.0",
61
+ "vitest": "^4.0.18"
56
62
  }
57
63
  }