@lumen-stack/react 0.9.1 → 0.9.3

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 $t=require('react'),sonner=require('sonner'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var $t__namespace=/*#__PURE__*/_interopNamespace($t);var T=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},bt=class extends T{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},vt=class extends T{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},Fe=class extends T{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},Fn="https://shakebugs.vercel.app",Un="/api/v1/sdk/submit",Wn=new Set([502,503,504]),St=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??Fn).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${Un}`,r=this.#e(e),o=null;for(let a=0;a<3;a++){a>0&&await zn(2**a*250);try{return await this.#t(n,r,t)}catch(i){if(o=i,i instanceof bt||i instanceof vt||i instanceof T&&typeof i.status=="number"&&!Wn.has(i.status))throw i}}throw o instanceof Error?o:new Fe("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,r=n?{...e.context,amplitude:n}:e.context;return t.append("context",JSON.stringify(r)),e.screenshot&&t.append("screenshot",e.screenshot,$n(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((r,o)=>{let a=new XMLHttpRequest;a.open("POST",e,true),a.setRequestHeader("X-Lumen-Api-Key",this.apiKey),a.responseType="text";let{onUploadProgress:i,signal:l}=n;i&&a.upload.addEventListener("progress",d=>{d.lengthComputable&&d.total>0&&i(Math.min(1,d.loaded/d.total));});let s=()=>{a.abort(),o(new Fe("Submit aborted."));};if(l){if(l.aborted){o(new Fe("Submit aborted."));return}l.addEventListener("abort",s,{once:true});}a.addEventListener("load",()=>{if(l&&l.removeEventListener("abort",s),a.status===403){o(new bt);return}if(a.status===429){let d=Number(a.getResponseHeader("Retry-After"))||60;o(new vt(d));return}if(a.status<200||a.status>=300){o(new T(qn(a.responseText)??`HTTP ${a.status}`,"HTTP_ERROR",a.status));return}try{let d=JSON.parse(a.responseText);r(d);}catch{o(new T("Malformed response from server.","BAD_RESPONSE"));}}),a.addEventListener("error",()=>{l&&l.removeEventListener("abort",s),o(new Fe("Network error during submit."));}),a.send(t);})}};function $n(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function zn(e){return new Promise(t=>setTimeout(t,e))}function qn(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var jn=2,Ae=8*1024*1024;async function $e(e={}){Nt();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return Qn(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 T("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return yt(e);if(t==="dom")return wt(e);if(t==="custom")throw new T("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await wt(e)}catch(n){if(Lt()){let r=await yt(e);return r.warnings=De(["DOM screenshot failed; used browser screen permission fallback.",...r.warnings]),e.onWarning?.(r.warnings),r}throw n}}function Ie(e,t=[]){Nt();let n=ze();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:De(t)}}async function wt(e){let t=await Zn(),n=e.target??document.documentElement,r=ze(),o=Math.max(1,Math.min(window.devicePixelRatio??1,e.maxScale??jn)),a=er(n);!e.provider&&Jn()&&a.unshift(`Lumen is capturing inside a React Native WebView with no native capture provider, so this screenshot is a DOM re-render \u2014 it won't match the native screen and omits native overlays/inputs. Wire createNativeCaptureProvider() with capture mode "custom" (see docs/native-screenshot-expo.md).`);let i=Yn(n),l=await t(n,{backgroundColor:null,logging:false,useCORS:true,allowTaint:false,width:r.width,height:r.height,windowWidth:r.width,windowHeight:r.height,scrollX:window.scrollX,scrollY:window.scrollY,x:window.scrollX,y:window.scrollY,scale:o,ignoreElements:d=>d instanceof HTMLElement&&(d.dataset.lumenCaptureIgnore==="true"||!!d.closest("[data-lumen-capture-ignore='true']")),onclone:(d,c)=>{Xn(c,i),Kn(d);}}),s={blob:await Pt(l,a),method:"web-dom",platform:"web",viewport:r,pixelRatio:o,warnings:De(a)};return s.warnings.length>0&&e.onWarning?.(s.warnings),s}var Mt=['input[type="password"]','input[autocomplete^="cc-"]','input[autocomplete="one-time-code"]',"[data-lumen-mask]"].join(", ");function Kn(e){for(let t of Array.from(e.querySelectorAll(Mt))){if(t.nodeName==="INPUT"||t.nodeName==="TEXTAREA"){let n=t;n.value&&(n.value="\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022");continue}t.style.visibility="hidden";}}var Gn="[data-lumen-root], [data-lumen-capture-ignore='true']";function Tt(e){return Array.from(e.querySelectorAll("input")).filter(t=>!t.closest(Gn))}function Yn(e){return Tt(e).map(t=>{if(t.matches(Mt))return {skip:true};let n=t.type;return n==="checkbox"||n==="radio"?{skip:false,checked:t.checked}:n==="file"?{skip:true}:{skip:false,value:t.value}})}function Xn(e,t){let n=Tt(e);n.length===t.length&&n.forEach((r,o)=>{let a=t[o];!a||a.skip||(a.checked!==void 0?r.checked=a.checked:a.value!==void 0&&(r.value=a.value));});}function Jn(){return typeof window<"u"&&typeof window.ReactNativeWebView<"u"}async function Zn(){let{default:e}=await import('html2canvas-pro');return e}async function yt(e){if(!Lt())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 n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.srcObject=t,await tr(n);let r=document.createElement("canvas");r.width=n.videoWidth,r.height=n.videoHeight;let o=r.getContext("2d");if(!o)throw new T("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");o.drawImage(n,0,0,r.width,r.height);let a=ze(),i=["Browser screen capture uses the window or tab selected by the user."],l={blob:await Pt(r,i),method:"web-display-media",platform:"web",viewport:a,pixelRatio:a.width>0?r.width/a.width:void 0,warnings:De(i)};return e.onWarning?.(l.warnings),l}finally{for(let n of t.getTracks())n.stop();}}function Qn(e,t){let n=ze(),r={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:De(e.warnings??[])};return r.warnings.length>0&&t.onWarning?.(r.warnings),r}function er(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 r of Array.from(e.querySelectorAll("img"))){let o=r.currentSrc||r.src;if(o)try{new URL(o,window.location.href).origin!==window.location.origin&&!r.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 Pt(e,t){let n=await Et(e,"image/png",.92);if(n.size<=Ae)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let r=e,o=0;for(;n.size>Ae&&o<6;){let a=Math.max(.35,Math.min(.95,Math.sqrt(Ae/n.size)*.9)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(r.width*a)),i.height=Math.max(1,Math.round(r.height*a));let l=i.getContext("2d");if(!l)return n;l.drawImage(r,0,0,i.width,i.height),r=i;for(let s of [.86,.74,.62,.5])if(n=await Et(r,"image/jpeg",s),n.size<=Ae)return n;if(o+=1,i.width<480||i.height<320)break}return n.size>Ae&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function Et(e,t,n){return new Promise((r,o)=>{e.toBlob(a=>{if(!a){o(new T("Could not encode screenshot.","ENCODE_FAILED"));return}r(a);},t,n);})}function ze(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function Lt(){return !!navigator.mediaDevices?.getDisplayMedia}async function tr(e){await new Promise((r,o)=>{let a=()=>r(),i=()=>o(new T("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 T("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(r=>requestAnimationFrame(()=>r()));}}function Nt(){if(typeof window>"u"||typeof document>"u")throw new T("Screenshot capture can only run in the browser.","INVALID_ENV")}function De(e){return Array.from(new Set(e.filter(Boolean)))}var At=/^(token|access_token|refresh_token|id_token|api_?key|key|secret|password|passwd|pwd|auth|authorization|sig|signature|session|sessionid|sid|email|jwt)$/i;function et(e){let t=e;return t=t.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._\-+/=]+/gi,"$1 ***"),t=t.replace(/\b([A-Za-z_][\w-]*)\s*[=:]\s*("?)([^"\s&]{6,})\2/g,(n,r,o,a)=>/^(Bearer|Basic)$/i.test(a)?n:At.test(r)?`${r}=${o}***${o}`:a.length>=24&&/^[A-Za-z0-9._\-+/=]+$/.test(a)&&!a.includes(" ")?`${r}=${o}${a.slice(0,4)}\u2026${o}`:n),t=t.replace(/\b[\w.+-]+@[\w-]+\.[\w.-]+\b/g,"***@***"),t}function It(e){try{let t=new URL(e,"http://relative.invalid");for(let r of [...t.searchParams.keys()])At.test(r)&&t.searchParams.set(r,"***");t.hash="";let n=t.toString();return et(t.host==="relative.invalid"?n.replace(/^http:\/\/relative\.invalid/,""):n)}catch{return et(e)}}function Dt(e){try{let t=new URL(e);return `${t.origin}${t.pathname}`}catch{return It(e)}}var Rt=200,Ct=4096,Ot=[],Ue=[],xt=false,tt=null;function Bt(e={}){xt||typeof window>"u"||(xt=true,tt=e.ignoreUrlPrefix??null,ar(),ir(),lr());}function nr(){return {consoleLog:Ot.slice(),networkLog:Ue.slice()}}function We(e,t){e.push(t),e.length>Rt&&e.splice(0,e.length-Rt);}function rr(e){let t=[];for(let r of e){if(typeof r=="string"){t.push(r);continue}if(r instanceof Error){t.push(`${r.name}: ${r.message}${r.stack?`
3
- ${r.stack}`:""}`);continue}try{t.push(JSON.stringify(r,or));}catch{t.push(String(r));}}let n=t.join(" ");return n.length>Ct?n.slice(0,Ct)+"\u2026[truncated]":n}function or(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function ar(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let r=e[n]?.bind(e);r&&(e[n]=(...o)=>{try{We(Ot,{level:n,ts:Date.now(),message:et(rr(o))});}catch{}r(...o);});}}function Ht(e){return tt?e.startsWith(tt):false}function ir(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let r=typeof t=="string"?t:t instanceof URL?t.toString():t.url,o=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if(Ht(r))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return We(Ue,{type:"fetch",method:o,url:nt(r),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw We(Ue,{type:"fetch",method:o,url:nt(r),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function lr(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(r,o,...a){return this.__lumen={method:String(r).toUpperCase(),url:typeof o=="string"?o:o.toString(),t:0},t.call(this,r,o,...a)},e.prototype.send=function(r){let o=this.__lumen;if(o&&!Ht(o.url)){o.t=performance.now();let a=()=>{try{We(Ue,{type:"xhr",method:o.method,url:nt(o.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-o.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",a);};this.addEventListener("loadend",a);}return n.call(this,r??null)};}function sr(e){return e.length>512?e.slice(0,512)+"\u2026":e}function nt(e){return sr(It(e))}function Vt(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:kt(e),consoleLog:[],networkLog:[]};let t=nr();return {url:Dt(window.location.href),userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:kt(e),device:ur(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function ur(){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?Dt(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 kt(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var qe="lumen:shake",cr=8e3,dr=50,mr='[data-lumen-root], [data-lumen-capture-ignore="true"]';function pr(e={}){return async function(){if(typeof window>"u")throw new T("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=gr(),n=e.send??fr,r=e.timeoutMs??cr,o=e.captureSettleMs??dr,a=Er(),i=br(e.concealSelector===void 0?mr:e.concealSelector);try{await vr(o);let l=await new Promise((c,p)=>{let g=window.setTimeout(()=>{t.pending.delete(a),p(new T("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},r);t.pending.set(a,{resolve:b=>{window.clearTimeout(g),c(b);},reject:b=>{window.clearTimeout(g),p(b);}});try{n({type:"lumen:capture-request",id:a,afterScreenUpdates:!0});}catch{t.pending.delete(a),window.clearTimeout(g),p(new T("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new T(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let s=Rr(l.dataUrl),d=e.platform??yr();return {blob:s,method:d==="android"?"android-native":"ios-native",platform:d,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:l.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{i();}}}function fr(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new T("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function gr(){if(window.__lumenNativeCapture)return window.__lumenNativeCapture;let e={pending:new Map,resolve(n,r,o){let a=e.pending.get(n);a&&(e.pending.delete(n),a.resolve({type:"lumen:capture-response",id:n,dataUrl:r,pixelRatio:o}));},reject(n,r){let o=e.pending.get(n);o&&(e.pending.delete(n),o.resolve({type:"lumen:capture-response",id:n,error:r}));}},t=n=>{let r=hr(n.data);if(!r||r.type!=="lumen:capture-response")return;let o=e.pending.get(r.id);o&&(e.pending.delete(r.id),o.resolve(r));};return window.addEventListener("message",t),document.addEventListener("message",t),window.__lumenNativeCapture=e,e}function hr(e){if(e&&typeof e=="object"&&"type"in e)return e;if(typeof e=="string")try{let t=JSON.parse(e);if(t&&typeof t=="object"&&t.type)return t}catch{}return null}function br(e){if(!e||typeof document>"u")return ()=>{};let t=[];for(let n of Array.from(document.querySelectorAll(e)))t.push({el:n,prev:n.style.visibility}),n.style.visibility="hidden";return ()=>{for(let{el:n,prev:r}of t)n.style.visibility=r;}}async function vr(e){await wr(),e>0&&await new Promise(t=>window.setTimeout(t,e));}function wr(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function yr(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function Er(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Rr(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new T("Native host returned an invalid image data URL.","NATIVE_CAPTURE_FAILED");let n=t[1]||"image/png",r=!!t[2],o=t[3]??"";if(!r)return new Blob([decodeURIComponent(o)],{type:n});let a=atob(o),i=new Uint8Array(a.length);for(let l=0;l<a.length;l++)i[l]=a.charCodeAt(l);return new Blob([i],{type:n})}var Cr="[data-lumen-root]",xr="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function kr(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(rt(n))return true;return rt(e.target)}function rt(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(xr)?true:!!e.closest(Cr):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?rt(e.host):false:false}async function _t(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 n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(b=>MediaRecorder.isTypeSupported(b))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,l=false,s=false,d,c,p=new Promise((b,E)=>{d=b,c=E;});p.catch(()=>{}),r.addEventListener("dataavailable",b=>{b.data&&b.data.size>0&&o.push(b.data);}),r.addEventListener("stop",()=>{i!==null&&window.clearTimeout(i),i=null;for(let v of t.getTracks())v.stop();if(s)return;if(s=true,l){c(new T("Recording cancelled.","RECORDER_STOPPED"));return}let b=performance.now()-a,E=r.mimeType||n||"audio/webm",w=new Blob(o,{type:E});d({blob:w,durationMs:b,mimeType:E});}),r.start(),i=window.setTimeout(()=>{r.state!=="inactive"&&r.stop();},e*1e3);function g(){if(r.state!=="inactive")try{r.stop();}catch{}}return {stream:t,cancel(){l=true,g(),i!==null&&window.clearTimeout(i),i=null;for(let b of t.getTracks())b.stop();},stop(){return g(),p}}}async function Ft(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 n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(E=>MediaRecorder.isTypeSupported(E))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,l=false,s=false,d,c,p=new Promise((E,w)=>{d=E,c=w;});p.catch(()=>{});function g(){i!==null&&(window.clearTimeout(i),i=null);for(let E of t.getTracks())E.stop();}r.addEventListener("dataavailable",E=>{E.data&&E.data.size>0&&o.push(E.data);}),r.addEventListener("stop",()=>{if(l)return;if(l=true,g(),s){c(new T("Recording cancelled.","RECORDER_STOPPED"));return}let E=r.mimeType||n||"video/webm";d({blob:new Blob(o,{type:E}),durationMs:performance.now()-a,mimeType:E});});function b(){r.state!=="inactive"&&r.stop();}return r.start(),i=window.setTimeout(b,e*1e3),t.getVideoTracks()[0]?.addEventListener("ended",b),{stream:t,result:p,stop:b,cancel(){s=true,r.state!=="inactive"?r.stop():l||(l=true,g(),c(new T("Recording cancelled.","RECORDER_STOPPED")));}}}var ot=$t.createContext(null);function Oe(){let e=$t.useContext(ot);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var it='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, sans-serif';function Wt(e,t=1){return Math.max(0,Math.min(t,e))}var zt=$t__namespace.forwardRef(function({screenshot:t,tool:n,color:r="rgb(239, 68, 68)",strokeWidth:o=4,onDrawingChange:a},i){let l=$t.useRef(null),s=$t.useRef(null),d=$t.useRef(null),[c,p]=$t.useState(null),[g,b]=$t.useState([]),E=$t.useRef(null),w=$t.useRef(false),v=$t.useRef(0),x=$t.useRef(false),[M,L]=$t.useState([]),A=$t.useRef(0),I=$t.useRef([]),N=$t.useRef(null),_=$t.useCallback((f,h)=>{L(C=>C.map(k=>k.id===f?{...k,text:h}:k));},[]),ee=$t.useCallback(f=>{L(C=>C.filter(k=>k.id!==f));let h=I.current.lastIndexOf("comment");h>=0&&I.current.splice(h,1);},[]);$t.useEffect(()=>{let f=N.current;if(f==null)return;N.current=null,d.current?.querySelector(`[data-bubble-id="${f}"] .lumen-bubble-text`)?.focus();},[M]),$t.useEffect(()=>{let f=false,h=null;return (async()=>{try{let C=await createImageBitmap(t);if(f){C.close?.();return}h=C,p(C);}catch{}})(),()=>{f=true,h?.close?.();}},[t]),$t.useEffect(()=>{if(!c)return;let f=l.current,h=s.current;if(!f||!h)return;f.width=c.width,f.height=c.height,h.width=c.width,h.height=c.height;let C=f.getContext("2d");C&&(C.imageSmoothingEnabled=false,C.drawImage(c,0,0));},[c]),$t.useEffect(()=>{let f=s.current;f&&je(f,g,E.current);},[g]),$t.useImperativeHandle(i,()=>({hasAnnotations:()=>g.length>0||M.some(f=>f.text.trim().length>0),reset:()=>{b([]),L([]),I.current=[];},undo:()=>{(I.current.pop()??"anno")==="comment"?L(h=>h.length===0?h:h.slice(0,-1)):b(h=>h.length===0?h:h.slice(0,-1));},async flatten(){let f=E.current,h=f?[...g,f]:g,C=M.filter(P=>P.text.trim().length>0);if(h.length===0&&C.length===0||!c)return t;let k=document.createElement("canvas");k.width=c.width,k.height=c.height;let V=k.getContext("2d");if(!V)return t;V.imageSmoothingEnabled=false,V.drawImage(c,0,0);for(let P of h)lt(V,P);let O=l.current?.clientWidth||c.width,X=c.width/Math.max(O,1);for(let P of C)Ar(V,P,c.width,c.height,X);return await new Promise(P=>{k.toBlob(K=>{P(K??t);},"image/jpeg",.85);})}}),[g,M,c,t]);function W(f){let h=s.current;if(!h)return {x:0,y:0};let C=h.getBoundingClientRect(),k=h.width/Math.max(C.width,1),V=h.height/Math.max(C.height,1);return {x:(f.clientX-C.left)*k,y:(f.clientY-C.top)*V}}function q(){x.current||(x.current=true,requestAnimationFrame(()=>{x.current=false;let f=s.current;f&&je(f,g,E.current);}));}function oe(f){if(f.button!==void 0&&f.button!==0)return;if(n==="comment"){let C=s.current;if(!C)return;let k=C.getBoundingClientRect(),V=Wt((f.clientX-k.left)/Math.max(k.width,1),.72),O=Wt((f.clientY-k.top)/Math.max(k.height,1),.8),X=++A.current;L(P=>[...P,{id:X,x:V,y:O,text:"",color:r}]),I.current.push("comment"),N.current=X;return}try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}w.current=true,a?.(true);let h=W(f);n==="arrow"?E.current={kind:"arrow",from:h,to:h,color:r,width:o}:n==="rect"?E.current={kind:"rect",from:h,to:h,color:r,width:o}:E.current={kind:"freehand",points:[h],color:r,width:o},v.current=performance.now(),q();}function se(f){if(!w.current||!E.current)return;let h=W(f),C=E.current;if(C.kind==="arrow"||C.kind==="rect")C.to=h;else {let k=C.points[C.points.length-1],V=k?(k.x-h.x)**2+(k.y-h.y)**2:1/0,O=performance.now(),X=O-v.current;(V>16||X>16)&&(C.points.push(h),v.current=O);}q();}function $(){if(!w.current)return;w.current=false,a?.(false);let f=E.current;if(E.current=null,!!f){if(f.kind==="arrow"||f.kind==="rect"){let h=f.to.x-f.from.x,C=f.to.y-f.from.y;if(h*h+C*C<16){let k=s.current;k&&je(k,g,null);return}}else if(f.points.length<2){let h=s.current;h&&je(h,g,null);return}b(h=>[...h,f].slice(-50)),I.current.push("anno");}}return jsxRuntime.jsxs("div",{ref:d,className:"lumen-annotate-frame","data-lumen-tool":n,children:[jsxRuntime.jsx("canvas",{ref:l}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:oe,onPointerMove:se,onPointerUp:$,onPointerCancel:$}),jsxRuntime.jsx("div",{className:"lumen-bubble-layer",children:M.map(f=>jsxRuntime.jsx(Lr,{comment:f,onChange:_,onRemove:ee},f.id))})]})});function Lr({comment:e,onChange:t,onRemove:n}){let r=$t.useRef(null);return $t.useEffect(()=>{let o=r.current;o&&o.textContent!==e.text&&(o.textContent=e.text);},[]),jsxRuntime.jsxs("div",{className:"lumen-bubble","data-bubble-id":e.id,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,"--lumen-bubble-accent":e.color},onPointerDown:o=>o.stopPropagation(),children:[jsxRuntime.jsx("span",{className:"lumen-bubble-label",children:"Comment"}),jsxRuntime.jsx("div",{ref:r,className:"lumen-bubble-text",contentEditable:true,suppressContentEditableWarning:true,role:"textbox","aria-label":"Comment text","data-placeholder":"Type a note\u2026",onInput:o=>t(e.id,o.currentTarget.textContent??"")}),jsxRuntime.jsx("button",{type:"button",className:"lumen-bubble-del","aria-label":"Remove comment",onPointerDown:o=>o.stopPropagation(),onClick:()=>n(e.id),children:"\xD7"})]})}function je(e,t,n){let r=e.getContext("2d");if(r){r.clearRect(0,0,e.width,e.height);for(let o of t)lt(r,o);n&&lt(r,n);}}function lt(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),r=Math.min(t.from.y,t.to.y),o=Math.abs(t.to.x-t.from.x),a=Math.abs(t.to.y-t.from.y);e.strokeRect(n,r,o,a);}else if(t.kind==="freehand")Nr(e,t.points);else {let{from:n,to:r,width:o}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(r.x,r.y),e.stroke();let a=Math.atan2(r.y-n.y,r.x-n.x),i=Math.max(12,o*4);e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(r.x-i*Math.cos(a-Math.PI/7),r.y-i*Math.sin(a-Math.PI/7)),e.lineTo(r.x-i*Math.cos(a+Math.PI/7),r.y-i*Math.sin(a+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function Nr(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 o=t[1];e.lineTo(o.x,o.y),e.stroke();return}for(let o=1;o<t.length-1;o++){let a=t[o],i=t[o+1],l=(a.x+i.x)/2,s=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,l,s);}let r=t[t.length-1];e.lineTo(r.x,r.y),e.stroke();}function Ar(e,t,n,r,o){let a=t.text.trim();if(!a)return;let i=10*o,l=14*o,s=10*o,d=12*o,c=l*1.35,p=s*1.7,g=t.x*n,b=t.y*r,E=Math.min(n*.6,n-g-8*o);e.save(),e.font=`500 ${l}px ${it}`,e.textBaseline="top";let w=Ir(e,a,E-i*2),v=w.reduce((N,_)=>Math.max(N,e.measureText(_).width),0),x=Math.min(E,Math.max(v,56*o)+i*2),M=i*2+p+w.length*c;Dr(e,g,b,x,M,d),e.fillStyle="#ffffff",e.fill(),e.lineWidth=Math.max(1,o),e.strokeStyle="rgba(0,0,0,0.10)",e.stroke();let L=g+18*o,A=b+M;e.beginPath(),e.moveTo(L,A-o),e.lineTo(L+13*o,A-o),e.lineTo(L+4*o,A+9*o),e.closePath(),e.fillStyle="#ffffff",e.fill(),e.fillStyle=t.color||"rgb(239, 68, 68)",e.font=`700 ${s}px ${it}`,e.fillText("COMMENT",g+i,b+i),e.fillStyle="#111318",e.font=`500 ${l}px ${it}`;let I=b+i+p;for(let N of w)e.fillText(N,g+i,I),I+=c;e.restore();}function Ir(e,t,n){let r=t.split(/\s+/).filter(Boolean),o=[],a="";for(let i of r){let l=a?`${a} ${i}`:i;a&&e.measureText(l).width>n?(o.push(a),a=i):a=l;}return a&&o.push(a),o.length?o:[t]}function Dr(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,r,o,i);return}e.moveTo(t+i,n),e.arcTo(t+r,n,t+r,n+o,i),e.arcTo(t+r,n+o,t,n+o,i),e.arcTo(t,n+o,t,n,i),e.arcTo(t,n,t+r,n,i),e.closePath();}function Ke({children:e,...t}){return jsxRuntime.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...t,children:e})}function Or(e){return jsxRuntime.jsxs(Ke,{...e,children:[jsxRuntime.jsx("path",{d:"M3 9a2 2 0 0 1 2-2h1.5l1-1.5h5l1 1.5H19a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"13",r:"3.2"})]})}function Br(e){return jsxRuntime.jsxs(Ke,{...e,children:[jsxRuntime.jsx("rect",{x:"3",y:"6",width:"13",height:"12",rx:"2.5"}),jsxRuntime.jsx("path",{d:"m16 10 5-3v10l-5-3"})]})}function Hr(e){return jsxRuntime.jsxs(Ke,{...e,children:[jsxRuntime.jsx("path",{d:"M12 16V4m0 0 4 4m-4-4-4 4"}),jsxRuntime.jsx("path",{d:"M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})]})}function jt(e){return jsxRuntime.jsxs(Ke,{...e,children:[jsxRuntime.jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),jsxRuntime.jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}var st={shot:Or,video:Br,upload:Hr};function Kt(e){let t=e.videoWidth||1280,n=e.videoHeight||720,r=document.createElement("canvas");r.width=t,r.height=n;let o=r.getContext("2d");return o?(o.drawImage(e,0,0,t,n),new Promise(a=>r.toBlob(i=>a(i),"image/jpeg",.82))):Promise.resolve(null)}function Vr(e,t){return !Number.isFinite(t)||t<=0?Promise.resolve():new Promise(n=>{e.addEventListener("seeked",()=>n(),{once:true});try{e.currentTime=t;}catch{n();}})}var _r=4e3;async function ut(e){if(typeof document>"u")return {poster:null,durationMs:0};let t=URL.createObjectURL(e),n=document.createElement("video");n.muted=true,n.playsInline=true,n.preload="auto",n.src=t;let r=async()=>{await new Promise((s,d)=>{if(n.readyState>=2)return s();n.addEventListener("loadeddata",()=>s(),{once:true}),n.addEventListener("error",()=>d(new Error("video decode failed")),{once:true});}),await Vr(n,Math.min(.1,(n.duration||0)/2));let i=await Kt(n),l=Number.isFinite(n.duration)?n.duration*1e3:0;return {poster:i,durationMs:l}},o,a=new Promise(i=>{o=window.setTimeout(()=>i({poster:null,durationMs:0}),_r);});try{return await Promise.race([r().catch(()=>({poster:null,durationMs:0})),a])}finally{window.clearTimeout(o),n.removeAttribute("src"),URL.revokeObjectURL(t);}}async function ct(e){if(typeof document>"u")return null;let t=document.createElement("video");t.muted=true,t.playsInline=true,t.srcObject=e;try{return await t.play().catch(()=>{}),await new Promise(n=>{if(t.readyState>=2)return n();t.addEventListener("loadeddata",()=>n(),{once:!0}),window.setTimeout(n,600);}),await Kt(t)}catch{return null}finally{t.srcObject=null;}}async function dt(){if(typeof document>"u")return null;let e=document.createElement("canvas");e.width=1280,e.height=720;let t=e.getContext("2d");return t?(t.fillStyle="#0e0e12",t.fillRect(0,0,e.width,e.height),t.fillStyle="#52525b",t.beginPath(),t.moveTo(590,312),t.lineTo(590,408),t.lineTo(694,360),t.closePath(),t.fill(),new Promise(n=>e.toBlob(r=>n(r),"image/jpeg",.8))):null}var mt=60,Fr=25*1024*1024,Gt=[{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)"}],Yt=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],Xt=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],Jt=[{value:"shot",label:"Screenshot",hint:"This page, instantly",primary:true},{value:"video",label:"Video",hint:"Record up to 60s"},{value:"upload",label:"Upload",hint:"Image or video"}];function pt(){let{client:e,isOpen:t,closeCapture:n,user:r,capture:o,initialCapture:a,initialCaptureError:i,startVideoSession:l,consumePendingVideo:s,canRecordScreen:d,consumeRecordStartError:c}=Oe(),[p,g]=$t.useState(1),[b,E]=$t.useState(null),[w,v]=$t.useState({kind:"idle"}),[x,M]=$t.useState(false),[L,A]=$t.useState(0),[I,N]=$t.useState(null),[_,ee]=$t.useState(false),[W,q]=$t.useState("arrow"),[oe,se]=$t.useState(Gt[0].value),[$,f]=$t.useState(Yt[1].value),[h,C]=$t.useState(""),[k,V]=$t.useState("bug"),[O,X]=$t.useState(r?.email??""),[P,K]=$t.useState(null),[B,ue]=$t.useState(null),[Ce,te]=$t.useState(0),[z,j]=$t.useState(null),[J,pe]=$t.useState(null),[be,xe]=$t.useState(false),ve=$t.useRef(null),Pe=$t.useRef(null),ke=$t.useRef(null),ne=$t.useRef(false),Se=$t.useRef(false);$t.useEffect(()=>{t||(Se.current=false);},[t]),$t.useEffect(()=>{if(!t)return;if(Se.current){ne.current=false;return}Se.current=true,ne.current=false,g(1),E(null),C(""),ue(null),te(0),j(null),M(false),A(0),N(null),ee(false),pe(null);let u=s();if(u)E("video"),j({blob:u.blob,durationMs:u.durationMs}),u.blob.size>Fr&&sonner.toast.warning("This recording is large and may be too big to upload. Try a shorter clip if the upload fails."),u.poster?v({kind:"ready",capture:Ie(u.poster,["Screen recording; preview is the first frame."])}):(v({kind:"capturing"}),(async()=>{let R=null;if(u.deriveBlobPoster)try{R=(await ut(u.blob)).poster;}catch{R=null;}R=R??await dt(),!ne.current&&v(R?{kind:"ready",capture:Ie(R,["Screen recording; preview is the first frame."])}:{kind:"manual"});})());else {let R=c();R?(E("video"),pe(R),v({kind:"idle"})):a?(E("shot"),v({kind:"ready",capture:a})):o?.mode==="manual"?v({kind:"manual"}):o?.provider&&!i?(E("shot"),Le(o.mode??"auto")):v({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."});}return ()=>{ne.current=true;}},[t,o,a,i]),$t.useEffect(()=>{if(!t)return;ke.current=document.activeElement??null;let u=document.documentElement,R=u.style.overflow,U=u.style.paddingRight,G=window.innerWidth-u.clientWidth;u.style.overflow="hidden",G>0&&(u.style.paddingRight=`${G}px`);let Q=false,ge=()=>{if(!Q){Q=true,u.style.overflow=R,u.style.paddingRight=U;try{ke.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",ge),()=>{window.removeEventListener("pagehide",ge),ge();}},[t]),$t.useEffect(()=>{if(!t)return;function u(R){if(R.key==="Escape"){R.preventDefault(),n();return}if(R.key!=="Tab")return;let U=Pe.current;if(!U)return;let G=Xr(U);if(G.length===0)return;let Q=G[0],ge=G[G.length-1],Qe=document.activeElement;R.shiftKey&&(Qe===Q||!U.contains(Qe))?(R.preventDefault(),ge.focus()):!R.shiftKey&&Qe===ge&&(R.preventDefault(),Q.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),$t.useEffect(()=>{if(!t||w.kind!=="manual")return;function u(R){let Q=Array.from(R.clipboardData?.items??[]).find(ge=>ge.type.startsWith("image/"))?.getAsFile();Q&&(R.preventDefault(),we(Q));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,w.kind]),$t.useEffect(()=>{if(!P)return;let u=Date.now(),R=window.setInterval(()=>{let U=Math.floor((Date.now()-u)/1e3);te(U),U>=mt&&Z();},250);return ()=>window.clearInterval(R)},[P]);let fe=$t.useRef(null);if(fe.current=P,$t.useEffect(()=>{t||fe.current&&(fe.current.cancel(),fe.current=null,K(null),te(0));},[t]),$t.useEffect(()=>()=>{fe.current?.cancel();},[]),!t)return null;async function Le(u){ne.current=false,v({kind:"capturing"});try{let R=await $e({...o,mode:u,target:o?.target??document.documentElement});return ne.current?!1:(Je(R),v({kind:"ready",capture:R}),!0)}catch(R){return ne.current||v({kind:"manual",error:R instanceof Error?R.message:"Automatic screenshot capture was unavailable."}),false}}async function Me(u){E(u),pe(null),N(null),u!=="video"&&Ne(),u==="shot"?await Le(o?.mode??"auto"):u==="video"?(j(null),v({kind:"idle"})):v({kind:"manual"});}async function we(u){if(u.type.startsWith("image/")){Ne();let R=Ie(u,["Manual image upload used."]);v({kind:"ready",capture:R});return}if(u.type.startsWith("video/")){v({kind:"capturing"});try{let{poster:R,durationMs:U}=await ut(u),G=R??await dt();if(!G){v({kind:"manual",error:"Could not read that video."});return}let Q=Ie(G,["Uploaded video; preview is the first frame."]);j({blob:u,durationMs:U}),v({kind:"ready",capture:Q});}catch{v({kind:"manual",error:"Could not read that video."});}return}sonner.toast.error("Choose an image (PNG, JPEG, WebP) or a video (MP4, WebM).");}function Je(u){u.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function Ve(){try{let u=await _t(mt);K(u);}catch(u){sonner.toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Z(){if(P)try{let u=await P.stop();ue({blob:u.blob,durationMs:u.durationMs});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{K(null);}}function S(){P?.cancel(),K(null),ue(null),te(0);}function H(u){let R=jsxRuntime.jsxs("div",{className:"lumen-audio-row",children:[!P&&!B?jsxRuntime.jsxs("button",{type:"button",onClick:Ve,className:u==="capture"?"lumen-voice-capture-btn":"lumen-btn-ghost",children:[jsxRuntime.jsx(jt,{}),"Record voice note"]}):null,P?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(qr,{stream:P.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[Ce,"s / ",mt,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:Z,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:S,className:"lumen-btn-ghost",children:"Cancel"})]}):null,B&&!P?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(Kr,{blob:B.blob,durationMs:B.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>ue(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]});return u==="capture"?jsxRuntime.jsxs("div",{className:"lumen-voice-capture",children:[R,!P&&!B?jsxRuntime.jsx("p",{className:"lumen-voice-capture-hint",children:"Say what went wrong while it\u2019s fresh."}):null]}):jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Add a voice note (optional)"}),R]})}async function F(){pe(null);try{await l();}catch(u){sonner.toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}function Ne(){j(null);}let In=w.kind==="ready";async function Dn(){if(P&&await Z(),p===1){if(w.kind==="ready"){let u=await ve.current?.flatten();N(u??w.capture.blob),ee(u!=null&&u!==w.capture.blob);}g(2);}else p===2?g(3):await Bn();}function On(){p>1&&g(u=>u-1);}async function Bn(){if(w.kind!=="ready")return;let u=h.trim(),{capture:R}=w;M(true),A(0);try{let U=I??R.blob,G=await e.submit({rawText:u.length>0?u:void 0,category:k,submitterEmail:O.trim()||void 0,screenshot:U,audio:B?.blob,audioDurationMs:B?.durationMs,video:z?.blob,videoDurationMs:z?.durationMs,context:Vt(R)},{onUploadProgress:Q=>A(Math.min(.95,Q))});A(1),sonner.toast.success("Feedback sent \u2014 thank you."),G.id,n();}catch(U){sonner.toast.error(U instanceof Error?U.message:"Could not submit feedback"),M(false);}}function Hn(u){u.target===u.currentTarget&&!x&&n();}let _e=Math.round(L*100),Ze=b==="video",Vn=p===1&&!In||x,_n=p<3?"Next":x?_e<95?`Uploading ${_e}%\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:Hn,children:jsxRuntime.jsxs("div",{ref:Pe,className:"lumen-modal","data-lumen-drawing":be?"true":void 0,children:[jsxRuntime.jsx(zr,{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(Ur,{step:p}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[p===1?jsxRuntime.jsx("div",{className:"lumen-pane",children:b===null?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:Jt.map(u=>{let R=st[u.value];return jsxRuntime.jsxs("button",{type:"button",className:"lumen-method-btn"+(u.primary?" lumen-method-primary":""),onClick:()=>Me(u.value),disabled:w.kind==="capturing",children:[jsxRuntime.jsx("span",{className:"lumen-method-ico",children:jsxRuntime.jsx(R,{})}),u.primary?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-method-text",children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]}),jsxRuntime.jsx("span",{className:"lumen-method-badge",children:"Fastest"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]})]},u.value)})}),jsxRuntime.jsx("p",{className:"lumen-status lumen-method-help",children:"Choose how to capture your feedback."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method-switch",role:"group","aria-label":"Switch capture method",children:Jt.map(u=>{let R=st[u.value];return jsxRuntime.jsxs("button",{type:"button","aria-pressed":b===u.value,onClick:()=>Me(u.value),disabled:w.kind==="capturing",children:[jsxRuntime.jsx(R,{}),u.label]},u.value)})}),b==="video"&&w.kind==="idle"?jsxRuntime.jsx(Wr,{canRecord:d,onRecord:F,error:J}):null,w.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,w.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:b==="upload"?"Choose an image or video to attach \u2014 or paste an image.":w.error?"Automatic capture was unavailable. Upload or paste an image to continue.":"Upload or paste an image to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:b==="upload"?"Choose a file \u2014 image or video":"Choose or paste an image"}),jsxRuntime.jsx("input",{type:"file",accept:b==="upload"?"image/png,image/jpeg,image/webp,video/mp4,video/webm,video/quicktime":"image/png,image/jpeg,image/webp",onChange:u=>{let R=u.currentTarget.files?.[0];R&&we(R),u.currentTarget.value="";}})]})]}):null,w.kind==="ready"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Ze?null:jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(Ye,{label:"Arrow",active:W==="arrow",onClick:()=>q("arrow")}),jsxRuntime.jsx(Ye,{label:"Box",active:W==="rect",onClick:()=>q("rect")}),jsxRuntime.jsx(Ye,{label:"Draw",active:W==="freehand",onClick:()=>q("freehand")}),jsxRuntime.jsx(Ye,{label:"Comment",active:W==="comment",onClick:()=>q("comment")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:Gt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":oe===u.value,onClick:()=>se(u.value)},u.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:Yt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":$===u.value,onClick:()=>f(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:()=>ve.current?.undo(),children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>ve.current?.reset(),children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(zt,{ref:ve,screenshot:w.capture.blob,tool:W,color:oe,strokeWidth:$,onDrawingChange:xe})}),jsxRuntime.jsxs("div",{className:"lumen-cap-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>b&&Me(b),children:Ze?"\u21BB Re-record":"\u21BB Recapture"}),Ze?z?jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round(z.durationMs/1e3),"s recorded"]}):null:jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:[Zt(b)," captured \xB7 switch method above anytime"]})]}),H("capture")]}):null]})}):null,p===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:h,onChange:u=>C(u.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),H("describe"),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:Xt.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":k===u.value,onClick:()=>V(u.value),children:u.label},u.value))})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Your email (optional)"}),jsxRuntime.jsx("input",{type:"email",value:O,onChange:u=>X(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,p===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:[Zt(b),_?" \xB7 annotated":"",jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>g(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:Xt.find(u=>u.value===k)?.label}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>g(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:[h.trim()?h.trim():jsxRuntime.jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>g(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:()=>ue(null),children:"\xD7"})]}):null,z?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round(z.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Ne,children:"\xD7"})]}):null,O.trim()?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u2709 ",O.trim()]}):null,!B&&!P?jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{g(2),Ve();},children:"+ Voice note"}):null]})]})]}):null]}),jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[x?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":_e,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${_e}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:p===1?n:On,className:"lumen-btn-ghost",disabled:x,children:p===1?"Cancel":"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:Dn,className:"lumen-btn-primary",disabled:Vn,children:_n})]})]})]})})}function Zt(e){return e==="video"?"Screen recording":e==="upload"?"Upload":"Screenshot"}function Ur({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,r)=>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}),r<t.length-1?jsxRuntime.jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function Wr({canRecord:e,onRecord:t,error:n}){return e?jsxRuntime.jsxs("div",{className:"lumen-record-prompt",children:[n?jsxRuntime.jsxs("p",{className:"lumen-record-unavailable",role:"alert",children:[n," Try again, or switch to ",jsxRuntime.jsx("strong",{children:"Upload"})," to attach a video instead."]}):null,jsxRuntime.jsx("button",{type:"button",className:"lumen-record-btn","aria-label":"Start screen recording",onClick:t}),jsxRuntime.jsxs("div",{className:"lumen-record-copy",children:[jsxRuntime.jsx("div",{className:"lumen-record-title",children:"Record your screen"}),jsxRuntime.jsx("div",{className:"lumen-record-sub",children:"Tap to start. The sheet closes so you can record freely \u2014 a Stop button stays on screen, then the sheet returns with your clip. Max 60s."})]})]}):jsxRuntime.jsx("div",{className:"lumen-record-prompt",children:jsxRuntime.jsx("p",{className:"lumen-record-unavailable",children:$r()?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Screen recording isn\u2019t available on iOS browsers. Record with Control Center\u2019s screen recorder, then attach the clip via"," ",jsxRuntime.jsx("strong",{children:"Upload"}),"."]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:["Screen recording isn\u2019t available in this browser. Switch to"," ",jsxRuntime.jsx("strong",{children:"Upload"})," to attach a video instead."]})})})}function $r(){if(typeof navigator>"u")return false;let e=navigator.userAgent||"";return /iPad|iPhone|iPod/.test(e)?true:/Macintosh/.test(e)&&typeof document<"u"&&"ontouchend"in document}function Ye({label:e,active:t,onClick:n}){return jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function zr({onDismiss:e}){let t=$t.useRef(null),n=$t.useRef(0),r=$t.useRef(null);function o(l){l.currentTarget.setPointerCapture(l.pointerId),t.current=l.clientY,n.current=performance.now(),r.current=l.currentTarget.parentElement;}function a(l){if(t.current==null||!r.current)return;let s=Math.max(0,l.clientY-t.current);r.current.style.transform=`translateY(${s}px)`;}function i(l){if(t.current==null||!r.current)return;let s=Math.max(0,l.clientY-t.current),d=Math.max(1,performance.now()-n.current),c=s/d;r.current.style.transform="",r.current.style.transition="",t.current=null,(s>80||c>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:o,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function qr({stream:e}){let t=$t.useRef(null);return $t.useEffect(()=>{let n=t.current;if(!n)return;let r=Math.min(window.devicePixelRatio||1,2),o=n.clientWidth||88,a=n.clientHeight||22;n.width=Math.round(o*r),n.height=Math.round(a*r);let i=n.getContext("2d");if(!i)return;i.scale(r,r);let l=window.AudioContext??window.webkitAudioContext;if(!l)return;let s=new l,d=s.createMediaStreamSource(e),c=s.createAnalyser();c.fftSize=1024,c.smoothingTimeConstant=.6,d.connect(c);let p=new Uint8Array(c.fftSize),g=18,b=3,E=3,w=Math.max(2,(o-b*(g-1))/g),v=Math.min(w/2,3),x=new Array(g).fill(0),M=0,L=false;function A(){if(L)return;c.getByteTimeDomainData(p);let I=Math.floor(p.length/g);i.clearRect(0,0,o,a),i.fillStyle=Gr("--lumen-danger")||"rgb(239,68,68)";for(let N=0;N<g;N++){let _=0;for(let $=0;$<I;$++){let f=Math.abs((p[N*I+$]??128)-128);f>_&&(_=f);}let ee=Math.min(1,_/128*1.8),W=x[N]??0;x[N]=ee>W?ee:W+(ee-W)*.35;let q=Math.max(E,x[N]*a),oe=N*(w+b),se=(a-q)/2;jr(i,oe,se,w,q,v),i.fill();}M=requestAnimationFrame(A);}return M=requestAnimationFrame(A),()=>{L=true,cancelAnimationFrame(M);try{d.disconnect();}catch{}s.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function jr(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,r,o,i);return}e.moveTo(t+i,n),e.arcTo(t+r,n,t+r,n+o,i),e.arcTo(t+r,n+o,t,n+o,i),e.arcTo(t,n+o,t,n,i),e.arcTo(t,n,t+r,n,i),e.closePath();}function Kr({blob:e,durationMs:t}){let[n,r]=$t.useState("");return $t.useEffect(()=>{let o=URL.createObjectURL(e);return r(o),()=>{URL.revokeObjectURL(o);}},[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 Gr(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var Yr='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Xr(e){return Array.from(e.querySelectorAll(Yr)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}function nn({state:e,portalTarget:t,onStop:n,onCancel:r}){let[o,a]=$t.useState(false);if($t.useEffect(()=>a(true),[]),!o||typeof document>"u")return null;let i=t??document.body;return e.phase==="recording"?reactDom.createPortal(jsxRuntime.jsx(Jr,{startedAt:e.startedAt,maxSeconds:e.maxSeconds,onStop:n,onCancel:r}),i):reactDom.createPortal(jsxRuntime.jsxs("div",{className:"lumen-rec-hud lumen-rec-hud-pending",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-spinner","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"lumen-rec-hud-time",children:e.phase==="starting"?"Starting\u2026":"Processing\u2026"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"})]}),i)}function Jr({startedAt:e,maxSeconds:t,onStop:n,onCancel:r}){let[o,a]=$t.useState(0);$t.useEffect(()=>{let l=()=>a(Math.min(t,Math.max(0,Math.floor((Date.now()-e)/1e3))));l();let s=window.setInterval(l,250);return ()=>window.clearInterval(s)},[e,t]);let i=l=>`${Math.floor(l/60)}:${String(l%60).padStart(2,"0")}`;return jsxRuntime.jsxs("div",{className:"lumen-rec-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-dot","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-rec-hud-time",children:[i(o)," ",jsxRuntime.jsxs("span",{className:"lumen-rec-hud-max",children:["/ ",i(t)]})]}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"}),jsxRuntime.jsxs("button",{type:"button",className:"lumen-rec-hud-stop",onClick:n,"aria-label":"Stop recording and return to feedback",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-square","aria-hidden":"true"}),"Stop"]})]})}function ft(e){let t=e.hasProvider&&e.providerAvailable!==false;return {canRecord:t||e.hasGetDisplayMedia,usingProvider:t}}function rn(e){return typeof e=="object"&&e!==null&&e.code==="RECORDER_STOPPED"}function on(e){return e instanceof Error?e:new Error(String(e))}function an(e,t,n){let r=false,o=false,a=false,i=null;function l(){o||(o=true,n.onCancelled());}function s(c){o||(o=true,n.onResult(c));}function d(c){o||(o=true,n.onError(c));}return n.onStarting(),Promise.resolve().then(()=>e(t)).then(c=>{if(i=c,r){try{c.cancel();}catch{}l();return}if(n.onActive(c),a){n.onProcessing();try{c.stop();}catch{}}Promise.resolve(c.result).then(p=>{r?l():s(p);}).catch(p=>{r||rn(p)?l():d(on(p));});}).catch(c=>{r||rn(c)?l():d(on(c));}),{stop(){if(!(o||r||a)&&(a=true,i)){n.onProcessing();try{i.stop();}catch{}}},cancel(){if(!(o&&r)){if(r=true,i)try{i.cancel();}catch{}l();}}}}function ln(){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,r=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],o=new Set,a=0;for(let i of r){let l=document.elementsFromPoint(i,n);for(let s of l){if(o.has(s))continue;o.add(s);let d=window.getComputedStyle(s);if(d.position!=="fixed"&&d.position!=="sticky")continue;let c=s.getBoundingClientRect();c.bottom<t-8||c.bottom>t+8||c.width<e*.6||c.height>a&&(a=c.height);}}return a}function gt(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,r=window.innerHeight,o=0;for(let a of e){let i;try{i=document.querySelectorAll(a);}catch{continue}for(let l of Array.from(i)){let s=l.getBoundingClientRect();if(s.height===0||s.width===0)continue;let d=0;switch(t){case "bottom":if(s.bottom<r-8)break;d=Math.max(0,r-s.top);break;case "top":if(s.top>8)break;d=Math.max(0,s.bottom);break;case "left":if(s.left>8)break;d=Math.max(0,s.right);break;case "right":if(s.right<n-8)break;d=Math.max(0,n-s.left);break}d>o&&(o=d);}}return o}function sn(e){let[t,n]=$t.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),r=$t.useRef(t),o=to(e.avoid),a=e.placement,i=e.offset.x,l=e.offset.y;return $t.useEffect(()=>{if(typeof window>"u")return;let s=0,d=false,c=()=>{if(s=0,d)return;let w=a[0]==="b"?"bottom":"top",v=a[1]==="r"?"right":"left",x=0,M=0;e.avoid==="auto"&&w==="bottom"?x=ln():Array.isArray(e.avoid)&&(x=gt(e.avoid,w),M=gt(e.avoid,v));let L={bottom:w==="bottom"?l+x:0,top:w==="top"?l+x:0,right:v==="right"?i+M:0,left:v==="left"?i+M:0},A=r.current;(L.bottom!==A.bottom||L.top!==A.top||L.right!==A.right||L.left!==A.left)&&(r.current=L,n(L));},p=()=>{s||(s=window.requestAnimationFrame(c));};p();let g=typeof ResizeObserver<"u"?new ResizeObserver(p):null;g?.observe(document.documentElement);let b=typeof MutationObserver<"u"?new MutationObserver(p):null;b?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",p);let E=window.visualViewport;return E?.addEventListener("resize",p),E?.addEventListener("scroll",p),()=>{d=true,s&&window.cancelAnimationFrame(s),g?.disconnect(),b?.disconnect(),window.removeEventListener("resize",p),E?.removeEventListener("resize",p),E?.removeEventListener("scroll",p);}},[a,i,l,o]),t}function to(e){return e===false?"false":e==="auto"?"auto":e.join("|")}function un(e){let[t,n]=$t.useState(false);return $t.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;let r=window.visualViewport;if(!r||typeof window.matchMedia!="function"||!window.matchMedia("(pointer: coarse)").matches)return;let o=100,a=0,i=()=>{a=0;let s=window.innerHeight-r.height;n(s>o);},l=()=>{a||(a=window.requestAnimationFrame(i));};return l(),r.addEventListener("resize",l),r.addEventListener("scroll",l),()=>{a&&window.cancelAnimationFrame(a),r.removeEventListener("resize",l),r.removeEventListener("scroll",l);}},[e]),t}function pn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o}){let[a,i]=$t.useState(null),l=$t.useRef(null),s=sn(e),d=un(e.hideOnKeyboard);if($t.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),io(l,!n&&!d),!a)return null;let c=e.placement,p=c[0]==="b"?"bottom":"top",g=c[1]==="r"?"right":"left",b=p==="bottom"?s.bottom:s.top,E=g==="right"?s.right:s.left,w={position:"fixed",[p]:e.safeArea?`calc(${b}px + env(safe-area-inset-${p}, 0px))`:`${b}px`,[g]:e.safeArea?`calc(${E}px + env(safe-area-inset-${g}, 0px))`:`${E}px`,zIndex:e.zIndex,opacity:n||d?0:1,pointerEvents:n||d?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:w,"aria-label":e.label,"aria-hidden":n||d?true:void 0,tabIndex:n||d?-1:0,onPointerDown:v=>r?.(v.nativeEvent),onClick:v=>o(v.nativeEvent),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),a)}function io(e,t){let n=$t.useRef(false);$t.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let r=window.setTimeout(()=>{let o=e.current;if(!o)return;let a=o.getBoundingClientRect();if(a.width===0||a.height===0)return;let i=a.left+a.width/2,l=a.top+a.height/2,s=document.elementsFromPoint(i,l),d=cn(window.getComputedStyle(o).zIndex);for(let c of s){if(c===o||o.contains(c))continue;if(cn(window.getComputedStyle(c).zIndex)>d){n.current=true,console.warn("[lumen] trigger is occluded by",c);break}}},250);return ()=>window.clearTimeout(r)},[t,e]);}function cn(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function fn({mount:e,label:t,icon:n,onPointerDown:r,onClick:o}){let[a,i]=$t.useState(null);return $t.useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;i(l);},[e]),a?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onPointerDown:l=>r?.(l.nativeEvent),onClick:l=>o(l.nativeEvent),"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsxRuntime.jsx("span",{children:t})]}),a):null}function bn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o}){let[a,i]=$t.useState(null),[l,s]=$t.useState(false),d=$t.useRef(null);if($t.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),!a)return null;let c=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function p(w){r?.(w.nativeEvent),d.current={x:w.clientX,y:w.clientY},s(true),w.currentTarget.setPointerCapture(w.pointerId);}function g(w){let v=d.current;if(!v)return;let x=w.clientX-v.x,M=w.clientY-v.y;(e.edge==="top"&&M>16||e.edge==="bottom"&&M<-16||e.edge==="right"&&x<-16||e.edge==="left"&&x>16)&&(d.current=null,o(w.nativeEvent));}function b(){d.current=null,s(false);}function E(){d.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:w=>o(w.nativeEvent),onPointerDown:p,onPointerMove:g,onPointerUp:b,onPointerCancel:E,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 vn(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function wn(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 Eo={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-radius":"radius"};function yn(e){let t=$t.useId();$t.useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,r=`data-lumen-theme-${Ro(t)}`,o={},a=(i,l)=>{o[i]=n.style.getPropertyValue(i)||null,n.style.setProperty(i,l);};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")o["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else {for(let[i,l]of Object.entries(Eo)){let s=e[l];typeof s=="string"&&s.length>0&&a(i,s);}typeof e.accent=="string"&&e.accent.length>0&&(a("--lumen-accent",e.accent),a("--lumen-primary",e.accent),a("--lumen-accent-fg","#ffffff")),(e.scheme==="light"||e.scheme==="dark")&&(o["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e.scheme));}return n.setAttribute(r,""),()=>{n.removeAttribute(r);for(let[i,l]of Object.entries(o))i.startsWith("--")?l?n.style.setProperty(i,l):n.style.removeProperty(i):l==null?n.removeAttribute(i):n.setAttribute(i,l);}},[e,t]);}function Ro(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var En=Symbol.for("lumen.history.patched"),ht="lumen:locationchange";function ko(){if(typeof window>"u")return;let e=window;if(e[En])return;e[En]=true;let t=()=>window.dispatchEvent(new Event(ht)),n=history.pushState;history.pushState=function(...o){let a=n.apply(this,o);return t(),a};let r=history.replaceState;history.replaceState=function(...o){let a=r.apply(this,o);return t(),a},window.addEventListener("popstate",t);}function Rn(e){let[t,n]=$t.useState(false);return $t.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;ko();let r=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return r(),window.addEventListener(ht,r),window.addEventListener("popstate",r),()=>{window.removeEventListener(ht,r),window.removeEventListener("popstate",r);}},[e]),t}var To=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function Cn(){let[e,t]=$t.useState(false);return $t.useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let r=n.webkit;if(r&&r.messageHandlers){t(true);return}let o=navigator.userAgent||"";To.some(a=>o.includes(a))&&t(true);},[]),e}var kn="lumen.config.v1.",No=3600*1e3;function Sn(e,t){let[n,r]=$t.useState(()=>({trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:true}));return $t.useEffect(()=>{if(typeof window>"u")return;let o=Ho(e);o&&r({trigger:o.trigger,enabled:xn(o.trigger),shakeToOpen:o.shake,brand:o.brand,loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),l=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(l,{method:"GET",mode:"cors",credentials:"omit",signal:a.signal}).then(async s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);let d=await s.json(),c=Mn(d.trigger);if(!c)throw new Error("Malformed config response");let p=Do(d.trigger),g=Tn(d.brand);Vo(e,c,p,g),r({trigger:c,enabled:xn(c),shakeToOpen:p,brand:g,loading:false});}).catch(()=>{r(s=>s.loading?{trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:false}:s);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function xn(e){return e.kind!=="headless"}var Ao=["br","bl","tr","tl"],Io=["top","right","bottom","left"];function Mn(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:Ao.find(o=>o===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:Io.find(o=>o===t.edge)??"top",label:n}:null}function Do(e){return !e||typeof e!="object"?false:e.shake===true}var Oo=/^#[0-9a-fA-F]{6}$/,Bo=["auto","light","dark"];function Tn(e){if(!e||typeof e!="object")return null;let t=e,n=typeof t.accent=="string"&&Oo.test(t.accent)?t.accent:null;if(!n)return null;let r=Bo.find(a=>a===t.mode)??"auto",o=typeof t.radius=="number"&&Number.isFinite(t.radius)?Math.min(20,Math.max(0,Math.round(t.radius))):10;return {accent:n,mode:r,radius:o}}function Ho(e){try{let t=window.localStorage.getItem(kn+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>No)return null;let r=Mn(n.trigger);return r?{fetchedAt:n.fetchedAt,trigger:r,shake:n.shake===!0,brand:Tn(n.brand)}:null}catch{return null}}function Vo(e,t,n,r){try{window.localStorage.setItem(kn+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n,brand:r}));}catch{}}function Fo(e){if(e&&typeof e=="object")return e.type===qe;if(typeof e=="string")try{return JSON.parse(e).type===qe}catch{return false}return false}function Uo(e={}){let t=e.threshold??18,n=e.neededHits??3,r=e.windowMs??700,o=e.throttleMs??60,a=null,i=[];return {push(l,s,d,c){if(!a)return a={x:l,y:s,z:d,t:c},false;if(c-a.t<o)return false;let p=Math.abs(l-a.x)+Math.abs(s-a.y)+Math.abs(d-a.z);return a={x:l,y:s,z:d,t:c},p<t?false:(i=i.filter(g=>c-g<r),i.push(c),i.length>=n?(i=[],true):false)}}}function Pn(e,t,n){$t.useEffect(()=>{if(!e||typeof window>"u")return;let r=0,o=1500;function a(){let c=Date.now();n||c-r<o||(r=c,t());}let i=c=>{Fo(c.data)&&a();};window.addEventListener("message",i),document.addEventListener("message",i);let l=Uo(),s=c=>{let p=c.accelerationIncludingGravity??c.acceleration;!p||p.x==null||p.y==null||p.z==null||l.push(p.x,p.y,p.z,Date.now())&&a();},d=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return d&&window.addEventListener("devicemotion",s),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),d&&window.removeEventListener("devicemotion",s);}},[e,t,n]);}var Nn="https://shakebugs.vercel.app",Xe=60;function An(){return typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function"}function $o({apiKey:e,apiUrl:t,user:n,amplitude:r,floatingButton:o=true,trigger:a,hideOn:i,theme:l,portalTarget:s,capture:d,record:c,shakeToOpen:p,onOpenChange:g,beforeOpen:b,onTriggerActivate:E,children:w}){let[v,x]=$t.useState(false),[M,L]=$t.useState(false),[A,I]=$t.useState(null),[N,_]=$t.useState(null),[ee]=$t.useState(false),[W]=$t.useState(null),q=$t.useRef(false),oe=$t.useRef(false),se=$t.useRef(null),$=$t.useMemo(()=>new St({apiKey:e,apiUrl:t,user:n,amplitude:r}),[e,t,n?.id,n?.email,n?.name,r?.userId,r?.deviceId,r?.sessionId]);$t.useEffect(()=>{Bt({ignoreUrlPrefix:(t??Nn).replace(/\/$/,"")});},[t]);let f=$t.useRef(g);f.current=g,$t.useEffect(()=>{if(!(typeof document>"u"))return v?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[v]);let h=$t.useRef(null);$t.useEffect(()=>{if(h.current===v)return;let S=h.current;h.current=v,S!==null&&f.current?.(v);},[v]);let C=$t.useRef(b);C.current=b;let k=$t.useRef(E);k.current=E;let V=$t.useCallback(S=>{oe.current=true,se.current=Promise.resolve().then(()=>C.current?.(S)).then(()=>k.current?.(S)).then(()=>{});},[]),O=$t.useCallback(S=>{q.current||v||j.current||(q.current=true,L(true),I(null),_(null),(async()=>{try{if(oe.current?await se.current:(await C.current?.(S),await k.current?.(S)),d?.mode==="manual")I(null),_(null);else if(d?.provider)I(null),_(null);else {let H=await $e({...d,mode:d?.mode??"auto",target:d?.target??document.documentElement});I(H);}}catch(H){_(H instanceof Error?H:new Error(String(H)));}finally{oe.current=false,se.current=null,q.current=false,L(false),x(true);}})());},[d,v]),X=$t.useCallback(()=>x(false),[]),P=$t.useCallback($.submit.bind($),[$]),[K,B]=$t.useState(null),[ue,Ce]=$t.useState(null),te=$t.useRef(null),z=$t.useRef(null),j=$t.useRef(false),J=$t.useRef(null),pe=$t.useRef(null),be=$t.useRef(null),xe=$t.useCallback((S,H=false)=>{if(te.current=null,z.current=null,j.current=false,B(null),!S){J.current=null;return}pe.current={blob:S.blob,durationMs:S.durationMs,poster:J.current,deriveBlobPoster:H},J.current=null,x(true);},[]);$t.useEffect(()=>{if(!v)return;if(!c?.provider){Ce(null);return}let S=c.isAvailable;if(!S){Ce(true);return}let H=false;return Promise.resolve().then(()=>S()).then(F=>{H||Ce(F);}).catch(()=>{H||Ce(false);}),()=>{H=true;}},[v,c?.provider,c?.isAvailable]);let ve=ft({hasProvider:!!c?.provider,providerAvailable:ue,hasGetDisplayMedia:An()}).canRecord,Pe=$t.useCallback(async()=>{if(j.current)return;if(be.current=null,ft({hasProvider:!!c?.provider,providerAvailable:ue,hasGetDisplayMedia:An()}).usingProvider&&c?.provider){j.current=true,J.current=null,x(false),z.current=an(c.provider,{maxDurationSeconds:Xe},{onStarting:()=>B({phase:"starting"}),onActive:F=>{B({phase:"recording",stream:F.stream??null,startedAt:Date.now(),maxSeconds:Xe}),F.stream&&ct(F.stream).then(Ne=>{J.current=Ne;}).catch(()=>{});},onProcessing:()=>B({phase:"processing"}),onResult:F=>xe({blob:F.blob,durationMs:F.durationMs},true),onCancelled:()=>{z.current=null,j.current=false,J.current=null,B(null),I(null),_(null),x(true);},onError:F=>{z.current=null,j.current=false,J.current=null,B(null),be.current=F.message||"Screen recording could not start.",x(true);}});return}if(te.current)return;let H=await Ft(Xe);te.current=H,j.current=true,J.current=null,B({phase:"recording",stream:H.stream,startedAt:Date.now(),maxSeconds:Xe}),x(false),ct(H.stream).then(F=>{J.current=F;}).catch(()=>{}),H.result.then(F=>xe(F)).catch(()=>xe(null));},[xe,c?.provider,ue]),ke=$t.useCallback(()=>{z.current?z.current.stop():te.current?.stop();},[]),ne=$t.useCallback(()=>{if(z.current){z.current.cancel();return}let S=te.current;te.current=null,j.current=false,J.current=null,B(null),S?.cancel(),I(null),_(null),x(true);},[]),Se=$t.useCallback(()=>{let S=pe.current;return pe.current=null,S},[]),fe=$t.useCallback(()=>{let S=be.current;return be.current=null,S},[]);$t.useEffect(()=>{v||(be.current=null);},[v]);let Le=Cn(),Me=Rn(i),we=Sn(a?"":e,t??Nn);yn(l??jo(we.brand));let Je=p??we.shakeToOpen;Pn(Je,O,v);let Ve=$t.useMemo(()=>({client:$,user:n,isOpen:v,isSubmitting:ee,error:W,open:O,close:X,openCapture:O,closeCapture:X,submit:P,isNativeShell:Le,capture:d,initialCapture:A,initialCaptureError:N,isOpening:M,startVideoSession:Pe,stopVideoSession:ke,cancelVideoSession:ne,recording:K,consumePendingVideo:Se,canRecordScreen:ve,consumeRecordStartError:fe}),[$,n,v,ee,W,O,X,P,Le,d,A,N,Pe,ke,ne,K,Se,ve,fe,M]),Z=qo({explicit:a,remote:we.trigger,remoteLoading:we.loading,floatingButton:o});return jsxRuntime.jsxs(ot.Provider,{value:Ve,children:[w,Z?.kind==="floating"?jsxRuntime.jsx(pn,{config:wn(Z),portalTarget:s,hidden:Me||M||K!=null,onPointerDown:V,onClick:S=>O(S)}):null,Z?.kind==="notch"?jsxRuntime.jsx(bn,{config:vn(Z),portalTarget:s,hidden:Me||M||K!=null,onPointerDown:V,onClick:S=>O(S)}):null,Z?.kind==="inline"?jsxRuntime.jsx(fn,{mount:Z.mount,label:Z.label??"Feedback",icon:Z.icon,onPointerDown:V,onClick:S=>O(S)}):null,K?jsxRuntime.jsx(nn,{state:K,portalTarget:s,onStop:ke,onCancel:ne}):null,jsxRuntime.jsx(pt,{}),jsxRuntime.jsx(zo,{})]})}function zo(){let[e,t]=$t.useState(false);return $t.useEffect(()=>{t(!document.querySelector("[data-sonner-toaster]"));},[]),e?jsxRuntime.jsx(sonner.Toaster,{position:"top-center",style:{zIndex:2147483647}}):null}function qo(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function jo(e){if(e)return {accent:e.accent,radius:`${e.radius}px`,scheme:e.mode}}function Go({variant:e="default",floating:t=false,className:n,children:r="Feedback",onClick:o,...a}){let{openCapture:i}=Oe(),l=["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:l,"data-lumen-trigger":"",onClick:s=>{o?.(s),s.defaultPrevented||i(s.nativeEvent);},...a,children:r})}
4
- exports.CaptureModal=pt;exports.FeedbackButton=Go;exports.LUMEN_SHAKE_MESSAGE=qe;exports.LumenProvider=$o;exports.createNativeCaptureProvider=pr;exports.isLumenEventTarget=kr;exports.useLumen=Oe;//# sourceMappingURL=index.cjs.map
2
+ 'use strict';var Yt=require('react'),sonner=require('sonner'),jsxRuntime=require('react/jsx-runtime'),reactDom=require('react-dom');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var Yt__namespace=/*#__PURE__*/_interopNamespace(Yt);var T=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},Et=class extends T{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},Rt=class extends T{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},We=class extends T{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},qn="https://shakebugs.vercel.app",jn="/api/v1/sdk/submit",Kn=new Set([502,503,504]),At=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??qn).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${jn}`,r=this.#e(e),o=null;for(let a=0;a<3;a++){a>0&&await Yn(2**a*250);try{return await this.#t(n,r,t)}catch(i){if(o=i,i instanceof Et||i instanceof Rt||i instanceof T&&typeof i.status=="number"&&!Kn.has(i.status))throw i}}throw o instanceof Error?o:new We("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,r=n?{...e.context,amplitude:n}:e.context;return t.append("context",JSON.stringify(r)),e.screenshot&&t.append("screenshot",e.screenshot,Gn(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((r,o)=>{let a=new XMLHttpRequest;a.open("POST",e,true),a.setRequestHeader("X-Lumen-Api-Key",this.apiKey),a.responseType="text";let{onUploadProgress:i,signal:l}=n;i&&a.upload.addEventListener("progress",m=>{m.lengthComputable&&m.total>0&&i(Math.min(1,m.loaded/m.total));});let s=()=>{a.abort(),o(new We("Submit aborted."));};if(l){if(l.aborted){o(new We("Submit aborted."));return}l.addEventListener("abort",s,{once:true});}a.addEventListener("load",()=>{if(l&&l.removeEventListener("abort",s),a.status===403){o(new Et);return}if(a.status===429){let m=Number(a.getResponseHeader("Retry-After"))||60;o(new Rt(m));return}if(a.status<200||a.status>=300){o(new T(Xn(a.responseText)??`HTTP ${a.status}`,"HTTP_ERROR",a.status));return}try{let m=JSON.parse(a.responseText);r(m);}catch{o(new T("Malformed response from server.","BAD_RESPONSE"));}}),a.addEventListener("error",()=>{l&&l.removeEventListener("abort",s),o(new We("Network error during submit."));}),a.send(t);})}};function Gn(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function Yn(e){return new Promise(t=>setTimeout(t,e))}function Xn(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var Jn=2,Zn=1.5,Qn=820,er=12,Ie=8*1024*1024;async function qe(e={}){Ht();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return lr(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 T("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return St(e);if(t==="dom")return xt(e);if(t==="custom")throw new T("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await xt(e)}catch(n){if(Bt()){let r=await St(e);return r.warnings=Oe(["DOM screenshot failed; used browser screen permission fallback.",...r.warnings]),e.onWarning?.(r.warnings),r}throw n}}function De(e,t=[]){Ht();let n=je();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:Oe(t)}}var Ct=Promise.resolve();function xt(e){let t=Ct.then(()=>kt(e),()=>kt(e));return Ct=t.catch(()=>{}),t}async function kt(e){let t=await ir(),n=e.target??document.documentElement,r=je(),o=ur(),a=window.visualViewport,i=window.scrollX+(a?.offsetLeft??0),l=window.scrollY+(a?.offsetTop??0),s=cr(e,r.width,r.height),m=sr(n);!e.provider&&ar()&&m.unshift(`Lumen is capturing inside a React Native WebView with no native capture provider, so this screenshot is a DOM re-render \u2014 it won't match the native screen and omits native overlays/inputs. Wire createNativeCaptureProvider() with capture mode "custom" (see docs/native-screenshot-expo.md).`);let c=rr(n);await mr();let p=await t(n,{backgroundColor:null,logging:false,useCORS:true,allowTaint:false,width:r.width,height:r.height,windowWidth:o.width,windowHeight:o.height,scrollX:window.scrollX,scrollY:window.scrollY,x:i,y:l,scale:s,ignoreElements:g=>g instanceof HTMLElement&&(g.dataset.lumenCaptureIgnore==="true"||!!g.closest("[data-lumen-capture-ignore='true']")),onclone:(g,v)=>{or(v,c),tr(g);}}),f={blob:await Ot(p,m),method:"web-dom",platform:"web",viewport:r,pixelRatio:s,warnings:Oe(m)};return f.warnings.length>0&&e.onWarning?.(f.warnings),f}var It=['input[type="password"]','input[autocomplete^="cc-"]','input[autocomplete="one-time-code"]',"[data-lumen-mask]"].join(", ");function tr(e){for(let t of Array.from(e.querySelectorAll(It))){if(t.nodeName==="INPUT"||t.nodeName==="TEXTAREA"){let n=t;n.value&&(n.value="\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022");continue}t.style.visibility="hidden";}}var nr="[data-lumen-root], [data-lumen-capture-ignore='true']";function Dt(e){return Array.from(e.querySelectorAll("input")).filter(t=>!t.closest(nr))}function rr(e){return Dt(e).map(t=>{if(t.matches(It))return {skip:true};let n=t.type;return n==="checkbox"||n==="radio"?{skip:false,checked:t.checked}:n==="file"?{skip:true}:{skip:false,value:t.value}})}function or(e,t){let n=Dt(e);n.length===t.length&&n.forEach((r,o)=>{let a=t[o];!a||a.skip||(a.checked!==void 0?r.checked=a.checked:a.value!==void 0&&(r.value=a.value));});}function ar(){return typeof window<"u"&&typeof window.ReactNativeWebView<"u"}async function ir(){let{default:e}=await import('html2canvas-pro');return e}async function St(e){if(!Bt())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 n=document.createElement("video");n.muted=!0,n.playsInline=!0,n.srcObject=t,await pr(n);let r=document.createElement("canvas");r.width=n.videoWidth,r.height=n.videoHeight;let o=r.getContext("2d");if(!o)throw new T("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");o.drawImage(n,0,0,r.width,r.height);let a=je(),i=["Browser screen capture uses the window or tab selected by the user."],l={blob:await Ot(r,i),method:"web-display-media",platform:"web",viewport:a,pixelRatio:a.width>0?r.width/a.width:void 0,warnings:Oe(i)};return e.onWarning?.(l.warnings),l}finally{for(let n of t.getTracks())n.stop();}}function lr(e,t){let n=je(),r={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:Oe(e.warnings??[])};return r.warnings.length>0&&t.onWarning?.(r.warnings),r}function sr(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 r of Array.from(e.querySelectorAll("img"))){let o=r.currentSrc||r.src;if(o)try{new URL(o,window.location.href).origin!==window.location.origin&&!r.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 Ot(e,t){let n=await Mt(e,"image/png",.92);if(n.size<=Ie)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let r=e,o=0;for(;n.size>Ie&&o<6;){let a=Math.max(.35,Math.min(.95,Math.sqrt(Ie/n.size)*.9)),i=document.createElement("canvas");i.width=Math.max(1,Math.round(r.width*a)),i.height=Math.max(1,Math.round(r.height*a));let l=i.getContext("2d");if(!l)return n;l.drawImage(r,0,0,i.width,i.height),r=i;for(let s of [.86,.74,.62,.5])if(n=await Mt(r,"image/jpeg",s),n.size<=Ie)return n;if(o+=1,i.width<480||i.height<320)break}return n.size>Ie&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function Mt(e,t,n){return new Promise((r,o)=>{e.toBlob(a=>{if(!a){o(new T("Could not encode screenshot.","ENCODE_FAILED"));return}r(a);},t,n);})}function je(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function ur(){let e=document.documentElement;return {width:Math.round(e.clientWidth||window.innerWidth),height:Math.round(e.clientHeight||window.innerHeight)}}function cr(e,t,n){let r=window.devicePixelRatio??1,o=e.maxScale??Jn;dr()&&(o=Math.min(o,Zn));let a=Math.max(1,Math.min(r,o)),i=Math.sqrt(er*1e6/Math.max(1,t*n));return Math.max(1,Math.min(a,i))}function dr(){let e=typeof navigator<"u"&&(navigator.maxTouchPoints??0)>0||typeof window<"u"&&"ontouchstart"in window,t=document.documentElement.clientWidth||window.innerWidth||0;return e&&t>0&&t<=Qn}function mr(){return typeof requestAnimationFrame!="function"?new Promise(e=>setTimeout(e,32)):new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(()=>e())))}function Bt(){return !!navigator.mediaDevices?.getDisplayMedia}async function pr(e){await new Promise((r,o)=>{let a=()=>r(),i=()=>o(new T("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 T("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(r=>requestAnimationFrame(()=>r()));}}function Ht(){if(typeof window>"u"||typeof document>"u")throw new T("Screenshot capture can only run in the browser.","INVALID_ENV")}function Oe(e){return Array.from(new Set(e.filter(Boolean)))}var Vt=/^(token|access_token|refresh_token|id_token|api_?key|key|secret|password|passwd|pwd|auth|authorization|sig|signature|session|sessionid|sid|email|jwt)$/i;function ot(e){let t=e;return t=t.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._\-+/=]+/gi,"$1 ***"),t=t.replace(/\b([A-Za-z_][\w-]*)\s*[=:]\s*("?)([^"\s&]{6,})\2/g,(n,r,o,a)=>/^(Bearer|Basic)$/i.test(a)?n:Vt.test(r)?`${r}=${o}***${o}`:a.length>=24&&/^[A-Za-z0-9._\-+/=]+$/.test(a)&&!a.includes(" ")?`${r}=${o}${a.slice(0,4)}\u2026${o}`:n),t=t.replace(/\b[\w.+-]+@[\w-]+\.[\w.-]+\b/g,"***@***"),t}function _t(e){try{let t=new URL(e,"http://relative.invalid");for(let r of [...t.searchParams.keys()])Vt.test(r)&&t.searchParams.set(r,"***");t.hash="";let n=t.toString();return ot(t.host==="relative.invalid"?n.replace(/^http:\/\/relative\.invalid/,""):n)}catch{return ot(e)}}function Ft(e){try{let t=new URL(e);return `${t.origin}${t.pathname}`}catch{return _t(e)}}var Tt=200,Pt=4096,Ut=[],$e=[],Lt=false,at=null;function Wt(e={}){Lt||typeof window>"u"||(Lt=true,at=e.ignoreUrlPrefix??null,br(),vr(),wr());}function fr(){return {consoleLog:Ut.slice(),networkLog:$e.slice()}}function ze(e,t){e.push(t),e.length>Tt&&e.splice(0,e.length-Tt);}function gr(e){let t=[];for(let r of e){if(typeof r=="string"){t.push(r);continue}if(r instanceof Error){t.push(`${r.name}: ${r.message}${r.stack?`
3
+ ${r.stack}`:""}`);continue}try{t.push(JSON.stringify(r,hr));}catch{t.push(String(r));}}let n=t.join(" ");return n.length>Pt?n.slice(0,Pt)+"\u2026[truncated]":n}function hr(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function br(){let e=window.console;if(!e)return;let t=["log","info","warn","error","debug"];for(let n of t){let r=e[n]?.bind(e);r&&(e[n]=(...o)=>{try{ze(Ut,{level:n,ts:Date.now(),message:ot(gr(o))});}catch{}r(...o);});}}function $t(e){return at?e.startsWith(at):false}function vr(){let e=window.fetch;typeof e=="function"&&(window.fetch=async function(t,n){let r=typeof t=="string"?t:t instanceof URL?t.toString():t.url,o=(n?.method??(t instanceof Request?t.method:"GET")).toUpperCase();if($t(r))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return ze($e,{type:"fetch",method:o,url:it(r),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw ze($e,{type:"fetch",method:o,url:it(r),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function wr(){let e=window.XMLHttpRequest;if(!e)return;let t=e.prototype.open,n=e.prototype.send;e.prototype.open=function(r,o,...a){return this.__lumen={method:String(r).toUpperCase(),url:typeof o=="string"?o:o.toString(),t:0},t.call(this,r,o,...a)},e.prototype.send=function(r){let o=this.__lumen;if(o&&!$t(o.url)){o.t=performance.now();let a=()=>{try{ze($e,{type:"xhr",method:o.method,url:it(o.url),status:this.status,ok:this.status>=200&&this.status<400,durationMs:Math.round(performance.now()-o.t),ts:Date.now()});}catch{}this.removeEventListener("loadend",a);};this.addEventListener("loadend",a);}return n.call(this,r??null)};}function yr(e){return e.length>512?e.slice(0,512)+"\u2026":e}function it(e){return yr(_t(e))}function zt(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:Nt(e),consoleLog:[],networkLog:[]};let t=fr();return {url:Ft(window.location.href),userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:Nt(e),device:Er(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function Er(){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?Ft(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 Nt(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var Ke="lumen:shake",Rr=8e3,Cr=50,xr='[data-lumen-root], [data-lumen-capture-ignore="true"]';function kr(e={}){return async function(){if(typeof window>"u")throw new T("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=Mr(),n=e.send??Sr,r=e.timeoutMs??Rr,o=e.captureSettleMs??Cr,a=Ir(),i=Pr(e.concealSelector===void 0?xr:e.concealSelector);try{await Lr(o);let l=await new Promise((c,p)=>{let f=window.setTimeout(()=>{t.pending.delete(a),p(new T("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},r);t.pending.set(a,{resolve:g=>{window.clearTimeout(f),c(g);},reject:g=>{window.clearTimeout(f),p(g);}});try{n({type:"lumen:capture-request",id:a,afterScreenUpdates:!0});}catch{t.pending.delete(a),window.clearTimeout(f),p(new T("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new T(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let s=Dr(l.dataUrl),m=e.platform??Ar();return {blob:s,method:m==="android"?"android-native":"ios-native",platform:m,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:l.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{i();}}}function Sr(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new T("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function Mr(){if(window.__lumenNativeCapture)return window.__lumenNativeCapture;let e={pending:new Map,resolve(n,r,o){let a=e.pending.get(n);a&&(e.pending.delete(n),a.resolve({type:"lumen:capture-response",id:n,dataUrl:r,pixelRatio:o}));},reject(n,r){let o=e.pending.get(n);o&&(e.pending.delete(n),o.resolve({type:"lumen:capture-response",id:n,error:r}));}},t=n=>{let r=Tr(n.data);if(!r||r.type!=="lumen:capture-response")return;let o=e.pending.get(r.id);o&&(e.pending.delete(r.id),o.resolve(r));};return window.addEventListener("message",t),document.addEventListener("message",t),window.__lumenNativeCapture=e,e}function Tr(e){if(e&&typeof e=="object"&&"type"in e)return e;if(typeof e=="string")try{let t=JSON.parse(e);if(t&&typeof t=="object"&&t.type)return t}catch{}return null}function Pr(e){if(!e||typeof document>"u")return ()=>{};let t=[];for(let n of Array.from(document.querySelectorAll(e)))t.push({el:n,prev:n.style.visibility}),n.style.visibility="hidden";return ()=>{for(let{el:n,prev:r}of t)n.style.visibility=r;}}async function Lr(e){await Nr(),e>0&&await new Promise(t=>window.setTimeout(t,e));}function Nr(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function Ar(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function Ir(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function Dr(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new T("Native host returned an invalid image data URL.","NATIVE_CAPTURE_FAILED");let n=t[1]||"image/png",r=!!t[2],o=t[3]??"";if(!r)return new Blob([decodeURIComponent(o)],{type:n});let a=atob(o),i=new Uint8Array(a.length);for(let l=0;l<a.length;l++)i[l]=a.charCodeAt(l);return new Blob([i],{type:n})}var Or="[data-lumen-root]",Br="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function Hr(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(lt(n))return true;return lt(e.target)}function lt(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(Br)?true:!!e.closest(Or):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?lt(e.host):false:false}async function qt(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 n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(g=>MediaRecorder.isTypeSupported(g))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,l=false,s=false,m,c,p=new Promise((g,v)=>{m=g,c=v;});p.catch(()=>{}),r.addEventListener("dataavailable",g=>{g.data&&g.data.size>0&&o.push(g.data);}),r.addEventListener("stop",()=>{i!==null&&window.clearTimeout(i),i=null;for(let w of t.getTracks())w.stop();if(s)return;if(s=true,l){c(new T("Recording cancelled.","RECORDER_STOPPED"));return}let g=performance.now()-a,v=r.mimeType||n||"audio/webm",y=new Blob(o,{type:v});m({blob:y,durationMs:g,mimeType:v});}),r.start(),i=window.setTimeout(()=>{r.state!=="inactive"&&r.stop();},e*1e3);function f(){if(r.state!=="inactive")try{r.stop();}catch{}}return {stream:t,cancel(){l=true,f(),i!==null&&window.clearTimeout(i),i=null;for(let g of t.getTracks())g.stop();},stop(){return f(),p}}}async function jt(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 n=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm","video/mp4"].find(v=>MediaRecorder.isTypeSupported(v))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,l=false,s=false,m,c,p=new Promise((v,y)=>{m=v,c=y;});p.catch(()=>{});function f(){i!==null&&(window.clearTimeout(i),i=null);for(let v of t.getTracks())v.stop();}r.addEventListener("dataavailable",v=>{v.data&&v.data.size>0&&o.push(v.data);}),r.addEventListener("stop",()=>{if(l)return;if(l=true,f(),s){c(new T("Recording cancelled.","RECORDER_STOPPED"));return}let v=r.mimeType||n||"video/webm";m({blob:new Blob(o,{type:v}),durationMs:performance.now()-a,mimeType:v});});function g(){r.state!=="inactive"&&r.stop();}return r.start(),i=window.setTimeout(g,e*1e3),t.getVideoTracks()[0]?.addEventListener("ended",g),{stream:t,result:p,stop:g,cancel(){s=true,r.state!=="inactive"?r.stop():l||(l=true,f(),c(new T("Recording cancelled.","RECORDER_STOPPED")));}}}var st=Yt.createContext(null);function Be(){let e=Yt.useContext(st);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var ct='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, sans-serif';function Gt(e,t=1){return Math.max(0,Math.min(t,e))}var Xt=Yt__namespace.forwardRef(function({screenshot:t,tool:n,color:r="rgb(239, 68, 68)",strokeWidth:o=4,onDrawingChange:a},i){let l=Yt.useRef(null),s=Yt.useRef(null),m=Yt.useRef(null),[c,p]=Yt.useState(null),[f,g]=Yt.useState([]),v=Yt.useRef(null),y=Yt.useRef(false),w=Yt.useRef(0),x=Yt.useRef(false),[M,P]=Yt.useState([]),I=Yt.useRef(0),N=Yt.useRef([]),A=Yt.useRef(null),B=Yt.useCallback((h,b)=>{P(C=>C.map(S=>S.id===h?{...S,text:b}:S));},[]),Z=Yt.useCallback(h=>{P(C=>C.filter(S=>S.id!==h));let b=N.current.lastIndexOf("comment");b>=0&&N.current.splice(b,1);},[]);Yt.useEffect(()=>{let h=A.current;if(h==null)return;A.current=null,m.current?.querySelector(`[data-bubble-id="${h}"] .lumen-bubble-text`)?.focus();},[M]),Yt.useEffect(()=>{let h=false,b=null;return (async()=>{try{let C=await createImageBitmap(t);if(h){C.close?.();return}b=C,p(C);}catch{}})(),()=>{h=true,b?.close?.();}},[t]),Yt.useEffect(()=>{if(!c)return;let h=l.current,b=s.current;if(!h||!b)return;h.width=c.width,h.height=c.height,b.width=c.width,b.height=c.height;let C=h.getContext("2d");C&&(C.imageSmoothingEnabled=false,C.drawImage(c,0,0));},[c]),Yt.useEffect(()=>{let h=s.current;h&&Ge(h,f,v.current);},[f]),Yt.useImperativeHandle(i,()=>({hasAnnotations:()=>f.length>0||M.some(h=>h.text.trim().length>0),reset:()=>{g([]),P([]),N.current=[];},undo:()=>{(N.current.pop()??"anno")==="comment"?P(b=>b.length===0?b:b.slice(0,-1)):g(b=>b.length===0?b:b.slice(0,-1));},async flatten(){let h=v.current,b=h?[...f,h]:f,C=M.filter(L=>L.text.trim().length>0);if(b.length===0&&C.length===0||!c)return t;let S=document.createElement("canvas");S.width=c.width,S.height=c.height;let V=S.getContext("2d");if(!V)return t;V.imageSmoothingEnabled=false,V.drawImage(c,0,0);for(let L of b)dt(V,L);let O=l.current?.clientWidth||c.width,G=c.width/Math.max(O,1);for(let L of C)zr(V,L,c.width,c.height,G);return await new Promise(L=>{S.toBlob(fe=>{L(fe??t);},"image/jpeg",.85);})}}),[f,M,c,t]);function U(h){let b=s.current;if(!b)return {x:0,y:0};let C=b.getBoundingClientRect(),S=b.width/Math.max(C.width,1),V=b.height/Math.max(C.height,1);return {x:(h.clientX-C.left)*S,y:(h.clientY-C.top)*V}}function W(){x.current||(x.current=true,requestAnimationFrame(()=>{x.current=false;let h=s.current;h&&Ge(h,f,v.current);}));}function te(h){if(h.button!==void 0&&h.button!==0)return;if(n==="comment"){let C=s.current;if(!C)return;let S=C.getBoundingClientRect(),V=Gt((h.clientX-S.left)/Math.max(S.width,1),.72),O=Gt((h.clientY-S.top)/Math.max(S.height,1),.8),G=++I.current;P(L=>[...L,{id:G,x:V,y:O,text:"",color:r}]),N.current.push("comment"),A.current=G;return}try{h.currentTarget.setPointerCapture(h.pointerId);}catch{}y.current=true,a?.(true);let b=U(h);n==="arrow"?v.current={kind:"arrow",from:b,to:b,color:r,width:o}:n==="rect"?v.current={kind:"rect",from:b,to:b,color:r,width:o}:v.current={kind:"freehand",points:[b],color:r,width:o},w.current=performance.now(),W();}function ce(h){if(!y.current||!v.current)return;let b=U(h),C=v.current;if(C.kind==="arrow"||C.kind==="rect")C.to=b;else {let S=C.points[C.points.length-1],V=S?(S.x-b.x)**2+(S.y-b.y)**2:1/0,O=performance.now(),G=O-w.current;(V>16||G>16)&&(C.points.push(b),w.current=O);}W();}function $(){if(!y.current)return;y.current=false,a?.(false);let h=v.current;if(v.current=null,!!h){if(h.kind==="arrow"||h.kind==="rect"){let b=h.to.x-h.from.x,C=h.to.y-h.from.y;if(b*b+C*C<16){let S=s.current;S&&Ge(S,f,null);return}}else if(h.points.length<2){let b=s.current;b&&Ge(b,f,null);return}g(b=>[...b,h].slice(-50)),N.current.push("anno");}}return jsxRuntime.jsxs("div",{ref:m,className:"lumen-annotate-frame","data-lumen-tool":n,children:[jsxRuntime.jsx("canvas",{ref:l}),jsxRuntime.jsx("canvas",{ref:s,className:"lumen-annotate-overlay",onPointerDown:te,onPointerMove:ce,onPointerUp:$,onPointerCancel:$}),jsxRuntime.jsx("div",{className:"lumen-bubble-layer",children:M.map(h=>jsxRuntime.jsx(Wr,{comment:h,onChange:B,onRemove:Z},h.id))})]})});function Wr({comment:e,onChange:t,onRemove:n}){let r=Yt.useRef(null);return Yt.useEffect(()=>{let o=r.current;o&&o.textContent!==e.text&&(o.textContent=e.text);},[]),jsxRuntime.jsxs("div",{className:"lumen-bubble","data-bubble-id":e.id,style:{left:`${e.x*100}%`,top:`${e.y*100}%`,"--lumen-bubble-accent":e.color},onPointerDown:o=>o.stopPropagation(),children:[jsxRuntime.jsx("span",{className:"lumen-bubble-label",children:"Comment"}),jsxRuntime.jsx("div",{ref:r,className:"lumen-bubble-text",contentEditable:true,suppressContentEditableWarning:true,role:"textbox","aria-label":"Comment text","data-placeholder":"Type a note\u2026",onInput:o=>t(e.id,o.currentTarget.textContent??"")}),jsxRuntime.jsx("button",{type:"button",className:"lumen-bubble-del","aria-label":"Remove comment",onPointerDown:o=>o.stopPropagation(),onClick:()=>n(e.id),children:"\xD7"})]})}function Ge(e,t,n){let r=e.getContext("2d");if(r){r.clearRect(0,0,e.width,e.height);for(let o of t)dt(r,o);n&&dt(r,n);}}function dt(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),r=Math.min(t.from.y,t.to.y),o=Math.abs(t.to.x-t.from.x),a=Math.abs(t.to.y-t.from.y);e.strokeRect(n,r,o,a);}else if(t.kind==="freehand")$r(e,t.points);else {let{from:n,to:r,width:o}=t;e.beginPath(),e.moveTo(n.x,n.y),e.lineTo(r.x,r.y),e.stroke();let a=Math.atan2(r.y-n.y,r.x-n.x),i=Math.max(12,o*4);e.beginPath(),e.moveTo(r.x,r.y),e.lineTo(r.x-i*Math.cos(a-Math.PI/7),r.y-i*Math.sin(a-Math.PI/7)),e.lineTo(r.x-i*Math.cos(a+Math.PI/7),r.y-i*Math.sin(a+Math.PI/7)),e.closePath(),e.fill();}e.restore();}function $r(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 o=t[1];e.lineTo(o.x,o.y),e.stroke();return}for(let o=1;o<t.length-1;o++){let a=t[o],i=t[o+1],l=(a.x+i.x)/2,s=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,l,s);}let r=t[t.length-1];e.lineTo(r.x,r.y),e.stroke();}function zr(e,t,n,r,o){let a=t.text.trim();if(!a)return;let i=10*o,l=14*o,s=10*o,m=12*o,c=l*1.35,p=s*1.7,f=t.x*n,g=t.y*r,v=Math.min(n*.6,n-f-8*o);e.save(),e.font=`500 ${l}px ${ct}`,e.textBaseline="top";let y=qr(e,a,v-i*2),w=y.reduce((A,B)=>Math.max(A,e.measureText(B).width),0),x=Math.min(v,Math.max(w,56*o)+i*2),M=i*2+p+y.length*c;jr(e,f,g,x,M,m),e.fillStyle="#ffffff",e.fill(),e.lineWidth=Math.max(1,o),e.strokeStyle="rgba(0,0,0,0.10)",e.stroke();let P=f+18*o,I=g+M;e.beginPath(),e.moveTo(P,I-o),e.lineTo(P+13*o,I-o),e.lineTo(P+4*o,I+9*o),e.closePath(),e.fillStyle="#ffffff",e.fill(),e.fillStyle=t.color||"rgb(239, 68, 68)",e.font=`700 ${s}px ${ct}`,e.fillText("COMMENT",f+i,g+i),e.fillStyle="#111318",e.font=`500 ${l}px ${ct}`;let N=g+i+p;for(let A of y)e.fillText(A,f+i,N),N+=c;e.restore();}function qr(e,t,n){let r=t.split(/\s+/).filter(Boolean),o=[],a="";for(let i of r){let l=a?`${a} ${i}`:i;a&&e.measureText(l).width>n?(o.push(a),a=i):a=l;}return a&&o.push(a),o.length?o:[t]}function jr(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,r,o,i);return}e.moveTo(t+i,n),e.arcTo(t+r,n,t+r,n+o,i),e.arcTo(t+r,n+o,t,n+o,i),e.arcTo(t,n+o,t,n,i),e.arcTo(t,n,t+r,n,i),e.closePath();}function Ye({children:e,...t}){return jsxRuntime.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.8,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:"false",...t,children:e})}function Kr(e){return jsxRuntime.jsxs(Ye,{...e,children:[jsxRuntime.jsx("path",{d:"M3 9a2 2 0 0 1 2-2h1.5l1-1.5h5l1 1.5H19a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z"}),jsxRuntime.jsx("circle",{cx:"12",cy:"13",r:"3.2"})]})}function Gr(e){return jsxRuntime.jsxs(Ye,{...e,children:[jsxRuntime.jsx("rect",{x:"3",y:"6",width:"13",height:"12",rx:"2.5"}),jsxRuntime.jsx("path",{d:"m16 10 5-3v10l-5-3"})]})}function Yr(e){return jsxRuntime.jsxs(Ye,{...e,children:[jsxRuntime.jsx("path",{d:"M12 16V4m0 0 4 4m-4-4-4 4"}),jsxRuntime.jsx("path",{d:"M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})]})}function Zt(e){return jsxRuntime.jsxs(Ye,{...e,children:[jsxRuntime.jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),jsxRuntime.jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}var mt={shot:Kr,video:Gr,upload:Yr};function Qt(e){let t=e.videoWidth||1280,n=e.videoHeight||720,r=document.createElement("canvas");r.width=t,r.height=n;let o=r.getContext("2d");return o?(o.drawImage(e,0,0,t,n),new Promise(a=>r.toBlob(i=>a(i),"image/jpeg",.82))):Promise.resolve(null)}function Xr(e,t){return !Number.isFinite(t)||t<=0?Promise.resolve():new Promise(n=>{e.addEventListener("seeked",()=>n(),{once:true});try{e.currentTime=t;}catch{n();}})}var Jr=4e3;async function pt(e){if(typeof document>"u")return {poster:null,durationMs:0};let t=URL.createObjectURL(e),n=document.createElement("video");n.muted=true,n.playsInline=true,n.preload="auto",n.src=t;let r=async()=>{await new Promise((s,m)=>{if(n.readyState>=2)return s();n.addEventListener("loadeddata",()=>s(),{once:true}),n.addEventListener("error",()=>m(new Error("video decode failed")),{once:true});}),await Xr(n,Math.min(.1,(n.duration||0)/2));let i=await Qt(n),l=Number.isFinite(n.duration)?n.duration*1e3:0;return {poster:i,durationMs:l}},o,a=new Promise(i=>{o=window.setTimeout(()=>i({poster:null,durationMs:0}),Jr);});try{return await Promise.race([r().catch(()=>({poster:null,durationMs:0})),a])}finally{window.clearTimeout(o),n.removeAttribute("src"),URL.revokeObjectURL(t);}}async function ft(e){if(typeof document>"u")return null;let t=document.createElement("video");t.muted=true,t.playsInline=true,t.srcObject=e;try{return await t.play().catch(()=>{}),await new Promise(n=>{if(t.readyState>=2)return n();t.addEventListener("loadeddata",()=>n(),{once:!0}),window.setTimeout(n,600);}),await Qt(t)}catch{return null}finally{t.srcObject=null;}}async function gt(){if(typeof document>"u")return null;let e=document.createElement("canvas");e.width=1280,e.height=720;let t=e.getContext("2d");return t?(t.fillStyle="#0e0e12",t.fillRect(0,0,e.width,e.height),t.fillStyle="#52525b",t.beginPath(),t.moveTo(590,312),t.lineTo(590,408),t.lineTo(694,360),t.closePath(),t.fill(),new Promise(n=>e.toBlob(r=>n(r),"image/jpeg",.8))):null}var ht=60,Zr=25*1024*1024,en=[{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)"}],tn=[{label:"Small",value:2,dot:6},{label:"Medium",value:4,dot:9},{label:"Large",value:6,dot:12}],nn=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],rn=[{value:"shot",label:"Screenshot",hint:"This page, instantly",primary:true},{value:"video",label:"Video",hint:"Record up to 60s"},{value:"upload",label:"Upload",hint:"Image or video"}];function bt(){let{client:e,isOpen:t,closeCapture:n,user:r,capture:o,initialCapture:a,initialCaptureError:i,startVideoSession:l,consumePendingVideo:s,canRecordScreen:m,consumeRecordStartError:c}=Be(),[p,f]=Yt.useState(1),[g,v]=Yt.useState(null),[y,w]=Yt.useState({kind:"idle"}),[x,M]=Yt.useState(false),[P,I]=Yt.useState(0),[N,A]=Yt.useState(null),[B,Z]=Yt.useState(false),[U,W]=Yt.useState("arrow"),[te,ce]=Yt.useState(en[0].value),[$,h]=Yt.useState(tn[1].value),[b,C]=Yt.useState(""),[S,V]=Yt.useState("bug"),[O,G]=Yt.useState(r?.email??""),[L,fe]=Yt.useState(null),[Y,Re]=Yt.useState(null),[ge,z]=Yt.useState(0),[ne,re]=Yt.useState(null),[he,q]=Yt.useState(null),[oe,X]=Yt.useState(false),be=Yt.useRef(null),ve=Yt.useRef(null),Ce=Yt.useRef(null),ae=Yt.useRef(false),Te=Yt.useRef(false);Yt.useEffect(()=>{t||(Te.current=false);},[t]),Yt.useEffect(()=>{if(!t)return;if(Te.current){ae.current=false;return}Te.current=true,ae.current=false,f(1),v(null),C(""),Re(null),z(0),re(null),M(false),I(0),A(null),Z(false),q(null);let u=s();if(u)v("video"),re({blob:u.blob,durationMs:u.durationMs}),u.blob.size>Zr&&sonner.toast.warning("This recording is large and may be too big to upload. Try a shorter clip if the upload fails."),u.poster?w({kind:"ready",capture:De(u.poster,["Screen recording; preview is the first frame."])}):(w({kind:"capturing"}),(async()=>{let R=null;if(u.deriveBlobPoster)try{R=(await pt(u.blob)).poster;}catch{R=null;}R=R??await gt(),!ae.current&&w(R?{kind:"ready",capture:De(R,["Screen recording; preview is the first frame."])}:{kind:"manual"});})());else {let R=c();R?(v("video"),q(R),w({kind:"idle"})):a?(v("shot"),w({kind:"ready",capture:a})):o?.mode==="manual"?w({kind:"manual"}):o?.provider&&!i?(v("shot"),Pe(o.mode??"auto")):w({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."});}return ()=>{ae.current=true;}},[t,o,a,i]),Yt.useEffect(()=>{if(!t)return;Ce.current=document.activeElement??null;let u=document.documentElement,R=u.style.overflow,F=u.style.paddingRight,j=window.innerWidth-u.clientWidth;u.style.overflow="hidden",j>0&&(u.style.paddingRight=`${j}px`);let J=false,ye=()=>{if(!J){J=true,u.style.overflow=R,u.style.paddingRight=F;try{Ce.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",ye),()=>{window.removeEventListener("pagehide",ye),ye();}},[t]),Yt.useEffect(()=>{if(!t)return;function u(R){if(R.key==="Escape"){R.preventDefault(),n();return}if(R.key!=="Tab")return;let F=ve.current;if(!F)return;let j=so(F);if(j.length===0)return;let J=j[0],ye=j[j.length-1],rt=document.activeElement;R.shiftKey&&(rt===J||!F.contains(rt))?(R.preventDefault(),ye.focus()):!R.shiftKey&&rt===ye&&(R.preventDefault(),J.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),Yt.useEffect(()=>{if(!t||y.kind!=="manual")return;function u(R){let J=Array.from(R.clipboardData?.items??[]).find(ye=>ye.type.startsWith("image/"))?.getAsFile();J&&(R.preventDefault(),Ne(J));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,y.kind]),Yt.useEffect(()=>{if(!L)return;let u=Date.now(),R=window.setInterval(()=>{let F=Math.floor((Date.now()-u)/1e3);z(F),F>=ht&&we();},250);return ()=>window.clearInterval(R)},[L]);let de=Yt.useRef(null);if(de.current=L,Yt.useEffect(()=>{t||de.current&&(de.current.cancel(),de.current=null,fe(null),z(0));},[t]),Yt.useEffect(()=>()=>{de.current?.cancel();},[]),!t)return null;async function Pe(u){ae.current=false,w({kind:"capturing"});try{let R=await qe({...o,mode:u,target:o?.target??document.documentElement});return ae.current?!1:(_e(R),w({kind:"ready",capture:R}),!0)}catch(R){return ae.current||w({kind:"manual",error:R instanceof Error?R.message:"Automatic screenshot capture was unavailable."}),false}}async function xe(u){v(u),q(null),A(null),u!=="video"&&k(),u==="shot"?await Pe(o?.mode??"auto"):u==="video"?(re(null),w({kind:"idle"})):w({kind:"manual"});}async function Ne(u){if(u.type.startsWith("image/")){k();let R=De(u,["Manual image upload used."]);w({kind:"ready",capture:R});return}if(u.type.startsWith("video/")){w({kind:"capturing"});try{let{poster:R,durationMs:F}=await pt(u),j=R??await gt();if(!j){w({kind:"manual",error:"Could not read that video."});return}let J=De(j,["Uploaded video; preview is the first frame."]);re({blob:u,durationMs:F}),w({kind:"ready",capture:J});}catch{w({kind:"manual",error:"Could not read that video."});}return}sonner.toast.error("Choose an image (PNG, JPEG, WebP) or a video (MP4, WebM).");}function _e(u){u.warnings.length!==0&&sonner.toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function Ae(){try{let u=await qt(ht);fe(u);}catch(u){sonner.toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function we(){if(L)try{let u=await L.stop();Re({blob:u.blob,durationMs:u.durationMs});}catch(u){sonner.toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{fe(null);}}function et(){L?.cancel(),fe(null),Re(null),z(0);}function Fe(u){let R=jsxRuntime.jsxs("div",{className:"lumen-audio-row",children:[!L&&!Y?jsxRuntime.jsxs("button",{type:"button",onClick:Ae,className:u==="capture"?"lumen-voice-capture-btn":"lumen-btn-ghost",children:[jsxRuntime.jsx(Zt,{}),"Record voice note"]}):null,L?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-recording",children:[jsxRuntime.jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsxRuntime.jsx(ro,{stream:L.stream}),jsxRuntime.jsxs("span",{className:"lumen-rec-time",children:[ge,"s / ",ht,"s"]})]}),jsxRuntime.jsx("button",{type:"button",onClick:we,className:"lumen-btn-ghost",children:"Stop"}),jsxRuntime.jsx("button",{type:"button",onClick:et,className:"lumen-btn-ghost",children:"Cancel"})]}):null,Y&&!L?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(ao,{blob:Y.blob,durationMs:Y.durationMs}),jsxRuntime.jsx("button",{type:"button",onClick:()=>Re(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]});return u==="capture"?jsxRuntime.jsxs("div",{className:"lumen-voice-capture",children:[R,!L&&!Y?jsxRuntime.jsx("p",{className:"lumen-voice-capture-hint",children:"Say what went wrong while it\u2019s fresh."}):null]}):jsxRuntime.jsxs("div",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Add a voice note (optional)"}),R]})}async function ie(){q(null);try{await l();}catch(u){sonner.toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}function k(){re(null);}let H=y.kind==="ready";async function _(){if(L&&await we(),p===1){if(y.kind==="ready"){let u=await be.current?.flatten();A(u??y.capture.blob),Z(u!=null&&u!==y.capture.blob);}f(2);}else p===2?f(3):await Un();}function tt(){p>1&&f(u=>u-1);}async function Un(){if(y.kind!=="ready")return;let u=b.trim(),{capture:R}=y;M(true),I(0);try{let F=N??R.blob,j=await e.submit({rawText:u.length>0?u:void 0,category:S,submitterEmail:O.trim()||void 0,screenshot:F,audio:Y?.blob,audioDurationMs:Y?.durationMs,video:ne?.blob,videoDurationMs:ne?.durationMs,context:zt(R)},{onUploadProgress:J=>I(Math.min(.95,J))});I(1),sonner.toast.success("Feedback sent \u2014 thank you."),j.id,n();}catch(F){sonner.toast.error(F instanceof Error?F.message:"Could not submit feedback"),M(false);}}function Wn(u){u.target===u.currentTarget&&!x&&n();}let Ue=Math.round(P*100),nt=g==="video",$n=p===1&&!H||x,zn=p<3?"Next":x?Ue<95?`Uploading ${Ue}%\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:Wn,children:jsxRuntime.jsxs("div",{ref:ve,className:"lumen-modal","data-lumen-drawing":oe?"true":void 0,children:[jsxRuntime.jsx(no,{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(Qr,{step:p}),jsxRuntime.jsxs("div",{className:"lumen-modal-body",children:[p===1?jsxRuntime.jsx("div",{className:"lumen-pane",children:g===null?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:rn.map(u=>{let R=mt[u.value];return jsxRuntime.jsxs("button",{type:"button",className:"lumen-method-btn"+(u.primary?" lumen-method-primary":""),onClick:()=>xe(u.value),disabled:y.kind==="capturing",children:[jsxRuntime.jsx("span",{className:"lumen-method-ico",children:jsxRuntime.jsx(R,{})}),u.primary?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("span",{className:"lumen-method-text",children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]}),jsxRuntime.jsx("span",{className:"lumen-method-badge",children:"Fastest"})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("span",{className:"lumen-method-label",children:u.label}),jsxRuntime.jsx("span",{className:"lumen-method-hint",children:u.hint})]})]},u.value)})}),jsxRuntime.jsx("p",{className:"lumen-status lumen-method-help",children:"Choose how to capture your feedback."})]}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"lumen-method-switch",role:"group","aria-label":"Switch capture method",children:rn.map(u=>{let R=mt[u.value];return jsxRuntime.jsxs("button",{type:"button","aria-pressed":g===u.value,onClick:()=>xe(u.value),disabled:y.kind==="capturing",children:[jsxRuntime.jsx(R,{}),u.label]},u.value)})}),g==="video"&&y.kind==="idle"?jsxRuntime.jsx(eo,{canRecord:m,onRecord:ie,onUpload:()=>xe("upload"),error:he}):null,y.kind==="capturing"?jsxRuntime.jsxs("p",{className:"lumen-status",children:[jsxRuntime.jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,y.kind==="manual"?jsxRuntime.jsxs("div",{className:"lumen-manual-capture",children:[jsxRuntime.jsx("p",{className:"lumen-status",children:g==="upload"?"Choose an image or video to attach \u2014 or paste an image.":y.error?"Automatic capture was unavailable. Upload or paste an image to continue.":"Upload or paste an image to continue."}),jsxRuntime.jsxs("label",{className:"lumen-manual-drop",children:[jsxRuntime.jsx("span",{children:g==="upload"?"Choose a file \u2014 image or video":"Choose or paste an image"}),jsxRuntime.jsx("input",{type:"file",accept:g==="upload"?"image/png,image/jpeg,image/webp,video/mp4,video/webm,video/quicktime":"image/png,image/jpeg,image/webp",onChange:u=>{let R=u.currentTarget.files?.[0];R&&Ne(R),u.currentTarget.value="";}})]})]}):null,y.kind==="ready"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[nt?null:jsxRuntime.jsxs("div",{className:"lumen-toolbar",children:[jsxRuntime.jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsxRuntime.jsx(Je,{label:"Arrow",active:U==="arrow",onClick:()=>W("arrow")}),jsxRuntime.jsx(Je,{label:"Box",active:U==="rect",onClick:()=>W("rect")}),jsxRuntime.jsx(Je,{label:"Draw",active:U==="freehand",onClick:()=>W("freehand")}),jsxRuntime.jsx(Je,{label:"Comment",active:U==="comment",onClick:()=>W("comment")})]}),jsxRuntime.jsx("span",{className:"lumen-toolbar-sep"}),jsxRuntime.jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:en.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":te===u.value,onClick:()=>ce(u.value)},u.value))}),jsxRuntime.jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:tn.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":$===u.value,onClick:()=>h(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:()=>be.current?.undo(),children:"Undo"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>be.current?.reset(),children:"Clear"})]}),jsxRuntime.jsx("div",{className:"lumen-annotate",children:jsxRuntime.jsx(Xt,{ref:be,screenshot:y.capture.blob,tool:U,color:te,strokeWidth:$,onDrawingChange:X})}),jsxRuntime.jsxs("div",{className:"lumen-cap-actions",children:[jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>g&&xe(g),children:nt?"\u21BB Re-record":"\u21BB Recapture"}),nt?ne?jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round(ne.durationMs/1e3),"s recorded"]}):null:jsxRuntime.jsxs("span",{className:"lumen-cap-note",children:[on(g)," captured \xB7 switch method above anytime"]})]}),Fe("capture")]}):null]})}):null,p===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:b,onChange:u=>C(u.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),Fe("describe"),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:nn.map(u=>jsxRuntime.jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":S===u.value,onClick:()=>V(u.value),children:u.label},u.value))})]}),jsxRuntime.jsxs("label",{className:"lumen-label",children:[jsxRuntime.jsx("span",{children:"Your email (optional)"}),jsxRuntime.jsx("input",{type:"email",value:O,onChange:u=>G(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,p===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:[on(g),B?" \xB7 annotated":"",jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>f(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:nn.find(u=>u.value===S)?.label}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>f(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:[b.trim()?b.trim():jsxRuntime.jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-edit",onClick:()=>f(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:[Y?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(Y.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>Re(null),children:"\xD7"})]}):null,ne?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round(ne.durationMs/1e3),"s",jsxRuntime.jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:k,children:"\xD7"})]}):null,O.trim()?jsxRuntime.jsxs("span",{className:"lumen-attach",children:["\u2709 ",O.trim()]}):null,!Y&&!L?jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{f(2),Ae();},children:"+ Voice note"}):null]})]})]}):null]}),jsxRuntime.jsxs("footer",{className:"lumen-modal-footer",children:[x?jsxRuntime.jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Ue,children:jsxRuntime.jsx("div",{className:"lumen-progress-fill",style:{width:`${Ue}%`}})}):null,jsxRuntime.jsxs("div",{className:"lumen-modal-actions",children:[jsxRuntime.jsx("button",{type:"button",onClick:p===1?n:tt,className:"lumen-btn-ghost",disabled:x,children:p===1?"Cancel":"Back"}),jsxRuntime.jsx("button",{type:"button",onClick:_,className:"lumen-btn-primary",disabled:$n,children:zn})]})]})]})})}function on(e){return e==="video"?"Screen recording":e==="upload"?"Upload":"Screenshot"}function Qr({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,r)=>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}),r<t.length-1?jsxRuntime.jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function eo({canRecord:e,onRecord:t,onUpload:n,error:r}){return e?jsxRuntime.jsxs("div",{className:"lumen-record-prompt",children:[r?jsxRuntime.jsxs("p",{className:"lumen-record-unavailable",role:"alert",children:[r," Try again, or switch to ",jsxRuntime.jsx("strong",{children:"Upload"})," to attach a video instead."]}):null,jsxRuntime.jsx("button",{type:"button",className:"lumen-record-btn","aria-label":"Start screen recording",onClick:t}),jsxRuntime.jsxs("div",{className:"lumen-record-copy",children:[jsxRuntime.jsx("div",{className:"lumen-record-title",children:"Record your screen"}),jsxRuntime.jsx("div",{className:"lumen-record-sub",children:"Tap to start. The sheet closes so you can record freely \u2014 a Stop button stays on screen, then the sheet returns with your clip. Max 60s."})]})]}):jsxRuntime.jsxs("div",{className:"lumen-record-prompt",children:[jsxRuntime.jsx("p",{className:"lumen-record-unavailable",children:to()?jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Screen recording isn\u2019t available on iOS browsers. Record with Control Center\u2019s screen recorder, then attach the clip below."}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:"Screen recording isn\u2019t available in this browser. Upload a video to attach one instead."})}),jsxRuntime.jsx("button",{type:"button",className:"lumen-btn-primary lumen-record-upload",onClick:n,children:"Upload a video"})]})}function to(){if(typeof navigator>"u")return false;let e=navigator.userAgent||"";return /iPad|iPhone|iPod/.test(e)?true:/Macintosh/.test(e)&&typeof document<"u"&&"ontouchend"in document}function Je({label:e,active:t,onClick:n}){return jsxRuntime.jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function no({onDismiss:e}){let t=Yt.useRef(null),n=Yt.useRef(0),r=Yt.useRef(null);function o(l){l.currentTarget.setPointerCapture(l.pointerId),t.current=l.clientY,n.current=performance.now(),r.current=l.currentTarget.parentElement;}function a(l){if(t.current==null||!r.current)return;let s=Math.max(0,l.clientY-t.current);r.current.style.transform=`translateY(${s}px)`;}function i(l){if(t.current==null||!r.current)return;let s=Math.max(0,l.clientY-t.current),m=Math.max(1,performance.now()-n.current),c=s/m;r.current.style.transform="",r.current.style.transition="",t.current=null,(s>80||c>.6)&&e();}return jsxRuntime.jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:o,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function ro({stream:e}){let t=Yt.useRef(null);return Yt.useEffect(()=>{let n=t.current;if(!n)return;let r=Math.min(window.devicePixelRatio||1,2),o=n.clientWidth||88,a=n.clientHeight||22;n.width=Math.round(o*r),n.height=Math.round(a*r);let i=n.getContext("2d");if(!i)return;i.scale(r,r);let l=window.AudioContext??window.webkitAudioContext;if(!l)return;let s=new l,m=s.createMediaStreamSource(e),c=s.createAnalyser();c.fftSize=1024,c.smoothingTimeConstant=.6,m.connect(c);let p=new Uint8Array(c.fftSize),f=18,g=3,v=3,y=Math.max(2,(o-g*(f-1))/f),w=Math.min(y/2,3),x=new Array(f).fill(0),M=0,P=false;function I(){if(P)return;c.getByteTimeDomainData(p);let N=Math.floor(p.length/f);i.clearRect(0,0,o,a),i.fillStyle=io("--lumen-danger")||"rgb(239,68,68)";for(let A=0;A<f;A++){let B=0;for(let $=0;$<N;$++){let h=Math.abs((p[A*N+$]??128)-128);h>B&&(B=h);}let Z=Math.min(1,B/128*1.8),U=x[A]??0;x[A]=Z>U?Z:U+(Z-U)*.35;let W=Math.max(v,x[A]*a),te=A*(y+g),ce=(a-W)/2;oo(i,te,ce,y,W,w),i.fill();}M=requestAnimationFrame(I);}return M=requestAnimationFrame(I),()=>{P=true,cancelAnimationFrame(M);try{m.disconnect();}catch{}s.close();}},[e]),jsxRuntime.jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function oo(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let l=e;if(typeof l.roundRect=="function"){l.roundRect(t,n,r,o,i);return}e.moveTo(t+i,n),e.arcTo(t+r,n,t+r,n+o,i),e.arcTo(t+r,n+o,t,n+o,i),e.arcTo(t,n+o,t,n,i),e.arcTo(t,n,t+r,n,i),e.closePath();}function ao({blob:e,durationMs:t}){let[n,r]=Yt.useState("");return Yt.useEffect(()=>{let o=URL.createObjectURL(e);return r(o),()=>{URL.revokeObjectURL(o);}},[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 io(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var lo='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function so(e){return Array.from(e.querySelectorAll(lo)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}var Ze=class extends Yt__namespace.Component{state={hasError:false};static getDerivedStateFromError(){return {hasError:true}}componentDidCatch(t){if(typeof document<"u"){let n=document.documentElement;n.style.overflow="",n.style.paddingRight="",document.body.removeAttribute("data-lumen-open");}console.error("[lumen] recovered from a widget error:",t),sonner.toast.error("Feedback widget hit a snag and was reset. Please try again."),Promise.resolve().then(()=>this.props.onReset());}render(){return this.state.hasError?null:this.props.children}};function cn({state:e,portalTarget:t,onStop:n,onCancel:r}){let[o,a]=Yt.useState(false);if(Yt.useEffect(()=>a(true),[]),!o||typeof document>"u")return null;let i=t??document.body;return e.phase==="recording"?reactDom.createPortal(jsxRuntime.jsx(co,{startedAt:e.startedAt,maxSeconds:e.maxSeconds,onStop:n,onCancel:r}),i):reactDom.createPortal(jsxRuntime.jsxs("div",{className:"lumen-rec-hud lumen-rec-hud-pending",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-spinner","aria-hidden":"true"}),jsxRuntime.jsx("span",{className:"lumen-rec-hud-time",children:e.phase==="starting"?"Starting\u2026":"Processing\u2026"}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"})]}),i)}function co({startedAt:e,maxSeconds:t,onStop:n,onCancel:r}){let[o,a]=Yt.useState(0);Yt.useEffect(()=>{let l=()=>a(Math.min(t,Math.max(0,Math.floor((Date.now()-e)/1e3))));l();let s=window.setInterval(l,250);return ()=>window.clearInterval(s)},[e,t]);let i=l=>`${Math.floor(l/60)}:${String(l%60).padStart(2,"0")}`;return jsxRuntime.jsxs("div",{className:"lumen-rec-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-dot","aria-hidden":"true"}),jsxRuntime.jsxs("span",{className:"lumen-rec-hud-time",children:[i(o)," ",jsxRuntime.jsxs("span",{className:"lumen-rec-hud-max",children:["/ ",i(t)]})]}),jsxRuntime.jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"}),jsxRuntime.jsxs("button",{type:"button",className:"lumen-rec-hud-stop",onClick:n,"aria-label":"Stop recording and return to feedback",children:[jsxRuntime.jsx("span",{className:"lumen-rec-hud-square","aria-hidden":"true"}),"Stop"]})]})}function vt(e){let t=e.hasProvider&&e.providerAvailable!==false;return {canRecord:t||e.hasGetDisplayMedia,usingProvider:t}}function dn(e){return typeof e=="object"&&e!==null&&e.code==="RECORDER_STOPPED"}function mn(e){return e instanceof Error?e:new Error(String(e))}function pn(e,t,n){let r=false,o=false,a=false,i=null;function l(){o||(o=true,n.onCancelled());}function s(c){o||(o=true,n.onResult(c));}function m(c){o||(o=true,n.onError(c));}return n.onStarting(),Promise.resolve().then(()=>e(t)).then(c=>{if(i=c,r){try{c.cancel();}catch{}l();return}if(n.onActive(c),a){n.onProcessing();try{c.stop();}catch{}}Promise.resolve(c.result).then(p=>{r?l():s(p);}).catch(p=>{r||dn(p)?l():m(mn(p));});}).catch(c=>{r||dn(c)?l():m(mn(c));}),{stop(){if(!(o||r||a)&&(a=true,i)){n.onProcessing();try{i.stop();}catch{}}},cancel(){if(!(o&&r)){if(r=true,i)try{i.cancel();}catch{}l();}}}}function fn(){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,r=[Math.round(e*.1),Math.round(e*.5),Math.round(e*.9)],o=new Set,a=0;for(let i of r){let l=document.elementsFromPoint(i,n);for(let s of l){if(o.has(s))continue;o.add(s);let m=window.getComputedStyle(s);if(m.position!=="fixed"&&m.position!=="sticky")continue;let c=s.getBoundingClientRect();c.bottom<t-8||c.bottom>t+8||c.width<e*.6||c.height>a&&(a=c.height);}}return a}function wt(e,t){if(typeof document>"u"||typeof window>"u")return 0;let n=window.innerWidth,r=window.innerHeight,o=0;for(let a of e){let i;try{i=document.querySelectorAll(a);}catch{continue}for(let l of Array.from(i)){let s=l.getBoundingClientRect();if(s.height===0||s.width===0)continue;let m=0;switch(t){case "bottom":if(s.bottom<r-8)break;m=Math.max(0,r-s.top);break;case "top":if(s.top>8)break;m=Math.max(0,s.bottom);break;case "left":if(s.left>8)break;m=Math.max(0,s.right);break;case "right":if(s.right<n-8)break;m=Math.max(0,n-s.left);break}m>o&&(o=m);}}return o}function gn(e){let[t,n]=Yt.useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),r=Yt.useRef(t),o=go(e.avoid),a=e.placement,i=e.offset.x,l=e.offset.y;return Yt.useEffect(()=>{if(typeof window>"u")return;let s=0,m=false,c=()=>{if(s=0,m)return;let y=a[0]==="b"?"bottom":"top",w=a[1]==="r"?"right":"left",x=0,M=0;e.avoid==="auto"&&y==="bottom"?x=fn():Array.isArray(e.avoid)&&(x=wt(e.avoid,y),M=wt(e.avoid,w));let P={bottom:y==="bottom"?l+x:0,top:y==="top"?l+x:0,right:w==="right"?i+M:0,left:w==="left"?i+M:0},I=r.current;(P.bottom!==I.bottom||P.top!==I.top||P.right!==I.right||P.left!==I.left)&&(r.current=P,n(P));},p=()=>{s||(s=window.requestAnimationFrame(c));};p();let f=typeof ResizeObserver<"u"?new ResizeObserver(p):null;f?.observe(document.documentElement);let g=typeof MutationObserver<"u"?new MutationObserver(p):null;g?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",p);let v=window.visualViewport;return v?.addEventListener("resize",p),v?.addEventListener("scroll",p),()=>{m=true,s&&window.cancelAnimationFrame(s),f?.disconnect(),g?.disconnect(),window.removeEventListener("resize",p),v?.removeEventListener("resize",p),v?.removeEventListener("scroll",p);}},[a,i,l,o]),t}function go(e){return e===false?"false":e==="auto"?"auto":e.join("|")}var wo=100;function yo({editableFocused:e,baseline:t,vvHeight:n,threshold:r=wo}){return e?{open:t-n>r,baseline:t}:{open:false,baseline:n}}function Eo(){if(typeof document>"u")return false;let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;if(!e)return false;let t=e.tagName;return t==="INPUT"||t==="TEXTAREA"||t==="SELECT"?true:e.isContentEditable===true}function hn(e){let[t,n]=Yt.useState(false),r=Yt.useRef(0);return Yt.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;r.current=o.height;let a=0,i=()=>{a=0;let s=yo({editableFocused:Eo(),baseline:r.current,vvHeight:o.height});r.current=s.baseline,n(s.open);},l=()=>{a||(a=window.requestAnimationFrame(i));};return l(),o.addEventListener("resize",l),o.addEventListener("scroll",l),document.addEventListener("focusin",l),document.addEventListener("focusout",l),()=>{a&&window.cancelAnimationFrame(a),o.removeEventListener("resize",l),o.removeEventListener("scroll",l),document.removeEventListener("focusin",l),document.removeEventListener("focusout",l);}},[e]),t}function yn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o}){let[a,i]=Yt.useState(null),l=Yt.useRef(null),s=gn(e),m=hn(e.hideOnKeyboard);if(Yt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),xo(l,!n&&!m),!a)return null;let c=e.placement,p=c[0]==="b"?"bottom":"top",f=c[1]==="r"?"right":"left",g=p==="bottom"?s.bottom:s.top,v=f==="right"?s.right:s.left,y={position:"fixed",[p]:e.safeArea?`calc(${g}px + env(safe-area-inset-${p}, 0px))`:`${g}px`,[f]:e.safeArea?`calc(${v}px + env(safe-area-inset-${f}, 0px))`:`${v}px`,zIndex:e.zIndex,opacity:n||m?0:1,pointerEvents:n||m?"none":"auto",transition:"opacity 160ms ease"};return reactDom.createPortal(jsxRuntime.jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:y,"aria-label":e.label,"aria-hidden":n||m?true:void 0,tabIndex:n||m?-1:0,onPointerDown:w=>r?.(w.nativeEvent),onClick:w=>o(w.nativeEvent),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsxRuntime.jsx("span",{children:e.label})]}),a)}function xo(e,t){let n=Yt.useRef(false);Yt.useEffect(()=>{if(process.env.NODE_ENV==="production"||!t||n.current||typeof window>"u")return;let r=window.setTimeout(()=>{let o=e.current;if(!o)return;let a=o.getBoundingClientRect();if(a.width===0||a.height===0)return;let i=a.left+a.width/2,l=a.top+a.height/2,s=document.elementsFromPoint(i,l),m=bn(window.getComputedStyle(o).zIndex);for(let c of s){if(c===o||o.contains(c))continue;if(bn(window.getComputedStyle(c).zIndex)>m){n.current=true,console.warn("[lumen] trigger is occluded by",c);break}}},250);return ()=>window.clearTimeout(r)},[t,e]);}function bn(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function En({mount:e,label:t,icon:n,onPointerDown:r,onClick:o}){let[a,i]=Yt.useState(null);return Yt.useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;i(l);},[e]),a?reactDom.createPortal(jsxRuntime.jsxs("button",{type:"button",className:"lumen-btn lumen-btn-primary",onPointerDown:l=>r?.(l.nativeEvent),onClick:l=>o(l.nativeEvent),"aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsxRuntime.jsx("span",{children:t})]}),a):null}function xn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o}){let[a,i]=Yt.useState(null),[l,s]=Yt.useState(false),m=Yt.useRef(null);if(Yt.useEffect(()=>{typeof document>"u"||i(t??document.body);},[t]),!a)return null;let c=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function p(y){r?.(y.nativeEvent),m.current={x:y.clientX,y:y.clientY},s(true),y.currentTarget.setPointerCapture(y.pointerId);}function f(y){let w=m.current;if(!w)return;let x=y.clientX-w.x,M=y.clientY-w.y;(e.edge==="top"&&M>16||e.edge==="bottom"&&M<-16||e.edge==="right"&&x<-16||e.edge==="left"&&x>16)&&(m.current=null,o(y.nativeEvent));}function g(){m.current=null,s(false);}function v(){m.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:y=>o(y.nativeEvent),onPointerDown:p,onPointerMove:f,onPointerUp:g,onPointerCancel:v,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 kn(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function Sn(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 Vo={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-radius":"radius"};function Mn(e){let t=Yt.useId();Yt.useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,r=`data-lumen-theme-${_o(t)}`,o={},a=(i,l)=>{o[i]=n.style.getPropertyValue(i)||null,n.style.setProperty(i,l);};if(e==="auto"||e==null)n.removeAttribute("data-lumen-theme");else if(e==="light"||e==="dark")o["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e);else {for(let[i,l]of Object.entries(Vo)){let s=e[l];typeof s=="string"&&s.length>0&&a(i,s);}typeof e.accent=="string"&&e.accent.length>0&&(a("--lumen-accent",e.accent),a("--lumen-primary",e.accent),a("--lumen-accent-fg","#ffffff")),(e.scheme==="light"||e.scheme==="dark")&&(o["data-lumen-theme"]=n.getAttribute("data-lumen-theme"),n.setAttribute("data-lumen-theme",e.scheme));}return n.setAttribute(r,""),()=>{n.removeAttribute(r);for(let[i,l]of Object.entries(o))i.startsWith("--")?l?n.style.setProperty(i,l):n.style.removeProperty(i):l==null?n.removeAttribute(i):n.setAttribute(i,l);}},[e,t]);}function _o(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var Tn=Symbol.for("lumen.history.patched"),yt="lumen:locationchange";function Wo(){if(typeof window>"u")return;let e=window;if(e[Tn])return;e[Tn]=true;let t=()=>window.dispatchEvent(new Event(yt)),n=history.pushState;history.pushState=function(...o){let a=n.apply(this,o);return t(),a};let r=history.replaceState;history.replaceState=function(...o){let a=r.apply(this,o);return t(),a},window.addEventListener("popstate",t);}function Pn(e){let[t,n]=Yt.useState(false);return Yt.useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;Wo();let r=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return r(),window.addEventListener(yt,r),window.addEventListener("popstate",r),()=>{window.removeEventListener(yt,r),window.removeEventListener("popstate",r);}},[e]),t}var qo=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function Ln(){let[e,t]=Yt.useState(false);return Yt.useEffect(()=>{if(typeof window>"u")return;let n=window;if(n.ReactNativeWebView){t(true);return}let r=n.webkit;if(r&&r.messageHandlers){t(true);return}let o=navigator.userAgent||"";qo.some(a=>o.includes(a))&&t(true);},[]),e}var An="lumen.config.v1.",Go=3600*1e3;function In(e,t){let[n,r]=Yt.useState(()=>({trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:true}));return Yt.useEffect(()=>{if(typeof window>"u")return;let o=ea(e);o&&r({trigger:o.trigger,enabled:Nn(o.trigger),shakeToOpen:o.shake,brand:o.brand,loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),l=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(l,{method:"GET",mode:"cors",credentials:"omit",signal:a.signal}).then(async s=>{if(!s.ok)throw new Error(`HTTP ${s.status}`);let m=await s.json(),c=Dn(m.trigger);if(!c)throw new Error("Malformed config response");let p=Jo(m.trigger),f=On(m.brand);ta(e,c,p,f),r({trigger:c,enabled:Nn(c),shakeToOpen:p,brand:f,loading:false});}).catch(()=>{r(s=>s.loading?{trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:false}:s);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function Nn(e){return e.kind!=="headless"}var Yo=["br","bl","tr","tl"],Xo=["top","right","bottom","left"];function Dn(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:Yo.find(o=>o===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:Xo.find(o=>o===t.edge)??"top",label:n}:null}function Jo(e){return !e||typeof e!="object"?false:e.shake===true}var Zo=/^#[0-9a-fA-F]{6}$/,Qo=["auto","light","dark"];function On(e){if(!e||typeof e!="object")return null;let t=e,n=typeof t.accent=="string"&&Zo.test(t.accent)?t.accent:null;if(!n)return null;let r=Qo.find(a=>a===t.mode)??"auto",o=typeof t.radius=="number"&&Number.isFinite(t.radius)?Math.min(20,Math.max(0,Math.round(t.radius))):10;return {accent:n,mode:r,radius:o}}function ea(e){try{let t=window.localStorage.getItem(An+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>Go)return null;let r=Dn(n.trigger);return r?{fetchedAt:n.fetchedAt,trigger:r,shake:n.shake===!0,brand:On(n.brand)}:null}catch{return null}}function ta(e,t,n,r){try{window.localStorage.setItem(An+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n,brand:r}));}catch{}}function ra(e){if(e&&typeof e=="object")return e.type===Ke;if(typeof e=="string")try{return JSON.parse(e).type===Ke}catch{return false}return false}function oa(e={}){let t=e.threshold??18,n=e.neededHits??3,r=e.windowMs??700,o=e.throttleMs??60,a=null,i=[];return {push(l,s,m,c){if(!a)return a={x:l,y:s,z:m,t:c},false;if(c-a.t<o)return false;let p=Math.abs(l-a.x)+Math.abs(s-a.y)+Math.abs(m-a.z);return a={x:l,y:s,z:m,t:c},p<t?false:(i=i.filter(f=>c-f<r),i.push(c),i.length>=n?(i=[],true):false)}}}function Bn(e,t,n){Yt.useEffect(()=>{if(!e||typeof window>"u")return;let r=0,o=1500;function a(){let c=Date.now();n||c-r<o||(r=c,t());}let i=c=>{ra(c.data)&&a();};window.addEventListener("message",i),document.addEventListener("message",i);let l=oa(),s=c=>{let p=c.accelerationIncludingGravity??c.acceleration;!p||p.x==null||p.y==null||p.z==null||l.push(p.x,p.y,p.z,Date.now())&&a();},m=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return m&&window.addEventListener("devicemotion",s),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),m&&window.removeEventListener("devicemotion",s);}},[e,t,n]);}var Vn="https://shakebugs.vercel.app",Qe=60;function _n(){return typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function"}function ia({apiKey:e,apiUrl:t,user:n,amplitude:r,floatingButton:o=true,trigger:a,hideOn:i,theme:l,portalTarget:s,capture:m,record:c,shakeToOpen:p,onOpenChange:f,beforeOpen:g,onTriggerActivate:v,children:y}){let[w,x]=Yt.useState(false),[M,P]=Yt.useState(false),[I,N]=Yt.useState(null),[A,B]=Yt.useState(null),[Z]=Yt.useState(false),[U]=Yt.useState(null),W=Yt.useRef(false),te=Yt.useRef(false),ce=Yt.useRef(null),$=Yt.useMemo(()=>new At({apiKey:e,apiUrl:t,user:n,amplitude:r}),[e,t,n?.id,n?.email,n?.name,r?.userId,r?.deviceId,r?.sessionId]);Yt.useEffect(()=>{Wt({ignoreUrlPrefix:(t??Vn).replace(/\/$/,"")});},[t]);let h=Yt.useRef(f);h.current=f,Yt.useEffect(()=>{if(!(typeof document>"u"))return w?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[w]);let b=Yt.useRef(null);Yt.useEffect(()=>{if(b.current===w)return;let k=b.current;b.current=w,k!==null&&h.current?.(w);},[w]);let C=Yt.useRef(g);C.current=g;let S=Yt.useRef(v);S.current=v;let V=Yt.useCallback(k=>{te.current=true,ce.current=Promise.resolve().then(()=>C.current?.(k)).then(()=>S.current?.(k)).then(()=>{});},[]),O=Yt.useCallback(k=>{W.current||w||oe.current||(W.current=true,P(true),N(null),B(null),(async()=>{try{if(te.current?await ce.current:(await C.current?.(k),await S.current?.(k)),m?.mode==="manual")N(null),B(null);else if(m?.provider)N(null),B(null);else {let H=await qe({...m,mode:m?.mode??"auto",target:m?.target??document.documentElement});N(H);}}catch(H){B(H instanceof Error?H:new Error(String(H)));}finally{te.current=false,ce.current=null,W.current=false,P(false),x(true);}})());},[m,w]),G=Yt.useCallback(()=>{x(false),N(null),B(null);},[]),L=Yt.useCallback($.submit.bind($),[$]),[fe,Y]=Yt.useState(0),Re=Yt.useCallback(()=>{W.current=false,P(false),x(false),N(null),B(null),Y(k=>k+1);},[]),[ge,z]=Yt.useState(null),[ne,re]=Yt.useState(null),he=Yt.useRef(null),q=Yt.useRef(null),oe=Yt.useRef(false),X=Yt.useRef(null),be=Yt.useRef(null),ve=Yt.useRef(null),Ce=Yt.useCallback((k,H=false)=>{if(he.current=null,q.current=null,oe.current=false,z(null),!k){X.current=null;return}be.current={blob:k.blob,durationMs:k.durationMs,poster:X.current,deriveBlobPoster:H},X.current=null,x(true);},[]);Yt.useEffect(()=>{if(!w)return;if(!c?.provider){re(null);return}let k=c.isAvailable;if(!k){re(true);return}let H=false;return Promise.resolve().then(()=>k()).then(_=>{H||re(_);}).catch(()=>{H||re(false);}),()=>{H=true;}},[w,c?.provider,c?.isAvailable]);let ae=vt({hasProvider:!!c?.provider,providerAvailable:ne,hasGetDisplayMedia:_n()}).canRecord,Te=Yt.useCallback(async()=>{if(oe.current)return;if(ve.current=null,vt({hasProvider:!!c?.provider,providerAvailable:ne,hasGetDisplayMedia:_n()}).usingProvider&&c?.provider){oe.current=true,X.current=null,x(false),q.current=pn(c.provider,{maxDurationSeconds:Qe},{onStarting:()=>z({phase:"starting"}),onActive:_=>{z({phase:"recording",stream:_.stream??null,startedAt:Date.now(),maxSeconds:Qe}),_.stream&&ft(_.stream).then(tt=>{X.current=tt;}).catch(()=>{});},onProcessing:()=>z({phase:"processing"}),onResult:_=>Ce({blob:_.blob,durationMs:_.durationMs},true),onCancelled:()=>{q.current=null,oe.current=false,X.current=null,z(null),N(null),B(null),x(true);},onError:_=>{q.current=null,oe.current=false,X.current=null,z(null),ve.current=_.message||"Screen recording could not start.",x(true);}});return}if(he.current)return;let H=await jt(Qe);he.current=H,oe.current=true,X.current=null,z({phase:"recording",stream:H.stream,startedAt:Date.now(),maxSeconds:Qe}),x(false),ft(H.stream).then(_=>{X.current=_;}).catch(()=>{}),H.result.then(_=>Ce(_)).catch(()=>Ce(null));},[Ce,c?.provider,ne]),de=Yt.useCallback(()=>{q.current?q.current.stop():he.current?.stop();},[]),Pe=Yt.useCallback(()=>{if(q.current){q.current.cancel();return}let k=he.current;he.current=null,oe.current=false,X.current=null,z(null),k?.cancel(),N(null),B(null),x(true);},[]),xe=Yt.useCallback(()=>{let k=be.current;return be.current=null,k},[]),Ne=Yt.useCallback(()=>{let k=ve.current;return ve.current=null,k},[]);Yt.useEffect(()=>{w||(ve.current=null);},[w]);let _e=Ln(),Ae=Pn(i),we=In(a?"":e,t??Vn);Mn(l??ua(we.brand));let et=p??we.shakeToOpen;Bn(et,O,w);let Fe=Yt.useMemo(()=>({client:$,user:n,isOpen:w,isSubmitting:Z,error:U,open:O,close:G,openCapture:O,closeCapture:G,submit:L,isNativeShell:_e,capture:m,initialCapture:I,initialCaptureError:A,isOpening:M,startVideoSession:Te,stopVideoSession:de,cancelVideoSession:Pe,recording:ge,consumePendingVideo:xe,canRecordScreen:ae,consumeRecordStartError:Ne}),[$,n,w,Z,U,O,G,L,_e,m,I,A,Te,de,Pe,ge,xe,ae,Ne,M]),ie=sa({explicit:a,remote:we.trigger,remoteLoading:we.loading,floatingButton:o});return jsxRuntime.jsxs(st.Provider,{value:Fe,children:[y,jsxRuntime.jsxs(Ze,{onReset:Re,children:[ie?.kind==="floating"?jsxRuntime.jsx(yn,{config:Sn(ie),portalTarget:s,hidden:Ae||M||ge!=null,onPointerDown:V,onClick:k=>O(k)}):null,ie?.kind==="notch"?jsxRuntime.jsx(xn,{config:kn(ie),portalTarget:s,hidden:Ae||M||ge!=null,onPointerDown:V,onClick:k=>O(k)}):null,ie?.kind==="inline"?jsxRuntime.jsx(En,{mount:ie.mount,label:ie.label??"Feedback",icon:ie.icon,onPointerDown:V,onClick:k=>O(k)}):null,ge?jsxRuntime.jsx(cn,{state:ge,portalTarget:s,onStop:de,onCancel:Pe}):null,jsxRuntime.jsx(bt,{})]},fe),jsxRuntime.jsx(la,{})]})}function la(){let[e,t]=Yt.useState(false);return Yt.useEffect(()=>{t(!document.querySelector("[data-sonner-toaster]"));},[]),e?jsxRuntime.jsx(sonner.Toaster,{position:"top-center",style:{zIndex:2147483647}}):null}function sa(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function ua(e){if(e)return {accent:e.accent,radius:`${e.radius}px`,scheme:e.mode}}function ca({variant:e="default",floating:t=false,className:n,children:r="Feedback",onClick:o,...a}){let{openCapture:i}=Be(),l=["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:l,"data-lumen-trigger":"",onClick:s=>{o?.(s),s.defaultPrevented||i(s.nativeEvent);},...a,children:r})}
4
+ exports.CaptureModal=bt;exports.FeedbackButton=ca;exports.LUMEN_SHAKE_MESSAGE=Ke;exports.LumenProvider=ia;exports.createNativeCaptureProvider=kr;exports.isLumenEventTarget=Hr;exports.useLumen=Be;//# sourceMappingURL=index.cjs.map
5
5
  //# sourceMappingURL=index.cjs.map