import{copyDocumentForFigmaNewOfficialClipboard as y,captureDocumentForFigmaNew as b,buildOfficialClipboardPayloadFromCapturedDocument as x,htmlToAxure as A,toPng as S}from"./chunks/vendor-export.js";import"./chunks/_commonjsHelpers.js";import"./chunks/preload-helper.js";const R="/api/export/image-proxy",v=`data:image/svg+xml;charset=utf-8,${encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="1" height="1" viewBox="0 0 1 1"></svg>')}`;function C(){try{return new URL(import.meta.url,window.location.href).origin}catch{return window.location.origin}}function p(e){var r;if(typeof window>"u"||!((r=window.location)!=null&&r.origin))return null;try{const i=new URL(e,document.baseURI).href,t=new URL(i);return!/^https?:$/i.test(t.protocol)||t.origin===window.location.origin?null:`${C()}${R}?url=${encodeURIComponent(i)}`}catch{return null}}function E(e){const r=[];if(!e||e==="none")return r;const i=/url\((['"]?)(.*?)\1\)/g;let t=null;for(;(t=i.exec(e))!==null;){const o=String(t[2]||"").trim();o&&r.push(o)}return r}function F(e){const r=[];return[e,...Array.from(e.querySelectorAll("*"))].forEach(t=>{if(t instanceof HTMLImageElement){const n=t.getAttribute("src"),l=t.currentSrc||n,u=l?p(l):null;if(!l||!u)return;const f=t.getAttribute("srcset"),d=t.getAttribute("sizes");t.setAttribute("src",u),t.removeAttribute("srcset"),t.removeAttribute("sizes"),r.push(()=>{n!==null?t.setAttribute("src",n):t.removeAttribute("src"),f!==null?t.setAttribute("srcset",f):t.removeAttribute("srcset"),d!==null?t.setAttribute("sizes",d):t.removeAttribute("sizes")});return}if(!(t instanceof HTMLElement))return;const o=t.style.backgroundImage,s=window.getComputedStyle(t).backgroundImage,g=o||s,a=E(g);if(a.length===0)return;let c=g,m=!1;if(a.forEach(n=>{const l=p(n);if(!l)return;const u=`url("${l}")`;c=c.replace(`url(${n})`,u).replace(`url('${n}')`,u).replace(`url("${n}")`,u),m=!0}),!m||c===g)return;const h=t.style.backgroundImage;t.style.setProperty("background-image",c,"important"),r.push(()=>{h?t.style.backgroundImage=h:t.style.removeProperty("background-image")})}),()=>{for(let t=r.length-1;t>=0;t-=1)r[t]()}}function I(e){const r=typeof e=="string"?document.querySelector(e):e;if(!(r instanceof HTMLElement))throw new Error("captureDocumentScreenshot: target element not found");return r}function w(e){const r=Number(e);return Number.isFinite(r)&&r>0?Math.round(r):void 0}function P(e){const r=e.getBoundingClientRect();return{width:Math.max(1,Math.round(Math.max(r.width,e.scrollWidth,e.clientWidth,e.offsetWidth))),height:Math.max(1,Math.round(Math.max(r.height,e.scrollHeight,e.clientHeight,e.offsetHeight)))}}function M(e="body"){return y(e)}function U(e="body"){return b(e)}function D(e){return x(e)}function T(e="body",r){return A(e,r)}async function N(e="body",r={}){const i=I(e),t=w(r.targetWidth),o=w(r.targetHeight),s={marginLeft:i.style.marginLeft,marginRight:i.style.marginRight,width:i.style.width,height:i.style.height};i.style.marginLeft="0",i.style.marginRight="0",t&&(i.style.width=`${t}px`),o&&(i.style.height=`${o}px`),(t||o)&&await new Promise(a=>window.setTimeout(a,100));const g=F(i);try{await new Promise(n=>window.setTimeout(n,80));const{width:a,height:c}=P(i),m=Math.max(1,Math.min(2,window.devicePixelRatio||2));return{dataUrl:await S(i,{width:a,height:c,canvasWidth:a,canvasHeight:c,pixelRatio:m,skipAutoScale:!0,backgroundColor:"#fff",skipFonts:!1,cacheBust:!1,includeQueryParams:!0,imagePlaceholder:v,onImageErrorHandler:(...n)=>{console.warn("[Axhub Runtime Export] Screenshot ignored image loading failure",n)}}),width:a,height:c}}finally{g(),i.style.marginLeft=s.marginLeft,i.style.marginRight=s.marginRight,i.style.width=s.width,i.style.height=s.height}}export{D as buildOfficialClipboardPayloadFromCapturedDocument,U as captureDocumentForFigmaNew,N as captureDocumentScreenshot,M as copyDocumentForFigmaNewOfficialClipboard,T as htmlToAxure};
