@lightworkai.official/debug-capture 0.10.0 → 0.10.2

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.
@@ -30,7 +30,7 @@
30
30
  }
31
31
  @keyframes in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
32
32
  @media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
33
- `;let Q=document.createElement("div");return Q.className="stack",Q.setAttribute("role","status"),Q.setAttribute("aria-live","polite"),j.append(J,Q),document.body.append($),I0=Q,Q}function l($,j="success",J){let Q=a2();if(!Q)return;let z=document.createElement("div");z.className="toast",z.dataset.tone=j;let W=document.createElement("span");W.className="dot";let V=document.createElement("span");V.textContent=$;let Y=document.createElement("button");Y.type="button",Y.className="close",Y.textContent="✕",Y.setAttribute("aria-label","ปิด");let w=()=>{window.clearTimeout(H),z.remove()};Y.addEventListener("click",w);let H=j==="error"||J?0:window.setTimeout(w,6000);if(z.append(W,V),J){let U=document.createElement("button");U.type="button",U.className="action",U.textContent=J.label,U.addEventListener("click",()=>{w(),J.onClick()}),z.append(U)}z.append(Y),Q.append(z)}function B1($,j,J){let Q=$.filter((W)=>Boolean(W.error)||W.status!=null&&W.status>=400).slice(-20).map((W)=>({method:W.method,url:W.url,status:W.status,error:W.error,at:W.startedAt})),z=j.filter((W)=>W.level==="error"||W.level==="exception"||W.level==="unhandledrejection").slice(-20).map((W)=>W.message);return{failedRequests:Q,errors:z,erroredQueries:J.slice(0,20)}}function t2(){let $={memoryUsedMb:null,memoryLimitMb:null,domContentLoadedMs:null,loadEventMs:null};if(typeof performance>"u")return $;let j=performance.memory;if(j)$.memoryUsedMb=Math.round(j.usedJSHeapSize/1024/1024),$.memoryLimitMb=Math.round(j.jsHeapSizeLimit/1024/1024);let[J]=performance.getEntriesByType("navigation");if(J)$.domContentLoadedMs=Math.round(J.domContentLoadedEventEnd),$.loadEventMs=Math.round(J.loadEventEnd);return $}function U0($,j){if(!$)return j;try{return $()}catch{return j}}function q1(){let $=k(),{pathname:j,search:J,href:Q}=window.location;return{capturedAt:new Date().toISOString(),route:{href:Q,pathname:j,search:J},module:L0(j),user:U0($.user,{}),apiHeaders:u(U0($.headers,{})),app:{name:h().name,version:h().version,environment:h().environment},client:{userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,online:navigator.onLine,viewport:{width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio},screen:{width:window.screen.width,height:window.screen.height}},performance:t2(),extra:U0($.extra,{})}}var e2=2;function D1($){let j=N1(),J=e0();return{context:q1(),reason:$.reason,note:$.note,cause:B1(j,J,$.erroredQueries),actionTrail:l0(),network:j,console:J,screenshotDataUrl:$.screenshotDataUrl,screenshotMethod:$.screenshotMethod,meta:{generatedBy:"lightwork-debug-capture",schemaVersion:e2}}}async function k1(){if(typeof navigator<"u"&&Boolean(navigator.mediaDevices?.getDisplayMedia)){let J=await $4();if(J.status==="ok")return{dataUrl:J.dataUrl,method:"display-media"};if(J.status==="cancelled")return{dataUrl:null,method:"cancelled"}}let j=await Q4();if(j)return{dataUrl:j,method:"html-to-image"};return{dataUrl:null,method:"none"}}async function $4(){let $=null;try{let j={video:{frameRate:30},audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude"};$=await navigator.mediaDevices.getDisplayMedia(j);let J=await j4($);return J?{status:"ok",dataUrl:J}:{status:"error"}}catch(j){if(j instanceof DOMException&&(j.name==="NotAllowedError"||j.name==="AbortError"))return{status:"cancelled"};return{status:"error"}}finally{$?.getTracks().forEach((j)=>j.stop())}}async function j4($){let j=document.createElement("video");j.srcObject=$,j.muted=!0,j.playsInline=!0,await new Promise((V)=>{let Y=!1,w=()=>{if(Y)return;Y=!0,V()};j.onloadedmetadata=()=>{j.play().then(w).catch(w)},window.setTimeout(w,1500)}),await J4(j);let{videoWidth:J,videoHeight:Q}=j;if(!J||!Q)return null;let z=document.createElement("canvas");z.width=J,z.height=Q;let W=z.getContext("2d");if(!W)return null;W.drawImage(j,0,0,J,Q),j.pause(),j.srcObject=null;try{return z.toDataURL("image/png")}catch{return null}}function J4($){return new Promise((j)=>{let J=!1,Q=()=>{if(J)return;J=!0,j()},z=$;if(typeof z.requestVideoFrameCallback==="function")z.requestVideoFrameCallback(()=>Q()),window.setTimeout(Q,1000);else window.setTimeout(Q,250)})}async function Q4(){let $=k().screenshotFallback;if(!$)return null;let j=await $().catch(()=>null);if(!j)return null;try{return await j(document.body,{cacheBust:!0,pixelRatio:Math.min(window.devicePixelRatio||1,2),filter:(J)=>!(J instanceof HTMLElement&&J.dataset?.debugReporter==="true")})}catch{return null}}var z4=2000,Z4=0.82,W4=3000000;function K4($){return new Promise((j,J)=>{let Q=new Image;Q.onload=()=>j(Q),Q.onerror=()=>J(Error("could not read the screenshot")),Q.src=$})}async function S1($){try{let j=await K4($),J=Math.max(j.naturalWidth,j.naturalHeight),Q=Math.min(1,z4/J),z=document.createElement("canvas");z.width=Math.max(1,Math.round(j.naturalWidth*Q)),z.height=Math.max(1,Math.round(j.naturalHeight*Q));let W=z.getContext("2d");if(!W)return $;W.fillStyle="#fff",W.fillRect(0,0,z.width,z.height),W.drawImage(j,0,0,z.width,z.height);let V=Z4,Y=z.toDataURL("image/jpeg",V);while(Y.length>W4&&V>0.4)V-=0.15,Y=z.toDataURL("image/jpeg",V);return Y}catch{return $}}var V4=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,G4=/^\d+$/,X4=/^[0-9a-f]{16,}$/i;function R1($){if($.reason.type==="manual")return null;let j=$.cause?.failedRequests?.[0];if(!j?.url)return null;let J;try{J=new URL(j.url,"http://x").pathname}catch{J=j.url}let Q=J.split("/").map((W)=>V4.test(W)||G4.test(W)||X4.test(W)?":id":W).join("/"),z=j.status??(j.error?"ERR":"?");return`${j.method??"REQ"} ${Q} ${z}`}var O1=2000000;function W0($){let{screenshotDataUrl:j,...J}=$;return JSON.stringify(J).length}function f1($,j=2000000){if(W0($)<=j)return $;let J=$.network.map((z)=>({...z})),Q={...$,network:J};for(let z of J){if(W0(Q)<=j)return Q;if(typeof z.responseSnippet==="string"&&z.responseSnippet.length>35)z.responseSnippet="[body dropped — report size budget]";if(typeof z.requestBody==="string"&&z.requestBody.length>35)z.requestBody="[body dropped — report size budget]"}while(Q.network.length>1&&W0(Q)>j)Q.network=Q.network.slice(1);while(Q.console.length>1&&W0(Q)>j)Q.console=Q.console.slice(1);return Q}var _1=32768;function Y4($){let j="";for(let J=0;J<$.length;J+=_1)j+=String.fromCharCode(...$.subarray(J,J+_1));return btoa(j)}function F4($){return{dataUri:`data:application/json;base64,${Y4(new TextEncoder().encode(JSON.stringify($)))}`,filename:"debug-bundle.json"}}async function w4(){let $=k().identity;if(!$)return{};try{let j=await $();return j?{authorization:`Bearer ${j}`}:{}}catch{return{}}}async function T1($,j){let J=k(),Q=f1(j,O1),{context:z,note:W}=Q,V=[];if(Q.screenshotDataUrl){let U=await S1(Q.screenshotDataUrl);V.push({dataUri:U,filename:"screenshot.jpg"})}V.push(F4(Q));let Y=R1(Q),w={title:$,description:W.trim()||void 0,appName:h().name,category:z.module?.label,routeUrl:z.route.href,priority:"MEDIUM",requesterEmail:z.user.email??void 0,requesterName:z.user.fullName??void 0,customFields:{unit:z.user.unit??"",appVersion:z.app.version,environment:z.app.environment,reasonType:Q.reason.type,appName:h().name,module:z.module?.label??""},context:{...Y?{signature:Y}:{},capturedAt:z.capturedAt,reason:Q.reason,cause:Q.cause,actionTrail:Q.actionTrail,client:z.client,performance:z.performance,apiHeaders:z.apiHeaders,extra:z.extra,counts:{network:Q.network.length,console:Q.console.length,actions:Q.actionTrail.length},screenshotMethod:Q.screenshotMethod},attachments:V},H=await fetch(`${J.host.replace(/\/$/,"")}/ingest/tickets`,{method:"POST",headers:{"content-type":"application/json","x-realm-key":J.realmKey,...await w4()},body:JSON.stringify(w)});if(!H.ok){let U=H.headers.get("retry-after"),P=await H.json().then((C)=>C.error).catch(()=>null);throw Error(H.status===429?`Too many reports — try again in ${U??"a moment"}s`:P??`Report failed (${H.status})`)}return await H.json()}var r=Math.PI/6;function A1($,j,J){let Q=j.x-$.x,z=j.y-$.y,W=Math.hypot(Q,z),V=Math.atan2(z,Q),Y=[{x:j.x,y:j.y},{x:j.x-J*Math.cos(V-r),y:j.y-J*Math.sin(V-r)},{x:j.x-J*Math.cos(V+r),y:j.y-J*Math.sin(V+r)}],w=J*Math.cos(r)*0.92;if(W<=w)return{shaft:null,head:Y};return{shaft:{from:$,to:{x:j.x-w*Math.cos(V),y:j.y-w*Math.sin(V)}},head:Y}}var C0="#f44336",M4="rgba(250, 204, 21, 0.4)",P0=22,L1="#2563eb",E1=9,x1=11,h1=18,p1=4,K0=8,H4=[{id:"nw",fx:0,fy:0,cursor:"nwse-resize"},{id:"n",fx:0.5,fy:0,cursor:"ns-resize"},{id:"ne",fx:1,fy:0,cursor:"nesw-resize"},{id:"e",fx:1,fy:0.5,cursor:"ew-resize"},{id:"se",fx:1,fy:1,cursor:"nwse-resize"},{id:"s",fx:0.5,fy:1,cursor:"ns-resize"},{id:"sw",fx:0,fy:1,cursor:"nesw-resize"},{id:"w",fx:0,fy:0.5,cursor:"ew-resize"}];function m1($,j,J){let Q=[],z=null,W=-1,V=null,Y=null,w=$.getContext("2d");function H(){let Z=$.getBoundingClientRect().width;return Z>0?$.width/Z:1}function U(Z){let K=$.getBoundingClientRect();return{x:(Z.clientX-K.left)/K.width*$.width,y:(Z.clientY-K.top)/K.height*$.height}}function P(Z){let K=Z.size??P0;if(!w)return(Z.text?.length??0)*K*0.6;w.save(),w.font=`600 ${K}px system-ui, sans-serif`;let X=w.measureText(Z.text??"").width;return w.restore(),X}function C(Z){if(Z.tool==="text"){let K=Z.size??P0;return{left:Z.x1,top:Z.y1,right:Z.x1+P(Z),bottom:Z.y1+K*1.25}}return{left:Math.min(Z.x1,Z.x2),top:Math.min(Z.y1,Z.y2),right:Math.max(Z.x1,Z.x2),bottom:Math.max(Z.y1,Z.y2)}}function S(Z){if(Z.tool==="arrow")return[{id:"tail",x:Z.x1,y:Z.y1,cursor:"move"},{id:"head",x:Z.x2,y:Z.y2,cursor:"move"}];let K=C(Z);if(Z.tool==="text")return[{id:"size",x:K.right,y:K.bottom,cursor:"nwse-resize"}];return H4.map((X)=>({id:X.id,x:K.left+(K.right-K.left)*X.fx,y:K.top+(K.bottom-K.top)*X.fy,cursor:X.cursor}))}function q(Z){let K=C(Z);return{x:K.right+h1*H(),y:K.top-h1*H()}}function D(Z,K,X){let{shaft:G,head:F}=A1({x:K.x1,y:K.y1},{x:K.x2,y:K.y2},Math.max(10,16*X));if(G)Z.lineCap="butt",Z.beginPath(),Z.moveTo(G.from.x,G.from.y),Z.lineTo(G.to.x,G.to.y),Z.stroke();Z.beginPath(),Z.moveTo(F[0].x,F[0].y),Z.lineTo(F[1].x,F[1].y),Z.lineTo(F[2].x,F[2].y),Z.closePath(),Z.fill()}function f(Z,K,X){Z.save(),Z.lineWidth=Math.max(2,3*X),Z.strokeStyle=C0,Z.fillStyle=C0;let G=C(K);if(K.tool==="rect")Z.strokeRect(G.left,G.top,G.right-G.left,G.bottom-G.top);else if(K.tool==="arrow")D(Z,K,X);else if(K.tool==="highlight")Z.fillStyle=M4,Z.fillRect(G.left,G.top,G.right-G.left,G.bottom-G.top);else if(K.tool==="text"&&K.text){let F=K.size??P0;Z.font=`600 ${F}px system-ui, sans-serif`,Z.textBaseline="top";let M=F*0.22;Z.fillStyle="rgba(255,255,255,0.92)",Z.fillRect(G.left-M,G.top-M,G.right-G.left+M*2,G.bottom-G.top+M*2),Z.fillStyle=C0,Z.fillText(K.text,G.left,G.top)}Z.restore()}function s(Z,K,X){let G=C(K);Z.save(),Z.strokeStyle=L1,Z.lineWidth=Math.max(1,1.5*X),Z.setLineDash([6*X,4*X]),Z.strokeRect(G.left,G.top,G.right-G.left,G.bottom-G.top),Z.setLineDash([]);let F=E1*X;for(let R of S(K))Z.fillStyle="#fff",Z.strokeStyle=L1,Z.lineWidth=Math.max(1,1.5*X),Z.beginPath(),Z.rect(R.x-F/2,R.y-F/2,F,F),Z.fill(),Z.stroke();let M=q(K),I=x1*X;Z.beginPath(),Z.arc(M.x,M.y,I,0,Math.PI*2),Z.fillStyle="#dc2626",Z.fill(),Z.strokeStyle="#fff",Z.lineWidth=Math.max(1.5,2*X),Z.beginPath(),Z.moveTo(M.x-I*0.4,M.y-I*0.4),Z.lineTo(M.x+I*0.4,M.y+I*0.4),Z.moveTo(M.x+I*0.4,M.y-I*0.4),Z.lineTo(M.x-I*0.4,M.y+I*0.4),Z.stroke(),Z.restore()}function N(){if(!w)return;let Z=H();if(w.clearRect(0,0,$.width,$.height),w.drawImage(j,0,0,$.width,$.height),Q.forEach((X,G)=>{if(G!==a)f(w,X,Z)}),V)f(w,V,Z);let K=Q[W];if(K&&!V)s(w,K,Z)}function B0(Z,K,X,G,F){return Math.abs(Z-X)<=F&&Math.abs(K-G)<=F}function q0(Z,K){let X=Q[W];if(!X)return null;let G=E1*H()/2+3*H();for(let F of S(X))if(B0(Z,K,F.x,F.y,G))return F.id;return null}function D0(Z,K){let X=Q[W];if(!X)return!1;let G=q(X);return B0(Z,K,G.x,G.y,x1*H())}function V0(Z,K){let X=6*H();for(let G=Q.length-1;G>=0;G-=1){let F=Q[G];if(F.tool==="arrow"){let I=F.x2-F.x1,R=F.y2-F.y1,E=Math.hypot(I,R)||1,x=Math.max(0,Math.min(1,((Z-F.x1)*I+(K-F.y1)*R)/(E*E)));if(Math.hypot(Z-(F.x1+x*I),K-(F.y1+x*R))<=X+4*H())return G;continue}let M=C(F);if(Z>=M.left-X&&Z<=M.right+X&&K>=M.top-X&&K<=M.bottom+X)return G}return-1}function u1(Z,K,X,G,F){if(K==="tail"){Z.x1=X.x1+G,Z.y1=X.y1+F;return}if(K==="head"){Z.x2=X.x2+G,Z.y2=X.y2+F;return}if(K==="size"){let c1=(X.size??24)+F;Z.size=Math.max(10,c1);return}let M=C(X),{left:I,top:R,right:E,bottom:x}=M;if(K.includes("w"))I=Math.min(E-K0,I+G);if(K.includes("e"))E=Math.max(I+K0,E+G);if(K.includes("n"))R=Math.min(x-K0,R+F);if(K.includes("s"))x=Math.max(R+K0,x+F);Z.x1=I,Z.y1=R,Z.x2=E,Z.y2=x}function i1(Z,K,X,G){Z.x1=K.x1+X,Z.y1=K.y1+G,Z.x2=K.x2+X,Z.y2=K.y2+G}let _=null,a=-1,T={x:0,y:0,size:24};function o1(){let Z=$.getBoundingClientRect().width;return Z>0?Z/$.width:1}function d1(Z,K){if(!w)return Z.length*K*0.6;w.save(),w.font=`600 ${K}px system-ui, sans-serif`;let X=w.measureText(Z||" ").width;return w.restore(),X}function k0(){if(!_)return;let Z=$.parentElement;if(!Z)return;let K=$.getBoundingClientRect(),X=Z.getBoundingClientRect(),G=o1(),F=T.size*G;_.style.left=`${K.left-X.left+T.x*G}px`,_.style.top=`${K.top-X.top+T.y*G}px`,_.style.fontSize=`${F}px`,_.style.width=`${Math.max(40,d1(_.value,F)+F)}px`}function y(Z){let K=_;if(!K)return;_=null;let X=K.value.trim(),G=a;if(a=-1,K.remove(),Z&&X){if(G>=0&&Q[G])Q[G].text=X,W=G;else Q.push({tool:"text",x1:T.x,y1:T.y,x2:T.x,y2:T.y,text:X,size:T.size}),W=Q.length-1;J()}else if(G>=0)W=G;$.focus(),N()}function S0(Z,K,X=-1){y(!0);let G=$.parentElement;if(!G)return;if(getComputedStyle(G).position==="static")G.style.position="relative";let F=X>=0?Q[X]:void 0;a=X,T={x:F?.x1??Z,y:F?.y1??K,size:F?.size??Math.round(24*H())};let M=document.createElement("input");M.type="text",M.className="text-edit",M.value=F?.text??"",M.setAttribute("aria-label","ข้อความบนภาพ"),M.placeholder="ข้อความ",_=M,G.append(M),k0(),M.addEventListener("input",k0),M.addEventListener("keydown",(I)=>{if(I.stopPropagation(),I.key==="Enter")y(!0);else if(I.key==="Escape")y(!1)}),requestAnimationFrame(()=>{if(_!==M)return;M.focus(),M.select(),M.addEventListener("blur",()=>y(!0))}),N()}function R0(Z){let{x:K,y:X}=U(Z);if($.setPointerCapture(Z.pointerId),D0(K,X)){G0();return}let G=q0(K,X);if(G&&Q[W]){Y={grip:G,x:K,y:X,start:{...Q[W]}};return}if(z==="text"){if(Z.preventDefault(),$.hasPointerCapture(Z.pointerId))$.releasePointerCapture(Z.pointerId);z=null,J(),S0(K,X);return}if(z){V={tool:z,x1:K,y1:X,x2:K,y2:X},W=-1;return}let F=V0(K,X);W=F,Y=F>=0?{grip:"body",x:K,y:X,start:{...Q[F]}}:null,N()}function O0(Z){let{x:K,y:X}=U(Z);if(V){V.x2=K,V.y2=X,N();return}if(Y){let F=Q[W];if(!F)return;let M=K-Y.x,I=X-Y.y;if(Y.grip==="body")i1(F,Y.start,M,I);else u1(F,Y.grip,Y.start,M,I);N();return}if(z){$.style.cursor="crosshair";return}if(D0(K,X)){$.style.cursor="pointer";return}let G=q0(K,X);if(G){let F=Q[W]?S(Q[W]).find((M)=>M.id===G):null;$.style.cursor=F?.cursor??"pointer";return}$.style.cursor=V0(K,X)>=0?"move":"default"}function t(){if(V){if(!(Math.abs(V.x2-V.x1)<p1&&Math.abs(V.y2-V.y1)<p1))Q.push(V),W=Q.length-1,z=null,J();V=null}if(Y)Y=null,J();N()}function f0(Z){let K=$.getBoundingClientRect(),X=(Z.clientX-K.left)/K.width*$.width,G=(Z.clientY-K.top)/K.height*$.height,F=V0(X,G),M=Q[F];if(!M||M.tool!=="text")return;Z.preventDefault(),S0(M.x1,M.y1,F)}function _0(Z){if(W<0)return;if(Z.key==="Delete"||Z.key==="Backspace")Z.preventDefault(),G0();else if(Z.key==="Escape")W=-1,N()}function G0(){if(W<0)return;Q.splice(W,1),W=-1,J(),N()}return $.addEventListener("pointerdown",R0),$.addEventListener("pointermove",O0),$.addEventListener("pointerup",t),$.addEventListener("pointercancel",t),$.addEventListener("dblclick",f0),$.tabIndex=0,$.addEventListener("keydown",_0),N(),{setTool(Z){z=Z,W=-1,$.style.cursor=Z?"crosshair":"default",N()},deleteSelected:G0,clear(){Q.length=0,W=-1,J(),N()},hasShapes:()=>Q.length>0,hasSelection:()=>W>=0,toDataUrl(){let Z=document.createElement("canvas");Z.width=j.naturalWidth,Z.height=j.naturalHeight;let K=Z.getContext("2d");if(!K)return $.toDataURL("image/png");K.drawImage(j,0,0);let X=H();for(let G of Q)f(K,G,X);return Z.toDataURL("image/png")},destroy(){y(!1),$.removeEventListener("pointerdown",R0),$.removeEventListener("pointermove",O0),$.removeEventListener("pointerup",t),$.removeEventListener("pointercancel",t),$.removeEventListener("dblclick",f0),$.removeEventListener("keydown",_0)}}}var g1=`
33
+ `;let Q=document.createElement("div");return Q.className="stack",Q.setAttribute("role","status"),Q.setAttribute("aria-live","polite"),j.append(J,Q),document.body.append($),I0=Q,Q}function l($,j="success",J){let Q=a2();if(!Q)return;let z=document.createElement("div");z.className="toast",z.dataset.tone=j;let W=document.createElement("span");W.className="dot";let V=document.createElement("span");V.textContent=$;let Y=document.createElement("button");Y.type="button",Y.className="close",Y.textContent="✕",Y.setAttribute("aria-label","ปิด");let w=()=>{window.clearTimeout(H),z.remove()};Y.addEventListener("click",w);let H=j==="error"||J?0:window.setTimeout(w,6000);if(z.append(W,V),J){let U=document.createElement("button");U.type="button",U.className="action",U.textContent=J.label,U.addEventListener("click",()=>{w(),J.onClick()}),z.append(U)}z.append(Y),Q.append(z)}function B1($,j,J){let Q=$.filter((W)=>Boolean(W.error)||W.status!=null&&W.status>=400).slice(-20).map((W)=>({method:W.method,url:W.url,status:W.status,error:W.error,at:W.startedAt})),z=j.filter((W)=>W.level==="error"||W.level==="exception"||W.level==="unhandledrejection").slice(-20).map((W)=>W.message);return{failedRequests:Q,errors:z,erroredQueries:J.slice(0,20)}}function t2(){let $={memoryUsedMb:null,memoryLimitMb:null,domContentLoadedMs:null,loadEventMs:null};if(typeof performance>"u")return $;let j=performance.memory;if(j)$.memoryUsedMb=Math.round(j.usedJSHeapSize/1024/1024),$.memoryLimitMb=Math.round(j.jsHeapSizeLimit/1024/1024);let[J]=performance.getEntriesByType("navigation");if(J)$.domContentLoadedMs=Math.round(J.domContentLoadedEventEnd),$.loadEventMs=Math.round(J.loadEventEnd);return $}function U0($,j){if(!$)return j;try{return $()}catch{return j}}function q1(){let $=k(),{pathname:j,search:J,href:Q}=window.location;return{capturedAt:new Date().toISOString(),route:{href:Q,pathname:j,search:J},module:L0(j),user:U0($.user,{}),apiHeaders:u(U0($.headers,{})),app:{name:h().name,version:h().version,environment:h().environment},client:{userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,online:navigator.onLine,viewport:{width:window.innerWidth,height:window.innerHeight,dpr:window.devicePixelRatio},screen:{width:window.screen.width,height:window.screen.height}},performance:t2(),extra:U0($.extra,{})}}var e2=2;function D1($){let j=N1(),J=e0();return{context:q1(),reason:$.reason,note:$.note,cause:B1(j,J,$.erroredQueries),actionTrail:l0(),network:j,console:J,screenshotDataUrl:$.screenshotDataUrl,screenshotMethod:$.screenshotMethod,meta:{generatedBy:"lightwork-debug-capture",schemaVersion:e2}}}async function k1(){if(typeof navigator<"u"&&Boolean(navigator.mediaDevices?.getDisplayMedia)){let J=await $4();if(J.status==="ok")return{dataUrl:J.dataUrl,method:"display-media"};if(J.status==="cancelled")return{dataUrl:null,method:"cancelled"}}let j=await Q4();if(j)return{dataUrl:j,method:"html-to-image"};return{dataUrl:null,method:"none"}}async function $4(){let $=null;try{let j={video:{frameRate:30},audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude"};$=await navigator.mediaDevices.getDisplayMedia(j);let J=await j4($);return J?{status:"ok",dataUrl:J}:{status:"error"}}catch(j){if(j instanceof DOMException&&(j.name==="NotAllowedError"||j.name==="AbortError"))return{status:"cancelled"};return{status:"error"}}finally{$?.getTracks().forEach((j)=>j.stop())}}async function j4($){let j=document.createElement("video");j.srcObject=$,j.muted=!0,j.playsInline=!0,await new Promise((V)=>{let Y=!1,w=()=>{if(Y)return;Y=!0,V()};j.onloadedmetadata=()=>{j.play().then(w).catch(w)},window.setTimeout(w,1500)}),await J4(j);let{videoWidth:J,videoHeight:Q}=j;if(!J||!Q)return null;let z=document.createElement("canvas");z.width=J,z.height=Q;let W=z.getContext("2d");if(!W)return null;W.drawImage(j,0,0,J,Q),j.pause(),j.srcObject=null;try{return z.toDataURL("image/png")}catch{return null}}function J4($){return new Promise((j)=>{let J=!1,Q=()=>{if(J)return;J=!0,j()},z=$;if(typeof z.requestVideoFrameCallback==="function")z.requestVideoFrameCallback(()=>Q()),window.setTimeout(Q,1000);else window.setTimeout(Q,250)})}async function Q4(){let $=k().screenshotFallback;if(!$)return null;let j=await $().catch(()=>null);if(!j)return null;try{return await j(document.body,{cacheBust:!0,pixelRatio:Math.min(window.devicePixelRatio||1,2),filter:(J)=>!(J instanceof HTMLElement&&J.dataset?.debugReporter==="true")})}catch{return null}}var z4=2000,Z4=0.82,W4=3000000;function K4($){return new Promise((j,J)=>{let Q=new Image;Q.onload=()=>j(Q),Q.onerror=()=>J(Error("could not read the screenshot")),Q.src=$})}async function S1($){try{let j=await K4($),J=Math.max(j.naturalWidth,j.naturalHeight),Q=Math.min(1,z4/J),z=document.createElement("canvas");z.width=Math.max(1,Math.round(j.naturalWidth*Q)),z.height=Math.max(1,Math.round(j.naturalHeight*Q));let W=z.getContext("2d");if(!W)return $;W.fillStyle="#fff",W.fillRect(0,0,z.width,z.height),W.drawImage(j,0,0,z.width,z.height);let V=Z4,Y=z.toDataURL("image/jpeg",V);while(Y.length>W4&&V>0.4)V-=0.15,Y=z.toDataURL("image/jpeg",V);return Y}catch{return $}}var V4=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,G4=/^\d+$/,X4=/^[0-9a-f]{16,}$/i;function R1($){if($.reason.type==="manual")return null;let j=$.cause?.failedRequests?.[0];if(!j?.url)return null;let J;try{J=new URL(j.url,"http://x").pathname}catch{J=j.url}let Q=J.split("/").map((W)=>V4.test(W)||G4.test(W)||X4.test(W)?":id":W).join("/"),z=j.status??(j.error?"ERR":"?");return`${j.method??"REQ"} ${Q} ${z}`}var O1=2000000;function W0($){let{screenshotDataUrl:j,...J}=$;return JSON.stringify(J).length}function f1($,j=2000000){if(W0($)<=j)return $;let J=$.network.map((z)=>({...z})),Q={...$,network:J};for(let z of J){if(W0(Q)<=j)return Q;if(typeof z.responseSnippet==="string"&&z.responseSnippet.length>35)z.responseSnippet="[body dropped — report size budget]";if(typeof z.requestBody==="string"&&z.requestBody.length>35)z.requestBody="[body dropped — report size budget]"}while(Q.network.length>1&&W0(Q)>j)Q.network=Q.network.slice(1);while(Q.console.length>1&&W0(Q)>j)Q.console=Q.console.slice(1);return Q}var _1=32768;function Y4($){let j="";for(let J=0;J<$.length;J+=_1)j+=String.fromCharCode(...$.subarray(J,J+_1));return btoa(j)}function F4($){let{screenshotDataUrl:j,...J}=$;return{dataUri:`data:application/json;base64,${Y4(new TextEncoder().encode(JSON.stringify(J)))}`,filename:"debug-bundle.json"}}async function w4(){let $=k().identity;if(!$)return{};try{let j=await $();return j?{authorization:`Bearer ${j}`}:{}}catch{return{}}}async function T1($,j){let J=k(),Q=f1(j,O1),{context:z,note:W}=Q,V=[];if(Q.screenshotDataUrl){let U=await S1(Q.screenshotDataUrl);V.push({dataUri:U,filename:"screenshot.jpg"})}V.push(F4(Q));let Y=R1(Q),w={title:$,description:W.trim()||void 0,appName:h().name,category:z.module?.label,routeUrl:z.route.href,priority:"MEDIUM",requesterEmail:z.user.email??void 0,requesterName:z.user.fullName??void 0,customFields:{unit:z.user.unit??"",appVersion:z.app.version,environment:z.app.environment,reasonType:Q.reason.type,appName:h().name,module:z.module?.label??""},context:{...Y?{signature:Y}:{},capturedAt:z.capturedAt,reason:Q.reason,cause:Q.cause,actionTrail:Q.actionTrail,client:z.client,performance:z.performance,apiHeaders:z.apiHeaders,extra:z.extra,counts:{network:Q.network.length,console:Q.console.length,actions:Q.actionTrail.length},screenshotMethod:Q.screenshotMethod},attachments:V},H=await fetch(`${J.host.replace(/\/$/,"")}/ingest/tickets`,{method:"POST",headers:{"content-type":"application/json","x-realm-key":J.realmKey,...await w4()},body:JSON.stringify(w)});if(!H.ok){let U=H.headers.get("retry-after"),P=await H.json().then((C)=>C.error).catch(()=>null);throw Error(H.status===429?`Too many reports — try again in ${U??"a moment"}s`:P??`Report failed (${H.status})`)}return await H.json()}var r=Math.PI/6;function A1($,j,J){let Q=j.x-$.x,z=j.y-$.y,W=Math.hypot(Q,z),V=Math.atan2(z,Q),Y=[{x:j.x,y:j.y},{x:j.x-J*Math.cos(V-r),y:j.y-J*Math.sin(V-r)},{x:j.x-J*Math.cos(V+r),y:j.y-J*Math.sin(V+r)}],w=J*Math.cos(r)*0.92;if(W<=w)return{shaft:null,head:Y};return{shaft:{from:$,to:{x:j.x-w*Math.cos(V),y:j.y-w*Math.sin(V)}},head:Y}}var C0="#f44336",M4="rgba(250, 204, 21, 0.4)",P0=22,L1="#2563eb",E1=9,x1=11,h1=18,p1=4,K0=8,H4=[{id:"nw",fx:0,fy:0,cursor:"nwse-resize"},{id:"n",fx:0.5,fy:0,cursor:"ns-resize"},{id:"ne",fx:1,fy:0,cursor:"nesw-resize"},{id:"e",fx:1,fy:0.5,cursor:"ew-resize"},{id:"se",fx:1,fy:1,cursor:"nwse-resize"},{id:"s",fx:0.5,fy:1,cursor:"ns-resize"},{id:"sw",fx:0,fy:1,cursor:"nesw-resize"},{id:"w",fx:0,fy:0.5,cursor:"ew-resize"}];function m1($,j,J){let Q=[],z=null,W=-1,V=null,Y=null,w=$.getContext("2d");function H(){let Z=$.getBoundingClientRect().width;return Z>0?$.width/Z:1}function U(Z){let K=$.getBoundingClientRect();return{x:(Z.clientX-K.left)/K.width*$.width,y:(Z.clientY-K.top)/K.height*$.height}}function P(Z){let K=Z.size??P0;if(!w)return(Z.text?.length??0)*K*0.6;w.save(),w.font=`600 ${K}px system-ui, sans-serif`;let X=w.measureText(Z.text??"").width;return w.restore(),X}function C(Z){if(Z.tool==="text"){let K=Z.size??P0;return{left:Z.x1,top:Z.y1,right:Z.x1+P(Z),bottom:Z.y1+K*1.25}}return{left:Math.min(Z.x1,Z.x2),top:Math.min(Z.y1,Z.y2),right:Math.max(Z.x1,Z.x2),bottom:Math.max(Z.y1,Z.y2)}}function S(Z){if(Z.tool==="arrow")return[{id:"tail",x:Z.x1,y:Z.y1,cursor:"move"},{id:"head",x:Z.x2,y:Z.y2,cursor:"move"}];let K=C(Z);if(Z.tool==="text")return[{id:"size",x:K.right,y:K.bottom,cursor:"nwse-resize"}];return H4.map((X)=>({id:X.id,x:K.left+(K.right-K.left)*X.fx,y:K.top+(K.bottom-K.top)*X.fy,cursor:X.cursor}))}function q(Z){let K=C(Z);return{x:K.right+h1*H(),y:K.top-h1*H()}}function D(Z,K,X){let{shaft:G,head:F}=A1({x:K.x1,y:K.y1},{x:K.x2,y:K.y2},Math.max(10,16*X));if(G)Z.lineCap="butt",Z.beginPath(),Z.moveTo(G.from.x,G.from.y),Z.lineTo(G.to.x,G.to.y),Z.stroke();Z.beginPath(),Z.moveTo(F[0].x,F[0].y),Z.lineTo(F[1].x,F[1].y),Z.lineTo(F[2].x,F[2].y),Z.closePath(),Z.fill()}function f(Z,K,X){Z.save(),Z.lineWidth=Math.max(2,3*X),Z.strokeStyle=C0,Z.fillStyle=C0;let G=C(K);if(K.tool==="rect")Z.strokeRect(G.left,G.top,G.right-G.left,G.bottom-G.top);else if(K.tool==="arrow")D(Z,K,X);else if(K.tool==="highlight")Z.fillStyle=M4,Z.fillRect(G.left,G.top,G.right-G.left,G.bottom-G.top);else if(K.tool==="text"&&K.text){let F=K.size??P0;Z.font=`600 ${F}px system-ui, sans-serif`,Z.textBaseline="top";let M=F*0.22;Z.fillStyle="rgba(255,255,255,0.92)",Z.fillRect(G.left-M,G.top-M,G.right-G.left+M*2,G.bottom-G.top+M*2),Z.fillStyle=C0,Z.fillText(K.text,G.left,G.top)}Z.restore()}function s(Z,K,X){let G=C(K);Z.save(),Z.strokeStyle=L1,Z.lineWidth=Math.max(1,1.5*X),Z.setLineDash([6*X,4*X]),Z.strokeRect(G.left,G.top,G.right-G.left,G.bottom-G.top),Z.setLineDash([]);let F=E1*X;for(let R of S(K))Z.fillStyle="#fff",Z.strokeStyle=L1,Z.lineWidth=Math.max(1,1.5*X),Z.beginPath(),Z.rect(R.x-F/2,R.y-F/2,F,F),Z.fill(),Z.stroke();let M=q(K),I=x1*X;Z.beginPath(),Z.arc(M.x,M.y,I,0,Math.PI*2),Z.fillStyle="#dc2626",Z.fill(),Z.strokeStyle="#fff",Z.lineWidth=Math.max(1.5,2*X),Z.beginPath(),Z.moveTo(M.x-I*0.4,M.y-I*0.4),Z.lineTo(M.x+I*0.4,M.y+I*0.4),Z.moveTo(M.x+I*0.4,M.y-I*0.4),Z.lineTo(M.x-I*0.4,M.y+I*0.4),Z.stroke(),Z.restore()}function N(){if(!w)return;let Z=H();if(w.clearRect(0,0,$.width,$.height),w.drawImage(j,0,0,$.width,$.height),Q.forEach((X,G)=>{if(G!==a)f(w,X,Z)}),V)f(w,V,Z);let K=Q[W];if(K&&!V)s(w,K,Z)}function B0(Z,K,X,G,F){return Math.abs(Z-X)<=F&&Math.abs(K-G)<=F}function q0(Z,K){let X=Q[W];if(!X)return null;let G=E1*H()/2+3*H();for(let F of S(X))if(B0(Z,K,F.x,F.y,G))return F.id;return null}function D0(Z,K){let X=Q[W];if(!X)return!1;let G=q(X);return B0(Z,K,G.x,G.y,x1*H())}function V0(Z,K){let X=6*H();for(let G=Q.length-1;G>=0;G-=1){let F=Q[G];if(F.tool==="arrow"){let I=F.x2-F.x1,R=F.y2-F.y1,E=Math.hypot(I,R)||1,x=Math.max(0,Math.min(1,((Z-F.x1)*I+(K-F.y1)*R)/(E*E)));if(Math.hypot(Z-(F.x1+x*I),K-(F.y1+x*R))<=X+4*H())return G;continue}let M=C(F);if(Z>=M.left-X&&Z<=M.right+X&&K>=M.top-X&&K<=M.bottom+X)return G}return-1}function u1(Z,K,X,G,F){if(K==="tail"){Z.x1=X.x1+G,Z.y1=X.y1+F;return}if(K==="head"){Z.x2=X.x2+G,Z.y2=X.y2+F;return}if(K==="size"){let c1=(X.size??24)+F;Z.size=Math.max(10,c1);return}let M=C(X),{left:I,top:R,right:E,bottom:x}=M;if(K.includes("w"))I=Math.min(E-K0,I+G);if(K.includes("e"))E=Math.max(I+K0,E+G);if(K.includes("n"))R=Math.min(x-K0,R+F);if(K.includes("s"))x=Math.max(R+K0,x+F);Z.x1=I,Z.y1=R,Z.x2=E,Z.y2=x}function i1(Z,K,X,G){Z.x1=K.x1+X,Z.y1=K.y1+G,Z.x2=K.x2+X,Z.y2=K.y2+G}let _=null,a=-1,T={x:0,y:0,size:24};function o1(){let Z=$.getBoundingClientRect().width;return Z>0?Z/$.width:1}function d1(Z,K){if(!w)return Z.length*K*0.6;w.save(),w.font=`600 ${K}px system-ui, sans-serif`;let X=w.measureText(Z||" ").width;return w.restore(),X}function k0(){if(!_)return;let Z=$.parentElement;if(!Z)return;let K=$.getBoundingClientRect(),X=Z.getBoundingClientRect(),G=o1(),F=T.size*G;_.style.left=`${K.left-X.left+T.x*G}px`,_.style.top=`${K.top-X.top+T.y*G}px`,_.style.fontSize=`${F}px`,_.style.width=`${Math.max(40,d1(_.value,F)+F)}px`}function y(Z){let K=_;if(!K)return;_=null;let X=K.value.trim(),G=a;if(a=-1,K.remove(),Z&&X){if(G>=0&&Q[G])Q[G].text=X,W=G;else Q.push({tool:"text",x1:T.x,y1:T.y,x2:T.x,y2:T.y,text:X,size:T.size}),W=Q.length-1;J()}else if(G>=0)W=G;$.focus(),N()}function S0(Z,K,X=-1){y(!0);let G=$.parentElement;if(!G)return;if(getComputedStyle(G).position==="static")G.style.position="relative";let F=X>=0?Q[X]:void 0;a=X,T={x:F?.x1??Z,y:F?.y1??K,size:F?.size??Math.round(24*H())};let M=document.createElement("input");M.type="text",M.className="text-edit",M.value=F?.text??"",M.setAttribute("aria-label","ข้อความบนภาพ"),M.placeholder="ข้อความ",_=M,G.append(M),k0(),M.addEventListener("input",k0),M.addEventListener("keydown",(I)=>{if(I.stopPropagation(),I.key==="Enter")y(!0);else if(I.key==="Escape")y(!1)}),requestAnimationFrame(()=>{if(_!==M)return;M.focus(),M.select(),M.addEventListener("blur",()=>y(!0))}),N()}function R0(Z){let{x:K,y:X}=U(Z);if($.setPointerCapture(Z.pointerId),D0(K,X)){G0();return}let G=q0(K,X);if(G&&Q[W]){Y={grip:G,x:K,y:X,start:{...Q[W]}};return}if(z==="text"){if(Z.preventDefault(),$.hasPointerCapture(Z.pointerId))$.releasePointerCapture(Z.pointerId);z=null,J(),S0(K,X);return}if(z){V={tool:z,x1:K,y1:X,x2:K,y2:X},W=-1;return}let F=V0(K,X);W=F,Y=F>=0?{grip:"body",x:K,y:X,start:{...Q[F]}}:null,N()}function O0(Z){let{x:K,y:X}=U(Z);if(V){V.x2=K,V.y2=X,N();return}if(Y){let F=Q[W];if(!F)return;let M=K-Y.x,I=X-Y.y;if(Y.grip==="body")i1(F,Y.start,M,I);else u1(F,Y.grip,Y.start,M,I);N();return}if(z){$.style.cursor="crosshair";return}if(D0(K,X)){$.style.cursor="pointer";return}let G=q0(K,X);if(G){let F=Q[W]?S(Q[W]).find((M)=>M.id===G):null;$.style.cursor=F?.cursor??"pointer";return}$.style.cursor=V0(K,X)>=0?"move":"default"}function t(){if(V){if(!(Math.abs(V.x2-V.x1)<p1&&Math.abs(V.y2-V.y1)<p1))Q.push(V),W=Q.length-1,z=null,J();V=null}if(Y)Y=null,J();N()}function f0(Z){let K=$.getBoundingClientRect(),X=(Z.clientX-K.left)/K.width*$.width,G=(Z.clientY-K.top)/K.height*$.height,F=V0(X,G),M=Q[F];if(!M||M.tool!=="text")return;Z.preventDefault(),S0(M.x1,M.y1,F)}function _0(Z){if(W<0)return;if(Z.key==="Delete"||Z.key==="Backspace")Z.preventDefault(),G0();else if(Z.key==="Escape")W=-1,N()}function G0(){if(W<0)return;Q.splice(W,1),W=-1,J(),N()}return $.addEventListener("pointerdown",R0),$.addEventListener("pointermove",O0),$.addEventListener("pointerup",t),$.addEventListener("pointercancel",t),$.addEventListener("dblclick",f0),$.tabIndex=0,$.addEventListener("keydown",_0),N(),{setTool(Z){z=Z,W=-1,$.style.cursor=Z?"crosshair":"default",N()},deleteSelected:G0,clear(){Q.length=0,W=-1,J(),N()},hasShapes:()=>Q.length>0,hasSelection:()=>W>=0,toDataUrl(){let Z=document.createElement("canvas");Z.width=j.naturalWidth,Z.height=j.naturalHeight;let K=Z.getContext("2d");if(!K)return $.toDataURL("image/png");K.drawImage(j,0,0);let X=H();for(let G of Q)f(K,G,X);return Z.toDataURL("image/png")},destroy(){y(!1),$.removeEventListener("pointerdown",R0),$.removeEventListener("pointermove",O0),$.removeEventListener("pointerup",t),$.removeEventListener("pointercancel",t),$.removeEventListener("dblclick",f0),$.removeEventListener("keydown",_0)}}}var g1=`
34
34
  :host { all: initial; }
