@pinsight/vite 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/bridge.mjs +25 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +5151 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pinsight Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/bridge.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function x(i){let{getNodeId:e,hot:t}=i,n=0,o=Date.now(),r=10,s=(h,l,u)=>{if(!t)return;let p=Date.now();if(p-o>1e3&&(o=p,n=0),++n>r)return;let R={nodeId:e(),url:window.location.href,kind:h,message:l.slice(0,1e3),stack:u?.slice(0,2e3),capturedAt:p};t.send("pinsight:runtime-error",R)},a=()=>{if(!t)return;let h={nodeId:e(),url:window.location.href,bootedAt:Date.now()};t.send("pinsight:page-boot",h)},c=h=>{let l=h.message||(h.error instanceof Error?h.error.message:"Uncaught error"),u=h.error instanceof Error?h.error.stack:void 0;s("runtime",l,u)},d=h=>{let l=h.reason,u=l instanceof Error?l.message:typeof l=="string"?l:"Unhandled promise rejection",p=l instanceof Error?l.stack:void 0;s("runtime",u,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(" "),u=h.find(p=>p instanceof Error);s("console_error",l,u?.stack)},window.addEventListener("error",c),window.addEventListener("unhandledrejection",d),t?.on?.("vite:afterUpdate",a),a(),()=>{window.removeEventListener("error",c),window.removeEventListener("unhandledrejection",d),console.error=m}}var I=/^(?:[a-z0-9-]+(?:\[[^\]]+\])?:)+/i,A=/^(?:(?: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|\[[^\]]+\])$)/,$=/^(?: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)$/,_=/^(?::r[0-9a-z]+:|headlessui-.+-\d+|radix-:r.+|[a-f0-9-]{16,})$/i,O=/^[a-z0-9]+_[a-zA-Z0-9]{5,}$/;function M(i){let e=i.replace(I,"").replace(/^[!-]+/,"").replace(/!$/,"");return!e||e.startsWith("[")&&e.endsWith("]")?!0:$.test(e)||A.test(e)}function w(i){return typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(i):i.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`)}function b(i,e=document){try{return e.querySelectorAll(i).length===1}catch{return!1}}function N(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 L(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 H(i){let e=[],t=i,n=0;for(;t&&t!==document.body&&t!==document.documentElement&&n<6;){let o=t.tagName.toLowerCase();for(let d of["data-testid","data-cy","data-slot"]){let m=t.getAttribute(d);if(m){let h=[`${o}[${d}="${w(m)}"]`,...e].join(" > ");if(b(h))return h}}if(t.id&&!_.test(t.id)){let d=[`#${w(t.id)}`,...e].join(" > ");if(b(d))return d}let r=Array.from(t.classList).filter(d=>d.length>1&&!M(d)&&!O.test(d)).slice(0,2).map(d=>`.${w(d)}`).join(""),s=N(t),a=`${o}${r}${s.total>1?`:nth-of-type(${s.index})`:""}`;e.unshift(a);let c=e.join(" > ");if(b(c))return c;t=t.parentElement,n++}return e.join(" > ")||i.tagName.toLowerCase()}function f(i){return(i??"").replace(/\s+/g," ").trim().slice(0,60)}function E(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 S(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 z(i){let e=i.tagName.toLowerCase(),t=f(i.textContent),n=E(i),o=i.getAttribute("role")??i.getAttribute("type")??"",r=S(i),s=0;if(t||n){let a=Array.from(document.querySelectorAll(e)),c=0;for(let d of a){if(d===i){s=c;break}(t&&f(d.textContent)===t||!t&&n&&E(d)===n)&&c++}}return{tag:e,ownText:t,ariaLabel:n,role:o,landmark:r,sameTextIndex:s}}function C(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 c=f(a.textContent);if(!c||c===e.ownText||c.includes(e.ownText)||e.ownText.includes(c))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),c=E(s),d=S(s),m=a||c,h=m?r.get(m)??0:-1;m&&r.set(m,h+1);let l=0,u=!1;e.ariaLabel&&c&&c===e.ariaLabel&&(l+=45,u=!0),e.ownText&&a&&(a===e.ownText?(l+=45,u=!0):(a.includes(e.ownText)||e.ownText.includes(a))&&(l+=25,u=!0)),e.landmark&&d&&d===e.landmark&&(l+=15),u&&h===e.sameTextIndex&&(l+=15),l>o&&(o=l,n=s)}return o>=50?n:null}function k(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 c=a.textContent?.trim();c&&t.appendChild(document.createTextNode(c.slice(0,80)))}else a.nodeType===1&&(r<5?(t.appendChild(k(a,e+1)),r++):s++);return s>0&&t.appendChild(document.createComment(` +${s} children `)),t}function U(i){let e=k(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}"`:"",c=s?` class="${s.trim().split(/\s+/).slice(0,8).join(" ")}"`:"";n=`<!-- parent: <${r}${a}${c}> -->
|
|
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=z(i);return{cssSelector:H(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:U(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 L(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 B(){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 T(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(B())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 v(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],[c,d])=>s===c?a.localeCompare(d):s.localeCompare(c))).toString(),r=e.hash.startsWith("#/")?e.hash:"";return`${e.origin}${t}${o?`?${o}`:""}${r}`}catch{return i.trim()}}var D={open:"#ef4444",fixed:"#f59e0b",resolved:"#10b981"};function F(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 y=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
|
+
.pinsight-pin-dot {
|
|
4
|
+
position: absolute;
|
|
5
|
+
top: 0;
|
|
6
|
+
left: 0;
|
|
7
|
+
width: 24px;
|
|
8
|
+
height: 24px;
|
|
9
|
+
border-radius: 9999px;
|
|
10
|
+
border: 2px solid #ffffff;
|
|
11
|
+
color: #ffffff;
|
|
12
|
+
font: 700 11px/1 system-ui, -apple-system, sans-serif;
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: center;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
cursor: pointer;
|
|
17
|
+
pointer-events: auto;
|
|
18
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.28);
|
|
19
|
+
padding: 0;
|
|
20
|
+
transition: box-shadow 120ms ease;
|
|
21
|
+
}
|
|
22
|
+
.pinsight-pin-dot[data-active="true"] {
|
|
23
|
+
box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.45), 0 4px 12px rgba(0,0,0,0.35);
|
|
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=v(window.location.href),t=this.pins.filter(o=>v(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 c=s.getBoundingClientRect();this.onPinClick(o.id,c.left+c.width/2,c.top+c.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=D[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=C(e.item.anchor)),e.el){e.state="active";let t=F(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 X(){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 j(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=()=>X(),r=l=>{!t||window.parent===window||window.parent.postMessage(l,t)},s=x({getNodeId:o,hot:n}),a=null,c=null,d=()=>{a||(a=new y((l,u,p)=>{r({type:"pinsight:pin-clicked",pinId:l,clientX:u,clientY:p})},l=>{r({type:"pinsight:pin-rects",url:window.location.href,rects:l})}),c=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",d,{once:!0}):d();let m=T({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 u=l.data;if(!(!u||typeof u!="object"||typeof u.type!="string"))switch(d(),u.type){case"pinsight:set-mode":c?.setEnabled(u.mode==="inspect");break;case"pinsight:sync-pins":a?.syncPins(u.pins,u.activePinId);break;case"pinsight:highlight-pin":a?.setActivePin(u.pinId);break;case"pinsight:navigate":u.url&&window.location.assign(u.url);break;case"pinsight:history-back":window.history.back();break;case"pinsight:reload":window.location.reload();break;case"pinsight:scroll-to-pin":a?.scrollToPinWithRetry(u.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(),c?.destroy(),a?.destroy()}}}typeof window<"u"&&typeof __PINSIGHT_BRIDGE_CONFIG__<"u"&&__PINSIGHT_BRIDGE_CONFIG__?.canvasOrigin&&j();export{g as ElementInspector,y as PinOverlayLayer,P as buildPinAnchor,H as buildSemanticSelector,z as buildTextSignature,U as compactOuterHtml,F as detectPositioningMode,j as initBridge,x as installErrorTap,T as installNavAndKeyTap,B as isEditableFocus,M as isTailwindUtility,X as resolveCurrentNodeId,C as resolvePinElement,L as snapInteractiveTarget};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Plugin, ViteDevServer } from 'vite';
|
|
2
|
+
import http from 'node:http';
|
|
3
|
+
|
|
4
|
+
declare function relaxFrameAncestorsCsp(cspValue: string, canvasOrigin: string): string;
|
|
5
|
+
declare function installFrameHeadersMiddleware(req: http.IncomingMessage, res: http.ServerResponse, getCanvasOrigin: () => string, next: () => void): void;
|
|
6
|
+
|
|
7
|
+
interface TailwindDetectionResult {
|
|
8
|
+
majorVersion: number | null;
|
|
9
|
+
v3Warning: string | null;
|
|
10
|
+
v4OrderWarning: string | null;
|
|
11
|
+
}
|
|
12
|
+
declare function detectTailwindMajor(workspaceRoot: string): number | null;
|
|
13
|
+
declare function checkTailwindV3Config(workspaceRoot: string): string | null;
|
|
14
|
+
declare function injectTailwindV4Source(cssCode: string, cssFilePath: string, workspaceRoot: string): string | null;
|
|
15
|
+
declare function createTailwindPrePlugin(onDetected: (result: TailwindDetectionResult) => void): Plugin;
|
|
16
|
+
|
|
17
|
+
declare const VIRTUAL_ENTRY_PREFIX = "pinsight:entry:";
|
|
18
|
+
declare const RESOLVED_ENTRY_PREFIX = "\0pinsight:entry:";
|
|
19
|
+
declare const VIRTUAL_BRIDGE_ID = "pinsight:bridge";
|
|
20
|
+
declare const RESOLVED_BRIDGE_ID = "\0pinsight:bridge";
|
|
21
|
+
declare function normalizeBasePrefix(base: string): string;
|
|
22
|
+
declare function escapeRegex(str: string): string;
|
|
23
|
+
declare function buildVirtualRouteRegex(basePrefix: string): RegExp;
|
|
24
|
+
declare function loadBridgeBundleSource(): string;
|
|
25
|
+
declare function buildBridgeVirtualModule(canvasOrigin: string): string;
|
|
26
|
+
declare function buildFallbackVirtualHtml(basePrefix: string, topic: string, variant: string): string;
|
|
27
|
+
declare function generateVirtualEntryCode(workspaceRoot: string, topic: string, variant: string): Promise<string>;
|
|
28
|
+
declare function invalidateVirtualEntryModules(server: ViteDevServer): void;
|
|
29
|
+
|
|
30
|
+
interface CompileErrorItem {
|
|
31
|
+
message: string;
|
|
32
|
+
frame?: string;
|
|
33
|
+
loc?: {
|
|
34
|
+
file: string;
|
|
35
|
+
line: number;
|
|
36
|
+
column: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface CompileCheckOutput {
|
|
40
|
+
ok: boolean;
|
|
41
|
+
errors: CompileErrorItem[];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Performs compile check via Vite server.transformRequest + moduleGraph BFS
|
|
45
|
+
* (covers multi-level imports, path aliases, and CSS; note: syntax/resolve only, not tsc).
|
|
46
|
+
*/
|
|
47
|
+
declare function runViteCompileCheck(server: ViteDevServer, workspaceRoot: string, nodeId: string): Promise<CompileCheckOutput>;
|
|
48
|
+
declare function attachErrorRelay(options: {
|
|
49
|
+
server: ViteDevServer;
|
|
50
|
+
workspaceRoot: string;
|
|
51
|
+
getCanvasTarget: () => {
|
|
52
|
+
canvasOrigin: string;
|
|
53
|
+
token: string;
|
|
54
|
+
} | null;
|
|
55
|
+
}): void;
|
|
56
|
+
|
|
57
|
+
interface PinsightPluginOptions {
|
|
58
|
+
/** Preferred starting port for Canvas Server (default: 4310) */
|
|
59
|
+
port?: number;
|
|
60
|
+
/** Disable auto-launching the canvas server (useful in tests) */
|
|
61
|
+
autoStartServer?: boolean;
|
|
62
|
+
/** Override canvasOrigin when autoStartServer is false */
|
|
63
|
+
canvasOrigin?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare function pinsight(options?: PinsightPluginOptions): Plugin[];
|
|
67
|
+
|
|
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 };
|