react-grep 0.3.0 → 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 f=new Map,R="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",P=[];for(let t=0;t<R.length;t++)P[R.charCodeAt(t)]=t;var g=(t,e)=>{let n=0,i=0;for(;e.i<t.length;){let o=P[t.charCodeAt(e.i++)];if(i+=(o&31)<<n,!(o&32))return i&1?-(i>>1):i>>1;n+=5;}return 0},D=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+=g(r,l),!(l.i>=r.length||r.charCodeAt(l.i)===44)&&(n+=g(r,l),i+=g(r,l),o+=g(r,l),l.i<r.length&&r.charCodeAt(l.i)!==44&&g(r,l),s.push([a,n,i,o]));}}e.push(s);}return e},K=/^data:application\/json[^,]*;base64,([A-Za-z0-9+/=]+)$/,W=(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(!W(e,n))return null;let i=await fetch(n);return i.ok?i.text():null},G=t=>{let e=[],n=[];for(let i of t){let o=D(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}},y=t=>{try{let e=JSON.parse(t);return Array.isArray(e.sections)?G(e.sections):!e.sources||!e.mappings?null:{sources:e.sources,mappings:D(e.mappings)}}catch{return null}},B=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=y(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=y(s);if(a)return a}}let r=await fetch(`${t}.map`);if(r.ok){let s=await r.text();return y(s)}return null}catch{return null}},X=/^webpack-internal:\/\/\//,_=/^about:\/\/React\/Server\/file:\/\/\//,z=/[/\\](\.next[/\\].+?)(?:\?.*)?$/,V=async t=>{try{let e=decodeURIComponent(t.replace(_,"")),n=z.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?y(s):null}catch{return null}},A=/sourceMappingURL=(data:application\/json[^"'\s\\]+)/g,Y=()=>{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},J=async t=>{try{let e=Y(),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(A.lastIndex=0;(c=A.exec(a))!==null;)l=c[1];if(!l)continue;let u=await C(l,t);if(u)return y(u)}return null}catch{return null}},Z=t=>{let e=f.get(t);if(!e){if(f.size>=100){let n=f.keys().next().value;f.delete(n);}_.test(t)?e=V(t):X.test(t)?e=J(t):e=B(t),f.set(t,e);}return e},Q=(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 Z(t);if(!i)return null;let o=Q(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=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]),q=t=>{try{let e=Object.keys(t).find(n=>n.startsWith("__reactFiber$"));return e?t[e]:null}catch{return null}},ee=t=>{let e=t;for(;e;){if(k.has(e.tag))return e;e=e.return;}return null},te=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=te(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"]),ne=/at (?:(.+) \()?(.+):(\d+):(\d+)\)?$/,oe=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=ne.exec(n.trim());if(!i)continue;let[,o,r,s,a]=i;if(!(o&&oe(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}},$=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},N=async t=>{if(t._debugSource)return t._debugSource;let e=T(t);return e?M(e):null},I=async t=>{let e=q(t);if(!e)return null;let n=ee(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),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 N(e),callSite:await $(n)}:{kind:"children",name:o&&b(o)?o.name:x(o&&!b(o)&&k.has(o.tag)?o:n),elementTag:r,source:await N(e),callSite:null}};var p={name:"#93c5fd",tag:"#a78bfa",path:"#71717a",pathActive:"#a1a1aa",pathDim:"#3f3f46",hint:"#52525b"},ie={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"},re={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)"},L=(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",L(this.highlight,ie),document.body.appendChild(this.highlight),this.tooltip=document.createElement("div"),this.tooltip.dataset.reactGrep="tooltip",L(this.tooltip,re),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,O=i==="callSite"?p.pathActive:p.pathDim,H=d?"\u21E7":"Shift",U=S(r),j=S(s);this.tooltip.appendChild(h(` ${i==="callSite"?"(":""}${U}${i==="callSite"?")":""}`,{color:u})),this.tooltip.appendChild(h(` ${H} `,{color:p.hint})),this.tooltip.appendChild(h(`${i==="source"?"(":""}${j}${i==="source"?")":""}`,{color:O}));}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 I(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 I(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 m=null,se=()=>{m||(m=new w,m.start());},be=()=>{m&&(m.stop(),m=null);};if(typeof window<"u"){let t=()=>se();document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t):t();}
3
- exports.destroy=be;exports.init=se;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
@@ -131,6 +131,7 @@ var fetchAndParse = async (url) => {
131
131
  };
132
132
  var WEBPACK_INTERNAL_RE = /^webpack-internal:\/\/\//;
133
133
  var ABOUT_SERVER_RE = /^about:\/\/React\/Server\/file:\/\/\//;
134
+ var ABOUT_SERVER_WEBPACK_RE = /^about:\/\/React\/Server\/webpack-internal:\/\/\//;
134
135
  var NEXT_DOTDIR_RE = /[/\\](\.next[/\\].+?)(?:\?.*)?$/;
135
136
  var fetchAndParseServerFile = async (url) => {
136
137
  try {
@@ -148,6 +149,22 @@ var fetchAndParseServerFile = async (url) => {
148
149
  return null;
149
150
  }
150
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
+ };
151
168
  var WEBPACK_SM_RE = /sourceMappingURL=(data:application\/json[^"'\s\\]+)/g;
152
169
  var getScriptUrls = () => {
153
170
  if (typeof performance === "undefined" || !performance.getEntriesByType) return [];
@@ -192,7 +209,8 @@ var getSourceMap = (url) => {
192
209
  const oldest = cache.keys().next().value;
193
210
  cache.delete(oldest);
194
211
  }
195
- if (ABOUT_SERVER_RE.test(url)) promise = fetchAndParseServerFile(url);
212
+ if (ABOUT_SERVER_WEBPACK_RE.test(url)) promise = fetchAndParseServerWebpackInternal(url);
213
+ else if (ABOUT_SERVER_RE.test(url)) promise = fetchAndParseServerFile(url);
196
214
  else if (WEBPACK_INTERNAL_RE.test(url)) promise = fetchAndParseWebpackInternal(url);
197
215
  else promise = fetchAndParse(url);
198
216
  cache.set(url, promise);
@@ -220,6 +238,8 @@ var resolveOriginalPosition = async (url, line, column) => {
220
238
  let fileName = map.sources[seg[1]];
221
239
  if (fileName.startsWith("file:///")) {
222
240
  fileName = decodeURIComponent(new URL(fileName).pathname);
241
+ } else if (fileName.startsWith("webpack://")) {
242
+ fileName = fileName.replace(/^webpack:\/\/\/?\.\/?/, "");
223
243
  }
224
244
  fileName = fileName.replace(/^(?:\.\.\/)+/, "");
225
245
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-grep",
3
- "version": "0.3.0",
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",