35
35
  * { box-sizing: border-box; }
36
36
 
package/dist/index.mjs CHANGED
@@ -38,7 +38,7 @@ ${g1(j)}${z}`}).join(`
38
38
  `)}function U4($){if($.length===0)return"No user actions captured.";let j=0;return $.map((J)=>{let Q=J.source?` (${J.source})`:"",z=`${J.detail}${D0(J.count)}${Q}`;if(J.kind==="ui")return` ↳ [${J.at}] ${z}`;j+=1;let W=`${j}. [${J.at}] ${z}`;return J.afterNote?`${W}
39
39
  ↳ ${J.afterNote}`:W}).join(`
40
40
  `)}function C4($){let j=[];for(let J of $.failedRequests)j.push(`✗ ${J.status??J.error??"ERR"} ${J.method} ${J.url}`);for(let J of $.errors)j.push(`⚠ ${J}`);for(let J of $.erroredQueries)j.push(`⚠ React Query error: ${J.key} — ${J.error}`);return j}function P4($){let{context:j}=$;return[`User : ${j.user.fullName??"—"} (${j.user.email??"—"})`,`Unit : ${j.user.unit??"—"}`,`Roles : ${j.user.roles?.join(", ")||"—"}`,`Route : ${j.route.href}`,`Module : ${j.module?`${j.module.label} (${j.module.key})`:"—"}`,`App : ${j.app.name} v${j.app.version} · ${j.app.environment}`,`Memory : ${j.performance.memoryUsedMb??"—"}/${j.performance.memoryLimitMb??"—"} MB`,`Client : ${j.client.userAgent}`,`Viewport : ${j.client.viewport.width}×${j.client.viewport.height} @${j.client.viewport.dpr}x`,`Reason : ${Y4[$.reason.type]}${$.reason.message?` — ${$.reason.message}`:""}`,`Captured : ${$.network.length} requests · ${$.console.length} console · ${$.actionTrail.length} actions · screenshot=${$.screenshotMethod}`]}function I4($){let j=C4($.cause),J=[`## \uD83D\uDC1E ${$.context.app.name} — Debug Report`,`**Generated:** ${$.context.capturedAt}`,"",...P4($).map((Q)=>`- ${Q.replace(/\s{2,}:/,":")}`),"",`**หมายเหตุจากผู้แจ้ง:** ${$.note.trim()||"(ไม่มี)"}`];if(j.length>0)J.push("","### ⚠ สาเหตุที่น่าจะเป็น","```",...j,"```");return J.push("",`<details><summary>ขั้นตอน (${$.actionTrail.length})</summary>`,"","```",U4($.actionTrail),"```","</details>","",`<details><summary>Network (${$.network.length})</summary>`,"","```",H4($.network),"```","</details>","",`<details><summary>Console (${$.console.length})</summary>`,"","```",M4($.console),"```","</details>","","_ข้อมูลลับ (token, cookie) ถูกปกปิดอัตโนมัติ · ภาพหน้าจออยู่ในไฟล์ .zip_"),J.join(`
