@lumen-stack/react 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- 'use strict';var react=require('react'),sonner=require('sonner'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');var T=class extends Error{constructor(e,t,r){super(e),this.code=t,this.status=r,this.name="LumenError";}code;status},Re=class extends T{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},Te=class extends T{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},Q=class extends T{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},Lt="https://shakebugs.vercel.app",Rt="/api/v1/sdk/submit",Tt=new Set([502,503,504]),Ie=class{apiKey;apiUrl;user;amplitude;constructor(e){if(!e.apiKey||!e.apiKey.startsWith("lk_pub_"))throw new T("Invalid Lumen apiKey \u2014 expected a key starting with `lk_pub_`.","INVALID_API_KEY");this.apiKey=e.apiKey,this.apiUrl=(e.apiUrl??Lt).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let r=`${this.apiUrl}${Rt}`,n=this.#e(e),a=null;for(let o=0;o<3;o++){o>0&&await At(2**o*250);try{return await this.#t(r,n,t)}catch(i){if(a=i,i instanceof Re||i instanceof Te||i instanceof T&&typeof i.status=="number"&&!Tt.has(i.status))throw i}}throw a instanceof Error?a:new Q("Submit failed after 3 attempts.")}#e(e){let t=new FormData;e.rawText&&t.append("rawText",e.rawText),e.category&&t.append("category",e.category),e.submitterEmail&&t.append("submitterEmail",e.submitterEmail),e.submitterFingerprint&&t.append("submitterFingerprint",e.submitterFingerprint);let r=e.context.amplitude??this.amplitude,n=r?{...e.context,amplitude:r}:e.context;return t.append("context",JSON.stringify(n)),e.screenshot&&t.append("screenshot",e.screenshot,Mt(e.screenshot)),e.audio&&t.append("audio",e.audio,"audio"),e.audioDurationMs!=null&&t.append("audioDurationMs",String(e.audioDurationMs)),e.video&&t.append("video",e.video,"video"),e.videoDurationMs!=null&&t.append("videoDurationMs",String(e.videoDurationMs)),t}#t(e,t,r){return new Promise((n,a)=>{let o=new XMLHttpRequest;o.open("POST",e,true),o.setRequestHeader("X-Lumen-Api-Key",this.apiKey),o.responseType="text";let{onUploadProgress:i,signal:s}=r;i&&o.upload.addEventListener("progress",c=>{c.lengthComputable&&c.total>0&&i(Math.min(1,c.loaded/c.total));});let l=()=>{o.abort(),a(new Q("Submit aborted."));};if(s){if(s.aborted){a(new Q("Submit aborted."));return}s.addEventListener("abort",l,{once:true});}o.addEventListener("load",()=>{if(s&&s.removeEventListener("abort",l),o.status===403){a(new Re);return}if(o.status===429){let c=Number(o.getResponseHeader("Retry-After"))||60;a(new Te(c));return}if(o.status<200||o.status>=300){a(new T(St(o.responseText)??`HTTP ${o.status}`,"HTTP_ERROR",o.status));return}try{let c=JSON.parse(o.responseText);n(c);}catch{a(new T("Malformed response from server.","BAD_RESPONSE"));}}),o.addEventListener("error",()=>{s&&s.removeEventListener("abort",l),a(new Q("Network error during submit."));}),o.send(t);})}};function Mt(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function At(e){return new Promise(t=>setTimeout(t,e))}function St(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var Nt=2,q=8*1024*1024;async function ue(e={}){Fe();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return It(await e.provider(),e)}catch(r){if(t==="custom")throw r;e.onWarning?.(["Custom capture provider failed; falling back to browser DOM capture."]);}if(t==="manual")throw new T("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return Ae(e);if(t==="dom")return Me(e);if(t==="custom")throw new T("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await Me(e)}catch(r){if(He()){let n=await Ae(e);return n.warnings=K(["DOM screenshot failed; used browser screen permission fallback.",...n.warnings]),e.onWarning?.(n.warnings),n}throw r}}function De(e,t=[]){Fe();let r=ne();return {blob:e,method:"manual-upload",platform:"web",viewport:r,pixelRatio:window.devicePixelRatio??1,warnings:K(t)}}async function Me(e){let t=await Pt(),r=e.target??document.documentElement,n=ne(),a=Math.max(1,Math.min(window.devicePixelRatio??1,e.maxScale??Nt)),o=Dt(r),i=await t(r,{backgroundColor:null,logging:false,useCORS:true,allowTaint:false,width:n.width,height:n.height,windowWidth:n.width,windowHeight:n.height,scrollX:window.scrollX,scrollY:window.scrollY,x:window.scrollX,y:window.scrollY,scale:a,ignoreElements:l=>l instanceof HTMLElement&&(l.dataset.lumenCaptureIgnore==="true"||!!l.closest("[data-lumen-capture-ignore='true']"))}),s={blob:await Oe(i,o),method:"web-dom",platform:"web",viewport:n,pixelRatio:a,warnings:K(o)};return s.warnings.length>0&&e.onWarning?.(s.warnings),s}async function Pt(){let{default:e}=await import('html2canvas-pro');return e}async function Ae(e){if(!He())throw new T("Browser screen capture is unavailable in this environment.","DISPLAY_MEDIA_UNAVAILABLE");let t=await navigator.mediaDevices.getDisplayMedia({video:true,audio:false});try{let r=document.createElement("video");r.muted=!0,r.playsInline=!0,r.srcObject=t,await Ot(r);let n=document.createElement("canvas");n.width=r.videoWidth,n.height=r.videoHeight;let a=n.getContext("2d");if(!a)throw new T("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");a.drawImage(r,0,0,n.width,n.height);let o=ne(),i=["Browser screen capture uses the window or tab selected by the user."],s={blob:await Oe(n,i),method:"web-display-media",platform:"web",viewport:o,pixelRatio:o.width>0?n.width/o.width:void 0,warnings:K(i)};return e.onWarning?.(s.warnings),s}finally{for(let r of t.getTracks())r.stop();}}function It(e,t){let r=ne(),n={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??r,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:K(e.warnings??[])};return n.warnings.length>0&&t.onWarning?.(n.warnings),n}function Dt(e){let t=new Set;e.querySelector("iframe")&&t.add("Embedded iframes may be blank or incomplete in DOM capture."),e.querySelector("video")&&t.add("Video frames may be blank or stale in DOM capture."),e.querySelector("canvas")&&t.add("Canvas/WebGL content may be blank if it is cross-origin tainted."),document.fonts&&document.fonts.status!=="loaded"&&t.add("Web fonts were still loading when the screenshot was captured.");let r=0;for(let n of Array.from(e.querySelectorAll("img"))){let a=n.currentSrc||n.src;if(a)try{new URL(a,window.location.href).origin!==window.location.origin&&!n.crossOrigin&&(r+=1);}catch{}}return r>0&&t.add(`${r} cross-origin image${r===1?"":"s"} without CORS may be omitted from the screenshot.`),Array.from(t)}async function Oe(e,t){let r=await Se(e,"image/png",.92);if(r.size<=q)return r;t.push("Screenshot exceeded the upload cap and was compressed.");let n=e,a=0;for(;r.size>q&&a<6;){let o=Math.max(.35,Math.min(.95,Math.sqrt(q/r.size)*.9)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(n.width*o)),i.height=Math.max(1,Math.round(n.height*o));let s=i.getContext("2d");if(!s)return r;s.drawImage(n,0,0,i.width,i.height),n=i;for(let l of [.86,.74,.62,.5])if(r=await Se(n,"image/jpeg",l),r.size<=q)return r;if(a+=1,i.width<480||i.height<320)break}return r.size>q&&t.push("Screenshot remained large after compression; upload may be rejected."),r}function Se(e,t,r){return new Promise((n,a)=>{e.toBlob(o=>{if(!o){a(new T("Could not encode screenshot.","ENCODE_FAILED"));return}n(o);},t,r);})}function ne(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function He(){return !!navigator.mediaDevices?.getDisplayMedia}async function Ot(e){await new Promise((n,a)=>{let o=()=>n(),i=()=>a(new T("Could not read screen capture video.","VIDEO_FAILED"));e.addEventListener("loadedmetadata",o,{once:true}),e.addEventListener("error",i,{once:true}),e.play().catch(i);});let t=performance.now(),r=1500;for(;e.videoWidth===0||e.videoHeight===0;){if(performance.now()-t>r)throw new T("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(n=>requestAnimationFrame(()=>n()));}}function Fe(){if(typeof window>"u"||typeof document>"u")throw new T("Screenshot capture can only run in the browser.","INVALID_ENV")}function K(e){return Array.from(new Set(e.filter(Boolean)))}var Be=[],ee=[],Ne=false,se=null;function _e(e={}){Ne||typeof window>"u"||(Ne=true,se=e.ignoreUrlPrefix??null,_t(),Ut(),Vt());}function Ht(){return {consoleLog:Be.slice(),networkLog:ee.slice()}}function te(e,t){e.push(t),e.length>200&&e.splice(0,e.length-200);}function Ft(e){let t=[];for(let n of e){if(typeof n=="string"){t.push(n);continue}if(n instanceof Error){t.push(`${n.name}: ${n.message}${n.stack?`
3
- ${n.stack}`:""}`);continue}try{t.push(JSON.stringify(n,Bt));}catch{t.push(String(n));}}let r=t.join(" ");return r.length>4096?r.slice(0,4096)+"\u2026[truncated]":r}function Bt(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function _t(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let r of t){let n=e[r]?.bind(e);n&&(e[r]=(...a)=>{try{te(Be,{level:r,ts:Date.now(),message:Ft(a)});}catch{}n(...a);});}}function Ue(e){return se?e.startsWith(se):false}function Ut(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,r){let n=typeof t=="string"?t:t instanceof URL?t.toString():t.url,a=(r?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(Ue(n))return e.call(window,t,r);let o=performance.now();try{let i=await e.call(window,t,r);return te(ee,{type:"fetch",method:a,url:le(n),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-o),ts:Date.now()}),i}catch(i){throw te(ee,{type:"fetch",method:a,url:le(n),status:0,ok:false,durationMs:Math.round(performance.now()-o),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function Vt(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,r=e.prototype.send;e.prototype.open=function(n,a,...o){return this.__lumen={method:String(n).toUpperCase(),url:typeof a=="string"?a:a.toString(),t:0},t.call(this,n,a,...o)},e.prototype.send=function(n){let a=this.__lumen;if(a&&!Ue(a.url)){a.t=performance.now();let o=()=>{try{te(ee,{type:"xhr",method:a.method,url:le(a.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-a.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",o);};this.addEventListener("loadend",o);}return r.call(this,n??null)};}function le(e){return e.length>512?e.slice(0,512)+"\u2026":e}function Ve(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:Pe(e),consoleLog:[],networkLog:[]};let t=Ht();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:Pe(e),device:zt(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function zt(){let e={};try{e.screen={width:window.screen?.width??0,height:window.screen?.height??0},e.pixelRatio=window.devicePixelRatio??1,e.language=navigator.language,e.languages=Array.from(navigator.languages??[]),e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.colorScheme=window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light",e.referrer=document.referrer||void 0,e.title=document.title||void 0,e.online=navigator.onLine,performance.getEntriesByType("navigation")[0]&&(e.uptimeMs=Math.round(performance.now()));}catch{}return e}function Pe(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}async function ze(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new T("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new T("Microphone access denied or unavailable.","MIC_DENIED")}let r=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(l=>MediaRecorder.isTypeSupported(l))??"",n=new MediaRecorder(t,r?{mimeType:r}:void 0),a=[],o=performance.now(),i=null;n.addEventListener("dataavailable",l=>{l.data&&l.data.size>0&&a.push(l.data);}),n.start(),i=window.setTimeout(()=>{n.state!=="inactive"&&n.stop();},e*1e3);function s(){i!==null&&window.clearTimeout(i),i=null;for(let l of t.getTracks())l.stop();}return {stream:t,cancel(){try{n.state!=="inactive"&&n.stop();}catch{}s();},stop(){return new Promise((l,c)=>{if(n.state==="inactive"){s(),c(new T("Recorder already stopped.","RECORDER_STOPPED"));return}n.addEventListener("stop",()=>{let f=performance.now()-o,g=n.mimeType||r||"audio/webm",v=new Blob(a,{type:g});s(),l({blob:v,durationMs:f,mimeType:g});},{once:true}),n.stop();})}}}async function We(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new T("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new T("Screen capture was denied or cancelled.","SCREEN_DENIED")}let r=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(c=>MediaRecorder.isTypeSupported(c))??"",n=new MediaRecorder(t,r?{mimeType:r}:void 0),a=[],o=performance.now(),i=null;n.addEventListener("dataavailable",c=>{c.data&&c.data.size>0&&a.push(c.data);}),n.start(),i=window.setTimeout(()=>{n.state!=="inactive"&&n.stop();},e*1e3);let s=t.getVideoTracks()[0];s&&s.addEventListener("ended",()=>{n.state!=="inactive"&&n.stop();});function l(){i!==null&&window.clearTimeout(i),i=null;for(let c of t.getTracks())c.stop();}return {stream:t,cancel(){try{n.state!=="inactive"&&n.stop();}catch{}l();},stop(){return new Promise((c,f)=>{if(n.state==="inactive"){l(),f(new T("Recorder already stopped.","RECORDER_STOPPED"));return}n.addEventListener("stop",()=>{let g=performance.now()-o,v=n.mimeType||r||"video/webm",w=new Blob(a,{type:v});l(),c({blob:w,durationMs:g,mimeType:v});},{once:true}),n.stop();})}}}var ce=react.createContext(null);function j(){let e=react.useContext(ce);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}function Ke({screenshot:e,tool:t,color:r="rgb(239, 68, 68)",strokeWidth:n=4,onDrawingChange:a,ref:o}){let i=react.useRef(null),s=react.useRef(null),l=react.useRef(null),[c,f]=react.useState(null),[g,v]=react.useState([]),w=react.useRef(null),E=react.useRef(false),x=react.useRef(0),L=react.useRef(false);react.useEffect(()=>{let d=false,p=null;return (async()=>{try{let b=await createImageBitmap(e);if(d){b.close?.();return}p=b,f(b);}catch{}})(),()=>{d=true,p?.close?.();}},[e]),react.useEffect(()=>{if(!c)return;let d=i.current,p=s.current;if(!d||!p)return;d.width=c.width,d.height=c.height,p.width=c.width,p.height=c.height;let b=d.getContext("2d");b&&(b.imageSmoothingEnabled=false,b.drawImage(c,0,0));},[c]),react.useEffect(()=>{let d=s.current;d&&re(d,g,w.current);},[g]),react.useImperativeHandle(o,()=>({hasAnnotations:()=>g.length>0,reset:()=>v([]),undo:()=>v(d=>d.length===0?d:d.slice(0,-1)),async flatten(){let d=w.current,p=d?[...g,d]:g;if(p.length===0||!c)return e;let b=document.createElement("canvas");b.width=c.width,b.height=c.height;let k=b.getContext("2d");if(!k)return e;k.imageSmoothingEnabled=false,k.drawImage(c,0,0);for(let N of p)me(k,N);return await new Promise(N=>{b.toBlob(I=>{N(I??e);},"image/jpeg",.85);})}}),[g,c,e]);function R(d){let p=s.current;if(!p)return {x:0,y:0};let b=p.getBoundingClientRect(),k=p.width/Math.max(b.width,1),N=p.height/Math.max(b.height,1);return {x:(d.clientX-b.left)*k,y:(d.clientY-b.top)*N}}function A(){L.current||(L.current=true,requestAnimationFrame(()=>{L.current=false;let d=s.current;d&&re(d,g,w.current);}));}function C(d){if(d.button!==void 0&&d.button!==0)return;try{d.currentTarget.setPointerCapture(d.pointerId);}catch{}E.current=true,a?.(true);let p=R(d);t==="arrow"?w.current={kind:"arrow",from:p,to:p,color:r,width:n}:t==="rect"?w.current={kind:"rect",from:p,to:p,color:r,width:n}:w.current={kind:"freehand",points:[p],color:r,width:n},x.current=performance.now(),A();}function S(d){if(!E.current||!w.current)return;let p=R(d),b=w.current;if(b.kind==="arrow"||b.kind==="rect")b.to=p;else {let k=b.points[b.points.length-1],N=k?(k.x-p.x)**2+(k.y-p.y)**2:1/0,I=performance.now(),V=I-x.current;(N>16||V>16)&&(b.points.push(p),x.current=I);}A();}function M(){if(!E.current)return;E.current=false,a?.(false);let d=w.current;if(w.current=null,!!d){if(d.kind==="arrow"||d.kind==="rect"){let p=d.to.x-d.from.x,b=d.to.y-d.from.y;if(p*p+b*b<16){let k=s.current;k&&re(k,g,null);return}}else if(d.points.length<2){let p=s.current;p&&re(p,g,null);return}v(p=>[...p,d].slice(-50));}}return jsxRuntime.jsxs("div",{ref:l,className:"lumen-annotate-frame",children:[jsxRuntime.jsx("canvas",{ref:i}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:C,onPointerMove:S,onPointerUp:M,onPointerCancel:M})]})}function re(e,t,r){let n=e.getContext("2d");if(n){n.clearRect(0,0,e.width,e.height);for(let a of t)me(n,a);r&&me(n,r);}}function me(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let r=Math.min(t.from.x,t.to.x),n=Math.min(t.from.y,t.to.y),a=Math.abs(t.to.x-t.from.x),o=Math.abs(t.to.y-t.from.y);e.strokeRect(r,n,a,o);}else if(t.kind==="freehand")jt(e,t.points);else {let{from:r,to:n,width:a}=t;e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(n.x,n.y),e.stroke();let o=Math.atan2(n.y-r.y,n.x-r.x),i=Math.max(12,a*4);e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(n.x-i*Math.cos(o-Math.PI/7),n.y-i*Math.sin(o-Math.PI/7)),e.lineTo(n.x-i*Math.cos(o+Math.PI/7),n.y-i*Math.sin(o+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function jt(e,t){if(t.length===0)return;e.beginPath();let r=t[0];if(!r)return;if(e.moveTo(r.x,r.y),t.length===1){e.arc(r.x,r.y,e.lineWidth/2,0,Math.PI*2),e.fill();return}if(t.length===2){let a=t[1];e.lineTo(a.x,a.y),e.stroke();return}for(let a=1;a<t.length-1;a++){let o=t[a],i=t[a+1],s=(o.x+i.x)/2,l=(o.y+i.y)/2;e.quadraticCurveTo(o.x,o.y,s,l);}let n=t[t.length-1];e.lineTo(n.x,n.y),e.stroke();}var pe=60,Xt=60,je=[{label:"Red",value:"rgb(239, 68, 68)"},{label:"Amber",value:"rgb(245, 158, 11)"},{label:"Blue",value:"rgb(59, 130, 246)"},{label:"Green",value:"rgb(34, 197, 94)"},{label:"Neutral",value:"rgb(244, 244, 245)"}],Ye=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],Gt=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}];function ge(){let{client:e,isOpen:t,closeCapture:r,user:n,capture:a}=j(),[o,i]=react.useState({kind:"idle"}),[s,l]=react.useState("arrow"),[c,f]=react.useState(je[0].value),[g,v]=react.useState(Ye[1].value),[w,E]=react.useState(""),[x,L]=react.useState("bug"),[R,A]=react.useState(n?.email??""),[C,S]=react.useState(null),[M,d]=react.useState(null),[p,b]=react.useState(0),[k,N]=react.useState(null),[I,V]=react.useState(null),[W,X]=react.useState(false),G=react.useRef(null),ae=react.useRef(null),ve=react.useRef(null),$=react.useRef(false);if(react.useEffect(()=>{if(t)return $.current=false,i({kind:"capturing"}),E(""),d(null),b(0),V(null),N(u=>(u?.cancel(),null)),(async()=>{if(a?.mode==="manual"){$.current||i({kind:"manual"});return}try{let u=await ue({...a,target:a?.target??document.documentElement});if($.current)return;Le(u),i({kind:"ready",capture:u});}catch(u){if($.current)return;i({kind:"manual",error:u instanceof Error?u.message:"Automatic screenshot capture was unavailable."});}})(),()=>{$.current=true;}},[t,a]),react.useEffect(()=>{if(!t)return;ve.current=document.activeElement??null;let u=document.documentElement,h=u.style.overflow,O=u.style.paddingRight,D=window.innerWidth-u.clientWidth;u.style.overflow="hidden",D>0&&(u.style.paddingRight=`${D}px`);let H=false,F=()=>{if(!H){H=true,u.style.overflow=h,u.style.paddingRight=O;try{ve.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",F),()=>{window.removeEventListener("pagehide",F),F();}},[t]),react.useEffect(()=>{if(!t)return;function u(h){if(h.key==="Escape"){h.preventDefault(),r();return}if(h.key!=="Tab")return;let O=ae.current;if(!O)return;let D=Xe(O);if(D.length===0)return;let H=D[0],F=D[D.length-1],ie=document.activeElement;h.shiftKey&&(ie===H||!O.contains(ie))?(h.preventDefault(),F.focus()):!h.shiftKey&&ie===F&&(h.preventDefault(),H.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,r]),react.useEffect(()=>{if(!t||o.kind!=="ready"&&o.kind!=="manual")return;let u=ae.current;if(!u)return;let h=Xe(u);(u.querySelector("textarea.lumen-input")??h[0])?.focus();},[t,o.kind]),react.useEffect(()=>{if(!t||o.kind!=="manual")return;function u(h){let H=Array.from(h.clipboardData?.items??[]).find(F=>F.type.startsWith("image/"))?.getAsFile();H&&(h.preventDefault(),ke(H));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,o.kind]),react.useEffect(()=>{if(!C)return;let u=Date.now(),h=window.setInterval(()=>{let O=Math.floor((Date.now()-u)/1e3);b(O),O>=pe&&Ee();},250);return ()=>window.clearInterval(h)},[C]),!t)return null;async function yt(){try{let u=await ze(pe);S(u);}catch(u){sonner.toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Ee(){if(C)try{let u=await C.stop();d({blob:u.blob,durationMs:u.durationMs});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{S(null);}}function vt(){C?.cancel(),S(null),d(null),b(0);}async function Et(){try{let u=await We(Xt);N(u),u.stream.getVideoTracks()[0]?.addEventListener("ended",()=>{xe();});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}async function xe(){if(!k)return;let u=k;N(null);try{let h=await u.stop();V({blob:h.blob,durationMs:h.durationMs});}catch(h){sonner.toast.error(h instanceof Error?h.message:"Could not stop recording");}}function Ce(){k?.cancel(),N(null),V(null);}function ke(u){if(!u.type.startsWith("image/")){sonner.toast.error("Choose a PNG, JPEG, or WebP screenshot.");return}let h=De(u,["Manual screenshot upload used."]);i({kind:"ready",capture:h});}async function xt(){i({kind:"capturing"});try{let u=await ue({...a,mode:"true-screen",target:a?.target??document.documentElement});Le(u),i({kind:"ready",capture:u});}catch(u){i({kind:"manual",error:u instanceof Error?u.message:"Browser screen capture was unavailable."});}}function Le(u){u.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function Ct(){if(o.kind!=="ready")return;let u=w.trim();if(!M&&u.length===0){sonner.toast.error("Add a voice note or write a description.");return}let{capture:h}=o,O=h.blob;i({kind:"uploading",capture:h,progress:0});try{let D=await G.current?.flatten()??O,H=await e.submit({rawText:u.length>0?u:void 0,category:x,submitterEmail:R.trim()||void 0,screenshot:D,audio:M?.blob,audioDurationMs:M?.durationMs,video:I?.blob,videoDurationMs:I?.durationMs,context:Ve(h)},{onUploadProgress:F=>{i({kind:"uploading",capture:h,progress:Math.min(.95,F)});}});i({kind:"uploading",capture:h,progress:1}),sonner.toast.success("Feedback sent \u2014 thank you."),H.id,r();}catch(D){sonner.toast.error(D instanceof Error?D.message:"Could not submit feedback"),i({kind:"ready",capture:h});}}let J=o.kind==="uploading"?Math.round(o.progress*100):0,Z=o.kind==="uploading";function kt(u){u.target===u.currentTarget&&r();}return jsxRuntime.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:kt,children:jsxRuntime.jsxs("div",{ref:ae,className:"lumen-modal","data-lumen-drawing":W?"true":void 0,children:[jsxRuntime.jsx(Jt,{onDismiss:r}),jsxRuntime.jsxs("header",{className:"lumen-modal-header",children:[jsxRuntime.jsxs("h2",{className:"lumen-modal-title",children:[jsxRuntime.jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsxRuntime.jsx("button",{type:"button",onClick:r,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[o.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing screenshot\u2026"]}):null,o.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:o.error?"Automatic screenshot capture was unavailable. Upload or paste a screenshot to continue.":"Upload or paste a screenshot to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:"Choose or paste a screenshot"}),jsxRuntime.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:u=>{let h=u.currentTarget.files?.[0];h&&ke(h),u.currentTarget.value="";}})]})]}):null,o.kind==="ready"||o.kind==="uploading"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(fe,{label:"Arrow",active:s==="arrow",onClick:()=>l("arrow")}),jsxRuntime.jsx(fe,{label:"Box",active:s==="rect",onClick:()=>l("rect")}),jsxRuntime.jsx(fe,{label:"Draw",active:s==="freehand",onClick:()=>l("freehand")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:je.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":c===u.value,onClick:()=>f(u.value)},u.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:Ye.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":g===u.value,onClick:()=>v(u.value),children:jsxRuntime.jsx("span",{className:"lumen-stroke-size-dot",style:{width:u.dot,height:u.dot}})},u.value))}),jsxRuntime.jsx("span",{className:"lumen-toolbar-spacer"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>G.current?.undo(),title:"Undo",children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>G.current?.reset(),title:"Clear all annotations",children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(Ke,{ref:G,screenshot:o.capture.blob,tool:s,color:c,strokeWidth:g,onDrawingChange:X})}),jsxRuntime.jsxs("div",{className:"lumen-form",children:[jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Category"}),jsxRuntime.jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:Gt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":x===u.value,onClick:()=>L(u.value),children:u.label},u.value))})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsxs("span",{children:["Description ",M?"(optional with audio)":""]}),jsxRuntime.jsx("textarea",{value:w,onChange:u=>E(u.target.value),rows:3,placeholder:"What happened?",className:"lumen-input"})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Your email (optional)"}),jsxRuntime.jsx("input",{type:"email",value:R,onChange:u=>A(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]}),jsxRuntime.jsxs("div",{className:"lumen-audio-row",children:[!C&&!M?jsxRuntime.jsx("button",{type:"button",onClick:yt,className:"lumen-btn-ghost",children:"Record voice note"}):null,C?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(Zt,{stream:C.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[p,"s / ",pe,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:Ee,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:vt,className:"lumen-btn-ghost",children:"Cancel"})]}):null,M&&!C?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(en,{blob:M.blob,durationMs:M.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>d(null),className:"lumen-btn-ghost",children:"Remove"})]}):null,!k&&!I?jsxRuntime.jsx("button",{type:"button",onClick:Et,className:"lumen-btn-ghost",title:"Record your screen",children:"Record screen"}):null,k?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"lumen-rec-time",children:"Recording\u2026"})]}),jsxRuntime.jsx("button",{type:"button",onClick:xe,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:Ce,className:"lumen-btn-ghost",children:"Cancel"})]}):null,I&&!k?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(tn,{blob:I.blob,durationMs:I.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:Ce,className:"lumen-btn-ghost",children:"Remove"})]}):null,jsxRuntime.jsx("span",{className:"lumen-toolbar-spacer"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:xt,title:"Use the browser's screen capture",children:"Screen capture"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>i({kind:"manual"}),title:"Upload a screenshot file",children:"Upload"})]})]})]}):null]}),o.kind==="ready"||o.kind==="uploading"?jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[Z?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":J,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${J}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:r,className:"lumen-btn-ghost",disabled:Z,children:"Cancel"}),jsxRuntime.jsx("button",{type:"button",onClick:Ct,className:"lumen-btn-primary",disabled:Z,children:Z?J<95?`Uploading ${J}%\u2026`:"Almost done\u2026":"Send feedback"})]})]}):null]})})}function fe({label:e,active:t,onClick:r}){return jsxRuntime.jsx("button",{type:"button",onClick:r,className:"lumen-tool","aria-pressed":t,children:e})}function Jt({onDismiss:e}){let t=react.useRef(null),r=react.useRef(0),n=react.useRef(null);function a(s){s.currentTarget.setPointerCapture(s.pointerId),t.current=s.clientY,r.current=performance.now(),n.current=s.currentTarget.parentElement;}function o(s){if(t.current==null||!n.current)return;let l=Math.max(0,s.clientY-t.current);n.current.style.transform=`translateY(${l}px)`;}function i(s){if(t.current==null||!n.current)return;let l=Math.max(0,s.clientY-t.current),c=Math.max(1,performance.now()-r.current),f=l/c;n.current.style.transform="",n.current.style.transition="",t.current=null,(l>80||f>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:a,onPointerMove:o,onPointerUp:i,onPointerCancel:i})}function Zt({stream:e}){let t=react.useRef(null);return react.useEffect(()=>{let r=t.current;if(!r)return;let n=Math.min(window.devicePixelRatio||1,2),a=r.clientWidth||88,o=r.clientHeight||22;r.width=Math.round(a*n),r.height=Math.round(o*n);let i=r.getContext("2d");if(!i)return;i.scale(n,n);let s=window.AudioContext??window.webkitAudioContext;if(!s)return;let l=new s,c=l.createMediaStreamSource(e),f=l.createAnalyser();f.fftSize=1024,f.smoothingTimeConstant=.6,c.connect(f);let g=new Uint8Array(f.fftSize),v=18,w=3,E=3,x=Math.max(2,(a-w*(v-1))/v),L=Math.min(x/2,3),R=new Array(v).fill(0),A=0,C=false;function S(){if(C)return;f.getByteTimeDomainData(g);let M=Math.floor(g.length/v);i.clearRect(0,0,a,o),i.fillStyle=nn("--lumen-danger")||"rgb(239,68,68)";for(let d=0;d<v;d++){let p=0;for(let W=0;W<M;W++){let X=Math.abs((g[d*M+W]??128)-128);X>p&&(p=X);}let b=Math.min(1,p/128*1.8),k=R[d]??0;R[d]=b>k?b:k+(b-k)*.35;let N=Math.max(E,R[d]*o),I=d*(x+w),V=(o-N)/2;Qt(i,I,V,x,N,L),i.fill();}A=requestAnimationFrame(S);}return A=requestAnimationFrame(S),()=>{C=true,cancelAnimationFrame(A);try{c.disconnect();}catch{}l.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function Qt(e,t,r,n,a,o){let i=Math.min(o,n/2,a/2);e.beginPath();let s=e;if(typeof s.roundRect=="function"){s.roundRect(t,r,n,a,i);return}e.moveTo(t+i,r),e.arcTo(t+n,r,t+n,r+a,i),e.arcTo(t+n,r+a,t,r+a,i),e.arcTo(t,r+a,t,r,i),e.arcTo(t,r,t+n,r,i),e.closePath();}function en({blob:e,durationMs:t}){let[r,n]=react.useState("");return react.useEffect(()=>{let a=URL.createObjectURL(e);return n(a),()=>{URL.revokeObjectURL(a);}},[e]),jsxRuntime.jsxs("div",{className:"lumen-audio-preview",children:[jsxRuntime.jsx("audio",{controls:true,preload:"metadata",src:r,className:"lumen-audio-el"}),jsxRuntime.jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function tn({blob:e,durationMs:t}){let[r,n]=react.useState("");return react.useEffect(()=>{let a=URL.createObjectURL(e);return n(a),()=>{URL.revokeObjectURL(a);}},[e]),jsxRuntime.jsxs("div",{className:"lumen-audio-preview",children:[jsxRuntime.jsx("video",{controls:true,preload:"metadata",src:r,className:"lumen-video-el",style:{maxHeight:72,borderRadius:6}}),jsxRuntime.jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function nn(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var rn='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Xe(e){return Array.from(e.querySelectorAll(rn)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function Ge(){if(typeof document>"u"||typeof window>"u")return 0;let e=window.innerWidth,t=window.innerHeight;if(e===0||t===0)return 0;let r=t-4,n=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],a=new Set,o=0;for(let i of n){let s=document.elementsFromPoint(i,r);for(let l of s){if(a.has(l))continue;a.add(l);let c=window.getComputedStyle(l);if(c.position!=="fixed"&&c.position!=="sticky")continue;let f=l.getBoundingClientRect();f.bottom<t-8||f.bottom>t+8||f.width<e*.6||f.height>o&&(o=f.height);}}return o}function be(e,t){if(typeof document>"u"||typeof window>"u")return 0;let r=window.innerWidth,n=window.innerHeight,a=0;for(let o of e){let i;try{i=document.querySelectorAll(o);}catch{continue}for(let s of Array.from(i)){let l=s.getBoundingClientRect();if(l.height===0||l.width===0)continue;let c=0;switch(t){case "bottom":if(l.bottom<n-8)break;c=Math.max(0,n-l.top);break;case "top":if(l.top>8)break;c=Math.max(0,l.bottom);break;case "left":if(l.left>8)break;c=Math.max(0,l.right);break;case "right":if(l.right<r-8)break;c=Math.max(0,r-l.left);break}c>a&&(a=c);}}return a}function Je(e){let[t,r]=react.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),n=react.useRef(t),a=ln(e.avoid),o=e.placement,i=e.offset.x,s=e.offset.y;return react.useEffect(()=>{if(typeof window>"u")return;let l=0,c=false,f=()=>{if(l=0,c)return;let x=o[0]==="b"?"bottom":"top",L=o[1]==="r"?"right":"left",R=0,A=0;e.avoid==="auto"&&x==="bottom"?R=Ge():Array.isArray(e.avoid)&&(R=be(e.avoid,x),A=be(e.avoid,L));let C={bottom:x==="bottom"?s+R:0,top:x==="top"?s+R:0,right:L==="right"?i+A:0,left:L==="left"?i+A:0},S=n.current;(C.bottom!==S.bottom||C.top!==S.top||C.right!==S.right||C.left!==S.left)&&(n.current=C,r(C));},g=()=>{l||(l=window.requestAnimationFrame(f));};g();let v=typeof ResizeObserver<"u"?new ResizeObserver(g):null;v?.observe(document.documentElement);let w=typeof MutationObserver<"u"?new MutationObserver(g):null;w?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",g);let E=window.visualViewport;return E?.addEventListener("resize",g),E?.addEventListener("scroll",g),()=>{c=true,l&&window.cancelAnimationFrame(l),v?.disconnect(),w?.disconnect(),window.removeEventListener("resize",g),E?.removeEventListener("resize",g),E?.removeEventListener("scroll",g);}},[o,i,s,a]),t}function ln(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function Ze(e){let[t,r]=react.useState(false);return react.useEffect(()=>{if(!e){r(false);return}if(typeof window>"u")return;let n=window.visualViewport;if(!n||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let a=100,o=0,i=()=>{o=0;let l=window.innerHeight-n.height;r(l>a);},s=()=>{o||(o=window.requestAnimationFrame(i));};return s(),n.addEventListener("resize",s),n.addEventListener("scroll",s),()=>{o&&window.cancelAnimationFrame(o),n.removeEventListener("resize",s),n.removeEventListener("scroll",s);}},[e]),t}function nt({config:e,portalTarget:t,hidden:r,onClick:n}){let[a,o]=react.useState(null),i=react.useRef(null),s=Je(e),l=Ze(e.hideOnKeyboard);if(react.useEffect(()=>{typeof document>"u"||o(t??document.body);},[t]),pn(i,!r&&!l),!a)return null;let c=e.placement,f=c[0]==="b"?"bottom":"top",g=c[1]==="r"?"right":"left",v=f==="bottom"?s.bottom:s.top,w=g==="right"?s.right:s.left,E={position:"fixed",[f]:e.safeArea?`calc(${v}px + env(safe-area-inset-${f}, 0px))`:`${v}px`,[g]:e.safeArea?`calc(${w}px + env(safe-area-inset-${g}, 0px))`:`${w}px`,zIndex:e.zIndex,opacity:r||l?0:1,pointerEvents:r||l?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:i,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:E,"aria-label":e.label,"aria-hidden":r||l?true:void 0,tabIndex:r||l?-1:0,onClick:n,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),a)}function pn(e,t){let r=react.useRef(false);react.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||r.current||typeof window>"u")return;let n=window.setTimeout(()=>{let a=e.current;if(!a)return;let o=a.getBoundingClientRect();if(o.width===0||o.height===0)return;let i=o.left+o.width/2,s=o.top+o.height/2,l=document.elementsFromPoint(i,s),c=Qe(window.getComputedStyle(a).zIndex);for(let f of l){if(f===a||a.contains(f))continue;if(Qe(window.getComputedStyle(f).zIndex)>c){r.current=true,console.warn("[lumen] trigger is occluded by",f);break}}},250);return ()=>window.clearTimeout(n)},[t,e]);}function Qe(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function rt({mount:e,label:t,icon:r,onClick:n}){let[a,o]=react.useState(null);return react.useEffect(()=>{if(typeof document>"u")return;let i=e instanceof HTMLElement?e:e.current??null;o(i);},[e]),a?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onClick:n,"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[r,jsxRuntime.jsx("span",{children:t})]}),a):null}function it({config:e,portalTarget:t,hidden:r,onClick:n}){let[a,o]=react.useState(null),[i,s]=react.useState(false),l=react.useRef(null);if(react.useEffect(()=>{typeof document>"u"||o(t??document.body);},[t]),!a)return null;let c=`lumen-notch lumen-notch-${e.edge}${i?" lumen-notch-expanded":""}`;function f(E){l.current={x:E.clientX,y:E.clientY},s(true),E.currentTarget.setPointerCapture(E.pointerId);}function g(E){let x=l.current;if(!x)return;let L=E.clientX-x.x,R=E.clientY-x.y;(e.edge==="top"&&R>16||e.edge==="bottom"&&R<-16||e.edge==="right"&&L<-16||e.edge==="left"&&L>16)&&(l.current=null,n());}function v(){l.current=null,s(false);}function w(){l.current=null,s(false);}return reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:c,style:{zIndex:e.zIndex,opacity:r?0:1,pointerEvents:r?"none":"auto"},"aria-label":e.label,"aria-hidden":r?true:void 0,tabIndex:r?-1:0,onClick:n,onPointerDown:f,onPointerMove:g,onPointerUp:v,onPointerCancel:w,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),a)}function st(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function lt(e){return {kind:"floating",placement:e.placement??"br",offset:{x:e.offset?.x??16,y:e.offset?.y??16},safeArea:e.safeArea??true,avoid:e.avoid===false?false:e.avoid==null?"auto":Array.isArray(e.avoid)?e.avoid:[e.avoid],hideOnKeyboard:e.hideOnKeyboard??true,zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var Tn={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function ut(e){let t=react.useId();react.useEffect(()=>{if(typeof document>"u")return;let r=document.documentElement,n=`data-lumen-theme-${Mn(t)}`,a={};if(e==="auto"||e==null)r.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")a["data-lumen-theme"]=r.getAttribute("data-lumen-theme"),r.setAttribute("data-lumen-theme",e);else for(let[o,i]of Object.entries(Tn)){let s=e[i];typeof s=="string"&&s.length>0&&(a[o]=r.style.getPropertyValue(o)||null,r.style.setProperty(o,s));}return r.setAttribute(n,""),()=>{r.removeAttribute(n);for(let[o,i]of Object.entries(a))o.startsWith("--")?i?r.style.setProperty(o,i):r.style.removeProperty(o):i==null?r.removeAttribute(o):r.setAttribute(o,i);}},[e,t]);}function Mn(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var ct=Symbol.for("lumen.history.patched"),he="lumen:locationchange";function Nn(){if(typeof window>"u")return;let e=window;if(e[ct])return;e[ct]=true;let t=()=>window.dispatchEvent(new Event(he)),r=history.pushState;history.pushState=function(...a){let o=r.apply(this,a);return t(),o};let n=history.replaceState;history.replaceState=function(...a){let o=n.apply(this,a);return t(),o},window.addEventListener("popstate",t);}function dt(e){let[t,r]=react.useState(false);return react.useEffect(()=>{if(!e){r(false);return}if(typeof window>"u")return;Nn();let n=()=>{try{r(!!e({pathname:window.location.pathname}));}catch{r(false);}};return n(),window.addEventListener(he,n),window.addEventListener("popstate",n),()=>{window.removeEventListener(he,n),window.removeEventListener("popstate",n);}},[e]),t}var Dn=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function mt(){let[e,t]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let r=window;if(r.ReactNativeWebView){t(true);return}let n=r.webkit;if(n&&n.messageHandlers){t(true);return}let a=navigator.userAgent||"";Dn.some(o=>a.includes(o))&&t(true);},[]),e}var ft="lumen.config.v1.",Fn=3600*1e3;function gt(e,t){let[r,n]=react.useState(()=>({trigger:null,enabled:true,loading:true}));return react.useEffect(()=>{if(typeof window>"u")return;let a=Un(e);a&&n({trigger:a.trigger,enabled:pt(a.trigger),loading:false});let o=new AbortController,i=window.setTimeout(()=>o.abort(),5e3),s=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(s,{method:"GET",mode:"cors",credentials:"omit",signal:o.signal}).then(async l=>{if(!l.ok)throw new Error(`HTTP ${l.status}`);let c=await l.json(),f=bt(c.trigger);if(!f)throw new Error("Malformed config response");Vn(e,f),n({trigger:f,enabled:pt(f),loading:false});}).catch(()=>{n(l=>l.loading?{trigger:null,enabled:true,loading:false}:l);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),o.abort();}},[e,t]),r}function pt(e){return e.kind!=="headless"}var Bn=["br","bl","tr","tl"],_n=["top","right","bottom","left"];function bt(e){if(!e||typeof e!="object")return null;let t=e;if(t.enabled===false)return {kind:"headless"};let r=typeof t.label=="string"?t.label:"Feedback";return t.kind==="floating"?{kind:"floating",placement:Bn.find(a=>a===t.placement)??"br",label:r}:t.kind==="notch"?{kind:"notch",edge:_n.find(a=>a===t.edge)??"top",label:r}:null}function Un(e){try{let t=window.localStorage.getItem(ft+e);if(!t)return null;let r=JSON.parse(t);if(typeof r?.fetchedAt!="number"||Date.now()-r.fetchedAt>Fn)return null;let n=bt(r.trigger);return n?{fetchedAt:r.fetchedAt,trigger:n}:null}catch{return null}}function Vn(e,t){try{window.localStorage.setItem(ft+e,JSON.stringify({fetchedAt:Date.now(),trigger:t}));}catch{}}var wt="https://shakebugs.vercel.app";function Wn({apiKey:e,apiUrl:t,user:r,amplitude:n,floatingButton:a=true,trigger:o,hideOn:i,theme:s,portalTarget:l,capture:c,children:f}){let[g,v]=react.useState(false),[w]=react.useState(false),[E]=react.useState(null),x=react.useMemo(()=>new Ie({apiKey:e,apiUrl:t,user:r,amplitude:n}),[e,t,r?.id,r?.email,r?.name,n?.userId,n?.deviceId,n?.sessionId]);react.useEffect(()=>{_e({ignoreUrlPrefix:(t??wt).replace(/\/$/,"")});},[t]);let L=react.useCallback(()=>v(true),[]),R=react.useCallback(()=>v(false),[]),A=react.useCallback(x.submit.bind(x),[x]),C=mt(),S=dt(i);ut(s);let M=gt(o?"":e,t??wt),d=react.useMemo(()=>({client:x,user:r,isOpen:g,isSubmitting:w,error:E,open:L,close:R,openCapture:L,closeCapture:R,submit:A,isNativeShell:C,capture:c}),[x,r,g,w,E,L,R,A,C,c]),p=$n({explicit:o,remote:M.trigger,remoteLoading:M.loading,floatingButton:a});return jsxRuntime.jsxs(ce.Provider,{value:d,children:[f,p?.kind==="floating"?jsxRuntime.jsx(nt,{config:lt(p),portalTarget:l,hidden:S,onClick:L}):null,p?.kind==="notch"?jsxRuntime.jsx(it,{config:st(p),portalTarget:l,hidden:S,onClick:L}):null,p?.kind==="inline"?jsxRuntime.jsx(rt,{mount:p.mount,label:p.label??"Feedback",icon:p.icon,onClick:L}):null,jsxRuntime.jsx(ge,{})]})}function $n(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function Kn({variant:e="default",floating:t=false,className:r,children:n="Feedback",onClick:a,...o}){let{openCapture:i}=j(),s=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,r].filter(Boolean).join(" ");return jsxRuntime.jsx("button",{type:"button",className:s,onClick:l=>{a?.(l),l.defaultPrevented||i();},...o,children:n})}
4
- exports.CaptureModal=ge;exports.FeedbackButton=Kn;exports.LumenProvider=Wn;exports.useLumen=j;//# sourceMappingURL=index.cjs.map
2
+ 'use strict';var react=require('react'),sonner=require('sonner'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');var R=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},Oe=class extends R{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},He=class extends R{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},re=class extends R{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},Ut="https://shakebugs.vercel.app",Wt="/api/v1/sdk/submit",$t=new Set([502,503,504]),Ue=class{apiKey;apiUrl;user;amplitude;constructor(e){if(!e.apiKey||!e.apiKey.startsWith("lk_pub_"))throw new R("Invalid Lumen apiKey \u2014 expected a key starting with `lk_pub_`.","INVALID_API_KEY");this.apiKey=e.apiKey,this.apiUrl=(e.apiUrl??Ut).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${Wt}`,o=this.#e(e),r=null;for(let a=0;a<3;a++){a>0&&await Kt(2**a*250);try{return await this.#t(n,o,t)}catch(i){if(r=i,i instanceof Oe||i instanceof He||i instanceof R&&typeof i.status=="number"&&!$t.has(i.status))throw i}}throw r instanceof Error?r:new re("Submit failed after 3 attempts.")}#e(e){let t=new FormData;e.rawText&&t.append("rawText",e.rawText),e.category&&t.append("category",e.category),e.submitterEmail&&t.append("submitterEmail",e.submitterEmail),e.submitterFingerprint&&t.append("submitterFingerprint",e.submitterFingerprint);let n=e.context.amplitude??this.amplitude,o=n?{...e.context,amplitude:n}:e.context;return t.append("context",JSON.stringify(o)),e.screenshot&&t.append("screenshot",e.screenshot,qt(e.screenshot)),e.audio&&t.append("audio",e.audio,"audio"),e.audioDurationMs!=null&&t.append("audioDurationMs",String(e.audioDurationMs)),e.video&&t.append("video",e.video,"video"),e.videoDurationMs!=null&&t.append("videoDurationMs",String(e.videoDurationMs)),t}#t(e,t,n){return new Promise((o,r)=>{let a=new XMLHttpRequest;a.open("POST",e,true),a.setRequestHeader("X-Lumen-Api-Key",this.apiKey),a.responseType="text";let{onUploadProgress:i,signal:s}=n;i&&a.upload.addEventListener("progress",c=>{c.lengthComputable&&c.total>0&&i(Math.min(1,c.loaded/c.total));});let u=()=>{a.abort(),r(new re("Submit aborted."));};if(s){if(s.aborted){r(new re("Submit aborted."));return}s.addEventListener("abort",u,{once:true});}a.addEventListener("load",()=>{if(s&&s.removeEventListener("abort",u),a.status===403){r(new Oe);return}if(a.status===429){let c=Number(a.getResponseHeader("Retry-After"))||60;r(new He(c));return}if(a.status<200||a.status>=300){r(new R(jt(a.responseText)??`HTTP ${a.status}`,"HTTP_ERROR",a.status));return}try{let c=JSON.parse(a.responseText);o(c);}catch{r(new R("Malformed response from server.","BAD_RESPONSE"));}}),a.addEventListener("error",()=>{s&&s.removeEventListener("abort",u),r(new re("Network error during submit."));}),a.send(t);})}};function qt(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function Kt(e){return new Promise(t=>setTimeout(t,e))}function jt(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var Yt=2,G=8*1024*1024;async function We(e={}){je();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return Gt(await e.provider(),e)}catch(n){if(t==="custom")throw n;e.onWarning?.(["Custom capture provider failed; falling back to browser DOM capture."]);}if(t==="manual")throw new R("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return Be(e);if(t==="dom")return Fe(e);if(t==="custom")throw new R("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await Fe(e)}catch(n){if(Ke()){let o=await Be(e);return o.warnings=J(["DOM screenshot failed; used browser screen permission fallback.",...o.warnings]),e.onWarning?.(o.warnings),o}throw n}}function $e(e,t=[]){je();let n=se();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:J(t)}}async function Fe(e){let t=await Xt(),n=e.target??document.documentElement,o=se(),r=Math.max(1,Math.min(window.devicePixelRatio??1,e.maxScale??Yt)),a=Jt(n),i=await t(n,{backgroundColor:null,logging:false,useCORS:true,allowTaint:false,width:o.width,height:o.height,windowWidth:o.width,windowHeight:o.height,scrollX:window.scrollX,scrollY:window.scrollY,x:window.scrollX,y:window.scrollY,scale:r,ignoreElements:u=>u instanceof HTMLElement&&(u.dataset.lumenCaptureIgnore==="true"||!!u.closest("[data-lumen-capture-ignore='true']"))}),s={blob:await qe(i,a),method:"web-dom",platform:"web",viewport:o,pixelRatio:r,warnings:J(a)};return s.warnings.length>0&&e.onWarning?.(s.warnings),s}async function Xt(){let{default:e}=await import('html2canvas-pro');return e}async function Be(e){if(!Ke())throw new R("Browser screen capture is unavailable in this environment.","DISPLAY_MEDIA_UNAVAILABLE");let t=await navigator.mediaDevices.getDisplayMedia({video:true,audio:false});try{let n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.srcObject=t,await Zt(n);let o=document.createElement("canvas");o.width=n.videoWidth,o.height=n.videoHeight;let r=o.getContext("2d");if(!r)throw new R("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");r.drawImage(n,0,0,o.width,o.height);let a=se(),i=["Browser screen capture uses the window or tab selected by the user."],s={blob:await qe(o,i),method:"web-display-media",platform:"web",viewport:a,pixelRatio:a.width>0?o.width/a.width:void 0,warnings:J(i)};return e.onWarning?.(s.warnings),s}finally{for(let n of t.getTracks())n.stop();}}function Gt(e,t){let n=se(),o={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:J(e.warnings??[])};return o.warnings.length>0&&t.onWarning?.(o.warnings),o}function Jt(e){let t=new Set;e.querySelector("iframe")&&t.add("Embedded iframes may be blank or incomplete in DOM capture."),e.querySelector("video")&&t.add("Video frames may be blank or stale in DOM capture."),e.querySelector("canvas")&&t.add("Canvas/WebGL content may be blank if it is cross-origin tainted."),document.fonts&&document.fonts.status!=="loaded"&&t.add("Web fonts were still loading when the screenshot was captured.");let n=0;for(let o of Array.from(e.querySelectorAll("img"))){let r=o.currentSrc||o.src;if(r)try{new URL(r,window.location.href).origin!==window.location.origin&&!o.crossOrigin&&(n+=1);}catch{}}return n>0&&t.add(`${n} cross-origin image${n===1?"":"s"} without CORS may be omitted from the screenshot.`),Array.from(t)}async function qe(e,t){let n=await _e(e,"image/png",.92);if(n.size<=G)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let o=e,r=0;for(;n.size>G&&r<6;){let a=Math.max(.35,Math.min(.95,Math.sqrt(G/n.size)*.9)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(o.width*a)),i.height=Math.max(1,Math.round(o.height*a));let s=i.getContext("2d");if(!s)return n;s.drawImage(o,0,0,i.width,i.height),o=i;for(let u of [.86,.74,.62,.5])if(n=await _e(o,"image/jpeg",u),n.size<=G)return n;if(r+=1,i.width<480||i.height<320)break}return n.size>G&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function _e(e,t,n){return new Promise((o,r)=>{e.toBlob(a=>{if(!a){r(new R("Could not encode screenshot.","ENCODE_FAILED"));return}o(a);},t,n);})}function se(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function Ke(){return !!navigator.mediaDevices?.getDisplayMedia}async function Zt(e){await new Promise((o,r)=>{let a=()=>o(),i=()=>r(new R("Could not read screen capture video.","VIDEO_FAILED"));e.addEventListener("loadedmetadata",a,{once:true}),e.addEventListener("error",i,{once:true}),e.play().catch(i);});let t=performance.now(),n=1500;for(;e.videoWidth===0||e.videoHeight===0;){if(performance.now()-t>n)throw new R("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(o=>requestAnimationFrame(()=>o()));}}function je(){if(typeof window>"u"||typeof document>"u")throw new R("Screenshot capture can only run in the browser.","INVALID_ENV")}function J(e){return Array.from(new Set(e.filter(Boolean)))}var Ye=[],ae=[],Ve=false,ge=null;function Xe(e={}){Ve||typeof window>"u"||(Ve=true,ge=e.ignoreUrlPrefix??null,nn(),on(),rn());}function Qt(){return {consoleLog:Ye.slice(),networkLog:ae.slice()}}function ie(e,t){e.push(t),e.length>200&&e.splice(0,e.length-200);}function en(e){let t=[];for(let o of e){if(typeof o=="string"){t.push(o);continue}if(o instanceof Error){t.push(`${o.name}: ${o.message}${o.stack?`
3
+ ${o.stack}`:""}`);continue}try{t.push(JSON.stringify(o,tn));}catch{t.push(String(o));}}let n=t.join(" ");return n.length>4096?n.slice(0,4096)+"\u2026[truncated]":n}function tn(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function nn(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let o=e[n]?.bind(e);o&&(e[n]=(...r)=>{try{ie(Ye,{level:n,ts:Date.now(),message:en(r)});}catch{}o(...r);});}}function Ge(e){return ge?e.startsWith(ge):false}function on(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let o=typeof t=="string"?t:t instanceof URL?t.toString():t.url,r=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(Ge(o))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return ie(ae,{type:"fetch",method:r,url:be(o),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw ie(ae,{type:"fetch",method:r,url:be(o),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function rn(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(o,r,...a){return this.__lumen={method:String(o).toUpperCase(),url:typeof r=="string"?r:r.toString(),t:0},t.call(this,o,r,...a)},e.prototype.send=function(o){let r=this.__lumen;if(r&&!Ge(r.url)){r.t=performance.now();let a=()=>{try{ie(ae,{type:"xhr",method:r.method,url:be(r.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-r.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",a);};this.addEventListener("loadend",a);}return n.call(this,o??null)};}function be(e){return e.length>512?e.slice(0,512)+"\u2026":e}function Je(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:ze(e),consoleLog:[],networkLog:[]};let t=Qt();return {url:window.location.href,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:ze(e),device:an(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function an(){let e={};try{e.screen={width:window.screen?.width??0,height:window.screen?.height??0},e.pixelRatio=window.devicePixelRatio??1,e.language=navigator.language,e.languages=Array.from(navigator.languages??[]),e.timezone=Intl.DateTimeFormat().resolvedOptions().timeZone,e.colorScheme=window.matchMedia?.("(prefers-color-scheme: dark)").matches?"dark":"light",e.referrer=document.referrer||void 0,e.title=document.title||void 0,e.online=navigator.onLine,performance.getEntriesByType("navigation")[0]&&(e.uptimeMs=Math.round(performance.now()));}catch{}return e}function ze(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}async function Ze(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new R("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new R("Microphone access denied or unavailable.","MIC_DENIED")}let n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(u=>MediaRecorder.isTypeSupported(u))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),r=[],a=performance.now(),i=null;o.addEventListener("dataavailable",u=>{u.data&&u.data.size>0&&r.push(u.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);function s(){i!==null&&window.clearTimeout(i),i=null;for(let u of t.getTracks())u.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}s();},stop(){return new Promise((u,c)=>{if(o.state==="inactive"){s(),c(new R("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let f=performance.now()-a,b=o.mimeType||n||"audio/webm",v=new Blob(r,{type:b});s(),u({blob:v,durationMs:f,mimeType:b});},{once:true}),o.stop();})}}}async function Qe(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new R("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new R("Screen capture was denied or cancelled.","SCREEN_DENIED")}let n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(c=>MediaRecorder.isTypeSupported(c))??"",o=new MediaRecorder(t,n?{mimeType:n}:void 0),r=[],a=performance.now(),i=null;o.addEventListener("dataavailable",c=>{c.data&&c.data.size>0&&r.push(c.data);}),o.start(),i=window.setTimeout(()=>{o.state!=="inactive"&&o.stop();},e*1e3);let s=t.getVideoTracks()[0];s&&s.addEventListener("ended",()=>{o.state!=="inactive"&&o.stop();});function u(){i!==null&&window.clearTimeout(i),i=null;for(let c of t.getTracks())c.stop();}return {stream:t,cancel(){try{o.state!=="inactive"&&o.stop();}catch{}u();},stop(){return new Promise((c,f)=>{if(o.state==="inactive"){u(),f(new R("Recorder already stopped.","RECORDER_STOPPED"));return}o.addEventListener("stop",()=>{let b=performance.now()-a,v=o.mimeType||n||"video/webm",x=new Blob(r,{type:v});u(),c({blob:x,durationMs:b,mimeType:v});},{once:true}),o.stop();})}}}var he=react.createContext(null);function Z(){let e=react.useContext(he);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}function nt({screenshot:e,tool:t,color:n="rgb(239, 68, 68)",strokeWidth:o=4,onDrawingChange:r,ref:a}){let i=react.useRef(null),s=react.useRef(null),u=react.useRef(null),[c,f]=react.useState(null),[b,v]=react.useState([]),x=react.useRef(null),y=react.useRef(false),E=react.useRef(0),C=react.useRef(false);react.useEffect(()=>{let m=false,p=null;return (async()=>{try{let w=await createImageBitmap(e);if(m){w.close?.();return}p=w,f(w);}catch{}})(),()=>{m=true,p?.close?.();}},[e]),react.useEffect(()=>{if(!c)return;let m=i.current,p=s.current;if(!m||!p)return;m.width=c.width,m.height=c.height,p.width=c.width,p.height=c.height;let w=m.getContext("2d");w&&(w.imageSmoothingEnabled=false,w.drawImage(c,0,0));},[c]),react.useEffect(()=>{let m=s.current;m&&le(m,b,x.current);},[b]),react.useImperativeHandle(a,()=>({hasAnnotations:()=>b.length>0,reset:()=>v([]),undo:()=>v(m=>m.length===0?m:m.slice(0,-1)),async flatten(){let m=x.current,p=m?[...b,m]:b;if(p.length===0||!c)return e;let w=document.createElement("canvas");w.width=c.width,w.height=c.height;let L=w.getContext("2d");if(!L)return e;L.imageSmoothingEnabled=false,L.drawImage(c,0,0);for(let I of p)ve(L,I);return await new Promise(I=>{w.toBlob(O=>{I(O??e);},"image/jpeg",.85);})}}),[b,c,e]);function k(m){let p=s.current;if(!p)return {x:0,y:0};let w=p.getBoundingClientRect(),L=p.width/Math.max(w.width,1),I=p.height/Math.max(w.height,1);return {x:(m.clientX-w.left)*L,y:(m.clientY-w.top)*I}}function M(){C.current||(C.current=true,requestAnimationFrame(()=>{C.current=false;let m=s.current;m&&le(m,b,x.current);}));}function N(m){if(m.button!==void 0&&m.button!==0)return;try{m.currentTarget.setPointerCapture(m.pointerId);}catch{}y.current=true,r?.(true);let p=k(m);t==="arrow"?x.current={kind:"arrow",from:p,to:p,color:n,width:o}:t==="rect"?x.current={kind:"rect",from:p,to:p,color:n,width:o}:x.current={kind:"freehand",points:[p],color:n,width:o},E.current=performance.now(),M();}function S(m){if(!y.current||!x.current)return;let p=k(m),w=x.current;if(w.kind==="arrow"||w.kind==="rect")w.to=p;else {let L=w.points[w.points.length-1],I=L?(L.x-p.x)**2+(L.y-p.y)**2:1/0,O=performance.now(),j=O-E.current;(I>16||j>16)&&(w.points.push(p),E.current=O);}M();}function D(){if(!y.current)return;y.current=false,r?.(false);let m=x.current;if(x.current=null,!!m){if(m.kind==="arrow"||m.kind==="rect"){let p=m.to.x-m.from.x,w=m.to.y-m.from.y;if(p*p+w*w<16){let L=s.current;L&&le(L,b,null);return}}else if(m.points.length<2){let p=s.current;p&&le(p,b,null);return}v(p=>[...p,m].slice(-50));}}return jsxRuntime.jsxs("div",{ref:u,className:"lumen-annotate-frame",children:[jsxRuntime.jsx("canvas",{ref:i}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:N,onPointerMove:S,onPointerUp:D,onPointerCancel:D})]})}function le(e,t,n){let o=e.getContext("2d");if(o){o.clearRect(0,0,e.width,e.height);for(let r of t)ve(o,r);n&&ve(o,n);}}function ve(e,t){if(e.save(),e.strokeStyle=t.color,e.fillStyle=t.color,e.lineWidth=t.width,e.lineCap="round",e.lineJoin="round",t.kind==="rect"){let n=Math.min(t.from.x,t.to.x),o=Math.min(t.from.y,t.to.y),r=Math.abs(t.to.x-t.from.x),a=Math.abs(t.to.y-t.from.y);e.strokeRect(n,o,r,a);}else if(t.kind==="freehand")dn(e,t.points);else {let{from:n,to:o,width:r}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(o.x,o.y),e.stroke();let a=Math.atan2(o.y-n.y,o.x-n.x),i=Math.max(12,r*4);e.beginPath(),e.moveTo(o.x,o.y),e.lineTo(o.x-i*Math.cos(a-Math.PI/7),o.y-i*Math.sin(a-Math.PI/7)),e.lineTo(o.x-i*Math.cos(a+Math.PI/7),o.y-i*Math.sin(a+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function dn(e,t){if(t.length===0)return;e.beginPath();let n=t[0];if(!n)return;if(e.moveTo(n.x,n.y),t.length===1){e.arc(n.x,n.y,e.lineWidth/2,0,Math.PI*2),e.fill();return}if(t.length===2){let r=t[1];e.lineTo(r.x,r.y),e.stroke();return}for(let r=1;r<t.length-1;r++){let a=t[r],i=t[r+1],s=(a.x+i.x)/2,u=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,s,u);}let o=t[t.length-1];e.lineTo(o.x,o.y),e.stroke();}var ye=60,pn=60,ot=[{label:"Red",value:"rgb(239, 68, 68)"},{label:"Amber",value:"rgb(245, 158, 11)"},{label:"Blue",value:"rgb(59, 130, 246)"},{label:"Green",value:"rgb(34, 197, 94)"},{label:"Neutral",value:"rgb(244, 244, 245)"}],rt=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],at=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],fn=[{value:"shot",label:"Screenshot",hint:"This page, instantly"},{value:"screen",label:"Screen",hint:"Pick a window or tab"},{value:"video",label:"Video",hint:"Record up to 60s"}];function Ee(){let{client:e,isOpen:t,closeCapture:n,user:o,capture:r}=Z(),[a,i]=react.useState(1),[s,u]=react.useState(null),[c,f]=react.useState({kind:"idle"}),[b,v]=react.useState(false),[x,y]=react.useState(0),[E,C]=react.useState(null),[k,M]=react.useState("arrow"),[N,S]=react.useState(ot[0].value),[D,m]=react.useState(rt[1].value),[p,w]=react.useState(""),[L,I]=react.useState("bug"),[O,j]=react.useState(o?.email??""),[A,q]=react.useState(null),[B,Y]=react.useState(null),[St,de]=react.useState(0),[K,Q]=react.useState(null),[U,me]=react.useState(null),[At,Pt]=react.useState(false),ee=react.useRef(null),Te=react.useRef(null),Me=react.useRef(null),X=react.useRef(false);if(react.useEffect(()=>{if(t)return X.current=false,i(1),u(null),w(""),Y(null),de(0),me(null),v(false),y(0),C(null),Q(l=>(l?.cancel(),null)),f(r?.mode==="manual"?{kind:"manual"}:{kind:"idle"}),()=>{X.current=true;}},[t,r]),react.useEffect(()=>{if(!t)return;Me.current=document.activeElement??null;let l=document.documentElement,h=l.style.overflow,P=l.style.paddingRight,H=window.innerWidth-l.clientWidth;l.style.overflow="hidden",H>0&&(l.style.paddingRight=`${H}px`);let F=false,_=()=>{if(!F){F=true,l.style.overflow=h,l.style.paddingRight=P;try{Me.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",_),()=>{window.removeEventListener("pagehide",_),_();}},[t]),react.useEffect(()=>{if(!t)return;function l(h){if(h.key==="Escape"){h.preventDefault(),n();return}if(h.key!=="Tab")return;let P=Te.current;if(!P)return;let H=En(P);if(H.length===0)return;let F=H[0],_=H[H.length-1],fe=document.activeElement;h.shiftKey&&(fe===F||!P.contains(fe))?(h.preventDefault(),_.focus()):!h.shiftKey&&fe===_&&(h.preventDefault(),F.focus());}return document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l)},[t,n]),react.useEffect(()=>{if(!t||c.kind!=="manual")return;function l(h){let F=Array.from(h.clipboardData?.items??[]).find(_=>_.type.startsWith("image/"))?.getAsFile();F&&(h.preventDefault(),Se(F));}return window.addEventListener("paste",l),()=>window.removeEventListener("paste",l)},[t,c.kind]),react.useEffect(()=>{if(!A)return;let l=Date.now(),h=window.setInterval(()=>{let P=Math.floor((Date.now()-l)/1e3);de(P),P>=ye&&Pe();},250);return ()=>window.clearInterval(h)},[A]),!t)return null;async function pe(l){X.current=false,f({kind:"capturing"});try{let h=await We({...r,mode:l,target:r?.target??document.documentElement});return X.current?!1:(It(h),f({kind:"ready",capture:h}),!0)}catch(h){return X.current||f({kind:"manual",error:h instanceof Error?h.message:"Automatic screenshot capture was unavailable."}),false}}async function Ne(l){u(l),C(null),l!=="video"&&De(),l==="shot"?await pe(r?.mode??"auto"):l==="screen"?await pe("true-screen"):await pe(r?.mode??"auto")&&await Ie();}function Se(l){if(!l.type.startsWith("image/")){sonner.toast.error("Choose a PNG, JPEG, or WebP screenshot.");return}let h=$e(l,["Manual screenshot upload used."]);f({kind:"ready",capture:h});}function It(l){l.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function Ae(){try{let l=await Ze(ye);q(l);}catch(l){sonner.toast.error(l instanceof Error?l.message:"Microphone unavailable");}}async function Pe(){if(A)try{let l=await A.stop();Y({blob:l.blob,durationMs:l.durationMs});}catch(l){sonner.toast.error(l instanceof Error?l.message:"Could not stop recording");}finally{q(null);}}function Dt(){A?.cancel(),q(null),Y(null),de(0);}async function Ie(){try{let l=await Qe(pn);Q(l),l.stream.getVideoTracks()[0]?.addEventListener("ended",()=>{te();});}catch(l){sonner.toast.error(l instanceof Error?l.message:"Screen capture unavailable");}}async function te(){if(!K)return;let l=K;Q(null);try{let h=await l.stop();me({blob:h.blob,durationMs:h.durationMs});}catch(h){sonner.toast.error(h instanceof Error?h.message:"Could not stop recording");}}function De(){K?.cancel(),Q(null),me(null);}let Ot=c.kind==="ready";async function Ht(){if(a===1){if(K&&await te(),c.kind==="ready"){let l=await ee.current?.flatten();C(l??c.capture.blob);}i(2);}else a===2?i(3):await Bt();}function Ft(){a>1&&i(l=>l-1);}async function Bt(){if(c.kind!=="ready")return;let l=p.trim(),{capture:h}=c;v(true),y(0);try{let P=E??h.blob,H=await e.submit({rawText:l.length>0?l:void 0,category:L,submitterEmail:O.trim()||void 0,screenshot:P,audio:B?.blob,audioDurationMs:B?.durationMs,video:U?.blob,videoDurationMs:U?.durationMs,context:Je(h)},{onUploadProgress:F=>y(Math.min(.95,F))});y(1),sonner.toast.success("Feedback sent \u2014 thank you."),H.id,n();}catch(P){sonner.toast.error(P instanceof Error?P.message:"Could not submit feedback"),v(false);}}function _t(l){l.target===l.currentTarget&&!b&&n();}let ne=Math.round(x*100),oe=s==="video",Vt=a===1&&!Ot||b,zt=a<3?"Next":b?ne<95?`Uploading ${ne}%\u2026`:"Almost done\u2026":"Send feedback";return jsxRuntime.jsx("div",{role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",onMouseDown:_t,children:jsxRuntime.jsxs("div",{ref:Te,className:"lumen-modal","data-lumen-drawing":At?"true":void 0,children:[jsxRuntime.jsx(bn,{onDismiss:n}),jsxRuntime.jsxs("header",{className:"lumen-modal-header",children:[jsxRuntime.jsxs("h2",{className:"lumen-modal-title",children:[jsxRuntime.jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsxRuntime.jsx(gn,{step:a}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[a===1?jsxRuntime.jsxs("div",{className:"lumen-pane",children:[jsxRuntime.jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:fn.map(l=>jsxRuntime.jsxs("button",{type:"button",className:"lumen-method-btn","aria-pressed":s===l.value,onClick:()=>Ne(l.value),disabled:c.kind==="capturing",children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:l.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:l.hint})]},l.value))}),c.kind==="idle"?jsxRuntime.jsxs("div",{className:"lumen-cap-empty",children:[jsxRuntime.jsx("p",{children:"Pick a capture method above \u2014 nothing is captured until you choose, so take your time positioning the screen."}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>f({kind:"manual"}),children:"Or upload a screenshot"})]}):null,c.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,c.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:c.error?"Automatic capture was unavailable. Upload or paste a screenshot to continue.":"Upload or paste a screenshot to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:"Choose or paste a screenshot"}),jsxRuntime.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:l=>{let h=l.currentTarget.files?.[0];h&&Se(h),l.currentTarget.value="";}})]})]}):null,c.kind==="ready"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[oe?null:jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(xe,{label:"Arrow",active:k==="arrow",onClick:()=>M("arrow")}),jsxRuntime.jsx(xe,{label:"Box",active:k==="rect",onClick:()=>M("rect")}),jsxRuntime.jsx(xe,{label:"Draw",active:k==="freehand",onClick:()=>M("freehand")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:ot.map(l=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:l.value},"aria-label":l.label,"aria-pressed":N===l.value,onClick:()=>S(l.value)},l.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:rt.map(l=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":l.label,"aria-pressed":D===l.value,onClick:()=>m(l.value),children:jsxRuntime.jsx("span",{className:"lumen-stroke-size-dot",style:{width:l.dot,height:l.dot}})},l.value))}),jsxRuntime.jsx("span",{className:"lumen-toolbar-spacer"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>ee.current?.undo(),children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>ee.current?.reset(),children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(nt,{ref:ee,screenshot:c.capture.blob,tool:k,color:N,strokeWidth:D,onDrawingChange:Pt})}),jsxRuntime.jsxs("div",{className:"lumen-cap-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>s&&Ne(s),children:oe?"\u21BB Re-record":"\u21BB Recapture"}),oe?K?jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"lumen-rec-time",children:"Recording\u2026"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:te,children:"Stop"})]}):U?jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round(U.durationMs/1e3),"s recorded"]}):null:jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:[it(s)," captured \xB7 switch method above anytime"]})]})]}):null]}):null,a===2?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-form",children:[jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"What happened?"}),jsxRuntime.jsx("textarea",{value:p,onChange:l=>w(l.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Add a voice note (optional)"}),jsxRuntime.jsxs("div",{className:"lumen-audio-row",children:[!A&&!B?jsxRuntime.jsx("button",{type:"button",onClick:Ae,className:"lumen-btn-ghost",children:"Record voice note"}):null,A?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(hn,{stream:A.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[St,"s / ",ye,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:Pe,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:Dt,className:"lumen-btn-ghost",children:"Cancel"})]}):null,B&&!A?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(vn,{blob:B.blob,durationMs:B.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>Y(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]})]}),jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Category"}),jsxRuntime.jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:at.map(l=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":L===l.value,onClick:()=>I(l.value),children:l.label},l.value))})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Your email (optional)"}),jsxRuntime.jsx("input",{type:"email",value:O,onChange:l=>j(l.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,a===3?jsxRuntime.jsxs("div",{className:"lumen-pane lumen-review",children:[jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[it(s),oe?"":" \xB7 annotated",jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>i(1),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Category"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[jsxRuntime.jsx("span",{className:"lumen-chip",children:at.find(l=>l.value===L)?.label}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>i(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Description"}),jsxRuntime.jsxs("span",{className:"lumen-review-v",children:[p.trim()?p.trim():jsxRuntime.jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>i(2),children:"edit"})]})]}),jsxRuntime.jsxs("div",{className:"lumen-review-row",children:[jsxRuntime.jsx("span",{className:"lumen-review-k",children:"Material"}),jsxRuntime.jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[B?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(B.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>Y(null),children:"\xD7"})]}):null,U?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round(U.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:De,children:"\xD7"})]}):null,O.trim()?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u2709 ",O.trim()]}):null,!B&&!A?jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{i(2),Ae();},children:"+ Voice note"}):null,K?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-attach",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),"Recording\u2026"]}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:te,children:"Stop"})]}):U?null:jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:Ie,children:"+ Screen recording"})]})]})]}):null]}),jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[b?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":ne,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${ne}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:a===1?n:Ft,className:"lumen-btn-ghost",disabled:b,children:a===1?"Cancel":"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:Ht,className:"lumen-btn-primary",disabled:Vt,children:zt})]})]})]})})}function it(e){return e==="video"?"Screen recording":e==="screen"?"Screen capture":"Screenshot"}function gn({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsxRuntime.jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,o)=>jsxRuntime.jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsxRuntime.jsx("span",{className:"lumen-step-num",children:n.n}),jsxRuntime.jsx("span",{className:"lumen-step-lbl",children:n.label}),o<t.length-1?jsxRuntime.jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function xe({label:e,active:t,onClick:n}){return jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function bn({onDismiss:e}){let t=react.useRef(null),n=react.useRef(0),o=react.useRef(null);function r(s){s.currentTarget.setPointerCapture(s.pointerId),t.current=s.clientY,n.current=performance.now(),o.current=s.currentTarget.parentElement;}function a(s){if(t.current==null||!o.current)return;let u=Math.max(0,s.clientY-t.current);o.current.style.transform=`translateY(${u}px)`;}function i(s){if(t.current==null||!o.current)return;let u=Math.max(0,s.clientY-t.current),c=Math.max(1,performance.now()-n.current),f=u/c;o.current.style.transform="",o.current.style.transition="",t.current=null,(u>80||f>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:r,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function hn({stream:e}){let t=react.useRef(null);return react.useEffect(()=>{let n=t.current;if(!n)return;let o=Math.min(window.devicePixelRatio||1,2),r=n.clientWidth||88,a=n.clientHeight||22;n.width=Math.round(r*o),n.height=Math.round(a*o);let i=n.getContext("2d");if(!i)return;i.scale(o,o);let s=window.AudioContext??window.webkitAudioContext;if(!s)return;let u=new s,c=u.createMediaStreamSource(e),f=u.createAnalyser();f.fftSize=1024,f.smoothingTimeConstant=.6,c.connect(f);let b=new Uint8Array(f.fftSize),v=18,x=3,y=3,E=Math.max(2,(r-x*(v-1))/v),C=Math.min(E/2,3),k=new Array(v).fill(0),M=0,N=false;function S(){if(N)return;f.getByteTimeDomainData(b);let D=Math.floor(b.length/v);i.clearRect(0,0,r,a),i.fillStyle=yn("--lumen-danger")||"rgb(239,68,68)";for(let m=0;m<v;m++){let p=0;for(let A=0;A<D;A++){let q=Math.abs((b[m*D+A]??128)-128);q>p&&(p=q);}let w=Math.min(1,p/128*1.8),L=k[m]??0;k[m]=w>L?w:L+(w-L)*.35;let I=Math.max(y,k[m]*a),O=m*(E+x),j=(a-I)/2;wn(i,O,j,E,I,C),i.fill();}M=requestAnimationFrame(S);}return M=requestAnimationFrame(S),()=>{N=true,cancelAnimationFrame(M);try{c.disconnect();}catch{}u.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function wn(e,t,n,o,r,a){let i=Math.min(a,o/2,r/2);e.beginPath();let s=e;if(typeof s.roundRect=="function"){s.roundRect(t,n,o,r,i);return}e.moveTo(t+i,n),e.arcTo(t+o,n,t+o,n+r,i),e.arcTo(t+o,n+r,t,n+r,i),e.arcTo(t,n+r,t,n,i),e.arcTo(t,n,t+o,n,i),e.closePath();}function vn({blob:e,durationMs:t}){let[n,o]=react.useState("");return react.useEffect(()=>{let r=URL.createObjectURL(e);return o(r),()=>{URL.revokeObjectURL(r);}},[e]),jsxRuntime.jsxs("div",{className:"lumen-audio-preview",children:[jsxRuntime.jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxRuntime.jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function yn(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var xn='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function En(e){return Array.from(e.querySelectorAll(xn)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function st(){if(typeof document>"u"||typeof window>"u")return 0;let e=window.innerWidth,t=window.innerHeight;if(e===0||t===0)return 0;let n=t-4,o=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],r=new Set,a=0;for(let i of o){let s=document.elementsFromPoint(i,n);for(let u of s){if(r.has(u))continue;r.add(u);let c=window.getComputedStyle(u);if(c.position!=="fixed"&&c.position!=="sticky")continue;let f=u.getBoundingClientRect();f.bottom<t-8||f.bottom>t+8||f.width<e*.6||f.height>a&&(a=f.height);}}return a}function Ce(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,o=window.innerHeight,r=0;for(let a of e){let i;try{i=document.querySelectorAll(a);}catch{continue}for(let s of Array.from(i)){let u=s.getBoundingClientRect();if(u.height===0||u.width===0)continue;let c=0;switch(t){case "bottom":if(u.bottom<o-8)break;c=Math.max(0,o-u.top);break;case "top":if(u.top>8)break;c=Math.max(0,u.bottom);break;case "left":if(u.left>8)break;c=Math.max(0,u.right);break;case "right":if(u.right<n-8)break;c=Math.max(0,n-u.left);break}c>r&&(r=c);}}return r}function lt(e){let[t,n]=react.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),o=react.useRef(t),r=Rn(e.avoid),a=e.placement,i=e.offset.x,s=e.offset.y;return react.useEffect(()=>{if(typeof window>"u")return;let u=0,c=false,f=()=>{if(u=0,c)return;let E=a[0]==="b"?"bottom":"top",C=a[1]==="r"?"right":"left",k=0,M=0;e.avoid==="auto"&&E==="bottom"?k=st():Array.isArray(e.avoid)&&(k=Ce(e.avoid,E),M=Ce(e.avoid,C));let N={bottom:E==="bottom"?s+k:0,top:E==="top"?s+k:0,right:C==="right"?i+M:0,left:C==="left"?i+M:0},S=o.current;(N.bottom!==S.bottom||N.top!==S.top||N.right!==S.right||N.left!==S.left)&&(o.current=N,n(N));},b=()=>{u||(u=window.requestAnimationFrame(f));};b();let v=typeof ResizeObserver<"u"?new ResizeObserver(b):null;v?.observe(document.documentElement);let x=typeof MutationObserver<"u"?new MutationObserver(b):null;x?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",b);let y=window.visualViewport;return y?.addEventListener("resize",b),y?.addEventListener("scroll",b),()=>{c=true,u&&window.cancelAnimationFrame(u),v?.disconnect(),x?.disconnect(),window.removeEventListener("resize",b),y?.removeEventListener("resize",b),y?.removeEventListener("scroll",b);}},[a,i,s,r]),t}function Rn(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function ut(e){let[t,n]=react.useState(false);return react.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;let o=window.visualViewport;if(!o||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let r=100,a=0,i=()=>{a=0;let u=window.innerHeight-o.height;n(u>r);},s=()=>{a||(a=window.requestAnimationFrame(i));};return s(),o.addEventListener("resize",s),o.addEventListener("scroll",s),()=>{a&&window.cancelAnimationFrame(a),o.removeEventListener("resize",s),o.removeEventListener("scroll",s);}},[e]),t}function pt({config:e,portalTarget:t,hidden:n,onClick:o}){let[r,a]=react.useState(null),i=react.useRef(null),s=lt(e),u=ut(e.hideOnKeyboard);if(react.useEffect(()=>{typeof document>"u"||a(t??document.body);},[t]),An(i,!n&&!u),!r)return null;let c=e.placement,f=c[0]==="b"?"bottom":"top",b=c[1]==="r"?"right":"left",v=f==="bottom"?s.bottom:s.top,x=b==="right"?s.right:s.left,y={position:"fixed",[f]:e.safeArea?`calc(${v}px + env(safe-area-inset-${f}, 0px))`:`${v}px`,[b]:e.safeArea?`calc(${x}px + env(safe-area-inset-${b}, 0px))`:`${x}px`,zIndex:e.zIndex,opacity:n||u?0:1,pointerEvents:n||u?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:i,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:y,"aria-label":e.label,"aria-hidden":n||u?true:void 0,tabIndex:n||u?-1:0,onClick:o,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),r)}function An(e,t){let n=react.useRef(false);react.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let o=window.setTimeout(()=>{let r=e.current;if(!r)return;let a=r.getBoundingClientRect();if(a.width===0||a.height===0)return;let i=a.left+a.width/2,s=a.top+a.height/2,u=document.elementsFromPoint(i,s),c=ct(window.getComputedStyle(r).zIndex);for(let f of u){if(f===r||r.contains(f))continue;if(ct(window.getComputedStyle(f).zIndex)>c){n.current=true,console.warn("[lumen] trigger is occluded by",f);break}}},250);return ()=>window.clearTimeout(o)},[t,e]);}function ct(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function ft({mount:e,label:t,icon:n,onClick:o}){let[r,a]=react.useState(null);return react.useEffect(()=>{if(typeof document>"u")return;let i=e instanceof HTMLElement?e:e.current??null;a(i);},[e]),r?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onClick:o,"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsxRuntime.jsx("span",{children:t})]}),r):null}function ht({config:e,portalTarget:t,hidden:n,onClick:o}){let[r,a]=react.useState(null),[i,s]=react.useState(false),u=react.useRef(null);if(react.useEffect(()=>{typeof document>"u"||a(t??document.body);},[t]),!r)return null;let c=`lumen-notch lumen-notch-${e.edge}${i?" lumen-notch-expanded":""}`;function f(y){u.current={x:y.clientX,y:y.clientY},s(true),y.currentTarget.setPointerCapture(y.pointerId);}function b(y){let E=u.current;if(!E)return;let C=y.clientX-E.x,k=y.clientY-E.y;(e.edge==="top"&&k>16||e.edge==="bottom"&&k<-16||e.edge==="right"&&C<-16||e.edge==="left"&&C>16)&&(u.current=null,o());}function v(){u.current=null,s(false);}function x(){u.current=null,s(false);}return reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:c,style:{zIndex:e.zIndex,opacity:n?0:1,pointerEvents:n?"none":"auto"},"aria-label":e.label,"aria-hidden":n?true:void 0,tabIndex:n?-1:0,onClick:o,onPointerDown:f,onPointerMove:b,onPointerUp:v,onPointerCancel:x,onMouseEnter:()=>s(true),onMouseLeave:()=>s(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),r)}function wt(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function vt(e){return {kind:"floating",placement:e.placement??"br",offset:{x:e.offset?.x??16,y:e.offset?.y??16},safeArea:e.safeArea??true,avoid:e.avoid===false?false:e.avoid==null?"auto":Array.isArray(e.avoid)?e.avoid:[e.avoid],hideOnKeyboard:e.hideOnKeyboard??true,zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var qn={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-primary":"accent","--lumen-radius":"radius"};function yt(e){let t=react.useId();react.useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,o=`data-lumen-theme-${Kn(t)}`,r={};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")r["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else for(let[a,i]of Object.entries(qn)){let s=e[i];typeof s=="string"&&s.length>0&&(r[a]=n.style.getPropertyValue(a)||null,n.style.setProperty(a,s));}return n.setAttribute(o,""),()=>{n.removeAttribute(o);for(let[a,i]of Object.entries(r))a.startsWith("--")?i?n.style.setProperty(a,i):n.style.removeProperty(a):i==null?n.removeAttribute(a):n.setAttribute(a,i);}},[e,t]);}function Kn(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var xt=Symbol.for("lumen.history.patched"),ke="lumen:locationchange";function Xn(){if(typeof window>"u")return;let e=window;if(e[xt])return;e[xt]=true;let t=()=>window.dispatchEvent(new Event(ke)),n=history.pushState;history.pushState=function(...r){let a=n.apply(this,r);return t(),a};let o=history.replaceState;history.replaceState=function(...r){let a=o.apply(this,r);return t(),a},window.addEventListener("popstate",t);}function Et(e){let[t,n]=react.useState(false);return react.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;Xn();let o=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return o(),window.addEventListener(ke,o),window.addEventListener("popstate",o),()=>{window.removeEventListener(ke,o),window.removeEventListener("popstate",o);}},[e]),t}var Zn=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function Ct(){let[e,t]=react.useState(false);return react.useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let o=n.webkit;if(o&&o.messageHandlers){t(true);return}let r=navigator.userAgent||"";Zn.some(a=>r.includes(a))&&t(true);},[]),e}var Lt="lumen.config.v1.",to=3600*1e3;function Rt(e,t){let[n,o]=react.useState(()=>({trigger:null,enabled:true,loading:true}));return react.useEffect(()=>{if(typeof window>"u")return;let r=ro(e);r&&o({trigger:r.trigger,enabled:kt(r.trigger),loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),s=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(s,{method:"GET",mode:"cors",credentials:"omit",signal:a.signal}).then(async u=>{if(!u.ok)throw new Error(`HTTP ${u.status}`);let c=await u.json(),f=Tt(c.trigger);if(!f)throw new Error("Malformed config response");ao(e,f),o({trigger:f,enabled:kt(f),loading:false});}).catch(()=>{o(u=>u.loading?{trigger:null,enabled:true,loading:false}:u);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function kt(e){return e.kind!=="headless"}var no=["br","bl","tr","tl"],oo=["top","right","bottom","left"];function Tt(e){if(!e||typeof e!="object")return null;let t=e;if(t.enabled===false)return {kind:"headless"};let n=typeof t.label=="string"?t.label:"Feedback";return t.kind==="floating"?{kind:"floating",placement:no.find(r=>r===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:oo.find(r=>r===t.edge)??"top",label:n}:null}function ro(e){try{let t=window.localStorage.getItem(Lt+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>to)return null;let o=Tt(n.trigger);return o?{fetchedAt:n.fetchedAt,trigger:o}:null}catch{return null}}function ao(e,t){try{window.localStorage.setItem(Lt+e,JSON.stringify({fetchedAt:Date.now(),trigger:t}));}catch{}}var Nt="https://shakebugs.vercel.app";function so({apiKey:e,apiUrl:t,user:n,amplitude:o,floatingButton:r=true,trigger:a,hideOn:i,theme:s,portalTarget:u,capture:c,children:f}){let[b,v]=react.useState(false),[x]=react.useState(false),[y]=react.useState(null),E=react.useMemo(()=>new Ue({apiKey:e,apiUrl:t,user:n,amplitude:o}),[e,t,n?.id,n?.email,n?.name,o?.userId,o?.deviceId,o?.sessionId]);react.useEffect(()=>{Xe({ignoreUrlPrefix:(t??Nt).replace(/\/$/,"")});},[t]);let C=react.useCallback(()=>v(true),[]),k=react.useCallback(()=>v(false),[]),M=react.useCallback(E.submit.bind(E),[E]),N=Ct(),S=Et(i);yt(s);let D=Rt(a?"":e,t??Nt),m=react.useMemo(()=>({client:E,user:n,isOpen:b,isSubmitting:x,error:y,open:C,close:k,openCapture:C,closeCapture:k,submit:M,isNativeShell:N,capture:c}),[E,n,b,x,y,C,k,M,N,c]),p=lo({explicit:a,remote:D.trigger,remoteLoading:D.loading,floatingButton:r});return jsxRuntime.jsxs(he.Provider,{value:m,children:[f,p?.kind==="floating"?jsxRuntime.jsx(pt,{config:vt(p),portalTarget:u,hidden:S,onClick:C}):null,p?.kind==="notch"?jsxRuntime.jsx(ht,{config:wt(p),portalTarget:u,hidden:S,onClick:C}):null,p?.kind==="inline"?jsxRuntime.jsx(ft,{mount:p.mount,label:p.label??"Feedback",icon:p.icon,onClick:C}):null,jsxRuntime.jsx(Ee,{})]})}function lo(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function co({variant:e="default",floating:t=false,className:n,children:o="Feedback",onClick:r,...a}){let{openCapture:i}=Z(),s=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsxRuntime.jsx("button",{type:"button",className:s,onClick:u=>{r?.(u),u.defaultPrevented||i();},...a,children:o})}
4
+ exports.CaptureModal=Ee;exports.FeedbackButton=co;exports.LumenProvider=so;exports.useLumen=Z;//# sourceMappingURL=index.cjs.map
5
5
  //# sourceMappingURL=index.cjs.map