@bugdump/sdk 0.0.1 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="https://api.bugdump.io";function H(n){return {projectKey:n.projectKey,endpoint:(n.endpoint||K).replace(/\/+$/,"")}}function k(){return {initialized:false,config:null,user:null,customContext:{},widgetOpen:false}}var m=class{endpoint;apiKey;constructor(t,e){this.endpoint=t,this.apiKey=e;}async submitReport(t){return this.post("/api/widget/v1/reports",t)}async requestUpload(t){return this.post("/api/widget/v1/reports/upload",t)}async uploadFileToS3(t,e,o){let r=new FormData;for(let[a,l]of Object.entries(e))r.append(a,l);r.append("file",o);let i=await fetch(t,{method:"POST",body:r});if(!i.ok)throw new h("S3_UPLOAD_FAILED",i.status)}async post(t,e){let o=`${this.endpoint}${t}`,r=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json","Bugdump-API-Key":this.apiKey},body:JSON.stringify(e)});if(!r.ok){let i;try{i=await r.json();}catch{}throw new h(i?.error||`HTTP_${r.status}`,r.status,i?.details)}return await r.json()}},h=class extends Error{code;statusCode;details;constructor(t,e,o){super(`Bugdump API error: ${t} (${e})`),this.name="BugdumpApiError",this.code=t,this.statusCode=e,this.details=o;}};var B=["log","warn","error","info","debug"],f=class{buffer=[];originals=new Map;active=false;start(){if(!this.active){this.active=true;for(let t of B)this.originals.set(t,console[t].bind(console)),console[t]=(...e)=>{this.push({level:t,args:this.serializeArgs(e),timestamp:Date.now()}),this.originals.get(t)(...e);};}}stop(){if(this.active){this.active=false;for(let t of B){let e=this.originals.get(t);e&&(console[t]=e);}this.originals.clear();}}flush(){let t=[...this.buffer];return this.buffer=[],t}push(t){this.buffer.push(t),this.buffer.length>50&&this.buffer.shift();}serializeArgs(t){return t.map(e=>{if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;try{return JSON.parse(JSON.stringify(e,this.circularReplacer()))}catch{return String(e)}})}circularReplacer(){let t=new WeakSet;return (e,o)=>{if(typeof o=="object"&&o!==null){if(t.has(o))return "[Circular]";t.add(o);}return o}}};var g=class{buffer=[];originalFetch=null;originalXhrOpen=null;originalXhrSend=null;active=false;start(){this.active||(this.active=true,this.patchFetch(),this.patchXhr());}stop(){this.active&&(this.active=false,this.restoreFetch(),this.restoreXhr());}flush(){let t=[...this.buffer];return this.buffer=[],t}push(t){this.buffer.push(t),this.buffer.length>30&&this.buffer.shift();}patchFetch(){this.originalFetch=window.fetch;let t=this;window.fetch=async function(e,o){let r=o?.method?.toUpperCase()||"GET",i=typeof e=="string"?e:e instanceof URL?e.href:e.url,a=Date.now(),l=t.extractHeaders(o?.headers);try{let d=await t.originalFetch.call(window,e,o);return t.push({method:r,url:i,status:d.status,statusText:d.statusText,requestHeaders:l,responseHeaders:t.extractHeaders(d.headers),duration:Date.now()-a,startedAt:a,error:null}),d}catch(d){throw t.push({method:r,url:i,status:null,statusText:null,requestHeaders:l,responseHeaders:{},duration:Date.now()-a,startedAt:a,error:d instanceof Error?d.message:String(d)}),d}};}restoreFetch(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null);}patchXhr(){this.originalXhrOpen=XMLHttpRequest.prototype.open,this.originalXhrSend=XMLHttpRequest.prototype.send;let t=this;XMLHttpRequest.prototype.open=function(e,o){return this.__bd_method=e.toUpperCase(),this.__bd_url=typeof o=="string"?o:o.href,t.originalXhrOpen.apply(this,arguments)},XMLHttpRequest.prototype.send=function(e){let o=Date.now(),r=this.__bd_method||"GET",i=this.__bd_url||"",a=()=>{t.push({method:r,url:i,status:this.status||null,statusText:this.statusText||null,requestHeaders:{},responseHeaders:t.parseXhrResponseHeaders(this.getAllResponseHeaders()),duration:Date.now()-o,startedAt:o,error:this.status===0?"Network error":null}),this.removeEventListener("loadend",a);};return this.addEventListener("loadend",a),t.originalXhrSend.call(this,e)};}restoreXhr(){this.originalXhrOpen&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,this.originalXhrOpen=null),this.originalXhrSend&&(XMLHttpRequest.prototype.send=this.originalXhrSend,this.originalXhrSend=null);}extractHeaders(t){let e={};if(!t)return e;if(t instanceof Headers)t.forEach((o,r)=>{e[r]=o;});else if(Array.isArray(t))for(let[o,r]of t)e[o]=r;else for(let[o,r]of Object.entries(t))e[o]=r;return e}parseXhrResponseHeaders(t){let e={};if(!t)return e;for(let o of t.trim().split(/[\r\n]+/)){let r=o.indexOf(":");if(r===-1)continue;let i=o.slice(0,r).trim().toLowerCase(),a=o.slice(r+1).trim();e[i]=a;}return e}};var Z=3e4,b=class{buffer=[];stopFn=null;active=false;start(){if(this.active)return;this.active=true;let t=record({emit:e=>{this.buffer.push(e),this.pruneOldEvents();},sampling:{mousemove:true,mouseInteraction:true,scroll:150,input:"last"},blockClass:"bugdump-block",maskAllInputs:true});t&&(this.stopFn=t);}stop(){this.active&&(this.active=false,this.stopFn&&(this.stopFn(),this.stopFn=null));}flush(){this.pruneOldEvents();let t=[...this.buffer];return this.buffer=[],t}pruneOldEvents(){let t=Date.now()-Z,e=this.buffer.findIndex(o=>o.timestamp>=t);e===-1?this.buffer=[]:e>0&&(this.buffer=this.buffer.slice(e));}};function _(){return {timing:Q(),memory:tt(),resources:et()}}function Q(){let n=performance.getEntriesByType("navigation");if(n.length===0)return null;let t=n[0],e=performance.getEntriesByType("paint"),o=e.find(i=>i.name==="first-paint"),r=e.find(i=>i.name==="first-contentful-paint");return {domContentLoaded:t.domContentLoadedEventEnd>0?Math.round(t.domContentLoadedEventEnd):null,loadComplete:t.loadEventEnd>0?Math.round(t.loadEventEnd):null,firstPaint:o?Math.round(o.startTime):null,firstContentfulPaint:r?Math.round(r.startTime):null,ttfb:t.responseStart>0?Math.round(t.responseStart):null}}function tt(){let n=performance;return n.memory?{usedJSHeapSize:n.memory.usedJSHeapSize,totalJSHeapSize:n.memory.totalJSHeapSize,jsHeapSizeLimit:n.memory.jsHeapSizeLimit}:null}function et(){return performance.getEntriesByType("resource").slice(-20).map(t=>({name:t.name,type:t.initiatorType,duration:Math.round(t.duration),size:t.transferSize||0}))}function D(){return {userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,viewport:{width:window.innerWidth,height:window.innerHeight},screenResolution:{width:screen.width,height:screen.height},devicePixelRatio:window.devicePixelRatio||1,url:window.location.href,referrer:document.referrer,timestamp:Date.now()}}var s={primary:"#6366f1",primaryHover:"#4f46e5",primaryText:"#ffffff",bg:"#ffffff",bgSecondary:"#f9fafb",bgHover:"#f3f4f6",border:"#e5e7eb",borderFocus:"#6366f1",text:"#111827",textSecondary:"#6b7280",textMuted:"#9ca3af",danger:"#ef4444",dangerHover:"#dc2626",overlay:"rgba(0, 0, 0, 0.5)",shadow:"rgba(0, 0, 0, 0.15)",shadowLight:"rgba(0, 0, 0, 0.08)"};function O(){return `
1
+ import {record}from'@rrweb/record';import ut from'html2canvas-pro';var lt="https://api.bugdump.com";function A(o){return {projectKey:o.projectKey,endpoint:(o.endpoint||lt).replace(/\/+$/,""),captureNetworkBodies:o.captureNetworkBodies??false,hideButton:o.hideButton??false}}function M(){return {initialized:false,config:null,user:null,customContext:{},widgetOpen:false}}var y=class{endpoint;apiKey;constructor(t,e){this.endpoint=t,this.apiKey=e;}async submitReport(t){return this.post("/api/widget/v1/reports",t)}async requestUpload(t){return this.post("/api/widget/v1/reports/upload",t)}async uploadFileToS3(t,e,n,r){let i=new FormData;for(let[l,d]of Object.entries(e))i.append(l,d);if(i.append("file",n),r)return new Promise((l,d)=>{let c=new XMLHttpRequest;c.open("POST",t),c.upload.addEventListener("progress",p=>{p.lengthComputable&&r(Math.round(p.loaded/p.total*100));}),c.addEventListener("load",()=>{c.status>=200&&c.status<300?(r(100),l()):d(new f("S3_UPLOAD_FAILED",c.status));}),c.addEventListener("error",()=>{d(new f("S3_UPLOAD_FAILED",0));}),c.send(i);});let s=await fetch(t,{method:"POST",body:i});if(!s.ok)throw new f("S3_UPLOAD_FAILED",s.status)}async post(t,e){let n=`${this.endpoint}${t}`,r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json","Bugdump-API-Key":this.apiKey},body:JSON.stringify(e)});if(!r.ok){let i;try{i=await r.json();}catch{}throw new f(i?.error||`HTTP_${r.status}`,r.status,i?.details)}return await r.json()}},f=class extends Error{code;statusCode;details;constructor(t,e,n){super(`Bugdump API error: ${t} (${e})`),this.name="BugdumpApiError",this.code=t,this.statusCode=e,this.details=n;}};var $=["log","warn","error","info","debug"],k=class{buffer=[];originals=new Map;active=false;start(){if(!this.active){this.active=true;for(let t of $)this.originals.set(t,console[t].bind(console)),console[t]=(...e)=>{this.push({level:t,args:this.serializeArgs(e),timestamp:Date.now()}),this.originals.get(t)(...e);};}}stop(){if(this.active){this.active=false;for(let t of $){let e=this.originals.get(t);e&&(console[t]=e);}this.originals.clear();}}flush(){let t=[...this.buffer];return this.buffer=[],t}push(t){this.buffer.push(t),this.buffer.length>50&&this.buffer.shift();}serializeArgs(t){return t.map(e=>{if(e==null||typeof e=="string"||typeof e=="number"||typeof e=="boolean")return e;if(e instanceof Error)return {name:e.name,message:e.message,stack:e.stack};try{return JSON.parse(JSON.stringify(e,this.circularReplacer()))}catch{return String(e)}})}circularReplacer(){let t=new WeakSet;return (e,n)=>{if(typeof n=="object"&&n!==null){if(t.has(n))return "[Circular]";t.add(n);}return n}}};var b=class{buffer=[];originalFetch=null;originalXhrOpen=null;originalXhrSend=null;active=false;options;constructor(t={}){this.options=t;}start(){this.active||(this.active=true,this.patchFetch(),this.patchXhr());}stop(){this.active&&(this.active=false,this.restoreFetch(),this.restoreXhr());}flush(){let t=[...this.buffer];return this.buffer=[],t}push(t){this.buffer.push(t),this.buffer.length>30&&this.buffer.shift();}patchFetch(){this.originalFetch=window.fetch;let t=this;window.fetch=async function(e,n){let r=n?.method?.toUpperCase()||"GET",i=typeof e=="string"?e:e instanceof URL?e.href:e.url,s=Date.now(),l=t.extractHeaders(n?.headers),d=t.options.captureBodies?t.serializeBody(n?.body):null;try{let c=await t.originalFetch.call(window,e,n),p=null;if(t.options.captureBodies)try{let u=await c.clone().text();p=t.truncateBody(u);}catch{}return t.push({method:r,url:i,status:c.status,statusText:c.statusText,requestHeaders:l,responseHeaders:t.extractHeaders(c.headers),requestBody:d,responseBody:p,duration:Date.now()-s,startedAt:s,error:null}),c}catch(c){throw t.push({method:r,url:i,status:null,statusText:null,requestHeaders:l,responseHeaders:{},requestBody:d,responseBody:null,duration:Date.now()-s,startedAt:s,error:c instanceof Error?c.message:String(c)}),c}};}restoreFetch(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null);}patchXhr(){this.originalXhrOpen=XMLHttpRequest.prototype.open,this.originalXhrSend=XMLHttpRequest.prototype.send;let t=this;XMLHttpRequest.prototype.open=function(e,n){return this.__bd_method=e.toUpperCase(),this.__bd_url=typeof n=="string"?n:n.href,t.originalXhrOpen.apply(this,arguments)},XMLHttpRequest.prototype.send=function(e){let n=Date.now(),r=this.__bd_method||"GET",i=this.__bd_url||"",s=t.options.captureBodies?t.serializeBody(e):null,l=()=>{let d=null;if(t.options.captureBodies)try{d=t.truncateBody(this.responseText);}catch{}t.push({method:r,url:i,status:this.status||null,statusText:this.statusText||null,requestHeaders:{},responseHeaders:t.parseXhrResponseHeaders(this.getAllResponseHeaders()),requestBody:s,responseBody:d,duration:Date.now()-n,startedAt:n,error:this.status===0?"Network error":null}),this.removeEventListener("loadend",l);};return this.addEventListener("loadend",l),t.originalXhrSend.call(this,e)};}restoreXhr(){this.originalXhrOpen&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,this.originalXhrOpen=null),this.originalXhrSend&&(XMLHttpRequest.prototype.send=this.originalXhrSend,this.originalXhrSend=null);}extractHeaders(t){let e={};if(!t)return e;if(t instanceof Headers)t.forEach((n,r)=>{e[r]=n;});else if(Array.isArray(t))for(let[n,r]of t)e[n]=r;else for(let[n,r]of Object.entries(t))e[n]=r;return e}serializeBody(t){if(t==null)return null;if(typeof t=="string")return this.truncateBody(t);if(t instanceof URLSearchParams)return this.truncateBody(t.toString());if(t instanceof FormData){let e=[];return t.forEach((n,r)=>{e.push(`${r}=${n instanceof File?`[File: ${n.name}]`:n}`);}),this.truncateBody(e.join("&"))}if(t instanceof ArrayBuffer||t instanceof Blob)return `[Binary: ${t instanceof Blob?t.size:t.byteLength} bytes]`;try{return this.truncateBody(JSON.stringify(t))}catch{return null}}truncateBody(t){return t.length<=32768?t:t.slice(0,32768)+"\u2026[truncated]"}parseXhrResponseHeaders(t){let e={};if(!t)return e;for(let n of t.trim().split(/[\r\n]+/)){let r=n.indexOf(":");if(r===-1)continue;let i=n.slice(0,r).trim().toLowerCase(),s=n.slice(r+1).trim();e[i]=s;}return e}};var P=6e4,_=5e3,S=class{buffer=[];stopFn=null;active=false;start(){if(this.active)return;this.active=true;let t=record({emit:e=>{this.buffer.push(e),this.pruneBuffer();},checkoutEveryNms:P,inlineStylesheet:true,inlineImages:true,collectFonts:true,sampling:{mousemove:50,mouseInteraction:true,scroll:150,input:"last",media:800},slimDOMOptions:{script:true,comment:true,headFavicon:true,headWhitespace:true,headMetaDescKeywords:true,headMetaSocial:true,headMetaRobots:true,headMetaHttpEquiv:true,headMetaAuthorship:true},blockClass:"bugdump-block",maskAllInputs:true});t&&(this.stopFn=t),this.schedulePostLoadSnapshot();}schedulePostLoadSnapshot(){let t=()=>{this.active&&record.takeFullSnapshot&&record.takeFullSnapshot();};document.readyState==="complete"?setTimeout(t,100):window.addEventListener("load",()=>setTimeout(t,100),{once:true});}stop(){this.active&&(this.active=false,this.stopFn&&(this.stopFn(),this.stopFn=null));}flush(){this.active&&record.takeFullSnapshot&&record.takeFullSnapshot();let t=this.extractReplayableSlice();return this.buffer=[],t}extractReplayableSlice(){let t=Date.now()-P,e=-1;for(let s=this.buffer.length-1;s>=0;s--)if(this.buffer[s]?.type===2){e=s;break}if(e===-1)return [];let n=e;n>0&&this.buffer[n-1]?.type===4&&(n=n-1);let r=this.buffer.slice(n),i=-1;for(let s=0;s<this.buffer.length;s++){let l=this.buffer[s];if(l&&!(l.timestamp<t)){if(l.type===2){i=s;break}if(l.type===4&&this.buffer[s+1]?.type===2){i=s;break}}}if(i>=0){let s=this.buffer.slice(i);if(s.length>r.length)return s}return r}pruneBuffer(){if(this.buffer.length<=_)return;let t=Date.now()-P,e=this.buffer.findIndex(n=>n.timestamp>=t);if(e===-1){let n=this.findLastSnapshotStart();this.buffer=n>=0?this.buffer.slice(n):[];return}if(e>0){let n=-1;for(let r=e;r>=0;r--)if(this.buffer[r]?.type===2){n=r;break}if(n>=0){let r=n>0&&this.buffer[n-1]?.type===4?n-1:n;this.buffer=this.buffer.slice(r);}else this.buffer=this.buffer.slice(e);}if(this.buffer.length>_){let n=this.findLastSnapshotStart();n>0?this.buffer=this.buffer.slice(n):this.buffer=this.buffer.slice(-_);}}findLastSnapshotStart(){for(let t=this.buffer.length-1;t>=0;t--)if(this.buffer[t]?.type===2)return t>0&&this.buffer[t-1]?.type===4?t-1:t;return -1}};function U(){return {timing:dt(),memory:ct(),resources:pt()}}function dt(){let o=performance.getEntriesByType("navigation");if(o.length===0)return null;let t=o[0],e=performance.getEntriesByType("paint"),n=e.find(i=>i.name==="first-paint"),r=e.find(i=>i.name==="first-contentful-paint");return {domContentLoaded:t.domContentLoadedEventEnd>0?Math.round(t.domContentLoadedEventEnd):null,loadComplete:t.loadEventEnd>0?Math.round(t.loadEventEnd):null,firstPaint:n?Math.round(n.startTime):null,firstContentfulPaint:r?Math.round(r.startTime):null,ttfb:t.responseStart>0?Math.round(t.responseStart):null}}function ct(){let o=performance;return o.memory?{usedJSHeapSize:o.memory.usedJSHeapSize,totalJSHeapSize:o.memory.totalJSHeapSize,jsHeapSizeLimit:o.memory.jsHeapSizeLimit}:null}function pt(){return performance.getEntriesByType("resource").slice(-20).map(t=>({name:t.name,type:t.initiatorType,duration:Math.round(t.duration),size:t.transferSize||0}))}function z(){return {userAgent:navigator.userAgent,language:navigator.language,platform:navigator.platform,viewport:{width:window.innerWidth,height:window.innerHeight},screenResolution:{width:screen.width,height:screen.height},devicePixelRatio:window.devicePixelRatio||1,url:window.location.href,referrer:document.referrer,timestamp:Date.now()}}var a={primary:"#6366f1",primaryHover:"#4f46e5",primaryText:"#ffffff",bg:"#ffffff",bgSecondary:"#f9fafb",bgHover:"#f3f4f6",border:"#e5e7eb",borderFocus:"#6366f1",text:"#111827",textSecondary:"#6b7280",textMuted:"#9ca3af",danger:"#ef4444",dangerHover:"#dc2626",shadow:"rgba(0, 0, 0, 0.15)",shadowLight:"rgba(0, 0, 0, 0.08)"};function F(){return `
2
2
  * {
3
3
  box-sizing: border-box;
4
4
  margin: 0;
@@ -12,23 +12,23 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
12
12
  width: 56px;
13
13
  height: 56px;
14
14
  border-radius: 50%;
15
- background: ${s.primary};
16
- color: ${s.primaryText};
15
+ background: ${a.primary};
16
+ color: ${a.primaryText};
17
17
  border: none;
18
18
  cursor: pointer;
19
19
  display: flex;
20
20
  align-items: center;
21
21
  justify-content: center;
22
- box-shadow: 0 4px 12px ${s.shadow};
22
+ box-shadow: 0 4px 12px ${a.shadow};
23
23
  transition: background-color 0.2s, transform 0.2s, box-shadow 0.2s;
24
24
  z-index: 2147483647;
25
25
  outline: none;
26
26
  }
27
27
 
28
28
  .bd-trigger:hover {
29
- background: ${s.primaryHover};
29
+ background: ${a.primaryHover};
30
30
  transform: scale(1.05);
31
- box-shadow: 0 6px 16px ${s.shadow};
31
+ box-shadow: 0 6px 16px ${a.shadow};
32
32
  }
33
33
 
34
34
  .bd-trigger:active {
@@ -51,9 +51,9 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
51
51
  right: 20px;
52
52
  width: 380px;
53
53
  max-height: calc(100vh - 120px);
54
- background: ${s.bg};
54
+ background: ${a.bg};
55
55
  border-radius: 16px;
56
- box-shadow: 0 8px 32px ${s.shadow}, 0 2px 8px ${s.shadowLight};
56
+ box-shadow: 0 8px 32px ${a.shadow}, 0 2px 8px ${a.shadowLight};
57
57
  display: flex;
58
58
  flex-direction: column;
59
59
  overflow: hidden;
@@ -65,7 +65,7 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
65
65
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
66
66
  font-size: 14px;
67
67
  line-height: 1.5;
68
- color: ${s.text};
68
+ color: ${a.text};
69
69
  }
70
70
 
71
71
  .bd-panel--visible {
@@ -79,21 +79,21 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
79
79
  align-items: center;
80
80
  justify-content: space-between;
81
81
  padding: 16px 20px;
82
- border-bottom: 1px solid ${s.border};
83
- background: ${s.bgSecondary};
82
+ border-bottom: 1px solid ${a.border};
83
+ background: ${a.bgSecondary};
84
84
  }
85
85
 
86
86
  .bd-panel__title {
87
87
  font-size: 16px;
88
88
  font-weight: 600;
89
- color: ${s.text};
89
+ color: ${a.text};
90
90
  }
91
91
 
92
92
  .bd-panel__close {
93
93
  background: none;
94
94
  border: none;
95
95
  cursor: pointer;
96
- color: ${s.textSecondary};
96
+ color: ${a.textSecondary};
97
97
  padding: 4px;
98
98
  border-radius: 6px;
99
99
  display: flex;
@@ -103,8 +103,8 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
103
103
  }
104
104
 
105
105
  .bd-panel__close:hover {
106
- color: ${s.text};
107
- background: ${s.bgHover};
106
+ color: ${a.text};
107
+ background: ${a.bgHover};
108
108
  }
109
109
 
110
110
  .bd-panel__close svg {
@@ -125,24 +125,24 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
125
125
  width: 100%;
126
126
  min-height: 100px;
127
127
  padding: 10px 12px;
128
- border: 1px solid ${s.border};
128
+ border: 1px solid ${a.border};
129
129
  border-radius: 8px;
130
130
  resize: vertical;
131
131
  font-family: inherit;
132
132
  font-size: 14px;
133
133
  line-height: 1.5;
134
- color: ${s.text};
135
- background: ${s.bg};
134
+ color: ${a.text};
135
+ background: ${a.bg};
136
136
  outline: none;
137
137
  transition: border-color 0.15s;
138
138
  }
139
139
 
140
140
  .bd-textarea::placeholder {
141
- color: ${s.textMuted};
141
+ color: ${a.textMuted};
142
142
  }
143
143
 
144
144
  .bd-textarea:focus {
145
- border-color: ${s.borderFocus};
145
+ border-color: ${a.borderFocus};
146
146
  }
147
147
 
148
148
  .bd-action-bar {
@@ -156,10 +156,10 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
156
156
  align-items: center;
157
157
  gap: 6px;
158
158
  padding: 6px 10px;
159
- border: 1px solid ${s.border};
159
+ border: 1px solid ${a.border};
160
160
  border-radius: 6px;
161
- background: ${s.bg};
162
- color: ${s.textSecondary};
161
+ background: ${a.bg};
162
+ color: ${a.textSecondary};
163
163
  font-size: 13px;
164
164
  font-family: inherit;
165
165
  cursor: pointer;
@@ -167,9 +167,9 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
167
167
  }
168
168
 
169
169
  .bd-action-btn:hover {
170
- color: ${s.text};
171
- border-color: ${s.textSecondary};
172
- background: ${s.bgSecondary};
170
+ color: ${a.text};
171
+ border-color: ${a.textSecondary};
172
+ background: ${a.bgSecondary};
173
173
  }
174
174
 
175
175
  .bd-action-btn:disabled {
@@ -195,8 +195,8 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
195
195
  height: 64px;
196
196
  border-radius: 8px;
197
197
  overflow: hidden;
198
- border: 1px solid ${s.border};
199
- background: ${s.bgSecondary};
198
+ border: 1px solid ${a.border};
199
+ background: ${a.bgSecondary};
200
200
  }
201
201
 
202
202
  .bd-attachment img,
@@ -212,7 +212,7 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
212
212
  display: flex;
213
213
  align-items: center;
214
214
  justify-content: center;
215
- color: ${s.textSecondary};
215
+ color: ${a.textSecondary};
216
216
  }
217
217
 
218
218
  .bd-attachment__icon svg {
@@ -227,9 +227,9 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
227
227
  width: 20px;
228
228
  height: 20px;
229
229
  border-radius: 50%;
230
- background: ${s.danger};
231
- color: ${s.primaryText};
232
- border: 2px solid ${s.bg};
230
+ background: ${a.danger};
231
+ color: ${a.primaryText};
232
+ border: 2px solid ${a.bg};
233
233
  cursor: pointer;
234
234
  display: flex;
235
235
  align-items: center;
@@ -241,7 +241,7 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
241
241
  }
242
242
 
243
243
  .bd-attachment__remove:hover {
244
- background: ${s.dangerHover};
244
+ background: ${a.dangerHover};
245
245
  }
246
246
 
247
247
  .bd-attachment__remove svg {
@@ -258,13 +258,13 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
258
258
  cursor: pointer;
259
259
  font-size: 13px;
260
260
  font-family: inherit;
261
- color: ${s.textSecondary};
261
+ color: ${a.textSecondary};
262
262
  padding: 0;
263
263
  transition: color 0.15s;
264
264
  }
265
265
 
266
266
  .bd-reporter-toggle:hover {
267
- color: ${s.text};
267
+ color: ${a.text};
268
268
  }
269
269
 
270
270
  .bd-reporter-toggle svg {
@@ -291,27 +291,27 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
291
291
  .bd-input {
292
292
  width: 100%;
293
293
  padding: 8px 12px;
294
- border: 1px solid ${s.border};
294
+ border: 1px solid ${a.border};
295
295
  border-radius: 8px;
296
296
  font-family: inherit;
297
297
  font-size: 14px;
298
- color: ${s.text};
299
- background: ${s.bg};
298
+ color: ${a.text};
299
+ background: ${a.bg};
300
300
  outline: none;
301
301
  transition: border-color 0.15s;
302
302
  }
303
303
 
304
304
  .bd-input::placeholder {
305
- color: ${s.textMuted};
305
+ color: ${a.textMuted};
306
306
  }
307
307
 
308
308
  .bd-input:focus {
309
- border-color: ${s.borderFocus};
309
+ border-color: ${a.borderFocus};
310
310
  }
311
311
 
312
312
  .bd-panel__footer {
313
313
  padding: 12px 20px;
314
- border-top: 1px solid ${s.border};
314
+ border-top: 1px solid ${a.border};
315
315
  display: flex;
316
316
  justify-content: flex-end;
317
317
  gap: 8px;
@@ -322,8 +322,8 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
322
322
  align-items: center;
323
323
  gap: 6px;
324
324
  padding: 8px 20px;
325
- background: ${s.primary};
326
- color: ${s.primaryText};
325
+ background: ${a.primary};
326
+ color: ${a.primaryText};
327
327
  border: none;
328
328
  border-radius: 8px;
329
329
  font-size: 14px;
@@ -334,7 +334,7 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
334
334
  }
335
335
 
336
336
  .bd-send-btn:hover {
337
- background: ${s.primaryHover};
337
+ background: ${a.primaryHover};
338
338
  }
339
339
 
340
340
  .bd-send-btn:disabled {
@@ -370,82 +370,13 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
370
370
 
371
371
  .bd-success__subtitle {
372
372
  font-size: 14px;
373
- color: ${s.textSecondary};
374
- }
375
-
376
- .bd-annotation-overlay {
377
- position: fixed;
378
- top: 0;
379
- left: 0;
380
- width: 100%;
381
- height: 100%;
382
- z-index: 2147483647;
383
- background: ${s.overlay};
384
- display: flex;
385
- flex-direction: column;
386
- }
387
-
388
- .bd-annotation-toolbar {
389
- display: flex;
390
- align-items: center;
391
- gap: 4px;
392
- padding: 8px 12px;
393
- background: rgba(0, 0, 0, 0.85);
394
- color: ${s.primaryText};
395
- }
396
-
397
- .bd-annotation-toolbar button {
398
- padding: 6px 10px;
399
- background: transparent;
400
- color: ${s.primaryText};
401
- border: 1px solid transparent;
402
- border-radius: 6px;
403
- font-size: 13px;
404
- font-family: inherit;
405
- cursor: pointer;
406
- transition: background-color 0.15s, border-color 0.15s;
407
- }
408
-
409
- .bd-annotation-toolbar button:hover {
410
- background: rgba(255, 255, 255, 0.1);
411
- }
412
-
413
- .bd-annotation-toolbar button.active {
414
- background: rgba(255, 255, 255, 0.2);
415
- border-color: rgba(255, 255, 255, 0.3);
416
- }
417
-
418
- .bd-annotation-toolbar__spacer {
419
- flex: 1;
420
- }
421
-
422
- .bd-annotation-toolbar__confirm {
423
- background: #22c55e !important;
424
- color: ${s.primaryText} !important;
425
- font-weight: 500;
426
- }
427
-
428
- .bd-annotation-toolbar__confirm:hover {
429
- background: #16a34a !important;
430
- }
431
-
432
- .bd-annotation-toolbar__cancel {
433
- color: ${s.textMuted} !important;
434
- }
435
-
436
- .bd-annotation-canvas-wrap {
437
- flex: 1;
438
- display: flex;
439
- align-items: center;
440
- justify-content: center;
441
- overflow: hidden;
442
- position: relative;
373
+ color: ${a.textSecondary};
443
374
  }
444
375
 
445
376
  .bd-spinner {
446
377
  width: 20px;
447
378
  height: 20px;
448
- border: 2px solid ${s.primaryText};
379
+ border: 2px solid ${a.primaryText};
449
380
  border-top-color: transparent;
450
381
  border-radius: 50%;
451
382
  animation: bd-spin 0.6s linear infinite;
@@ -469,21 +400,21 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
469
400
  border-radius: 16px 16px 0 0;
470
401
  }
471
402
  }
472
- `}function S(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2l1.88 1.88"/><path d="M14.12 3.88 16 2"/><path d="M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/><path d="M12 20v-9"/><path d="M6.53 9C4.6 8.8 3 7.1 3 5"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="M22 13h-4"/><path d="M17.2 17c2.1.1 3.8 1.9 3.8 4"/></svg>'}function v(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>'}function I(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>'}function A(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg>'}function E(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"/><rect x="2" y="6" width="14" height="12" rx="2"/></svg>'}function L(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m22 2-7 20-4-9-9-4z"/><path d="M22 2 11 13"/></svg>'}function $(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>'}function U(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="m9 11 3 3L22 4"/></svg>'}function z(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/></svg>'}function W(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>'}function F(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>'}var ot=.85,rt="image/jpeg";async function x(n={}){let{quality:t=ot,target:e=document.body,filter:o}=n,r=e.scrollWidth,i=e.scrollHeight,a=await toBlob(e,{quality:t,type:rt,filter:o,cacheBust:true});if(!a)throw new Error("Screenshot capture failed: no blob produced");return {blob:a,width:r,height:i}}var w=Math.PI/6,it="#ff0000",st=3,at=16,lt=10,dt=0;function u(){return `ann_${Date.now()}_${++dt}`}function j(n,t,e,o,r){let i=Math.atan2(e.y-t.y,e.x-t.x);n.save(),n.strokeStyle=o,n.fillStyle=o,n.lineWidth=r,n.lineCap="round",n.lineJoin="round",n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(e.x,e.y),n.stroke(),n.beginPath(),n.moveTo(e.x,e.y),n.lineTo(e.x-15*Math.cos(i-w),e.y-15*Math.sin(i-w)),n.lineTo(e.x-15*Math.cos(i+w),e.y-15*Math.sin(i+w)),n.closePath(),n.fill(),n.restore();}function q(n,t,e,o,r){n.save(),n.strokeStyle=o,n.lineWidth=r,n.lineCap="round",n.lineJoin="round",n.strokeRect(t.x,t.y,e.x-t.x,e.y-t.y),n.restore();}function pt(n,t,e,o,r){n.save(),n.font=`${r}px sans-serif`,n.textBaseline="top";let i=4,a=n.measureText(e),l=r*1.2;n.fillStyle="rgba(0, 0, 0, 0.6)",n.fillRect(t.x-i,t.y-i,a.width+i*2,l+i*2),n.fillStyle=o,n.fillText(e,t.x,t.y),n.restore();}function N(n,t,e,o,r){let i=Math.min(e.x,o.x),a=Math.min(e.y,o.y),l=Math.abs(o.x-e.x),d=Math.abs(o.y-e.y);l===0||d===0||(n.save(),n.filter=`blur(${r}px)`,n.drawImage(t,i,a,l,d,i,a,l,d),n.filter="none",n.strokeStyle="rgba(128, 128, 128, 0.5)",n.lineWidth=1,n.setLineDash([4,4]),n.strokeRect(i,a,l,d),n.setLineDash([]),n.restore());}function X(n,t,e,o){if(t.length<2)return;n.save(),n.strokeStyle=e,n.lineWidth=o,n.lineCap="round",n.lineJoin="round";let r=t[0];n.beginPath(),n.moveTo(r.x,r.y);for(let i=1;i<t.length;i++){let a=t[i];n.lineTo(a.x,a.y);}n.stroke(),n.restore();}function V(n,t,e){switch(e.tool){case "arrow":j(n,e.start,e.end,e.color,e.lineWidth);break;case "box":q(n,e.start,e.end,e.color,e.lineWidth);break;case "text":pt(n,e.position,e.text,e.color,e.fontSize);break;case "blur":N(n,t,e.start,e.end,e.blurRadius);break;case "freehand":X(n,e.points,e.color,e.lineWidth);break}}function J(n,t){for(let e of t)V(n,n.canvas,e);}var c=class{constructor(t,e,o){this.container=t;this.width=e;this.height=o;this.canvas=document.createElement("canvas"),this.canvas.width=e,this.canvas.height=o,this.canvas.style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;cursor:crosshair;touch-action:none;";let r=this.canvas.getContext("2d");if(!r)throw new Error("Failed to get 2D canvas context");this.ctx=r,this.onPointerDownBound=this.onPointerDown.bind(this),this.onPointerMoveBound=this.onPointerMove.bind(this),this.onPointerUpBound=this.onPointerUp.bind(this),this.canvas.addEventListener("pointerdown",this.onPointerDownBound),this.canvas.addEventListener("pointermove",this.onPointerMoveBound),this.canvas.addEventListener("pointerup",this.onPointerUpBound),this.container.appendChild(this.canvas);}canvas;ctx;operations=[];currentTool="arrow";color=it;lineWidth=st;fontSize=at;blurRadius=lt;isDrawing=false;startPoint=null;currentPoints=[];screenshotImage=null;onPointerDownBound;onPointerMoveBound;onPointerUpBound;setScreenshotImage(t){this.screenshotImage=t,this.redraw();}setTool(t){this.currentTool=t;}getTool(){return this.currentTool}setColor(t){this.color=t;}setLineWidth(t){this.lineWidth=t;}setFontSize(t){this.fontSize=t;}setBlurRadius(t){this.blurRadius=t;}getOperations(){return [...this.operations]}undo(){this.operations.pop(),this.redraw();}clear(){this.operations=[],this.redraw();}addTextAtPosition(t,e){let o={id:u(),tool:"text",color:this.color,lineWidth:this.lineWidth,position:t,text:e,fontSize:this.fontSize,timestamp:Date.now()};this.operations.push(o),this.redraw();}destroy(){this.canvas.removeEventListener("pointerdown",this.onPointerDownBound),this.canvas.removeEventListener("pointermove",this.onPointerMoveBound),this.canvas.removeEventListener("pointerup",this.onPointerUpBound),this.canvas.remove();}getCanvasPoint(t){let e=this.canvas.getBoundingClientRect();return {x:(t.clientX-e.left)/e.width*this.width,y:(t.clientY-e.top)/e.height*this.height}}onPointerDown(t){t.preventDefault(),this.canvas.setPointerCapture(t.pointerId);let e=this.getCanvasPoint(t);if(this.startPoint=e,this.currentTool==="text"){this.promptTextInput(e);return}this.isDrawing=true,this.currentTool==="freehand"&&(this.currentPoints=[e]);}onPointerMove(t){if(!this.isDrawing||!this.startPoint)return;t.preventDefault();let e=this.getCanvasPoint(t);this.currentTool==="freehand"&&this.currentPoints.push(e),this.redraw(),this.drawPreview(e);}onPointerUp(t){if(!this.isDrawing||!this.startPoint)return;t.preventDefault();let e=this.getCanvasPoint(t);switch(this.currentTool){case "arrow":this.operations.push({id:u(),tool:"arrow",color:this.color,lineWidth:this.lineWidth,start:this.startPoint,end:e,timestamp:Date.now()});break;case "box":this.operations.push({id:u(),tool:"box",color:this.color,lineWidth:this.lineWidth,start:this.startPoint,end:e,timestamp:Date.now()});break;case "blur":this.operations.push({id:u(),tool:"blur",color:this.color,lineWidth:this.lineWidth,start:this.startPoint,end:e,blurRadius:this.blurRadius,timestamp:Date.now()});break;case "freehand":this.currentPoints.push(e),this.operations.push({id:u(),tool:"freehand",color:this.color,lineWidth:this.lineWidth,points:[...this.currentPoints],timestamp:Date.now()}),this.currentPoints=[];break;}this.isDrawing=false,this.startPoint=null,this.redraw();}promptTextInput(t){let e=prompt("Enter annotation text:");e&&this.addTextAtPosition(t,e);}drawPreview(t){if(this.startPoint)switch(this.currentTool){case "arrow":j(this.ctx,this.startPoint,t,this.color,this.lineWidth);break;case "box":q(this.ctx,this.startPoint,t,this.color,this.lineWidth);break;case "blur":N(this.ctx,this.canvas,this.startPoint,t,this.blurRadius);break;case "freehand":X(this.ctx,this.currentPoints,this.color,this.lineWidth);break;}}redraw(){this.ctx.clearRect(0,0,this.width,this.height),this.screenshotImage&&this.ctx.drawImage(this.screenshotImage,0,0,this.width,this.height);for(let t of this.operations)V(this.ctx,this.canvas,t);}};var ct=0;function C(){return `att_${Date.now()}_${++ct}`}var y=class{constructor(t){this.shadowRoot=t;this.elements=this.createDOM(),this.bindEvents();}elements;attachments=[];visible=false;submitting=false;recording=false;mediaRecorder=null;mediaStream=null;recordedChunks=[];reporterVisible=false;annotationOverlay=null;annotationContainer=null;onSubmit=null;onClose=null;setOnSubmit(t){this.onSubmit=t;}setOnClose(t){this.onClose=t;}show(){this.visible=true,this.elements.root.classList.add("bd-panel--visible"),this.elements.textarea.focus();}hide(){this.visible=false,this.elements.root.classList.remove("bd-panel--visible");}isVisible(){return this.visible}reset(){this.elements.textarea.value="",this.elements.nameInput.value="",this.elements.emailInput.value="",this.revokeAttachmentUrls(),this.attachments=[],this.renderAttachments(),this.showFormView(),this.setSubmitting(false);}setReporterInfo(t,e){this.elements.nameInput.value=t,this.elements.emailInput.value=e;}getElement(){return this.elements.root}destroy(){this.stopRecording(),this.destroyAnnotation(),this.revokeAttachmentUrls(),this.elements.root.remove();}createDOM(){let t=document.createElement("div");t.className="bd-panel",t.innerHTML=`
403
+ `}function H(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2l1.88 1.88"/><path d="M14.12 3.88 16 2"/><path d="M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/><path d="M12 20v-9"/><path d="M6.53 9C4.6 8.8 3 7.1 3 5"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="M22 13h-4"/><path d="M17.2 17c2.1.1 3.8 1.9 3.8 4"/></svg>'}function x(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>'}function j(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>'}function W(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"/><circle cx="12" cy="13" r="3"/></svg>'}function I(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5"/><rect x="2" y="6" width="14" height="12" rx="2"/></svg>'}function O(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m22 2-7 20-4-9-9-4z"/><path d="M22 2 11 13"/></svg>'}function N(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m9 18 6-6-6-6"/></svg>'}function q(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><path d="m9 11 3 3L22 4"/></svg>'}function X(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/></svg>'}function V(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>'}function J(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="6" y="6" width="12" height="12" rx="2"/></svg>'}function Y(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 19L19 5"/><path d="M12 5h7v7"/></svg>'}function K(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/></svg>'}function G(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/></svg>'}function Z(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="4 7 4 4 20 4 20 7"/><line x1="9" y1="20" x2="15" y2="20"/><line x1="12" y1="4" x2="12" y2="20"/></svg>'}function Q(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10" opacity="0.5"/><circle cx="12" cy="12" r="6" opacity="0.3"/><circle cx="12" cy="12" r="2"/></svg>'}function tt(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 7v6h6"/><path d="M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"/></svg>'}function et(){return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg>'}var ht=.85,mt="image/jpeg";async function T(o={}){let{quality:t=ht,target:e=document.documentElement,filter:n}=o,r=window.innerWidth,i=window.innerHeight,s=await ut(e,{width:r,height:i,useCORS:true,allowTaint:false,logging:false,ignoreElements:d=>!!(n&&d instanceof HTMLElement&&!n(d))});return {blob:await new Promise((d,c)=>{s.toBlob(p=>{p?d(p):c(new Error("Screenshot capture failed: no blob produced"));},mt,t);}),width:r,height:i}}var R=Math.PI/6,ft="#ff0000",gt=3,bt=16,vt=10,xt=0;function w(){return `ann_${Date.now()}_${++xt}`}function nt(o,t,e,n,r){let i=Math.atan2(e.y-t.y,e.x-t.x);o.save(),o.strokeStyle=n,o.fillStyle=n,o.lineWidth=r,o.lineCap="round",o.lineJoin="round",o.beginPath(),o.moveTo(t.x,t.y),o.lineTo(e.x,e.y),o.stroke(),o.beginPath(),o.moveTo(e.x,e.y),o.lineTo(e.x-15*Math.cos(i-R),e.y-15*Math.sin(i-R)),o.lineTo(e.x-15*Math.cos(i+R),e.y-15*Math.sin(i+R)),o.closePath(),o.fill(),o.restore();}function ot(o,t,e,n,r){o.save(),o.strokeStyle=n,o.lineWidth=r,o.lineCap="round",o.lineJoin="round",o.strokeRect(t.x,t.y,e.x-t.x,e.y-t.y),o.restore();}function wt(o,t,e,n,r){o.save(),o.font=`${r}px sans-serif`,o.textBaseline="top";let i=4,s=o.measureText(e),l=r*1.2;o.fillStyle="rgba(0, 0, 0, 0.6)",o.fillRect(t.x-i,t.y-i,s.width+i*2,l+i*2),o.fillStyle=n,o.fillText(e,t.x,t.y),o.restore();}function rt(o,t,e,n,r){let i=Math.min(e.x,n.x),s=Math.min(e.y,n.y),l=Math.abs(n.x-e.x),d=Math.abs(n.y-e.y);l===0||d===0||(o.save(),o.filter=`blur(${r}px)`,o.drawImage(t,i,s,l,d,i,s,l,d),o.filter="none",o.strokeStyle="rgba(128, 128, 128, 0.5)",o.lineWidth=1,o.setLineDash([4,4]),o.strokeRect(i,s,l,d),o.setLineDash([]),o.restore());}function it(o,t,e,n){if(t.length<2)return;o.save(),o.strokeStyle=e,o.lineWidth=n,o.lineCap="round",o.lineJoin="round";let r=t[0];o.beginPath(),o.moveTo(r.x,r.y);for(let i=1;i<t.length;i++){let s=t[i];o.lineTo(s.x,s.y);}o.stroke(),o.restore();}function st(o,t,e){switch(e.tool){case "arrow":nt(o,e.start,e.end,e.color,e.lineWidth);break;case "box":ot(o,e.start,e.end,e.color,e.lineWidth);break;case "text":wt(o,e.position,e.text,e.color,e.fontSize);break;case "blur":rt(o,t,e.start,e.end,e.blurRadius);break;case "freehand":it(o,e.points,e.color,e.lineWidth);break}}function E(o,t){for(let e of t)st(o,o.canvas,e);}var g=class{constructor(t,e,n){this.container=t;this.width=e;this.height=n;this.canvas=document.createElement("canvas"),this.canvas.width=e,this.canvas.height=n,this.canvas.style.cssText="position:absolute;top:0;left:0;width:100%;height:100%;cursor:crosshair;touch-action:none;";let r=this.canvas.getContext("2d");if(!r)throw new Error("Failed to get 2D canvas context");this.ctx=r,this.onPointerDownBound=this.onPointerDown.bind(this),this.onPointerMoveBound=this.onPointerMove.bind(this),this.onPointerUpBound=this.onPointerUp.bind(this),this.canvas.addEventListener("pointerdown",this.onPointerDownBound),this.canvas.addEventListener("pointermove",this.onPointerMoveBound),this.canvas.addEventListener("pointerup",this.onPointerUpBound),this.container.appendChild(this.canvas);}canvas;ctx;operations=[];currentTool="arrow";color=ft;lineWidth=gt;fontSize=bt;blurRadius=vt;isDrawing=false;startPoint=null;currentPoints=[];screenshotImage=null;onPointerDownBound;onPointerMoveBound;onPointerUpBound;setScreenshotImage(t){this.screenshotImage=t,this.redraw();}setTool(t){this.currentTool=t;}getTool(){return this.currentTool}setColor(t){this.color=t;}setLineWidth(t){this.lineWidth=t;}setFontSize(t){this.fontSize=t;}setBlurRadius(t){this.blurRadius=t;}getOperations(){return [...this.operations]}getCanvasWidth(){return this.width}getCanvasHeight(){return this.height}undo(){this.operations.pop(),this.redraw();}clear(){this.operations=[],this.redraw();}addTextAtPosition(t,e){let n={id:w(),tool:"text",color:this.color,lineWidth:this.lineWidth,position:t,text:e,fontSize:this.fontSize,timestamp:Date.now()};this.operations.push(n),this.redraw();}destroy(){this.canvas.removeEventListener("pointerdown",this.onPointerDownBound),this.canvas.removeEventListener("pointermove",this.onPointerMoveBound),this.canvas.removeEventListener("pointerup",this.onPointerUpBound),this.canvas.remove();}getCanvasPoint(t){let e=this.canvas.getBoundingClientRect();return {x:(t.clientX-e.left)/e.width*this.width,y:(t.clientY-e.top)/e.height*this.height}}onPointerDown(t){t.preventDefault(),this.canvas.setPointerCapture(t.pointerId);let e=this.getCanvasPoint(t);if(this.startPoint=e,this.currentTool==="text"){this.promptTextInput(e);return}this.isDrawing=true,this.currentTool==="freehand"&&(this.currentPoints=[e]);}onPointerMove(t){if(!this.isDrawing||!this.startPoint)return;t.preventDefault();let e=this.getCanvasPoint(t);this.currentTool==="freehand"&&this.currentPoints.push(e),this.redraw(),this.drawPreview(e);}onPointerUp(t){if(!this.isDrawing||!this.startPoint)return;t.preventDefault();let e=this.getCanvasPoint(t);switch(this.currentTool){case "arrow":this.operations.push({id:w(),tool:"arrow",color:this.color,lineWidth:this.lineWidth,start:this.startPoint,end:e,timestamp:Date.now()});break;case "box":this.operations.push({id:w(),tool:"box",color:this.color,lineWidth:this.lineWidth,start:this.startPoint,end:e,timestamp:Date.now()});break;case "blur":this.operations.push({id:w(),tool:"blur",color:this.color,lineWidth:this.lineWidth,start:this.startPoint,end:e,blurRadius:this.blurRadius,timestamp:Date.now()});break;case "freehand":this.currentPoints.push(e),this.operations.push({id:w(),tool:"freehand",color:this.color,lineWidth:this.lineWidth,points:[...this.currentPoints],timestamp:Date.now()}),this.currentPoints=[];break;}this.isDrawing=false,this.startPoint=null,this.redraw();}promptTextInput(t){let e=prompt("Enter annotation text:");e&&this.addTextAtPosition(t,e);}drawPreview(t){if(this.startPoint)switch(this.currentTool){case "arrow":nt(this.ctx,this.startPoint,t,this.color,this.lineWidth);break;case "box":ot(this.ctx,this.startPoint,t,this.color,this.lineWidth);break;case "blur":rt(this.ctx,this.canvas,this.startPoint,t,this.blurRadius);break;case "freehand":it(this.ctx,this.currentPoints,this.color,this.lineWidth);break;}}redraw(){this.ctx.clearRect(0,0,this.width,this.height),this.screenshotImage&&this.ctx.drawImage(this.screenshotImage,0,0,this.width,this.height);for(let t of this.operations)st(this.ctx,this.canvas,t);}};var yt=10,kt=0;function D(){return `att_${Date.now()}_${++kt}`}var L=class{constructor(t){this.shadowRoot=t;this.elements=this.createDOM(),this.bindEvents();}elements;attachments=[];visible=false;submitting=false;recording=false;mediaRecorder=null;mediaStream=null;recordedChunks=[];reporterVisible=false;annotationOverlay=null;annotationContainer=null;annotationStyleEl=null;onSubmit=null;onClose=null;setOnSubmit(t){this.onSubmit=t;}setOnClose(t){this.onClose=t;}show(){this.visible=true,this.elements.root.classList.add("bd-panel--visible"),this.elements.textarea.focus();}hide(){this.visible=false,this.elements.root.classList.remove("bd-panel--visible");}isVisible(){return this.visible}reset(){this.elements.textarea.value="",this.elements.nameInput.value="",this.elements.emailInput.value="",this.revokeAttachmentUrls(),this.attachments=[],this.renderAttachments(),this.showFormView(),this.setSubmitting(false);}setReporterInfo(t,e){this.elements.nameInput.value=t,this.elements.emailInput.value=e;}getElement(){return this.elements.root}destroy(){this.stopRecording(),this.destroyAnnotation(),this.revokeAttachmentUrls(),this.elements.root.remove();}createDOM(){let t=document.createElement("div");t.className="bd-panel",t.innerHTML=`
473
404
  <div class="bd-panel__header">
474
405
  <span class="bd-panel__title">Report a bug</span>
475
- <button class="bd-panel__close" aria-label="Close">${v()}</button>
406
+ <button class="bd-panel__close" aria-label="Close">${x()}</button>
476
407
  </div>
477
408
  <div class="bd-panel__body" data-role="body">
478
409
  <textarea class="bd-textarea" placeholder="Describe the bug you found..." rows="4"></textarea>
479
410
  <div class="bd-action-bar">
480
- <button class="bd-action-btn" data-action="attach">${I()} Attach</button>
481
- <button class="bd-action-btn" data-action="screenshot">${A()} Screenshot</button>
482
- <button class="bd-action-btn" data-action="record">${E()} Record</button>
411
+ <button class="bd-action-btn" data-action="attach">${j()} Attach</button>
412
+ <button class="bd-action-btn" data-action="screenshot">${W()} Screenshot</button>
413
+ <button class="bd-action-btn" data-action="record">${I()} Record</button>
483
414
  </div>
484
415
  <div class="bd-attachments" data-role="attachments"></div>
485
416
  <button class="bd-reporter-toggle" data-action="toggle-reporter">
486
- ${$()} Reporter info
417
+ ${N()} Reporter info
487
418
  </button>
488
419
  <div class="bd-reporter-fields" data-role="reporter-fields">
489
420
  <input class="bd-input" type="text" placeholder="Your name" data-role="name" />
@@ -492,26 +423,224 @@ import {record}from'@rrweb/record';import {toBlob}from'html-to-image';var K="htt
492
423
  <input class="bd-file-input" type="file" multiple data-role="file-input" />
493
424
  </div>
494
425
  <div class="bd-success" data-role="success" style="display:none">
495
- ${U()}
426
+ ${q()}
496
427
  <div class="bd-success__title">Bug report sent!</div>
497
428
  <div class="bd-success__subtitle">Thank you for your feedback.</div>
498
429
  </div>
499
430
  <div class="bd-panel__footer">
500
- <button class="bd-send-btn" data-action="send">${L()} Send report</button>
431
+ <button class="bd-send-btn" data-action="send">${O()} Send report</button>
432
+ </div>
433
+ `;let e=r=>t.querySelector(r);return {root:t,textarea:e(".bd-textarea"),nameInput:e('[data-role="name"]'),emailInput:e('[data-role="email"]'),sendBtn:e('[data-action="send"]'),screenshotBtn:e('[data-action="screenshot"]'),recordBtn:e('[data-action="record"]'),attachBtn:e('[data-action="attach"]'),fileInput:e('[data-role="file-input"]'),attachmentsList:e('[data-role="attachments"]'),reporterToggle:e('[data-action="toggle-reporter"]'),reporterFields:e('[data-role="reporter-fields"]'),body:e('[data-role="body"]'),successView:e('[data-role="success"]')}}bindEvents(){this.elements.root.querySelector(".bd-panel__close").addEventListener("click",()=>this.handleClose()),this.elements.sendBtn.addEventListener("click",()=>this.handleSubmit()),this.elements.screenshotBtn.addEventListener("click",()=>this.handleScreenshot()),this.elements.recordBtn.addEventListener("click",()=>this.handleRecord()),this.elements.attachBtn.addEventListener("click",()=>this.elements.fileInput.click()),this.elements.fileInput.addEventListener("change",()=>this.handleFileSelect()),this.elements.reporterToggle.addEventListener("click",()=>this.toggleReporter()),this.elements.attachmentsList.addEventListener("click",e=>{let r=e.target.closest("[data-remove-id]");if(r){let i=r.dataset.removeId;this.removeAttachment(i);}});}handleClose(){this.onClose?.();}async handleSubmit(){let t=this.elements.textarea.value.trim();if(!t){this.elements.textarea.focus();return}if(!(this.submitting||!this.onSubmit)){this.setSubmitting(true);try{await this.onSubmit({description:t,reporterName:this.elements.nameInput.value.trim(),reporterEmail:this.elements.emailInput.value.trim(),attachments:[...this.attachments]}),this.showSuccessView(),setTimeout(()=>{this.reset(),this.handleClose();},2e3);}catch{this.setSubmitting(false);}}}async handleScreenshot(){this.elements.screenshotBtn.disabled=true;let t=this.elements.screenshotBtn.innerHTML;this.elements.screenshotBtn.innerHTML='<span class="bd-spinner"></span> Capturing...';try{this.hide(),await St(50);let e=await T({filter:i=>!(i instanceof HTMLElement&&i.tagName.toLowerCase()==="bugdump-widget")}),n=URL.createObjectURL(e.blob),r=await Tt(n);this.showAnnotationOverlay(r,e.blob,e.width,e.height);}catch(e){console.warn("[Bugdump] Screenshot capture failed:",e),this.show();}finally{this.elements.screenshotBtn.disabled=false,this.elements.screenshotBtn.innerHTML=t;}}showAnnotationOverlay(t,e,n,r){this.annotationStyleEl=document.createElement("style"),this.annotationStyleEl.textContent=Et(),document.head.appendChild(this.annotationStyleEl),this.annotationContainer=document.createElement("div"),this.annotationContainer.className="bd-annotation-overlay";let i=document.createElement("div");i.className="bd-annotation-toolbar",i.innerHTML=`
434
+ <div class="bd-annotation-toolbar__group">
435
+ <button class="bd-annotation-tool-btn active" data-tool="arrow" title="Arrow">${Y()}</button>
436
+ <button class="bd-annotation-tool-btn" data-tool="box" title="Rectangle">${K()}</button>
437
+ <button class="bd-annotation-tool-btn" data-tool="freehand" title="Draw">${G()}</button>
438
+ <button class="bd-annotation-tool-btn" data-tool="text" title="Text">${Z()}</button>
439
+ <button class="bd-annotation-tool-btn" data-tool="blur" title="Blur">${Q()}</button>
440
+ </div>
441
+ <div class="bd-annotation-toolbar__colors">
442
+ <button class="bd-annotation-color-btn active" data-color="#ff0000" style="background:#ff0000" title="Red"></button>
443
+ <button class="bd-annotation-color-btn" data-color="#ffcc00" style="background:#ffcc00" title="Yellow"></button>
444
+ <button class="bd-annotation-color-btn" data-color="#00cc44" style="background:#00cc44" title="Green"></button>
445
+ <button class="bd-annotation-color-btn" data-color="#0099ff" style="background:#0099ff" title="Blue"></button>
446
+ <button class="bd-annotation-color-btn" data-color="#ffffff" style="background:#ffffff" title="White"></button>
501
447
  </div>
502
- `;let e=r=>t.querySelector(r);return {root:t,textarea:e(".bd-textarea"),nameInput:e('[data-role="name"]'),emailInput:e('[data-role="email"]'),sendBtn:e('[data-action="send"]'),screenshotBtn:e('[data-action="screenshot"]'),recordBtn:e('[data-action="record"]'),attachBtn:e('[data-action="attach"]'),fileInput:e('[data-role="file-input"]'),attachmentsList:e('[data-role="attachments"]'),reporterToggle:e('[data-action="toggle-reporter"]'),reporterFields:e('[data-role="reporter-fields"]'),body:e('[data-role="body"]'),successView:e('[data-role="success"]')}}bindEvents(){this.elements.root.querySelector(".bd-panel__close").addEventListener("click",()=>this.handleClose()),this.elements.sendBtn.addEventListener("click",()=>this.handleSubmit()),this.elements.screenshotBtn.addEventListener("click",()=>this.handleScreenshot()),this.elements.recordBtn.addEventListener("click",()=>this.handleRecord()),this.elements.attachBtn.addEventListener("click",()=>this.elements.fileInput.click()),this.elements.fileInput.addEventListener("change",()=>this.handleFileSelect()),this.elements.reporterToggle.addEventListener("click",()=>this.toggleReporter()),this.elements.attachmentsList.addEventListener("click",e=>{let r=e.target.closest("[data-remove-id]");if(r){let i=r.dataset.removeId;this.removeAttachment(i);}});}handleClose(){this.onClose?.();}async handleSubmit(){let t=this.elements.textarea.value.trim();if(!t){this.elements.textarea.focus();return}if(!(this.submitting||!this.onSubmit)){this.setSubmitting(true);try{await this.onSubmit({description:t,reporterName:this.elements.nameInput.value.trim(),reporterEmail:this.elements.emailInput.value.trim(),attachments:[...this.attachments]}),this.showSuccessView(),setTimeout(()=>{this.reset(),this.handleClose();},2e3);}catch{this.setSubmitting(false);}}}async handleScreenshot(){this.elements.screenshotBtn.disabled=true;try{this.hide(),await ht(100);let t=await x({filter:r=>!(r instanceof HTMLElement&&r.tagName.toLowerCase()==="bugdump-widget")}),e=URL.createObjectURL(t.blob),o=await ut(e);this.showAnnotationOverlay(o,t.blob,t.width,t.height);}catch{this.show();}finally{this.elements.screenshotBtn.disabled=false;}}showAnnotationOverlay(t,e,o,r){this.annotationContainer=document.createElement("div"),this.annotationContainer.className="bd-annotation-overlay";let i=document.createElement("div");i.className="bd-annotation-toolbar",i.innerHTML=`
503
- <button class="active" data-tool="arrow">Arrow</button>
504
- <button data-tool="box">Box</button>
505
- <button data-tool="freehand">Draw</button>
506
- <button data-tool="text">Text</button>
507
- <button data-tool="blur">Blur</button>
508
448
  <div class="bd-annotation-toolbar__spacer"></div>
509
- <button data-annotation-action="undo">Undo</button>
510
- <button class="bd-annotation-toolbar__cancel" data-annotation-action="cancel">Cancel</button>
511
- <button class="bd-annotation-toolbar__confirm" data-annotation-action="confirm">Done</button>
512
- `;let a=document.createElement("div");a.className="bd-annotation-canvas-wrap",this.annotationContainer.appendChild(i),this.annotationContainer.appendChild(a),document.body.appendChild(this.annotationContainer),this.annotationOverlay=new c(a,o,r),this.annotationOverlay.setScreenshotImage(t),i.addEventListener("click",l=>{let p=l.target.closest("button");if(!p)return;let M=p.dataset.tool;if(M){this.annotationOverlay?.setTool(M),i.querySelectorAll("[data-tool]").forEach(G=>G.classList.remove("active")),p.classList.add("active");return}let T=p.dataset.annotationAction;T==="undo"?this.annotationOverlay?.undo():T==="cancel"?(URL.revokeObjectURL(t.src),this.destroyAnnotation(),this.show()):T==="confirm"&&this.finishAnnotation(e,t);});}finishAnnotation(t,e){let o=this.annotationOverlay?.getOperations()??[],r=URL.createObjectURL(t);this.addAttachment({id:C(),type:"screenshot",blob:t,name:`screenshot-${Date.now()}.jpg`,thumbnailUrl:r,annotations:o.length>0?o:void 0}),URL.revokeObjectURL(e.src),this.destroyAnnotation(),this.show();}destroyAnnotation(){this.annotationOverlay?.destroy(),this.annotationOverlay=null,this.annotationContainer?.remove(),this.annotationContainer=null;}async handleRecord(){if(this.recording){this.stopRecording();return}try{this.mediaStream=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1}),this.recordedChunks=[],this.mediaRecorder=new MediaRecorder(this.mediaStream,{mimeType:mt()}),this.mediaRecorder.ondataavailable=t=>{t.data.size>0&&this.recordedChunks.push(t.data);},this.mediaRecorder.onstop=()=>{let t=new Blob(this.recordedChunks,{type:this.mediaRecorder?.mimeType||"video/webm"}),e=URL.createObjectURL(t);this.addAttachment({id:C(),type:"recording",blob:t,name:`recording-${Date.now()}.webm`,thumbnailUrl:e}),this.cleanupMediaStream(),this.setRecordingState(!1);},this.mediaStream.getVideoTracks()[0]?.addEventListener("ended",()=>{this.stopRecording();}),this.mediaRecorder.start(),this.setRecordingState(!0);}catch{this.cleanupMediaStream(),this.setRecordingState(false);}}stopRecording(){this.mediaRecorder&&this.mediaRecorder.state!=="inactive"&&this.mediaRecorder.stop(),this.cleanupMediaStream();}cleanupMediaStream(){this.mediaStream&&(this.mediaStream.getTracks().forEach(t=>t.stop()),this.mediaStream=null);}setRecordingState(t){this.recording=t,t?(this.elements.recordBtn.innerHTML=`${F()} Stop`,this.elements.recordBtn.style.color="#ef4444"):(this.elements.recordBtn.innerHTML=`${E()} Record`,this.elements.recordBtn.style.color="");}handleFileSelect(){let t=this.elements.fileInput.files;if(t){for(let e=0;e<t.length;e++){let o=t[e],i=o.type.startsWith("image/")?URL.createObjectURL(o):void 0;this.addAttachment({id:C(),type:"file",blob:o,name:o.name,thumbnailUrl:i});}this.elements.fileInput.value="";}}addAttachment(t){this.attachments.push(t),this.renderAttachments();}removeAttachment(t){let e=this.attachments.findIndex(r=>r.id===t);if(e===-1)return;let o=this.attachments[e];o.thumbnailUrl&&URL.revokeObjectURL(o.thumbnailUrl),this.attachments.splice(e,1),this.renderAttachments();}renderAttachments(){let t=this.elements.attachmentsList;if(t.innerHTML="",this.attachments.length===0){t.style.display="none";return}t.style.display="flex";for(let e of this.attachments){let o=document.createElement("div");o.className="bd-attachment";let r;e.thumbnailUrl&&e.type!=="recording"?r=`<img src="${e.thumbnailUrl}" alt="${e.name}" />`:e.type==="recording"&&e.thumbnailUrl?r=`<video src="${e.thumbnailUrl}" muted></video>`:r=`<div class="bd-attachment__icon">${z()}</div>`,o.innerHTML=`
449
+ <button class="bd-annotation-action-btn" data-annotation-action="undo" title="Undo">${tt()}</button>
450
+ <div class="bd-annotation-toolbar__divider"></div>
451
+ <button class="bd-annotation-toolbar__cancel" data-annotation-action="cancel">${x()} Cancel</button>
452
+ <button class="bd-annotation-toolbar__confirm" data-annotation-action="confirm">${et()} Done</button>
453
+ `;let s=document.createElement("div");s.className="bd-annotation-canvas-wrap",this.annotationContainer.appendChild(i),this.annotationContainer.appendChild(s),document.body.appendChild(this.annotationContainer),this.annotationOverlay=new g(s,n,r),this.annotationOverlay.setScreenshotImage(t),i.addEventListener("click",l=>{let c=l.target.closest("button");if(!c)return;let p=c.dataset.tool;if(p){this.annotationOverlay?.setTool(p),i.querySelectorAll("[data-tool]").forEach(m=>m.classList.remove("active")),c.classList.add("active");return}let h=c.dataset.color;if(h){this.annotationOverlay?.setColor(h),i.querySelectorAll("[data-color]").forEach(m=>m.classList.remove("active")),c.classList.add("active");return}let u=c.dataset.annotationAction;u==="undo"?this.annotationOverlay?.undo():u==="cancel"?(URL.revokeObjectURL(t.src),this.destroyAnnotation(),this.show()):u==="confirm"&&this.finishAnnotation(e,t);});}async finishAnnotation(t,e){let n=this.annotationOverlay?.getOperations()??[],r,i;if(n.length>0){let l=document.createElement("canvas");l.width=e.naturalWidth,l.height=e.naturalHeight;let d=l.getContext("2d");d.drawImage(e,0,0);let c=e.naturalWidth/this.annotationOverlay.getCanvasWidth(),p=e.naturalHeight/this.annotationOverlay.getCanvasHeight();d.save(),d.scale(c,p),E(d,n),d.restore(),r=await new Promise(u=>{l.toBlob(m=>u(m),"image/jpeg",.92);});let h=n.filter(u=>u.tool==="text");h.length>0&&(i=h.map(u=>({text:u.text,x:Math.round(u.position.x),y:Math.round(u.position.y)})));}else r=t;let s=URL.createObjectURL(r);this.addAttachment({id:D(),type:"screenshot",blob:r,name:`screenshot-${Date.now()}.jpg`,thumbnailUrl:s,textAnnotations:i}),URL.revokeObjectURL(e.src),this.destroyAnnotation(),this.show();}destroyAnnotation(){this.annotationOverlay?.destroy(),this.annotationOverlay=null,this.annotationContainer?.remove(),this.annotationContainer=null,this.annotationStyleEl?.remove(),this.annotationStyleEl=null;}async handleRecord(){if(this.recording){this.stopRecording();return}try{this.mediaStream=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!1,preferCurrentTab:!0}),this.recordedChunks=[],this.mediaRecorder=new MediaRecorder(this.mediaStream,{mimeType:Rt()}),this.mediaRecorder.ondataavailable=t=>{t.data.size>0&&this.recordedChunks.push(t.data);},this.mediaRecorder.onstop=()=>{let t=new Blob(this.recordedChunks,{type:this.mediaRecorder?.mimeType||"video/webm"}),e=URL.createObjectURL(t);this.addAttachment({id:D(),type:"recording",blob:t,name:`recording-${Date.now()}.webm`,thumbnailUrl:e}),this.cleanupMediaStream(),this.setRecordingState(!1);},this.mediaStream.getVideoTracks()[0]?.addEventListener("ended",()=>{this.stopRecording();}),this.mediaRecorder.start(),this.setRecordingState(!0);}catch{this.cleanupMediaStream(),this.setRecordingState(false);}}stopRecording(){this.mediaRecorder&&this.mediaRecorder.state!=="inactive"&&this.mediaRecorder.stop(),this.cleanupMediaStream();}cleanupMediaStream(){this.mediaStream&&(this.mediaStream.getTracks().forEach(t=>t.stop()),this.mediaStream=null);}setRecordingState(t){this.recording=t,t?(this.elements.recordBtn.innerHTML=`${J()} Stop`,this.elements.recordBtn.style.color="#ef4444"):(this.elements.recordBtn.innerHTML=`${I()} Record`,this.elements.recordBtn.style.color="");}handleFileSelect(){let t=this.elements.fileInput.files;if(t){for(let e=0;e<t.length;e++){let n=t[e],i=n.type.startsWith("image/")?URL.createObjectURL(n):void 0;this.addAttachment({id:D(),type:"file",blob:n,name:n.name,thumbnailUrl:i});}this.elements.fileInput.value="";}}addAttachment(t){this.attachments.length>=yt||(this.attachments.push(t),this.renderAttachments());}removeAttachment(t){let e=this.attachments.findIndex(r=>r.id===t);if(e===-1)return;let n=this.attachments[e];n.thumbnailUrl&&URL.revokeObjectURL(n.thumbnailUrl),this.attachments.splice(e,1),this.renderAttachments();}renderAttachments(){let t=this.elements.attachmentsList;if(t.innerHTML="",this.attachments.length===0){t.style.display="none";return}t.style.display="flex";for(let e of this.attachments){let n=document.createElement("div");n.className="bd-attachment";let r;e.thumbnailUrl&&e.type!=="recording"?r=`<img src="${e.thumbnailUrl}" alt="${e.name}" />`:e.type==="recording"&&e.thumbnailUrl?r=`<video src="${e.thumbnailUrl}" muted></video>`:r=`<div class="bd-attachment__icon">${X()}</div>`,n.innerHTML=`
513
454
  ${r}
514
455
  <button class="bd-attachment__remove" data-remove-id="${e.id}" aria-label="Remove">
515
- ${W()}
456
+ ${V()}
516
457
  </button>
517
- `,t.appendChild(o);}}toggleReporter(){this.reporterVisible=!this.reporterVisible,this.elements.reporterToggle.classList.toggle("bd-reporter-toggle--open",this.reporterVisible),this.elements.reporterFields.classList.toggle("bd-reporter-fields--visible",this.reporterVisible);}setSubmitting(t){this.submitting=t,this.elements.sendBtn.disabled=t,t?this.elements.sendBtn.innerHTML='<span class="bd-spinner"></span> Sending...':this.elements.sendBtn.innerHTML=`${L()} Send report`;}showSuccessView(){this.elements.body.style.display="none",this.elements.successView.style.display="flex";let t=this.elements.root.querySelector(".bd-panel__footer");t.style.display="none";}showFormView(){this.elements.body.style.display="flex",this.elements.successView.style.display="none";let t=this.elements.root.querySelector(".bd-panel__footer");t.style.display="flex";}revokeAttachmentUrls(){for(let t of this.attachments)t.thumbnailUrl&&URL.revokeObjectURL(t.thumbnailUrl);}};function ht(n){return new Promise(t=>setTimeout(t,n))}function ut(n){return new Promise((t,e)=>{let o=new Image;o.onload=()=>t(o),o.onerror=e,o.src=n;})}function mt(){let n=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm","video/mp4"];for(let t of n)if(MediaRecorder.isTypeSupported(t))return t;return "video/webm"}var R=class{host;shadowRoot;triggerBtn;panel;open=false;onSubmit=null;constructor(){this.host=document.createElement("bugdump-widget"),this.host.style.cssText="all:initial;position:fixed;z-index:2147483647;",this.shadowRoot=this.host.attachShadow({mode:"closed"});let t=document.createElement("style");t.textContent=O(),this.shadowRoot.appendChild(t),this.triggerBtn=this.createTriggerButton(),this.shadowRoot.appendChild(this.triggerBtn),this.panel=new y(this.shadowRoot),this.shadowRoot.appendChild(this.panel.getElement()),this.panel.setOnClose(()=>this.close()),document.body.appendChild(this.host);}setOnSubmit(t){this.onSubmit=t,this.panel.setOnSubmit(t);}setReporterInfo(t,e){this.panel.setReporterInfo(t,e);}toggle(){this.open?this.close():this.openPanel();}openPanel(){this.open||(this.open=true,this.triggerBtn.classList.add("bd-trigger--open"),this.triggerBtn.innerHTML=v(),this.panel.show());}close(){this.open&&(this.open=false,this.triggerBtn.classList.remove("bd-trigger--open"),this.triggerBtn.innerHTML=S(),this.panel.hide());}isOpen(){return this.open}destroy(){this.panel.destroy(),this.host.remove();}createTriggerButton(){let t=document.createElement("button");return t.className="bd-trigger",t.setAttribute("aria-label","Report a bug"),t.innerHTML=S(),t.addEventListener("click",()=>this.toggle()),t}};var P=class n{static instance=null;state;httpClient=null;consoleCollector;networkCollector;sessionReplayCollector;widget=null;constructor(){this.state=k(),this.consoleCollector=new f,this.networkCollector=new g,this.sessionReplayCollector=new b;}static init(t){if(n.instance)return n.instance;let e=new n,o=H(t);return e.state.config=o,e.state.initialized=true,e.httpClient=new m(o.endpoint,o.projectKey),e.consoleCollector.start(),e.networkCollector.start(),e.sessionReplayCollector.start(),e.mountWidget(),n.instance=e,e}static getInstance(){return n.instance}identify(t){this.ensureInitialized(),this.state.user=t,this.widget&&this.widget.setReporterInfo(t.name||"",t.email||"");}setContext(t){this.ensureInitialized(),this.state.customContext={...this.state.customContext,...t};}open(){this.ensureInitialized(),this.state.widgetOpen=true,this.widget?.openPanel();}close(){this.ensureInitialized(),this.state.widgetOpen=false,this.widget?.close();}collectTelemetry(){return this.ensureInitialized(),{consoleLogs:this.consoleCollector.flush(),networkRequests:this.networkCollector.flush(),sessionReplayEvents:this.sessionReplayCollector.flush(),performance:_(),metadata:D()}}destroy(){this.widget?.destroy(),this.widget=null,this.consoleCollector.stop(),this.networkCollector.stop(),this.sessionReplayCollector.stop(),this.state=k(),this.httpClient=null,n.instance=null;}getConfig(){return this.state.config}getUser(){return this.state.user}getContext(){return this.state.customContext}getHttpClient(){return this.ensureInitialized(),this.httpClient}isWidgetOpen(){return this.state.widgetOpen}mountWidget(){typeof document>"u"||(this.widget=new R,this.widget.setOnSubmit(t=>this.handleSubmit(t)));}async handleSubmit(t){let e=this.httpClient,o=this.collectTelemetry(),r=o.metadata,i=[];for(let l of t.attachments){let d=await e.requestUpload({originalName:l.name,mimeType:l.blob.type,size:l.blob.size});await e.uploadFileToS3(d.url,d.fields,l.blob);let p=l.type==="file"?"screenshot":l.type;i.push({fileId:d.fileId,type:p,metadata:l.annotations?{annotations:l.annotations}:void 0});}let a={description:t.description,reporterName:t.reporterName||this.state.user?.name||void 0,reporterEmail:t.reporterEmail||this.state.user?.email||void 0,reporterExternalId:this.state.user?.id||void 0,pageUrl:r.url,referrerUrl:r.referrer||void 0,userAgent:r.userAgent,viewport:r.viewport,consoleLogs:o.consoleLogs,networkRequests:o.networkRequests,performance:o.performance,customContext:Object.keys(this.state.customContext).length>0?this.state.customContext:void 0,attachments:i.length>0?i:void 0};await e.submitReport(a);}ensureInitialized(){if(!this.state.initialized)throw new Error("Bugdump SDK is not initialized. Call Bugdump.init() first.")}};export{c as AnnotationOverlay,P as Bugdump,h as BugdumpApiError,x as captureScreenshot,J as renderOperationsToCanvas};
458
+ `,t.appendChild(n);}}toggleReporter(){this.reporterVisible=!this.reporterVisible,this.elements.reporterToggle.classList.toggle("bd-reporter-toggle--open",this.reporterVisible),this.elements.reporterFields.classList.toggle("bd-reporter-fields--visible",this.reporterVisible);}setUploadProgress(t,e,n){if(e===0)return;let r=Math.round((t-1+n/100)/e*100);this.elements.sendBtn.innerHTML=`<span class="bd-spinner"></span> Uploading ${t}/${e}\u2026 ${r}%`;}setSubmitting(t){this.submitting=t,this.elements.sendBtn.disabled=t,t?this.elements.sendBtn.innerHTML='<span class="bd-spinner"></span> Sending...':this.elements.sendBtn.innerHTML=`${O()} Send report`;}showSuccessView(){this.elements.body.style.display="none",this.elements.successView.style.display="flex";let t=this.elements.root.querySelector(".bd-panel__footer");t.style.display="none";}showFormView(){this.elements.body.style.display="flex",this.elements.successView.style.display="none";let t=this.elements.root.querySelector(".bd-panel__footer");t.style.display="flex";}revokeAttachmentUrls(){for(let t of this.attachments)t.thumbnailUrl&&URL.revokeObjectURL(t.thumbnailUrl);}};function St(o){return new Promise(t=>setTimeout(t,o))}function Tt(o){return new Promise((t,e)=>{let n=new Image;n.onload=()=>t(n),n.onerror=e,n.src=o;})}function Rt(){let o=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm","video/mp4"];for(let t of o)if(MediaRecorder.isTypeSupported(t))return t;return "video/webm"}function Et(){return `
459
+ .bd-annotation-overlay {
460
+ position: fixed;
461
+ top: 0;
462
+ left: 0;
463
+ width: 100%;
464
+ height: 100%;
465
+ z-index: 2147483647;
466
+ background: rgba(0, 0, 0, 0.6);
467
+ display: flex;
468
+ flex-direction: column;
469
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
470
+ }
471
+
472
+ .bd-annotation-toolbar {
473
+ display: flex;
474
+ align-items: center;
475
+ gap: 8px;
476
+ padding: 8px 16px;
477
+ background: #1a1a2e;
478
+ border-bottom: 1px solid rgba(255, 255, 255, 0.1);
479
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
480
+ }
481
+
482
+ .bd-annotation-toolbar__group {
483
+ display: flex;
484
+ align-items: center;
485
+ gap: 2px;
486
+ background: rgba(255, 255, 255, 0.06);
487
+ border-radius: 8px;
488
+ padding: 3px;
489
+ }
490
+
491
+ .bd-annotation-tool-btn {
492
+ display: flex;
493
+ align-items: center;
494
+ justify-content: center;
495
+ width: 36px;
496
+ height: 36px;
497
+ padding: 0;
498
+ background: transparent;
499
+ color: rgba(255, 255, 255, 0.7);
500
+ border: 2px solid transparent;
501
+ border-radius: 6px;
502
+ cursor: pointer;
503
+ transition: all 0.15s ease;
504
+ }
505
+
506
+ .bd-annotation-tool-btn svg {
507
+ width: 18px;
508
+ height: 18px;
509
+ }
510
+
511
+ .bd-annotation-tool-btn:hover {
512
+ color: #ffffff;
513
+ background: rgba(255, 255, 255, 0.1);
514
+ }
515
+
516
+ .bd-annotation-tool-btn.active {
517
+ color: #ffffff;
518
+ background: rgba(99, 102, 241, 0.5);
519
+ border-color: rgba(99, 102, 241, 0.8);
520
+ }
521
+
522
+ .bd-annotation-toolbar__colors {
523
+ display: flex;
524
+ align-items: center;
525
+ gap: 4px;
526
+ padding: 0 8px;
527
+ }
528
+
529
+ .bd-annotation-color-btn {
530
+ width: 20px;
531
+ height: 20px;
532
+ border-radius: 50%;
533
+ border: 2px solid rgba(255, 255, 255, 0.2);
534
+ cursor: pointer;
535
+ padding: 0;
536
+ transition: transform 0.15s ease, border-color 0.15s ease;
537
+ }
538
+
539
+ .bd-annotation-color-btn:hover {
540
+ transform: scale(1.2);
541
+ border-color: rgba(255, 255, 255, 0.5);
542
+ }
543
+
544
+ .bd-annotation-color-btn.active {
545
+ border-color: #ffffff;
546
+ transform: scale(1.15);
547
+ box-shadow: 0 0 6px rgba(255, 255, 255, 0.3);
548
+ }
549
+
550
+ .bd-annotation-toolbar__spacer {
551
+ flex: 1;
552
+ }
553
+
554
+ .bd-annotation-action-btn {
555
+ display: flex;
556
+ align-items: center;
557
+ justify-content: center;
558
+ width: 36px;
559
+ height: 36px;
560
+ padding: 0;
561
+ background: transparent;
562
+ color: rgba(255, 255, 255, 0.7);
563
+ border: 1px solid transparent;
564
+ border-radius: 6px;
565
+ cursor: pointer;
566
+ transition: all 0.15s ease;
567
+ }
568
+
569
+ .bd-annotation-action-btn svg {
570
+ width: 18px;
571
+ height: 18px;
572
+ }
573
+
574
+ .bd-annotation-action-btn:hover {
575
+ color: #ffffff;
576
+ background: rgba(255, 255, 255, 0.1);
577
+ }
578
+
579
+ .bd-annotation-toolbar__divider {
580
+ width: 1px;
581
+ height: 24px;
582
+ background: rgba(255, 255, 255, 0.15);
583
+ margin: 0 4px;
584
+ }
585
+
586
+ .bd-annotation-toolbar__cancel {
587
+ display: inline-flex;
588
+ align-items: center;
589
+ gap: 6px;
590
+ padding: 7px 14px;
591
+ background: transparent;
592
+ color: rgba(255, 255, 255, 0.6);
593
+ border: 1px solid rgba(255, 255, 255, 0.15);
594
+ border-radius: 6px;
595
+ font-size: 13px;
596
+ font-weight: 500;
597
+ font-family: inherit;
598
+ cursor: pointer;
599
+ transition: all 0.15s ease;
600
+ }
601
+
602
+ .bd-annotation-toolbar__cancel svg {
603
+ width: 14px;
604
+ height: 14px;
605
+ }
606
+
607
+ .bd-annotation-toolbar__cancel:hover {
608
+ color: #ffffff;
609
+ background: rgba(255, 255, 255, 0.08);
610
+ border-color: rgba(255, 255, 255, 0.3);
611
+ }
612
+
613
+ .bd-annotation-toolbar__confirm {
614
+ display: inline-flex;
615
+ align-items: center;
616
+ gap: 6px;
617
+ padding: 7px 16px;
618
+ background: #22c55e;
619
+ color: #ffffff;
620
+ border: none;
621
+ border-radius: 6px;
622
+ font-size: 13px;
623
+ font-weight: 600;
624
+ font-family: inherit;
625
+ cursor: pointer;
626
+ transition: background-color 0.15s ease;
627
+ }
628
+
629
+ .bd-annotation-toolbar__confirm svg {
630
+ width: 14px;
631
+ height: 14px;
632
+ }
633
+
634
+ .bd-annotation-toolbar__confirm:hover {
635
+ background: #16a34a;
636
+ }
637
+
638
+ .bd-annotation-canvas-wrap {
639
+ flex: 1;
640
+ display: flex;
641
+ align-items: center;
642
+ justify-content: center;
643
+ overflow: hidden;
644
+ position: relative;
645
+ }
646
+ `}var B=class{host;shadowRoot;triggerBtn;panel;open=false;onSubmit=null;constructor(t){this.host=document.createElement("bugdump-widget"),this.host.style.cssText="all:initial;position:fixed;z-index:2147483647;",this.shadowRoot=this.host.attachShadow({mode:"closed"});let e=document.createElement("style");e.textContent=F(),this.shadowRoot.appendChild(e),this.triggerBtn=this.createTriggerButton(),t?.hideButton&&(this.triggerBtn.style.display="none"),this.shadowRoot.appendChild(this.triggerBtn),this.panel=new L(this.shadowRoot),this.shadowRoot.appendChild(this.panel.getElement()),this.panel.setOnClose(()=>this.close()),document.body.appendChild(this.host);}setOnSubmit(t){this.onSubmit=t,this.panel.setOnSubmit(t);}setReporterInfo(t,e){this.panel.setReporterInfo(t,e);}setUploadProgress(t,e,n){this.panel.setUploadProgress(t,e,n);}toggle(){this.open?this.close():this.openPanel();}openPanel(){this.open||(this.open=true,this.triggerBtn.classList.add("bd-trigger--open"),this.triggerBtn.innerHTML=x(),this.panel.show());}close(){this.open&&(this.open=false,this.triggerBtn.classList.remove("bd-trigger--open"),this.triggerBtn.innerHTML=H(),this.panel.hide());}isOpen(){return this.open}destroy(){this.panel.destroy(),this.host.remove();}createTriggerButton(){let t=document.createElement("button");return t.className="bd-trigger",t.setAttribute("aria-label","Report a bug"),t.innerHTML=H(),t.addEventListener("click",()=>this.toggle()),t}};var C=class o{static instance=null;state;httpClient=null;consoleCollector;networkCollector;sessionReplayCollector;widget=null;constructor(){this.state=M(),this.consoleCollector=new k,this.networkCollector=new b,this.sessionReplayCollector=new S;}static init(t){if(o.instance)return o.instance;let e=new o,n=A(t);return e.state.config=n,e.state.initialized=true,e.httpClient=new y(n.endpoint,n.projectKey),e.networkCollector=new b({captureBodies:n.captureNetworkBodies}),e.consoleCollector.start(),e.networkCollector.start(),e.sessionReplayCollector.start(),e.mountWidget(),o.instance=e,e}static getInstance(){return o.instance}identify(t){this.ensureInitialized(),this.state.user=t,this.widget&&this.widget.setReporterInfo(t.name||"",t.email||"");}setContext(t){this.ensureInitialized(),this.state.customContext={...this.state.customContext,...t};}open(){this.ensureInitialized(),this.state.widgetOpen=true,this.widget?.openPanel();}close(){this.ensureInitialized(),this.state.widgetOpen=false,this.widget?.close();}collectTelemetry(){return this.ensureInitialized(),{consoleLogs:this.consoleCollector.flush(),networkRequests:this.networkCollector.flush(),sessionReplayEvents:this.sessionReplayCollector.flush(),performance:U(),metadata:z()}}destroy(){this.widget?.destroy(),this.widget=null,this.consoleCollector.stop(),this.networkCollector.stop(),this.sessionReplayCollector.stop(),this.state=M(),this.httpClient=null,o.instance=null;}getConfig(){return this.state.config}getUser(){return this.state.user}getContext(){return this.state.customContext}getHttpClient(){return this.ensureInitialized(),this.httpClient}isWidgetOpen(){return this.state.widgetOpen}mountWidget(){typeof document>"u"||(this.widget=new B({hideButton:this.state.config?.hideButton}),this.widget.setOnSubmit(t=>this.handleSubmit(t)));}async handleSubmit(t){let e=this.httpClient,n=this.collectTelemetry(),r=n.metadata,i=[],s=n.sessionReplayEvents.length>0,l=t.attachments.length+(s?1:0),d=0;for(let p of t.attachments){d++;let h=d,u=await e.requestUpload({originalName:p.name,mimeType:p.blob.type,size:p.blob.size});await e.uploadFileToS3(u.url,u.fields,p.blob,at=>{this.widget?.setUploadProgress(h,l,at);});let m=p.type==="file"?"screenshot":p.type;i.push({fileId:u.fileId,type:m,metadata:p.textAnnotations?{textAnnotations:p.textAnnotations}:void 0});}if(s){d++;let p=d,h=new Blob([JSON.stringify(n.sessionReplayEvents)],{type:"application/json"}),u=await e.requestUpload({originalName:`session-replay-${Date.now()}.json`,mimeType:"application/json",size:h.size});await e.uploadFileToS3(u.url,u.fields,h,m=>{this.widget?.setUploadProgress(p,l,m);}),i.push({fileId:u.fileId,type:"session_replay"});}let c={description:t.description,reporterName:t.reporterName||this.state.user?.name||void 0,reporterEmail:t.reporterEmail||this.state.user?.email||void 0,reporterExternalId:this.state.user?.id||void 0,pageUrl:r.url,referrerUrl:r.referrer||void 0,userAgent:r.userAgent,viewport:r.viewport,consoleLogs:n.consoleLogs,networkRequests:n.networkRequests,performance:n.performance,customContext:Object.keys(this.state.customContext).length>0?this.state.customContext:void 0,attachments:i.length>0?i:void 0};await e.submitReport(c);}ensureInitialized(){if(!this.state.initialized)throw new Error("Bugdump SDK is not initialized. Call Bugdump.init() first.")}};if(typeof document<"u"){let o=document.currentScript||(()=>{let t=document.querySelectorAll("script[data-api-key]");return t[t.length-1]})();if(o){let t=o,e=t.getAttribute("data-api-key"),n=t.getAttribute("data-api-url"),r=t.getAttribute("data-capture-network-bodies")==="true",i=t.getAttribute("data-hide-button")==="true";e&&C.init({projectKey:e,...n&&{endpoint:n},...r&&{captureNetworkBodies:r},...i&&{hideButton:i}});}}export{g as AnnotationOverlay,C as Bugdump,f as BugdumpApiError,T as captureScreenshot,E as renderOperationsToCanvas};