41
- `)}function w4($){return $.replace(/[:.]/g,"-").replace("T","_").slice(0,19)}function D4($,j){return`debug-report_${w4($.context.capturedAt)}.${j}`}function N4($){return E1($.cause)>0}async function E0(){if(typeof navigator<"u"&&Boolean(navigator.mediaDevices?.getDisplayMedia)){let J=await B4();if(J.status==="ok")return{dataUrl:J.dataUrl,method:"display-media"};if(J.status==="cancelled")return{dataUrl:null,method:"cancelled"}}let j=await R4();if(j)return{dataUrl:j,method:"html-to-image"};return{dataUrl:null,method:"none"}}async function B4(){let $=null;try{let j={video:{frameRate:30},audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude"};$=await navigator.mediaDevices.getDisplayMedia(j);let J=await q4($);return J?{status:"ok",dataUrl:J}:{status:"error"}}catch(j){if(j instanceof DOMException&&(j.name==="NotAllowedError"||j.name==="AbortError"))return{status:"cancelled"};return{status:"error"}}finally{$?.getTracks().forEach((j)=>j.stop())}}async function q4($){let j=document.createElement("video");j.srcObject=$,j.muted=!0,j.playsInline=!0,await new Promise((K)=>{let G=!1,H=()=>{if(G)return;G=!0,K()};j.onloadedmetadata=()=>{j.play().then(H).catch(H)},window.setTimeout(H,1500)}),await S4(j);let{videoWidth:J,videoHeight:Q}=j;if(!J||!Q)return null;let z=document.createElement("canvas");z.width=J,z.height=Q;let W=z.getContext("2d");if(!W)return null;W.drawImage(j,0,0,J,Q),j.pause(),j.srcObject=null;try{return z.toDataURL("image/png")}catch{return null}}function S4($){return new Promise((j)=>{let J=!1,Q=()=>{if(J)return;J=!0,j()},z=$;if(typeof z.requestVideoFrameCallback==="function")z.requestVideoFrameCallback(()=>Q()),window.setTimeout(Q,1000);else window.setTimeout(Q,250)})}async function R4(){let $=R().screenshotFallback;if(!$)return null;let j=await $().catch(()=>null);if(!j)return null;try{return await j(document.body,{cacheBust:!0,pixelRatio:Math.min(window.devicePixelRatio||1,2),filter:(J)=>!(J instanceof HTMLElement&&J.dataset?.debugReporter==="true")})}catch{return null}}var O4=2000,_4=0.82,L4=3000000;function A4($){return new Promise((j,J)=>{let Q=new Image;Q.onload=()=>j(Q),Q.onerror=()=>J(Error("could not read the screenshot")),Q.src=$})}async function p1($){try{let j=await A4($),J=Math.max(j.naturalWidth,j.naturalHeight),Q=Math.min(1,O4/J),z=document.createElement("canvas");z.width=Math.max(1,Math.round(j.naturalWidth*Q)),z.height=Math.max(1,Math.round(j.naturalHeight*Q));let W=z.getContext("2d");if(!W)return $;W.fillStyle="#fff",W.fillRect(0,0,z.width,z.height),W.drawImage(j,0,0,z.width,z.height);let K=_4,G=z.toDataURL("image/jpeg",K);while(G.length>L4&&K>0.4)K-=0.15,G=z.toDataURL("image/jpeg",K);return G}catch{return $}}var T4=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,k4=/^\d+$/,f4=/^[0-9a-f]{16,}$/i;function x0($){if($.reason.type==="manual")return null;let j=$.cause?.failedRequests?.[0];if(!j?.url)return null;let J;try{J=new URL(j.url,"http://x").pathname}catch{J=j.url}let Q=J.split("/").map((W)=>T4.test(W)||k4.test(W)||f4.test(W)?":id":W).join("/"),z=j.status??(j.error?"ERR":"?");return`${j.method??"REQ"} ${Q} ${z}`}var h0=2000000;function G0($){let{screenshotDataUrl:j,...J}=$;return JSON.stringify(J).length}function g0($,j=2000000){if(G0($)<=j)return $;let J=$.network.map((z)=>({...z})),Q={...$,network:J};for(let z of J){if(G0(Q)<=j)return Q;if(typeof z.responseSnippet==="string"&&z.responseSnippet.length>35)z.responseSnippet="[body dropped — report size budget]";if(typeof z.requestBody==="string"&&z.requestBody.length>35)z.requestBody="[body dropped — report size budget]"}while(Q.network.length>1&&G0(Q)>j)Q.network=Q.network.slice(1);while(Q.console.length>1&&G0(Q)>j)Q.console=Q.console.slice(1);return Q}var m1=32768;function E4($){let j="";for(let J=0;J<$.length;J+=m1)j+=String.fromCharCode(...$.subarray(J,J+m1));return btoa(j)}function x4($){return{dataUri:`data:application/json;base64,${E4(new TextEncoder().encode(JSON.stringify($)))}`,filename:"debug-bundle.json"}}async function h4(){let $=R().identity;if(!$)return{};try{let j=await $();return j?{authorization:`Bearer ${j}`}:{}}catch{return{}}}async function p0($,j){let J=R(),Q=g0(j,h0),{context:z,note:W}=Q,K=[];if(Q.screenshotDataUrl){let C=await p1(Q.screenshotDataUrl);K.push({dataUri:C,filename:"screenshot.jpg"})}K.push(x4(Q));let G=x0(Q),H={title:$,description:W.trim()||void 0,appName:x().name,category:z.module?.label,routeUrl:z.route.href,priority:"MEDIUM",requesterEmail:z.user.email??void 0,requesterName:z.user.fullName??void 0,customFields:{unit:z.user.unit??"",appVersion:z.app.version,environment:z.app.environment,reasonType:Q.reason.type,appName:x().name,module:z.module?.label??""},context:{...G?{signature:G}:{},capturedAt:z.capturedAt,reason:Q.reason,cause:Q.cause,actionTrail:Q.actionTrail,client:z.client,performance:z.performance,apiHeaders:z.apiHeaders,extra:z.extra,counts:{network:Q.network.length,console:Q.console.length,actions:Q.actionTrail.length},screenshotMethod:Q.screenshotMethod},attachments:K},U=await fetch(`${J.host.replace(/\/$/,"")}/ingest/tickets`,{method:"POST",headers:{"content-type":"application/json","x-realm-key":J.realmKey,...await h4()},body:JSON.stringify(H)});if(!U.ok){let C=U.headers.get("retry-after"),w=await U.json().then((P)=>P.error).catch(()=>null);throw Error(U.status===429?`Too many reports — try again in ${C??"a moment"}s`:w??`Report failed (${U.status})`)}return await U.json()}var Q0=Math.PI/6;function v1($,j,J){let Q=j.x-$.x,z=j.y-$.y,W=Math.hypot(Q,z),K=Math.atan2(z,Q),G=[{x:j.x,y:j.y},{x:j.x-J*Math.cos(K-Q0),y:j.y-J*Math.sin(K-Q0)},{x:j.x-J*Math.cos(K+Q0),y:j.y-J*Math.sin(K+Q0)}],H=J*Math.cos(Q0)*0.92;if(W<=H)return{shaft:null,head:G};return{shaft:{from:$,to:{x:j.x-H*Math.cos(K),y:j.y-H*Math.sin(K)}},head:G}}var m0="#f44336",g4="rgba(250, 204, 21, 0.4)",v0=22,y1="#2563eb",b1=9,u1=11,d1=18,c1=4,Y0=8,p4=[{id:"nw",fx:0,fy:0,cursor:"nwse-resize"},{id:"n",fx:0.5,fy:0,cursor:"ns-resize"},{id:"ne",fx:1,fy:0,cursor:"nesw-resize"},{id:"e",fx:1,fy:0.5,cursor:"ew-resize"},{id:"se",fx:1,fy:1,cursor:"nwse-resize"},{id:"s",fx:0.5,fy:1,cursor:"ns-resize"},{id:"sw",fx:0,fy:1,cursor:"nesw-resize"},{id:"w",fx:0,fy:0.5,cursor:"ew-resize"}];function y0($,j,J){let Q=[],z=null,W=-1,K=null,G=null,H=$.getContext("2d");function U(){let Z=$.getBoundingClientRect().width;return Z>0?$.width/Z:1}function C(Z){let V=$.getBoundingClientRect();return{x:(Z.clientX-V.left)/V.width*$.width,y:(Z.clientY-V.top)/V.height*$.height}}function w(Z){let V=Z.size??v0;if(!H)return(Z.text?.length??0)*V*0.6;H.save(),H.font=`600 ${V}px system-ui, sans-serif`;let Y=H.measureText(Z.text??"").width;return H.restore(),Y}function P(Z){if(Z.tool==="text"){let V=Z.size??v0;return{left:Z.x1,top:Z.y1,right:Z.x1+w(Z),bottom:Z.y1+V*1.25}}return{left:Math.min(Z.x1,Z.x2),top:Math.min(Z.y1,Z.y2),right:Math.max(Z.x1,Z.x2),bottom:Math.max(Z.y1,Z.y2)}}function O(Z){if(Z.tool==="arrow")return[{id:"tail",x:Z.x1,y:Z.y1,cursor:"move"},{id:"head",x:Z.x2,y:Z.y2,cursor:"move"}];let V=P(Z);if(Z.tool==="text")return[{id:"size",x:V.right,y:V.bottom,cursor:"nwse-resize"}];return p4.map((Y)=>({id:Y.id,x:V.left+(V.right-V.left)*Y.fx,y:V.top+(V.bottom-V.top)*Y.fy,cursor:Y.cursor}))}function N(Z){let V=P(Z);return{x:V.right+d1*U(),y:V.top-d1*U()}}function S(Z,V,Y){let{shaft:X,head:F}=v1({x:V.x1,y:V.y1},{x:V.x2,y:V.y2},Math.max(10,16*Y));if(X)Z.lineCap="butt",Z.beginPath(),Z.moveTo(X.from.x,X.from.y),Z.lineTo(X.to.x,X.to.y),Z.stroke();Z.beginPath(),Z.moveTo(F[0].x,F[0].y),Z.lineTo(F[1].x,F[1].y),Z.lineTo(F[2].x,F[2].y),Z.closePath(),Z.fill()}function _(Z,V,Y){Z.save(),Z.lineWidth=Math.max(2,3*Y),Z.strokeStyle=m0,Z.fillStyle=m0;let X=P(V);if(V.tool==="rect")Z.strokeRect(X.left,X.top,X.right-X.left,X.bottom-X.top);else if(V.tool==="arrow")S(Z,V,Y);else if(V.tool==="highlight")Z.fillStyle=g4,Z.fillRect(X.left,X.top,X.right-X.left,X.bottom-X.top);else if(V.tool==="text"&&V.text){let F=V.size??v0;Z.font=`600 ${F}px system-ui, sans-serif`,Z.textBaseline="top";let M=F*0.22;Z.fillStyle="rgba(255,255,255,0.92)",Z.fillRect(X.left-M,X.top-M,X.right-X.left+M*2,X.bottom-X.top+M*2),Z.fillStyle=m0,Z.fillText(V.text,X.left,X.top)}Z.restore()}function D(Z,V,Y){let X=P(V);Z.save(),Z.strokeStyle=y1,Z.lineWidth=Math.max(1,1.5*Y),Z.setLineDash([6*Y,4*Y]),Z.strokeRect(X.left,X.top,X.right-X.left,X.bottom-X.top),Z.setLineDash([]);let F=b1*Y;for(let T of O(V))Z.fillStyle="#fff",Z.strokeStyle=y1,Z.lineWidth=Math.max(1,1.5*Y),Z.beginPath(),Z.rect(T.x-F/2,T.y-F/2,F,F),Z.fill(),Z.stroke();let M=N(V),I=u1*Y;Z.beginPath(),Z.arc(M.x,M.y,I,0,Math.PI*2),Z.fillStyle="#dc2626",Z.fill(),Z.strokeStyle="#fff",Z.lineWidth=Math.max(1.5,2*Y),Z.beginPath(),Z.moveTo(M.x-I*0.4,M.y-I*0.4),Z.lineTo(M.x+I*0.4,M.y+I*0.4),Z.moveTo(M.x+I*0.4,M.y-I*0.4),Z.lineTo(M.x-I*0.4,M.y+I*0.4),Z.stroke(),Z.restore()}function q(){if(!H)return;let Z=U();if(H.clearRect(0,0,$.width,$.height),H.drawImage(j,0,0,$.width,$.height),Q.forEach((Y,X)=>{if(X!==m)_(H,Y,Z)}),K)_(H,K,Z);let V=Q[W];if(V&&!K)D(H,V,Z)}function g(Z,V,Y,X,F){return Math.abs(Z-Y)<=F&&Math.abs(V-X)<=F}function e(Z,V){let Y=Q[W];if(!Y)return null;let X=b1*U()/2+3*U();for(let F of O(Y))if(g(Z,V,F.x,F.y,X))return F.id;return null}function u(Z,V){let Y=Q[W];if(!Y)return!1;let X=N(Y);return g(Z,V,X.x,X.y,u1*U())}function E(Z,V){let Y=6*U();for(let X=Q.length-1;X>=0;X-=1){let F=Q[X];if(F.tool==="arrow"){let I=F.x2-F.x1,T=F.y2-F.y1,v=Math.hypot(I,T)||1,y=Math.max(0,Math.min(1,((Z-F.x1)*I+(V-F.y1)*T)/(v*v)));if(Math.hypot(Z-(F.x1+y*I),V-(F.y1+y*T))<=Y+4*U())return X;continue}let M=P(F);if(Z>=M.left-Y&&Z<=M.right+Y&&V>=M.top-Y&&V<=M.bottom+Y)return X}return-1}function p(Z,V,Y,X,F){if(V==="tail"){Z.x1=Y.x1+X,Z.y1=Y.y1+F;return}if(V==="head"){Z.x2=Y.x2+X,Z.y2=Y.y2+F;return}if(V==="size"){let j2=(Y.size??24)+F;Z.size=Math.max(10,j2);return}let M=P(Y),{left:I,top:T,right:v,bottom:y}=M;if(V.includes("w"))I=Math.min(v-Y0,I+X);if(V.includes("e"))v=Math.max(I+Y0,v+X);if(V.includes("n"))T=Math.min(y-Y0,T+F);if(V.includes("s"))y=Math.max(T+Y0,y+F);Z.x1=I,Z.y1=T,Z.x2=v,Z.y2=y}function H0(Z,V,Y,X){Z.x1=V.x1+Y,Z.y1=V.y1+X,Z.x2=V.x2+Y,Z.y2=V.y2+X}let L=null,m=-1,B={x:0,y:0,size:24};function f(){let Z=$.getBoundingClientRect().width;return Z>0?Z/$.width:1}function $2(Z,V){if(!H)return Z.length*V*0.6;H.save(),H.font=`600 ${V}px system-ui, sans-serif`;let Y=H.measureText(Z||" ").width;return H.restore(),Y}function c0(){if(!L)return;let Z=$.parentElement;if(!Z)return;let V=$.getBoundingClientRect(),Y=Z.getBoundingClientRect(),X=f(),F=B.size*X;L.style.left=`${V.left-Y.left+B.x*X}px`,L.style.top=`${V.top-Y.top+B.y*X}px`,L.style.fontSize=`${F}px`,L.style.width=`${Math.max(40,$2(L.value,F)+F)}px`}function $0(Z){let V=L;if(!V)return;L=null;let Y=V.value.trim(),X=m;if(m=-1,V.remove(),Z&&Y){if(X>=0&&Q[X])Q[X].text=Y,W=X;else Q.push({tool:"text",x1:B.x,y1:B.y,x2:B.x,y2:B.y,text:Y,size:B.size}),W=Q.length-1;J()}else if(X>=0)W=X;$.focus(),q()}function i0(Z,V,Y=-1){$0(!0);let X=$.parentElement;if(!X)return;if(getComputedStyle(X).position==="static")X.style.position="relative";let F=Y>=0?Q[Y]:void 0;m=Y,B={x:F?.x1??Z,y:F?.y1??V,size:F?.size??Math.round(24*U())};let M=document.createElement("input");M.type="text",M.className="text-edit",M.value=F?.text??"",M.setAttribute("aria-label","ข้อความบนภาพ"),M.placeholder="ข้อความ",L=M,X.append(M),c0(),M.addEventListener("input",c0),M.addEventListener("keydown",(I)=>{if(I.stopPropagation(),I.key==="Enter")$0(!0);else if(I.key==="Escape")$0(!1)}),requestAnimationFrame(()=>{if(L!==M)return;M.focus(),M.select(),M.addEventListener("blur",()=>$0(!0))}),q()}function o0(Z){let{x:V,y:Y}=C(Z);if($.setPointerCapture(Z.pointerId),u(V,Y)){M0();return}let X=e(V,Y);if(X&&Q[W]){G={grip:X,x:V,y:Y,start:{...Q[W]}};return}if(z==="text"){if(Z.preventDefault(),$.hasPointerCapture(Z.pointerId))$.releasePointerCapture(Z.pointerId);z=null,J(),i0(V,Y);return}if(z){K={tool:z,x1:V,y1:Y,x2:V,y2:Y},W=-1;return}let F=E(V,Y);W=F,G=F>=0?{grip:"body",x:V,y:Y,start:{...Q[F]}}:null,q()}function l0(Z){let{x:V,y:Y}=C(Z);if(K){K.x2=V,K.y2=Y,q();return}if(G){let F=Q[W];if(!F)return;let M=V-G.x,I=Y-G.y;if(G.grip==="body")H0(F,G.start,M,I);else p(F,G.grip,G.start,M,I);q();return}if(z){$.style.cursor="crosshair";return}if(u(V,Y)){$.style.cursor="pointer";return}let X=e(V,Y);if(X){let F=Q[W]?O(Q[W]).find((M)=>M.id===X):null;$.style.cursor=F?.cursor??"pointer";return}$.style.cursor=E(V,Y)>=0?"move":"default"}function z0(){if(K){if(!(Math.abs(K.x2-K.x1)<c1&&Math.abs(K.y2-K.y1)<c1))Q.push(K),W=Q.length-1,z=null,J();K=null}if(G)G=null,J();q()}function r0(Z){let V=$.getBoundingClientRect(),Y=(Z.clientX-V.left)/V.width*$.width,X=(Z.clientY-V.top)/V.height*$.height,F=E(Y,X),M=Q[F];if(!M||M.tool!=="text")return;Z.preventDefault(),i0(M.x1,M.y1,F)}function s0(Z){if(W<0)return;if(Z.key==="Delete"||Z.key==="Backspace")Z.preventDefault(),M0();else if(Z.key==="Escape")W=-1,q()}function M0(){if(W<0)return;Q.splice(W,1),W=-1,J(),q()}return $.addEventListener("pointerdown",o0),$.addEventListener("pointermove",l0),$.addEventListener("pointerup",z0),$.addEventListener("pointercancel",z0),$.addEventListener("dblclick",r0),$.tabIndex=0,$.addEventListener("keydown",s0),q(),{setTool(Z){z=Z,W=-1,$.style.cursor=Z?"crosshair":"default",q()},deleteSelected:M0,clear(){Q.length=0,W=-1,J(),q()},hasShapes:()=>Q.length>0,hasSelection:()=>W>=0,toDataUrl(){let Z=document.createElement("canvas");Z.width=j.naturalWidth,Z.height=j.naturalHeight;let V=Z.getContext("2d");if(!V)return $.toDataURL("image/png");V.drawImage(j,0,0);let Y=U();for(let X of Q)_(V,X,Y);return Z.toDataURL("image/png")},destroy(){$0(!1),$.removeEventListener("pointerdown",o0),$.removeEventListener("pointermove",l0),$.removeEventListener("pointerup",z0),$.removeEventListener("pointercancel",z0),$.removeEventListener("dblclick",r0),$.removeEventListener("keydown",s0)}}}var i1=`
41
+ `)}function w4($){return $.replace(/[:.]/g,"-").replace("T","_").slice(0,19)}function D4($,j){return`debug-report_${w4($.context.capturedAt)}.${j}`}function N4($){return E1($.cause)>0}async function E0(){if(typeof navigator<"u"&&Boolean(navigator.mediaDevices?.getDisplayMedia)){let J=await B4();if(J.status==="ok")return{dataUrl:J.dataUrl,method:"display-media"};if(J.status==="cancelled")return{dataUrl:null,method:"cancelled"}}let j=await R4();if(j)return{dataUrl:j,method:"html-to-image"};return{dataUrl:null,method:"none"}}async function B4(){let $=null;try{let j={video:{frameRate:30},audio:!1,preferCurrentTab:!0,selfBrowserSurface:"include",surfaceSwitching:"exclude"};$=await navigator.mediaDevices.getDisplayMedia(j);let J=await q4($);return J?{status:"ok",dataUrl:J}:{status:"error"}}catch(j){if(j instanceof DOMException&&(j.name==="NotAllowedError"||j.name==="AbortError"))return{status:"cancelled"};return{status:"error"}}finally{$?.getTracks().forEach((j)=>j.stop())}}async function q4($){let j=document.createElement("video");j.srcObject=$,j.muted=!0,j.playsInline=!0,await new Promise((K)=>{let G=!1,H=()=>{if(G)return;G=!0,K()};j.onloadedmetadata=()=>{j.play().then(H).catch(H)},window.setTimeout(H,1500)}),await S4(j);let{videoWidth:J,videoHeight:Q}=j;if(!J||!Q)return null;let z=document.createElement("canvas");z.width=J,z.height=Q;let W=z.getContext("2d");if(!W)return null;W.drawImage(j,0,0,J,Q),j.pause(),j.srcObject=null;try{return z.toDataURL("image/png")}catch{return null}}function S4($){return new Promise((j)=>{let J=!1,Q=()=>{if(J)return;J=!0,j()},z=$;if(typeof z.requestVideoFrameCallback==="function")z.requestVideoFrameCallback(()=>Q()),window.setTimeout(Q,1000);else window.setTimeout(Q,250)})}async function R4(){let $=R().screenshotFallback;if(!$)return null;let j=await $().catch(()=>null);if(!j)return null;try{return await j(document.body,{cacheBust:!0,pixelRatio:Math.min(window.devicePixelRatio||1,2),filter:(J)=>!(J instanceof HTMLElement&&J.dataset?.debugReporter==="true")})}catch{return null}}var O4=2000,_4=0.82,L4=3000000;function A4($){return new Promise((j,J)=>{let Q=new Image;Q.onload=()=>j(Q),Q.onerror=()=>J(Error("could not read the screenshot")),Q.src=$})}async function p1($){try{let j=await A4($),J=Math.max(j.naturalWidth,j.naturalHeight),Q=Math.min(1,O4/J),z=document.createElement("canvas");z.width=Math.max(1,Math.round(j.naturalWidth*Q)),z.height=Math.max(1,Math.round(j.naturalHeight*Q));let W=z.getContext("2d");if(!W)return $;W.fillStyle="#fff",W.fillRect(0,0,z.width,z.height),W.drawImage(j,0,0,z.width,z.height);let K=_4,G=z.toDataURL("image/jpeg",K);while(G.length>L4&&K>0.4)K-=0.15,G=z.toDataURL("image/jpeg",K);return G}catch{return $}}var T4=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,k4=/^\d+$/,f4=/^[0-9a-f]{16,}$/i;function x0($){if($.reason.type==="manual")return null;let j=$.cause?.failedRequests?.[0];if(!j?.url)return null;let J;try{J=new URL(j.url,"http://x").pathname}catch{J=j.url}let Q=J.split("/").map((W)=>T4.test(W)||k4.test(W)||f4.test(W)?":id":W).join("/"),z=j.status??(j.error?"ERR":"?");return`${j.method??"REQ"} ${Q} ${z}`}var h0=2000000;function G0($){let{screenshotDataUrl:j,...J}=$;return JSON.stringify(J).length}function g0($,j=2000000){if(G0($)<=j)return $;let J=$.network.map((z)=>({...z})),Q={...$,network:J};for(let z of J){if(G0(Q)<=j)return Q;if(typeof z.responseSnippet==="string"&&z.responseSnippet.length>35)z.responseSnippet="[body dropped — report size budget]";if(typeof z.requestBody==="string"&&z.requestBody.length>35)z.requestBody="[body dropped — report size budget]"}while(Q.network.length>1&&G0(Q)>j)Q.network=Q.network.slice(1);while(Q.console.length>1&&G0(Q)>j)Q.console=Q.console.slice(1);return Q}var m1=32768;function E4($){let j="";for(let J=0;J<$.length;J+=m1)j+=String.fromCharCode(...$.subarray(J,J+m1));return btoa(j)}function x4($){let{screenshotDataUrl:j,...J}=$;return{dataUri:`data:application/json;base64,${E4(new TextEncoder().encode(JSON.stringify(J)))}`,filename:"debug-bundle.json"}}async function h4(){let $=R().identity;if(!$)return{};try{let j=await $();return j?{authorization:`Bearer ${j}`}:{}}catch{return{}}}async function p0($,j){let J=R(),Q=g0(j,h0),{context:z,note:W}=Q,K=[];if(Q.screenshotDataUrl){let C=await p1(Q.screenshotDataUrl);K.push({dataUri:C,filename:"screenshot.jpg"})}K.push(x4(Q));let G=x0(Q),H={title:$,description:W.trim()||void 0,appName:x().name,category:z.module?.label,routeUrl:z.route.href,priority:"MEDIUM",requesterEmail:z.user.email??void 0,requesterName:z.user.fullName??void 0,customFields:{unit:z.user.unit??"",appVersion:z.app.version,environment:z.app.environment,reasonType:Q.reason.type,appName:x().name,module:z.module?.label??""},context:{...G?{signature:G}:{},capturedAt:z.capturedAt,reason:Q.reason,cause:Q.cause,actionTrail:Q.actionTrail,client:z.client,performance:z.performance,apiHeaders:z.apiHeaders,extra:z.extra,counts:{network:Q.network.length,console:Q.console.length,actions:Q.actionTrail.length},screenshotMethod:Q.screenshotMethod},attachments:K},U=await fetch(`${J.host.replace(/\/$/,"")}/ingest/tickets`,{method:"POST",headers:{"content-type":"application/json","x-realm-key":J.realmKey,...await h4()},body:JSON.stringify(H)});if(!U.ok){let C=U.headers.get("retry-after"),w=await U.json().then((P)=>P.error).catch(()=>null);throw Error(U.status===429?`Too many reports — try again in ${C??"a moment"}s`:w??`Report failed (${U.status})`)}return await U.json()}var Q0=Math.PI/6;function v1($,j,J){let Q=j.x-$.x,z=j.y-$.y,W=Math.hypot(Q,z),K=Math.atan2(z,Q),G=[{x:j.x,y:j.y},{x:j.x-J*Math.cos(K-Q0),y:j.y-J*Math.sin(K-Q0)},{x:j.x-J*Math.cos(K+Q0),y:j.y-J*Math.sin(K+Q0)}],H=J*Math.cos(Q0)*0.92;if(W<=H)return{shaft:null,head:G};return{shaft:{from:$,to:{x:j.x-H*Math.cos(K),y:j.y-H*Math.sin(K)}},head:G}}var m0="#f44336",g4="rgba(250, 204, 21, 0.4)",v0=22,y1="#2563eb",b1=9,u1=11,d1=18,c1=4,Y0=8,p4=[{id:"nw",fx:0,fy:0,cursor:"nwse-resize"},{id:"n",fx:0.5,fy:0,cursor:"ns-resize"},{id:"ne",fx:1,fy:0,cursor:"nesw-resize"},{id:"e",fx:1,fy:0.5,cursor:"ew-resize"},{id:"se",fx:1,fy:1,cursor:"nwse-resize"},{id:"s",fx:0.5,fy:1,cursor:"ns-resize"},{id:"sw",fx:0,fy:1,cursor:"nesw-resize"},{id:"w",fx:0,fy:0.5,cursor:"ew-resize"}];function y0($,j,J){let Q=[],z=null,W=-1,K=null,G=null,H=$.getContext("2d");function U(){let Z=$.getBoundingClientRect().width;return Z>0?$.width/Z:1}function C(Z){let V=$.getBoundingClientRect();return{x:(Z.clientX-V.left)/V.width*$.width,y:(Z.clientY-V.top)/V.height*$.height}}function w(Z){let V=Z.size??v0;if(!H)return(Z.text?.length??0)*V*0.6;H.save(),H.font=`600 ${V}px system-ui, sans-serif`;let Y=H.measureText(Z.text??"").width;return H.restore(),Y}function P(Z){if(Z.tool==="text"){let V=Z.size??v0;return{left:Z.x1,top:Z.y1,right:Z.x1+w(Z),bottom:Z.y1+V*1.25}}return{left:Math.min(Z.x1,Z.x2),top:Math.min(Z.y1,Z.y2),right:Math.max(Z.x1,Z.x2),bottom:Math.max(Z.y1,Z.y2)}}function O(Z){if(Z.tool==="arrow")return[{id:"tail",x:Z.x1,y:Z.y1,cursor:"move"},{id:"head",x:Z.x2,y:Z.y2,cursor:"move"}];let V=P(Z);if(Z.tool==="text")return[{id:"size",x:V.right,y:V.bottom,cursor:"nwse-resize"}];return p4.map((Y)=>({id:Y.id,x:V.left+(V.right-V.left)*Y.fx,y:V.top+(V.bottom-V.top)*Y.fy,cursor:Y.cursor}))}function N(Z){let V=P(Z);return{x:V.right+d1*U(),y:V.top-d1*U()}}function S(Z,V,Y){let{shaft:X,head:F}=v1({x:V.x1,y:V.y1},{x:V.x2,y:V.y2},Math.max(10,16*Y));if(X)Z.lineCap="butt",Z.beginPath(),Z.moveTo(X.from.x,X.from.y),Z.lineTo(X.to.x,X.to.y),Z.stroke();Z.beginPath(),Z.moveTo(F[0].x,F[0].y),Z.lineTo(F[1].x,F[1].y),Z.lineTo(F[2].x,F[2].y),Z.closePath(),Z.fill()}function _(Z,V,Y){Z.save(),Z.lineWidth=Math.max(2,3*Y),Z.strokeStyle=m0,Z.fillStyle=m0;let X=P(V);if(V.tool==="rect")Z.strokeRect(X.left,X.top,X.right-X.left,X.bottom-X.top);else if(V.tool==="arrow")S(Z,V,Y);else if(V.tool==="highlight")Z.fillStyle=g4,Z.fillRect(X.left,X.top,X.right-X.left,X.bottom-X.top);else if(V.tool==="text"&&V.text){let F=V.size??v0;Z.font=`600 ${F}px system-ui, sans-serif`,Z.textBaseline="top";let M=F*0.22;Z.fillStyle="rgba(255,255,255,0.92)",Z.fillRect(X.left-M,X.top-M,X.right-X.left+M*2,X.bottom-X.top+M*2),Z.fillStyle=m0,Z.fillText(V.text,X.left,X.top)}Z.restore()}function D(Z,V,Y){let X=P(V);Z.save(),Z.strokeStyle=y1,Z.lineWidth=Math.max(1,1.5*Y),Z.setLineDash([6*Y,4*Y]),Z.strokeRect(X.left,X.top,X.right-X.left,X.bottom-X.top),Z.setLineDash([]);let F=b1*Y;for(let T of O(V))Z.fillStyle="#fff",Z.strokeStyle=y1,Z.lineWidth=Math.max(1,1.5*Y),Z.beginPath(),Z.rect(T.x-F/2,T.y-F/2,F,F),Z.fill(),Z.stroke();let M=N(V),I=u1*Y;Z.beginPath(),Z.arc(M.x,M.y,I,0,Math.PI*2),Z.fillStyle="#dc2626",Z.fill(),Z.strokeStyle="#fff",Z.lineWidth=Math.max(1.5,2*Y),Z.beginPath(),Z.moveTo(M.x-I*0.4,M.y-I*0.4),Z.lineTo(M.x+I*0.4,M.y+I*0.4),Z.moveTo(M.x+I*0.4,M.y-I*0.4),Z.lineTo(M.x-I*0.4,M.y+I*0.4),Z.stroke(),Z.restore()}function q(){if(!H)return;let Z=U();if(H.clearRect(0,0,$.width,$.height),H.drawImage(j,0,0,$.width,$.height),Q.forEach((Y,X)=>{if(X!==m)_(H,Y,Z)}),K)_(H,K,Z);let V=Q[W];if(V&&!K)D(H,V,Z)}function g(Z,V,Y,X,F){return Math.abs(Z-Y)<=F&&Math.abs(V-X)<=F}function e(Z,V){let Y=Q[W];if(!Y)return null;let X=b1*U()/2+3*U();for(let F of O(Y))if(g(Z,V,F.x,F.y,X))return F.id;return null}function u(Z,V){let Y=Q[W];if(!Y)return!1;let X=N(Y);return g(Z,V,X.x,X.y,u1*U())}function E(Z,V){let Y=6*U();for(let X=Q.length-1;X>=0;X-=1){let F=Q[X];if(F.tool==="arrow"){let I=F.x2-F.x1,T=F.y2-F.y1,v=Math.hypot(I,T)||1,y=Math.max(0,Math.min(1,((Z-F.x1)*I+(V-F.y1)*T)/(v*v)));if(Math.hypot(Z-(F.x1+y*I),V-(F.y1+y*T))<=Y+4*U())return X;continue}let M=P(F);if(Z>=M.left-Y&&Z<=M.right+Y&&V>=M.top-Y&&V<=M.bottom+Y)return X}return-1}function p(Z,V,Y,X,F){if(V==="tail"){Z.x1=Y.x1+X,Z.y1=Y.y1+F;return}if(V==="head"){Z.x2=Y.x2+X,Z.y2=Y.y2+F;return}if(V==="size"){let j2=(Y.size??24)+F;Z.size=Math.max(10,j2);return}let M=P(Y),{left:I,top:T,right:v,bottom:y}=M;if(V.includes("w"))I=Math.min(v-Y0,I+X);if(V.includes("e"))v=Math.max(I+Y0,v+X);if(V.includes("n"))T=Math.min(y-Y0,T+F);if(V.includes("s"))y=Math.max(T+Y0,y+F);Z.x1=I,Z.y1=T,Z.x2=v,Z.y2=y}function H0(Z,V,Y,X){Z.x1=V.x1+Y,Z.y1=V.y1+X,Z.x2=V.x2+Y,Z.y2=V.y2+X}let L=null,m=-1,B={x:0,y:0,size:24};function f(){let Z=$.getBoundingClientRect().width;return Z>0?Z/$.width:1}function $2(Z,V){if(!H)return Z.length*V*0.6;H.save(),H.font=`600 ${V}px system-ui, sans-serif`;let Y=H.measureText(Z||" ").width;return H.restore(),Y}function c0(){if(!L)return;let Z=$.parentElement;if(!Z)return;let V=$.getBoundingClientRect(),Y=Z.getBoundingClientRect(),X=f(),F=B.size*X;L.style.left=`${V.left-Y.left+B.x*X}px`,L.style.top=`${V.top-Y.top+B.y*X}px`,L.style.fontSize=`${F}px`,L.style.width=`${Math.max(40,$2(L.value,F)+F)}px`}function $0(Z){let V=L;if(!V)return;L=null;let Y=V.value.trim(),X=m;if(m=-1,V.remove(),Z&&Y){if(X>=0&&Q[X])Q[X].text=Y,W=X;else Q.push({tool:"text",x1:B.x,y1:B.y,x2:B.x,y2:B.y,text:Y,size:B.size}),W=Q.length-1;J()}else if(X>=0)W=X;$.focus(),q()}function i0(Z,V,Y=-1){$0(!0);let X=$.parentElement;if(!X)return;if(getComputedStyle(X).position==="static")X.style.position="relative";let F=Y>=0?Q[Y]:void 0;m=Y,B={x:F?.x1??Z,y:F?.y1??V,size:F?.size??Math.round(24*U())};let M=document.createElement("input");M.type="text",M.className="text-edit",M.value=F?.text??"",M.setAttribute("aria-label","ข้อความบนภาพ"),M.placeholder="ข้อความ",L=M,X.append(M),c0(),M.addEventListener("input",c0),M.addEventListener("keydown",(I)=>{if(I.stopPropagation(),I.key==="Enter")$0(!0);else if(I.key==="Escape")$0(!1)}),requestAnimationFrame(()=>{if(L!==M)return;M.focus(),M.select(),M.addEventListener("blur",()=>$0(!0))}),q()}function o0(Z){let{x:V,y:Y}=C(Z);if($.setPointerCapture(Z.pointerId),u(V,Y)){M0();return}let X=e(V,Y);if(X&&Q[W]){G={grip:X,x:V,y:Y,start:{...Q[W]}};return}if(z==="text"){if(Z.preventDefault(),$.hasPointerCapture(Z.pointerId))$.releasePointerCapture(Z.pointerId);z=null,J(),i0(V,Y);return}if(z){K={tool:z,x1:V,y1:Y,x2:V,y2:Y},W=-1;return}let F=E(V,Y);W=F,G=F>=0?{grip:"body",x:V,y:Y,start:{...Q[F]}}:null,q()}function l0(Z){let{x:V,y:Y}=C(Z);if(K){K.x2=V,K.y2=Y,q();return}if(G){let F=Q[W];if(!F)return;let M=V-G.x,I=Y-G.y;if(G.grip==="body")H0(F,G.start,M,I);else p(F,G.grip,G.start,M,I);q();return}if(z){$.style.cursor="crosshair";return}if(u(V,Y)){$.style.cursor="pointer";return}let X=e(V,Y);if(X){let F=Q[W]?O(Q[W]).find((M)=>M.id===X):null;$.style.cursor=F?.cursor??"pointer";return}$.style.cursor=E(V,Y)>=0?"move":"default"}function z0(){if(K){if(!(Math.abs(K.x2-K.x1)<c1&&Math.abs(K.y2-K.y1)<c1))Q.push(K),W=Q.length-1,z=null,J();K=null}if(G)G=null,J();q()}function r0(Z){let V=$.getBoundingClientRect(),Y=(Z.clientX-V.left)/V.width*$.width,X=(Z.clientY-V.top)/V.height*$.height,F=E(Y,X),M=Q[F];if(!M||M.tool!=="text")return;Z.preventDefault(),i0(M.x1,M.y1,F)}function s0(Z){if(W<0)return;if(Z.key==="Delete"||Z.key==="Backspace")Z.preventDefault(),M0();else if(Z.key==="Escape")W=-1,q()}function M0(){if(W<0)return;Q.splice(W,1),W=-1,J(),q()}return $.addEventListener("pointerdown",o0),$.addEventListener("pointermove",l0),$.addEventListener("pointerup",z0),$.addEventListener("pointercancel",z0),$.addEventListener("dblclick",r0),$.tabIndex=0,$.addEventListener("keydown",s0),q(),{setTool(Z){z=Z,W=-1,$.style.cursor=Z?"crosshair":"default",q()},deleteSelected:M0,clear(){Q.length=0,W=-1,J(),q()},hasShapes:()=>Q.length>0,hasSelection:()=>W>=0,toDataUrl(){let Z=document.createElement("canvas");Z.width=j.naturalWidth,Z.height=j.naturalHeight;let V=Z.getContext("2d");if(!V)return $.toDataURL("image/png");V.drawImage(j,0,0);let Y=U();for(let X of Q)_(V,X,Y);return Z.toDataURL("image/png")},destroy(){$0(!1),$.removeEventListener("pointerdown",o0),$.removeEventListener("pointermove",l0),$.removeEventListener("pointerup",z0),$.removeEventListener("pointercancel",z0),$.removeEventListener("dblclick",r0),$.removeEventListener("keydown",s0)}}}var i1=`
42
42
  :host { all: initial; }
