@pinsight/vite 0.1.0 → 0.2.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/bridge.mjs +3 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +54 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/bridge.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
function x(i){let{getNodeId:e,hot:t}=i,n=0,o=Date.now(),r=10,s=(h,l,
|
|
2
|
-
`}let o=`${n}${e.outerHTML}`;return o.length>1200?`${o.slice(0,1197)}...`:o}function P(i,e,t){let n=i.getBoundingClientRect(),o=n.width>0?Math.min(1,Math.max(0,(e-n.left)/n.width)):.5,r=n.height>0?Math.min(1,Math.max(0,(t-n.top)/n.height)):.5,s=
|
|
1
|
+
function x(i){let{getNodeId:e,hot:t}=i,n=0,o=Date.now(),r=10,s=(h,l,d)=>{if(!t)return;let p=Date.now();if(p-o>1e3&&(o=p,n=0),++n>r)return;let I={nodeId:e(),url:window.location.href,kind:h,message:l.slice(0,1e3),stack:d?.slice(0,2e3),capturedAt:p};t.send("pinsight:runtime-error",I)},a=()=>{if(!t)return;let h={nodeId:e(),url:window.location.href,bootedAt:Date.now()};t.send("pinsight:page-boot",h)},u=h=>{let l=h.message||(h.error instanceof Error?h.error.message:"Uncaught error"),d=h.error instanceof Error?h.error.stack:void 0;s("runtime",l,d)},c=h=>{let l=h.reason,d=l instanceof Error?l.message:typeof l=="string"?l:"Unhandled promise rejection",p=l instanceof Error?l.stack:void 0;s("runtime",d,p)},m=console.error;return console.error=(...h)=>{m.apply(console,h);let l=h.map(p=>p instanceof Error?p.message:typeof p=="string"?p:JSON.stringify(p)).join(" "),d=h.find(p=>p instanceof Error);s("console_error",l,d?.stack)},window.addEventListener("error",u),window.addEventListener("unhandledrejection",c),t?.on?.("vite:afterUpdate",a),a(),()=>{window.removeEventListener("error",u),window.removeEventListener("unhandledrejection",c),console.error=m}}var T=/^(?:[a-z0-9-]+(?:\[[^\]]+\])?:)+/i,k=/^(?:(?:p|px|py|pt|pr|pb|pl|ps|pe|m|mx|my|mt|mr|mb|ml|ms|me|space|w|h|min|max|size|col|row|gap|justify|items|self|place|text|font|leading|tracking|bg|from|via|to|border|divide|rounded|shadow|ring|outline|opacity|z|top|right|bottom|left|inset|start|end|overflow|overscroll|cursor|select|pointer-events|transition|duration|ease|delay|animate|scale|rotate|translate|skew|origin|aspect|basis|shrink|grow|fill|stroke|whitespace|break|line-clamp|backdrop|blur|brightness|contrast|grayscale|saturate|drop-shadow|mix-blend|bg-blend|grid-cols|grid-rows|auto-cols|auto-rows|flex|inline|object|float|clear|decoration|underline-offset|indent|align|scroll|snap|touch|will-change|accent|caret|appearance|resize)-|order-(?:first|last|none|\d+|\[[^\]]+\])$|content-(?:normal|center|start|end|between|around|evenly|baseline|stretch|none|\[[^\]]+\])$|box-(?:border|content|decoration-clone|decoration-slice)$|table-(?:auto|fixed|caption|cell|column|column-group|footer-group|header-group|row-group|row)$|list-(?:none|disc|decimal|inside|outside|image-none|\[[^\]]+\])$)/,R=/^(?:block|inline|inline-block|flex|inline-flex|grid|inline-grid|table|contents|flow-root|hidden|visible|invisible|collapse|static|fixed|absolute|relative|sticky|container|truncate|sr-only|not-sr-only|border|rounded|shadow|ring|outline|transition|grow|shrink|italic|not-italic|underline|overline|line-through|no-underline|uppercase|lowercase|capitalize|normal-case|antialiased|subpixel-antialiased|isolate|isolation-auto|group|peer)$/,B=/^(?::r[0-9a-z]+:|headlessui-.+-\d+|radix-:r.+|[a-f0-9-]{16,})$/i,_=/^[a-z0-9]+_[a-zA-Z0-9]{5,}$/;function $(i){let e=i.replace(T,"").replace(/^[!-]+/,"").replace(/!$/,"");return!e||e.startsWith("[")&&e.endsWith("]")?!0:R.test(e)||k.test(e)}function y(i){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(i):i.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`)}function w(i,e=document){try{return e.querySelectorAll(i).length===1}catch{return!1}}function D(i){let e=i.parentElement;if(!e)return{index:1,total:1};let t=i.tagName,n=0,o=0;for(let r=0;r<e.children.length;r++){let s=e.children[r];s.tagName===t&&(o++,s===i&&(n=o))}return{index:n||1,total:o||1}}function C(i){if(!(i.namespaceURI==="http://www.w3.org/2000/svg"&&i.tagName.toLowerCase()!=="svg"))return i;let t=i.closest("svg");return(t??i).closest('button, a, [role="button"]')??t??i}function O(i){let e=[],t=i,n=0;for(;t&&t!==document.body&&t!==document.documentElement&&n<6;){let o=t.tagName.toLowerCase();for(let c of["data-testid","data-cy","data-slot"]){let m=t.getAttribute(c);if(m){let h=[`${o}[${c}="${y(m)}"]`,...e].join(" > ");if(w(h))return h}}if(t.id&&!B.test(t.id)){let c=[`#${y(t.id)}`,...e].join(" > ");if(w(c))return c}let r=Array.from(t.classList).filter(c=>c.length>1&&!$(c)&&!_.test(c)).slice(0,2).map(c=>`.${y(c)}`).join(""),s=D(t),a=`${o}${r}${s.total>1?`:nth-of-type(${s.index})`:""}`;e.unshift(a);let u=e.join(" > ");if(w(u))return u;t=t.parentElement,n++}return e.join(" > ")||i.tagName.toLowerCase()}function f(i){return(i??"").replace(/\s+/g," ").trim().slice(0,60)}function b(i){for(let e of["aria-label","placeholder","alt","title","name"]){let t=i.getAttribute(e);if(t&&t.trim())return t.trim().slice(0,60)}return""}function F(i){let e=i.closest("dialog, table, form, nav, header, main, section");if(!e)return"";let t=e.querySelector("h1, h2, h3, h4, caption, legend"),n=f(t?.textContent);return`${e.tagName.toLowerCase()}:${n}`}function M(i){let e=i.tagName.toLowerCase(),t=f(i.textContent),n=b(i),o=i.getAttribute("role")??i.getAttribute("type")??"",r=F(i),s=0;if(t||n){let a=Array.from(document.querySelectorAll(e)),u=0;for(let c of a){if(c===i){s=u;break}(t&&f(c.textContent)===t||!t&&n&&b(c)===n)&&u++}}return{tag:e,ownText:t,ariaLabel:n,role:o,landmark:r,sameTextIndex:s}}function S(i){let e=null;if(i.textSignature)try{e=JSON.parse(i.textSignature)}catch{e=null}try{let s=document.querySelectorAll(i.cssSelector);if(s.length===1){let a=s[0];if(!e||!e.ownText)return a;let u=f(a.textContent);if(!u||u===e.ownText||u.includes(e.ownText)||e.ownText.includes(u))return a}}catch{}if(!e||!e.tag)return null;let t=Array.from(document.querySelectorAll(e.tag));if(t.length===0)return null;let n=null,o=0,r=new Map;for(let s of t){let a=f(s.textContent),u=b(s),c=F(s),m=a||u,h=m?r.get(m)??0:-1;m&&r.set(m,h+1);let l=0,d=!1;e.ariaLabel&&u&&u===e.ariaLabel&&(l+=45,d=!0),e.ownText&&a&&(a===e.ownText?(l+=45,d=!0):(a.includes(e.ownText)||e.ownText.includes(a))&&(l+=25,d=!0)),e.landmark&&c&&c===e.landmark&&(l+=15),d&&h===e.sameTextIndex&&(l+=15),l>o&&(o=l,n=s)}return o>=50?n:null}function L(i,e){let t=i.cloneNode(!1),n=t.getAttribute("class");if(n){let a=n.trim().split(/\s+/);a.length>16&&t.setAttribute("class",`${a.slice(0,16).join(" ")} ...`)}let o=t.getAttribute("src");if(o&&o.startsWith("data:")&&t.setAttribute("src","[data-url]"),i.tagName.toLowerCase()==="svg")return t.appendChild(document.createComment(" svg ")),t;if(e>=2){let a=f(i.textContent);return a&&(t.textContent=a),t}let r=0,s=0;for(let a of Array.from(i.childNodes))if(a.nodeType===3){let u=a.textContent?.trim();u&&t.appendChild(document.createTextNode(u.slice(0,80)))}else a.nodeType===1&&(r<5?(t.appendChild(L(a,e+1)),r++):s++);return s>0&&t.appendChild(document.createComment(` +${s} children `)),t}function N(i){let e=L(i,0),t=i.parentElement,n="";if(t&&t!==document.body&&t!==document.documentElement){let r=t.tagName.toLowerCase(),s=t.getAttribute("class"),a=t.id?` id="${t.id}"`:"",u=s?` class="${s.trim().split(/\s+/).slice(0,8).join(" ")}"`:"";n=`<!-- parent: <${r}${a}${u}> -->
|
|
2
|
+
`}let o=`${n}${e.outerHTML}`;return o.length>1200?`${o.slice(0,1197)}...`:o}function P(i,e,t){let n=i.getBoundingClientRect(),o=n.width>0?Math.min(1,Math.max(0,(e-n.left)/n.width)):.5,r=n.height>0?Math.min(1,Math.max(0,(t-n.top)/n.height)):.5,s=M(i);return{cssSelector:O(i),textSignature:JSON.stringify(s),relX:Number(o.toFixed(4)),relY:Number(r.toFixed(4)),viewport:{width:window.innerWidth||1280,height:window.innerHeight||800},outerHtmlSnippet:N(i)}}var g=class{constructor(e,t,n){this.overlayHost=e;this.shadowRoot=t;this.onPick=n;this.shieldEl=document.createElement("div"),this.shieldEl.setAttribute("data-pinsight-inspect-shield","true"),this.shieldEl.style.cssText="position:fixed;inset:0;cursor:crosshair;pointer-events:auto;display:none;z-index:10;",this.highlightEl=document.createElement("div"),this.highlightEl.style.cssText="position:fixed;top:0;left:0;pointer-events:none;border:2px solid #2563eb;background:rgba(37,99,235,0.12);border-radius:3px;box-sizing:border-box;display:none;z-index:9;",this.pillEl=document.createElement("div"),this.pillEl.style.cssText="position:fixed;top:0;left:0;pointer-events:none;background:#1e3a8a;color:#fff;font:600 11px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;padding:2px 6px;border-radius:4px;white-space:nowrap;display:none;z-index:11;box-shadow:0 2px 8px rgba(0,0,0,0.2);",this.shadowRoot.append(this.highlightEl,this.shieldEl,this.pillEl),this.shieldEl.addEventListener("pointermove",this.handlePointerMove),this.shieldEl.addEventListener("pointerdown",this.blockEvent,!0),this.shieldEl.addEventListener("mousedown",this.blockEvent,!0),this.shieldEl.addEventListener("click",this.handleClick,!0)}overlayHost;shadowRoot;onPick;shieldEl;highlightEl;pillEl;enabled=!1;hoveredEl=null;setEnabled(e){this.enabled=e,this.shieldEl.style.display=e?"block":"none",e||(this.hoveredEl=null,this.highlightEl.style.display="none",this.pillEl.style.display="none")}isEnabled(){return this.enabled}pickTargetAt(e,t){if(typeof document.elementsFromPoint!="function")return null;let n=document.elementsFromPoint(e,t);for(let o of n)if(!(o===this.overlayHost||this.overlayHost.contains(o))&&!(o===document.documentElement||o===document.body))return C(o);return null}handlePointerMove=e=>{if(!this.enabled)return;let t=this.pickTargetAt(e.clientX,e.clientY);if(this.hoveredEl=t,!t){this.highlightEl.style.display="none",this.pillEl.style.display="none";return}let n=t.getBoundingClientRect();this.highlightEl.style.display="block",this.highlightEl.style.transform=`translate3d(${n.left}px, ${n.top}px, 0)`,this.highlightEl.style.width=`${n.width}px`,this.highlightEl.style.height=`${n.height}px`;let o=t.tagName.toLowerCase();this.pillEl.textContent=`<${o}> ${Math.round(n.width)} \xD7 ${Math.round(n.height)}`,this.pillEl.style.display="block";let r=n.top>26?n.top-24:n.bottom+4,s=Math.max(4,Math.min(n.left,(window.innerWidth||1280)-180));this.pillEl.style.transform=`translate3d(${s}px, ${r}px, 0)`};blockEvent=e=>{this.enabled&&(e.preventDefault(),e.stopPropagation())};handleClick=e=>{if(!this.enabled)return;e.preventDefault(),e.stopPropagation();let t=this.pickTargetAt(e.clientX,e.clientY)??this.hoveredEl;if(!t)return;let n=P(t,e.clientX,e.clientY);this.onPick({anchor:n,clientX:e.clientX,clientY:e.clientY})};destroy(){this.shieldEl.removeEventListener("pointermove",this.handlePointerMove),this.shieldEl.removeEventListener("pointerdown",this.blockEvent,!0),this.shieldEl.removeEventListener("mousedown",this.blockEvent,!0),this.shieldEl.removeEventListener("click",this.handleClick,!0),this.shieldEl.remove(),this.highlightEl.remove(),this.pillEl.remove()}};function H(){let i=document.activeElement;for(;i&&i.shadowRoot&&i.shadowRoot.activeElement;)i=i.shadowRoot.activeElement;if(!i)return!1;let e=i.tagName.toUpperCase();return!!(e==="INPUT"||e==="TEXTAREA"||e==="SELECT"||i.isContentEditable)}function A(i){let e=history.pushState.bind(history),t=history.replaceState.bind(history),n=()=>{i.onUrlChanged(window.location.href)};history.pushState=function(...r){let s=e(...r);return n(),s},history.replaceState=function(...r){let s=t(...r);return n(),s};let o=r=>{if(r.key==="Escape"&&r.shiftKey){r.preventDefault(),r.stopPropagation(),i.onShortcut("exit-mode");return}if((r.key==="c"||r.key==="C")&&!r.metaKey&&!r.ctrlKey&&!r.altKey&&!r.shiftKey){if(H())return;r.preventDefault(),r.stopPropagation(),i.onShortcut("toggle-inspect")}};return window.addEventListener("popstate",n),window.addEventListener("hashchange",n),window.addEventListener("keydown",o,{capture:!0}),()=>{history.pushState=e,history.replaceState=t,window.removeEventListener("popstate",n),window.removeEventListener("hashchange",n),window.removeEventListener("keydown",o,{capture:!0})}}function E(i){try{let e=new URL(i),t=e.pathname.length>1&&e.pathname.endsWith("/")?e.pathname.slice(0,-1):e.pathname,o=new URLSearchParams(Array.from(e.searchParams.entries()).sort(([s,a],[u,c])=>s===u?a.localeCompare(c):s.localeCompare(u))).toString(),r=e.hash.startsWith("#/")?e.hash:"";return`${e.origin}${t}${o?`?${o}`:""}${r}`}catch{return i.trim()}}var U={open:"#ef4444",fixed:"#f59e0b",resolved:"#10b981"};function z(i){let e=i;for(;e&&e!==document.documentElement;){let t=window.getComputedStyle(e).position;if(t==="fixed")return"fixed";if(t==="sticky")return"sticky";e=e.parentElement}return"absolute"}var v=class{constructor(e,t){this.onPinClick=e;this.onRectsChange=t;let n=document.querySelector("pinsight-overlay");n&&n.remove(),this.host=document.createElement("pinsight-overlay"),this.host.style.cssText="all:initial;position:absolute;top:0;left:0;width:0;height:0;overflow:visible;z-index:2147483646;pointer-events:none;",this.shadowRoot=this.host.attachShadow({mode:"open"});let o=document.createElement("style");o.textContent=`
|
|
3
3
|
.pinsight-pin-dot {
|
|
4
4
|
position: absolute;
|
|
5
5
|
top: 0;
|
|
@@ -22,4 +22,4 @@ function x(i){let{getNodeId:e,hot:t}=i,n=0,o=Date.now(),r=10,s=(h,l,u)=>{if(!t)r
|
|
|
22
22
|
.pinsight-pin-dot[data-active="true"] {
|
|
23
23
|
box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.45), 0 4px 12px rgba(0,0,0,0.35);
|
|
24
24
|
}
|
|
25
|
-
`,this.docLayer=document.createElement("div"),this.docLayer.setAttribute("data-layer","doc"),this.docLayer.style.cssText="position:absolute;top:0;left:0;width:0;height:0;overflow:visible;",this.fixedLayer=document.createElement("div"),this.fixedLayer.setAttribute("data-layer","fixed"),this.fixedLayer.style.cssText="position:fixed;top:0;left:0;width:0;height:0;overflow:visible;",this.shadowRoot.append(o,this.docLayer,this.fixedLayer),(document.documentElement??document.body).appendChild(this.host),this.attachObservers()}onPinClick;onRectsChange;host;shadowRoot;docLayer;fixedLayer;pins=[];activePinId=null;mounted=new Map;rafId=null;lastResolveAt=0;mutationObserver=null;resizeObserver=null;retryObserver=null;retryTimer=null;attachObservers(){window.addEventListener("scroll",this.handleScrollCapture,{capture:!0,passive:!0}),window.addEventListener("resize",this.scheduleLayout,{passive:!0}),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.scheduleLayout()),document.body&&this.resizeObserver.observe(document.body)),typeof MutationObserver<"u"&&document.body&&(this.mutationObserver=new MutationObserver(()=>{let e=Date.now();Array.from(this.mounted.values()).some(n=>!n.el||!n.el.isConnected)||e-this.lastResolveAt>=250?(this.lastResolveAt=e,this.reconcileElements()):this.scheduleLayout()}),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden","open"]}))}handleScrollCapture=e=>{if(e.target===document||e.target===window||e.target===document.documentElement){(this.activePinId!==null||Array.from(this.mounted.values()).some(o=>o.positioning==="sticky"))&&this.scheduleLayout();return}this.scheduleLayout()};syncPins(e,t){this.pins=e,t!==void 0&&(this.activePinId=t),this.rebuildVisiblePins()}setActivePin(e){this.activePinId=e;for(let[t,n]of this.mounted.entries())n.dot.setAttribute("data-active",String(t===e));this.scheduleLayout()}rebuildVisiblePins(){let e=
|
|
25
|
+
`,this.docLayer=document.createElement("div"),this.docLayer.setAttribute("data-layer","doc"),this.docLayer.style.cssText="position:absolute;top:0;left:0;width:0;height:0;overflow:visible;",this.fixedLayer=document.createElement("div"),this.fixedLayer.setAttribute("data-layer","fixed"),this.fixedLayer.style.cssText="position:fixed;top:0;left:0;width:0;height:0;overflow:visible;",this.shadowRoot.append(o,this.docLayer,this.fixedLayer),(document.documentElement??document.body).appendChild(this.host),this.attachObservers()}onPinClick;onRectsChange;host;shadowRoot;docLayer;fixedLayer;pins=[];activePinId=null;mounted=new Map;rafId=null;lastResolveAt=0;mutationObserver=null;resizeObserver=null;retryObserver=null;retryTimer=null;attachObservers(){window.addEventListener("scroll",this.handleScrollCapture,{capture:!0,passive:!0}),window.addEventListener("resize",this.scheduleLayout,{passive:!0}),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.scheduleLayout()),document.body&&this.resizeObserver.observe(document.body)),typeof MutationObserver<"u"&&document.body&&(this.mutationObserver=new MutationObserver(()=>{let e=Date.now();Array.from(this.mounted.values()).some(n=>!n.el||!n.el.isConnected)||e-this.lastResolveAt>=250?(this.lastResolveAt=e,this.reconcileElements()):this.scheduleLayout()}),this.mutationObserver.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["class","style","hidden","open"]}))}handleScrollCapture=e=>{if(e.target===document||e.target===window||e.target===document.documentElement){(this.activePinId!==null||Array.from(this.mounted.values()).some(o=>o.positioning==="sticky"))&&this.scheduleLayout();return}this.scheduleLayout()};syncPins(e,t){this.pins=e,t!==void 0&&(this.activePinId=t),this.rebuildVisiblePins()}setActivePin(e){this.activePinId=e;for(let[t,n]of this.mounted.entries())n.dot.setAttribute("data-active",String(t===e));this.scheduleLayout()}rebuildVisiblePins(){let e=E(window.location.href),t=this.pins.filter(o=>E(o.url)===e),n=new Set(t.map(o=>o.id));for(let[o,r]of this.mounted.entries())n.has(o)||(r.dot.remove(),this.mounted.delete(o));for(let o of t){let r=this.mounted.get(o.id);if(r)r.item=o;else{let s=document.createElement("button");s.type="button",s.className="pinsight-pin-dot",s.setAttribute("data-pin-id",o.id),s.addEventListener("click",a=>{a.preventDefault(),a.stopPropagation();let u=s.getBoundingClientRect();this.onPinClick(o.id,u.left+u.width/2,u.top+u.height/2)}),r={item:o,el:null,positioning:"absolute",dot:s,state:"hidden"},this.docLayer.appendChild(s),this.mounted.set(o.id,r)}r.dot.textContent=String(o.index),r.dot.style.background=U[o.status]??"#ef4444",r.dot.setAttribute("data-active",String(o.id===this.activePinId))}this.reconcileElements()}reconcileElements(){for(let e of this.mounted.values())if((!e.el||!e.el.isConnected)&&(e.el=S(e.item.anchor)),e.el){e.state="active";let t=z(e.el);if(t!==e.positioning){e.positioning=t;let n=t==="absolute"?this.docLayer:this.fixedLayer;e.dot.parentElement!==n&&n.appendChild(e.dot)}e.dot.style.display="flex"}else e.state="hidden",e.dot.style.display="none";this.updatePositions()}scheduleLayout=()=>{this.rafId===null&&(this.rafId=window.requestAnimationFrame(()=>{this.rafId=null,this.updatePositions()}))};updatePositions(){let e=[];for(let t of this.mounted.values()){if(!t.el||!t.el.isConnected){t.state="hidden",t.dot.style.display="none",e.push({pinId:t.item.id,clientX:0,clientY:0,anchorState:"hidden",status:t.item.status,index:t.item.index});continue}let n=t.el.getBoundingClientRect(),o=n.left+n.width*t.item.anchor.relX,r=n.top+n.height*t.item.anchor.relY;if(t.positioning==="absolute"){let s=o+window.scrollX,a=r+window.scrollY;t.dot.style.transform=`translate3d(${s}px, ${a}px, 0) translate(-50%, -50%)`}else t.dot.style.transform=`translate3d(${o}px, ${r}px, 0) translate(-50%, -50%)`;t.dot.style.display="flex",e.push({pinId:t.item.id,clientX:o,clientY:r,anchorState:"active",status:t.item.status,index:t.item.index})}this.onRectsChange(e)}scrollToPinWithRetry(e,t=2500){this.clearRetry();let n=()=>{this.reconcileElements();let o=this.mounted.get(e);if(!o||!o.el||!o.el.isConnected)return!1;typeof o.el.scrollIntoView=="function"&&o.el.scrollIntoView({behavior:"smooth",block:"center",inline:"center"}),this.setActivePin(e),this.updatePositions();let r=o.el.getBoundingClientRect(),s=r.left+r.width*o.item.anchor.relX,a=r.top+r.height*o.item.anchor.relY;return this.onPinClick(e,s,a),!0};n()||typeof MutationObserver<"u"&&document.body&&(this.retryObserver=new MutationObserver(()=>{n()&&this.clearRetry()}),this.retryObserver.observe(document.body,{childList:!0,subtree:!0}),this.retryTimer=window.setTimeout(()=>this.clearRetry(),t))}clearRetry(){this.retryObserver&&(this.retryObserver.disconnect(),this.retryObserver=null),this.retryTimer!==null&&(clearTimeout(this.retryTimer),this.retryTimer=null)}destroy(){this.clearRetry(),this.rafId!==null&&cancelAnimationFrame(this.rafId),window.removeEventListener("scroll",this.handleScrollCapture,!0),window.removeEventListener("resize",this.scheduleLayout),this.mutationObserver?.disconnect(),this.resizeObserver?.disconnect(),this.host.remove()}};function j(){let i=/^pinsight-node:(.+)$/.exec(window.name??"");if(i)return i[1];let e=/\/__pinsight\/([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)/.exec(window.location.pathname);if(e)return`file:${e[1]}/${e[2]}`}function X(i){let e=typeof __PINSIGHT_BRIDGE_CONFIG__<"u"?__PINSIGHT_BRIDGE_CONFIG__?.canvasOrigin:void 0,t=i?.canvasOrigin??e,n=i?.hot??import.meta.hot??void 0,o=()=>j(),r=l=>{!t||window.parent===window||window.parent.postMessage(l,t)},s=x({getNodeId:o,hot:n}),a=null,u=null,c=()=>{a||(a=new v((l,d,p)=>{r({type:"pinsight:pin-clicked",pinId:l,clientX:d,clientY:p})},l=>{r({type:"pinsight:pin-rects",url:window.location.href,rects:l})}),u=new g(a.host,a.shadowRoot,l=>{r({type:"pinsight:element-picked",nodeId:o(),url:window.location.href,anchor:l.anchor,clientX:l.clientX,clientY:l.clientY})}))};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",c,{once:!0}):c();let m=A({onUrlChanged:l=>{a?.rebuildVisiblePins(),r({type:"pinsight:url-changed",nodeId:o(),url:l})},onShortcut:l=>{r({type:"pinsight:shortcut",shortcut:l})}}),h=l=>{if(!t||l.source!==window.parent||l.origin!==t)return;let d=l.data;if(!(!d||typeof d!="object"||typeof d.type!="string"))switch(c(),d.type){case"pinsight:set-mode":u?.setEnabled(d.mode==="inspect");break;case"pinsight:sync-pins":a?.syncPins(d.pins,d.activePinId);break;case"pinsight:highlight-pin":a?.setActivePin(d.pinId);break;case"pinsight:navigate":d.url&&window.location.assign(d.url);break;case"pinsight:history-back":window.history.back();break;case"pinsight:reload":window.location.reload();break;case"pinsight:scroll-to-pin":a?.scrollToPinWithRetry(d.pinId);break}};return window.addEventListener("message",h),r({type:"pinsight:ready",nodeId:o(),url:window.location.href}),{getNodeId:o,destroy:()=>{window.removeEventListener("message",h),m(),s(),u?.destroy(),a?.destroy()}}}typeof window<"u"&&typeof __PINSIGHT_BRIDGE_CONFIG__<"u"&&__PINSIGHT_BRIDGE_CONFIG__?.canvasOrigin&&X();export{g as ElementInspector,v as PinOverlayLayer,P as buildPinAnchor,O as buildSemanticSelector,M as buildTextSignature,N as compactOuterHtml,z as detectPositioningMode,X as initBridge,x as installErrorTap,A as installNavAndKeyTap,H as isEditableFocus,$ as isTailwindUtility,j as resolveCurrentNodeId,S as resolvePinElement,C as snapInteractiveTarget};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Plugin, ViteDevServer } from 'vite';
|
|
2
2
|
import http from 'node:http';
|
|
3
3
|
|
|
4
|
-
declare function
|
|
5
|
-
declare function
|
|
4
|
+
declare function getDefaultDevFrameAncestors(canvasOrigin: string): string[];
|
|
5
|
+
declare function relaxFrameAncestorsCsp(cspValue: string, canvasOrigin: string, extraAncestors?: readonly string[]): string;
|
|
6
|
+
declare function installFrameHeadersMiddleware(req: http.IncomingMessage, res: http.ServerResponse, getCanvasOrigin: () => string, next: () => void, getExtraAncestors?: () => readonly string[]): void;
|
|
6
7
|
|
|
7
8
|
interface TailwindDetectionResult {
|
|
8
9
|
majorVersion: number | null;
|
|
@@ -61,8 +62,10 @@ interface PinsightPluginOptions {
|
|
|
61
62
|
autoStartServer?: boolean;
|
|
62
63
|
/** Override canvasOrigin when autoStartServer is false */
|
|
63
64
|
canvasOrigin?: string;
|
|
65
|
+
/** Additional CSP frame-ancestors entries to allow in dev mode (e.g. custom host origin) */
|
|
66
|
+
frameAncestors?: string[];
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
declare function pinsight(options?: PinsightPluginOptions): Plugin[];
|
|
67
70
|
|
|
68
|
-
export { type CompileCheckOutput, type CompileErrorItem, type PinsightPluginOptions, RESOLVED_BRIDGE_ID, RESOLVED_ENTRY_PREFIX, type TailwindDetectionResult, VIRTUAL_BRIDGE_ID, VIRTUAL_ENTRY_PREFIX, attachErrorRelay, buildBridgeVirtualModule, buildFallbackVirtualHtml, buildVirtualRouteRegex, checkTailwindV3Config, createTailwindPrePlugin, pinsight as default, detectTailwindMajor, escapeRegex, generateVirtualEntryCode, injectTailwindV4Source, installFrameHeadersMiddleware, invalidateVirtualEntryModules, loadBridgeBundleSource, normalizeBasePrefix, pinsight, relaxFrameAncestorsCsp, runViteCompileCheck };
|
|
71
|
+
export { type CompileCheckOutput, type CompileErrorItem, type PinsightPluginOptions, RESOLVED_BRIDGE_ID, RESOLVED_ENTRY_PREFIX, type TailwindDetectionResult, VIRTUAL_BRIDGE_ID, VIRTUAL_ENTRY_PREFIX, attachErrorRelay, buildBridgeVirtualModule, buildFallbackVirtualHtml, buildVirtualRouteRegex, checkTailwindV3Config, createTailwindPrePlugin, pinsight as default, detectTailwindMajor, escapeRegex, generateVirtualEntryCode, getDefaultDevFrameAncestors, injectTailwindV4Source, installFrameHeadersMiddleware, invalidateVirtualEntryModules, loadBridgeBundleSource, normalizeBasePrefix, pinsight, relaxFrameAncestorsCsp, runViteCompileCheck };
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
import fs7 from "fs";
|
|
9
9
|
import path6 from "path";
|
|
10
10
|
|
|
11
|
-
// ../shared/dist/chunk-
|
|
11
|
+
// ../shared/dist/chunk-M6BI4UAR.js
|
|
12
12
|
function makeFileNodeId(topic, variant) {
|
|
13
13
|
return `file:${topic}/${variant}`;
|
|
14
14
|
}
|
|
@@ -4256,6 +4256,31 @@ var ArtifactEventSchema = external_exports.discriminatedUnion("type", [
|
|
|
4256
4256
|
type: external_exports.literal("promote_copied"),
|
|
4257
4257
|
nodeId: external_exports.string(),
|
|
4258
4258
|
pinCount: external_exports.number().int().min(0)
|
|
4259
|
+
}),
|
|
4260
|
+
external_exports.object({
|
|
4261
|
+
ts: external_exports.number(),
|
|
4262
|
+
type: external_exports.literal("dsh_dispatched"),
|
|
4263
|
+
kind: external_exports.enum(["pins", "promote"]),
|
|
4264
|
+
pinIds: external_exports.array(external_exports.string()),
|
|
4265
|
+
nodeId: external_exports.string().optional(),
|
|
4266
|
+
sessionId: external_exports.string().optional(),
|
|
4267
|
+
latencyMs: external_exports.number().int().min(0).optional()
|
|
4268
|
+
})
|
|
4269
|
+
]);
|
|
4270
|
+
var DispatchBaseSchema = external_exports.object({
|
|
4271
|
+
requestId: external_exports.string().min(8).max(64),
|
|
4272
|
+
sessionId: external_exports.string().min(1).optional(),
|
|
4273
|
+
targetClientId: external_exports.string().min(1).optional()
|
|
4274
|
+
});
|
|
4275
|
+
var DispatchRequestSchema = external_exports.discriminatedUnion("kind", [
|
|
4276
|
+
DispatchBaseSchema.extend({
|
|
4277
|
+
kind: external_exports.literal("pins"),
|
|
4278
|
+
pinIds: external_exports.array(external_exports.string().min(1)).min(1).max(100),
|
|
4279
|
+
nodeId: external_exports.string().min(1).optional()
|
|
4280
|
+
}),
|
|
4281
|
+
DispatchBaseSchema.extend({
|
|
4282
|
+
kind: external_exports.literal("promote"),
|
|
4283
|
+
nodeId: external_exports.string().min(1)
|
|
4259
4284
|
})
|
|
4260
4285
|
]);
|
|
4261
4286
|
var CreatePinRequestSchema = external_exports.object({
|
|
@@ -4640,7 +4665,14 @@ async function ensureCanvasServerRunning(options) {
|
|
|
4640
4665
|
}
|
|
4641
4666
|
|
|
4642
4667
|
// src/frame-headers.ts
|
|
4643
|
-
function
|
|
4668
|
+
function getDefaultDevFrameAncestors(canvasOrigin) {
|
|
4669
|
+
const base = ["http://localhost:*", "http://127.0.0.1:*", "http://[::1]:*"];
|
|
4670
|
+
if (canvasOrigin.toLowerCase().startsWith("https://")) {
|
|
4671
|
+
return [...base, "https://localhost:*", "https://127.0.0.1:*", "https://[::1]:*"];
|
|
4672
|
+
}
|
|
4673
|
+
return base;
|
|
4674
|
+
}
|
|
4675
|
+
function relaxFrameAncestorsCsp(cspValue, canvasOrigin, extraAncestors = []) {
|
|
4644
4676
|
const directives = cspValue.split(";").map((d) => d.trim()).filter(Boolean);
|
|
4645
4677
|
let modified = false;
|
|
4646
4678
|
const updated = directives.map((trimmed) => {
|
|
@@ -4650,25 +4682,32 @@ function relaxFrameAncestorsCsp(cspValue, canvasOrigin) {
|
|
|
4650
4682
|
const rest = tokens.slice(1).filter((t) => t.toLowerCase() !== "'none'");
|
|
4651
4683
|
if (!rest.includes("'self'")) rest.unshift("'self'");
|
|
4652
4684
|
if (!rest.includes(canvasOrigin)) rest.push(canvasOrigin);
|
|
4685
|
+
for (const raw of extraAncestors) {
|
|
4686
|
+
const ancestor = raw.trim();
|
|
4687
|
+
if (ancestor && !rest.includes(ancestor)) {
|
|
4688
|
+
rest.push(ancestor);
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4653
4691
|
return `frame-ancestors ${rest.join(" ")}`;
|
|
4654
4692
|
});
|
|
4655
4693
|
return modified ? updated.join("; ") : cspValue;
|
|
4656
4694
|
}
|
|
4657
|
-
function installFrameHeadersMiddleware(req, res, getCanvasOrigin, next) {
|
|
4695
|
+
function installFrameHeadersMiddleware(req, res, getCanvasOrigin, next, getExtraAncestors) {
|
|
4658
4696
|
const originalWriteHead = res.writeHead.bind(res);
|
|
4659
4697
|
const patchedWriteHead = function(statusCode, statusMessageOrHeaders, maybeHeaders) {
|
|
4660
4698
|
const canvasOrigin = getCanvasOrigin();
|
|
4699
|
+
const extraAncestors = canvasOrigin ? [...getDefaultDevFrameAncestors(canvasOrigin), ...getExtraAncestors?.() ?? []] : [];
|
|
4661
4700
|
for (const name of res.getHeaderNames()) {
|
|
4662
4701
|
if (name.toLowerCase() === "x-frame-options") {
|
|
4663
4702
|
res.removeHeader(name);
|
|
4664
4703
|
} else if (name.toLowerCase() === "content-security-policy" && canvasOrigin) {
|
|
4665
4704
|
const val = res.getHeader(name);
|
|
4666
4705
|
if (typeof val === "string") {
|
|
4667
|
-
res.setHeader(name, relaxFrameAncestorsCsp(val, canvasOrigin));
|
|
4706
|
+
res.setHeader(name, relaxFrameAncestorsCsp(val, canvasOrigin, extraAncestors));
|
|
4668
4707
|
} else if (Array.isArray(val)) {
|
|
4669
4708
|
res.setHeader(
|
|
4670
4709
|
name,
|
|
4671
|
-
val.map((v) => relaxFrameAncestorsCsp(String(v), canvasOrigin))
|
|
4710
|
+
val.map((v) => relaxFrameAncestorsCsp(String(v), canvasOrigin, extraAncestors))
|
|
4672
4711
|
);
|
|
4673
4712
|
}
|
|
4674
4713
|
}
|
|
@@ -4682,7 +4721,7 @@ function installFrameHeadersMiddleware(req, res, getCanvasOrigin, next) {
|
|
|
4682
4721
|
const val = String(arg[i + 1] ?? "");
|
|
4683
4722
|
if (key.toLowerCase() === "x-frame-options") continue;
|
|
4684
4723
|
if (key.toLowerCase() === "content-security-policy" && canvasOrigin) {
|
|
4685
|
-
out.push(key, relaxFrameAncestorsCsp(val, canvasOrigin));
|
|
4724
|
+
out.push(key, relaxFrameAncestorsCsp(val, canvasOrigin, extraAncestors));
|
|
4686
4725
|
} else {
|
|
4687
4726
|
out.push(key, val);
|
|
4688
4727
|
}
|
|
@@ -4693,7 +4732,7 @@ function installFrameHeadersMiddleware(req, res, getCanvasOrigin, next) {
|
|
|
4693
4732
|
for (const [key, val] of Object.entries(arg)) {
|
|
4694
4733
|
if (key.toLowerCase() === "x-frame-options") continue;
|
|
4695
4734
|
if (key.toLowerCase() === "content-security-policy" && canvasOrigin && val !== void 0) {
|
|
4696
|
-
cleaned[key] = Array.isArray(val) ? val.map((v) => relaxFrameAncestorsCsp(String(v), canvasOrigin)) : relaxFrameAncestorsCsp(String(val), canvasOrigin);
|
|
4735
|
+
cleaned[key] = Array.isArray(val) ? val.map((v) => relaxFrameAncestorsCsp(String(v), canvasOrigin, extraAncestors)) : relaxFrameAncestorsCsp(String(val), canvasOrigin, extraAncestors);
|
|
4697
4736
|
} else {
|
|
4698
4737
|
cleaned[key] = val;
|
|
4699
4738
|
}
|
|
@@ -4999,7 +5038,13 @@ function pinsight(options = {}) {
|
|
|
4999
5038
|
const virtualRouteRegex = buildVirtualRouteRegex(basePrefix);
|
|
5000
5039
|
const internalCompilePath = `${basePrefix}/__pinsight/__internal/compile-check`;
|
|
5001
5040
|
server.middlewares.use((req, res, next) => {
|
|
5002
|
-
installFrameHeadersMiddleware(
|
|
5041
|
+
installFrameHeadersMiddleware(
|
|
5042
|
+
req,
|
|
5043
|
+
res,
|
|
5044
|
+
() => canvasOrigin,
|
|
5045
|
+
next,
|
|
5046
|
+
() => options.frameAncestors ?? []
|
|
5047
|
+
);
|
|
5003
5048
|
});
|
|
5004
5049
|
server.middlewares.use(async (req, res, next) => {
|
|
5005
5050
|
if (req.method !== "POST" || (req.url ?? "").split("?")[0] !== internalCompilePath) {
|
|
@@ -5139,6 +5184,7 @@ export {
|
|
|
5139
5184
|
detectTailwindMajor,
|
|
5140
5185
|
escapeRegex,
|
|
5141
5186
|
generateVirtualEntryCode,
|
|
5187
|
+
getDefaultDevFrameAncestors,
|
|
5142
5188
|
injectTailwindV4Source,
|
|
5143
5189
|
installFrameHeadersMiddleware,
|
|
5144
5190
|
invalidateVirtualEntryModules,
|