@rspnseapp/dev-inspector 0.1.0 → 0.3.0
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.
- package/dist/index.inspector.js +8 -1
- package/dist/webpack.d.ts +59 -0
- package/dist/webpack.js +105 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +15 -4
package/dist/index.inspector.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
"use strict";var RspnseInspector=(()=>{var f="rspnse-injected-css",p="rspnse-inspect-highlight",w="rspnse-inspect-label",x="rspnse-inspect-margin",S="rspnse-inspect-padding",g="1.0.0",C=["https://rspnse.net","https://www.rspnse.net","http://localhost","http://127.0.0.1"];function G(){return window.__RSPNSE_TRUSTED_ORIGINS__&&Array.isArray(window.__RSPNSE_TRUSTED_ORIGINS__)?[...C,...window.__RSPNSE_TRUSTED_ORIGINS__]:C}var m=!1,u=null,c=null,M={layout:["display","position","top","right","bottom","left","z-index"],flexbox:["flex","flex-direction","flex-wrap","justify-content","align-items","align-content","gap","row-gap","column-gap"],grid:["grid-template-columns","grid-template-rows","grid-column","grid-row"],box:["width","height","min-width","max-width","min-height","max-height","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","border","border-radius","box-sizing"],typography:["font-family","font-size","font-weight","font-style","line-height","letter-spacing","text-align","text-decoration","text-transform","color","white-space"],background:["background","background-color","background-image","background-size","background-position"],visual:["opacity","visibility","overflow","overflow-x","overflow-y","box-shadow","transform","cursor"]};function F(t){return G().some(n=>n.startsWith("http://localhost")||n.startsWith("http://127.0.0.1")?t.startsWith("http://localhost")||t.startsWith("http://127.0.0.1"):t===n||t.startsWith(n))}function H(t){let e=document.getElementById(f);return e||(e=document.createElement("style"),e.id=f,(document.head||document.documentElement).appendChild(e)),e.textContent=t,{success:!0}}function U(){let t=document.getElementById(f);return t?(t.remove(),{success:!0}):{success:!1,error:"No styles to remove"}}function V(){let t=document.getElementById(f);return t&&t.textContent||""}async function j(){let t=[];document.querySelectorAll("style").forEach((s,i)=>{s.textContent&&s.id!==f&&t.push({type:"inline",index:i+1,css:s.textContent.trim()})});let n=document.querySelectorAll('link[rel="stylesheet"]');for(let s of Array.from(n)){let i=s.href;try{let o=await fetch(i);if(o.ok){let r=await o.text();t.push({type:"external",href:i,css:r.trim()})}}catch(o){t.push({type:"external",href:i,css:null,error:`Could not fetch: ${o.message}`})}}return t}function z(t){if(t.id)return"#"+CSS.escape(t.id);let e=[],n=t,s=0;for(;n&&n!==document.body&&n!==document.documentElement&&s<3;){let i=n.tagName.toLowerCase();if(n.className&&typeof n.className=="string"){let o=n.className.trim().split(/\s+/).filter(r=>r&&!r.startsWith("rspnse-")).slice(0,2);o.length>0&&(i+="."+o.map(r=>CSS.escape(r)).join("."))}if(n.parentElement){let o=Array.from(n.parentElement.children).filter(r=>r.tagName===n.tagName);if(o.length>1){let r=o.indexOf(n)+1;i+=`:nth-of-type(${r})`}}e.unshift(i),n=n.parentElement,s++}return e.join(" > ")}function L(t){let e=window.getComputedStyle(t),n={},s=document.createElement(t.tagName);s.style.cssText="position: absolute; visibility: hidden;",document.body.appendChild(s);let i=window.getComputedStyle(s);return Object.keys(M).forEach(o=>{M[o].forEach(r=>{let l=e.getPropertyValue(r),E=i.getPropertyValue(r);l&&l!==E&&l!=="none"&&l!=="auto"&&l!=="normal"&&l!=="0px"&&l!=="rgba(0, 0, 0, 0)"&&(n[r]=l)})}),s.remove(),{selector:z(t),tagName:t.tagName.toLowerCase(),classList:Array.from(t.classList),id:t.id||null,computedStyles:n}}function P(t){let e=[],n=t;for(;n&&n!==document.documentElement;){if(n.nodeType!==1){n=n.parentElement;continue}let s=n.tagName.toLowerCase(),i=n.id?"#"+n.id:"",o=n.className&&typeof n.className=="string"?"."+n.className.trim().split(/\s+/).filter(r=>r&&!r.startsWith("rspnse-")).slice(0,1).join("."):"";e.unshift({label:s+i+o,index:e.length}),n=n.parentElement}e.unshift({label:"html",index:e.length});for(let s=0;s<e.length;s++)e[s].index=s;return e}function Y(t){if(!c)return null;let e=[],n=c;for(;n&&n!==document.documentElement;)n.nodeType===1&&e.unshift(n),n=n.parentElement;return e.unshift(document.documentElement),e[t]||null}function q(t){let e=t.tagName.toLowerCase(),n=t.id?"#"+t.id:"",s=t.className&&typeof t.className=="string"?"."+t.className.trim().split(/\s+/).filter(i=>i&&!i.startsWith("rspnse-")).slice(0,2).join("."):"";return e+n+s}function X(){[p,w,x,S].forEach(i=>{let o=document.getElementById(i);o&&o.remove()});let t=document.createElement("div");t.id=p,t.style.cssText="position: fixed; pointer-events: none; z-index: 2147483646; border: 2px solid #3b82f6; background: rgba(59, 130, 246, 0.15); transition: all 0.05s ease-out; display: none;",document.body.appendChild(t);let e=document.createElement("div");e.id=x,e.style.cssText="position: fixed; pointer-events: none; z-index: 2147483645; background: rgba(249, 115, 22, 0.25); transition: all 0.05s ease-out; display: none;",document.body.appendChild(e);let n=document.createElement("div");n.id=S,n.style.cssText="position: fixed; pointer-events: none; z-index: 2147483644; background: rgba(34, 197, 94, 0.25); transition: all 0.05s ease-out; display: none;",document.body.appendChild(n);let s=document.createElement("div");return s.id=w,s.style.cssText="position: fixed; pointer-events: none; z-index: 2147483647; background: #1e293b; color: #f8fafc; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 11px; padding: 4px 8px; border-radius: 4px; white-space: nowrap; display: none; box-shadow: 0 2px 8px rgba(0,0,0,0.3); max-width: calc(100vw - 16px); overflow: hidden; text-overflow: ellipsis;",document.body.appendChild(s),t}function k(t){let e=document.getElementById(p),n=document.getElementById(w),s=document.getElementById(x),i=document.getElementById(S);if(!e||!n)return;if(!t){e.style.display="none",n.style.display="none",s&&(s.style.display="none"),i&&(i.style.display="none");return}let o=t.getBoundingClientRect(),r=window.getComputedStyle(t),l=parseFloat(r.marginTop)||0,E=parseFloat(r.marginRight)||0,R=parseFloat(r.marginBottom)||0,d=parseFloat(r.marginLeft)||0,h=parseFloat(r.paddingTop)||0,b=parseFloat(r.paddingRight)||0,I=parseFloat(r.paddingBottom)||0,y=parseFloat(r.paddingLeft)||0;e.style.display="block",e.style.top=o.top+"px",e.style.left=o.left+"px",e.style.width=o.width+"px",e.style.height=o.height+"px",s&&(l||E||R||d)?(s.style.display="block",s.style.top=o.top-l+"px",s.style.left=o.left-d+"px",s.style.width=o.width+d+E+"px",s.style.height=o.height+l+R+"px",s.style.clipPath=`polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 0, ${d}px ${l}px, ${d}px ${l+o.height}px, ${d+o.width}px ${l+o.height}px, ${d+o.width}px ${l}px, ${d}px ${l}px)`):s&&(s.style.display="none"),i&&(h||b||I||y)?(i.style.display="block",i.style.top=o.top+"px",i.style.left=o.left+"px",i.style.width=o.width+"px",i.style.height=o.height+"px",i.style.clipPath=`polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 0, ${y}px ${h}px, ${y}px ${o.height-I}px, ${o.width-b}px ${o.height-I}px, ${o.width-b}px ${h}px, ${y}px ${h}px)`):i&&(i.style.display="none");let B=q(t),W=`${Math.round(o.width)} x ${Math.round(o.height)}`;n.innerHTML=`<span style="color: #93c5fd;">${B}</span> <span style="color: #94a3b8; margin-left: 6px;">${W}</span>`,n.style.display="block",n.style.left="auto",n.style.right="auto";let v=window.innerWidth,_=o.top-24-6;_<4&&(_=o.bottom+6),n.style.top=_+"px",o.left+o.width/2>v/2?(n.style.right=Math.max(4,v-o.right)+"px",n.style.left="auto"):(n.style.left=Math.max(4,o.left)+"px",n.style.right="auto")}function N(t){if(!c)return-1;let e=[],n=c;for(;n&&n!==document.documentElement;)n.nodeType===1&&e.unshift(n),n=n.parentElement;e.unshift(document.documentElement);for(let s=0;s<e.length;s++)if(e[s]===t)return s;return-1}function T(t){if(!t||t.id&&t.id.startsWith("rspnse-"))return!1;u=t,k(t);let e=L(t),n=P(c),s=N(t);return window.parent!==window&&window.parent.postMessage({type:"RSPNSE_INSPECT_ELEMENT_RESULT",success:!0,element:e,breadcrumb:n,breadcrumbIndex:s},"*"),!0}function O(t){if(!m)return;let e=document.elementFromPoint(t.clientX,t.clientY);e&&e.id!==p&&k(e)}function A(t){if(!m)return;t.preventDefault(),t.stopPropagation();let e=document.elementFromPoint(t.clientX,t.clientY);if(e&&e.id!==p&&!e.id?.startsWith("rspnse-")){c=e,u=e;let n=L(e),s=P(e);window.parent!==window&&window.parent.postMessage({type:"RSPNSE_INSPECT_ELEMENT_RESULT",success:!0,element:n,breadcrumb:s,breadcrumbIndex:s.length-1},"*")}}function $(t){if(!m)return;if(t.key==="Escape"){D(),window.parent!==window&&window.parent.postMessage({type:"RSPNSE_INSPECT_CANCELLED",reason:"escape"},"*");return}if(!u||!c)return;let e=N(u),n=[],s=c;for(;s&&s!==document.documentElement;)s.nodeType===1&&n.unshift(s),s=s.parentElement;n.unshift(document.documentElement);let i=e;switch(t.key){case"ArrowUp":case"ArrowLeft":i=e-1;break;case"ArrowDown":case"ArrowRight":i=e+1;break;default:return}i>=0&&i<n.length&&(t.preventDefault(),T(n[i]))}function K(){m||(m=!0,document.body.style.cursor="crosshair",X(),document.addEventListener("mousemove",O,!0),document.addEventListener("click",A,!0),document.addEventListener("keydown",$,!0))}function D(){m=!1,u=null,c=null,document.body.style.cursor="",[p,w,x,S].forEach(t=>{let e=document.getElementById(t);e&&e.remove()}),document.removeEventListener("mousemove",O,!0),document.removeEventListener("click",A,!0),document.removeEventListener("keydown",$,!0)}function a(t,e,n){if(t.source&&t.source!==window)try{t.source.postMessage({type:e.type+"_RESULT",requestId:e.requestId,frameId:e.frameId,...n},"*")}catch{}}function J(t){if(!F(t.origin))return;let e=t.data;if(!(!e||typeof e!="object")&&e.type&&e.type.startsWith("RSPNSE_"))switch(e.type){case"RSPNSE_INJECT_CSS":typeof e.css=="string"?a(t,e,H(e.css)):a(t,e,{success:!1,error:"CSS must be a string"});break;case"RSPNSE_REMOVE_CSS":a(t,e,U());break;case"RSPNSE_GET_CSS":a(t,e,{success:!0,css:V()});break;case"RSPNSE_CAPTURE_STYLES":j().then(n=>{a(t,e,{success:!0,styles:n})}).catch(n=>{a(t,e,{success:!1,error:n.message})});break;case"RSPNSE_INSPECT_START":K(),a(t,e,{success:!0});break;case"RSPNSE_INSPECT_STOP":D(),a(t,e,{success:!0});break;case"RSPNSE_INSPECT_NAVIGATE_TO":if(c&&typeof e.breadcrumbIndex=="number"){let n=Y(e.breadcrumbIndex);n?(T(n),a(t,e,{success:!0})):a(t,e,{success:!1,error:"Element not found"})}else a(t,e,{success:!1,error:"No original element or invalid index"});break;case"RSPNSE_INSPECT_NAVIGATE":if(c&&u&&e.direction){let n=N(u),s=[],i=c;for(;i&&i!==document.documentElement;)i.nodeType===1&&s.unshift(i),i=i.parentElement;s.unshift(document.documentElement);let o=n;(e.direction==="left"||e.direction==="up")&&(o=n-1),(e.direction==="right"||e.direction==="down")&&(o=n+1),o>=0&&o<s.length?(T(s[o]),a(t,e,{success:!0})):a(t,e,{success:!1,error:"At end of breadcrumb"})}else a(t,e,{success:!1,error:"No selection"});break;case"RSPNSE_PING":a(t,e,{success:!0,pong:!0,version:g});break}}function Q(){if(document.documentElement.setAttribute("data-rspnse-inspector",g),window.addEventListener("message",J),window.parent!==window)try{window.parent.postMessage({type:"RSPNSE_DEV_INSPECTOR_READY",version:g,url:window.location.href},"*"),window.parent.postMessage({type:"RSPNSE_EXTENSION_READY",version:g,url:window.location.href},"*")}catch{}window.dispatchEvent(new CustomEvent("rspnse-inspector-loaded",{detail:{version:g}}))}Q();})();
|
|
1
|
+
"use strict";var RspnseInspector=(()=>{var re="rspnse-layout-overlay-canvas",p=null,h=null,W=[],T=new Map,R=!1;function ae(){return p||(p=document.createElement("canvas"),p.id=re,p.style.cssText=`
|
|
2
|
+
position: fixed;
|
|
3
|
+
inset: 0;
|
|
4
|
+
width: 100%;
|
|
5
|
+
height: 100%;
|
|
6
|
+
pointer-events: none;
|
|
7
|
+
z-index: 2147483645;
|
|
8
|
+
`,document.body.appendChild(p),h=p.getContext("2d"),H(),ye(),p)}function H(){if(!p||!h)return;let e=window.devicePixelRatio||1,t=window.innerWidth,n=window.innerHeight;p.width=t*e,p.height=n*e,p.style.width=t+"px",p.style.height=n+"px",h.scale(e,e)}function B(){p&&(p.remove(),p=null,h=null)}function G(){let e=[],t=document.querySelectorAll("*"),n=0,s=0;return t.forEach(o=>{if(o.id?.startsWith("rspnse-"))return;let r=window.getComputedStyle(o).display;r==="grid"||r==="inline-grid"?e.push(le(o,n++)):(r==="flex"||r==="inline-flex")&&e.push(ce(o,s++))}),W=e,e}function le(e,t){let n=window.getComputedStyle(e),s=e.getBoundingClientRect(),o=parseFloat(n.columnGap)||0,i=parseFloat(n.rowGap)||0,r=P(n.gridTemplateColumns,o),a=P(n.gridTemplateRows,i),l=de(n.gridTemplateAreas,r.length,a.length);return{id:`grid-${t}`,type:"grid",selector:F(e),label:U(e),rect:{x:s.x,y:s.y,width:s.width,height:s.height},columns:r,rows:a,areas:l,columnGap:o,rowGap:i}}function ce(e,t){let n=window.getComputedStyle(e),s=e.getBoundingClientRect();return{id:`flex-${t}`,type:"flex",selector:F(e),label:U(e),rect:{x:s.x,y:s.y,width:s.width,height:s.height},direction:n.flexDirection,wrap:n.flexWrap,justifyContent:n.justifyContent,alignItems:n.alignItems,gap:parseFloat(n.gap)||0}}function P(e,t){if(!e||e==="none")return[];let n=e.split(" ").filter(i=>i.trim()),s=[],o=0;return n.forEach((i,r)=>{let a=parseFloat(i);isNaN(a)||(s.push({index:r,start:o,end:o+a,size:i,isImplicit:!1}),o+=a+(r<n.length-1?t:0))}),s}function de(e,t,n){if(!e||e==="none")return[];let s=e.match(/"([^"]+)"/g);if(!s)return[];let o=new Map;return s.forEach((i,r)=>{i.replace(/"/g,"").split(/\s+/).filter(l=>l).forEach((l,d)=>{if(l!==".")if(!o.has(l))o.set(l,{name:l,rowStart:r,rowEnd:r+1,colStart:d,colEnd:d+1});else{let c=o.get(l);c.rowEnd=Math.max(c.rowEnd,r+1),c.colEnd=Math.max(c.colEnd,d+1)}})}),Array.from(o.values())}function F(e){if(e.id)return`#${e.id}`;let t=Array.from(e.classList).filter(s=>!s.startsWith("__")&&!s.startsWith("rspnse-")).slice(0,2);if(t.length>0){let s=`.${t.join(".")}`;if(document.querySelectorAll(s).length===1)return s}let n=e.tagName.toLowerCase();return t.length>0?`${n}.${t[0]}`:n}function U(e){if(e.id)return`#${e.id}`;if(e.classList.length>0){let t=Array.from(e.classList).find(n=>!n.startsWith("__"));if(t)return`.${t}`}return e.tagName.toLowerCase()}function Y(e,t,n){let s=W.find(o=>o.id===e);s&&(ae(),T.set(e,{containerId:e,container:s,settings:t,color:n}),V())}function j(e){T.delete(e),V(),T.size===0&&B()}function q(){T.clear(),B()}function V(){R||(R=!0,requestAnimationFrame(()=>{R=!1,M()}))}function M(){if(!h||!p)return;let e=window.devicePixelRatio||1;h.setTransform(1,0,0,1,0,0),h.clearRect(0,0,p.width,p.height),h.scale(e,e),T.forEach(t=>{t.container.type==="grid"?ue(t):ge(t)})}function ue(e){let{container:t,settings:n,color:s}=e,o=h,i=document.querySelector(t.selector);if(!i)return;let r=i.getBoundingClientRect();o.strokeStyle=s,o.lineWidth=2,o.setLineDash([]),o.strokeRect(r.x,r.y,r.width,r.height),t.columns&&t.columns.length>0&&k(o,r,t.columns,"column",s,n),t.rows&&t.rows.length>0&&k(o,r,t.rows,"row",s,n),n.showAreaNames&&t.areas&&t.areas.length>0&&pe(o,r,t,s)}function k(e,t,n,s,o,i){let r=s==="column";n.forEach((l,d)=>{let c=r?t.x+l.start:t.y+l.start;if(e.strokeStyle=l.isImplicit&&i.highlightImplicitTracks?w(o,.5):w(o,.7),e.lineWidth=1,e.setLineDash(l.isImplicit?[4,4]:[]),e.beginPath(),r?(e.moveTo(c,t.y),e.lineTo(c,t.y+t.height)):(e.moveTo(t.x,c),e.lineTo(t.x+t.width,c)),e.stroke(),i.showLineNumbers&&$(e,d+1,c,t,r,o),i.showTrackSizes){let f=r?t.x+l.end:t.y+l.end;fe(e,l.size,c,f,t,r,o)}});let a=n[n.length-1];if(a){let l=r?t.x+a.end:t.y+a.end;e.strokeStyle=w(o,.7),e.lineWidth=1,e.setLineDash([]),e.beginPath(),r?(e.moveTo(l,t.y),e.lineTo(l,t.y+t.height)):(e.moveTo(t.x,l),e.lineTo(t.x+t.width,l)),e.stroke(),i.showLineNumbers&&$(e,n.length+1,l,t,r,o)}}function $(e,t,n,s,o,i){let r=String(t),a=10,l=2;e.font=`${a}px ui-monospace, monospace`;let d=e.measureText(r).width,c,f;o?(c=n-d/2,f=s.y-a/2):(c=s.x-d-l*3,f=n+a/3),e.fillStyle=i,e.fillRect(c-l,f-a,d+l*2,a+l),e.fillStyle="#ffffff",e.fillText(r,c,f)}function fe(e,t,n,s,o,i,r){let a=(n+s)/2,l=9,d=2;e.font=`${l}px ui-monospace, monospace`;let c=e.measureText(t).width,f,m;i?(f=a-c/2,m=o.y+o.height+l+d*2):(f=o.x+o.width+d*2,m=a+l/3),e.fillStyle=w(r,.8),e.fillRect(f-d,m-l,c+d*2,l+d),e.fillStyle="#ffffff",e.fillText(t,f,m)}function pe(e,t,n,s){!n.areas||!n.columns||!n.rows||n.areas.forEach(o=>{let i=n.columns[o.colStart]?.start||0,r=n.columns[o.colEnd-1]?.end||0,a=n.rows[o.rowStart]?.start||0,l=n.rows[o.rowEnd-1]?.end||0,d={x:t.x+i,y:t.y+a,width:r-i,height:l-a};e.fillStyle=w(s,.1),e.fillRect(d.x,d.y,d.width,d.height);let c=11;e.font=`bold ${c}px sans-serif`;let f=e.measureText(o.name).width,m=d.x+(d.width-f)/2,E=d.y+(d.height+c)/2;e.fillStyle=s,e.fillRect(m-4,E-c,f+8,c+4),e.fillStyle="#ffffff",e.fillText(o.name,m,E)})}function ge(e){let{container:t,color:n}=e,s=h,o=document.querySelector(t.selector);if(!o)return;let i=o.getBoundingClientRect();s.strokeStyle=n,s.lineWidth=2,s.setLineDash([8,4]),s.strokeRect(i.x,i.y,i.width,i.height),me(s,i,t.direction||"row",n),s.setLineDash([]),s.strokeStyle=w(n,.6),s.lineWidth=1;let r=o.children;for(let a=0;a<r.length;a++){let l=r[a];if(l.id?.startsWith("rspnse-"))continue;let d=l.getBoundingClientRect();s.strokeRect(d.x,d.y,d.width,d.height)}he(s,i,"flex",n)}function me(e,t,n,s){e.fillStyle=s,e.beginPath();let r=t.x+t.width/2,a=t.y+t.height/2;switch(n){case"row":e.moveTo(t.x+8,a-16/2),e.lineTo(t.x+8+16,a),e.lineTo(t.x+8,a+16/2);break;case"row-reverse":e.moveTo(t.x+t.width-8,a-16/2),e.lineTo(t.x+t.width-8-16,a),e.lineTo(t.x+t.width-8,a+16/2);break;case"column":e.moveTo(r-16/2,t.y+8),e.lineTo(r,t.y+8+16),e.lineTo(r+16/2,t.y+8);break;case"column-reverse":e.moveTo(r-16/2,t.y+t.height-8),e.lineTo(r,t.y+t.height-8-16),e.lineTo(r+16/2,t.y+t.height-8);break}e.closePath(),e.fill()}function he(e,t,n,s){let i=n.toUpperCase();e.font="bold 10px sans-serif";let r=e.measureText(i).width,a=t.x+4,l=t.y+10+4;e.fillStyle=s,e.fillRect(a-2,l-10,r+4,12),e.fillStyle="#ffffff",e.fillText(i,a,l)}function w(e,t){let n=parseInt(e.slice(1,3),16),s=parseInt(e.slice(3,5),16),o=parseInt(e.slice(5,7),16);return`rgba(${n}, ${s}, ${o}, ${t})`}var z=!1;function ye(){if(z)return;z=!0;let e=!1,t=()=>{e||(e=!0,requestAnimationFrame(()=>{M(),e=!1}))};window.addEventListener("scroll",t,{passive:!0}),window.addEventListener("resize",()=>{H(),M()})}var v="rspnse-injected-css",S="rspnse-inspect-highlight",L="rspnse-inspect-label",I="rspnse-inspect-margin",_="rspnse-inspect-padding",x="1.0.0",X=["https://rspnse.net","https://www.rspnse.net","http://localhost","http://127.0.0.1"];function Ee(){return window.__RSPNSE_TRUSTED_ORIGINS__&&Array.isArray(window.__RSPNSE_TRUSTED_ORIGINS__)?[...X,...window.__RSPNSE_TRUSTED_ORIGINS__]:X}var b=!1,y=null,g=null,K={layout:["display","position","top","right","bottom","left","z-index"],flexbox:["flex","flex-direction","flex-wrap","justify-content","align-items","align-content","gap","row-gap","column-gap"],grid:["grid-template-columns","grid-template-rows","grid-column","grid-row"],box:["width","height","min-width","max-width","min-height","max-height","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","border","border-radius","box-sizing"],typography:["font-family","font-size","font-weight","font-style","line-height","letter-spacing","text-align","text-decoration","text-transform","color","white-space"],background:["background","background-color","background-image","background-size","background-position"],visual:["opacity","visibility","overflow","overflow-x","overflow-y","box-shadow","transform","cursor"]};function we(e){return Ee().some(n=>n.startsWith("http://localhost")||n.startsWith("http://127.0.0.1")?e.startsWith("http://localhost")||e.startsWith("http://127.0.0.1"):e===n||e.startsWith(n))}function Se(e){let t=document.getElementById(v);return t||(t=document.createElement("style"),t.id=v,(document.head||document.documentElement).appendChild(t)),t.textContent=e,{success:!0}}function be(){let e=document.getElementById(v);return e?(e.remove(),{success:!0}):{success:!1,error:"No styles to remove"}}function Te(){let e=document.getElementById(v);return e&&e.textContent||""}async function xe(){let e=[];document.querySelectorAll("style").forEach((s,o)=>{s.textContent&&s.id!==v&&e.push({type:"inline",index:o+1,css:s.textContent.trim()})});let n=document.querySelectorAll('link[rel="stylesheet"]');for(let s of Array.from(n)){let o=s.href;try{let i=await fetch(o);if(i.ok){let r=await i.text();e.push({type:"external",href:o,css:r.trim()})}}catch(i){e.push({type:"external",href:o,css:null,error:`Could not fetch: ${i.message}`})}}return e}function ve(e){if(e.id)return"#"+CSS.escape(e.id);let t=[],n=e,s=0;for(;n&&n!==document.body&&n!==document.documentElement&&s<3;){let o=n.tagName.toLowerCase();if(n.className&&typeof n.className=="string"){let i=n.className.trim().split(/\s+/).filter(r=>r&&!r.startsWith("rspnse-")).slice(0,2);i.length>0&&(o+="."+i.map(r=>CSS.escape(r)).join("."))}if(n.parentElement){let i=Array.from(n.parentElement.children).filter(r=>r.tagName===n.tagName);if(i.length>1){let r=i.indexOf(n)+1;o+=`:nth-of-type(${r})`}}t.unshift(o),n=n.parentElement,s++}return t.join(" > ")}function J(e){let t=window.getComputedStyle(e),n={},s=document.createElement(e.tagName);s.style.cssText="position: absolute; visibility: hidden;",document.body.appendChild(s);let o=window.getComputedStyle(s);return Object.keys(K).forEach(i=>{K[i].forEach(r=>{let a=t.getPropertyValue(r),l=o.getPropertyValue(r);a&&a!==l&&a!=="none"&&a!=="auto"&&a!=="normal"&&a!=="0px"&&a!=="rgba(0, 0, 0, 0)"&&(n[r]=a)})}),s.remove(),{selector:ve(e),tagName:e.tagName.toLowerCase(),classList:Array.from(e.classList),id:e.id||null,computedStyles:n}}function Q(e){let t=[],n=e;for(;n&&n!==document.documentElement;){if(n.nodeType!==1){n=n.parentElement;continue}let s=n.tagName.toLowerCase(),o=n.id?"#"+n.id:"",i=n.className&&typeof n.className=="string"?"."+n.className.trim().split(/\s+/).filter(r=>r&&!r.startsWith("rspnse-")).slice(0,1).join("."):"";t.unshift({label:s+o+i,index:t.length}),n=n.parentElement}t.unshift({label:"html",index:t.length});for(let s=0;s<t.length;s++)t[s].index=s;return t}function Ce(e){if(!g)return null;let t=[],n=g;for(;n&&n!==document.documentElement;)n.nodeType===1&&t.unshift(n),n=n.parentElement;return t.unshift(document.documentElement),t[e]||null}function Le(e){let t=e.tagName.toLowerCase(),n=e.id?"#"+e.id:"",s=e.className&&typeof e.className=="string"?"."+e.className.trim().split(/\s+/).filter(o=>o&&!o.startsWith("rspnse-")).slice(0,2).join("."):"";return t+n+s}function Ie(){[S,L,I,_].forEach(o=>{let i=document.getElementById(o);i&&i.remove()});let e=document.createElement("div");e.id=S,e.style.cssText="position: fixed; pointer-events: none; z-index: 2147483646; border: 2px solid #3b82f6; background: rgba(59, 130, 246, 0.15); transition: all 0.05s ease-out; display: none;",document.body.appendChild(e);let t=document.createElement("div");t.id=I,t.style.cssText="position: fixed; pointer-events: none; z-index: 2147483645; background: rgba(249, 115, 22, 0.25); transition: all 0.05s ease-out; display: none;",document.body.appendChild(t);let n=document.createElement("div");n.id=_,n.style.cssText="position: fixed; pointer-events: none; z-index: 2147483644; background: rgba(34, 197, 94, 0.25); transition: all 0.05s ease-out; display: none;",document.body.appendChild(n);let s=document.createElement("div");return s.id=L,s.style.cssText="position: fixed; pointer-events: none; z-index: 2147483647; background: #1e293b; color: #f8fafc; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 11px; padding: 4px 8px; border-radius: 4px; white-space: nowrap; display: none; box-shadow: 0 2px 8px rgba(0,0,0,0.3); max-width: calc(100vw - 16px); overflow: hidden; text-overflow: ellipsis;",document.body.appendChild(s),e}function Z(e){let t=document.getElementById(S),n=document.getElementById(L),s=document.getElementById(I),o=document.getElementById(_);if(!t||!n)return;if(!e){t.style.display="none",n.style.display="none",s&&(s.style.display="none"),o&&(o.style.display="none");return}let i=e.getBoundingClientRect(),r=window.getComputedStyle(e),a=parseFloat(r.marginTop)||0,l=parseFloat(r.marginRight)||0,d=parseFloat(r.marginBottom)||0,c=parseFloat(r.marginLeft)||0,f=parseFloat(r.paddingTop)||0,m=parseFloat(r.paddingRight)||0,E=parseFloat(r.paddingBottom)||0,C=parseFloat(r.paddingLeft)||0;t.style.display="block",t.style.top=i.top+"px",t.style.left=i.left+"px",t.style.width=i.width+"px",t.style.height=i.height+"px",s&&(a||l||d||c)?(s.style.display="block",s.style.top=i.top-a+"px",s.style.left=i.left-c+"px",s.style.width=i.width+c+l+"px",s.style.height=i.height+a+d+"px",s.style.clipPath=`polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 0, ${c}px ${a}px, ${c}px ${a+i.height}px, ${c+i.width}px ${a+i.height}px, ${c+i.width}px ${a}px, ${c}px ${a}px)`):s&&(s.style.display="none"),o&&(f||m||E||C)?(o.style.display="block",o.style.top=i.top+"px",o.style.left=i.left+"px",o.style.width=i.width+"px",o.style.height=i.height+"px",o.style.clipPath=`polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 0, ${C}px ${f}px, ${C}px ${i.height-E}px, ${i.width-m}px ${i.height-E}px, ${i.width-m}px ${f}px, ${C}px ${f}px)`):o&&(o.style.display="none");let oe=Le(e),ie=`${Math.round(i.width)} x ${Math.round(i.height)}`;n.innerHTML=`<span style="color: #93c5fd;">${oe}</span> <span style="color: #94a3b8; margin-left: 6px;">${ie}</span>`,n.style.display="block",n.style.left="auto",n.style.right="auto";let O=window.innerWidth,N=i.top-24-6;N<4&&(N=i.bottom+6),n.style.top=N+"px",i.left+i.width/2>O/2?(n.style.right=Math.max(4,O-i.right)+"px",n.style.left="auto"):(n.style.left=Math.max(4,i.left)+"px",n.style.right="auto")}function A(e){if(!g)return-1;let t=[],n=g;for(;n&&n!==document.documentElement;)n.nodeType===1&&t.unshift(n),n=n.parentElement;t.unshift(document.documentElement);for(let s=0;s<t.length;s++)if(t[s]===e)return s;return-1}function D(e){if(!e||e.id&&e.id.startsWith("rspnse-"))return!1;y=e,Z(e);let t=J(e),n=Q(g),s=A(e);return window.parent!==window&&window.parent.postMessage({type:"RSPNSE_INSPECT_ELEMENT_RESULT",success:!0,element:t,breadcrumb:n,breadcrumbIndex:s},"*"),!0}function ee(e){if(!b)return;let t=document.elementFromPoint(e.clientX,e.clientY);t&&t.id!==S&&Z(t)}function te(e){if(!b)return;e.preventDefault(),e.stopPropagation();let t=document.elementFromPoint(e.clientX,e.clientY);if(t&&t.id!==S&&!t.id?.startsWith("rspnse-")){g=t,y=t;let n=J(t),s=Q(t);window.parent!==window&&window.parent.postMessage({type:"RSPNSE_INSPECT_ELEMENT_RESULT",success:!0,element:n,breadcrumb:s,breadcrumbIndex:s.length-1},"*")}}function ne(e){if(!b)return;if(e.key==="Escape"){se(),window.parent!==window&&window.parent.postMessage({type:"RSPNSE_INSPECT_CANCELLED",reason:"escape"},"*");return}if(!y||!g)return;let t=A(y),n=[],s=g;for(;s&&s!==document.documentElement;)s.nodeType===1&&n.unshift(s),s=s.parentElement;n.unshift(document.documentElement);let o=t;switch(e.key){case"ArrowUp":case"ArrowLeft":o=t-1;break;case"ArrowDown":case"ArrowRight":o=t+1;break;default:return}o>=0&&o<n.length&&(e.preventDefault(),D(n[o]))}function _e(){b||(b=!0,document.body.style.cursor="crosshair",Ie(),document.addEventListener("mousemove",ee,!0),document.addEventListener("click",te,!0),document.addEventListener("keydown",ne,!0))}function se(){b=!1,y=null,g=null,document.body.style.cursor="",[S,L,I,_].forEach(e=>{let t=document.getElementById(e);t&&t.remove()}),document.removeEventListener("mousemove",ee,!0),document.removeEventListener("click",te,!0),document.removeEventListener("keydown",ne,!0)}function u(e,t,n){if(e.source&&e.source!==window)try{e.source.postMessage({type:t.type+"_RESULT",requestId:t.requestId,frameId:t.frameId,...n},"*")}catch{}}function Ne(e){if(!we(e.origin))return;let t=e.data;if(!(!t||typeof t!="object")&&t.type&&t.type.startsWith("RSPNSE_"))switch(t.type){case"RSPNSE_INJECT_CSS":typeof t.css=="string"?u(e,t,Se(t.css)):u(e,t,{success:!1,error:"CSS must be a string"});break;case"RSPNSE_REMOVE_CSS":u(e,t,be());break;case"RSPNSE_GET_CSS":u(e,t,{success:!0,css:Te()});break;case"RSPNSE_CAPTURE_STYLES":xe().then(n=>{u(e,t,{success:!0,styles:n})}).catch(n=>{u(e,t,{success:!1,error:n.message})});break;case"RSPNSE_INSPECT_START":_e(),u(e,t,{success:!0});break;case"RSPNSE_INSPECT_STOP":se(),u(e,t,{success:!0});break;case"RSPNSE_INSPECT_NAVIGATE_TO":if(g&&typeof t.breadcrumbIndex=="number"){let n=Ce(t.breadcrumbIndex);n?(D(n),u(e,t,{success:!0})):u(e,t,{success:!1,error:"Element not found"})}else u(e,t,{success:!1,error:"No original element or invalid index"});break;case"RSPNSE_INSPECT_NAVIGATE":if(g&&y&&t.direction){let n=A(y),s=[],o=g;for(;o&&o!==document.documentElement;)o.nodeType===1&&s.unshift(o),o=o.parentElement;s.unshift(document.documentElement);let i=n;(t.direction==="left"||t.direction==="up")&&(i=n-1),(t.direction==="right"||t.direction==="down")&&(i=n+1),i>=0&&i<s.length?(D(s[i]),u(e,t,{success:!0})):u(e,t,{success:!1,error:"At end of breadcrumb"})}else u(e,t,{success:!1,error:"No selection"});break;case"RSPNSE_PING":u(e,t,{success:!0,pong:!0,version:x});break;case"RSPNSE_LAYOUT_DETECT":console.log("[dev-inspector] RSPNSE_LAYOUT_DETECT received, requestId:",t.requestId);try{let n=G();console.log("[dev-inspector] Detected",n.length,"containers"),u(e,t,{success:!0,containers:n}),console.log("[dev-inspector] Sent RSPNSE_LAYOUT_DETECT_RESULT")}catch(n){console.error("[dev-inspector] Detection error:",n),u(e,t,{success:!1,error:n.message})}break;case"RSPNSE_LAYOUT_HIGHLIGHT":t.containerId&&t.settings&&t.color?(t.visible!==!1?Y(t.containerId,t.settings,t.color):j(t.containerId),u(e,t,{success:!0})):u(e,t,{success:!1,error:"Missing containerId, settings, or color"});break;case"RSPNSE_LAYOUT_CLEAR":q(),u(e,t,{success:!0});break}}function Re(){if(document.documentElement.setAttribute("data-rspnse-inspector",x),window.addEventListener("message",Ne),window.parent!==window)try{window.parent.postMessage({type:"RSPNSE_DEV_INSPECTOR_READY",version:x,url:window.location.href},"*"),window.parent.postMessage({type:"RSPNSE_EXTENSION_READY",version:x,url:window.location.href},"*")}catch{}window.dispatchEvent(new CustomEvent("rspnse-inspector-loaded",{detail:{version:x}}))}Re();})();
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Compiler } from 'webpack';
|
|
2
|
+
|
|
3
|
+
interface BreadcrumbItem {
|
|
4
|
+
label: string;
|
|
5
|
+
index: number;
|
|
6
|
+
}
|
|
7
|
+
interface InspectedElement {
|
|
8
|
+
selector: string;
|
|
9
|
+
tagName: string;
|
|
10
|
+
classList: string[];
|
|
11
|
+
id: string | null;
|
|
12
|
+
computedStyles: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
interface StyleEntry {
|
|
15
|
+
type: 'inline' | 'external';
|
|
16
|
+
index?: number;
|
|
17
|
+
href?: string;
|
|
18
|
+
css: string | null;
|
|
19
|
+
error?: string;
|
|
20
|
+
}
|
|
21
|
+
interface RspnseInspectorOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Enable/disable the inspector. Defaults to true in development.
|
|
24
|
+
*/
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Trusted origins that can communicate with the inspector.
|
|
28
|
+
* Defaults to ['https://rspnse.net', 'http://localhost']
|
|
29
|
+
*/
|
|
30
|
+
trustedOrigins?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Webpack plugin that injects the Rspnse inspector script into dev server pages.
|
|
35
|
+
* This enables inspect functionality from rspnse.net without a browser extension.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* // webpack.config.js (ESM)
|
|
40
|
+
* import { RspnseInspectorPlugin } from '@rspnseapp/dev-inspector/webpack';
|
|
41
|
+
*
|
|
42
|
+
* export default {
|
|
43
|
+
* plugins: [new RspnseInspectorPlugin()]
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare class RspnseInspectorPlugin {
|
|
48
|
+
private options;
|
|
49
|
+
private inspectorScript;
|
|
50
|
+
constructor(options?: RspnseInspectorOptions);
|
|
51
|
+
private getInspectorScript;
|
|
52
|
+
apply(compiler: Compiler): void;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Factory function for creating the plugin (alternative to class instantiation)
|
|
56
|
+
*/
|
|
57
|
+
declare function rspnseInspector(options?: RspnseInspectorOptions): RspnseInspectorPlugin;
|
|
58
|
+
|
|
59
|
+
export { type BreadcrumbItem, type InspectedElement, type RspnseInspectorOptions, RspnseInspectorPlugin, type StyleEntry, rspnseInspector };
|
package/dist/webpack.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// src/webpack-plugin.ts
|
|
9
|
+
import { readFileSync } from "fs";
|
|
10
|
+
import { resolve, dirname } from "path";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
var PLUGIN_NAME = "RspnseInspectorPlugin";
|
|
13
|
+
var INSPECTOR_PATH = "/__rspnse-inspector__/inspector.js";
|
|
14
|
+
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
var RspnseInspectorPlugin = class {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
this.inspectorScript = null;
|
|
18
|
+
this.options = {
|
|
19
|
+
enabled: true,
|
|
20
|
+
...options
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
getInspectorScript() {
|
|
24
|
+
if (this.inspectorScript) return this.inspectorScript;
|
|
25
|
+
try {
|
|
26
|
+
const scriptPath = resolve(__dirname, "index.inspector.js");
|
|
27
|
+
this.inspectorScript = readFileSync(scriptPath, "utf-8");
|
|
28
|
+
} catch {
|
|
29
|
+
console.warn(
|
|
30
|
+
`[${PLUGIN_NAME}] Could not load inspector script from ${__dirname}.`
|
|
31
|
+
);
|
|
32
|
+
this.inspectorScript = "// Inspector script not found";
|
|
33
|
+
}
|
|
34
|
+
return this.inspectorScript;
|
|
35
|
+
}
|
|
36
|
+
apply(compiler) {
|
|
37
|
+
if (!this.options.enabled) return;
|
|
38
|
+
if (compiler.options.mode !== "development") return;
|
|
39
|
+
const { trustedOrigins } = this.options;
|
|
40
|
+
compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => {
|
|
41
|
+
const devServer = compiler.options.devServer;
|
|
42
|
+
if (!devServer) return;
|
|
43
|
+
const originalSetupMiddlewares = devServer.setupMiddlewares;
|
|
44
|
+
devServer.setupMiddlewares = (middlewares, devServerInstance) => {
|
|
45
|
+
middlewares.unshift({
|
|
46
|
+
name: PLUGIN_NAME,
|
|
47
|
+
path: INSPECTOR_PATH,
|
|
48
|
+
middleware: (_req, res) => {
|
|
49
|
+
res.setHeader("Content-Type", "application/javascript");
|
|
50
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
51
|
+
let script = this.getInspectorScript();
|
|
52
|
+
if (trustedOrigins && trustedOrigins.length > 0) {
|
|
53
|
+
const originsArray = JSON.stringify(trustedOrigins);
|
|
54
|
+
script = `window.__RSPNSE_TRUSTED_ORIGINS__ = ${originsArray};
|
|
55
|
+
${script}`;
|
|
56
|
+
}
|
|
57
|
+
res.end(script);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (originalSetupMiddlewares) {
|
|
61
|
+
return originalSetupMiddlewares(middlewares, devServerInstance);
|
|
62
|
+
}
|
|
63
|
+
return middlewares;
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
67
|
+
compilation.hooks.processAssets.tap(
|
|
68
|
+
{
|
|
69
|
+
name: PLUGIN_NAME,
|
|
70
|
+
// Run after HTML has been generated
|
|
71
|
+
stage: 1e3
|
|
72
|
+
},
|
|
73
|
+
(assets) => {
|
|
74
|
+
const scriptTag = `<script src="${INSPECTOR_PATH}" defer></script>`;
|
|
75
|
+
for (const name of Object.keys(assets)) {
|
|
76
|
+
if (name.endsWith(".html")) {
|
|
77
|
+
const asset = assets[name];
|
|
78
|
+
let html = asset.source().toString();
|
|
79
|
+
if (html.includes(INSPECTOR_PATH)) continue;
|
|
80
|
+
if (html.includes("</head>")) {
|
|
81
|
+
html = html.replace("</head>", `${scriptTag}
|
|
82
|
+
</head>`);
|
|
83
|
+
} else if (html.includes("<body")) {
|
|
84
|
+
html = html.replace(/<body([^>]*)>/, `<body$1>
|
|
85
|
+
${scriptTag}`);
|
|
86
|
+
} else {
|
|
87
|
+
html = scriptTag + "\n" + html;
|
|
88
|
+
}
|
|
89
|
+
const webpack = __require("webpack");
|
|
90
|
+
compilation.updateAsset(name, new webpack.sources.RawSource(html));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function rspnseInspector(options = {}) {
|
|
99
|
+
return new RspnseInspectorPlugin(options);
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
RspnseInspectorPlugin,
|
|
103
|
+
rspnseInspector
|
|
104
|
+
};
|
|
105
|
+
//# sourceMappingURL=webpack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webpack-plugin.ts"],"sourcesContent":["import type { Compiler } from 'webpack';\nimport { readFileSync } from 'fs';\nimport { resolve, dirname } from 'path';\nimport { fileURLToPath } from 'url';\nimport type { RspnseInspectorOptions } from './types';\n\nconst PLUGIN_NAME = 'RspnseInspectorPlugin';\nconst INSPECTOR_PATH = '/__rspnse-inspector__/inspector.js';\n\n// Get the directory of this module (ESM)\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\n/**\n * Webpack plugin that injects the Rspnse inspector script into dev server pages.\n * This enables inspect functionality from rspnse.net without a browser extension.\n *\n * @example\n * ```ts\n * // webpack.config.js (ESM)\n * import { RspnseInspectorPlugin } from '@rspnseapp/dev-inspector/webpack';\n *\n * export default {\n * plugins: [new RspnseInspectorPlugin()]\n * }\n * ```\n */\nexport class RspnseInspectorPlugin {\n private options: Required<Pick<RspnseInspectorOptions, 'enabled'>> &\n RspnseInspectorOptions;\n private inspectorScript: string | null = null;\n\n constructor(options: RspnseInspectorOptions = {}) {\n this.options = {\n enabled: true,\n ...options,\n };\n }\n\n private getInspectorScript(): string {\n if (this.inspectorScript) return this.inspectorScript;\n\n try {\n // Load the bundled inspector script from dist\n const scriptPath = resolve(__dirname, 'index.inspector.js');\n this.inspectorScript = readFileSync(scriptPath, 'utf-8');\n } catch {\n console.warn(\n `[${PLUGIN_NAME}] Could not load inspector script from ${__dirname}.`\n );\n this.inspectorScript = '// Inspector script not found';\n }\n\n return this.inspectorScript;\n }\n\n apply(compiler: Compiler): void {\n if (!this.options.enabled) return;\n\n // Only apply in development mode\n if (compiler.options.mode !== 'development') return;\n\n const { trustedOrigins } = this.options;\n\n // Add middleware to serve the inspector script via devServer\n compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => {\n const devServer = compiler.options.devServer as\n | {\n setupMiddlewares?: (\n middlewares: Array<{\n name: string;\n path: string;\n middleware: (\n req: unknown,\n res: { setHeader: (k: string, v: string) => void; end: (s: string) => void }\n ) => void;\n }>,\n devServer: unknown\n ) => unknown[];\n }\n | undefined;\n\n if (!devServer) return;\n\n // Store original setupMiddlewares if it exists\n const originalSetupMiddlewares = devServer.setupMiddlewares;\n\n devServer.setupMiddlewares = (middlewares, devServerInstance) => {\n // Add our middleware first\n middlewares.unshift({\n name: PLUGIN_NAME,\n path: INSPECTOR_PATH,\n middleware: (_req, res) => {\n res.setHeader('Content-Type', 'application/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n\n let script = this.getInspectorScript();\n\n // If custom trusted origins are provided, inject them\n if (trustedOrigins && trustedOrigins.length > 0) {\n const originsArray = JSON.stringify(trustedOrigins);\n script = `window.__RSPNSE_TRUSTED_ORIGINS__ = ${originsArray};\\n${script}`;\n }\n\n res.end(script);\n },\n });\n\n // Call original setupMiddlewares if it exists\n if (originalSetupMiddlewares) {\n return originalSetupMiddlewares(middlewares, devServerInstance) as typeof middlewares;\n }\n\n return middlewares;\n };\n });\n\n // Inject script tag into HTML assets\n compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n // Run after HTML has been generated\n stage: 1000,\n },\n (assets) => {\n const scriptTag = `<script src=\"${INSPECTOR_PATH}\" defer></script>`;\n\n for (const name of Object.keys(assets)) {\n if (name.endsWith('.html')) {\n const asset = assets[name];\n let html = asset.source().toString();\n\n // Don't inject twice\n if (html.includes(INSPECTOR_PATH)) continue;\n\n if (html.includes('</head>')) {\n html = html.replace('</head>', `${scriptTag}\\n</head>`);\n } else if (html.includes('<body')) {\n html = html.replace(/<body([^>]*)>/, `<body$1>\\n${scriptTag}`);\n } else {\n html = scriptTag + '\\n' + html;\n }\n\n // Update the asset - use webpack's sources API\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const webpack = require('webpack') as typeof import('webpack');\n compilation.updateAsset(name, new webpack.sources.RawSource(html));\n }\n }\n }\n );\n });\n }\n}\n\n/**\n * Factory function for creating the plugin (alternative to class instantiation)\n */\nexport function rspnseInspector(\n options: RspnseInspectorOptions = {}\n): RspnseInspectorPlugin {\n return new RspnseInspectorPlugin(options);\n}\n"],"mappings":";;;;;;;;AACA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AAG9B,IAAM,cAAc;AACpB,IAAM,iBAAiB;AAGvB,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAgBjD,IAAM,wBAAN,MAA4B;AAAA,EAKjC,YAAY,UAAkC,CAAC,GAAG;AAFlD,SAAQ,kBAAiC;AAGvC,SAAK,UAAU;AAAA,MACb,SAAS;AAAA,MACT,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEQ,qBAA6B;AACnC,QAAI,KAAK,gBAAiB,QAAO,KAAK;AAEtC,QAAI;AAEF,YAAM,aAAa,QAAQ,WAAW,oBAAoB;AAC1D,WAAK,kBAAkB,aAAa,YAAY,OAAO;AAAA,IACzD,QAAQ;AACN,cAAQ;AAAA,QACN,IAAI,WAAW,0CAA0C,SAAS;AAAA,MACpE;AACA,WAAK,kBAAkB;AAAA,IACzB;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,MAAM,UAA0B;AAC9B,QAAI,CAAC,KAAK,QAAQ,QAAS;AAG3B,QAAI,SAAS,QAAQ,SAAS,cAAe;AAE7C,UAAM,EAAE,eAAe,IAAI,KAAK;AAGhC,aAAS,MAAM,iBAAiB,IAAI,aAAa,MAAM;AACrD,YAAM,YAAY,SAAS,QAAQ;AAgBnC,UAAI,CAAC,UAAW;AAGhB,YAAM,2BAA2B,UAAU;AAE3C,gBAAU,mBAAmB,CAAC,aAAa,sBAAsB;AAE/D,oBAAY,QAAQ;AAAA,UAClB,MAAM;AAAA,UACN,MAAM;AAAA,UACN,YAAY,CAAC,MAAM,QAAQ;AACzB,gBAAI,UAAU,gBAAgB,wBAAwB;AACtD,gBAAI,UAAU,iBAAiB,UAAU;AAEzC,gBAAI,SAAS,KAAK,mBAAmB;AAGrC,gBAAI,kBAAkB,eAAe,SAAS,GAAG;AAC/C,oBAAM,eAAe,KAAK,UAAU,cAAc;AAClD,uBAAS,uCAAuC,YAAY;AAAA,EAAM,MAAM;AAAA,YAC1E;AAEA,gBAAI,IAAI,MAAM;AAAA,UAChB;AAAA,QACF,CAAC;AAGD,YAAI,0BAA0B;AAC5B,iBAAO,yBAAyB,aAAa,iBAAiB;AAAA,QAChE;AAEA,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAGD,aAAS,MAAM,YAAY,IAAI,aAAa,CAAC,gBAAgB;AAC3D,kBAAY,MAAM,cAAc;AAAA,QAC9B;AAAA,UACE,MAAM;AAAA;AAAA,UAEN,OAAO;AAAA,QACT;AAAA,QACA,CAAC,WAAW;AACV,gBAAM,YAAY,gBAAgB,cAAc;AAEhD,qBAAW,QAAQ,OAAO,KAAK,MAAM,GAAG;AACtC,gBAAI,KAAK,SAAS,OAAO,GAAG;AAC1B,oBAAM,QAAQ,OAAO,IAAI;AACzB,kBAAI,OAAO,MAAM,OAAO,EAAE,SAAS;AAGnC,kBAAI,KAAK,SAAS,cAAc,EAAG;AAEnC,kBAAI,KAAK,SAAS,SAAS,GAAG;AAC5B,uBAAO,KAAK,QAAQ,WAAW,GAAG,SAAS;AAAA,QAAW;AAAA,cACxD,WAAW,KAAK,SAAS,OAAO,GAAG;AACjC,uBAAO,KAAK,QAAQ,iBAAiB;AAAA,EAAa,SAAS,EAAE;AAAA,cAC/D,OAAO;AACL,uBAAO,YAAY,OAAO;AAAA,cAC5B;AAIA,oBAAM,UAAU,UAAQ,SAAS;AACjC,0BAAY,YAAY,MAAM,IAAI,QAAQ,QAAQ,UAAU,IAAI,CAAC;AAAA,YACnE;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAKO,SAAS,gBACd,UAAkC,CAAC,GACZ;AACvB,SAAO,IAAI,sBAAsB,OAAO;AAC1C;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspnseapp/dev-inspector",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Dev server
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Dev server plugins for Rspnse inspect functionality (Vite & Webpack)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"import": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./webpack": {
|
|
15
|
+
"types": "./dist/webpack.d.ts",
|
|
16
|
+
"import": "./dist/webpack.js"
|
|
13
17
|
}
|
|
14
18
|
},
|
|
15
19
|
"files": [
|
|
@@ -24,6 +28,7 @@
|
|
|
24
28
|
},
|
|
25
29
|
"keywords": [
|
|
26
30
|
"vite-plugin",
|
|
31
|
+
"webpack-plugin",
|
|
27
32
|
"rspnse",
|
|
28
33
|
"responsive",
|
|
29
34
|
"inspect",
|
|
@@ -38,16 +43,22 @@
|
|
|
38
43
|
"directory": "packages/dev-inspector"
|
|
39
44
|
},
|
|
40
45
|
"peerDependencies": {
|
|
41
|
-
"vite": ">=4.0.0"
|
|
46
|
+
"vite": ">=4.0.0",
|
|
47
|
+
"webpack": ">=5.0.0"
|
|
42
48
|
},
|
|
43
49
|
"peerDependenciesMeta": {
|
|
44
50
|
"vite": {
|
|
45
51
|
"optional": true
|
|
52
|
+
},
|
|
53
|
+
"webpack": {
|
|
54
|
+
"optional": true
|
|
46
55
|
}
|
|
47
56
|
},
|
|
48
57
|
"devDependencies": {
|
|
58
|
+
"@types/webpack": "^5.28.0",
|
|
49
59
|
"tsup": "^8.0.0",
|
|
50
60
|
"typescript": "^5.0.0",
|
|
51
|
-
"vite": "^6.0.0"
|
|
61
|
+
"vite": "^6.0.0",
|
|
62
|
+
"webpack": "^5.0.0"
|
|
52
63
|
}
|
|
53
64
|
}
|