43
43
  * { box-sizing: border-box; }
44
44
 
package/dist/submit.d.ts CHANGED
@@ -5,4 +5,19 @@ export interface FiledTicket {
5
5
  status: string;
6
6
  }
7
7
  export declare function toBase64(bytes: Uint8Array): string;
8
+ /**
9
+ * A data URI for the JSON bundle, so the bulk lands in object storage.
10
+ *
11
+ * The screenshot is dropped first, and that is not an optimisation. It travels
12
+ * as its own compressed attachment; leaving it in here embedded the raw
13
+ * full-resolution data URL a second time and then base64'd the lot again, so a
14
+ * report from a 4K display arrived over the server's 5 MB per-file cap and
15
+ * failed — every time, with nothing the reporter could do about it. The size
16
+ * budget already excludes it from its own measurement for exactly this reason
17
+ * (`budget.ts`), which is what made the duplication invisible.
18
+ */
19
+ export declare function bundleAttachment(bundle: DebugBundle): {
20
+ dataUri: string;
21
+ filename: string;
22
+ };
8
23
  export declare function submitBundle(title: string, bundle: DebugBundle): Promise<FiledTicket>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightworkai.official/debug-capture",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "Report-a-problem widget: rolling network/console/action capture, annotated screenshot, and submission to a Lightwork Support host",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
