@lumen-stack/react 0.12.1 → 0.12.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.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use client";
2
- import*as Rn from'react';import {createContext,useRef,useState,useCallback,useEffect,useImperativeHandle,useContext,useMemo,useId}from'react';import {toast,Toaster}from'sonner';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';var N=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},zt=class extends N{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},Kt=class extends N{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},at=class extends N{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},br="https://shakebugs.vercel.app",vr="/api/v1/sdk/submit",wr=new Set([502,503,504]),en=class{apiKey;apiUrl;user;amplitude;constructor(e){if(!e.apiKey||!e.apiKey.startsWith("lk_pub_"))throw new N("Invalid Lumen apiKey \u2014 expected a key starting with `lk_pub_`.","INVALID_API_KEY");this.apiKey=e.apiKey,this.apiUrl=(e.apiUrl??br).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${vr}`,r=this.#e(e),o=null;for(let a=0;a<3;a++){a>0&&await Er(2**a*250);try{return await this.#t(n,r,t)}catch(i){if(o=i,i instanceof zt||i instanceof Kt||i instanceof N&&typeof i.status=="number"&&!wr.has(i.status))throw i}}throw o instanceof Error?o:new at("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,yr(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:s}=n;i&&a.upload.addEventListener("progress",u=>{u.lengthComputable&&u.total>0&&i(Math.min(1,u.loaded/u.total));});let l=()=>{a.abort(),o(new at("Submit aborted."));};if(s){if(s.aborted){o(new at("Submit aborted."));return}s.addEventListener("abort",l,{once:true});}a.addEventListener("load",()=>{if(s&&s.removeEventListener("abort",l),a.status===403){o(new zt);return}if(a.status===429){let u=Number(a.getResponseHeader("Retry-After"))||60;o(new Kt(u));return}if(a.status<200||a.status>=300){o(new N(Cr(a.responseText)??`HTTP ${a.status}`,"HTTP_ERROR",a.status));return}try{let u=JSON.parse(a.responseText);r(u);}catch{o(new N("Malformed response from server.","BAD_RESPONSE"));}}),a.addEventListener("error",()=>{s&&s.removeEventListener("abort",l),o(new at("Network error during submit."));}),a.send(t);})}};function yr(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function Er(e){return new Promise(t=>setTimeout(t,e))}function Cr(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var tn='[data-lumen-root], [data-lumen-capture-ignore="true"]';function nn(e=tn){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;}}var Rr=2,Sr=1.5,xr=820,kr=12,$e=8*1024*1024;async function lt(e={}){kt();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return Ir(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 N("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return jt(e);if(t==="dom")return $t(e);if(t==="custom")throw new N("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await $t(e)}catch(n){if(ln()){let r=await jt(e);return r.warnings=je(["DOM screenshot failed; used browser screen permission fallback.",...r.warnings]),e.onWarning?.(r.warnings),r}throw n}}function qe(e,t=[]){kt();let n=ut();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:je(t)}}var Wt=Promise.resolve();function $t(e){let t=Wt.then(()=>qt(e),()=>qt(e));return Wt=t.catch(()=>{}),t}async function qt(e){let t=await Nr(),n=e.target??document.documentElement,r=ut(),o=Or(),a=window.visualViewport,i=window.scrollX+(a?.offsetLeft??0),s=window.scrollY+(a?.offsetTop??0),l=Br(e,r.width,r.height),u=Dr(n);!e.provider&&Ar()&&u.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 d=Tr(n);await sn(e.awaitAnimationsMs??Vr),await Hr();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:s,scale:l,ignoreElements:w=>w instanceof HTMLElement&&(w.dataset.lumenCaptureIgnore==="true"||!!w.closest("[data-lumen-capture-ignore='true']")),onclone:(w,g)=>{Pr(g,d),Mr(w);}}),h={blob:await an(p,u),method:"web-dom",platform:"web",viewport:r,pixelRatio:l,warnings:je(u)};return h.warnings.length>0&&e.onWarning?.(h.warnings),h}var rn=['input[type="password"]','input[autocomplete^="cc-"]','input[autocomplete="one-time-code"]',"[data-lumen-mask]"].join(", ");function Mr(e){for(let t of Array.from(e.querySelectorAll(rn))){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 Lr="[data-lumen-root], [data-lumen-capture-ignore='true']";function on(e){return Array.from(e.querySelectorAll("input")).filter(t=>!t.closest(Lr))}function Tr(e){return on(e).map(t=>{if(t.matches(rn))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 Pr(e,t){let n=on(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 Nr(){let{default:e}=await import('html2canvas-pro');return e}async function xt(e={}){if(kt(),!ln())throw new N("Browser screen capture is unavailable in this environment.","DISPLAY_MEDIA_UNAVAILABLE");let t=await navigator.mediaDevices.getDisplayMedia({video:true,audio:false}),n=null;try{n=document.createElement("video"),n.muted=!0,n.playsInline=!0,n.srcObject=t,await Fr(n);}catch(i){for(let s of t.getTracks())s.stop();throw i}let r=n,o=false,a=[];for(let i of t.getTracks())i.addEventListener("ended",()=>{o||a.forEach(s=>s());});return {stream:t,onEnded(i){a.push(i);},async grab(i){let s=i?.conceal??true,l=s?nn():()=>{};try{s&&await Ur(r,3,400);let u=document.createElement("canvas");u.width=r.videoWidth,u.height=r.videoHeight;let d=u.getContext("2d");if(!d)throw new N("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");d.drawImage(r,0,0,u.width,u.height);let p=ut(),h=["Browser screen capture uses the window or tab selected by the user."],w={blob:await an(u,h),method:"web-display-media",platform:"web",viewport:p,pixelRatio:p.width>0?u.width/p.width:void 0,warnings:je(h)};return e.onWarning?.(w.warnings),w}finally{l();}},stop(){if(!o){o=true;for(let i of t.getTracks())i.stop();r.srcObject=null;}}}}async function jt(e){let t=await xt(e);try{return await t.grab({conceal:!1})}finally{t.stop();}}function Ir(e,t){let n=ut(),r={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:je(e.warnings??[])};return r.warnings.length>0&&t.onWarning?.(r.warnings),r}function Dr(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 an(e,t){let n=await Yt(e,"image/png",.92);if(n.size<=$e)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let r=e,o=0;for(;n.size>$e&&o<6;){let a=Math.max(.35,Math.min(.95,Math.sqrt($e/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 s=i.getContext("2d");if(!s)return n;s.drawImage(r,0,0,i.width,i.height),r=i;for(let l of [.86,.74,.62,.5])if(n=await Yt(r,"image/jpeg",l),n.size<=$e)return n;if(o+=1,i.width<480||i.height<320)break}return n.size>$e&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function Yt(e,t,n){return new Promise((r,o)=>{e.toBlob(a=>{if(!a){o(new N("Could not encode screenshot.","ENCODE_FAILED"));return}r(a);},t,n);})}function ut(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function Or(){let e=document.documentElement;return {width:Math.round(e.clientWidth||window.innerWidth),height:Math.round(e.clientHeight||window.innerHeight)}}function Br(e,t,n){let r=window.devicePixelRatio??1,o=e.maxScale??Rr;_r()&&(o=Math.min(o,Sr));let a=Math.max(1,Math.min(r,o)),i=Math.sqrt(kr*1e6/Math.max(1,t*n));return Math.max(1,Math.min(a,i))}function _r(){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<=xr}function Hr(){return typeof requestAnimationFrame!="function"?new Promise(e=>setTimeout(e,32)):new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(()=>e())))}var Vr=400;async function sn(e){if(typeof document>"u"||typeof document.getAnimations!="function"||!(e>0))return;let t;try{t=document.getAnimations();}catch{return}let n=t.filter(a=>{if(a.playState!=="running")return false;let i=a.effect?.getComputedTiming?.();return !!i&&i.iterations!==1/0});if(n.length===0)return;let r=Promise.allSettled(n.map(a=>a.finished)).then(()=>{}),o=new Promise(a=>setTimeout(a,e));await Promise.race([r,o]);}function ln(){return !!navigator.mediaDevices?.getDisplayMedia}async function Fr(e){await new Promise((r,o)=>{let a=()=>r(),i=()=>o(new N("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 N("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(r=>requestAnimationFrame(()=>r()));}}async function Ur(e,t,n){let r=e.requestVideoFrameCallback?.bind(e);if(typeof r!="function"){await new Promise(i=>setTimeout(i,Math.min(n,250)));return}let o=performance.now(),a=0;await new Promise(i=>{let s=()=>{if(a+=1,a>=t||performance.now()-o>=n){i();return}r(s);};r(s),setTimeout(i,n);});}function kt(){if(typeof window>"u"||typeof document>"u")throw new N("Screenshot capture can only run in the browser.","INVALID_ENV")}function je(e){return Array.from(new Set(e.filter(Boolean)))}var un=/^(token|access_token|refresh_token|id_token|api_?key|key|secret|password|passwd|pwd|auth|authorization|sig|signature|session|sessionid|sid|email|jwt)$/i,zr=[/-----BEGIN (?:[A-Z]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z]+ )?PRIVATE KEY-----/g,/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,/\b(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA|ANVA|AIPA)[A-Z0-9]{16}\b/g,/\bgh[posru]_[A-Za-z0-9]{20,}\b/g,/\bgithub_pat_[A-Za-z0-9_]{20,}\b/g,/\bglpat-[A-Za-z0-9_-]{18,}\b/g,/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g,/\bAIza[A-Za-z0-9_-]{35}\b/g,/\b[srp]k_(?:live|test)_[A-Za-z0-9]{10,}\b/g,/\bsk-(?:proj-|ant-)?[A-Za-z0-9_-]{32,}\b/g];function Kr(e){let t=e.replace(/\D/g,"");if(t.length<13||t.length>19)return false;let n=0,r=false;for(let o=t.length-1;o>=0;o--){let a=t.charCodeAt(o)-48;r&&(a*=2,a>9&&(a-=9)),n+=a,r=!r;}return n%10===0}function Et(e){let t=e;for(let n of zr)t=t.replace(n,"***");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:un.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\d(?:[ -]?\d){12,18}\b/g,n=>Kr(n)?"***":n),t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***"),t=t.replace(/\b[\w.+-]+@[\w-]+\.[\w.-]+\b/g,"***@***"),t}function cn(e){try{let t=new URL(e,"http://relative.invalid");for(let r of [...t.searchParams.keys()])un.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 dn(e){try{let t=new URL(e);return `${t.origin}${t.pathname}`}catch{return cn(e)}}var Gt=200,Zt=4096,mn=[],it=[],Xt=false,Ct=null;function pn(e={}){Xt||typeof window>"u"||(Xt=true,Ct=e.ignoreUrlPrefix??null,jr(),Yr(),Gr());}function Wr(){return {consoleLog:mn.slice(),networkLog:it.slice()}}function st(e,t){e.push(t),e.length>Gt&&e.splice(0,e.length-Gt);}function $r(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,qr));}catch{t.push(String(r));}}let n=t.join(" ");return n.length>Zt?n.slice(0,Zt)+"\u2026[truncated]":n}function qr(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function jr(){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{st(mn,{level:n,ts:Date.now(),message:Et($r(o))});}catch{}r(...o);});}}function fn(e){return Ct?e.startsWith(Ct):false}function Yr(){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(fn(r))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return st(it,{type:"fetch",method:o,url:Rt(r),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw st(it,{type:"fetch",method:o,url:Rt(r),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function Gr(){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&&!fn(o.url)){o.t=performance.now();let a=()=>{try{st(it,{type:"xhr",method:o.method,url:Rt(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 Zr(e){return e.length>512?e.slice(0,512)+"\u2026":e}function Rt(e){return Zr(cn(e))}function gn(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:Jt(e),consoleLog:[],networkLog:[]};let t=Wr();return {url:dn(window.location.href),userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:Jt(e),device:Xr(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function Xr(){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?dn(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 Jt(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var Jr="[data-lumen-root]",Qr="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function eo(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(St(n))return true;return St(e.target)}var Qt=["pointerdown","mousedown","touchstart","click"];function to(e){if(!e||typeof e.addEventListener!="function")return ()=>{};let t=n=>n.stopPropagation();for(let n of Qt)e.addEventListener(n,t,n==="touchstart"?{passive:true}:void 0);return ()=>{for(let n of Qt)e.removeEventListener(n,t);}}function St(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(Qr)?true:!!e.closest(Jr):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?St(e.host):false:false}var ct="lumen:shake",no=8e3,ro=50,oo=400;function ao(e={}){return async function(){if(typeof window>"u")throw new N("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=so(),n=e.send??io,r=e.timeoutMs??no,o=e.captureSettleMs??ro,a=e.awaitAnimationsMs??oo,i=po(),s=nn(e.concealSelector===void 0?tn:e.concealSelector);try{await uo(o,a);let l=await new Promise((p,h)=>{let w=window.setTimeout(()=>{t.pending.delete(i),h(new N("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},r);t.pending.set(i,{resolve:g=>{window.clearTimeout(w),p(g);},reject:g=>{window.clearTimeout(w),h(g);}});try{n({type:"lumen:capture-request",id:i,afterScreenUpdates:!0});}catch{t.pending.delete(i),window.clearTimeout(w),h(new N("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(l.error||!l.dataUrl)throw new N(l.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let u=fo(l.dataUrl),d=e.platform??mo();return {blob:u,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{s();}}}function io(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new N("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function so(){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=lo(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 lo(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}async function uo(e,t){await sn(t),await co(),e>0&&await new Promise(n=>window.setTimeout(n,e));}function co(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function mo(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function po(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function fo(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new N("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 s=0;s<a.length;s++)i[s]=a.charCodeAt(s);return new Blob([i],{type:n})}var Ye="lumen:keyboardchange",Mt="--lumen-keyboard-inset";function go(e){if(typeof window>"u")return;let t=typeof e=="number"&&Number.isFinite(e)&&e>0?Math.round(e):0;window.__lumenKeyboardInset=t,typeof document<"u"&&document.documentElement.style.setProperty(Mt,`${t}px`),window.dispatchEvent(new Event(Ye));}function Lt(){if(typeof window>"u")return null;let e=window.__lumenKeyboardInset;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;if(typeof document<"u"&&typeof getComputedStyle=="function"){let t=getComputedStyle(document.documentElement).getPropertyValue(Mt).trim();if(t){let n=parseFloat(t);if(Number.isFinite(n)&&n>=0)return n}}return null}async function hn(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new N("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new N("Microphone access denied or unavailable.","MIC_DENIED")}let n=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus"].find(w=>MediaRecorder.isTypeSupported(w))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,s=false,l=false,u,d,p=new Promise((w,g)=>{u=w,d=g;});p.catch(()=>{}),r.addEventListener("dataavailable",w=>{w.data&&w.data.size>0&&o.push(w.data);}),r.addEventListener("stop",()=>{i!==null&&window.clearTimeout(i),i=null;for(let x of t.getTracks())x.stop();if(l)return;if(l=true,s){d(new N("Recording cancelled.","RECORDER_STOPPED"));return}let w=performance.now()-a,g=r.mimeType||n||"audio/webm",S=new Blob(o,{type:g});u({blob:S,durationMs:w,mimeType:g});}),r.start(),i=window.setTimeout(()=>{r.state!=="inactive"&&r.stop();},e*1e3);function h(){if(r.state!=="inactive")try{r.stop();}catch{}}return {stream:t,cancel(){s=true,h(),i!==null&&window.clearTimeout(i),i=null;for(let w of t.getTracks())w.stop();},stop(){return h(),p}}}async function bn(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new N("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new N("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(g=>MediaRecorder.isTypeSupported(g))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,s=false,l=false,u,d,p=new Promise((g,S)=>{u=g,d=S;});p.catch(()=>{});function h(){i!==null&&(window.clearTimeout(i),i=null);for(let g of t.getTracks())g.stop();}r.addEventListener("dataavailable",g=>{g.data&&g.data.size>0&&o.push(g.data);}),r.addEventListener("stop",()=>{if(s)return;if(s=true,h(),l){d(new N("Recording cancelled.","RECORDER_STOPPED"));return}let g=r.mimeType||n||"video/webm";u({blob:new Blob(o,{type:g}),durationMs:performance.now()-a,mimeType:g});});function w(){r.state!=="inactive"&&r.stop();}return r.start(),i=window.setTimeout(w,e*1e3),t.getVideoTracks()[0]?.addEventListener("ended",w),{stream:t,result:p,stop:w,cancel(){l=true,r.state!=="inactive"?r.stop():s||(s=true,h(),d(new N("Recording cancelled.","RECORDER_STOPPED")));}}}var Tt=createContext(null);function Ge(){let e=useContext(Tt);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var vn=100;function wn(){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}var Ze={open:false,inset:0};function yo(e){let t=e.override??e.injected;if(t!=null){let r=t>1&&e.editable;return r?{open:r,inset:Math.round(t)}:Ze}if(e.vvHeight==null||!e.coarse||!e.editable)return Ze;let n=e.vvBaseline-e.vvHeight;return n>vn?{open:true,inset:Math.round(n)}:Ze}function Xe(e,t){let[n,r]=useState(Ze),o=useRef(0),a=useRef(t);return a.current=t,useEffect(()=>{if(!e){r(Ze);return}if(typeof window>"u")return;let i=typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches,s=()=>{let p=wn(),h=a.current,w=Lt(),g=window.visualViewport??null;g&&h==null&&w==null&&!p&&(o.current=g.height),r(yo({editable:p,override:h,injected:w,vvBaseline:o.current,vvHeight:g?g.height:null,coarse:i}));},l=0,u=()=>{l||(l=window.requestAnimationFrame(()=>{l=0,s();}));},d=window.visualViewport;return d&&(o.current=d.height),u(),d?.addEventListener("resize",u),d?.addEventListener("scroll",u),document.addEventListener("focusin",u),document.addEventListener("focusout",u),window.addEventListener(Ye,u),()=>{l&&window.cancelAnimationFrame(l),d?.removeEventListener("resize",u),d?.removeEventListener("scroll",u),document.removeEventListener("focusin",u),document.removeEventListener("focusout",u),window.removeEventListener(Ye,u);}},[e]),n}var At='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, sans-serif';function Cn(e,t=1){return Math.max(0,Math.min(t,e))}var Sn=Rn.forwardRef(function({screenshot:t,tool:n,color:r="rgb(239, 68, 68)",strokeWidth:o=4,onDrawingChange:a},i){let s=useRef(null),l=useRef(null),u=useRef(null),[d,p]=useState(null),[h,w]=useState([]),g=useRef(null),S=useRef(false),x=useRef(0),M=useRef(false),[L,b]=useState([]),C=useRef(0),I=useRef([]),A=useRef(null),q=useCallback((f,y)=>{b(k=>k.map(T=>T.id===f?{...T,text:y}:T));},[]),D=useCallback(f=>{b(k=>k.filter(T=>T.id!==f));let y=I.current.lastIndexOf("comment");y>=0&&I.current.splice(y,1);},[]);useEffect(()=>{let f=A.current;if(f==null)return;A.current=null,u.current?.querySelector(`[data-bubble-id="${f}"] .lumen-bubble-text`)?.focus();},[L]),useEffect(()=>{let f=false,y=null;return (async()=>{try{let k=await createImageBitmap(t);if(f){k.close?.();return}y=k,p(k);}catch{}})(),()=>{f=true,y?.close?.();}},[t]),useEffect(()=>{if(!d)return;let f=s.current,y=l.current;if(!f||!y)return;f.width=d.width,f.height=d.height,y.width=d.width,y.height=d.height;let k=f.getContext("2d");k&&(k.imageSmoothingEnabled=false,k.drawImage(d,0,0));},[d]),useEffect(()=>{let f=l.current;f&&dt(f,h,g.current);},[h]),useImperativeHandle(i,()=>({hasAnnotations:()=>h.length>0||L.some(f=>f.text.trim().length>0),reset:()=>{w([]),b([]),I.current=[];},undo:()=>{(I.current.pop()??"anno")==="comment"?b(y=>y.length===0?y:y.slice(0,-1)):w(y=>y.length===0?y:y.slice(0,-1));},async flatten(){let f=g.current,y=f?[...h,f]:h,k=L.filter(F=>F.text.trim().length>0);if(y.length===0&&k.length===0||!d)return t;let T=document.createElement("canvas");T.width=d.width,T.height=d.height;let V=T.getContext("2d");if(!V)return t;V.imageSmoothingEnabled=false,V.drawImage(d,0,0);for(let F of y)Nt(V,F);let K=s.current?.clientWidth||d.width,j=d.width/Math.max(K,1);for(let F of k)xo(V,F,d.width,d.height,j);return await new Promise(F=>{T.toBlob(oe=>{F(oe??t);},"image/jpeg",.85);})}}),[h,L,d,t]);function re(f){let y=l.current;if(!y)return {x:0,y:0};let k=y.getBoundingClientRect(),T=y.width/Math.max(k.width,1),V=y.height/Math.max(k.height,1);return {x:(f.clientX-k.left)*T,y:(f.clientY-k.top)*V}}function _(){M.current||(M.current=true,requestAnimationFrame(()=>{M.current=false;let f=l.current;f&&dt(f,h,g.current);}));}function Ce(f){if(f.button!==void 0&&f.button!==0)return;if(n==="comment"){let k=l.current;if(!k)return;let T=k.getBoundingClientRect(),V=Cn((f.clientX-T.left)/Math.max(T.width,1),.72),K=Cn((f.clientY-T.top)/Math.max(T.height,1),.8),j=++C.current;b(F=>[...F,{id:j,x:V,y:K,text:"",color:r}]),I.current.push("comment"),A.current=j;return}try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}S.current=true,a?.(true);let y=re(f);n==="arrow"?g.current={kind:"arrow",from:y,to:y,color:r,width:o}:n==="rect"?g.current={kind:"rect",from:y,to:y,color:r,width:o}:g.current={kind:"freehand",points:[y],color:r,width:o},x.current=performance.now(),_();}function he(f){if(!S.current||!g.current)return;let y=re(f),k=g.current;if(k.kind==="arrow"||k.kind==="rect")k.to=y;else {let T=k.points[k.points.length-1],V=T?(T.x-y.x)**2+(T.y-y.y)**2:1/0,K=performance.now(),j=K-x.current;(V>16||j>16)&&(k.points.push(y),x.current=K);}_();}function H(){if(!S.current)return;S.current=false,a?.(false);let f=g.current;if(g.current=null,!!f){if(f.kind==="arrow"||f.kind==="rect"){let y=f.to.x-f.from.x,k=f.to.y-f.from.y;if(y*y+k*k<16){let T=l.current;T&&dt(T,h,null);return}}else if(f.points.length<2){let y=l.current;y&&dt(y,h,null);return}w(y=>[...y,f].slice(-50)),I.current.push("anno");}}return jsxs("div",{ref:u,className:"lumen-annotate-frame","data-lumen-tool":n,children:[jsx("canvas",{ref:s}),jsx("canvas",{ref:l,className:"lumen-annotate-overlay",onPointerDown:Ce,onPointerMove:he,onPointerUp:H,onPointerCancel:H}),jsx("div",{className:"lumen-bubble-layer",children:L.map(f=>jsx(Ro,{comment:f,onChange:q,onRemove:D},f.id))})]})});function Ro({comment:e,onChange:t,onRemove:n}){let r=useRef(null);return useEffect(()=>{let o=r.current;o&&o.textContent!==e.text&&(o.textContent=e.text);},[]),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:[jsx("span",{className:"lumen-bubble-label",children:"Comment"}),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??"")}),jsx("button",{type:"button",className:"lumen-bubble-del","aria-label":"Remove comment",onPointerDown:o=>o.stopPropagation(),onClick:()=>n(e.id),children:"\xD7"})]})}function dt(e,t,n){let r=e.getContext("2d");if(r){r.clearRect(0,0,e.width,e.height);for(let o of t)Nt(r,o);n&&Nt(r,n);}}function Nt(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")So(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 So(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],s=(a.x+i.x)/2,l=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,s,l);}let r=t[t.length-1];e.lineTo(r.x,r.y),e.stroke();}function xo(e,t,n,r,o){let a=t.text.trim();if(!a)return;let i=10*o,s=14*o,l=10*o,u=12*o,d=s*1.35,p=l*1.7,h=t.x*n,w=t.y*r,g=Math.min(n*.6,n-h-8*o);e.save(),e.font=`500 ${s}px ${At}`,e.textBaseline="top";let S=ko(e,a,g-i*2),x=S.reduce((A,q)=>Math.max(A,e.measureText(q).width),0),M=Math.min(g,Math.max(x,56*o)+i*2),L=i*2+p+S.length*d;Mo(e,h,w,M,L,u),e.fillStyle="#ffffff",e.fill(),e.lineWidth=Math.max(1,o),e.strokeStyle="rgba(0,0,0,0.10)",e.stroke();let b=h+18*o,C=w+L;e.beginPath(),e.moveTo(b,C-o),e.lineTo(b+13*o,C-o),e.lineTo(b+4*o,C+9*o),e.closePath(),e.fillStyle="#ffffff",e.fill(),e.fillStyle=t.color||"rgb(239, 68, 68)",e.font=`700 ${l}px ${At}`,e.fillText("COMMENT",h+i,w+i),e.fillStyle="#111318",e.font=`500 ${s}px ${At}`;let I=w+i+p;for(let A of S)e.fillText(A,h+i,I),I+=d;e.restore();}function ko(e,t,n){let r=t.split(/\s+/).filter(Boolean),o=[],a="";for(let i of r){let s=a?`${a} ${i}`:i;a&&e.measureText(s).width>n?(o.push(a),a=i):a=s;}return a&&o.push(a),o.length?o:[t]}function Mo(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let s=e;if(typeof s.roundRect=="function"){s.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 Qe({children:e,...t}){return 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 Lo(e){return jsxs(Qe,{...e,children:[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"}),jsx("circle",{cx:"12",cy:"13",r:"3.2"})]})}function To(e){return jsxs(Qe,{...e,children:[jsx("rect",{x:"3",y:"6",width:"13",height:"12",rx:"2.5"}),jsx("path",{d:"m16 10 5-3v10l-5-3"})]})}function Po(e){return jsxs(Qe,{...e,children:[jsx("path",{d:"M12 16V4m0 0 4 4m-4-4-4 4"}),jsx("path",{d:"M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})]})}function mt(e){return jsxs(Qe,{...e,children:[jsx("rect",{x:"3",y:"4",width:"18",height:"13",rx:"2"}),jsx("path",{d:"M8 21h8M12 17v4"})]})}function kn(e){return jsxs(Qe,{...e,children:[jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}var It={shot:Lo,video:To,upload:Po};function Mn(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 Ao(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 No=4e3;async function Dt(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((l,u)=>{if(n.readyState>=2)return l();n.addEventListener("loadeddata",()=>l(),{once:true}),n.addEventListener("error",()=>u(new Error("video decode failed")),{once:true});}),await Ao(n,Math.min(.1,(n.duration||0)/2));let i=await Mn(n),s=Number.isFinite(n.duration)?n.duration*1e3:0;return {poster:i,durationMs:s}},o,a=new Promise(i=>{o=window.setTimeout(()=>i({poster:null,durationMs:0}),No);});try{return await Promise.race([r().catch(()=>({poster:null,durationMs:0})),a])}finally{window.clearTimeout(o),n.removeAttribute("src"),URL.revokeObjectURL(t);}}async function Ot(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 Mn(t)}catch{return null}finally{t.srcObject=null;}}async function Bt(){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 _t=60,Io=25*1024*1024,Ln=[{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}],Pn=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],An=[{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 Ht(){let{client:e,isOpen:t,closeCapture:n,user:r,capture:o,initialCapture:a,initialCaptureError:i,startVideoSession:s,consumePendingVideo:l,canRecordScreen:u,consumeRecordStartError:d,startScreenCaptureSession:p,consumePendingScreenshot:h,isolateEvents:w,keyboardInset:g}=Ge(),[S,x]=useState(1),[M,L]=useState(null),[b,C]=useState({kind:"idle"}),[I,A]=useState(false),[q,D]=useState(0),[re,_]=useState(null),[Ce,he]=useState(false),[H,f]=useState("arrow"),[y,k]=useState(Ln[0].value),[T,V]=useState(Tn[1].value),[K,j]=useState(""),[F,oe]=useState("bug"),[Re,nt]=useState(r?.email??""),[W,Ie]=useState(null),[X,J]=useState(null),[de,Se]=useState(0),[ae,Q]=useState(null),[me,Y]=useState(null),[ee,Fe]=useState(false),pe=useRef(null),xe=useRef(null),Ue=useRef(null),ze=useRef(null),be=Xe(t,g),ie=useRef(false),De=useRef(false);useEffect(()=>{t||(De.current=false);},[t]),useEffect(()=>{if(!t)return;if(De.current){ie.current=false;return}De.current=true,ie.current=false,x(1),L(null),j(""),J(null),Se(0),Q(null),A(false),D(0),_(null),he(false),Y(null);let c=h();if(c){L("shot"),Oe(c),C({kind:"ready",capture:c});return}let v=l();if(v)L("video"),Q({blob:v.blob,durationMs:v.durationMs}),v.blob.size>Io&&toast.warning("This recording is large and may be too big to upload. Try a shorter clip if the upload fails."),v.poster?C({kind:"ready",capture:qe(v.poster,["Screen recording; preview is the first frame."])}):(C({kind:"capturing"}),(async()=>{let P=null;if(v.deriveBlobPoster)try{P=(await Dt(v.blob)).poster;}catch{P=null;}P=P??await Bt(),!ie.current&&C(P?{kind:"ready",capture:qe(P,["Screen recording; preview is the first frame."])}:{kind:"manual"});})());else {let P=d();P?(L("video"),Y(P),C({kind:"idle"})):a?(L("shot"),C({kind:"ready",capture:a})):o?.mode==="manual"?C({kind:"manual"}):o?.provider&&!i?(L("shot"),ve(o.mode??"auto")):C({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."});}return ()=>{ie.current=true;}},[t,o,a,i]),useEffect(()=>{if(!t)return;ze.current=document.activeElement??null;let c=document.documentElement,v=c.style.overflow,P=c.style.paddingRight,Z=window.innerWidth-c.clientWidth;c.style.overflow="hidden",Z>0&&(c.style.paddingRight=`${Z}px`);let te=false,Me=()=>{if(!te){te=true,c.style.overflow=v,c.style.paddingRight=P;try{ze.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",Me),()=>{window.removeEventListener("pagehide",Me),Me();}},[t]),useEffect(()=>{if(!t)return;function c(v){if(v.key==="Escape"){v.preventDefault(),n();return}if(v.key!=="Tab")return;let P=xe.current;if(!P)return;let Z=Ko(P);if(Z.length===0)return;let te=Z[0],Me=Z[Z.length-1],yt=document.activeElement;v.shiftKey&&(yt===te||!P.contains(yt))?(v.preventDefault(),Me.focus()):!v.shiftKey&&yt===Me&&(v.preventDefault(),te.focus());}return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,n]),useEffect(()=>{if(!t||!w)return;let c=Ue.current;if(!c)return;let v=P=>{P.target===c&&P.stopPropagation();};return c.addEventListener("pointerdown",v),c.addEventListener("click",v),c.addEventListener("touchstart",v,{passive:true}),()=>{c.removeEventListener("pointerdown",v),c.removeEventListener("click",v),c.removeEventListener("touchstart",v);}},[t,w]),useEffect(()=>{if(!t||!be.open)return;let c=xe.current,v=document.activeElement;if(c&&v&&c.contains(v))try{v.scrollIntoView({block:"center"});}catch{}},[t,be.open,be.inset]),useEffect(()=>{if(!t||b.kind!=="manual")return;function c(v){let te=Array.from(v.clipboardData?.items??[]).find(Me=>Me.type.startsWith("image/"))?.getAsFile();te&&(v.preventDefault(),G(te));}return window.addEventListener("paste",c),()=>window.removeEventListener("paste",c)},[t,b.kind]),useEffect(()=>{if(!W)return;let c=Date.now(),v=window.setInterval(()=>{let P=Math.floor((Date.now()-c)/1e3);Se(P),P>=_t&&ye();},250);return ()=>window.clearInterval(v)},[W]);let ke=useRef(null);if(ke.current=W,useEffect(()=>{t||ke.current&&(ke.current.cancel(),ke.current=null,Ie(null),Se(0));},[t]),useEffect(()=>()=>{ke.current?.cancel();},[]),!t)return null;async function ve(c){ie.current=false,C({kind:"capturing"});try{let v=await lt({...o,mode:c,target:o?.target??document.documentElement});return ie.current?!1:(Oe(v),C({kind:"ready",capture:v}),!0)}catch(v){return ie.current||C({kind:"manual",error:v instanceof Error?v.message:"Automatic screenshot capture was unavailable."}),false}}async function fe(c){L(c),Y(null),_(null),c!=="video"&&Be(),c==="shot"?await ve(o?.mode??"auto"):c==="video"?(Q(null),C({kind:"idle"})):C({kind:"manual"});}async function G(c){if(c.type.startsWith("image/")){Be();let v=qe(c,["Manual image upload used."]);C({kind:"ready",capture:v});return}if(c.type.startsWith("video/")){C({kind:"capturing"});try{let{poster:v,durationMs:P}=await Dt(c),Z=v??await Bt();if(!Z){C({kind:"manual",error:"Could not read that video."});return}let te=qe(Z,["Uploaded video; preview is the first frame."]);Q({blob:c,durationMs:P}),C({kind:"ready",capture:te});}catch{C({kind:"manual",error:"Could not read that video."});}return}toast.error("Choose an image (PNG, JPEG, WebP) or a video (MP4, WebM).");}function Oe(c){c.warnings.length!==0&&toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function we(){try{let c=await hn(_t);Ie(c);}catch(c){toast.error(c instanceof Error?c.message:"Microphone unavailable");}}async function ye(){if(W)try{let c=await W.stop();J({blob:c.blob,durationMs:c.durationMs});}catch(c){toast.error(c instanceof Error?c.message:"Could not stop recording");}finally{Ie(null);}}function Ke(){W?.cancel(),Ie(null),J(null),Se(0);}function We(c){let v=jsxs("div",{className:"lumen-audio-row",children:[!W&&!X?jsxs("button",{type:"button",onClick:we,className:c==="capture"?"lumen-voice-capture-btn":"lumen-btn-ghost",children:[jsx(kn,{}),"Record voice note"]}):null,W?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-recording",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsx(Ho,{stream:W.stream}),jsxs("span",{className:"lumen-rec-time",children:[de,"s / ",_t,"s"]})]}),jsx("button",{type:"button",onClick:ye,className:"lumen-btn-ghost",children:"Stop"}),jsx("button",{type:"button",onClick:Ke,className:"lumen-btn-ghost",children:"Cancel"})]}):null,X&&!W?jsxs(Fragment,{children:[jsx(Fo,{blob:X.blob,durationMs:X.durationMs}),jsx("button",{type:"button",onClick:()=>J(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]});return c==="capture"?jsxs("div",{className:"lumen-voice-capture",children:[v,!W&&!X?jsx("p",{className:"lumen-voice-capture-hint",children:"Say what went wrong while it\u2019s fresh."}):null]}):jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Add a voice note (optional)"}),v]})}async function rt(){Y(null);try{await s();}catch(c){toast.error(c instanceof Error?c.message:"Screen capture unavailable");}}function Be(){Q(null);}let ot=b.kind==="ready";async function _e(){if(W&&await ye(),S===1){if(b.kind==="ready"){let c=await pe.current?.flatten();_(c??b.capture.blob),he(c!=null&&c!==b.capture.blob);}x(2);}else S===2?x(3):await vt();}function bt(){S>1&&x(c=>c-1);}async function vt(){if(b.kind!=="ready")return;let c=K.trim(),{capture:v}=b;A(true),D(0);try{let P=re??v.blob,Z=await e.submit({rawText:c.length>0?c:void 0,category:F,submitterEmail:Re.trim()||void 0,screenshot:P,audio:X?.blob,audioDurationMs:X?.durationMs,video:ae?.blob,videoDurationMs:ae?.durationMs,context:gn(v)},{onUploadProgress:te=>D(Math.min(.95,te))});D(1),toast.success("Feedback sent \u2014 thank you."),Z.id,n();}catch(P){toast.error(P instanceof Error?P.message:"Could not submit feedback"),A(false);}}function ge(c){c.target===c.currentTarget&&!I&&n();}let R=Math.round(q*100),O=M==="video",U=typeof navigator<"u"&&!!navigator.mediaDevices?.getDisplayMedia,wt=M==="shot"&&!o?.provider&&o?.allowTrueScreen!==false&&U,gr=S===1&&!ot||I,hr=S<3?"Next":I?R<95?`Uploading ${R}%\u2026`:"Almost done\u2026":"Send feedback";return jsx("div",{ref:Ue,role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",style:be.inset?{"--lumen-keyboard-inset":`${be.inset}px`}:void 0,onMouseDown:ge,children:jsxs("div",{ref:xe,className:"lumen-modal","data-lumen-drawing":ee?"true":void 0,children:[jsx(_o,{onDismiss:n}),jsxs("header",{className:"lumen-modal-header",children:[jsxs("h2",{className:"lumen-modal-title",children:[jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsx(Do,{step:S}),jsxs("div",{className:"lumen-modal-body",children:[S===1?jsx("div",{className:"lumen-pane",children:M===null?jsxs(Fragment,{children:[jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:An.map(c=>{let v=It[c.value];return jsxs("button",{type:"button",className:"lumen-method-btn"+(c.primary?" lumen-method-primary":""),onClick:()=>fe(c.value),disabled:b.kind==="capturing",children:[jsx("span",{className:"lumen-method-ico",children:jsx(v,{})}),c.primary?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-method-text",children:[jsx("span",{className:"lumen-method-label",children:c.label}),jsx("span",{className:"lumen-method-hint",children:c.hint})]}),jsx("span",{className:"lumen-method-badge",children:"Fastest"})]}):jsxs(Fragment,{children:[jsx("span",{className:"lumen-method-label",children:c.label}),jsx("span",{className:"lumen-method-hint",children:c.hint})]})]},c.value)})}),jsx("p",{className:"lumen-status lumen-method-help",children:"Choose how to capture your feedback."})]}):jsxs(Fragment,{children:[jsx("div",{className:"lumen-method-switch",role:"group","aria-label":"Switch capture method",children:An.map(c=>{let v=It[c.value];return jsxs("button",{type:"button","aria-pressed":M===c.value,onClick:()=>fe(c.value),disabled:b.kind==="capturing",children:[jsx(v,{}),c.label]},c.value)})}),M==="video"&&b.kind==="idle"?jsx(Oo,{canRecord:u,onRecord:rt,onUpload:()=>fe("upload"),error:me}):null,b.kind==="capturing"?jsxs("p",{className:"lumen-status",children:[jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,b.kind==="manual"?jsxs("div",{className:"lumen-manual-capture",children:[jsx("p",{className:"lumen-status",children:M==="upload"?"Choose an image or video to attach \u2014 or paste an image.":b.error?"Automatic capture was unavailable. Upload or paste an image to continue.":"Upload or paste an image to continue."}),jsxs("label",{className:"lumen-manual-drop",children:[jsx("span",{children:M==="upload"?"Choose a file \u2014 image or video":"Choose or paste an image"}),jsx("input",{type:"file",accept:M==="upload"?"image/png,image/jpeg,image/webp,video/mp4,video/webm,video/quicktime":"image/png,image/jpeg,image/webp",onChange:c=>{let v=c.currentTarget.files?.[0];v&&G(v),c.currentTarget.value="";}})]})]}):null,b.kind==="ready"?jsxs(Fragment,{children:[O?null:jsxs("div",{className:"lumen-toolbar",children:[jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsx(pt,{label:"Arrow",active:H==="arrow",onClick:()=>f("arrow")}),jsx(pt,{label:"Box",active:H==="rect",onClick:()=>f("rect")}),jsx(pt,{label:"Draw",active:H==="freehand",onClick:()=>f("freehand")}),jsx(pt,{label:"Comment",active:H==="comment",onClick:()=>f("comment")})]}),jsx("span",{className:"lumen-toolbar-sep"}),jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:Ln.map(c=>jsx("button",{type:"button",className:"lumen-swatch",style:{background:c.value},"aria-label":c.label,"aria-pressed":y===c.value,onClick:()=>k(c.value)},c.value))}),jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:Tn.map(c=>jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":c.label,"aria-pressed":T===c.value,onClick:()=>V(c.value),children:jsx("span",{className:"lumen-stroke-size-dot",style:{width:c.dot,height:c.dot}})},c.value))}),jsx("span",{className:"lumen-toolbar-spacer"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>pe.current?.undo(),children:"Undo"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>pe.current?.reset(),children:"Clear"})]}),jsx("div",{className:"lumen-annotate",children:jsx(Sn,{ref:pe,screenshot:b.capture.blob,tool:H,color:y,strokeWidth:T,onDrawingChange:Fe})}),jsxs("div",{className:"lumen-cap-actions",children:[jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>M&&fe(M),children:O?"\u21BB Re-record":"\u21BB Recapture"}),wt?jsxs("button",{type:"button",className:"lumen-btn-ghost lumen-exact-btn",onClick:()=>{p();},title:"Capture the real screen pixels \u2014 your browser will ask which tab or window to share, then you arrange the page and press Capture.",children:[jsx(mt,{})," Capture exact screen"]}):null,O?ae?jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round(ae.durationMs/1e3),"s recorded"]}):null:jsx("span",{className:"lumen-cap-note",children:b.capture.method==="web-display-media"?"Exact screen captured":`${Nn(M)} captured \xB7 switch method above anytime`})]}),We("capture")]}):null]})}):null,S===2?jsxs("div",{className:"lumen-pane lumen-form",children:[jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"What happened?"}),jsx("textarea",{value:K,onChange:c=>j(c.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),We("describe"),jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Category"}),jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:Pn.map(c=>jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":F===c.value,onClick:()=>oe(c.value),children:c.label},c.value))})]}),jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"Your email (optional)"}),jsx("input",{type:"email",value:Re,onChange:c=>nt(c.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,S===3?jsxs("div",{className:"lumen-pane lumen-review",children:[jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxs("span",{className:"lumen-review-v",children:[Nn(M),Ce?" \xB7 annotated":"",jsx("button",{type:"button",className:"lumen-edit",onClick:()=>x(1),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Category"}),jsxs("span",{className:"lumen-review-v",children:[jsx("span",{className:"lumen-chip",children:Pn.find(c=>c.value===F)?.label}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>x(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Description"}),jsxs("span",{className:"lumen-review-v",children:[K.trim()?K.trim():jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>x(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Material"}),jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[X?jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(X.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>J(null),children:"\xD7"})]}):null,ae?jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round(ae.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Be,children:"\xD7"})]}):null,Re.trim()?jsxs("span",{className:"lumen-attach",children:["\u2709 ",Re.trim()]}):null,!X&&!W?jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{x(2),we();},children:"+ Voice note"}):null]})]})]}):null]}),jsxs("footer",{className:"lumen-modal-footer",children:[I?jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":R,children:jsx("div",{className:"lumen-progress-fill",style:{width:`${R}%`}})}):null,jsxs("div",{className:"lumen-modal-actions",children:[jsx("button",{type:"button",onClick:S===1?n:bt,className:"lumen-btn-ghost",disabled:I,children:S===1?"Cancel":"Back"}),jsx("button",{type:"button",onClick:_e,className:"lumen-btn-primary",disabled:gr,children:hr})]})]})]})})}function Nn(e){return e==="video"?"Screen recording":e==="upload"?"Upload":"Screenshot"}function Do({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,r)=>jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsx("span",{className:"lumen-step-num",children:n.n}),jsx("span",{className:"lumen-step-lbl",children:n.label}),r<t.length-1?jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function Oo({canRecord:e,onRecord:t,onUpload:n,error:r}){return e?jsxs("div",{className:"lumen-record-prompt",children:[r?jsxs("p",{className:"lumen-record-unavailable",role:"alert",children:[r," Try again, or switch to ",jsx("strong",{children:"Upload"})," to attach a video instead."]}):null,jsx("button",{type:"button",className:"lumen-record-btn","aria-label":"Start screen recording",onClick:t}),jsxs("div",{className:"lumen-record-copy",children:[jsx("div",{className:"lumen-record-title",children:"Record your screen"}),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."})]})]}):jsxs("div",{className:"lumen-record-prompt",children:[jsx("p",{className:"lumen-record-unavailable",children:Bo()?jsx(Fragment,{children:"Screen recording isn\u2019t available on iOS browsers. Record with Control Center\u2019s screen recorder, then attach the clip below."}):jsx(Fragment,{children:"Screen recording isn\u2019t available in this browser. Upload a video to attach one instead."})}),jsx("button",{type:"button",className:"lumen-btn-primary lumen-record-upload",onClick:n,children:"Upload a video"})]})}function Bo(){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 pt({label:e,active:t,onClick:n}){return jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function _o({onDismiss:e}){let t=useRef(null),n=useRef(0),r=useRef(null);function o(s){s.currentTarget.setPointerCapture(s.pointerId),t.current=s.clientY,n.current=performance.now(),r.current=s.currentTarget.parentElement;}function a(s){if(t.current==null||!r.current)return;let l=Math.max(0,s.clientY-t.current);r.current.style.transform=`translateY(${l}px)`;}function i(s){if(t.current==null||!r.current)return;let l=Math.max(0,s.clientY-t.current),u=Math.max(1,performance.now()-n.current),d=l/u;r.current.style.transform="",r.current.style.transition="",t.current=null,(l>80||d>.6)&&e();}return jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:o,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function Ho({stream:e}){let t=useRef(null);return 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 s=window.AudioContext??window.webkitAudioContext;if(!s)return;let l=new s,u=l.createMediaStreamSource(e),d=l.createAnalyser();d.fftSize=1024,d.smoothingTimeConstant=.6,u.connect(d);let p=new Uint8Array(d.fftSize),h=18,w=3,g=3,S=Math.max(2,(o-w*(h-1))/h),x=Math.min(S/2,3),M=new Array(h).fill(0),L=0,b=false;function C(){if(b)return;d.getByteTimeDomainData(p);let I=Math.floor(p.length/h);i.clearRect(0,0,o,a),i.fillStyle=Uo("--lumen-danger")||"rgb(239,68,68)";for(let A=0;A<h;A++){let q=0;for(let H=0;H<I;H++){let f=Math.abs((p[A*I+H]??128)-128);f>q&&(q=f);}let D=Math.min(1,q/128*1.8),re=M[A]??0;M[A]=D>re?D:re+(D-re)*.35;let _=Math.max(g,M[A]*a),Ce=A*(S+w),he=(a-_)/2;Vo(i,Ce,he,S,_,x),i.fill();}L=requestAnimationFrame(C);}return L=requestAnimationFrame(C),()=>{b=true,cancelAnimationFrame(L);try{u.disconnect();}catch{}l.close();}},[e]),jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function Vo(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let s=e;if(typeof s.roundRect=="function"){s.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 Fo({blob:e,durationMs:t}){let[n,r]=useState("");return useEffect(()=>{let o=URL.createObjectURL(e);return r(o),()=>{URL.revokeObjectURL(o);}},[e]),jsxs("div",{className:"lumen-audio-preview",children:[jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function Uo(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var zo='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Ko(e){return Array.from(e.querySelectorAll(zo)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}var ft=class extends Rn.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),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 _n({state:e,portalTarget:t,onStop:n,onCancel:r}){let[o,a]=useState(false);if(useEffect(()=>a(true),[]),!o||typeof document>"u")return null;let i=t??document.body;return e.phase==="recording"?createPortal(jsx($o,{startedAt:e.startedAt,maxSeconds:e.maxSeconds,onStop:n,onCancel:r}),i):createPortal(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:[jsx("span",{className:"lumen-rec-hud-spinner","aria-hidden":"true"}),jsx("span",{className:"lumen-rec-hud-time",children:e.phase==="starting"?"Starting\u2026":"Processing\u2026"}),jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"})]}),i)}function $o({startedAt:e,maxSeconds:t,onStop:n,onCancel:r}){let[o,a]=useState(0);useEffect(()=>{let s=()=>a(Math.min(t,Math.max(0,Math.floor((Date.now()-e)/1e3))));s();let l=window.setInterval(s,250);return ()=>window.clearInterval(l)},[e,t]);let i=s=>`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`;return jsxs("div",{className:"lumen-rec-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsx("span",{className:"lumen-rec-hud-dot","aria-hidden":"true"}),jsxs("span",{className:"lumen-rec-hud-time",children:[i(o)," ",jsxs("span",{className:"lumen-rec-hud-max",children:["/ ",i(t)]})]}),jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"}),jsxs("button",{type:"button",className:"lumen-rec-hud-stop",onClick:n,"aria-label":"Stop recording and return to feedback",children:[jsx("span",{className:"lumen-rec-hud-square","aria-hidden":"true"}),"Stop"]})]})}function Hn({state:e,portalTarget:t,onCapture:n,onCancel:r}){let[o,a]=useState(false);if(useEffect(()=>a(true),[]),!o||typeof document>"u")return null;let i=t??document.body,s=e.phase==="grabbing";return createPortal(jsxs("div",{className:"lumen-cap-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[s?jsx("span",{className:"lumen-cap-hud-spinner","aria-hidden":"true"}):jsx("span",{className:"lumen-cap-hud-ico","aria-hidden":"true",children:jsx(mt,{})}),jsx("span",{className:"lumen-cap-hud-text",children:s?"Capturing\u2026":"Arrange the screen, then capture"}),jsx("button",{type:"button",className:"lumen-cap-hud-cancel",onClick:r,disabled:s,children:"Cancel"}),jsx("button",{type:"button",className:"lumen-cap-hud-capture",onClick:n,disabled:s,"aria-label":"Capture this screen and return to feedback",children:"Capture"})]}),i)}function Vt(e){let t=e.hasProvider&&e.providerAvailable!==false;return {canRecord:t||e.hasGetDisplayMedia,usingProvider:t}}function Vn(e){return typeof e=="object"&&e!==null&&e.code==="RECORDER_STOPPED"}function Fn(e){return e instanceof Error?e:new Error(String(e))}function Un(e,t,n){let r=false,o=false,a=false,i=null;function s(){o||(o=true,n.onCancelled());}function l(d){o||(o=true,n.onResult(d));}function u(d){o||(o=true,n.onError(d));}return n.onStarting(),Promise.resolve().then(()=>e(t)).then(d=>{if(i=d,r){try{d.cancel();}catch{}s();return}if(n.onActive(d),a){n.onProcessing();try{d.stop();}catch{}}Promise.resolve(d.result).then(p=>{r?s():l(p);}).catch(p=>{r||Vn(p)?s():u(Fn(p));});}).catch(d=>{r||Vn(d)?s():u(Fn(d));}),{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{}s();}}}}function zn(){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 s=document.elementsFromPoint(i,n);for(let l of s){if(o.has(l))continue;o.add(l);let u=window.getComputedStyle(l);if(u.position!=="fixed"&&u.position!=="sticky")continue;let d=l.getBoundingClientRect();d.bottom<t-8||d.bottom>t+8||d.width<e*.6||d.height>a&&(a=d.height);}}return a}function Ft(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 s of Array.from(i)){let l=s.getBoundingClientRect();if(l.height===0||l.width===0)continue;let u=0;switch(t){case "bottom":if(l.bottom<r-8)break;u=Math.max(0,r-l.top);break;case "top":if(l.top>8)break;u=Math.max(0,l.bottom);break;case "left":if(l.left>8)break;u=Math.max(0,l.right);break;case "right":if(l.right<n-8)break;u=Math.max(0,n-l.left);break}u>o&&(o=u);}}return o}function Kn(e){let[t,n]=useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),r=useRef(t),o=Qo(e.avoid),a=e.placement,i=e.offset.x,s=e.offset.y;return useEffect(()=>{if(typeof window>"u")return;let l=0,u=false,d=()=>{if(l=0,u)return;let S=a[0]==="b"?"bottom":"top",x=a[1]==="r"?"right":"left",M=0,L=0;e.avoid==="auto"&&S==="bottom"?M=zn():Array.isArray(e.avoid)&&(M=Ft(e.avoid,S),L=Ft(e.avoid,x));let b={bottom:S==="bottom"?s+M:0,top:S==="top"?s+M:0,right:x==="right"?i+L:0,left:x==="left"?i+L:0},C=r.current;(b.bottom!==C.bottom||b.top!==C.top||b.right!==C.right||b.left!==C.left)&&(r.current=b,n(b));},p=()=>{l||(l=window.requestAnimationFrame(d));};p();let h=typeof ResizeObserver<"u"?new ResizeObserver(p):null;h?.observe(document.documentElement);let w=typeof MutationObserver<"u"?new MutationObserver(p):null;w?.observe(document.body,{childList:true,subtree:true,attributes:true,attributeFilter:["class","style","hidden"]}),window.addEventListener("resize",p);let g=window.visualViewport;return g?.addEventListener("resize",p),g?.addEventListener("scroll",p),()=>{u=true,l&&window.cancelAnimationFrame(l),h?.disconnect(),w?.disconnect(),window.removeEventListener("resize",p),g?.removeEventListener("resize",p),g?.removeEventListener("scroll",p);}},[a,i,s,o]),t}function Qo(e){return e===false?"false":e==="auto"?"auto":e.join("|")}var Wn=["mousedown","touchstart"];function Ve(e){let t=useRef(e.onPointerDown);t.current=e.onPointerDown;let n=useRef(e.onClick);n.current=e.onClick;let r=useRef(e.isolate??true);r.current=e.isolate??true;let o=useRef(null);return useCallback(a=>{if(o.current?.(),o.current=null,!a)return;let i=u=>{r.current&&u.stopPropagation(),t.current?.(u);},s=u=>{r.current&&u.stopPropagation(),n.current(u);},l=u=>{r.current&&u.stopPropagation();};a.addEventListener("pointerdown",i),a.addEventListener("click",s);for(let u of Wn)a.addEventListener(u,l,u==="touchstart"?{passive:true}:void 0);o.current=()=>{a.removeEventListener("pointerdown",i),a.removeEventListener("click",s);for(let u of Wn)a.removeEventListener(u,l);};},[])}function Yn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o,isolateEvents:a=true,keyboardInset:i}){let[s,l]=useState(null),u=useRef(null),d=Kn(e),p=Xe(e.keyboard!=="off",i),h=Ve({onPointerDown:r,onClick:o,isolate:a}),w=useCallback(D=>{u.current=D,h(D);},[h]);useEffect(()=>{typeof document>"u"||l(t??document.body);},[t]);let g=e.placement,S=g[0]==="b"?"bottom":"top",x=g[1]==="r"?"right":"left",M=S==="bottom",L=p.open&&M&&(e.keyboard==="lift"||e.keyboard==="auto"&&p.inset>0)?p.inset:0,b=p.open&&(e.keyboard==="hide"||e.keyboard==="auto"&&M&&p.inset<=0);if(oa(u,!n&&!b),!s)return null;let C=S==="bottom"?d.bottom:d.top,I=x==="right"?d.right:d.left,A=n||b,q={position:"fixed",[S]:e.safeArea?`calc(${C}px + env(safe-area-inset-${S}, 0px))`:`${C}px`,[x]:e.safeArea?`calc(${I}px + env(safe-area-inset-${x}, 0px))`:`${I}px`,zIndex:e.zIndex,transform:L?`translateY(-${L}px)`:void 0,opacity:A?0:1,pointerEvents:A?"none":"auto",transition:"opacity 160ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1)"};return createPortal(jsxs("button",{ref:w,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:q,"aria-label":e.label,"aria-hidden":A?true:void 0,tabIndex:A?-1:0,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsx("span",{children:e.label})]}),s)}function oa(e,t){let n=useRef(false);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,s=a.top+a.height/2,l=document.elementsFromPoint(i,s),u=$n(window.getComputedStyle(o).zIndex);for(let d of l){if(d===o||o.contains(d))continue;if($n(window.getComputedStyle(d).zIndex)>u){n.current=true,console.warn("[lumen] trigger is occluded by",d);break}}},250);return ()=>window.clearTimeout(r)},[t,e]);}function $n(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function Gn({mount:e,label:t,icon:n,onPointerDown:r,onClick:o,isolateEvents:a=true}){let[i,s]=useState(null),l=Ve({onPointerDown:r,onClick:o,isolate:a});return useEffect(()=>{if(typeof document>"u")return;let u=e instanceof HTMLElement?e:e.current??null;s(u);},[e]),i?createPortal(jsxs("button",{ref:l,type:"button",className:"lumen-btn lumen-btn-primary","aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsx("span",{children:t})]}),i):null}function Jn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o,isolateEvents:a=true}){let[i,s]=useState(null),[l,u]=useState(false),d=useRef(null),p=Ve({onPointerDown:x=>{r?.(x),d.current={x:x.clientX,y:x.clientY},u(true);let M=x.currentTarget;try{M?.setPointerCapture?.(x.pointerId);}catch{}},onClick:o,isolate:a});if(useEffect(()=>{typeof document>"u"||s(t??document.body);},[t]),!i)return null;let h=`lumen-notch lumen-notch-${e.edge}${l?" lumen-notch-expanded":""}`;function w(x){let M=d.current;if(!M)return;let L=x.clientX-M.x,b=x.clientY-M.y;(e.edge==="top"&&b>16||e.edge==="bottom"&&b<-16||e.edge==="right"&&L<-16||e.edge==="left"&&L>16)&&(d.current=null,o(x.nativeEvent));}function g(){d.current=null,u(false);}function S(){d.current=null,u(false);}return createPortal(jsxs("button",{ref:p,type:"button",className:h,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,onPointerMove:w,onPointerUp:g,onPointerCancel:S,onMouseEnter:()=>u(true),onMouseLeave:()=>u(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),i)}function Qn(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function ha(e){return e===false?"off":e===true?"hide":e==="auto"||e==="lift"||e==="hide"?e:"auto"}function er(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],keyboard:ha(e.hideOnKeyboard),zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var wa={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-radius":"radius"};function tr(e){let t=useId();useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,r=`data-lumen-theme-${ya(t)}`,o={},a=(i,s)=>{o[i]=n.style.getPropertyValue(i)||null,n.style.setProperty(i,s);};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,s]of Object.entries(wa)){let l=e[s];typeof l=="string"&&l.length>0&&a(i,l);}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,s]of Object.entries(o))i.startsWith("--")?s?n.style.setProperty(i,s):n.style.removeProperty(i):s==null?n.removeAttribute(i):n.setAttribute(i,s);}},[e,t]);}function ya(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var nr=Symbol.for("lumen.history.patched"),Ut="lumen:locationchange";function Ra(){if(typeof window>"u")return;let e=window;if(e[nr])return;e[nr]=true;let t=()=>window.dispatchEvent(new Event(Ut)),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 rr(e){let[t,n]=useState(false);return useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;Ra();let r=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return r(),window.addEventListener(Ut,r),window.addEventListener("popstate",r),()=>{window.removeEventListener(Ut,r),window.removeEventListener("popstate",r);}},[e]),t}var ka=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function or(){let[e,t]=useState(false);return 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||"";ka.some(a=>o.includes(a))&&t(true);},[]),e}var ir="lumen.config.v1.",Ta=3600*1e3;function sr(e,t){let[n,r]=useState(()=>({trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:true}));return useEffect(()=>{if(typeof window>"u")return;let o=Oa(e);o&&r({trigger:o.trigger,enabled:ar(o.trigger),shakeToOpen:o.shake,brand:o.brand,loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),s=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(s,{method:"GET",mode:"cors",credentials:"omit",signal:a.signal}).then(async l=>{if(!l.ok)throw new Error(`HTTP ${l.status}`);let u=await l.json(),d=lr(u.trigger);if(!d)throw new Error("Malformed config response");let p=Na(u.trigger),h=ur(u.brand);Ba(e,d,p,h),r({trigger:d,enabled:ar(d),shakeToOpen:p,brand:h,loading:false});}).catch(()=>{r(l=>l.loading?{trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:false}:l);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function ar(e){return e.kind!=="headless"}var Pa=["br","bl","tr","tl"],Aa=["top","right","bottom","left"];function lr(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:Pa.find(o=>o===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:Aa.find(o=>o===t.edge)??"top",label:n}:null}function Na(e){return !e||typeof e!="object"?false:e.shake===true}var Ia=/^#[0-9a-fA-F]{6}$/,Da=["auto","light","dark"];function ur(e){if(!e||typeof e!="object")return null;let t=e,n=typeof t.accent=="string"&&Ia.test(t.accent)?t.accent:null;if(!n)return null;let r=Da.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 Oa(e){try{let t=window.localStorage.getItem(ir+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>Ta)return null;let r=lr(n.trigger);return r?{fetchedAt:n.fetchedAt,trigger:r,shake:n.shake===!0,brand:ur(n.brand)}:null}catch{return null}}function Ba(e,t,n,r){try{window.localStorage.setItem(ir+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n,brand:r}));}catch{}}function Ha(e){if(e&&typeof e=="object")return e.type===ct;if(typeof e=="string")try{return JSON.parse(e).type===ct}catch{return false}return false}function Va(e={}){let t=e.threshold??18,n=e.neededHits??3,r=e.windowMs??700,o=e.throttleMs??60,a=null,i=[];return {push(s,l,u,d){if(!a)return a={x:s,y:l,z:u,t:d},false;if(d-a.t<o)return false;let p=Math.abs(s-a.x)+Math.abs(l-a.y)+Math.abs(u-a.z);return a={x:s,y:l,z:u,t:d},p<t?false:(i=i.filter(h=>d-h<r),i.push(d),i.length>=n?(i=[],true):false)}}}function cr(e,t,n){useEffect(()=>{if(!e||typeof window>"u")return;let r=0,o=1500;function a(){let d=Date.now();n||d-r<o||(r=d,t());}let i=d=>{Ha(d.data)&&a();};window.addEventListener("message",i),document.addEventListener("message",i);let s=Va(),l=d=>{let p=d.accelerationIncludingGravity??d.acceleration;!p||p.x==null||p.y==null||p.z==null||s.push(p.x,p.y,p.z,Date.now())&&a();},u=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return u&&window.addEventListener("devicemotion",l),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),u&&window.removeEventListener("devicemotion",l);}},[e,t,n]);}var mr="https://shakebugs.vercel.app",ht=60;function pr(){return typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function"}function za({apiKey:e,apiUrl:t,user:n,amplitude:r,floatingButton:o=true,trigger:a,hideOn:i,theme:s,portalTarget:l,capture:u,record:d,shakeToOpen:p,onOpenChange:h,beforeOpen:w,onTriggerActivate:g,isolateEvents:S=true,keyboardInset:x,suppressTrigger:M=false,children:L}){let[b,C]=useState(false),[I,A]=useState(false),[q,D]=useState(null),[re,_]=useState(null),[Ce]=useState(false),[he]=useState(null),H=useRef(false),f=useRef(false),y=useRef(null),k=useMemo(()=>new en({apiKey:e,apiUrl:t,user:n,amplitude:r}),[e,t,n?.id,n?.email,n?.name,r?.userId,r?.deviceId,r?.sessionId]);useEffect(()=>{pn({ignoreUrlPrefix:(t??mr).replace(/\/$/,"")});},[t]);let T=useRef(h);T.current=h,useEffect(()=>{if(!(typeof document>"u"))return b?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[b]);let V=useRef(null);useEffect(()=>{if(V.current===b)return;let R=V.current;V.current=b,R!==null&&T.current?.(b);},[b]);let K=useRef(w);K.current=w;let j=useRef(g);j.current=g;let F=useCallback(R=>{f.current=true,y.current=Promise.resolve().then(()=>K.current?.(R)).then(()=>j.current?.(R)).then(()=>{});},[]),oe=useCallback(R=>{H.current||b||Y.current||we.current||(H.current=true,A(true),D(null),_(null),(async()=>{try{if(f.current?await y.current:(await K.current?.(R),await j.current?.(R)),u?.mode==="manual")D(null),_(null);else if(u?.provider)D(null),_(null);else {let O=await lt({...u,mode:u?.mode??"auto",target:u?.target??document.documentElement});D(O);}}catch(O){_(O instanceof Error?O:new Error(String(O)));}finally{f.current=false,y.current=null,H.current=false,A(false),C(true);}})());},[u,b]),Re=useCallback(()=>{C(false),D(null),_(null);},[]),nt=useCallback(k.submit.bind(k),[k]),[W,Ie]=useState(0),X=useCallback(()=>{H.current=false,A(false),C(false),D(null),_(null),Ie(R=>R+1);},[]),[J,de]=useState(null),[Se,ae]=useState(null),Q=useRef(null),me=useRef(null),Y=useRef(false),ee=useRef(null),Fe=useRef(null),pe=useRef(null),xe=useCallback((R,O=false)=>{if(Q.current=null,me.current=null,Y.current=false,de(null),!R){ee.current=null;return}Fe.current={blob:R.blob,durationMs:R.durationMs,poster:ee.current,deriveBlobPoster:O},ee.current=null,C(true);},[]);useEffect(()=>{if(!b)return;if(!d?.provider){ae(null);return}let R=d.isAvailable;if(!R){ae(true);return}let O=false;return Promise.resolve().then(()=>R()).then(U=>{O||ae(U);}).catch(()=>{O||ae(false);}),()=>{O=true;}},[b,d?.provider,d?.isAvailable]);let Ue=Vt({hasProvider:!!d?.provider,providerAvailable:Se,hasGetDisplayMedia:pr()}).canRecord,ze=useCallback(async()=>{if(Y.current)return;if(pe.current=null,Vt({hasProvider:!!d?.provider,providerAvailable:Se,hasGetDisplayMedia:pr()}).usingProvider&&d?.provider){Y.current=true,ee.current=null,C(false),me.current=Un(d.provider,{maxDurationSeconds:ht},{onStarting:()=>de({phase:"starting"}),onActive:U=>{de({phase:"recording",stream:U.stream??null,startedAt:Date.now(),maxSeconds:ht}),U.stream&&Ot(U.stream).then(wt=>{ee.current=wt;}).catch(()=>{});},onProcessing:()=>de({phase:"processing"}),onResult:U=>xe({blob:U.blob,durationMs:U.durationMs},true),onCancelled:()=>{me.current=null,Y.current=false,ee.current=null,de(null),D(null),_(null),C(true);},onError:U=>{me.current=null,Y.current=false,ee.current=null,de(null),pe.current=U.message||"Screen recording could not start.",C(true);}});return}if(Q.current)return;let O=await bn(ht);Q.current=O,Y.current=true,ee.current=null,de({phase:"recording",stream:O.stream,startedAt:Date.now(),maxSeconds:ht}),C(false),Ot(O.stream).then(U=>{ee.current=U;}).catch(()=>{}),O.result.then(U=>xe(U)).catch(()=>xe(null));},[xe,d?.provider,Se]),be=useCallback(()=>{me.current?me.current.stop():Q.current?.stop();},[]),ie=useCallback(()=>{if(me.current){me.current.cancel();return}let R=Q.current;Q.current=null,Y.current=false,ee.current=null,de(null),R?.cancel(),D(null),_(null),C(true);},[]),De=useCallback(()=>{let R=Fe.current;return Fe.current=null,R},[]),ke=useCallback(()=>{let R=pe.current;return pe.current=null,R},[]);useEffect(()=>{b||(pe.current=null);},[b]);let[ve,fe]=useState(null),G=useRef(null),Oe=useRef(null),we=useRef(false),ye=useCallback(()=>{let R=G.current;G.current=null,we.current=false,R?.stop(),fe(null),C(true);},[]),Ke=useCallback(()=>{let R=G.current;R&&(fe({phase:"grabbing"}),(async()=>{try{let O=await R.grab();if(G.current!==R)return;Oe.current=O,G.current=null,we.current=!1,R.stop(),fe(null),C(!0);}catch{if(G.current!==R)return;G.current=null,we.current=false,R.stop(),fe(null),toast.error("Could not capture the screen. Please try again."),C(true);}})());},[]),We=useCallback(async()=>{if(we.current)return;let R;try{R=await xt({...u});}catch{return}G.current=R,we.current=true,R.onEnded(()=>ye()),fe({phase:"live"}),C(false);},[u,ye]),rt=useCallback(()=>{let R=Oe.current;return Oe.current=null,R},[]);useEffect(()=>()=>{G.current?.stop(),G.current=null;},[]);let Be=or(),ot=rr(i),_e=sr(a?"":e,t??mr);tr(s??$a(_e.brand));let bt=p??_e.shakeToOpen;cr(bt,oe,b);let vt=useMemo(()=>({client:k,user:n,isOpen:b,isSubmitting:Ce,error:he,open:oe,close:Re,openCapture:oe,closeCapture:Re,submit:nt,isNativeShell:Be,capture:u,initialCapture:q,initialCaptureError:re,isOpening:I,startVideoSession:ze,stopVideoSession:be,cancelVideoSession:ie,recording:J,consumePendingVideo:De,canRecordScreen:Ue,consumeRecordStartError:ke,startScreenCaptureSession:We,grabScreenCaptureFrame:Ke,cancelScreenCaptureSession:ye,screenCapture:ve,consumePendingScreenshot:rt,isolateEvents:S,keyboardInset:x}),[k,n,b,Ce,he,oe,Re,nt,Be,u,q,re,ze,be,ie,J,De,Ue,ke,We,Ke,ye,ve,rt,I,S,x]),ge=Wa({explicit:a,remote:_e.trigger,remoteLoading:_e.loading,floatingButton:o});return jsxs(Tt.Provider,{value:vt,children:[L,jsxs(ft,{onReset:X,children:[ge?.kind==="floating"?jsx(Yn,{config:er(ge),portalTarget:l,hidden:ot||M||I||J!=null||ve!=null,onPointerDown:F,onClick:R=>oe(R),isolateEvents:S,keyboardInset:x}):null,ge?.kind==="notch"?jsx(Jn,{config:Qn(ge),portalTarget:l,hidden:ot||M||I||J!=null||ve!=null,onPointerDown:F,onClick:R=>oe(R),isolateEvents:S}):null,ge?.kind==="inline"?jsx(Gn,{mount:ge.mount,label:ge.label??"Feedback",icon:ge.icon,onPointerDown:F,onClick:R=>oe(R),isolateEvents:S}):null,ve?jsx(Hn,{state:ve,portalTarget:l,onCapture:Ke,onCancel:ye}):null,J?jsx(_n,{state:J,portalTarget:l,onStop:be,onCancel:ie}):null,jsx(Ht,{})]},W),jsx(Ka,{})]})}function Ka(){let[e,t]=useState(false);return useEffect(()=>{t(!document.querySelector("[data-sonner-toaster]"));},[]),e?jsx(Toaster,{position:"top-center",style:{zIndex:2147483647}}):null}function Wa(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function $a(e){if(e)return {accent:e.accent,radius:`${e.radius}px`,scheme:e.mode}}function qa({variant:e="default",floating:t=false,className:n,children:r="Feedback",onClick:o,...a}){let{openCapture:i}=Ge(),s=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsx("button",{type:"button",className:s,"data-lumen-trigger":"",onClick:l=>{o?.(l),l.defaultPrevented||i(l.nativeEvent);},...a,children:r})}
4
- export{Ht as CaptureModal,qa as FeedbackButton,Mt as LUMEN_KEYBOARD_CSS_VAR,Ye as LUMEN_KEYBOARD_EVENT,ct as LUMEN_SHAKE_MESSAGE,za as LumenProvider,ao as createNativeCaptureProvider,eo as isLumenEventTarget,to as isolateLumenEvents,Lt as readLumenKeyboardInset,go as setLumenKeyboardInset,Xe as useKeyboardInset,Ge as useLumen};//# sourceMappingURL=index.js.map
2
+ import*as Rn from'react';import {createContext,useRef,useState,useCallback,useEffect,useImperativeHandle,useContext,useMemo,useId}from'react';import {toast,Toaster}from'sonner';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import {createPortal}from'react-dom';var N=class extends Error{constructor(e,t,n){super(e),this.code=t,this.status=n,this.name="LumenError";}code;status},$t=class extends N{constructor(){super("Origin not allowed. Add this origin in your Lumen project settings.","ORIGIN_NOT_ALLOWED",403),this.name="LumenOriginError";}},Kt=class extends N{constructor(e){super(`Rate limited \u2014 retry after ${e}s.`,"RATE_LIMITED",429),this.retryAfter=e,this.name="LumenRateLimitError";}retryAfter},it=class extends N{constructor(e){super(e,"NETWORK_ERROR"),this.name="LumenNetworkError";}},wr="https://shakebugs.vercel.app",yr="/api/v1/sdk/submit",Er="/api/v1/sdk/error",Cr="0.13.2",Rr=5,Sr=new Set([502,503,504]),tn=class{apiKey;apiUrl;user;amplitude;#e=new Set;#t=0;constructor(e){if(!e.apiKey||!e.apiKey.startsWith("lk_pub_"))throw new N("Invalid Lumen apiKey \u2014 expected a key starting with `lk_pub_`.","INVALID_API_KEY");this.apiKey=e.apiKey,this.apiUrl=(e.apiUrl??wr).replace(/\/$/,""),this.user=e.user,this.amplitude=e.amplitude;}async submit(e,t={}){let n=`${this.apiUrl}${yr}`,r=this.#n(e),o=null;for(let a=0;a<3;a++){a>0&&await kr(2**a*250);try{return await this.#r(n,r,t)}catch(i){if(o=i,i instanceof $t||i instanceof Kt||i instanceof N&&typeof i.status=="number"&&!Sr.has(i.status))throw i}}throw o instanceof Error?o:new it("Submit failed after 3 attempts.")}reportClientError(e){try{if(typeof window>"u"||this.#t>=Rr)return;let t=(e.stack??"").split(`
3
+ `)[1]?.trim()??"",n=`${e.name}:${e.message}@${t}`;if(this.#e.has(n))return;this.#e.add(n),this.#t+=1;let r=typeof navigator<"u"?navigator:void 0,o=typeof performance<"u"?performance.memory:void 0,a;try{let s=new URL(window.location.href);a=s.origin+s.pathname;}catch{a=void 0;}let i={message:String(e.message??"").slice(0,1e3),name:String(e.name??"Error").slice(0,200),stack:e.stack?.slice(0,8e3),componentStack:e.componentStack?.slice(0,8e3),url:a,userAgent:r?.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},dpr:window.devicePixelRatio,deviceMemory:r?.deviceMemory,jsHeap:o?{used:o.usedJSHeapSize,limit:o.jsHeapSizeLimit}:void 0,sdkVersion:Cr,context:e.context};fetch(`${this.apiUrl}${Er}`,{method:"POST",headers:{"Content-Type":"application/json","X-Lumen-Api-Key":this.apiKey},body:JSON.stringify(i),keepalive:!0,credentials:"omit",mode:"cors"}).catch(()=>{});}catch{}}#n(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,xr(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}#r(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:s}=n;i&&a.upload.addEventListener("progress",l=>{l.lengthComputable&&l.total>0&&i(Math.min(1,l.loaded/l.total));});let c=()=>{a.abort(),o(new it("Submit aborted."));};if(s){if(s.aborted){o(new it("Submit aborted."));return}s.addEventListener("abort",c,{once:true});}a.addEventListener("load",()=>{if(s&&s.removeEventListener("abort",c),a.status===403){o(new $t);return}if(a.status===429){let l=Number(a.getResponseHeader("Retry-After"))||60;o(new Kt(l));return}if(a.status<200||a.status>=300){o(new N(Mr(a.responseText)??`HTTP ${a.status}`,"HTTP_ERROR",a.status));return}try{let l=JSON.parse(a.responseText);r(l);}catch{o(new N("Malformed response from server.","BAD_RESPONSE"));}}),a.addEventListener("error",()=>{s&&s.removeEventListener("abort",c),o(new it("Network error during submit."));}),a.send(t);})}};function xr(e){return `screenshot.${e.type==="image/jpeg"?"jpg":e.type==="image/webp"?"webp":"png"}`}function kr(e){return new Promise(t=>setTimeout(t,e))}function Mr(e){try{let t=JSON.parse(e);return t.error??t.message??null}catch{return e||null}}var nn='[data-lumen-root], [data-lumen-capture-ignore="true"]';function rn(e=nn){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;}}var Lr=2,Tr=1.5,Ar=820,Pr=12,Ye=8*1024*1024;async function ut(e={}){kt();let t=e.mode??"auto";if(e.provider&&(t==="auto"||t==="custom"))try{return _r(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 N("Manual screenshot upload is required for this capture mode.","MANUAL_CAPTURE_REQUIRED");if(t==="true-screen")return Yt(e);if(t==="dom")return qt(e);if(t==="custom")throw new N("`capture.provider` is required when capture mode is `custom`.","CAPTURE_PROVIDER_REQUIRED");try{return await qt(e)}catch(n){if(un()){let r=await Yt(e);return r.warnings=Ze(["DOM screenshot failed; used browser screen permission fallback.",...r.warnings]),e.onWarning?.(r.warnings),r}throw n}}function Ge(e,t=[]){kt();let n=ct();return {blob:e,method:"manual-upload",platform:"web",viewport:n,pixelRatio:window.devicePixelRatio??1,warnings:Ze(t)}}var Wt=Promise.resolve();function qt(e){let t=Wt.then(()=>jt(e),()=>jt(e));return Wt=t.catch(()=>{}),t}async function jt(e){let t=await Hr(),n=e.target??document.documentElement,r=ct(),o=Fr(),a=window.visualViewport,i=window.scrollX+(a?.offsetLeft??0),s=window.scrollY+(a?.offsetTop??0),c=Ur(e,r.width,r.height),l=Vr(n);!e.provider&&Br()&&l.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 d=Dr(n);await ln(e.awaitAnimationsMs??Kr),await $r();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:s,scale:c,ignoreElements:g=>g instanceof HTMLElement&&(g.dataset.lumenCaptureIgnore==="true"||!!g.closest("[data-lumen-capture-ignore='true']")),onclone:(g,y)=>{Or(y,d),Nr(g);}}),R={blob:await sn(p,l),method:"web-dom",platform:"web",viewport:r,pixelRatio:c,warnings:Ze(l)};return R.warnings.length>0&&e.onWarning?.(R.warnings),R}var on=['input[type="password"]','input[autocomplete^="cc-"]','input[autocomplete="one-time-code"]',"[data-lumen-mask]"].join(", ");function Nr(e){for(let t of Array.from(e.querySelectorAll(on))){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 Ir="[data-lumen-root], [data-lumen-capture-ignore='true']";function an(e){return Array.from(e.querySelectorAll("input")).filter(t=>!t.closest(Ir))}function Dr(e){return an(e).map(t=>{if(t.matches(on))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=an(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 Br(){return typeof window<"u"&&typeof window.ReactNativeWebView<"u"}async function Hr(){let{default:e}=await import('html2canvas-pro');return e}async function xt(e={}){if(kt(),!un())throw new N("Browser screen capture is unavailable in this environment.","DISPLAY_MEDIA_UNAVAILABLE");let t=await navigator.mediaDevices.getDisplayMedia({video:true,audio:false}),n=null;try{n=document.createElement("video"),n.muted=!0,n.playsInline=!0,n.srcObject=t,await Wr(n);}catch(i){for(let s of t.getTracks())s.stop();throw i}let r=n,o=false,a=[];for(let i of t.getTracks())i.addEventListener("ended",()=>{o||a.forEach(s=>s());});return {stream:t,onEnded(i){a.push(i);},async grab(i){let s=i?.conceal??true,c=s?rn():()=>{};try{s&&await qr(r,3,400);let l=document.createElement("canvas");l.width=r.videoWidth,l.height=r.videoHeight;let d=l.getContext("2d");if(!d)throw new N("Could not create a drawing context for screen capture.","CANVAS_CONTEXT_UNAVAILABLE");d.drawImage(r,0,0,l.width,l.height);let p=ct(),R=["Browser screen capture uses the window or tab selected by the user."],g={blob:await sn(l,R),method:"web-display-media",platform:"web",viewport:p,pixelRatio:p.width>0?l.width/p.width:void 0,warnings:Ze(R)};return e.onWarning?.(g.warnings),g}finally{c();}},stop(){if(!o){o=true;for(let i of t.getTracks())i.stop();r.srcObject=null;}}}}async function Yt(e){let t=await xt(e);try{return await t.grab({conceal:!1})}finally{t.stop();}}function _r(e,t){let n=ct(),r={...e,method:e.method??"custom",platform:e.platform??"custom",viewport:e.viewport??n,pixelRatio:e.pixelRatio??window.devicePixelRatio??1,warnings:Ze(e.warnings??[])};return r.warnings.length>0&&t.onWarning?.(r.warnings),r}function Vr(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 sn(e,t){let n=await Gt(e,"image/png",.92);if(n.size<=Ye)return n;t.push("Screenshot exceeded the upload cap and was compressed.");let r=e,o=0;for(;n.size>Ye&&o<6;){let a=Math.max(.35,Math.min(.95,Math.sqrt(Ye/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 s=i.getContext("2d");if(!s)return n;s.drawImage(r,0,0,i.width,i.height),r=i;for(let c of [.86,.74,.62,.5])if(n=await Gt(r,"image/jpeg",c),n.size<=Ye)return n;if(o+=1,i.width<480||i.height<320)break}return n.size>Ye&&t.push("Screenshot remained large after compression; upload may be rejected."),n}function Gt(e,t,n){return new Promise((r,o)=>{e.toBlob(a=>{if(!a){o(new N("Could not encode screenshot.","ENCODE_FAILED"));return}r(a);},t,n);})}function ct(){let e=window.visualViewport;return {width:Math.round(e?.width??window.innerWidth),height:Math.round(e?.height??window.innerHeight)}}function Fr(){let e=document.documentElement;return {width:Math.round(e.clientWidth||window.innerWidth),height:Math.round(e.clientHeight||window.innerHeight)}}function Ur(e,t,n){let r=window.devicePixelRatio??1,o=e.maxScale??Lr;zr()&&(o=Math.min(o,Tr));let a=Math.max(1,Math.min(r,o)),i=Math.sqrt(Pr*1e6/Math.max(1,t*n));return Math.max(1,Math.min(a,i))}function zr(){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<=Ar}function $r(){return typeof requestAnimationFrame!="function"?new Promise(e=>setTimeout(e,32)):new Promise(e=>requestAnimationFrame(()=>requestAnimationFrame(()=>e())))}var Kr=400;async function ln(e){if(typeof document>"u"||typeof document.getAnimations!="function"||!(e>0))return;let t;try{t=document.getAnimations();}catch{return}let n=t.filter(a=>{if(a.playState!=="running")return false;let i=a.effect?.getComputedTiming?.();return !!i&&i.iterations!==1/0});if(n.length===0)return;let r=Promise.allSettled(n.map(a=>a.finished)).then(()=>{}),o=new Promise(a=>setTimeout(a,e));await Promise.race([r,o]);}function un(){return !!navigator.mediaDevices?.getDisplayMedia}async function Wr(e){await new Promise((r,o)=>{let a=()=>r(),i=()=>o(new N("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 N("Screen capture did not produce a frame in time.","VIDEO_TIMEOUT");await new Promise(r=>requestAnimationFrame(()=>r()));}}async function qr(e,t,n){let r=e.requestVideoFrameCallback?.bind(e);if(typeof r!="function"){await new Promise(i=>setTimeout(i,Math.min(n,250)));return}let o=performance.now(),a=0;await new Promise(i=>{let s=()=>{if(a+=1,a>=t||performance.now()-o>=n){i();return}r(s);};r(s),setTimeout(i,n);});}function kt(){if(typeof window>"u"||typeof document>"u")throw new N("Screenshot capture can only run in the browser.","INVALID_ENV")}function Ze(e){return Array.from(new Set(e.filter(Boolean)))}var cn=/^(token|access_token|refresh_token|id_token|api_?key|key|secret|password|passwd|pwd|auth|authorization|sig|signature|session|sessionid|sid|email|jwt)$/i,jr=[/-----BEGIN (?:[A-Z]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z]+ )?PRIVATE KEY-----/g,/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,/\b(?:AKIA|ASIA|AGPA|AIDA|AROA|ANPA|ANVA|AIPA)[A-Z0-9]{16}\b/g,/\bgh[posru]_[A-Za-z0-9]{20,}\b/g,/\bgithub_pat_[A-Za-z0-9_]{20,}\b/g,/\bglpat-[A-Za-z0-9_-]{18,}\b/g,/\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g,/\bAIza[A-Za-z0-9_-]{35}\b/g,/\b[srp]k_(?:live|test)_[A-Za-z0-9]{10,}\b/g,/\bsk-(?:proj-|ant-)?[A-Za-z0-9_-]{32,}\b/g];function Yr(e){let t=e.replace(/\D/g,"");if(t.length<13||t.length>19)return false;let n=0,r=false;for(let o=t.length-1;o>=0;o--){let a=t.charCodeAt(o)-48;r&&(a*=2,a>9&&(a-=9)),n+=a,r=!r;}return n%10===0}function Et(e){let t=e;for(let n of jr)t=t.replace(n,"***");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:cn.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\d(?:[ -]?\d){12,18}\b/g,n=>Yr(n)?"***":n),t=t.replace(/\b\d{3}-\d{2}-\d{4}\b/g,"***"),t=t.replace(/\b[\w.+-]+@[\w-]+\.[\w.-]+\b/g,"***@***"),t}function dn(e){try{let t=new URL(e,"http://relative.invalid");for(let r of [...t.searchParams.keys()])cn.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 mn(e){try{let t=new URL(e);return `${t.origin}${t.pathname}`}catch{return dn(e)}}var Zt=200,Xt=4096,pn=[],st=[],Jt=false,Ct=null;function fn(e={}){Jt||typeof window>"u"||(Jt=true,Ct=e.ignoreUrlPrefix??null,Jr(),Qr(),eo());}function Gr(){return {consoleLog:pn.slice(),networkLog:st.slice()}}function lt(e,t){e.push(t),e.length>Zt&&e.splice(0,e.length-Zt);}function Zr(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?`
4
+ ${r.stack}`:""}`);continue}try{t.push(JSON.stringify(r,Xr));}catch{t.push(String(r));}}let n=t.join(" ");return n.length>Xt?n.slice(0,Xt)+"\u2026[truncated]":n}function Xr(e,t){return t instanceof Element?`[Element ${t.tagName}]`:typeof t=="function"?"[Function]":t}function Jr(){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{lt(pn,{level:n,ts:Date.now(),message:Et(Zr(o))});}catch{}r(...o);});}}function gn(e){return Ct?e.startsWith(Ct):false}function Qr(){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(gn(r))return e.call(window,t,n);let a=performance.now();try{let i=await e.call(window,t,n);return lt(st,{type:"fetch",method:o,url:Rt(r),status:i.status,ok:i.ok,durationMs:Math.round(performance.now()-a),ts:Date.now()}),i}catch(i){throw lt(st,{type:"fetch",method:o,url:Rt(r),status:0,ok:false,durationMs:Math.round(performance.now()-a),ts:Date.now(),error:i instanceof Error?i.message:"fetch error"}),i}});}function eo(){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&&!gn(o.url)){o.t=performance.now();let a=()=>{try{lt(st,{type:"xhr",method:o.method,url:Rt(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 to(e){return e.length>512?e.slice(0,512)+"\u2026":e}function Rt(e){return to(dn(e))}function hn(e){if(typeof window>"u")return {url:"",userAgent:"",viewport:{width:0,height:0},capture:Qt(e),consoleLog:[],networkLog:[]};let t=Gr();return {url:mn(window.location.href),userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},capture:Qt(e),device:no(),consoleLog:t.consoleLog,networkLog:t.networkLog}}function no(){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?mn(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 Qt(e){if(e)return {method:e.method,platform:e.platform,viewport:e.viewport,pixelRatio:e.pixelRatio,warnings:e.warnings}}var ro="[data-lumen-root]",oo="[data-lumen-root], [data-lumen-trigger], [data-lumen-capture-ignore='true']";function ao(e){let t=typeof e.composedPath=="function"?e.composedPath():[];for(let n of t)if(St(n))return true;return St(e.target)}var en=["pointerdown","mousedown","touchstart","click"];function io(e){if(!e||typeof e.addEventListener!="function")return ()=>{};let t=n=>n.stopPropagation();for(let n of en)e.addEventListener(n,t,n==="touchstart"?{passive:true}:void 0);return ()=>{for(let n of en)e.removeEventListener(n,t);}}function St(e){return e?typeof Element<"u"&&e instanceof Element?e.matches(oo)?true:!!e.closest(ro):typeof ShadowRoot<"u"&&e instanceof ShadowRoot?St(e.host):false:false}var dt="lumen:shake",so=8e3,lo=50,uo=400;function co(e={}){return async function(){if(typeof window>"u")throw new N("Native capture bridge requires a WebView/browser window.","INVALID_ENV");let t=po(),n=e.send??mo,r=e.timeoutMs??so,o=e.captureSettleMs??lo,a=e.awaitAnimationsMs??uo,i=vo(),s=rn(e.concealSelector===void 0?nn:e.concealSelector);try{await go(o,a);let c=await new Promise((p,R)=>{let g=window.setTimeout(()=>{t.pending.delete(i),R(new N("Native screenshot timed out; the host did not respond.","NATIVE_CAPTURE_TIMEOUT"));},r);t.pending.set(i,{resolve:y=>{window.clearTimeout(g),p(y);},reject:y=>{window.clearTimeout(g),R(y);}});try{n({type:"lumen:capture-request",id:i,afterScreenUpdates:!0});}catch{t.pending.delete(i),window.clearTimeout(g),R(new N("Could not reach the native host for screen capture.","NATIVE_CAPTURE_UNAVAILABLE"));}});if(c.error||!c.dataUrl)throw new N(c.error??"Native screenshot returned no image.","NATIVE_CAPTURE_FAILED");let l=wo(c.dataUrl),d=e.platform??bo();return {blob:l,method:d==="android"?"android-native":"ios-native",platform:d,viewport:{width:Math.round(window.innerWidth),height:Math.round(window.innerHeight)},pixelRatio:c.pixelRatio??window.devicePixelRatio??1,warnings:[]}}finally{s();}}}function mo(e){let t=window.ReactNativeWebView;if(!t?.postMessage)throw new N("window.ReactNativeWebView is unavailable; pass a custom `send`.","NATIVE_CAPTURE_UNAVAILABLE");t.postMessage(JSON.stringify(e));}function po(){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=fo(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 fo(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}async function go(e,t){await ln(t),await ho(),e>0&&await new Promise(n=>window.setTimeout(n,e));}function ho(){return new Promise(e=>{requestAnimationFrame(()=>e());})}function bo(){let e=navigator.userAgent||"";return /android/i.test(e)?"android":"ios"}function vo(){return `lumen-cap-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID():Math.random().toString(36).slice(2)}`}function wo(e){let t=/^data:([^;,]*)(;base64)?,(.*)$/s.exec(e);if(!t)throw new N("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 s=0;s<a.length;s++)i[s]=a.charCodeAt(s);return new Blob([i],{type:n})}var Xe="lumen:keyboardchange",Mt="--lumen-keyboard-inset";function yo(e){if(typeof window>"u")return;let t=typeof e=="number"&&Number.isFinite(e)&&e>0?Math.round(e):0;window.__lumenKeyboardInset=t,typeof document<"u"&&document.documentElement.style.setProperty(Mt,`${t}px`),window.dispatchEvent(new Event(Xe));}function Lt(){if(typeof window>"u")return null;let e=window.__lumenKeyboardInset;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;if(typeof document<"u"&&typeof getComputedStyle=="function"){let t=getComputedStyle(document.documentElement).getPropertyValue(Mt).trim();if(t){let n=parseFloat(t);if(Number.isFinite(n)&&n>=0)return n}}return null}async function bn(e=60){if(typeof window>"u"||!navigator.mediaDevices)throw new N("Audio recording requires a browser with MediaDevices.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getUserMedia({audio:!0});}catch{throw new N("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,s=false,c=false,l,d,p=new Promise((g,y)=>{l=g,d=y;});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 k of t.getTracks())k.stop();if(c)return;if(c=true,s){d(new N("Recording cancelled.","RECORDER_STOPPED"));return}let g=performance.now()-a,y=r.mimeType||n||"audio/webm",C=new Blob(o,{type:y});l({blob:C,durationMs:g,mimeType:y});}),r.start(),i=window.setTimeout(()=>{r.state!=="inactive"&&r.stop();},e*1e3);function R(){if(r.state!=="inactive")try{r.stop();}catch{}}return {stream:t,cancel(){s=true,R(),i!==null&&window.clearTimeout(i),i=null;for(let g of t.getTracks())g.stop();},stop(){return R(),p}}}async function vn(e=60){if(typeof window>"u"||!navigator.mediaDevices||typeof navigator.mediaDevices.getDisplayMedia!="function")throw new N("Screen recording requires a browser with getDisplayMedia.","INVALID_ENV");let t;try{t=await navigator.mediaDevices.getDisplayMedia({video:!0,audio:!0});}catch{throw new N("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(y=>MediaRecorder.isTypeSupported(y))??"",r=new MediaRecorder(t,n?{mimeType:n}:void 0),o=[],a=performance.now(),i=null,s=false,c=false,l,d,p=new Promise((y,C)=>{l=y,d=C;});p.catch(()=>{});function R(){i!==null&&(window.clearTimeout(i),i=null);for(let y of t.getTracks())y.stop();}r.addEventListener("dataavailable",y=>{y.data&&y.data.size>0&&o.push(y.data);}),r.addEventListener("stop",()=>{if(s)return;if(s=true,R(),c){d(new N("Recording cancelled.","RECORDER_STOPPED"));return}let y=r.mimeType||n||"video/webm";l({blob:new Blob(o,{type:y}),durationMs:performance.now()-a,mimeType:y});});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(){c=true,r.state!=="inactive"?r.stop():s||(s=true,R(),d(new N("Recording cancelled.","RECORDER_STOPPED")));}}}var Tt=createContext(null);function Je(){let e=useContext(Tt);if(!e)throw new Error("useLumen() must be used inside <LumenProvider>.");return e}var wn=100;function yn(){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}var Qe={open:false,inset:0};function xo(e){let t=e.override??e.injected;if(t!=null){let r=t>1&&e.editable;return r?{open:r,inset:Math.round(t)}:Qe}if(e.vvHeight==null||!e.coarse||!e.editable)return Qe;let n=e.vvBaseline-e.vvHeight;return n>wn?{open:true,inset:Math.round(n)}:Qe}function et(e,t){let[n,r]=useState(Qe),o=useRef(0),a=useRef(t);return a.current=t,useEffect(()=>{if(!e){r(Qe);return}if(typeof window>"u")return;let i=typeof window.matchMedia=="function"&&window.matchMedia("(pointer: coarse)").matches,s=()=>{let p=yn(),R=a.current,g=Lt(),y=window.visualViewport??null;y&&R==null&&g==null&&!p&&(o.current=y.height),r(xo({editable:p,override:R,injected:g,vvBaseline:o.current,vvHeight:y?y.height:null,coarse:i}));},c=0,l=()=>{c||(c=window.requestAnimationFrame(()=>{c=0,s();}));},d=window.visualViewport;return d&&(o.current=d.height),l(),d?.addEventListener("resize",l),d?.addEventListener("scroll",l),document.addEventListener("focusin",l),document.addEventListener("focusout",l),window.addEventListener(Xe,l),()=>{c&&window.cancelAnimationFrame(c),d?.removeEventListener("resize",l),d?.removeEventListener("scroll",l),document.removeEventListener("focusin",l),document.removeEventListener("focusout",l),window.removeEventListener(Xe,l);}},[e]),n}var Nt='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, ui-sans-serif, sans-serif';function Cn(e,t=1){return Math.max(0,Math.min(t,e))}var Sn=Rn.forwardRef(function({screenshot:t,tool:n,color:r="rgb(239, 68, 68)",strokeWidth:o=4,onDrawingChange:a,onHistoryChange:i},s){let c=useRef(null),l=useRef(null),d=useRef(null),[p,R]=useState(null),[g,y]=useState([]),C=useRef(null),k=useRef(false),M=useRef(0),A=useRef(false),[h,w]=useState([]),O=useRef(0),T=useRef([]),I=useRef([]),D=useRef(g);D.current=g;let $=useRef(h);$.current=h;let F=useRef(null),be=useRef(i);be.current=i;let z=useCallback(()=>{be.current?.({canUndo:T.current.length>0,canRedo:I.current.length>0});},[]),K=useCallback((f,b)=>{w(S=>S.map(L=>L.id===f?{...L,text:b}:L));},[]),Z=useCallback(f=>{w(S=>S.filter(L=>L.id!==f));let b=T.current.lastIndexOf("comment");b>=0&&T.current.splice(b,1),I.current=[],z();},[z]);useEffect(()=>{let f=F.current;if(f==null)return;F.current=null,d.current?.querySelector(`[data-bubble-id="${f}"] .lumen-bubble-text`)?.focus();},[h]),useEffect(()=>{y([]),w([]),T.current=[],I.current=[],z();},[t,z]),useEffect(()=>{let f=false,b=null;return (async()=>{try{let S=await createImageBitmap(t);if(f){S.close?.();return}b=S,R(S);}catch{}})(),()=>{f=true,b?.close?.();}},[t]),useEffect(()=>{if(!p)return;let f=c.current,b=l.current;if(!f||!b)return;f.width=p.width,f.height=p.height,b.width=p.width,b.height=p.height;let S=f.getContext("2d");S&&(S.imageSmoothingEnabled=false,S.drawImage(p,0,0));},[p]),useEffect(()=>{let f=l.current;f&&mt(f,g,C.current);},[g]),useImperativeHandle(s,()=>({hasAnnotations:()=>g.length>0||h.some(f=>f.text.trim().length>0),reset:()=>{y([]),w([]),D.current=[],$.current=[],T.current=[],I.current=[],z();},undo:()=>{let f=T.current[T.current.length-1];if(f){if(f==="comment"){let b=$.current,S=b[b.length-1];if(!S)return;let L=b.slice(0,-1);$.current=L,I.current.push({type:"comment",item:S}),w(L);}else {let b=D.current,S=b[b.length-1];if(!S)return;let L=b.slice(0,-1);D.current=L,I.current.push({type:"anno",item:S}),y(L);}T.current.pop(),z();}},redo:()=>{let f=I.current[I.current.length-1];if(f){if(f.type==="comment"){let b=[...$.current,f.item];$.current=b,w(b);}else {let b=[...D.current,f.item];D.current=b,y(b);}T.current.push(f.type),I.current.pop(),z();}},async flatten(){let f=C.current,b=f?[...g,f]:g,S=h.filter(H=>H.text.trim().length>0);if(b.length===0&&S.length===0||!p)return t;let L=document.createElement("canvas");L.width=p.width,L.height=p.height;let W=L.getContext("2d");if(!W)return t;W.imageSmoothingEnabled=false,W.drawImage(p,0,0);for(let H of b)It(W,H);let B=c.current?.clientWidth||p.width,X=p.width/Math.max(B,1);for(let H of S)Ao(W,H,p.width,p.height,X);return await new Promise(H=>{L.toBlob(j=>{H(j??t);},"image/jpeg",.85);})}}),[g,h,p,t,z]);function ve(f){let b=l.current;if(!b)return {x:0,y:0};let S=b.getBoundingClientRect(),L=b.width/Math.max(S.width,1),W=b.height/Math.max(S.height,1);return {x:(f.clientX-S.left)*L,y:(f.clientY-S.top)*W}}function ae(){A.current||(A.current=true,requestAnimationFrame(()=>{A.current=false;let f=l.current;f&&mt(f,g,C.current);}));}function Pe(f){if(f.button!==void 0&&f.button!==0)return;if(n==="comment"){let S=l.current;if(!S)return;let L=S.getBoundingClientRect(),W=Cn((f.clientX-L.left)/Math.max(L.width,1),.72),B=Cn((f.clientY-L.top)/Math.max(L.height,1),.8),X=++O.current;w(H=>[...H,{id:X,x:W,y:B,text:"",color:r}]),T.current.push("comment"),I.current=[],F.current=X,z();return}try{f.currentTarget.setPointerCapture(f.pointerId);}catch{}k.current=true,a?.(true);let b=ve(f);n==="arrow"?C.current={kind:"arrow",from:b,to:b,color:r,width:o}:n==="rect"?C.current={kind:"rect",from:b,to:b,color:r,width:o}:C.current={kind:"freehand",points:[b],color:r,width:o},M.current=performance.now(),ae();}function Ne(f){if(!k.current||!C.current)return;let b=ve(f),S=C.current;if(S.kind==="arrow"||S.kind==="rect")S.to=b;else {let L=S.points[S.points.length-1],W=L?(L.x-b.x)**2+(L.y-b.y)**2:1/0,B=performance.now(),X=B-M.current;(W>16||X>16)&&(S.points.push(b),M.current=B);}ae();}function ie(){if(!k.current)return;k.current=false,a?.(false);let f=C.current;if(C.current=null,!!f){if(f.kind==="arrow"||f.kind==="rect"){let b=f.to.x-f.from.x,S=f.to.y-f.from.y;if(b*b+S*S<16){let L=l.current;L&&mt(L,g,null);return}}else if(f.points.length<2){let b=l.current;b&&mt(b,g,null);return}y(b=>[...b,f].slice(-50)),T.current.push("anno"),I.current=[],z();}}return jsxs("div",{ref:d,className:"lumen-annotate-frame","data-lumen-tool":n,children:[jsx("canvas",{ref:c}),jsx("canvas",{ref:l,className:"lumen-annotate-overlay",onPointerDown:Pe,onPointerMove:Ne,onPointerUp:ie,onPointerCancel:ie}),jsx("div",{className:"lumen-bubble-layer",children:h.map(f=>jsx(Lo,{comment:f,onChange:K,onRemove:Z},f.id))})]})});function Lo({comment:e,onChange:t,onRemove:n}){let r=useRef(null);return useEffect(()=>{let o=r.current;o&&o.textContent!==e.text&&(o.textContent=e.text);},[]),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:[jsx("span",{className:"lumen-bubble-label",children:"Comment"}),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??"")}),jsx("button",{type:"button",className:"lumen-bubble-del","aria-label":"Remove comment",onPointerDown:o=>o.stopPropagation(),onClick:()=>n(e.id),children:"\xD7"})]})}function mt(e,t,n){let r=e.getContext("2d");if(r){r.clearRect(0,0,e.width,e.height);for(let o of t)It(r,o);n&&It(r,n);}}function It(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")To(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 To(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],s=(a.x+i.x)/2,c=(a.y+i.y)/2;e.quadraticCurveTo(a.x,a.y,s,c);}let r=t[t.length-1];e.lineTo(r.x,r.y),e.stroke();}function Ao(e,t,n,r,o){let a=t.text.trim();if(!a)return;let i=10*o,s=14*o,c=10*o,l=12*o,d=s*1.35,p=c*1.7,R=t.x*n,g=t.y*r,y=Math.min(n*.6,n-R-8*o);e.save(),e.font=`500 ${s}px ${Nt}`,e.textBaseline="top";let C=Po(e,a,y-i*2),k=C.reduce((T,I)=>Math.max(T,e.measureText(I).width),0),M=Math.min(y,Math.max(k,56*o)+i*2),A=i*2+p+C.length*d;No(e,R,g,M,A,l),e.fillStyle="#ffffff",e.fill(),e.lineWidth=Math.max(1,o),e.strokeStyle="rgba(0,0,0,0.10)",e.stroke();let h=R+18*o,w=g+A;e.beginPath(),e.moveTo(h,w-o),e.lineTo(h+13*o,w-o),e.lineTo(h+4*o,w+9*o),e.closePath(),e.fillStyle="#ffffff",e.fill(),e.fillStyle=t.color||"rgb(239, 68, 68)",e.font=`700 ${c}px ${Nt}`,e.fillText("COMMENT",R+i,g+i),e.fillStyle="#111318",e.font=`500 ${s}px ${Nt}`;let O=g+i+p;for(let T of C)e.fillText(T,R+i,O),O+=d;e.restore();}function Po(e,t,n){let r=t.split(/\s+/).filter(Boolean),o=[],a="";for(let i of r){let s=a?`${a} ${i}`:i;a&&e.measureText(s).width>n?(o.push(a),a=i):a=s;}return a&&o.push(a),o.length?o:[t]}function No(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let s=e;if(typeof s.roundRect=="function"){s.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 tt({children:e,...t}){return 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 Io(e){return jsxs(tt,{...e,children:[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"}),jsx("circle",{cx:"12",cy:"13",r:"3.2"})]})}function Do(e){return jsxs(tt,{...e,children:[jsx("rect",{x:"3",y:"6",width:"13",height:"12",rx:"2.5"}),jsx("path",{d:"m16 10 5-3v10l-5-3"})]})}function Oo(e){return jsxs(tt,{...e,children:[jsx("path",{d:"M12 16V4m0 0 4 4m-4-4-4 4"}),jsx("path",{d:"M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"})]})}function pt(e){return jsxs(tt,{...e,children:[jsx("rect",{x:"3",y:"4",width:"18",height:"13",rx:"2"}),jsx("path",{d:"M8 21h8M12 17v4"})]})}function kn(e){return jsxs(tt,{...e,children:[jsx("rect",{x:"9",y:"3",width:"6",height:"11",rx:"3"}),jsx("path",{d:"M5 11a7 7 0 0 0 14 0M12 18v3"})]})}var Dt={shot:Io,video:Do,upload:Oo};function Mn(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 Bo(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 Ho=4e3;async function Ot(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((c,l)=>{if(n.readyState>=2)return c();n.addEventListener("loadeddata",()=>c(),{once:true}),n.addEventListener("error",()=>l(new Error("video decode failed")),{once:true});}),await Bo(n,Math.min(.1,(n.duration||0)/2));let i=await Mn(n),s=Number.isFinite(n.duration)?n.duration*1e3:0;return {poster:i,durationMs:s}},o,a=new Promise(i=>{o=window.setTimeout(()=>i({poster:null,durationMs:0}),Ho);});try{return await Promise.race([r().catch(()=>({poster:null,durationMs:0})),a])}finally{window.clearTimeout(o),n.removeAttribute("src"),URL.revokeObjectURL(t);}}async function Bt(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 Mn(t)}catch{return null}finally{t.srcObject=null;}}async function Ht(){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 _t=60,_o=25*1024*1024,Ln=[{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}],An=[{value:"bug",label:"Bug"},{value:"feature",label:"Idea"},{value:"other",label:"Other"}],Pn=[{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 Vt(){let{client:e,isOpen:t,closeCapture:n,user:r,capture:o,initialCapture:a,initialCaptureError:i,startVideoSession:s,consumePendingVideo:c,canRecordScreen:l,consumeRecordStartError:d,startScreenCaptureSession:p,consumePendingScreenshot:R,isolateEvents:g,keyboardInset:y}=Je(),[C,k]=useState(1),[M,A]=useState(null),[h,w]=useState({kind:"idle"}),[O,T]=useState(false),[I,D]=useState(0),[$,F]=useState(null),[be,z]=useState(false),[K,Z]=useState("arrow"),[ve,ae]=useState(Ln[0].value),[Pe,Ne]=useState(Tn[1].value),[ie,f]=useState(""),[b,S]=useState("bug"),[L,W]=useState(r?.email??""),[B,X]=useState(null),[H,j]=useState(null),[pe,Ce]=useState(0),[se,te]=useState(null),[fe,J]=useState(null),[ne,We]=useState(false),[we,Ie]=useState({canUndo:false,canRedo:false}),Re=useRef(null),He=useRef(null),_e=useRef(null),Ve=useRef(null),Se=et(t,y),ge=useRef(false),le=useRef(false);useEffect(()=>{t||(le.current=false);},[t]),useEffect(()=>{if(!t)return;if(le.current){ge.current=false;return}le.current=true,ge.current=false,k(1),A(null),f(""),j(null),Ce(0),te(null),T(false),D(0),F(null),z(false),J(null),Ie({canUndo:false,canRedo:false});let u=R();if(u){A("shot"),ke(u),w({kind:"ready",capture:u});return}let v=c();if(v)A("video"),te({blob:v.blob,durationMs:v.durationMs}),v.blob.size>_o&&toast.warning("This recording is large and may be too big to upload. Try a shorter clip if the upload fails."),v.poster?w({kind:"ready",capture:Ge(v.poster,["Screen recording; preview is the first frame."])}):(w({kind:"capturing"}),(async()=>{let P=null;if(v.deriveBlobPoster)try{P=(await Ot(v.blob)).poster;}catch{P=null;}P=P??await Ht(),!ge.current&&w(P?{kind:"ready",capture:Ge(P,["Screen recording; preview is the first frame."])}:{kind:"manual"});})());else {let P=d();P?(A("video"),J(P),w({kind:"idle"})):a?(A("shot"),w({kind:"ready",capture:a})):o?.mode==="manual"?w({kind:"manual"}):o?.provider&&!i?(A("shot"),Q(o.mode??"auto")):w({kind:"manual",error:i?.message??"Automatic screenshot capture was unavailable."});}return ()=>{ge.current=true;}},[t,o,a,i]),useEffect(()=>{if(!t)return;Ve.current=document.activeElement??null;let u=document.documentElement,v=u.style.overflow,P=u.style.paddingRight,ee=window.innerWidth-u.clientWidth;u.style.overflow="hidden",ee>0&&(u.style.paddingRight=`${ee}px`);let re=false,Le=()=>{if(!re){re=true,u.style.overflow=v,u.style.paddingRight=P;try{Ve.current?.focus?.();}catch{}}};return window.addEventListener("pagehide",Le),()=>{window.removeEventListener("pagehide",Le),Le();}},[t]),useEffect(()=>{if(!t)return;function u(v){if(v.key==="Escape"){v.preventDefault(),n();return}if(v.key!=="Tab")return;let P=He.current;if(!P)return;let ee=Yo(P);if(ee.length===0)return;let re=ee[0],Le=ee[ee.length-1],yt=document.activeElement;v.shiftKey&&(yt===re||!P.contains(yt))?(v.preventDefault(),Le.focus()):!v.shiftKey&&yt===Le&&(v.preventDefault(),re.focus());}return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[t,n]),useEffect(()=>{if(!t||!g)return;let u=_e.current;if(!u)return;let v=P=>{P.target===u&&P.stopPropagation();};return u.addEventListener("pointerdown",v),u.addEventListener("click",v),u.addEventListener("touchstart",v,{passive:true}),()=>{u.removeEventListener("pointerdown",v),u.removeEventListener("click",v),u.removeEventListener("touchstart",v);}},[t,g]),useEffect(()=>{if(!t||!Se.open)return;let u=He.current,v=document.activeElement;if(u&&v&&u.contains(v))try{v.scrollIntoView({block:"center"});}catch{}},[t,Se.open,Se.inset]),useEffect(()=>{if(!t||h.kind!=="manual")return;function u(v){let re=Array.from(v.clipboardData?.items??[]).find(Le=>Le.type.startsWith("image/"))?.getAsFile();re&&(v.preventDefault(),ye(re));}return window.addEventListener("paste",u),()=>window.removeEventListener("paste",u)},[t,h.kind]),useEffect(()=>{if(!B)return;let u=Date.now(),v=window.setInterval(()=>{let P=Math.floor((Date.now()-u)/1e3);Ce(P),P>=_t&&Ue();},250);return ()=>window.clearInterval(v)},[B]);let ue=useRef(null);if(ue.current=B,useEffect(()=>{t||ue.current&&(ue.current.cancel(),ue.current=null,X(null),Ce(0));},[t]),useEffect(()=>()=>{ue.current?.cancel();},[]),!t)return null;async function Q(u){ge.current=false,w({kind:"capturing"});try{let v=await ut({...o,mode:u,target:o?.target??document.documentElement});return ge.current?!1:(ke(v),w({kind:"ready",capture:v}),!0)}catch(v){return ge.current||w({kind:"manual",error:v instanceof Error?v.message:"Automatic screenshot capture was unavailable."}),false}}async function xe(u){A(u),J(null),F(null),u!=="video"&&Me(),u==="shot"?await Q(o?.mode??"auto"):u==="video"?(te(null),w({kind:"idle"})):w({kind:"manual"});}async function ye(u){if(u.type.startsWith("image/")){Me();let v=Ge(u,["Manual image upload used."]);w({kind:"ready",capture:v});return}if(u.type.startsWith("video/")){w({kind:"capturing"});try{let{poster:v,durationMs:P}=await Ot(u),ee=v??await Ht();if(!ee){w({kind:"manual",error:"Could not read that video."});return}let re=Ge(ee,["Uploaded video; preview is the first frame."]);te({blob:u,durationMs:P}),w({kind:"ready",capture:re});}catch{w({kind:"manual",error:"Could not read that video."});}return}toast.error("Choose an image (PNG, JPEG, WebP) or a video (MP4, WebM).");}function ke(u){u.warnings.length!==0&&toast.warning("Screenshot captured, but iframe, video, canvas, or cross-origin content may be incomplete.");}async function Fe(){try{let u=await bn(_t);X(u);}catch(u){toast.error(u instanceof Error?u.message:"Microphone unavailable");}}async function Ue(){if(B)try{let u=await B.stop();j({blob:u.blob,durationMs:u.durationMs});}catch(u){toast.error(u instanceof Error?u.message:"Could not stop recording");}finally{X(null);}}function ot(){B?.cancel(),X(null),j(null),Ce(0);}function qe(u){let v=jsxs("div",{className:"lumen-audio-row",children:[!B&&!H?jsxs("button",{type:"button",onClick:Fe,className:u==="capture"?"lumen-voice-capture-btn":"lumen-btn-ghost",children:[jsx(kn,{}),"Record voice note"]}):null,B?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-recording",children:[jsx("span",{className:"lumen-rec-dot","aria-hidden":"true"}),jsx($o,{stream:B.stream}),jsxs("span",{className:"lumen-rec-time",children:[pe,"s / ",_t,"s"]})]}),jsx("button",{type:"button",onClick:Ue,className:"lumen-btn-ghost",children:"Stop"}),jsx("button",{type:"button",onClick:ot,className:"lumen-btn-ghost",children:"Cancel"})]}):null,H&&!B?jsxs(Fragment,{children:[jsx(Wo,{blob:H.blob,durationMs:H.durationMs}),jsx("button",{type:"button",onClick:()=>j(null),className:"lumen-btn-ghost",children:"Remove"})]}):null]});return u==="capture"?jsxs("div",{className:"lumen-voice-capture",children:[v,!B&&!H?jsx("p",{className:"lumen-voice-capture-hint",children:"Say what went wrong while it\u2019s fresh."}):null]}):jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Add a voice note (optional)"}),v]})}async function at(){J(null);try{await s();}catch(u){toast.error(u instanceof Error?u.message:"Screen capture unavailable");}}function Me(){te(null);}let vt=h.kind==="ready";async function wt(){if(B&&await Ue(),C===1){if(h.kind==="ready"){let u=await Re.current?.flatten();F(u??h.capture.blob),z(u!=null&&u!==h.capture.blob);}k(2);}else C===2?k(3):await x();}function he(){C>1&&k(u=>u-1);}async function x(){if(h.kind!=="ready")return;let u=ie.trim(),{capture:v}=h;T(true),D(0);try{let P=$??v.blob,ee=await e.submit({rawText:u.length>0?u:void 0,category:b,submitterEmail:L.trim()||void 0,screenshot:P,audio:H?.blob,audioDurationMs:H?.durationMs,video:se?.blob,videoDurationMs:se?.durationMs,context:hn(v)},{onUploadProgress:re=>D(Math.min(.95,re))});D(1),toast.success("Feedback sent \u2014 thank you."),ee.id,n();}catch(P){toast.error(P instanceof Error?P.message:"Could not submit feedback"),T(false);}}function V(u){u.target===u.currentTarget&&!O&&n();}let U=Math.round(I*100),je=M==="video",gr=typeof navigator<"u"&&!!navigator.mediaDevices?.getDisplayMedia,hr=M==="shot"&&!o?.provider&&o?.allowTrueScreen!==false&&gr,br=C===1&&!vt||O,vr=C<3?"Next":O?U<95?`Uploading ${U}%\u2026`:"Almost done\u2026":"Send feedback";return jsx("div",{ref:_e,role:"dialog","aria-modal":"true","aria-label":"Send feedback",className:"lumen-modal-backdrop","data-lumen-capture-ignore":"true",style:Se.inset?{"--lumen-keyboard-inset":`${Se.inset}px`}:void 0,onMouseDown:V,children:jsxs("div",{ref:He,className:"lumen-modal","data-lumen-drawing":ne?"true":void 0,children:[jsx(zo,{onDismiss:n}),jsxs("header",{className:"lumen-modal-header",children:[jsxs("h2",{className:"lumen-modal-title",children:[jsx("span",{className:"lumen-modal-title-dot","aria-hidden":"true"}),"Send feedback"]}),jsx("button",{type:"button",onClick:n,className:"lumen-icon-btn","aria-label":"Close",children:"\xD7"})]}),jsx(Vo,{step:C}),jsxs("div",{className:"lumen-modal-body",children:[C===1?jsx("div",{className:"lumen-pane",children:M===null?jsxs(Fragment,{children:[jsx("div",{className:"lumen-method",role:"group","aria-label":"Capture method",children:Pn.map(u=>{let v=Dt[u.value];return jsxs("button",{type:"button",className:"lumen-method-btn"+(u.primary?" lumen-method-primary":""),onClick:()=>xe(u.value),disabled:h.kind==="capturing",children:[jsx("span",{className:"lumen-method-ico",children:jsx(v,{})}),u.primary?jsxs(Fragment,{children:[jsxs("span",{className:"lumen-method-text",children:[jsx("span",{className:"lumen-method-label",children:u.label}),jsx("span",{className:"lumen-method-hint",children:u.hint})]}),jsx("span",{className:"lumen-method-badge",children:"Fastest"})]}):jsxs(Fragment,{children:[jsx("span",{className:"lumen-method-label",children:u.label}),jsx("span",{className:"lumen-method-hint",children:u.hint})]})]},u.value)})}),jsx("p",{className:"lumen-status lumen-method-help",children:"Choose how to capture your feedback."})]}):jsxs(Fragment,{children:[jsx("div",{className:"lumen-method-switch",role:"group","aria-label":"Switch capture method",children:Pn.map(u=>{let v=Dt[u.value];return jsxs("button",{type:"button","aria-pressed":M===u.value,onClick:()=>xe(u.value),disabled:h.kind==="capturing",children:[jsx(v,{}),u.label]},u.value)})}),M==="video"&&h.kind==="idle"?jsx(Fo,{canRecord:l,onRecord:at,onUpload:()=>xe("upload"),error:fe}):null,h.kind==="capturing"?jsxs("p",{className:"lumen-status",children:[jsx("span",{className:"lumen-spinner","aria-hidden":"true"}),"Capturing\u2026"]}):null,h.kind==="manual"?jsxs("div",{className:"lumen-manual-capture",children:[jsx("p",{className:"lumen-status",children:M==="upload"?"Choose an image or video to attach \u2014 or paste an image.":h.error?"Automatic capture was unavailable. Upload or paste an image to continue.":"Upload or paste an image to continue."}),jsxs("label",{className:"lumen-manual-drop",children:[jsx("span",{children:M==="upload"?"Choose a file \u2014 image or video":"Choose or paste an image"}),jsx("input",{type:"file",accept:M==="upload"?"image/png,image/jpeg,image/webp,video/mp4,video/webm,video/quicktime":"image/png,image/jpeg,image/webp",onChange:u=>{let v=u.currentTarget.files?.[0];v&&ye(v),u.currentTarget.value="";}})]})]}):null,h.kind==="ready"?jsxs(Fragment,{children:[je?null:jsxs("div",{className:"lumen-toolbar",children:[jsxs("div",{className:"lumen-segmented",role:"group","aria-label":"Annotation tool",children:[jsx(ft,{label:"Arrow",active:K==="arrow",onClick:()=>Z("arrow")}),jsx(ft,{label:"Box",active:K==="rect",onClick:()=>Z("rect")}),jsx(ft,{label:"Draw",active:K==="freehand",onClick:()=>Z("freehand")}),jsx(ft,{label:"Comment",active:K==="comment",onClick:()=>Z("comment")})]}),jsx("span",{className:"lumen-toolbar-sep"}),jsx("div",{className:"lumen-swatches",role:"group","aria-label":"Color",children:Ln.map(u=>jsx("button",{type:"button",className:"lumen-swatch",style:{background:u.value},"aria-label":u.label,"aria-pressed":ve===u.value,onClick:()=>ae(u.value)},u.value))}),jsx("div",{className:"lumen-stroke-sizes",role:"group","aria-label":"Stroke width",children:Tn.map(u=>jsx("button",{type:"button",className:"lumen-stroke-size","aria-label":u.label,"aria-pressed":Pe===u.value,onClick:()=>Ne(u.value),children:jsx("span",{className:"lumen-stroke-size-dot",style:{width:u.dot,height:u.dot}})},u.value))}),jsx("span",{className:"lumen-toolbar-spacer"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>Re.current?.undo(),disabled:!we.canUndo,children:"Undo"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>Re.current?.redo(),disabled:!we.canRedo,children:"Redo"}),jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>Re.current?.reset(),disabled:!we.canUndo,children:"Clear"})]}),jsx("div",{className:"lumen-annotate",children:jsx(Sn,{ref:Re,screenshot:h.capture.blob,tool:K,color:ve,strokeWidth:Pe,onDrawingChange:We,onHistoryChange:Ie})}),jsxs("div",{className:"lumen-cap-actions",children:[jsx("button",{type:"button",className:"lumen-btn-ghost",onClick:()=>M&&xe(M),children:je?"\u21BB Re-record":"\u21BB Recapture"}),hr?jsxs("button",{type:"button",className:"lumen-btn-ghost lumen-exact-btn",onClick:()=>{p();},title:"Capture the real screen pixels \u2014 your browser will ask which tab or window to share, then you arrange the page and press Capture.",children:[jsx(pt,{})," Capture exact screen"]}):null,je?se?jsxs("span",{className:"lumen-cap-note",children:["\u2713 ",Math.round(se.durationMs/1e3),"s recorded"]}):null:jsx("span",{className:"lumen-cap-note",children:h.capture.method==="web-display-media"?"Exact screen captured":`${Nn(M)} captured \xB7 switch method above anytime`})]}),qe("capture")]}):null]})}):null,C===2?jsxs("div",{className:"lumen-pane lumen-form",children:[jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"What happened?"}),jsx("textarea",{value:ie,onChange:u=>f(u.target.value),rows:3,placeholder:"Describe the issue or idea\u2026",className:"lumen-input",autoFocus:true})]}),qe("describe"),jsxs("div",{className:"lumen-label",children:[jsx("span",{children:"Category"}),jsx("div",{className:"lumen-category",role:"group","aria-label":"Feedback category",children:An.map(u=>jsx("button",{type:"button",className:"lumen-category-opt","aria-pressed":b===u.value,onClick:()=>S(u.value),children:u.label},u.value))})]}),jsxs("label",{className:"lumen-label",children:[jsx("span",{children:"Your email (optional)"}),jsx("input",{type:"email",value:L,onChange:u=>W(u.target.value),placeholder:"you@example.com",className:"lumen-input"})]})]}):null,C===3?jsxs("div",{className:"lumen-pane lumen-review",children:[jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Capture"}),jsxs("span",{className:"lumen-review-v",children:[Nn(M),be?" \xB7 annotated":"",jsx("button",{type:"button",className:"lumen-edit",onClick:()=>k(1),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Category"}),jsxs("span",{className:"lumen-review-v",children:[jsx("span",{className:"lumen-chip",children:An.find(u=>u.value===b)?.label}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>k(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Description"}),jsxs("span",{className:"lumen-review-v",children:[ie.trim()?ie.trim():jsx("span",{className:"lumen-muted-empty",children:"\u2014"}),jsx("button",{type:"button",className:"lumen-edit",onClick:()=>k(2),children:"edit"})]})]}),jsxs("div",{className:"lumen-review-row",children:[jsx("span",{className:"lumen-review-k",children:"Material"}),jsxs("span",{className:"lumen-review-v lumen-attach-row",children:[H?jsxs("span",{className:"lumen-attach",children:["\u{1F399} Voice ",Math.round(H.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove voice note",onClick:()=>j(null),children:"\xD7"})]}):null,se?jsxs("span",{className:"lumen-attach",children:["\u25B6 Video ",Math.round(se.durationMs/1e3),"s",jsx("button",{type:"button",className:"lumen-att-x","aria-label":"Remove video",onClick:Me,children:"\xD7"})]}):null,L.trim()?jsxs("span",{className:"lumen-attach",children:["\u2709 ",L.trim()]}):null,!H&&!B?jsx("button",{type:"button",className:"lumen-btn-ghost lumen-add-btn",onClick:()=>{k(2),Fe();},children:"+ Voice note"}):null]})]})]}):null]}),jsxs("footer",{className:"lumen-modal-footer",children:[O?jsx("div",{className:"lumen-progress",role:"progressbar","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":U,children:jsx("div",{className:"lumen-progress-fill",style:{width:`${U}%`}})}):null,jsxs("div",{className:"lumen-modal-actions",children:[jsx("button",{type:"button",onClick:C===1?n:he,className:"lumen-btn-ghost",disabled:O,children:C===1?"Cancel":"Back"}),jsx("button",{type:"button",onClick:wt,className:"lumen-btn-primary",disabled:br,children:vr})]})]})]})})}function Nn(e){return e==="video"?"Screen recording":e==="upload"?"Upload":"Screenshot"}function Vo({step:e}){let t=[{n:1,label:"Capture"},{n:2,label:"Describe"},{n:3,label:"Review"}];return jsx("div",{className:"lumen-stepper","aria-hidden":"true",children:t.map((n,r)=>jsxs("div",{className:"lumen-step"+(e===n.n?" lumen-step-active":"")+(e>n.n?" lumen-step-done":""),children:[jsx("span",{className:"lumen-step-num",children:n.n}),jsx("span",{className:"lumen-step-lbl",children:n.label}),r<t.length-1?jsx("span",{className:"lumen-step-bar"}):null]},n.n))})}function Fo({canRecord:e,onRecord:t,onUpload:n,error:r}){return e?jsxs("div",{className:"lumen-record-prompt",children:[r?jsxs("p",{className:"lumen-record-unavailable",role:"alert",children:[r," Try again, or switch to ",jsx("strong",{children:"Upload"})," to attach a video instead."]}):null,jsx("button",{type:"button",className:"lumen-record-btn","aria-label":"Start screen recording",onClick:t}),jsxs("div",{className:"lumen-record-copy",children:[jsx("div",{className:"lumen-record-title",children:"Record your screen"}),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."})]})]}):jsxs("div",{className:"lumen-record-prompt",children:[jsx("p",{className:"lumen-record-unavailable",children:Uo()?jsx(Fragment,{children:"Screen recording isn\u2019t available on iOS browsers. Record with Control Center\u2019s screen recorder, then attach the clip below."}):jsx(Fragment,{children:"Screen recording isn\u2019t available in this browser. Upload a video to attach one instead."})}),jsx("button",{type:"button",className:"lumen-btn-primary lumen-record-upload",onClick:n,children:"Upload a video"})]})}function Uo(){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 ft({label:e,active:t,onClick:n}){return jsx("button",{type:"button",onClick:n,className:"lumen-tool","aria-pressed":t,children:e})}function zo({onDismiss:e}){let t=useRef(null),n=useRef(0),r=useRef(null);function o(s){s.currentTarget.setPointerCapture(s.pointerId),t.current=s.clientY,n.current=performance.now(),r.current=s.currentTarget.parentElement;}function a(s){if(t.current==null||!r.current)return;let c=Math.max(0,s.clientY-t.current);r.current.style.transform=`translateY(${c}px)`;}function i(s){if(t.current==null||!r.current)return;let c=Math.max(0,s.clientY-t.current),l=Math.max(1,performance.now()-n.current),d=c/l;r.current.style.transform="",r.current.style.transition="",t.current=null,(c>80||d>.6)&&e();}return jsx("div",{className:"lumen-modal-grabber","aria-hidden":"true",onPointerDown:o,onPointerMove:a,onPointerUp:i,onPointerCancel:i})}function $o({stream:e}){let t=useRef(null);return 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 s=window.AudioContext??window.webkitAudioContext;if(!s)return;let c=new s,l=c.createMediaStreamSource(e),d=c.createAnalyser();d.fftSize=1024,d.smoothingTimeConstant=.6,l.connect(d);let p=new Uint8Array(d.fftSize),R=18,g=3,y=3,C=Math.max(2,(o-g*(R-1))/R),k=Math.min(C/2,3),M=new Array(R).fill(0),A=0,h=false;function w(){if(h)return;d.getByteTimeDomainData(p);let O=Math.floor(p.length/R);i.clearRect(0,0,o,a),i.fillStyle=qo("--lumen-danger")||"rgb(239,68,68)";for(let T=0;T<R;T++){let I=0;for(let K=0;K<O;K++){let Z=Math.abs((p[T*O+K]??128)-128);Z>I&&(I=Z);}let D=Math.min(1,I/128*1.8),$=M[T]??0;M[T]=D>$?D:$+(D-$)*.35;let F=Math.max(y,M[T]*a),be=T*(C+g),z=(a-F)/2;Ko(i,be,z,C,F,k),i.fill();}A=requestAnimationFrame(w);}return A=requestAnimationFrame(w),()=>{h=true,cancelAnimationFrame(A);try{l.disconnect();}catch{}c.close();}},[e]),jsx("canvas",{ref:t,className:"lumen-waveform","aria-hidden":"true"})}function Ko(e,t,n,r,o,a){let i=Math.min(a,r/2,o/2);e.beginPath();let s=e;if(typeof s.roundRect=="function"){s.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 Wo({blob:e,durationMs:t}){let[n,r]=useState("");return useEffect(()=>{let o=URL.createObjectURL(e);return r(o),()=>{URL.revokeObjectURL(o);}},[e]),jsxs("div",{className:"lumen-audio-preview",children:[jsx("audio",{controls:true,preload:"metadata",src:n,className:"lumen-audio-el"}),jsxs("span",{className:"lumen-audio-meta",children:[Math.round(t/1e3),"s"]})]})}function qo(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()}var jo='a[href], button:not([disabled]), textarea:not([disabled]), input:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Yo(e){return Array.from(e.querySelectorAll(jo)).filter(t=>!t.hasAttribute("disabled")&&t.offsetParent!==null)}var gt=class extends Rn.Component{state={hasError:false};static getDerivedStateFromError(){return {hasError:true}}componentDidCatch(t,n){if(typeof document<"u"){let r=document.documentElement;r.style.overflow="",r.style.paddingRight="",document.body.removeAttribute("data-lumen-open");}console.error("[lumen] recovered from a widget error:",t),toast.error("Feedback widget hit a snag and was reset. Please try again.");try{let r=t instanceof Error?t:null;this.props.onError?.({message:r?.message??String(t),name:r?.name??"Error",stack:r?.stack,componentStack:n?.componentStack??void 0});}catch{}Promise.resolve().then(()=>this.props.onReset());}render(){return this.state.hasError?null:this.props.children}};function Hn({state:e,portalTarget:t,onStop:n,onCancel:r}){let[o,a]=useState(false);if(useEffect(()=>a(true),[]),!o||typeof document>"u")return null;let i=t??document.body;return e.phase==="recording"?createPortal(jsx(Zo,{startedAt:e.startedAt,maxSeconds:e.maxSeconds,onStop:n,onCancel:r}),i):createPortal(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:[jsx("span",{className:"lumen-rec-hud-spinner","aria-hidden":"true"}),jsx("span",{className:"lumen-rec-hud-time",children:e.phase==="starting"?"Starting\u2026":"Processing\u2026"}),jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"})]}),i)}function Zo({startedAt:e,maxSeconds:t,onStop:n,onCancel:r}){let[o,a]=useState(0);useEffect(()=>{let s=()=>a(Math.min(t,Math.max(0,Math.floor((Date.now()-e)/1e3))));s();let c=window.setInterval(s,250);return ()=>window.clearInterval(c)},[e,t]);let i=s=>`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`;return jsxs("div",{className:"lumen-rec-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[jsx("span",{className:"lumen-rec-hud-dot","aria-hidden":"true"}),jsxs("span",{className:"lumen-rec-hud-time",children:[i(o)," ",jsxs("span",{className:"lumen-rec-hud-max",children:["/ ",i(t)]})]}),jsx("button",{type:"button",className:"lumen-rec-hud-cancel",onClick:r,"aria-label":"Discard recording",children:"Discard"}),jsxs("button",{type:"button",className:"lumen-rec-hud-stop",onClick:n,"aria-label":"Stop recording and return to feedback",children:[jsx("span",{className:"lumen-rec-hud-square","aria-hidden":"true"}),"Stop"]})]})}function _n({state:e,portalTarget:t,onCapture:n,onCancel:r}){let[o,a]=useState(false);if(useEffect(()=>a(true),[]),!o||typeof document>"u")return null;let i=t??document.body,s=e.phase==="grabbing";return createPortal(jsxs("div",{className:"lumen-cap-hud",role:"status","aria-live":"polite","data-lumen-root":"true","data-lumen-capture-ignore":"true",children:[s?jsx("span",{className:"lumen-cap-hud-spinner","aria-hidden":"true"}):jsx("span",{className:"lumen-cap-hud-ico","aria-hidden":"true",children:jsx(pt,{})}),jsx("span",{className:"lumen-cap-hud-text",children:s?"Capturing\u2026":"Arrange the screen, then capture"}),jsx("button",{type:"button",className:"lumen-cap-hud-cancel",onClick:r,disabled:s,children:"Cancel"}),jsx("button",{type:"button",className:"lumen-cap-hud-capture",onClick:n,disabled:s,"aria-label":"Capture this screen and return to feedback",children:"Capture"})]}),i)}function Ft(e){let t=e.hasProvider&&e.providerAvailable!==false;return {canRecord:t||e.hasGetDisplayMedia,usingProvider:t}}function Vn(e){return typeof e=="object"&&e!==null&&e.code==="RECORDER_STOPPED"}function Fn(e){return e instanceof Error?e:new Error(String(e))}function Un(e,t,n){let r=false,o=false,a=false,i=null;function s(){o||(o=true,n.onCancelled());}function c(d){o||(o=true,n.onResult(d));}function l(d){o||(o=true,n.onError(d));}return n.onStarting(),Promise.resolve().then(()=>e(t)).then(d=>{if(i=d,r){try{d.cancel();}catch{}s();return}if(n.onActive(d),a){n.onProcessing();try{d.stop();}catch{}}Promise.resolve(d.result).then(p=>{r?s():c(p);}).catch(p=>{r||Vn(p)?s():l(Fn(p));});}).catch(d=>{r||Vn(d)?s():l(Fn(d));}),{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{}s();}}}}function zn(){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 s=document.elementsFromPoint(i,n);for(let c of s){if(o.has(c))continue;o.add(c);let l=window.getComputedStyle(c);if(l.position!=="fixed"&&l.position!=="sticky")continue;let d=c.getBoundingClientRect();d.bottom<t-8||d.bottom>t+8||d.width<e*.6||d.height>a&&(a=d.height);}}return a}function Ut(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 s of Array.from(i)){let c=s.getBoundingClientRect();if(c.height===0||c.width===0)continue;let l=0;switch(t){case "bottom":if(c.bottom<r-8)break;l=Math.max(0,r-c.top);break;case "top":if(c.top>8)break;l=Math.max(0,c.bottom);break;case "left":if(c.left>8)break;l=Math.max(0,c.right);break;case "right":if(c.right<n-8)break;l=Math.max(0,n-c.left);break}l>o&&(o=l);}}return o}function $n(e){let[t,n]=useState(()=>({bottom:e.offset.y,right:e.offset.x,left:e.offset.x,top:e.offset.y})),r=useRef(t),o=oa(e.avoid),a=e.placement,i=e.offset.x,s=e.offset.y;return useEffect(()=>{if(typeof window>"u")return;let c=0,l=false,d=()=>{if(c=0,l)return;let C=a[0]==="b"?"bottom":"top",k=a[1]==="r"?"right":"left",M=0,A=0;e.avoid==="auto"&&C==="bottom"?M=zn():Array.isArray(e.avoid)&&(M=Ut(e.avoid,C),A=Ut(e.avoid,k));let h={bottom:C==="bottom"?s+M:0,top:C==="top"?s+M:0,right:k==="right"?i+A:0,left:k==="left"?i+A:0},w=r.current;(h.bottom!==w.bottom||h.top!==w.top||h.right!==w.right||h.left!==w.left)&&(r.current=h,n(h));},p=()=>{c||(c=window.requestAnimationFrame(d));};p();let R=typeof ResizeObserver<"u"?new ResizeObserver(p):null;R?.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 y=window.visualViewport;return y?.addEventListener("resize",p),y?.addEventListener("scroll",p),()=>{l=true,c&&window.cancelAnimationFrame(c),R?.disconnect(),g?.disconnect(),window.removeEventListener("resize",p),y?.removeEventListener("resize",p),y?.removeEventListener("scroll",p);}},[a,i,s,o]),t}function oa(e){return e===false?"false":e==="auto"?"auto":e.join("|")}var Kn=["mousedown","touchstart"];function Ke(e){let t=useRef(e.onPointerDown);t.current=e.onPointerDown;let n=useRef(e.onClick);n.current=e.onClick;let r=useRef(e.isolate??true);r.current=e.isolate??true;let o=useRef(null);return useCallback(a=>{if(o.current?.(),o.current=null,!a)return;let i=l=>{r.current&&l.stopPropagation(),t.current?.(l);},s=l=>{r.current&&l.stopPropagation(),n.current(l);},c=l=>{r.current&&l.stopPropagation();};a.addEventListener("pointerdown",i),a.addEventListener("click",s);for(let l of Kn)a.addEventListener(l,c,l==="touchstart"?{passive:true}:void 0);o.current=()=>{a.removeEventListener("pointerdown",i),a.removeEventListener("click",s);for(let l of Kn)a.removeEventListener(l,c);};},[])}function Yn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o,isolateEvents:a=true,keyboardInset:i}){let[s,c]=useState(null),l=useRef(null),d=$n(e),p=et(e.keyboard!=="off",i),R=Ke({onPointerDown:r,onClick:o,isolate:a}),g=useCallback(D=>{l.current=D,R(D);},[R]);useEffect(()=>{typeof document>"u"||c(t??document.body);},[t]);let y=e.placement,C=y[0]==="b"?"bottom":"top",k=y[1]==="r"?"right":"left",M=C==="bottom",A=p.open&&M&&(e.keyboard==="lift"||e.keyboard==="auto"&&p.inset>0)?p.inset:0,h=p.open&&(e.keyboard==="hide"||e.keyboard==="auto"&&M&&p.inset<=0);if(ua(l,!n&&!h),!s)return null;let w=C==="bottom"?d.bottom:d.top,O=k==="right"?d.right:d.left,T=n||h,I={position:"fixed",[C]:e.safeArea?`calc(${w}px + env(safe-area-inset-${C}, 0px))`:`${w}px`,[k]:e.safeArea?`calc(${O}px + env(safe-area-inset-${k}, 0px))`:`${O}px`,zIndex:e.zIndex,transform:A?`translateY(-${A}px)`:void 0,opacity:T?0:1,pointerEvents:T?"none":"auto",transition:"opacity 160ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1)"};return createPortal(jsxs("button",{ref:g,type:"button",className:"lumen-btn lumen-btn-primary lumen-btn-floating",style:I,"aria-label":e.label,"aria-hidden":T?true:void 0,tabIndex:T?-1:0,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[e.icon,jsx("span",{children:e.label})]}),s)}function ua(e,t){let n=useRef(false);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,s=a.top+a.height/2,c=document.elementsFromPoint(i,s),l=Wn(window.getComputedStyle(o).zIndex);for(let d of c){if(d===o||o.contains(d))continue;if(Wn(window.getComputedStyle(d).zIndex)>l){n.current=true,console.warn("[lumen] trigger is occluded by",d);break}}},250);return ()=>window.clearTimeout(r)},[t,e]);}function Wn(e){let t=parseInt(e,10);return Number.isNaN(t)?0:t}function Gn({mount:e,label:t,icon:n,onPointerDown:r,onClick:o,isolateEvents:a=true}){let[i,s]=useState(null),c=Ke({onPointerDown:r,onClick:o,isolate:a});return useEffect(()=>{if(typeof document>"u")return;let l=e instanceof HTMLElement?e:e.current??null;s(l);},[e]),i?createPortal(jsxs("button",{ref:c,type:"button",className:"lumen-btn lumen-btn-primary","aria-label":t,"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[n,jsx("span",{children:t})]}),i):null}function Jn({config:e,portalTarget:t,hidden:n,onPointerDown:r,onClick:o,isolateEvents:a=true}){let[i,s]=useState(null),[c,l]=useState(false),d=useRef(null),p=Ke({onPointerDown:k=>{r?.(k),d.current={x:k.clientX,y:k.clientY},l(true);let M=k.currentTarget;try{M?.setPointerCapture?.(k.pointerId);}catch{}},onClick:o,isolate:a});if(useEffect(()=>{typeof document>"u"||s(t??document.body);},[t]),!i)return null;let R=`lumen-notch lumen-notch-${e.edge}${c?" lumen-notch-expanded":""}`;function g(k){let M=d.current;if(!M)return;let A=k.clientX-M.x,h=k.clientY-M.y;(e.edge==="top"&&h>16||e.edge==="bottom"&&h<-16||e.edge==="right"&&A<-16||e.edge==="left"&&A>16)&&(d.current=null,o(k.nativeEvent));}function y(){d.current=null,l(false);}function C(){d.current=null,l(false);}return createPortal(jsxs("button",{ref:p,type:"button",className:R,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,onPointerMove:g,onPointerUp:y,onPointerCancel:C,onMouseEnter:()=>l(true),onMouseLeave:()=>l(false),"data-lumen-trigger":"","data-lumen-capture-ignore":"true",children:[jsx("span",{className:"lumen-notch-handle","aria-hidden":"true"}),jsxs("span",{className:"lumen-notch-label",children:[e.icon,e.label]})]}),i)}function Qn(e){return {kind:"notch",edge:e.edge??"top",label:e.label??"Feedback",icon:e.icon,zIndex:e.zIndex??2147483600}}function Ea(e){return e===false?"off":e===true?"hide":e==="auto"||e==="lift"||e==="hide"?e:"auto"}function er(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],keyboard:Ea(e.hideOnKeyboard),zIndex:e.zIndex??2147483600,label:e.label??"Feedback",icon:e.icon}}var Sa={"--lumen-bg":"background","--lumen-fg":"foreground","--lumen-radius":"radius"};function tr(e){let t=useId();useEffect(()=>{if(typeof document>"u")return;let n=document.documentElement,r=`data-lumen-theme-${xa(t)}`,o={},a=(i,s)=>{o[i]=n.style.getPropertyValue(i)||null,n.style.setProperty(i,s);};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,s]of Object.entries(Sa)){let c=e[s];typeof c=="string"&&c.length>0&&a(i,c);}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,s]of Object.entries(o))i.startsWith("--")?s?n.style.setProperty(i,s):n.style.removeProperty(i):s==null?n.removeAttribute(i):n.setAttribute(i,s);}},[e,t]);}function xa(e){return e.replace(/[^a-zA-Z0-9]/g,"")}var nr=Symbol.for("lumen.history.patched"),zt="lumen:locationchange";function La(){if(typeof window>"u")return;let e=window;if(e[nr])return;e[nr]=true;let t=()=>window.dispatchEvent(new Event(zt)),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 rr(e){let[t,n]=useState(false);return useEffect(()=>{if(!e){n(false);return}if(typeof window>"u")return;La();let r=()=>{try{n(!!e({pathname:window.location.pathname}));}catch{n(false);}};return r(),window.addEventListener(zt,r),window.addEventListener("popstate",r),()=>{window.removeEventListener(zt,r),window.removeEventListener("popstate",r);}},[e]),t}var Pa=["wv","Capacitor","Cordova","Expo","FBAN","FBAV","Instagram","Line/","Twitter"];function or(){let[e,t]=useState(false);return 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||"";Pa.some(a=>o.includes(a))&&t(true);},[]),e}var ir="lumen.config.v1.",Da=3600*1e3;function sr(e,t){let[n,r]=useState(()=>({trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:true}));return useEffect(()=>{if(typeof window>"u")return;let o=Fa(e);o&&r({trigger:o.trigger,enabled:ar(o.trigger),shakeToOpen:o.shake,brand:o.brand,loading:false});let a=new AbortController,i=window.setTimeout(()=>a.abort(),5e3),s=`${t.replace(/\/$/,"")}/api/v1/sdk/config?apiKey=${encodeURIComponent(e)}`;return fetch(s,{method:"GET",mode:"cors",credentials:"omit",signal:a.signal}).then(async c=>{if(!c.ok)throw new Error(`HTTP ${c.status}`);let l=await c.json(),d=lr(l.trigger);if(!d)throw new Error("Malformed config response");let p=Ha(l.trigger),R=ur(l.brand);Ua(e,d,p,R),r({trigger:d,enabled:ar(d),shakeToOpen:p,brand:R,loading:false});}).catch(()=>{r(c=>c.loading?{trigger:null,enabled:true,shakeToOpen:false,brand:null,loading:false}:c);}).finally(()=>window.clearTimeout(i)),()=>{window.clearTimeout(i),a.abort();}},[e,t]),n}function ar(e){return e.kind!=="headless"}var Oa=["br","bl","tr","tl"],Ba=["top","right","bottom","left"];function lr(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:Oa.find(o=>o===t.placement)??"br",label:n}:t.kind==="notch"?{kind:"notch",edge:Ba.find(o=>o===t.edge)??"top",label:n}:null}function Ha(e){return !e||typeof e!="object"?false:e.shake===true}var _a=/^#[0-9a-fA-F]{6}$/,Va=["auto","light","dark"];function ur(e){if(!e||typeof e!="object")return null;let t=e,n=typeof t.accent=="string"&&_a.test(t.accent)?t.accent:null;if(!n)return null;let r=Va.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 Fa(e){try{let t=window.localStorage.getItem(ir+e);if(!t)return null;let n=JSON.parse(t);if(typeof n?.fetchedAt!="number"||Date.now()-n.fetchedAt>Da)return null;let r=lr(n.trigger);return r?{fetchedAt:n.fetchedAt,trigger:r,shake:n.shake===!0,brand:ur(n.brand)}:null}catch{return null}}function Ua(e,t,n,r){try{window.localStorage.setItem(ir+e,JSON.stringify({fetchedAt:Date.now(),trigger:t,shake:n,brand:r}));}catch{}}function $a(e){if(e&&typeof e=="object")return e.type===dt;if(typeof e=="string")try{return JSON.parse(e).type===dt}catch{return false}return false}function Ka(e={}){let t=e.threshold??18,n=e.neededHits??3,r=e.windowMs??700,o=e.throttleMs??60,a=null,i=[];return {push(s,c,l,d){if(!a)return a={x:s,y:c,z:l,t:d},false;if(d-a.t<o)return false;let p=Math.abs(s-a.x)+Math.abs(c-a.y)+Math.abs(l-a.z);return a={x:s,y:c,z:l,t:d},p<t?false:(i=i.filter(R=>d-R<r),i.push(d),i.length>=n?(i=[],true):false)}}}function cr(e,t,n){useEffect(()=>{if(!e||typeof window>"u")return;let r=0,o=1500;function a(){let d=Date.now();n||d-r<o||(r=d,t());}let i=d=>{$a(d.data)&&a();};window.addEventListener("message",i),document.addEventListener("message",i);let s=Ka(),c=d=>{let p=d.accelerationIncludingGravity??d.acceleration;!p||p.x==null||p.y==null||p.z==null||s.push(p.x,p.y,p.z,Date.now())&&a();},l=typeof window.DeviceMotionEvent<"u"&&typeof window.DeviceMotionEvent.requestPermission!="function";return l&&window.addEventListener("devicemotion",c),()=>{window.removeEventListener("message",i),document.removeEventListener("message",i),l&&window.removeEventListener("devicemotion",c);}},[e,t,n]);}var mr="https://shakebugs.vercel.app",bt=60;function pr(){return typeof navigator<"u"&&!!navigator.mediaDevices&&typeof navigator.mediaDevices.getDisplayMedia=="function"}function ja({apiKey:e,apiUrl:t,user:n,amplitude:r,floatingButton:o=true,trigger:a,hideOn:i,theme:s,portalTarget:c,capture:l,record:d,shakeToOpen:p,onOpenChange:R,beforeOpen:g,onTriggerActivate:y,isolateEvents:C=true,keyboardInset:k,suppressTrigger:M=false,children:A}){let[h,w]=useState(false),[O,T]=useState(false),[I,D]=useState(null),[$,F]=useState(null),[be]=useState(false),[z]=useState(null),K=useRef(false),Z=useRef(false),ve=useRef(null),ae=useMemo(()=>new tn({apiKey:e,apiUrl:t,user:n,amplitude:r}),[e,t,n?.id,n?.email,n?.name,r?.userId,r?.deviceId,r?.sessionId]);useEffect(()=>{fn({ignoreUrlPrefix:(t??mr).replace(/\/$/,"")});},[t]);let Pe=useRef(R);Pe.current=R,useEffect(()=>{if(!(typeof document>"u"))return h?document.body.setAttribute("data-lumen-open","true"):document.body.removeAttribute("data-lumen-open"),()=>{document.body.removeAttribute("data-lumen-open");}},[h]);let Ne=useRef(null);useEffect(()=>{if(Ne.current===h)return;let x=Ne.current;Ne.current=h,x!==null&&Pe.current?.(h);},[h]);let ie=useRef(g);ie.current=g;let f=useRef(y);f.current=y;let b=useCallback(x=>{Z.current=true,ve.current=Promise.resolve().then(()=>ie.current?.(x)).then(()=>f.current?.(x)).then(()=>{});},[]),S=useCallback(x=>{K.current||h||J.current||ye.current||(K.current=true,T(true),D(null),F(null),(async()=>{try{if(Z.current?await ve.current:(await ie.current?.(x),await f.current?.(x)),l?.mode==="manual")D(null),F(null);else if(l?.provider)D(null),F(null);else {let V=await ut({...l,mode:l?.mode??"auto",target:l?.target??document.documentElement});D(V);}}catch(V){F(V instanceof Error?V:new Error(String(V)));}finally{Z.current=false,ve.current=null,K.current=false,T(false),w(true);}})());},[l,h]),L=useCallback(()=>{w(false),D(null),F(null);},[]),W=useCallback(ae.submit.bind(ae),[ae]),[B,X]=useState(0),H=useCallback(()=>{K.current=false,T(false),w(false),D(null),F(null),X(x=>x+1);},[]),[j,pe]=useState(null),[Ce,se]=useState(null),te=useRef(null),fe=useRef(null),J=useRef(false),ne=useRef(null),We=useRef(null),we=useRef(null),Ie=useCallback((x,V=false)=>{if(te.current=null,fe.current=null,J.current=false,pe(null),!x){ne.current=null;return}We.current={blob:x.blob,durationMs:x.durationMs,poster:ne.current,deriveBlobPoster:V},ne.current=null,w(true);},[]);useEffect(()=>{if(!h)return;if(!d?.provider){se(null);return}let x=d.isAvailable;if(!x){se(true);return}let V=false;return Promise.resolve().then(()=>x()).then(U=>{V||se(U);}).catch(()=>{V||se(false);}),()=>{V=true;}},[h,d?.provider,d?.isAvailable]);let Re=Ft({hasProvider:!!d?.provider,providerAvailable:Ce,hasGetDisplayMedia:pr()}).canRecord,He=useCallback(async()=>{if(J.current)return;if(we.current=null,Ft({hasProvider:!!d?.provider,providerAvailable:Ce,hasGetDisplayMedia:pr()}).usingProvider&&d?.provider){J.current=true,ne.current=null,w(false),fe.current=Un(d.provider,{maxDurationSeconds:bt},{onStarting:()=>pe({phase:"starting"}),onActive:U=>{pe({phase:"recording",stream:U.stream??null,startedAt:Date.now(),maxSeconds:bt}),U.stream&&Bt(U.stream).then(je=>{ne.current=je;}).catch(()=>{});},onProcessing:()=>pe({phase:"processing"}),onResult:U=>Ie({blob:U.blob,durationMs:U.durationMs},true),onCancelled:()=>{fe.current=null,J.current=false,ne.current=null,pe(null),D(null),F(null),w(true);},onError:U=>{fe.current=null,J.current=false,ne.current=null,pe(null),we.current=U.message||"Screen recording could not start.",w(true);}});return}if(te.current)return;let V=await vn(bt);te.current=V,J.current=true,ne.current=null,pe({phase:"recording",stream:V.stream,startedAt:Date.now(),maxSeconds:bt}),w(false),Bt(V.stream).then(U=>{ne.current=U;}).catch(()=>{}),V.result.then(U=>Ie(U)).catch(()=>Ie(null));},[Ie,d?.provider,Ce]),_e=useCallback(()=>{fe.current?fe.current.stop():te.current?.stop();},[]),Ve=useCallback(()=>{if(fe.current){fe.current.cancel();return}let x=te.current;te.current=null,J.current=false,ne.current=null,pe(null),x?.cancel(),D(null),F(null),w(true);},[]),Se=useCallback(()=>{let x=We.current;return We.current=null,x},[]),ge=useCallback(()=>{let x=we.current;return we.current=null,x},[]);useEffect(()=>{h||(we.current=null);},[h]);let[le,ue]=useState(null),Q=useRef(null),xe=useRef(null),ye=useRef(false),ke=useCallback(()=>{let x=Q.current;Q.current=null,ye.current=false,x?.stop(),ue(null),w(true);},[]),Fe=useCallback(()=>{let x=Q.current;x&&(ue({phase:"grabbing"}),(async()=>{try{let V=await x.grab();if(Q.current!==x)return;xe.current=V,Q.current=null,ye.current=!1,x.stop(),ue(null),w(!0);}catch{if(Q.current!==x)return;Q.current=null,ye.current=false,x.stop(),ue(null),toast.error("Could not capture the screen. Please try again."),w(true);}})());},[]),Ue=useCallback(async()=>{if(ye.current)return;let x;try{x=await xt({...l});}catch{return}Q.current=x,ye.current=true,x.onEnded(()=>ke()),ue({phase:"live"}),w(false);},[l,ke]),ot=useCallback(()=>{let x=xe.current;return xe.current=null,x},[]);useEffect(()=>()=>{Q.current?.stop(),Q.current=null;},[]);let qe=or(),at=rr(i),Me=sr(a?"":e,t??mr);tr(s??Za(Me.brand));let vt=p??Me.shakeToOpen;cr(vt,S,h);let wt=useMemo(()=>({client:ae,user:n,isOpen:h,isSubmitting:be,error:z,open:S,close:L,openCapture:S,closeCapture:L,submit:W,isNativeShell:qe,capture:l,initialCapture:I,initialCaptureError:$,isOpening:O,startVideoSession:He,stopVideoSession:_e,cancelVideoSession:Ve,recording:j,consumePendingVideo:Se,canRecordScreen:Re,consumeRecordStartError:ge,startScreenCaptureSession:Ue,grabScreenCaptureFrame:Fe,cancelScreenCaptureSession:ke,screenCapture:le,consumePendingScreenshot:ot,isolateEvents:C,keyboardInset:k}),[ae,n,h,be,z,S,L,W,qe,l,I,$,He,_e,Ve,j,Se,Re,ge,Ue,Fe,ke,le,ot,O,C,k]),he=Ga({explicit:a,remote:Me.trigger,remoteLoading:Me.loading,floatingButton:o});return jsxs(Tt.Provider,{value:wt,children:[A,jsxs(gt,{onReset:H,onError:x=>ae.reportClientError({...x,context:{open:h,opening:O,screenCapturePhase:le?.phase,recordingPhase:j?.phase,initialCaptureMethod:I?.method,initialCapturePixelRatio:I?.pixelRatio,initialCaptureViewport:I?.viewport,hadInitialCaptureError:$!=null}}),children:[he?.kind==="floating"?jsx(Yn,{config:er(he),portalTarget:c,hidden:at||M||O||j!=null||le!=null,onPointerDown:b,onClick:x=>S(x),isolateEvents:C,keyboardInset:k}):null,he?.kind==="notch"?jsx(Jn,{config:Qn(he),portalTarget:c,hidden:at||M||O||j!=null||le!=null,onPointerDown:b,onClick:x=>S(x),isolateEvents:C}):null,he?.kind==="inline"?jsx(Gn,{mount:he.mount,label:he.label??"Feedback",icon:he.icon,onPointerDown:b,onClick:x=>S(x),isolateEvents:C}):null,le?jsx(_n,{state:le,portalTarget:c,onCapture:Fe,onCancel:ke}):null,j?jsx(Hn,{state:j,portalTarget:c,onStop:_e,onCancel:Ve}):null,jsx(Vt,{})]},B),jsx(Ya,{})]})}function Ya(){let[e,t]=useState(false);return useEffect(()=>{t(!document.querySelector("[data-sonner-toaster]"));},[]),e?jsx(Toaster,{position:"top-center",style:{zIndex:2147483647}}):null}function Ga(e){return e.explicit?e.explicit:e.floatingButton===false?{kind:"headless"}:e.remote?e.remote:e.remoteLoading?null:{kind:"floating"}}function Za(e){if(e)return {accent:e.accent,radius:`${e.radius}px`,scheme:e.mode}}function Xa({variant:e="default",floating:t=false,className:n,children:r="Feedback",onClick:o,...a}){let{openCapture:i}=Je(),s=["lumen-btn",e==="default"?"lumen-btn-primary":null,e==="ghost"?"lumen-btn-ghost":null,e==="outline"?"lumen-btn-outline":null,t?"lumen-btn-floating":null,n].filter(Boolean).join(" ");return jsx("button",{type:"button",className:s,"data-lumen-trigger":"",onClick:c=>{o?.(c),c.defaultPrevented||i(c.nativeEvent);},...a,children:r})}
5
+ export{Vt as CaptureModal,Xa as FeedbackButton,Mt as LUMEN_KEYBOARD_CSS_VAR,Xe as LUMEN_KEYBOARD_EVENT,dt as LUMEN_SHAKE_MESSAGE,ja as LumenProvider,co as createNativeCaptureProvider,ao as isLumenEventTarget,io as isolateLumenEvents,Lt as readLumenKeyboardInset,yo as setLumenKeyboardInset,et as useKeyboardInset,Je as useLumen};//# sourceMappingURL=index.js.map
5
6
  //# sourceMappingURL=index.js.map