package/src/submit.ts CHANGED
@@ -39,10 +39,21 @@ export function toBase64(bytes: Uint8Array): string {
39
39
  return btoa(binary);
40
40
  }
41
41
 
42
- /** A data URI for the JSON bundle, so the bulk lands in object storage. */
43
- function bundleAttachment(bundle: DebugBundle): { dataUri: string; filename: string } {
42
+ /**
43
+ * A data URI for the JSON bundle, so the bulk lands in object storage.
44
+ *
45
+ * The screenshot is dropped first, and that is not an optimisation. It travels
46
+ * as its own compressed attachment; leaving it in here embedded the raw
47
+ * full-resolution data URL a second time and then base64'd the lot again, so a
48
+ * report from a 4K display arrived over the server's 5 MB per-file cap and
49
+ * failed — every time, with nothing the reporter could do about it. The size
50
+ * budget already excludes it from its own measurement for exactly this reason
51
+ * (`budget.ts`), which is what made the duplication invisible.
52
+ */
53
+ export function bundleAttachment(bundle: DebugBundle): { dataUri: string; filename: string } {
54
+ const { screenshotDataUrl: _sentSeparately, ...rest } = bundle;
44
55
  // btoa is latin1-only and a bundle is full of Thai. Encode to bytes first.
45
- const base64 = toBase64(new TextEncoder().encode(JSON.stringify(bundle)));
56
+ const base64 = toBase64(new TextEncoder().encode(JSON.stringify(rest)));
46
57
  return { dataUri: `data:application/json;base64,${base64}`, filename: "debug-bundle.json" };
47
58
  }
48
59